Repository navigation
fix(gateway): drain update notice work before shutdown - #139304
Conversation
|
🦞👀 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: blocked before merge. Reviewed September 5, 2026, 4:17 PM ET / 20:17 UTC. ClawSweeper reviewWhat this changesGateway shutdown now waits for entered update notifications and their delivery commits, including work continuing after the notification response timeout. Merge readiness⛔ Blocked before merge - 2 items remain The repair remains necessary on current main. No blocking correctness finding was identified, and the PR explicitly resolves the embedded-close tradeoff in favor of retaining work ownership until settlement. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway watches recorded update progress and sends milestone notifications to the originating conversation. Its shutdown lifecycle must retain channel and storage resources until entered notification work finishes. flowchart TD
A[Recorded update progress] --> B[Update watcher]
B --> C{Shutdown started?}
C -->|Yes| D[Fence queued notices]
C -->|No| E[Deliver milestone notice]
E --> F[Commit delivery outcome]
E --> G[Work scope retains pending operations]
F --> G
G --> H[Shutdown releases resources]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +4, Tests +88. Total +92 across 6 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the existing scope-based ownership repair and accepted embedded-close contract; the four added production lines separate FIFO ordering from lifetime tracking without adding another queue. Do we have a high-confidence way to reproduce the issue? Yes, source establishes that stopping the current-main watcher does not await an entered notice; the PR supplies focused failing-before/passing-after cases. This reviewer did not execute them. Is this the best way to solve the issue? Yes for the bounded ownership repair: reusing the shared work scope covers both notifier calls and their continuing operations; merely awaiting the timeout-wrapped FIFO would still release ownership early. Independent timeout-library verification remains a reviewer limitation. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 979a200bcf6a. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Review-risk disposition
Additional embedded Gateway proof now passes on unchanged head Observed sequence: one send enters; the real ten-second notice response expires while the queue remains pending; public close fences the watcher but waits; releasing transport completes the queue while a held after-commit hook still keeps close pending; releasing that hook completes close normally. Exactly one send occurred and the emergency release did not fire. The final scenario passed 1/1 in 33.312 seconds (116.41 seconds including import/worker preparation), with normal worker cleanup and unchanged source/index. Journal SHA-256: This local scenario used Node 24.20.0 and the disclosed installed dependency graph (fs-safe 0.7.0, with the verified identical timeout contract; Undici 8.10.0). It is controlled synthetic transport through a real Gateway, not live external-provider cancellation or host force-kill proof. Earlier fixture attempts failed before this complete flow and remain recorded as failures. Exact-head hosted CI remains green as recorded in the PR body. The remaining external-cancellation/force-kill cases are explicitly deferred, not asserted as verified or silently treated as passing. |
|
Merged via squash.
|
(cherry picked from commit feda396)
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.
What Problem This Solves
Resolves a problem where Gateway shutdown could finish stopping the update-notification owner while an activation or final update notice was still being delivered or committing its delivery record. Later teardown could then overlap work that shutdown treated as finished, including when the notice had already reached its ten-second response deadline.
Why This Change Was Made
The watcher now uses the existing
AsyncWorkScopeto retain its FIFO work and join entered notices during shutdown, replacing its separate stopped flag; the update-check shutdown caller joins that owner too. The lifecycle notifier tracks the original enqueue/send/commit operation before applying the unchanged response timeout, so a timed-out response no longer releases ownership of still-running work.User Impact
Gateway shutdown now waits for entered update-notice work and its cooperating delivery/commit work instead of treating polling cancellation or a response timeout as completion. Queued notices that have not entered remain fenced during shutdown. Notice content, duplicate suppression, retry limits, configuration, and stored representations are unchanged; this does not guarantee delivery through a forced process termination.
Evidence
Candidate:
71853ed26f3c4397f97a32d8368a4b368a472896.Four failures were captured before the production repair in existing suites:
The complete three-file replay passed on Node 24.20.0:
137 passed in 3 files; 14.95 seconds including the repository wrapper. Only a clarifying production comment changed afterward. The tests exercise synthetic transport with real SQLite delivery-queue custody, delayed send/commit settlement, duplicate suppression, restart admission, failure/recovery behavior, the existing 45-attempt budget, and startup/stop fences. They are not a live external-channel or full process-handoff test.
Focused lint, six-file formatting, and
git diff --checkpassed. Independent scoped review completed all three packets with no accepted/actionable P0–P2 findings; it was static review, not additional runtime proof.Ownership and size: production +27/−23, net +4; tests +97/−9, net +88. The remaining growth expresses two distinct requirements: FIFO orders notifier calls, while the scope owns their lifetime and underlying work beyond the response deadline. Removing the duplicate stopped flag and using the existing scope avoids another queue/registry. FIFO does not establish strict platform-send ordering after a timeout.
Dependency and tooling limits: installed
@openclaw/fs-safe0.7.0 differs from required 0.8.1, but their completetiming.jsandtiming.d.tswere directly inspected and byte-identical. This verifies the specific non-cancellingPromise.racecontract, not package-wide equivalence. Installed Undici 8.10.0 also differs from required 8.10.2. The local core typecheck remains failed with fourassertBeforeRenameoption diagnostics at unchangedinstall-package-dir.tssites; the full changed-file gate was only classified by dry-run, not passed. Exact-head hosted CI 33986006909 subsequently passed: 107 successful jobs and 17 skipped. The final PR-wide rollup had 131 successful, 45 skipped and one neutral check, with none unfinished or failed. Native prepare verified those gates against the unchanged head; the local dependency qualifications above remain.Shutdown limits: the scope abort signal is not currently forwarded into this notice's preparation/send path. Direct embedded
server.close()can therefore wait indefinitely for a never-settling admitted transport or commit hook. Existing CLI hard-stop and managed-update parent deadlines remain intact, but forced termination is not graceful completion. Source review found no demonstrated bundled-transport cycle that requires the later channel teardown to release this work; full embedded-close, native handoff, and live-provider cancellation remain unverified.Embedded-close decision
Retain the joined lifetime contract in this repair. This resolves the review's requested tradeoff: an admitted notice still owns delivery/state resources until its original operation and commit hooks settle. Ending that ownership at the response timeout would reintroduce the reproduced teardown race. The existing CLI watchdog and managed-update parent deadline remain the outer process bounds; direct embedded callers do not gain a bounded-close guarantee.
Cooperative cancellation across transport preparation, adapters and commit hooks is a separate owner-contract improvement, not a timeout added around this join. No bundled teardown-dependent cycle was established in the source challenge. This choice deliberately preserves resource-lifetime correctness and does not claim live cancellation or graceful completion for permanently non-cooperating work.