Skip to content

fix: keep task retention from blocking the gateway - #158235

Merged
steipete merged 8 commits into
mainfrom
codex/task-retention-worker-20260925
Sep 26, 2026
Merged

steipete merged 8 commits into
mainfrom
codex/task-retention-worker-20260925

Conversation

@steipete

@steipete steipete commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Task-retention maintenance could block the Gateway event loop while waiting for SQLite write coordination. It now uses the existing read and write workers so unrelated Gateway work can continue.

User Impact

Retention deadlines, cron-history limits, stored formats, and update behavior are unchanged. No operator migration is required.

Why This Change Was Made

The read worker prepares the selected task and fingerprint; the write worker revalidates that source and live authority inside the transaction. A compact commit receipt settles a lost reply without replaying the write. The publication owner reconciles indexes, activity, and flow effects before notifying observers, preserving newer owners and unknown outcomes. The superseded synchronous retention APIs and callers are removed.

Evidence

The real coordinator-contention regression passes with this cutover and fails on the original synchronous path at the responsiveness assertion. Retained proof covers retention, publication, delivery, restore and replacement races, shutdown, and lost-result settlement. The full build, benchmark flow, production types, all 25 test-type graphs, script types and selected guards passed. Counts from the successive proof batches overlap and are not a unique-test total.

CI exposed an import cycle, variable shadowing, and fixture timestamp parity; these were corrected at their existing owners. The unchanged paging RPC reproduced its ordering failure before the fixture normalization fix; afterward it passed with its original 27-file cohort and 139 siblings.

The later asynchronous terminal writer exposed an unjoined restart-drain test. Its correction passed 20 full-file runs (188 cases each), three original 38-file cohorts (785 cases each), 59 completion/sweeper cases, and lint/format/owning test types on Linux/Node24.21. Neither bounded original-source probe reproduced that intermittent CI failure. The final size guard rejected the five-line addition to the oversized test file; main subsequently landed the canonical joined helper and extraction in #158344. This candidate adopts that existing version and removes the duplicate fixture edit. No size limit, assertion, or deadline was weakened.

Integration review also found that a committed cleanup stamp could lose its flow retry when managed cancellation returned an unfinished result. The retention owner now preserves that result and retains the existing retry obligation. The original module failed the new current-owner regression at the missing retry; the repaired row and all 128 cases across six owner/sibling files passed. The injected cancellation failure uses the in-memory command adapter; the separate retention, Gateway dispatch, and run-owner suites exercise native SQLite.

The subsequent main integration preserves #156919's final commit admissions for run-owner binding and task settlement alongside retention's ordered admission stages. Fresh focused review is clean, and the native Gateway dispatch and run-owner cases passed in the combined proof.

The earlier bacc head passed CI. The combined isolated run also passed lint and formatting, then stopped at main's two missing SDK projector calls; its later type-graph, size, and diff checks did not run. The published branch integrates the canonical #158520 repair while preserving all 199 pinned runtime-proof inputs. No overall success is claimed for that isolated run.

Fresh CI then found a newer SDK selection fixture still calling the retired synchronous deletion API. That fixture now uses the existing asynchronous retention command on the same store, preserving its held-read removal/replacement sequence and assertions. No production alias or new test seam was added. Managed review is clean. All 19 selection cases passed in the agentic-plugin-sdk-hosted-2 group, and exact-head CI for dd00fe76e46b succeeded across 173 jobs, including conditional skips.

Synthetic 64 KiB and 1 MiB profiles measured warm maintenance/publication timer gaps of 7–11 ms. Replies still use whole-object structured cloning; cold initialization was outside those probe windows, and peak process RSS includes fixtures, imports, and workers. These measurements establish neither deployed gains nor a per-message memory bound.

Test cost

Each measurement selects one file per invocation. Node24.19 used a worker upper bound of two and reported one file; Node24.21 explicitly used one worker on a four-CPU Linux allocation. Wall time includes compiled-worker preparation, imports, and tests. The slower cases retain real database/worker or Gateway boundary coverage; replacing those paths with mocks would lose the contract this change protects. Retained CI output also reports 7.611 seconds summed across 49 registry-store cases, which is not file or job wall time.

The latest flow-effects measurement covers 47 cases and reuses the same lease's compilation caches after the focused negative/fixed probes. The SDK selection fixture migration adds no cases; its 19 existing cases passed in final-head CI. Their reported case times sum to 116 ms, which is not standalone file or job wall time.

Suite Invocation wall Node
task-registry.maintenance-retention.test.ts 22.73 s 24.19
task-registry-worker-publication.test.ts 16.81 s 24.19
task-executor-create.flow-effects.test.ts 17.14 s 24.19
task-registry-query.test.ts 22.91 s 24.19
task-registry-state-notification.test.ts 35.83 s 24.19
server.tasks-list-performance.test.ts 25.63 s 24.19
tasks.access.test.ts 48.70 s 24.21
task-registry-projection-read.test.ts 34.45 s 24.21
task-registry-refresh.test.ts 28.05 s 24.21
task-registry-session-index.test.ts 22.07 s 24.21
task-registry.async-restore.test.ts 20.71 s 24.21
task-registry.maintenance-projection.test.ts 31.23 s 24.21
task-registry.store.test.ts 30.48 s 24.21
task-run-owner.test.ts 33.95 s 24.21

Release-note context: task-retention maintenance no longer waits synchronously for SQLite coordination on the Gateway event loop.

@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts size: XL labels Sep 25, 2026
@steipete
steipete marked this pull request as ready for review September 25, 2026 17:51
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 25, 2026
@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 25, 2026, 11:59 PM ET / September 26, 2026, 03:59 UTC (Revision 9).

ClawSweeper review

What this changes

Moves task-retention reads and writes to SQLite workers and reconciles committed pruning or cleanup stamps with Gateway task and parent-flow state.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep this PR open. Current main and the latest release still use synchronous task retention, so the change remains useful. The prior review’s blocker remains: a second managed-cancellation failure after a committed cleanup stamp can lose the retained flow retry.

Priority: P1
Reviewed head: dd00fe76e46b78e47a4e1af1815788fd01c12999

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Native contention proof supports the central repair, but an unresolved flow-settlement defect prevents merge readiness.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The PR’s native SQLite contention regression invokes task maintenance through its production owner, holds a competing coordinator writer, and observes event-loop progress plus durable prune and stamp results after release; the reported baseline fails that responsiveness assertion. The latest commit changes only a test fixture, so this proof still covers the worker cutover. Repeated managed-cancellation settlement remains a separate correctness finding. No stored-row format or schema contract changes.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR’s native SQLite contention regression invokes task maintenance through its production owner, holds a competing coordinator writer, and observes event-loop progress plus durable prune and stamp results after release; the reported baseline fails that responsiveness assertion. The latest commit changes only a test fixture, so this proof still covers the worker cutover. Repeated managed-cancellation settlement remains a separate correctness finding. No stored-row format or schema contract changes.
Evidence reviewed 10 items Current main still has synchronous retention: The fetched main revision calls the synchronous task deletion and cleanup-stamp APIs from maintenance; it does not contain this worker cutover.
Latest release has the same synchronous path: Release v2026.9.6 contains the synchronous retention implementation, so it does not supersede this PR.
Introduced retained flow obligation: The new cleanup-stamp path retains parent-flow effects when initial settlement returns unfinished.
Findings 1 actionable finding [P2] Keep retrying when managed cancellation remains unfinished
Security None None.

How this fits together

Gateway task maintenance selects completed tasks from the registry and applies retention to their SQLite records. The registry then updates its in-memory indexes and notifies task observers and parent flows.

flowchart LR
  A[Gateway task maintenance] --> B[Select completed task]
  B --> C[Read worker prepares task]
  C --> D[Write worker checks owner and commits]
  D --> E[Registry reconciles task state]
  E --> F[Task observers]
  E --> G[Parent flow effects]
Loading

Before merge

  • Keep retrying when managed cancellation remains unfinished (P2) - This new cleanup-stamp path retains flow effects after the first failed cancellation. On the timer retry, the existing callback ignores a second false settlement; the timer has already been removed, and later sweeps skip the stamped task. Preserve that unfinished result in the bounded retry owner and cover two consecutive failures.
  • Resolve merge risk (P1) - After a committed cleanup stamp, a second non-overload managed-cancellation failure can leave the parent flow running while later retention sweeps skip the stamped task.
  • Complete next step (P2) - Repair the repeated managed-cancellation retry loss and prove durable flow settlement before merge.

Findings

  • [P2] Keep retrying when managed cancellation remains unfinished — src/tasks/task-registry-maintenance-retention.ts:140-141
Agent review details

Security

None.

PR surface

Source +315, Tests +652, Docs +12, Other -1. Total +978 across 62 files.

View PR surface stats
Area Files Added Removed Net
Source 32 519 204 +315
Tests 27 1054 402 +652
Docs 1 12 0 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 2 12 13 -1
Total 62 1597 619 +978

Review metrics

Metric Value Why it matters
Production and test delta production +519/-204; tests/support +1054/-402 The production growth implements worker admission, commit receipts, and publication reconciliation; the PR body explains that boundary change.

Merge-risk options

Maintainer options:

  1. Retain the cancellation retry (recommended)
    Propagate an unfinished cancellation result through the existing bounded retry owner and prove eventual flow settlement after two injected failures.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Preserve the existing retry when the managed-cancellation callback returns unfinished after a committed cleanup stamp; add a two-failure owner-boundary regression and retain current authority and retry limits.

Technical review

Best possible solution:

Keep worker-owned retention and make an unfinished managed-cancellation callback preserve the bounded retry obligation, with a two-failure regression that verifies the eventual durable flow state.

Do we have a high-confidence way to reproduce the issue?

Yes. Holding the SQLite coordinator while running task maintenance gives a high-confidence path to check Gateway responsiveness and durable retention; the PR reports a failing baseline and passing worker-path result, though this read-only review did not execute it.

Is this the best way to solve the issue?

No, not yet. Moving retention to the existing read and write workers fits the storage owner, but the retained flow callback must continue retrying when managed cancellation remains unfinished.

Full review comments:

  • [P2] Keep retrying when managed cancellation remains unfinished — src/tasks/task-registry-maintenance-retention.ts:140-141
    This new cleanup-stamp path retains flow effects after the first failed cancellation. On the timer retry, the existing callback ignores a second false settlement; the timer has already been removed, and later sweeps skip the stamped task. Preserve that unfinished result in the bounded retry owner and cover two consecutive failures.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4363d7d55bdd.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR’s native SQLite contention regression invokes task maintenance through its production owner, holds a competing coordinator writer, and observes event-loop progress plus durable prune and stamp results after release; the reported baseline fails that responsiveness assertion. The latest commit changes only a test fixture, so this proof still covers the worker cutover. Repeated managed-cancellation settlement remains a separate correctness finding. No stored-row format or schema contract changes.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR’s native SQLite contention regression invokes task maintenance through its production owner, holds a competing coordinator writer, and observes event-loop progress plus durable prune and stamp results after release; the reported baseline fails that responsiveness assertion. The latest commit changes only a test fixture, so this proof still covers the worker cutover. Repeated managed-cancellation settlement remains a separate correctness finding. No stored-row format or schema contract changes.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: ⏳ waiting on author.

Label justifications:

  • P1: The PR addresses a Gateway event-loop stall during task maintenance, a broken core workflow that can affect active users.
  • merge-risk: 🚨 session-state: A repeated cancellation failure on the new stamped-task path can strand a parent flow in running state.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR’s native SQLite contention regression invokes task maintenance through its production owner, holds a competing coordinator writer, and observes event-loop progress plus durable prune and stamp results after release; the reported baseline fails that responsiveness assertion. The latest commit changes only a test fixture, so this proof still covers the worker cutover. Repeated managed-cancellation settlement remains a separate correctness finding. No stored-row format or schema contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR’s native SQLite contention regression invokes task maintenance through its production owner, holds a competing coordinator writer, and observes event-loop progress plus durable prune and stamp results after release; the reported baseline fails that responsiveness assertion. The latest commit changes only a test fixture, so this proof still covers the worker cutover. Repeated managed-cancellation settlement remains a separate correctness finding. No stored-row format or schema contract changes.

Evidence

Acceptance criteria:

  • [P1] pnpm test src/tasks/task-executor-create.flow-effects.test.ts --maxWorkers=1.
  • [P1] pnpm test src/tasks/task-registry.maintenance-retention.test.ts --maxWorkers=1.
  • [P1] node scripts/check-changed.mjs --dry-run -- src/tasks/task-registry-flow-sync.ts src/tasks/task-executor-mutation-effects.async.ts src/tasks/task-executor-create.flow-effects.test.ts.

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • roboclaw-bot: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Show a committed cleanup stamp reaching durable cancelled flow state after two consecutive injected managed-cancellation failures on the corrected head.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (8 earlier review cycles)
  • reviewed 2026-09-25T17:56:48.512Z sha 0631489 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-25T18:40:48.288Z sha a73cc98 :: blocked before merge. :: none
  • reviewed 2026-09-25T18:54:47.782Z sha a73cc98 :: blocked before merge. :: none
  • reviewed 2026-09-25T19:38:58.147Z sha 14f5d44 :: blocked before merge. :: none
  • reviewed 2026-09-25T21:19:07.459Z sha bacc525 :: blocked before merge. :: none
  • reviewed 2026-09-26T01:19:34.656Z sha b780168 :: blocked before merge. :: none
  • reviewed 2026-09-26T02:04:29.715Z sha 7fdf909 :: blocked before merge. :: none
  • reviewed 2026-09-26T02:29:48.072Z sha 5d2a1ee :: blocked before merge. :: [P2] Reschedule managed cancellation when its retained retry is unfinished

@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Sep 25, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 25, 2026
@steipete steipete self-assigned this Sep 25, 2026
Integrate the canonical restart-drain fixture extraction from main and
remove the duplicate test edit. Preserve the flow retry when a committed
retention stamp leaves managed cancellation unfinished.
@openclaw-barnacle openclaw-barnacle Bot removed the agents Agent runtime and tooling label Sep 26, 2026
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Sep 26, 2026
Integrate main's final authority checks for run-owner binding and task
settlement while preserving ordered retention admission and joined cleanup.
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 26, 2026
Bring in the canonical async harness task projection fix from #158520.
The task-retention patch and its frozen proof inputs remain unchanged.
Preserve the same in-memory store and the existing held-read race while
removing rows through the current asynchronous retention contract.
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 26, 2026
@clawsweeper clawsweeper Bot added the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Sep 26, 2026
@steipete
steipete merged commit ac9b848 into main Sep 26, 2026
249 checks passed
@steipete
steipete deleted the codex/task-retention-worker-20260925 branch September 26, 2026 04:51
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
* fix: keep task retention from blocking the gateway

* fix: keep task activity cleanup in the registry state owner

* test: preserve native retention timestamps in memory fixtures

* test: join restarted subagent completion

* test(tasks): use retention commands in selection races

Preserve the same in-memory store and the existing held-read race while
removing rows through the current asynchronous retention contract.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant