Skip to content

chore: identify slow database shutdown owners - #197382

Merged
steipete merged 5 commits into
mainfrom
steipete/perf-micro-agent-db-close-5s-shutdown-wait-20260919
Nov 11, 2026
Merged

steipete merged 5 commits into
mainfrom
steipete/perf-micro-agent-db-close-5s-shutdown-wait-20260919

Conversation

@steipete

@steipete steipete commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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:changed found 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 82ff38906a08a82900c277c155c304ccd1501e98 as 32c839b6f0b55257ad0cb5fd8425ba1df814d3d6, 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.

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.
@clawsweeper

clawsweeper Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes scripts Repository scripts size: M labels Nov 11, 2026
@steipete
steipete marked this pull request as ready for review November 11, 2026 21:03
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T21:45:14.467521Z 82ff389 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Please review final head 4f00c8a87167ed2b4cd8ab9c7439d9e490b3d8cb. The first CI head's watchdog-test string typing failure is reproduced and fixed; the affected config-cli type graph and independent Codex review pass. Production diagnostics are unchanged. There is no ClawSweeper findings review on this PR yet; landing will wait for a final-head review with zero open items.

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 11, 2026
@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Adds slow database-close phase timings, bounded exit-handle details, and richer synthetic shutdown tracing.

Example: The main agent database takes 500 ms to close.

  • Before: The clean-close receipt reports its outcome without phase durations.
  • After: The receipt includes totalMs=500, walStopMs=295, checkpointMs=120, nativeCloseMs=60, and leaseReleaseMs=25.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused instrumentation with no actionable defect; confidence in exercised behavior rests on reported harness results rather than shipped-entry-point evidence.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied results cover native SQLite storage harnesses and real TLS/child subprocess fixtures, while production handoff attribution is explicitly unclaimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Operators cannot attribute slow database shutdowns or identify lingering endpoints from the existing receipt and handle-type summaries.
Reason: The maintainer-authored direction supplies bounded attribution through existing owners without speculative transport cleanup or new settings.

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
Reviewed head: 82ff38906a08a82900c277c155c304ccd1501e98

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Reported storage harness and subprocess fixtures do not demonstrate a deployed Gateway emitting the new slow-close diagnostics during a later handoff.
Agent review details

How this fits together

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

Technical review

Best 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

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 70ca834 adds src/state/openclaw-agent-execution-close.ts:40 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 70ca83470faa; files: src/state/openclaw-agent-execution-close.ts)

PR surface

Source +86, Tests +110, Docs +16, Other +181. Total +393 across 15 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 7 95 9 +86
Tests 3 118 8 +110
Docs 1 19 3 +16
Config 0 0 0 0
Generated 0 0 0 0
Other 4 208 27 +181
Total 15 440 47 +393

Preflight source

Source 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

Metric Value Why it matters
Production versus test growth Production +86 net lines; tests +110 net lines The growth covers separate native-receipt and enclosing-drain boundaries, four existing WAL-stop callers, and bounded handle diagnostics; tests protect distinct timing, resource-only, and real-handle contracts.

Labels

Label changes:

No label changes.

Label justifications:

  • P3: This improves operator diagnostics without claiming a shutdown speedup or changing runtime cleanup policy.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-11T21:26:19.742Z sha 4f00c8a :: needs maintainer review before merge. :: none

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.
Reuse the exact fixture and allocation from #197366 (638960b), authored by Peter Steinberger. Join startup completion before retaining the bounded write-admission assertion.
@steipete

Copy link
Copy Markdown
Contributor Author

The previous review on 4f00c8a87167ed2b4cd8ab9c7439d9e490b3d8cb had zero open items. Final head 82ff38906a08a82900c277c155c304ccd1501e98 reuses the existing fixture fix from #197366 (638960b06f2a3ca8687400ea304cb50300d77425), credited in the PR: src/state/openclaw-database-verify.test.ts joins fixture startup before retaining write admission and verification assertions. No production changes since your review. Both affected cases pass locally, the test-line ratchet passes, and independent Codex review is clean.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added the clawsweeper:intake:feature Preliminary submission classification; full source review pending. label Nov 11, 2026
@steipete
steipete merged commit 32c839b into main Nov 11, 2026
144 of 146 checks passed
@steipete
steipete deleted the steipete/perf-micro-agent-db-close-5s-shutdown-wait-20260919 branch November 11, 2026 22:15
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 12, 2026
* 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.
steipete added a commit that referenced this pull request Nov 12, 2026
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.
steipete added a commit that referenced this pull request Nov 12, 2026
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.
steipete added a commit that referenced this pull request Nov 12, 2026
* 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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 13, 2026
…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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 13, 2026
…#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:feature Preliminary submission classification; full source review pending. cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: M 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