---
id: WF-CRM-DQ-007
title: Settle lost merge jobs and expire abandoned plans
trigger: >-
  The five-minute CRM reconciliation schedule invokes merge recovery and plan
  expiry.
product_area: crm
module: data-quality
revision: 1
status: draft
design_intent: proposed
implementation_evidence: observed
inference: []
source_sha:
  services-crm: a8d1364f1dd44b723bb5f9acba12f983e9ec8d69
implements:
  - CAP-CRM-DQ-016
  - CAP-CRM-DQ-012
moves:
  - STATE-CRM-DQ-005
  - STATE-CRM-DQ-004
crosses:
  - SVC-CRM-DQ-merges
idempotency: >-
  Conditional settlement preserves terminal attempts and reopens only eligible
  executing plans. Expiry excludes already-expired plans, so repeating it does
  not expire the same row again.
concurrency: >-
  Monitoring reads job roots across workspaces; domain settlement enters each
  job’s workspace. Expiry visits workspaces with a one-minute budget and limits
  each visit to one hundred plans.
hops:
  - 'n': 1
    actor_or_service: CRM job reconciler
    action: >-
      Locate stalled merge jobs, probe execution state and settle work that
      cannot report completion.
    anchor: 'services-crm:aws/lambda/JOB_RECONCILER.ts'
    seam: schedule
    on_failure: Log job recovery failure and continue where the reconciler permits.
    left_inconsistent: An unfinished-looking attempt can persist until a later recovery pass.
    observer: 'Job monitoring and reconciler logs, with a silence alarm.'
    provenance: observed
    source: 'services-crm:aws/lambda/JOB_RECONCILER.ts'
  - 'n': 2
    actor_or_service: Record-merge job type
    action: >-
      Record internal failure for an unresolved attempt and reopen its eligible
      plan in the job workspace.
    anchor: >-
      services-crm:modules/merges/services/jobs/record-merge-job.ts:markMergeFailedForLostJob
    seam: sync
    on_failure: Let later reconciliation repeat conditional settlement.
    left_inconsistent: The delay remains visible in job and attempt status.
    observer: 'Reconciler warning log naming merge, job and reopened status.'
    provenance: test
    source: >-
      services-crm:modules/merges/tests/integration/services/jobs/job-reconciliation.integration.spec.js#settles
      the job failed, rather than leaving it in flight for ever
  - 'n': 3
    actor_or_service: Merge plan expiry sweep
    action: >-
      After job recovery, mark overdue plans expired, excluding only executed
      and expired standing.
    anchor: >-
      services-crm:modules/merges/services/merges/merge-plan-expiry.ts:sweepExpiredRecordMergePlans
    seam: schedule
    on_failure: Log workspace expiry failure and retry on a later scheduled pass.
    left_inconsistent: >-
      Budget-limited workspaces expire late, while active plans can be expired
      too.
    observer: Sweep log line.
    provenance: test
    source: >-
      services-crm:modules/merges/tests/integration/services/merges/merge-plan-expiry.integration.spec.js#expires
      a blocked plan too, a plan nobody cleared being as abandoned as one nobody
      decided
branches:
  - >-
    Other reconciliation tasks share this schedule but remain owned by their own
    CRM modules.
evidence:
  - >-
    services-crm at a8d1364f: aws/lambda/JOB_RECONCILER.ts;
    modules/merges/services/jobs/record-merge-job.ts;
    services/merges/merge-plan-expiry.ts, merge-settlement.ts;
    services/persistence/record-merge-plans.ts:expireRecordMergePlans.
controls: [TC-AVL-004, TC-AZ-001, TC-AZ-002, TC-AZ-003, TC-AZ-004, TC-AZ-005, TC-AZ-006, TC-DAT-001, TC-DAT-002, TC-DAT-003, TC-IAM-001, 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-PRV-001, TC-PRV-002, TC-TEN-001, TC-TEN-002, TC-TEN-003]
---

# Settle Lost Merge Jobs And Expire Abandoned Plans

## What It Does

Reconciliation provides terminal outcomes for lost merge executions and closes overdue working plans. The two actions are independent and use conditional domain writes.

## The Flow

```mermaid
flowchart TD
  H1["Locate stalled merge jobs, probe execution state and settle work that cannot report completion."]
  H2["Record internal failure for an unresolved attempt and reopen its eligible plan in the job workspace."]
  H1 --> H2
  H3["After job recovery, mark overdue plans expired, excluding only executed and expired standing."]
  H2 --> H3
```

## When Something Fails

Failed visits can be attempted again at the next cadence. The sweep only marks expiry and does not remove retained snapshots. It can also expire an executing plan, preventing later failure reopening.

## Open Design Questions

Creation-based lifetime conflicts with the approved last-change rule. Settled-plan cleanup and consistent lost-execution timing need resolution before preparation can rely on these operations.
