Skip to content

fix(gateway): drain update notice work before shutdown - #139304

Merged
steipete merged 1 commit into
mainfrom
codex/stable91-update-notice-drain-20260905
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/stable91-update-notice-drain-20260905

Conversation

@steipete

@steipete steipete commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor
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 AsyncWorkScope to 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:

  • Watcher stop resolved while an entered notice was blocked: 1 failed, 5 passed.
  • The existing blocked-send and delayed-after-commit cases drained their owner after the response deadline, before the original operation settled: 2 failed, 13 passed.
  • The startup caller's stop resolved while watcher stop remained pending: 1 targeted failure.

The complete three-file replay passed on Node 24.20.0:

node scripts/run-vitest.mjs \
  src/gateway/update-run-watcher.test.ts \
  src/gateway/server-restart-sentinel-notice.test.ts \
  src/gateway/server-startup-post-attach.test.ts

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 --check passed. 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-safe 0.7.0 differs from required 0.8.1, but their complete timing.js and timing.d.ts were directly inspected and byte-identical. This verifies the specific non-cancelling Promise.race contract, not package-wide equivalence. Installed Undici 8.10.0 also differs from required 8.10.2. The local core typecheck remains failed with four assertBeforeRename option diagnostics at unchanged install-package-dir.ts sites; 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.

@clawsweeper

clawsweeper Bot commented Sep 5, 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 gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Sep 5, 2026
@steipete steipete self-assigned this Sep 5, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 5, 2026, 4:17 PM ET / 20:17 UTC.

ClawSweeper review

What this changes

Gateway 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
Reviewed head: 71853ed26f3c4397f97a32d8368a4b368a472896

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with useful regression coverage, no identified blocking defect, and an explicitly accepted shutdown tradeoff.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate and does not materially change authority. Its reported synthetic-transport tests cover watcher draining and delivery-commit settlement, but are not live cancellation or full process-handoff proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate and does not materially change authority. Its reported synthetic-transport tests cover watcher draining and delivery-commit settlement, but are not live cancellation or full process-handoff proof.
Evidence reviewed 10 items Introduced change and size: The pinned introduction changes only notification ownership, its shutdown caller, and regression coverage: production +27/-23, net +4; tests +97/-9, net +88. The independent stopped flag is removed; FIFO ordering and lifetime ownership remain separate responsibilities.
Canonical lifetime owner: AsyncWorkScope registers work before invoking it, propagates ownership through AsyncLocalStorage, and drains cooperating descendants with allSettled. The watcher enters this existing scope and the notifier registers its original enqueue/send/commit operation before applying the response deadline. This is OpenClaw-owned lifecycle behavior; no Codex runtime or protocol dependency was identified.
Caller and teardown boundary: The update-check stop joins both watcher and discovery cleanup. Gateway lifecycle fencing starts that stop synchronously and awaits it before later channel and shared-resource teardown. Existing close coverage already asserts that update cleanup precedes resource disposal.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

  • Resolve merge risk (P1) - An admitted transport or commit hook that never settles can now indefinitely delay direct embedded server.close(); the PR explicitly accepts this tradeoff, while forced process termination remains outside graceful completion.
  • Resolve merge risk (P2) - Independent inspection of the pinned timeout dependency was unavailable in this review environment; full embedded-close and live transport cancellation behavior also remain unverified.
Agent review details

Security

None.

PR surface

Source +4, Tests +88. Total +92 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 27 23 +4
Tests 3 97 9 +88
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 124 32 +92

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +4; tests net +88 Production growth expresses distinct ordering and lifetime responsibilities while removing the duplicate stopped flag.

Merge-risk options

Maintainer options:

  1. Retain the documented lifetime tradeoff (recommended)
    Keep the joined shutdown contract accepted in the PR body, with cooperative transport cancellation remaining a separate owner-contract improvement.

Technical review

Best 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.

Labels

Label changes:

  • add P2: This repairs a bounded update-notification shutdown race without evidence of a widespread current outage.
  • add merge-risk: 🚨 availability: Joining non-settling notice work can prevent embedded shutdown from completing, an explicitly accepted tradeoff.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate and does not materially change authority. Its reported synthetic-transport tests cover watcher draining and delivery-commit settlement, but are not live cancellation or full process-handoff proof.

Label justifications:

  • P2: This repairs a bounded update-notification shutdown race without evidence of a widespread current outage.
  • merge-risk: 🚨 availability: Joining non-settling notice work can prevent embedded shutdown from completing, an explicitly accepted tradeoff.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate and does not materially change authority. Its reported synthetic-transport tests cover watcher draining and delivery-commit settlement, but are not live cancellation or full process-handoff proof.

Evidence

What I checked:

  • Introduced change and size: The pinned introduction changes only notification ownership, its shutdown caller, and regression coverage: production +27/-23, net +4; tests +97/-9, net +88. The independent stopped flag is removed; FIFO ordering and lifetime ownership remain separate responsibilities. (src/gateway/update-run-watcher.ts:60, 71853ed26f3c)
  • Canonical lifetime owner: AsyncWorkScope registers work before invoking it, propagates ownership through AsyncLocalStorage, and drains cooperating descendants with allSettled. The watcher enters this existing scope and the notifier registers its original enqueue/send/commit operation before applying the response deadline. This is OpenClaw-owned lifecycle behavior; no Codex runtime or protocol dependency was identified. (src/shared/async-work-scope.ts:25, 71853ed26f3c)
  • Caller and teardown boundary: The update-check stop joins both watcher and discovery cleanup. Gateway lifecycle fencing starts that stop synchronously and awaits it before later channel and shared-resource teardown. Existing close coverage already asserts that update cleanup precedes resource disposal. (src/gateway/server-startup-post-attach.ts:1105, 71853ed26f3c)
  • Regression coverage: Inspected tests cover a blocked entered notice, retirement of queued notices, retained delivery ownership after ten seconds, retained after-commit work, and the startup caller awaiting watcher stop. Existing cases cover duplicate suppression, durable queue custody, failure recovery, restart admission, and the 45-attempt budget. Tests were inspected, not executed during this read-only review. (src/gateway/server-restart-sentinel-notice.test.ts:258, 71853ed26f3c)
  • Current-main necessity: At fetched main, the watcher still returns a synchronous stop without joining notices, and the lifecycle notifier still leaves its original operation outside explicit scope tracking. Comparison of the three production paths shows the proposed repair remains absent. (src/gateway/update-run-watcher.ts:98, 979a200bcf6a)
  • Latest-release behavior: The supplied latest release also contains the synchronous watcher stop and does not join entered notifications. (src/gateway/update-run-watcher.ts:98, 3928bad9badf)

Likely related people:

  • Peter Steinberger: Raw commit 0d830e9 adds src/shared/async-work-scope.ts:12 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0d830e9e7448; files: src/shared/async-work-scope.ts)

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.

@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Review-risk disposition

  1. Embedded close lifetime: retain the explicitly documented joined lifetime contract, as selected in the PR body. Entered work keeps its resources until settlement. Direct embedded callers do not gain a bounded-close guarantee; CLI and managed-process hard-stop deadlines remain unchanged. Cooperative cancellation is a separate owner-contract improvement, not an unowned timeout around this join.

  2. Dependency and full-close evidence: The complete timeout implementation and declarations were inspected directly from the pinned fs-safe 0.8.1 tarball. dist/timing.js SHA-256 is 6cecab79fcb6f64483eecfa21dcc674f9d00ab5fe7609f69f4cc64edb6a04b15; declarations are 8854ba28ab930449b5b660766ba7ca5abf20f93fd89a7cde692e7c55622d0f07. The deadline races the operation and clears its timer; it does not cancel or join the original operation. These exact bytes were also supplied to the separate completed three-packet independent review. This is a narrow timeout-contract verification, not package-wide equivalence.

Additional embedded Gateway proof now passes on unchanged head 71853ed26f3c4397f97a32d8368a4b368a472896: the existing Gateway fixture boots the public server, completes a real WebSocket hello and health RPC, then activates a synthetic outbound adapter through the supported registry helper. The actual watcher/notice/durable queue and public close stay real. No fake timers were used.

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: b74b87898f3b469545082fd16c358b6dcbad9b325546672fb9573b35c7e31698.

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.

@steipete
steipete merged commit feda396 into main Sep 5, 2026
191 checks passed
@steipete
steipete deleted the codex/stable91-update-notice-drain-20260905 branch September 5, 2026 21:28
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant