Skip to content

perf(sessions): keep requests responsive during reclamation commits - #158073

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-mainthread-stalls-reclamation-wait-20260919
Sep 25, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-mainthread-stalls-reclamation-wait-20260919

Conversation

@steipete

@steipete steipete commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Gateway requests stop making progress when a reclamation worker takes a long time to settle its SQLite commit. The parent authorizer opened another SQLite connection and synchronously waited for the worker's writer lock.

User Impact

Unrelated requests keep running during slow reclamation commits. Pending revocation still refuses a commit, and accepted work retains its writer slot and request lifetime until native settlement. No configuration, schema, retention, or update changes are required.

Why This Change Was Made

Check current authority and atomically accept the commit in the existing parent owner, then consume completion through the existing asynchronous result/exit transport. Remove the synchronous probe, its parent-release handshake, and obsolete probe-failure tests. Keep FIFO ordering and post-settlement publication with their existing owners.

Automatic-maintenance conflict backoff from #156583 already applies; its quiet-window/capped-retry regression passes unchanged.

Evidence

Blacksmith Testbox (blacksmith-testbox, profile openclaw-check), lease tbx_01m3byyes7bfgft4j4jxn0g3kz (hydration run), using synthetic SQLite data and the actual commit owner/request bridge. Each measurement holds the worker transaction for 1,500 ms after commit acceptance while serving a loopback HTTP request:

Measurement Original Patched
Event-loop delay maximum 1,655.70 ms 10.39 ms
HTTP RPC latency 1,667.04 ms 7.45 ms
  • node --import tsx reclamation-perf-probe.mts: before/after results above; temporary fixture removed after proof.

  • node scripts/run-vitest.mjs across reclamation commit/admission/reuse/memory, maintenance worker/admission/kick, and cold storage: 114 tests passed in 8 files. This also ran the full runtime build successfully (34.9 s).

  • The new responsiveness regression fails on the original commit owner: queued work cannot run until the worker has committed and released admission. It passes with this change, together with rollback, abrupt exit, pending revocation, accepted-operation drainage, and FIFO checks.

  • pnpm test src/config/sessions/session-accessor.sqlite-reclamation-commit.test.ts --maxWorkers=1: 7 passed, 29.56 s wall including transformation; approximately 2.7 s test execution.

  • pnpm test src/config/sessions/session-accessor.sqlite-reclamation-admission-race.test.ts --maxWorkers=1: 9 passed, 21.34 s wall. These existing lifecycle integration cases retain real SQLite/worker and session-publication coverage.

  • Independent review through P2: no actionable findings.

  • Initial probe setup lacked tsx on the lease; pnpm install --frozen-lockfile repaired that prerequisite. Both subsequent performance probes succeeded; the original-code regression intentionally fails.

  • Additional node scripts/run-vitest.mjs checkpoint, reclamation-maintenance, canonical-validation, request-lifetime, and commit coverage: 38 passed in 6 files, 32.27 s Vitest wall (7 commit cases overlap the earlier batch: 145 distinct tests across 13 files).

  • node scripts/check-changed.mjs: core typechecking, all 25 core-test graphs, and all preceding guards/dead-export scans passed. Final lint caught a missing explicit empty Worker transfer list in the new fixture; fixed it, then reran the exact selected run-oxlint.mjs command and all remaining schema, database, media, runtime-loader, import-cycle, webhook, and pairing guards successfully. A separate attempted --lint-only invocation was rejected as unsupported; it supplied no validation evidence.

  • pnpm check:docs: passed, including 14,611 internal links with zero broken links and config-example/changelog checks.

  • git diff --check: passed. The Testbox lease was stopped after validation. Net production change: 160 fewer lines.

The timing fixture isolates slow commit settlement; it is not a production deployment or proof that every observed stall has this cause. Other legacy synchronous SQLite writers can still contend on native locks. Existing unlabeled deferred-hold logs cannot be conclusively attributed to this immediate-transaction owner.

CI status

Squash auto-merge is enabled for 6e2bc69e89fccedd805980a7049a0f42099798a1. The initial bare merge commands were refused by the local publication guard; supplying the explicit reviewed subject/body and exact-head condition was accepted.

CI run 36123920765 was canceled by fail-fast after the unchanged Windows tooling test test/scripts/direct-run-entrypoints.test.ts → runs the checked-out Crabbox wrapper through its Windows Job child exceeded its 10,000 ms managed-command deadline (failed job). The shard recorded 168 passing tests, one failure, and 12 skips. Core production types, completed test-type stripes, lint, security, and docs checks passed; unfinished test shards were canceled, so full CI and per-file CI timing closeout remain incomplete.

Bounded diagnosis: the 10,514 ms case reached its first fake CLI invocation about 8,739 ms after case start; all four expected invocations then wrote their output within 1,168 ms. This suggests cold source startup consuming the deadline, rather than establishing a shutdown deadlock. The fixture, its managed-process owner, and Crabbox wrapper are unchanged by this PR. Current-main history already contains the cold-compilation, startup-tracing, and output-close ownership changes (#156011, #155905, #147781); no newer owning fix was found. The configured Testbox provider cannot execute this Windows-only native Job case: crabbox warmup --target windows --keep --timing-json refused before provisioning with provider=blacksmith-testbox managed provisioning supports target=linux only. The task requires this provider; AWS or an existing Windows host would be a host-rule exception. No timeout increase, retry-to-green, weakened assertion, or speculative unrelated repair was made.

Accept reclamation commits atomically under current authority and retain writer admission through asynchronous native settlement. Remove the synchronous parent SQLite probe and its release handshake. A 1.5-second worker hold now leaves the event loop responsive; revocation, FIFO, cleanup, and publication remain covered by focused Testbox proof.
@clawsweeper

clawsweeper Bot commented Sep 25, 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 docs Improvements or additions to documentation size: L labels Sep 25, 2026
@steipete
steipete enabled auto-merge (squash) September 25, 2026 10:41
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 25, 2026
@clawsweeper

clawsweeper Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 25, 2026, 6:50 AM ET / 10:50 UTC.

ClawSweeper review

What this changes

The branch replaces the parent’s synchronous SQLite commit probe with an atomic authority check and asynchronous worker settlement for session reclamation, and updates tests and documentation.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main and the latest release still contain the blocking commit probe; this PR addresses that behavior with a focused change and credible production-boundary proof.

Priority: P2
Reviewed head: 6e2bc69e89fccedd805980a7049a0f42099798a1

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Measured production-boundary behavior and focused authority and settlement coverage support a good, reviewable patch.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The changed parent authorization owner and real worker transport were exercised on a Linux Testbox with a delayed SQLite commit and loopback HTTP request: after the change, reported latency was 7.45 ms versus 1,667.04 ms before. Focused real-worker cases also cover pre-acceptance refusal, rollback, native exit, and writer drainage. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed parent authorization owner and real worker transport were exercised on a Linux Testbox with a delayed SQLite commit and loopback HTTP request: after the change, reported latency was 7.45 ms versus 1,667.04 ms before. Focused real-worker cases also cover pre-acceptance refusal, rollback, native exit, and writer drainage. No stored-data contract changes.
Evidence reviewed 8 items Current main retains the stall: The current-main commit owner still opens a second SQLite connection and synchronously joins the worker’s writer lock.
Latest release retains the probe: The latest identified release, v2026.9.6, also contains the synchronous settlement transaction; the proposed change is not already shipped.
Introduced authority change: The PR checks current parent authority and accepts a requested commit with a compare-and-exchange, removing the synchronous SQLite probe.
Findings None None.
Security None None.

How this fits together

Session reclamation archives or deletes session data in a SQLite worker after a Gateway operation requests cleanup. The parent authorizes the commit, retains writer admission through settlement, and then publishes session changes.

flowchart LR
A[Gateway cleanup request] --> B[Session reclamation plan]
B --> C[Worker write admission]
C --> D[SQLite transaction]
D --> E[Parent authority check]
E --> F[Worker settlement]
F --> G[Publish session changes]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -160, Tests -196, Docs +7. Total -349 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 3 18 178 -160
Tests 5 111 307 -196
Docs 2 13 6 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 142 491 -349

Review metrics

None.

Technical review

Best possible solution:

Land the existing owner change through normal merge gates while preserving pending-revocation refusal, FIFO writer custody, and publication after native settlement.

Do we have a high-confidence way to reproduce the issue?

Yes. The reported Testbox comparison held a real worker transaction for 1,500 ms and measured a 1,667.04 ms loopback request on the original owner; current main still contains that owner. This read-only review did not rerun the probe.

Is this the best way to solve the issue?

Yes. Removing the parent’s synchronous lock probe while retaining the existing authorization and worker-result owners is a narrow solution; the changed tests cover refusal and settlement ordering.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4e4b5c5c515b.

Labels

Label changes:

  • add P2: Slow session reclamation can delay unrelated Gateway requests, but the affected path is bounded and the PR supplies a focused repair.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The changed parent authorization owner and real worker transport were exercised on a Linux Testbox with a delayed SQLite commit and loopback HTTP request: after the change, reported latency was 7.45 ms versus 1,667.04 ms before. Focused real-worker cases also cover pre-acceptance refusal, rollback, native exit, and writer drainage. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed parent authorization owner and real worker transport were exercised on a Linux Testbox with a delayed SQLite commit and loopback HTTP request: after the change, reported latency was 7.45 ms versus 1,667.04 ms before. Focused real-worker cases also cover pre-acceptance refusal, rollback, native exit, and writer drainage. No stored-data contract changes.

Label justifications:

  • P2: Slow session reclamation can delay unrelated Gateway requests, but the affected path is bounded and the PR supplies a focused repair.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed parent authorization owner and real worker transport were exercised on a Linux Testbox with a delayed SQLite commit and loopback HTTP request: after the change, reported latency was 7.45 ms versus 1,667.04 ms before. Focused real-worker cases also cover pre-acceptance refusal, rollback, native exit, and writer drainage. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed parent authorization owner and real worker transport were exercised on a Linux Testbox with a delayed SQLite commit and loopback HTTP request: after the change, reported latency was 7.45 ms versus 1,667.04 ms before. Focused real-worker cases also cover pre-acceptance refusal, rollback, native exit, and writer drainage. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • RoboClaw: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 merged commit 8995c29 into main Sep 25, 2026
311 of 370 checks passed
@steipete
steipete deleted the steipete/perf-micro-mainthread-stalls-reclamation-wait-20260919 branch September 25, 2026 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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