---
id: WF-PFM-QRY-005
title: Settle abandoned query generations and remove old ones
trigger: The five-minute generation reconciliation schedule invokes the cleanup operation.
product_area: platform
module: queries
revision: 1
status: draft
design_intent: confirmed
implementation_evidence: observed
source_sha:
  services-platform: ad3f6a6582843008ed0f5a17b131878d15829af1
  react-console: baf6dae382d6f41dce976c7f848667ccc37e076f
inference: []
implements:
  - CAP-PFM-QRY-003
moves:
  - STATE-PFM-QRY-003
crosses:
  - SVC-PFM-QRY-queries
idempotency: >-
  Abandonment uses the same working-status condition as worker settlement. Repeated deletion of
  already-removed rows has no additional effect.
concurrency: >-
  The reconciler uses workspace and time bounds rather than guaranteeing all outstanding rows finish
  in one invocation. A worker settlement can win the conditional update.
hops:
  - 'n': 1
    actor_or_service: EventBridge schedule
    action: Invoke reconciliation on the generation function every five minutes.
    anchor: 'services-platform:modules/queries/aws/logic/queries-generation.lambda.ts'
    seam: schedule
    on_failure: A missed invocation leaves work for a later scheduled pass.
    left_inconsistent: Abandoned rows remain working until a successful pass reaches them.
    observer: the function's standard alarms
    provenance: observed
    source: 'services-platform:modules/queries/aws/logic/queries-generation.lambda.ts'
  - 'n': 2
    actor_or_service: Generation reconciler
    action: >-
      Visit eligible workspaces and fail working generations older than the worker deadline and
      margin.
    anchor: 'services-platform:modules/queries/services/generate/reconcile-generations.ts'
    seam: sync
    on_failure: Log the workspace failure for a later pass.
    left_inconsistent: Some abandoned outcomes can remain unsettled longer.
    observer: the reconciler's log
    provenance: observed
    source: 'services-platform:modules/queries/services/generate/reconcile-generations.ts'
  - 'n': 3
    actor_or_service: Generation reconciler
    action: 'Remove generation rows beyond thirty-day retention, irrespective of status.'
    anchor: 'services-platform:modules/queries/services/generate/reconcile-generations.ts'
    seam: sync
    on_failure: A later pass retries unfinished cleanup.
    left_inconsistent: Old request and outcome text remains retained until cleanup succeeds.
    observer: the reconciler's log
    provenance: observed
    source: 'services-platform:modules/queries/services/generate/reconcile-generations.ts'
branches: []
waits: []
evidence:
  - >-
    services-platform at ad3f6a6: modules/queries/services/generate/reconcile-generations.ts;
    aws/logic/queries-generation.lambda.ts
controls: [TC-AI-001, TC-AI-002, TC-AI-003, TC-AI-004, TC-AI-005, TC-AI-006, TC-AI-007, TC-AVL-001, TC-AVL-004, TC-AVL-005, TC-AZ-001, TC-AZ-002, TC-AZ-003, TC-AZ-004, TC-DAT-001, TC-DAT-003, TC-DAT-004, TC-IAM-001, TC-IAM-002, TC-IAM-004, TC-IAM-005, TC-IAM-006, 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-TEN-001, TC-TEN-002, TC-TEN-003, TC-VEN-001, TC-VEN-002, TC-VEN-003]
---

# Settle abandoned query generations and remove old ones

## What It Does

The five-minute generation reconciliation schedule invokes the cleanup operation. 

## The Flow

```mermaid
sequenceDiagram
  participant C as Request or schedule
  participant H0 as EventBridge schedule
  participant H1 as Generation reconciler
  participant H2 as Generation reconciler
  C-)H0: Invoke reconciliation on the generation function every five minutes
  H0->>H1: Visit eligible workspaces and fail working generations older than the worker deadline and margin
  H1->>H2: Remove generation rows beyond thirty-day retention, irrespective of status
```

Invoke reconciliation on the generation function every five minutes. Visit eligible workspaces and fail working generations older than the worker deadline and margin. Remove generation rows beyond thirty-day retention, irrespective of status.

## When Something Fails

A missed invocation leaves work for a later scheduled pass. Abandoned rows remain working until a successful pass reaches them. Log the workspace failure for a later pass. Some abandoned outcomes can remain unsettled longer. A later pass retries unfinished cleanup. Old request and outcome text remains retained until cleanup succeeds.

## Idempotency and Concurrency

Abandonment uses the same working-status condition as worker settlement. Repeated deletion of already-removed rows has no additional effect. The reconciler uses workspace and time bounds rather than guaranteeing all outstanding rows finish in one invocation. A worker settlement can win the conditional update.
