Repository navigation
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. What this changesThis PR drains dependent readers before writers close and moves full integrity verification behind bounded startup admission for current-schema agent databases. Example: Restarting an agent with a 9.82 GiB database and a 12,392-byte committed WAL.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 1 item remains Keep this PR open: it addresses substantial restart delays and a clean-close ordering defect, with no definite introduced bug found in the pinned diff. Priority: P2 Before merge
FindingsNone. Tests
Agent review detailsHow this fits togetherGateway startup inspects agent databases, prepares their native execution owners, and publishes readiness; background verification then supplies completed integrity receipts or revokes admission and records quarantine. flowchart TD
A[Gateway startup] --> B[Schema and ownership inspection]
B --> C[Bounded native admission]
C --> D[Agent reads and writes]
C --> E[Background integrity child]
E --> F[Verification receipt]
E --> G[Admission revocation and quarantine]
F --> H[Clean close seal]
Technical reviewBest possible solution: Retain the existing startup, execution, quarantine, and ordered-drain owners, and complete candidate Gateway and upgrade validation before landing. Do we have a high-confidence way to reproduce the issue? Source traces the foreground full-scan and premature idle-close paths, and the body records native-owner measurements plus a base-failing clean-close regression; no target code was executed during this read-only review. Is this the best way to solve the issue? The implementation separates provisional admission from completed verification while reusing established owners; its added lifecycle machinery serves cancellation, revocation, persistence, and seal eligibility rather than introducing a competing validator. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b6b8ee32b33e. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +465, Tests +251, Docs +36, Other +303. Total +1055 across 27 files. Added test files: 0. View PR surface stats
LabelsLabel changes:
Label justifications:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
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 Reviewed October 30, 2026, 11:31 AM ET / 15:31 UTC. |
e34d51d to
f7e1032
Compare
Codex Review SummaryThis 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. |
f7e1032 to
43c8a06
Compare
|
Production startup observation for the existing proportionate-inspection lane: Team build A separate, directly attributed main-thread stall consumed 201,391 ms: The preceding stop also logged a hard-exit watchdog kill after the shutdown deadline with |
b59abb4 to
8d83fc1
Compare
Drain dependent readers before the final writer so graceful shutdown can preserve its clean-close seal. This addresses a residual seal-loss path after #186783. Admit exact current-schema agent databases through SQLite recovery and bounded structural checks, then verify integrity and foreign keys in the background. Only a successful full check permits a seal; proven corruption revokes admission and persists quarantine with Doctor guidance. Keep migration and index-repair gates foreground, and discard verification results after configured database paths change.
Resume existing shutdown idle timers when dependent resources release, preserving clean seals and the pre-sidecar lease handoff. Keep bounded SQLite header facts at their native catalog owner, separate the verifier leaf contract, and retain foreground repair cancellation proof.
8d83fc1 to
4c0be2c
Compare
|
Landing evidence for exact head
Both baseline files ran separately with On the exact PR head, all configured-store discovery tests and the real Linux managed-SIGTERM lease-release/seal proof pass. Independent review is clean; enforced exact-head review and all applicable security checks pass. This PR uses the standing authorization to land with attributed inherited failures; CI remains truthfully recorded as failed. |
…8459) * perf(state): keep agent startup inspection proportionate Drain dependent readers before the final writer so graceful shutdown can preserve its clean-close seal. This addresses a residual seal-loss path after openclaw#186783. Admit exact current-schema agent databases through SQLite recovery and bounded structural checks, then verify integrity and foreign keys in the background. Only a successful full check permits a seal; proven corruption revokes admission and persists quarantine with Doctor guidance. Keep migration and index-repair gates foreground, and discard verification results after configured database paths change. * refactor(state): keep quarantine dispatch behind verification boundary * fix(state): settle deferred writers when readers retire Resume existing shutdown idle timers when dependent resources release, preserving clean seals and the pre-sidecar lease handoff. Keep bounded SQLite header facts at their native catalog owner, separate the verifier leaf contract, and retain foreground repair cancellation proof. * docs(state): distinguish startup admission from crash recovery receipts * fix(state): let resource owners settle before idle writer cleanup * fix(sessions): retire idle readers during shutdown cleanup * test(gateway): keep configured stores in the suite registry * docs(state): align idle retirement with restart marker persistence
Team's r253 update crossing scanned the 65 GiB roboclaw agent database twice after the schema migration had already finished: Doctor's 'Session transcripts' reopen found no clean-close seal and ran a 584 s whole-file quick_check on the main thread; its close was checkpoint-incomplete, so 'Config audit' reopened with no proof and scanned again (~13 min). The Gateway was down throughout. Agent-database opens without a seal now use the bounded structure admission already used at Gateway startup (#188459), keep this process's proof across checkpoint-incomplete closes, and run any required scan in the integrity worker. Bounded admission mints neither a verification timestamp nor a seal, so full verification stays owed and the next Gateway start runs it in the background. A lease-less unclean close now takes this bounded path; closes whose lease survives keep their synchronous full check, and a corrupt page is still rejected. Pre-migration checks are unchanged.
…189247) Team's r253 update crossing scanned the 65 GiB roboclaw agent database twice after the schema migration had already finished: Doctor's 'Session transcripts' reopen found no clean-close seal and ran a 584 s whole-file quick_check on the main thread; its close was checkpoint-incomplete, so 'Config audit' reopened with no proof and scanned again (~13 min). The Gateway was down throughout. Agent-database opens without a seal now use the bounded structure admission already used at Gateway startup (openclaw#188459), keep this process's proof across checkpoint-incomplete closes, and run any required scan in the integrity worker. Bounded admission mints neither a verification timestamp nor a seal, so full verification stays owed and the next Gateway start runs it in the background. A lease-less unclean close now takes this bounded path; closes whose lease survives keep their synchronous full check, and a corrupt page is still rejected. Pre-migration checks are unchanged.
Backport the assertion synchronization from 4464e6f (#188459, Peter Steinberger). Keep the sidecar held until independently retired readers release their leases, preserving the existing shutdown assertions. Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]> (cherry picked from commit c05b7491b912c5b0599c43590c3db1d5666cb9d7)
What Problem This Solves
Large agent databases can leave sessions unavailable for minutes after a restart because writable admission scans the entire database. Graceful shutdown can also lose its clean-close seal when an idle writer closes before a retained reader.
Related: #186783. That fix is already present in both reported affected builds; this addresses residual close ordering and startup scan cost.
User Impact
Exact current-schema agent databases recover through SQLite and bounded structural checks before readiness; full integrity and foreign-key verification continues in a cancellable background child. A matching clean-close seal skips that scan. Existing schema/index repair and migration gates remain foreground.
Integrity policy for maintainer review: ordinary reads and writes may run before the background verdict, so untouched damaged pages can exist during that interval. Proven corruption revokes admission and persists quarantine, makes the agent unavailable in readiness/status, and directs the operator to Doctor. Cancelled or inconclusive verification never supplies a seal. Background-discovered FTS damage also requires Doctor; automatic backed-up FTS repair remains on the foreground repair path. No schema or stored-data format changes.
Why This Change Was Made
Keep dependent readers in the existing ordered drain before the last writer closes. A native SQLite reproduction shows that even an idle read-only connection can strand the WAL after the last writer closes; no active reader transaction is required. The production reader responsible for the reported receipt was not directly observed.
Use the existing startup owner, native execution owner, and quarantine store for the new provisional-admission lifecycle. At most two full scans run at once. Provisional admission publishes no integrity receipt; only a successful full scan supplies this path's full-verification timestamp. The existing ordinary-open crash-recovery QUICK receipt remains distinct.
Runtime production delta is +507 lines (+546/-39); the benchmark adds 302 lines and tests/support add 301 net lines. The growth is required by the delegated integrity policy: provisional admission must remain distinct from completed verification across native workers, the asynchronous scan needs bounded/cancellable ownership, and corruption must remain durably refused after its agent writer is retired. It reuses the existing integrity worker and quarantine database rather than adding a second validator or a new store.
Evidence
Synthetic fixture: 10,000 sessions, 9.82 GiB initially (9.87 GiB after ordinary Gateway usage-projection maintenance). Fresh-process owner measurements on base
885e57e9f9d1and the candidate patch, with a committed 12,392-byte WAL left by SIGKILL:Clean owner admission reused its seal: 4.53 s base, 1.56 s candidate. Every healthy owner run finished with a valid seal. The improvement is reduced blocking time, not less full-scan work or a CPU/allocation reduction. Native scan CPU and child RSS are excluded from these owner counters; these are single startup observations on a shared Mac, not controlled throughput or tail measurements. End-of-arm 1/5/15-minute host load: base 48.8/56.4/55.5, candidate 33.3/43.9/52.3. Allocation passes use 32 KiB sampling including collected objects.
Built Gateway proof uses the same database and real HTTP readiness plus WebSocket
sessions.list(10 returned, 10,000 total), with isolated loopback ports and state. Base build is885e57e9f9d1; candidate build isf7e1032c80183546431ae61fc7208050b227485a(before the later shutdown refinements below).All four healthy runs acknowledged graceful shutdown, exited 0, and wrote the clean-close seal. The candidate served the session list before its full integrity verdict. RSS is a point observation at different phases of startup, not a peak or retained-memory comparison. These are single shared-host observations, not p99s. Start/end 1/5/15-minute host load: base clean 56.4/61.9/59.4 → 70.4/64.1/60.5; candidate clean 32.7/27.2/28.8 → 39.3/30.1/29.7; base unclean 46.9/51.9/54.2 → 61.2/56.1/55.4; candidate unclean 65.4/41.3/34.0 → 55.9/45.5/36.9. No throughput, tail-latency, GC-rate, or CPU-reduction claim is made.
Two immediate-after-readiness baseline stops exceeded the harness's 120 s deadline while startup usage projection drained; both wrote a database seal. The steady-state clean-stop protocol allows the same 60 s post-readiness settling window in both arms. Physical-corruption proof passed on the built candidate: after damaging the
cache_entriesroot page in the same 9.87 GiB database, the background integrity check reported corruption at 120.42 s, HTTP readiness returned 503, and a real WebSocketsessions.createwas refused withUNAVAILABLE. The Gateway acknowledged shutdown and exited 0 in 339 ms, with no clean-close seal. Native integration tests separately prove the durable quarantine refusal across reopening.Focused proof: the clean-close regression fails on the base and passes with the fix; integrity/quarantine, native execution/restart recovery, reader-resource, and startup-index tests pass. All 26 Gateway preparation tests pass, including two regressions that first reproduced stale config-change quarantine. Import-closure checks found one missing wrapper inventory path; it is fixed and the affected six checks pass (remaining closure checks had already passed). Changed-file lint, format, export-name collision checks, and the core typecheck pass. No schema or budget/baseline changes.
This startup admission policy is not a turn-processing hot-path optimization. The lane's FAST PATH exception applies; no multi-pair ten-minute load campaign was run. No live service or production database was touched.
Independent subagent review (autoreview route unavailable): no actionable findings. The configured helper rejected the selected provider route before starting; operator configuration was not changed.
The initial candidate runtime build passed on
f7e1032c80183546431ae61fc7208050b227485a, which is also the built-Gateway measurement head above. Build preparation first exposed stale installed dependencies after rebasing (resolved by the frozen install), then a strict import-boundary warning introduced here (fixed by keeping quarantine dispatch in the existing lazy verification module).CI found and this PR repaired import cycles, a test connection-type mismatch, native-header query ownership, and an early-shutdown lease handoff regression. Resource retirement now notifies the writable lifecycle through a registered callback, keeping the resource registry independent of its caller. The existing idle timer closes the deferred writer after readers and workers settle. It never starts path-wide revocation: a new native-worker regression first failed against that discarded approach, then passed with the final passive callback while committing accepted writes during shutdown. The portable seal test requires reader retirement itself to close/seal the writer without global drainage. The managed-shutdown test still requires zero leases while an independent sidecar remains held, with a bounded wait for asynchronous retirement. A startup cancellation fixture now requires an actual missing-index repair, preserving foreground integrity-child cancellation and exact database bytes under the new policy. No budgets were raised.
The next Linux CI pass exposed the remaining reader owner: an idle session-history pool retained its database through its normal 90-second/five-minute warm deadline. The exact managed-SIGTERM scenario reproduced the same held lease locally. Reader pools now use their existing idle retirement operation when shutdown cleanup starts; pending reads retain custody and retire only after settlement. A portable idle-versus-busy regression was red before this change and green afterward. The managed scenario then released all agent leases while its independent sidecar remained held, completed shutdown, and wrote a valid clean-close seal. Its Linux-only selection was temporarily removed only for local reproduction and restored before committing. Three setup failures shared one intentionally isolated resource-registry mock; adding the new callback-registration export repaired all three consumers without importing real lifecycle state.
Final reader repair validation: 57 tests passed across the three reader/usage consumers and native worker-store file, including the accepted-native-write regression. The original managed scenario passed locally; focused lint, format, runtime-cycle and Madge-cycle guards pass. The previously recorded typecheck, closure, and integrity results below remain supporting evidence. CI is the final Linux and broad validation.
Earlier repair validation: 47 focused shutdown/native-worker tests passed with one Linux-only skip; 27 import-sensitive Bun tests passed with one Linux-only skip, and 20 worker-consumer Bun tests passed. Both runtime and Madge cycle checks report zero cycles; focused lint, the persisted-catalog closure check, and export-name guard pass. Earlier repair validation also passed the failed state-test typecheck leaf, database dialect ratchet, startup shutdown-preparation case, and 55 native execution/integrity tests (one Linux-only skip).
The eight-commit stack is based on main
83064b3ae115, including #188462's provider-refusal notice fix, #188409's separate Linux quick-recovery receipt policy, and the auxiliary quarantine-file identity refresh. Independent integration review confirmed the QUICK/FULL distinction, quarantine ordering, and retained-reader lifetime. Following the earlier quarantine identity-refresh integration on basebd4d2c76a583, all 28 quarantine and database-verification tests passed. Final head is4c0be2cb9b0dbdb39a32abcef756971f20c0b584; exact-head CI results and inherited failures are recorded below. The multi-GiB built-Gateway measurements above predate the final shutdown refinements, which are covered by native owner/Gateway tests.A later CI failure exposed a fixture overlap in
server.sessions.store-paths.test.ts: the configured-store case rebound the process state root beneath the suite Gateway. Five ordinary fresh-process runs on each of the pinned base and candidate did not reproduce it, so passing replays were not used to dismiss the failure. A temporary controlled interleaving selected the real suite registry after the real case-registry read, reproducing the exact registry-witness failure on base8f1ef6c97eff. Removing only the state-root override passed the same interleaving, and the final uninstrumented file passed all five tests. Absolute configured stores, parent-child lineage, exact returned keys, and the no-directory-discovery assertion are unchanged; no diagnostic hook remains.Final integration also includes main's #188402 marker-before-cleanup boundary and #188496 snapshot/shared-state retirement ordering. All 28 native-idle/worker-store tests and the now-portable managed-SIGTERM scenario pass with the marker boundary; independent source review confirms the later shared-state ordering preserves asynchronous quarantine and accepted native writes. On the preceding head, Linux CI passed all four agent-database shutdown cases, including the managed lease-release and written-seal proof. On exact final head
4c0be2cb9b0d, all 28 quarantine and database-verification tests pass with the new shared-state close ordering. Exact-final-head Linux CI passed all five configured-store discovery cases and the actual managed-SIGTERM lease-release/seal case, together with the agent-database shutdown siblings.Known baseline evidence:
doctor-usage-cost-cache.test.ts/ unreadable temp entry reports two warnings instead of one on both the prior candidate and unchanged mainba6cfcd58df47a3037507362e45ed95757fae41c(main job). This is inherited evidence, not a passing result. A focused auth-product replay passed its original CI timeout case, then hit a different retryable catalog-generation-superseded error in the second case; that observation remains investigated but unclassified, and a passing replay alone is not claimed as a fix.Final exact-head CI attribution (
4c0be2cb9b0dbdb39a32abcef756971f20c0b584, run 41101511557): three jobs failed, all with unchanged-base evidence. The Doctor warning-count failure matches the main job linked above. The other two files were run individually on unchanged base83064b3ae1155f0c6c96081c863e7db4bd4451f4usingOPENCLAW_VITEST_RUNTIME=bun node scripts/run-vitest.mjs <file> --maxWorkers=1:src/gateway/server-close.auth-usage.test.ts: 2 failed, 1 passed on both candidate and base. The failures expect an owner-closed error instead of the scheduler abort error, and expect the provider signal already aborted at the earlier request-admission boundary. Upstream fix: resume running channel threads after graceful restarts #188402 moved auth/model-account cleanup after restart-marker persistence; these unchanged tests still observe the earlier phase.src/auto-reply/reply/reply-turn-admission.worker.test.ts: the same 4 full-idle-cache variants fail at line 440 on CI and base (base: 4 failed, 3 passed). The fixture signals restart drain without starting shutdown cleanup; fix: resume running channel threads after graceful restarts #188402 intentionally retains idle executors until that later cleanup signal, leaving one lease. The predecessor/successor settlement assertions pass. The owner, worker store, admission implementation, and test are unchanged by this PR.These are recorded failures, not green replays. No CI rerun, budget increase, or unrelated source repair was used to obtain a passing result. The configured-store and actual Linux managed-shutdown cases pass on this exact head. Enforced exact-head review, dependency review, security-sensitive review, security-fast, all six Security High checks, and Opengrep pass. All three PostgreSQL conformance shards and the remaining execution jobs completed successfully. Landing uses the explicitly authorized inherited-failure exception for the three attributed jobs above; the CI aggregate remains failed.
Compatibility scope: the built-Gateway proof reopens the existing multi-GiB current-schema fixture, with retained sessions and normal writes. No latest-stable upgrade campaign was run; schema/index repair and migration admission remain on the existing foreground path, and no schema or stored-format change is introduced. The earlier advisory review requested Gateway/corruption proof when those scenarios were still pending; the completed results and this remaining upgrade-proof limit are recorded above.