Repository navigation
fix: prevent stalled transcript workers from blocking Gateway shutdown - #170493
Conversation
Give accepted transcript reconciliation a five-second close grace, then cancel publication and native tasks through their existing owners. Keep handler settlement and independent lease recovery ahead of agent database retirement. Covers a withheld final acknowledgement without losing committed transcript bytes.
…ile-pool-close-bounded
…ile-pool-close-bounded
Abort queued admission before worker dispatch while preserving native task settlement and independent lease recovery. Forward cancellation through first-creation admission and cover delayed dispatch with a deterministic regression.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR cancels stalled transcript reconciliation after a five-second shutdown grace while retaining native-exit and database-lease cleanup barriers. Example: A three-agent Gateway receives SIGTERM while a transcript planner acknowledgement is withheld.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this PR fixes a shutdown stall still present on current main, preserves native and lease settlement, and has no actionable review findings; exact-head CI remains in progress. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherTranscript reconciliation rebuilds derived indexes from stored session history; Gateway shutdown closes its shared worker pool before retiring agent databases. flowchart TD
A[Gateway shutdown] --> B[Reconcile pool]
B --> C[Five second grace]
C --> D[Cancel operations and tasks]
D --> E[Join native exit and accepted writes]
E --> F[Recover database leases]
F --> G[Close agent databases]
Technical reviewBest possible solution: Land lifecycle-owned shutdown cancellation while preserving accepted writes, native exit, independent lease recovery, and restart rediscovery of unfinished indexes. Do we have a high-confidence way to reproduce the issue? Current source establishes the unbounded wait and later database revocation, while the supplied Gateway comparison reproduces the withheld-acknowledgement stall against matching pool code. Is this the best way to solve the issue? The fix belongs in the existing reconciliation owner and correctly separates cancellation before dispatch from native and lease settlement after dispatch. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8e0d08ad52a0. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +39, Tests +62, Docs +7. Total +108 across 3 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 12, 2026, 9:33 PM ET / October 13, 2026, 01:33 UTC. |
|
Merged via squash.
|
openclaw#170493) * fix: stop stalled transcript reconciliation during shutdown Give accepted transcript reconciliation a five-second close grace, then cancel publication and native tasks through their existing owners. Keep handler settlement and independent lease recovery ahead of agent database retirement. Covers a withheld final acknowledgement without losing committed transcript bytes. * fix: cancel transcript admission waits during shutdown Abort queued admission before worker dispatch while preserving native task settlement and independent lease recovery. Forward cancellation through first-creation admission and cover delayed dispatch with a deterministic regression.
#170493) * fix: stop stalled transcript reconciliation during shutdown Give accepted transcript reconciliation a five-second close grace, then cancel publication and native tasks through their existing owners. Keep handler settlement and independent lease recovery ahead of agent database retirement. Covers a withheld final acknowledgement without losing committed transcript bytes. * fix: cancel transcript admission waits during shutdown Abort queued admission before worker dispatch while preserving native task settlement and independent lease recovery. Forward cancellation through first-creation admission and cover delayed dispatch with a deterministic regression. Backport note: the release line still uses the ReconcileAdmission permit queue instead of main's SQLite database admission turn, so the grace timer cancels queued work by aborting operation controllers (the existing permit waiters already cancel on that signal) rather than racing runWithSqliteDatabaseAdmissionTurn. Admission permits, generation bumps, and the waiter-inclusive pendingTasks snapshot are unchanged. The queued-admission regression holds every permit with stalled workers and proves the waiter is cancelled without dispatch. (cherry picked from commit f7e3fef)
openclaw#170493) * fix: stop stalled transcript reconciliation during shutdown Give accepted transcript reconciliation a five-second close grace, then cancel publication and native tasks through their existing owners. Keep handler settlement and independent lease recovery ahead of agent database retirement. Covers a withheld final acknowledgement without losing committed transcript bytes. * fix: cancel transcript admission waits during shutdown Abort queued admission before worker dispatch while preserving native task settlement and independent lease recovery. Forward cancellation through first-creation admission and cover delayed dispatch with a deterministic regression. Backport adaptation: release has no SQLite database admission turn, so only the shutdown grace deadline, task cancellation, and first-creation signal forwarding were ported, without the queued-admission wrapper and its test. (cherry picked from commit f7e3fef)
Co-authored-by: RomneyDa <[email protected]>
Fixes #169777
What Problem This Solves
Fixes Gateway shutdown waiting indefinitely for transcript reconciliation even when the supervised drain reports no active turns.
User Impact
A stalled transcript worker receives a five-second shutdown grace, then cancellation and native termination. Shutdown continues after lease recovery, with a warning naming the worker; committed transcripts remain available after restart. No operator configuration or migration is required.
Why This Change Was Made
The pool previously joined reconciliation owners before requesting cancellation; agent-database revocation happened later in shutdown. A withheld planner acknowledgement could therefore consume the supervisor's entire stop budget. The pool now owns cancellation of both operations and tasks, including admission waits before dispatch. Once a task is dispatched, shutdown still joins its native exit, parent writes, and independent lease recovery before closing databases. The shutdown ordering is preserved.
Evidence
The isolated real-Gateway comparison used three agents, public session/chat RPCs,
gateway.suspend.prepare,gateway.suspend.handoff, and SIGTERM. The forced case injected synthetic transcript entries throughchat.inject, rewound throughsessions.rewind, and withheld the existing planner acknowledgement through a worker preload. Both forced stops reportedactiveCount=0, no blockers, and no write custody.The baseline was
40c523b2c67792c9fb93069b519133590e988d57; its reconcile-pool source is unchanged through the integrated main basef9d5447c5946433d2a3fe63d299de3f93bb19fa9and the later main tipbe49163a5b5fbdf984e0c209f790d5823131f221. The fixed head is2ed0da0f10900793ab0ad7b935dd0df8f5a9f9c2. Total exit times include unrelated SQLite cleanup, so they are not attributed wholly to this change. The baseline observation was censored at 15 seconds; this does not claim a measured 325-second reproduction.The fixed run logged the expired grace and named planner, observed its native exit, dispatched the independent release task, then completed the pool close. Recovery readback passed on the same state: all three original replies survived, and the rewound second turn stayed absent; the recovery Gateway then completed another supervised stop (exit 0, transcript close 0.1 ms).
node scripts/run-vitest.mjs src/config/sessions/session-transcript-reconcile-pool.test.ts --maxWorkers=1: seven native/lease cases passed in the full run. The queued-admission test initially asserted before Node delivered MessagePort close; after an event-loop yield, its focused run passed in 28 ms (224.93 s wrapper wall time including cold compilation). Fresh Testbox full module proof passed: 365 files passed / 1 opt-in benchmark skipped, 3,325 tests passed / 1 skipped, 1,088.85 s command wall time. All eight pool tests passed on that run; the held-admission case took 2 ms, native-exit case 5.001 s, and pool-timeout case 2.292 s.pnpm tsgo:corepassed;pnpm tsgo:core:test --ci-graphs-json '["core-test-agents-sessions"]'passed (19.46 s command wall time). Targeted oxlint, oxfmt, andgit diff --checkpassed. An initial test-type command supplied a shard name where the runner expected a group; the explicit graph command corrected that invocation.tbx_01m4sbnx3g5z3ez9s0fyw1nfxj, run 38329014234: exact source/tree verified. Core types passed in 54.78 s and the session test graph in 55.45 s. The live-only run completed with exit 0 in 203.291 s.Every final remote stop reported
activeCount=0,blockers=[],writeCustody=[], and an armed handoff. The fixed fault log names the stalled task, observes worker 19 exiting, then a separate lease-release task on worker 21 before pool close. Recovery verified all three original replies and absence of the rewound turn.The first remote live attempt requested suspension while
startup:subagent-recoverywas still active and timed out before arming the fault. The final harness waits for the existing startup-recovery completion trace before draining; no production change or guard bypass was involved. An earlier lease expired during local source staging, and an initial source check incorrectly compared the transport-carrier commit with the source commit; subsequent runs verified the full source tree and file hashes using the wrapper's documented source identity.Two earlier local native-exit attempts timed out at 30 seconds; the later traced run passed (21.829 s), showing native exit and independent lease recovery. The earlier failures remain recorded; a passing replay is not treated as a separate fix.
The production LOC exception is +39 (74 added / 35 removed), tests +62 (66 / 4), docs +7 (7 / 0). The added state keeps cancellation separate from native settlement; collapsing those owners would weaken the lease guarantee. No changelog or public protocol/SDK/schema changes.