---
id: WF-CRM-ACT-006
title: Sweep overdue tasks every day
trigger: >-
  The daily attention schedule or an explicit operator invocation starts overdue-task
  reconciliation.
product_area: crm
module: activities-tasks
revision: 1
status: draft
design_intent: proposed
implementation_evidence: partially-observed
inference: []
source_sha:
  services-crm: a8d1364f1dd44b723bb5f9acba12f983e9ec8d69
implements:
  - CAP-CRM-ACT-015
moves:
  - STATE-CRM-ACT-004
crosses:
  - SVC-CRM-ACT-tasks
idempotency: >-
  Publication updates the item identified by its task, so repeating a page does not create
  a second item. Final resolution excludes items republished since the pass’s database
  start instant. This generation test does not guarantee fresh task details.
concurrency: >-
  The shared function permits three concurrent executions without a per-definition
  singleton. It reads task pages separately from publication and does not lock or reread
  tasks before publishing. Concurrent changes and overlapping passes can therefore publish
  older details.
hops:
  - 'n': 1
    actor_or_service: Daily attention schedule
    action: Invoke the overdue-task attention definition on its declared daily schedule.
    anchor: 'services-crm:aws/crm.attention-sweeps.ts:CRM_ATTENTION_SWEEPS'
    seam: schedule
    on_failure: >-
      The local infrastructure declares failure and silence alarms; actual delivery and
      external stale-sweep alarming are not proved here.
    left_inconsistent: Attention reflects preceding writes and completed passes.
    observer: Declared alerts and sweep logs provide the local monitoring boundary.
    provenance: documented
    source: 'services-crm:docs/attention.md#5. The sweeps'
  - 'n': 2
    actor_or_service: Workspace sweep coordinator
    action: >-
      Return skipped before reads when disabled; otherwise enter workspaces in identifier
      order and check the ten-minute budget between workspaces.
    anchor: 'services-crm:aws/crm.attention-sweeps.ts:sweepAttentionDefinition'
    seam: schedule
    on_failure: >-
      Log failed workspaces without stamping them, continue other workspaces and report
      failure; defer workspaces outside the budget.
    left_inconsistent: Unreached or failed workspaces can retain old items and miss newly overdue work.
    observer: Function logs and declared error monitoring expose the local outcome.
    provenance: observed
    source: 'services-crm:aws/crm.attention-sweeps.ts:sweepAttentionDefinition'
  - 'n': 3
    actor_or_service: Overdue task page publisher
    action: >-
      Read a database start instant, page overdue unfinished work by status in batches of
      200, and publish each separately read page in its own transaction.
    anchor: >-
      services-crm:modules/tasks/services/persistence/task-attention-items.ts:sweepOverdueTasks
    seam: schedule
    on_failure: A failed page stops that workspace while earlier page transactions remain committed.
    left_inconsistent: >-
      Earlier pages can remain published while later ones are absent, and concurrent task
      changes can stale published details.
    observer: Sweep logs record the page failure.
    provenance: test
    source: >-
      services-crm:modules/tasks/tests/integration/services/persistence/task-attention-items.integration.spec.js#publishes
      the overdue task no write had published, with no contact
  - 'n': 4
    actor_or_service: Sweep resolution and stamp
    action: Resolve older unseen items and then record the completed workspace sweep stamp.
    anchor: >-
      services-crm:modules/tasks/services/persistence/task-attention-items.ts:sweepOverdueTasks
    seam: schedule
    on_failure: A failed finishing step leaves the workspace without its new completion stamp.
    left_inconsistent: >-
      Older open items may remain until another successful change or pass; no repair
      deadline is established.
    observer: Platform consumes the declared stamp; its monitoring behavior is external proof.
    provenance: observed
    source: >-
      services-crm:modules/tasks/services/persistence/task-attention-items.ts:sweepOverdueTasks
branches:
  - An explicit request can scope reconciliation to one workspace.
waits:
  - >-
    The schedule runs daily rather than at every workspace midnight. Failed or deferred
    passes can extend publication delay beyond a day.
evidence:
  - >-
    services-crm at a8d1364f: aws/crm.attention-sweeps.ts;
    aws/cdk/logic/attention-sweep.lambda.ts; lib/attention.ts;
    modules/tasks/services/persistence/task-attention-items.ts (sweepOverdueTasks,
    pageOverdueTasks); docs/attention.md (§3, §5).
controls: [TC-DAT-001, TC-DAT-002, TC-DAT-003, TC-IAM-001, TC-IAM-005, TC-IAM-006, 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]
---

# Sweep overdue tasks every day

## What It Does

Reconciliation supplies attention after due days end without task writes. It republishes qualifying work and resolves older unseen items after a completed workspace pass. These are repair attempts over separately read data rather than a current-state consistency guarantee.

## The Flow

```mermaid
flowchart TD
  A[Daily schedule or operator request] --> B{Publication enabled?}
  B -->|No| C[Return skipped before reads]
  B -->|Yes| D[Select workspace within boundary budget]
  D --> E[Read overdue task page]
  E --> F[Publish separately read page transaction]
  F --> G{More pages?}
  G -->|Yes| E
  G -->|No| H[Resolve older unseen items and stamp completion]
  H --> I{More workspaces within budget?}
  I -->|Yes| D
  I -->|No| J[Report counts and failed or deferred workspaces]
```

The numbered hops specify the request, persistence and integration boundaries in order. Each hop identifies its evidence anchor, synchronization seam and observable failure outcome. Branches distinguish optional and delegated paths.

## When Something Fails

Committed pages survive a later page failure. Failed workspaces are logged and unstamped, while other workspaces continue. The budget is checked between workspaces rather than inside each page loop. The default-off switch returns a skipped result without reading task data.

## Open Design Questions

Product must settle the audience for unheld role offers. Integration proof must establish deployed switch settings, monitoring delivery and the acceptable delay or stale-item window.
