---
id: WF-ACC-BAT-011
title: Purge batch and ledger records when a workspace is deleted
trigger: Workspace deletion invokes the registered Accounting lifecycle participants.
product_area: accounting
module: batches
revision: 1
status: draft
design_intent: confirmed
origin: >-
  Andrew D9 (2026-10-15, the ledger is append-only and the posting tables join
  the existing participant's purge order), recorded at
  services-accounting:modules/batches/services/lifecycle/batch-posting-purge-order.ts
  (header)
implementation_evidence: observed
inference: []
source_sha:
  services-accounting: f47cb263875bbc0c5640fba7dae6785ec32695f8
implements:
  - CAP-ACC-BAT-017
crosses:
  - SVC-ACC-BAT-batches
idempotency: >-
  Each purge step removes surviving workspace rows; repeating completed steps
  finds no remaining rows to remove.
concurrency: >-
  The guarded ledger function requires the workspace deletion state. The shared
  lifecycle owns broader coordination with active writes and retries.
hops:
  - 'n': 1
    actor_or_service: Transactions lifecycle participant
    action: >-
      Remove schedule children and schedule headers before removing ledger
      children and ledger headers.
    anchor: >-
      services-accounting:modules/batches/services/lifecycle/batch-posting-purge-order.ts:ACCOUNTING_BATCH_POSTING_PURGE_ORDER
    seam: sync
    on_failure: The participant reports the failed step for lifecycle recovery.
    left_inconsistent: Earlier completed steps can remain removed while later records survive.
    observer: Platform workspace-deletion monitoring
    provenance: test
    source: >-
      services-accounting:modules/batches/tests/integration/services/lifecycle/ledger-purge.integration.spec.js#removes
      every batch posting table’s rows, the ledger’s first among them, and
      answers done with nothing left
  - 'n': 2
    actor_or_service: Ledger purge definer function
    action: >-
      Use the guarded ledger function to remove headers and lines only for a
      deleting workspace.
    anchor: >-
      services-accounting:modules/batches/services/lifecycle/batch-posting-purge-order.ts
      (accountingLedgerPurgeStep)
    seam: sync
    on_failure: Live-workspace admission rejects the deletion.
    left_inconsistent: The live ledger remains intact.
    observer: Platform workspace-deletion monitoring
    provenance: documented
    source: >-
      services-accounting:docs/accounting/batches.md#Unposting deletes the
      entries
  - 'n': 3
    actor_or_service: Transactions lifecycle participant
    action: >-
      Remove generation history and job families, then remove collections and
      inter-unit mappings after Transactions document tables.
    anchor: >-
      services-accounting:modules/batches/services/lifecycle/batch-posting-purge-order.ts:ACCOUNTING_BATCHES_PURGE_ORDER
    seam: sync
    on_failure: A failed step leaves later work for lifecycle retry.
    left_inconsistent: >-
      Restricting document references can keep collections until their own
      removal completes.
    observer: Platform workspace-deletion monitoring
    provenance: observed
    source: >-
      services-accounting:modules/transactions/services/lifecycle/transactions-participant.ts
branches:
  - >-
    The configuration participant later removes stream and routing
    configuration.
waits: []
evidence:
  - >-
    services-accounting at f47cb263:
    modules/batches/services/lifecycle/batch-posting-purge-order.ts;
    modules/transactions/services/lifecycle/transactions-participant.ts;
    docs/accounting/batches.md
controls: [TC-IAM-001, TC-IAM-005, TC-IAM-006, TC-AZ-001, TC-AZ-002, TC-AZ-003, TC-AZ-004, TC-AZ-005, TC-TEN-001, TC-TEN-002, TC-TEN-003, TC-DAT-001, TC-DAT-004, TC-LOG-001, TC-LOG-002, TC-LOG-003, TC-PI-002, TC-PI-003, TC-PI-005]
---

# Purge batch and ledger records when a workspace is deleted

## What It Does

Workspace deletion removes collection accounting in dependency order. Transactions registers the lifecycle participant, while Batch Management supplies posting purge order and the protected ledger-removal seam.

## The Flow

```mermaid
flowchart LR
  L[Deleting workspace] --> S[Remove schedule children]
  S --> G[Guarded ledger purge]
  G --> P[Remove postings and jobs]
  P --> D[Remove source documents]
  D --> B[Remove batches and mappings]
  B --> C[Configuration participant]
```

## When Something Fails

Completed table steps can remain removed when a later step fails. Lifecycle recovery resumes removal; the contract does not claim one transaction spanning the entire workspace. Guarded ledger admission protects live workspaces.

## Open Design Questions

Participant retry and lifecycle coordination are imported responsibilities. They remain supported indirectly by the available Accounting evidence, not by a direct examination of Platform standards.
