---
id: WF-PFM-QRY-021
title: Provision and remove module data with the workspace lifecycle
trigger: 'The workspace provisioning, deletion or reset workflow invokes the registered module participants.'
product_area: platform
module: queries
revision: 1
status: draft
design_intent: proposed
implementation_evidence: observed
source_sha:
  services-platform: ad3f6a6582843008ed0f5a17b131878d15829af1
inference: []
implements:
  - CAP-PFM-QRY-017
  - CAP-PFM-QRY-018
  - CAP-PFM-QRY-019
moves:
  - STATE-PFM-QRY-013
crosses:
  - SVC-PFM-QRY-queries
  - SVC-PFM-QRY-explorer
  - SVC-PFM-QRY-quick-search
  - SVC-PFM-QRY-snapshots
  - SVC-PFM-QRY-data-exports
idempotency: >-
  Provisioning reuses existing scopes. Purge participants report more work until their batches are
  empty and can retry incomplete cleanup.
concurrency: >-
  Search purge waits for open rebuild work; workers stop indexing deleting workspaces and events
  acknowledge without further writes there.
hops:
  - 'n': 1
    actor_or_service: Quick Search participant (provisioning)
    action: 'Provision every registered search type with defaults, ledger state and initial rebuild work.'
    anchor: 'services-platform:modules/quick-search/services/maintenance/tenant-participant.ts'
    seam: state_machine
    on_failure: The workspace job retries unfinished provisioning.
    left_inconsistent: A type can lack its scope until retry succeeds.
    observer: the participant's verifyProvisioned
    provenance: observed
    source: 'services-platform:modules/quick-search/services/maintenance/tenant-participant.ts'
  - 'n': 2
    actor_or_service: Queries and Explorer participants (deletion)
    action: >-
      Remove workspace query definitions, schedules, reports, generations, file rows and queue work,
      assignments and Explorer state while retaining product-level custom-table history.
    anchor: >-
      services-platform:modules/tenants/services/lifecycle/participants.ts:platformQueriesParticipant
    seam: state_machine
    on_failure: Retry unfinished deletion batches.
    left_inconsistent: >-
      Completed file objects can remain in the legacy storage bucket until its retention lifecycle
      removes them.
    observer: the deletion job's inventory
    provenance: observed
    source: 'services-platform:modules/tenants/services/lifecycle/participants.ts'
  - 'n': 3
    actor_or_service: Quick Search participant (deletion)
    action: >-
      Delete provider documents before clearing search configuration, claims, ledger and rebuild
      records.
    anchor: 'services-platform:modules/quick-search/services/maintenance/wipe.ts'
    seam: state_machine
    on_failure: Wait for open work or report blocked cleanup when provider credentials are absent.
    left_inconsistent: Blocked scopes can retain provider documents.
    observer: the deletion job
    provenance: observed
    source: 'services-platform:modules/quick-search/services/maintenance/tenant-participant.ts'
  - 'n': 4
    actor_or_service: Snapshots participant (deletion)
    action: >-
      Clear Platform self-test rows, workspace policy and snapshot ledger versions in
      dependency-safe order after other owners remove their rows.
    anchor: 'services-platform:modules/snapshots/services/maintenance/tenant-participant.ts'
    seam: state_machine
    on_failure: The workspace job retries an incomplete batch.
    left_inconsistent: Some snapshot rows can remain until deletion progresses.
    observer: the deletion job
    provenance: observed
    source: 'services-platform:modules/snapshots/services/maintenance/tenant-participant.ts'
  - 'n': 5
    actor_or_service: Data exports participants (deletion and reset)
    action: >-
      Remove staged and published package bytes before workspace export history, then settings for
      deletion; reset clears history while retaining settings.
    anchor: 'services-platform:modules/data-exports/services/maintenance/tenant-participant.ts'
    seam: state_machine
    on_failure: Retry incomplete storage or persistence cleanup.
    left_inconsistent: >-
      Unfinished bytes or rows can remain until retry, with staging also subject to its three-day
      retention.
    observer: the deletion or reset job
    provenance: observed
    source: 'services-platform:modules/data-exports/services/maintenance/tenant-participant.ts'
branches:
  - >-
    The selected lifecycle operation and participant resource declarations determine what reset
    retains.
waits: []
evidence:
  - >-
    services-platform at ad3f6a6: modules/tenants/services/lifecycle/participants.ts,
    reset-participants.ts; modules/quick-search/services/maintenance/tenant-participant.ts, wipe.ts;
    modules/snapshots/services/maintenance/tenant-participant.ts;
    modules/data-exports/services/maintenance/tenant-participant.ts
controls: [TC-AVL-001, TC-AVL-004, TC-AVL-005, TC-AZ-001, TC-AZ-002, TC-AZ-003, TC-AZ-004, TC-AZ-005, TC-CRY-001, TC-CRY-002, TC-CRY-003, TC-CRY-004, TC-DAT-001, TC-DAT-002, TC-DAT-003, TC-DAT-004, TC-DAT-005, TC-IAM-001, TC-IAM-002, TC-IAM-003, TC-IAM-004, TC-IAM-005, TC-IAM-006, TC-LOG-001, TC-LOG-002, TC-LOG-003, TC-LOG-004, TC-LOG-005, TC-MON-001, TC-MON-002, TC-PI-001, TC-PI-002, TC-PI-003, TC-PI-004, TC-PI-005, TC-PRV-001, TC-PRV-002, TC-SEC-001, TC-SEC-002, TC-SEC-003, TC-SEC-004, TC-TEN-001, TC-TEN-002, TC-TEN-003, TC-VEN-001, TC-VEN-002, TC-VEN-003]
---

# Provision and remove module data with the workspace lifecycle

## What It Does

The workspace provisioning, deletion or reset workflow invokes the registered module participants. The selected lifecycle operation and participant resource declarations determine what reset retains.

## The Flow

```mermaid
sequenceDiagram
  participant C as Request or schedule
  participant H0 as Quick Search participant provisioning
  participant H1 as Queries and Explorer participants deletion
  participant H2 as Quick Search participant deletion
  participant H3 as Snapshots participant deletion
  participant H4 as Data exports participants deletion and reset
  opt Workspace provisioning
    C-)H0: Provision every registered search type with defaults, ledger state and initial rebuild work
  end
  opt Workspace deletion
    C-)H1: Remove workspace query definitions, schedules, reports, generations, file rows and queue work, assig
  end
  opt Workspace deletion
    C-)H2: Delete provider documents before clearing search configuration, claims, ledger and rebuild records
  end
  opt Workspace deletion
    C-)H3: Clear Platform self-test rows, workspace policy and snapshot ledger versions in dependency-safe orde
  end
  opt Workspace deletion or history reset
    C-)H4: Remove staged and published package bytes before workspace export history, then settings for deletio
  end
```

Provision every registered search type with defaults, ledger state and initial rebuild work. Remove workspace query definitions, schedules, reports, generations, file rows and queue work, assignments and Explorer state while retaining product-level custom-table history. Delete provider documents before clearing search configuration, claims, ledger and rebuild records. Clear Platform self-test rows, workspace policy and snapshot ledger versions in dependency-safe order after other owners remove their rows. Remove staged and published package bytes before workspace export history, then settings for deletion; reset clears history while retaining settings.

## When Something Fails

The workspace job retries unfinished provisioning. A type can lack its scope until retry succeeds. Retry unfinished deletion batches. Completed file objects can remain in the legacy storage bucket until its retention lifecycle removes them. Wait for open work or report blocked cleanup when provider credentials are absent. Blocked scopes can retain provider documents. The workspace job retries an incomplete batch. Some snapshot rows can remain until deletion progresses. Retry incomplete storage or persistence cleanup. Unfinished bytes or rows can remain until retry, with staging also subject to its three-day retention.

## Idempotency and Concurrency

Provisioning reuses existing scopes. Purge participants report more work until their batches are empty and can retry incomplete cleanup. Search purge waits for open rebuild work; workers stop indexing deleting workspaces and events acknowledge without further writes there.
