Repository navigation
chore: identify slow database shutdown owners - #197382
Conversation
Extend the existing synthetic small-WAL measurement with retained readers and the storage owner shutdown order. Trace WAL stop, resource close, native checkpoint, lease transactions, and worker retirement across isolates. Preserve synthetic path confinement and native-close, lease, and seal assertions. No production behavior change.
Keep native receipt publication in place and correlate slow resource completion after worker cleanup. Add bounded endpoint details to the existing settled-exit watchdog. No durability, timeout, schema, configuration or shutdown ordering changes. Allocate 108 regression lines for native close phase thresholds, resource-only joins, and bounded real watchdog handles in existing fixtures.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@clawsweeper re-review Please review final head |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesAdds slow database-close phase timings, bounded exit-handle details, and richer synthetic shutdown tracing. Example: The main agent database takes 500 ms to close.
Review scores
ProductKind: Feature · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this maintainer-authored diagnostic PR open: it adds useful shutdown attribution, preserves existing cleanup contracts, and has no actionable review findings; exact-head CI remains pending. Priority: P3 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway and CLI shutdown drain database resources, join native executors, close database handles, and release leases; the existing logger and exit watchdog expose the resulting diagnostic information. flowchart TD
A[Shutdown request] --> B[Database resource drain]
B --> C[Native executor join]
C --> D[WAL stop and native close]
D --> E[Lease receipt and phase timings]
B --> F[Drain completion diagnostic]
A --> G[Settled exit handle diagnostic]
Technical reviewBest possible solution: Keep timing capture with the existing native and resource-drain owners while preserving receipt publication, cleanup ordering, and exit policy. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the missing phase and handle attribution; the underlying multi-second production delay remains unproven, and this read-only review ran no target code. Is this the best way to solve the issue? The smallest complete diagnostic change instruments the existing owners and keeps native receipt publication separate from subsequent worker cleanup; the added tests cover distinct observable failures. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against cfb40ec803b2. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +86, Tests +110, Docs +16, Other +181. Total +393 across 15 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. 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 HistoryReview history (1 earlier review cycle)
Reviewed November 11, 2026, 4:48 PM ET / 21:48 UTC (Revision 2). |
The fixture owns preparation and holds background verification. Join its completion directly while retaining the writable-admission assertion, rather than imposing the production caller deadline on this owner-boundary test. Production timeouts remain unchanged.
|
The previous review on @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
* test(perf): trace agent database close with worker leases Extend the existing synthetic small-WAL measurement with retained readers and the storage owner shutdown order. Trace WAL stop, resource close, native checkpoint, lease transactions, and worker retirement across isolates. Preserve synthetic path confinement and native-close, lease, and seal assertions. No production behavior change. * chore: identify slow agent database shutdown phases Keep native receipt publication in place and correlate slow resource completion after worker cleanup. Add bounded endpoint details to the existing settled-exit watchdog. No durability, timeout, schema, configuration or shutdown ordering changes. Allocate 108 regression lines for native close phase thresholds, resource-only joins, and bounded real watchdog handles in existing fixtures. * test: typecheck settled-exit diagnostic parsing * test(state): join startup preparation in verification fixture The fixture owns preparation and holds background verification. Join its completion directly while retaining the writable-admission assertion, rather than imposing the production caller deadline on this owner-boundary test. Production timeouts remain unchanged. * test(state): reuse startup verification readiness fix Reuse the exact fixture and allocation from openclaw#197366 (638960b), authored by Peter Steinberger. Join startup completion before retaining the bounded write-admission assertion.
Terminate the inbox WebSocket and join its close event so a relay that withholds the close reply cannot retain TLS and the ws close timer after account shutdown. Preserve serialized inbox handling and cursor writes. Generic Gateway shutdown already awaits account teardown. Related: #197382.
Keep the precomputed help path free of TLS initialization introduced by #197382. Acquire the same constructor synchronously inside the existing watchdog callback; preserve its diagnostics, timer, finalization and exit behavior.
* test(gateway): run boot lifecycle before cleanup signal proof Match the real CLI child startup before exercising retained cleanup custody. Preserve the documented one-second signal settlement policy and original deadlines; remove parent-only database seeding and the temporary diagnostics that identified the missing setup. * fix(cli): load TLS diagnostics only when the exit watchdog fires Keep the precomputed help path free of TLS initialization introduced by #197382. Acquire the same constructor synchronously inside the existing watchdog callback; preserve its diagnostics, timer, finalization and exit behavior.
…197717) Terminate the inbox WebSocket and join its close event so a relay that withholds the close reply cannot retain TLS and the ws close timer after account shutdown. Preserve serialized inbox handling and cursor writes. Generic Gateway shutdown already awaits account teardown. Related: openclaw#197382.
…#197936) * test(gateway): run boot lifecycle before cleanup signal proof Match the real CLI child startup before exercising retained cleanup custody. Preserve the documented one-second signal settlement policy and original deadlines; remove parent-only database seeding and the temporary diagnostics that identified the missing setup. * fix(cli): load TLS diagnostics only when the exit watchdog fires Keep the precomputed help path free of TLS initialization introduced by openclaw#197382. Acquire the same constructor synchronously inside the existing watchdog callback; preserve its diagnostics, timer, finalization and exit behavior.
What Problem This Solves
Repeated multi-second agent-database shutdowns cannot be attributed from the current close receipts and exit-handle census.
User Impact
Operators can identify which database-close phase is slow and which endpoint remains alive after clean shutdown. This is diagnostic only; it does not claim to fix the observed delay or change deadlines, cleanup order, checkpoints, receipts, durability, configuration, or schema.
Production proof must come from the handoff after deployment carrying this change: the outgoing release runs shutdown.
Why This Change Was Made
Native closes of at least 500 ms append WAL-maintenance stop, checkpoint, native-close and lease-release durations to their existing receipt. One slow completion line per database drain on the same logger captures resource join, native executor join and remaining native-owner work, including resource-only closes. Agent ID, thread ID and a short captured-path hash correlate the lines without printing database paths. Executor join includes the native phases and subsequent shared-state cleanup, so these measurements overlap.
The committed native receipt precedes worker cleanup and exit. Preserving that publication boundary requires a separate enclosing completion line; moving the receipt would change the lifecycle being diagnosed. Net production growth is 86 lines, above the 30-line target, to cover those separate owners, the four existing WAL-stop callers, and bounded exit-handle details. No new logger channel, cache, filesystem scan or setting is introduced.
The existing exit watchdog adds details for at most eight handles: stdout/stderr identity, TLS servername/remote address, and child argv[0] without arguments. Strings are bounded and JSON escaped. A TLS socket plus two pipe resources does not identify a child or client owner, so this PR does not close a speculative transport.
The small-WAL measurement harness now retains worker leases and history readers when storage shutdown begins, and traces WAL joins and worker retirement. It exercises the storage owner, not a full Gateway.
Evidence
Existing fixtures cover the 499/500 ms boundary and all native phases, resource-only executor joins, and bounded details from real TLS/child subprocess handles. The new 500 ms receipt assertion and watchdog-detail assertion fail against the pre-change production owners. Focused database/resource/close-wedge coverage: 53 passing cases; watchdog coverage: 12 passing cases; final receipt suite: 16 passing cases.
Previously completed synthetic btrfs proof: 35.18 GiB database, 10,800 sessions, 212,888 events, 31.32 MiB WAL, about 62k workspace files. Five counterbalanced pairs: exact prior release median close 158.6 ms versus existing upstream reference 155.5 ms; process CPU 97.467/96.946 ms; sampled main-isolate JS allocation 2,635,816/2,294,888 bytes. Initial unchanged A/A controls were 571.9/178.7 ms; warmed samples were 140–170 ms. These are negative attribution results, not a claimed optimization.
No >=1 s WAL stop join in 16 retained large-fixture spans; maximum 3.760 ms. Pinned-reader controls returned in 103.5/37.4 ms and preserved the seal/lease contract. The production delay remains unproven.
Updated-harness smoke: 109.4/93.2 ms close, 2.429/2.249 ms WAL join, zero remaining leases and valid seals. Small macOS fixture verifies instrumentation only.
The separate 108-line regression allocation covers threshold/phase accuracy, resource-only drains, and bounded real watchdog handles within existing fixtures.
Full
pnpm check:changedfound only new test typing and two lint issues; all were corrected and the affected type/lint checks passed. Other repository guards passed, including schema, worker ownership, dead exports and import cycles. Independent Codex review through P2 is clean. Final close-failure/receipt proof: 26 cases passed.Local wall time: receipt suite 37.99 s including cold compilation (16 cases); existing watchdog suite 40.08 s (12 cases). The watchdog extends an existing real-process exit contract with TLS/child handles rather than adding sleeps or a new process suite. Final exact-head CI run 43105473564 passed. ClawSweeper reviewed the final head with zero findings and zero open items. Native scripts/pr landed
82ff38906a08a82900c277c155c304ccd1501e98as32c839b6f0b55257ad0cb5fd8425ba1df814d3d6, with no inherited-red exception.CI exposed a timing-sensitive startup-verification fixture that waited through the one-second request admission deadline. Reuses the exact fixture repair and two-line allocation from #197366, commit
638960b06f2a3ca8687400ea304cb50300d77425, by Peter Steinberger: join startup completion before preserving the write-admission call and integrity assertions. Peer red/green evidence is reused; the integrated two affected cases pass. Total test allocation is 110 lines. No production timeout changes or inherited-red waiver.