Repository navigation
perf(gateway): admit agent databases when the listener binds - #164670
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: needs maintainer review before merge. Reviewed October 4, 2026, 3:09 AM ET / 07:09 UTC (Revision 4). ClawSweeper reviewWhat this changesThe PR begins bounded agent database admission when the Gateway listener binds, restores full integrity checks, and keeps recovered chat metadata refreshes within the Gateway lifetime. Merge readiness✅ Ready for maintainer review This PR remains useful: current main retains the earlier startup arrangement, and neither related PR supersedes this work. No actionable introduced defect was found, and the supplied runtime evidence supports the recovery behavior. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway checks agent databases before allowing session writes and model use. Startup admission connects database ownership and integrity validation to session preparation, readiness, and chat metadata. flowchart TD
A[Existing agent databases] --> B[Compatibility and ownership inspection]
B --> C[Pending admission fence]
D[Gateway listener binds] --> E[Bounded native database admission]
C --> E
E --> F[Full integrity validation]
F --> G[Serialized session and model preparation]
G --> H[Available agents and refreshed metadata]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +32, Tests +234, Docs -1, Other +1. Total +266 across 36 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep one native writable integrity gate, preserve pending-agent fences through preparation, and refresh metadata from its Gateway lifetime owner. Do we have a high-confidence way to reproduce the issue? Yes: the supplied real Gateway before/after trace and source identify duplicate startup validation and delayed metadata publication under an expired preparation scope; this review did not execute a current-main reproduction. Is this the best way to solve the issue? Yes: the patch moves validation to the existing writable owner and binds refresh to its existing lifecycle, with focused negative controls and no competing persistence owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 5f656752e404. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
acd4af6 to
22c1d69
Compare
Move current-schema physical validation from foreground inspection to the existing native writable owner. Start bounded admission independently of subagent restoration while keeping session, secrets, and model publication serialized and authority checked. Retain one full integrity and foreign-key gate for dirty opens and remove partial table-check batching, which cannot detect shared or orphaned pages. Clean receipts retain the existing reuse path; strict canary, migration, and Doctor checks remain unchanged.
Refresh metadata in its Gateway lifecycle context and observe final agent admission. Late model catalog publications can then refresh recovered agents without inheriting an expired preparation borrow. Extend the existing shared-Gateway boundary test to cover deferred admission and late publication while preserving projection and owner-failure behavior.
… for CI Follow-up to the listener-time agent database admission: align the test-instance helper and preflight fixtures with the configured/historical ownership distinction, register the moved module in the PR-wrapper inventory, and keep the full integrity and foreign-key gate.
Move ACP session metadata preparation into the existing session-projection owner and bind refresh directly with AsyncLocalStorage.bind. Preserve the Gateway lifetime context while removing the per-call wrapper and keeping the runtime at the 700-line limit.
22c1d69 to
2c0db98
Compare
…w#164670) * perf(gateway): begin agent database admission when the listener binds Move current-schema physical validation from foreground inspection to the existing native writable owner. Start bounded admission independently of subagent restoration while keeping session, secrets, and model publication serialized and authority checked. Retain one full integrity and foreign-key gate for dirty opens and remove partial table-check batching, which cannot detect shared or orphaned pages. Clean receipts retain the existing reuse path; strict canary, migration, and Doctor checks remain unchanged. * fix(gateway): retain metadata ownership after database admission Refresh metadata in its Gateway lifecycle context and observe final agent admission. Late model catalog publications can then refresh recovered agents without inheriting an expired preparation borrow. Extend the existing shared-Gateway boundary test to cover deferred admission and late publication while preserving projection and owner-failure behavior. * fix(gateway): repair startup admission fixtures and wrapper inventory for CI Follow-up to the listener-time agent database admission: align the test-instance helper and preflight fixtures with the configured/historical ownership distinction, register the moved module in the PR-wrapper inventory, and keep the full integrity and foreign-key gate. * fix(gateway): keep metadata runtime within its line cap Move ACP session metadata preparation into the existing session-projection owner and bind refresh directly with AsyncLocalStorage.bind. Preserve the Gateway lifetime context while removing the per-call wrapper and keeping the runtime at the 700-line limit. * test(gateway): supply settled startup responses in readiness proof
Continue startup recovery when a pending agent database publishes its successful admission. Reuse the existing recovery owner, original startup cutoff, live authority checks, and serialized capacity. Limit subsequent scans to the newly admitted agents while preserving fixed-store ownership. This prevents an orphaned run from blocking new sends after SIGKILL. Keep the original recovery timeout and add coverage for admission during the first scan, after that scan, and after shutdown. Deferred dirty-store admission in #164670 exposed the missing continuation reported in #165225.
Continue startup recovery when a pending agent database publishes its successful admission. Reuse the existing recovery owner, original startup cutoff, live authority checks, and serialized capacity. Limit subsequent scans to the newly admitted agents while preserving fixed-store ownership. This prevents an orphaned run from blocking new sends after SIGKILL. Keep the original recovery timeout and add coverage for admission during the first scan, after that scan, and after shutdown. Deferred dirty-store admission in openclaw#164670 exposed the missing continuation reported in openclaw#165225.
What Problem This Solves
After an unclean restart, agent databases can remain unavailable behind a full startup inspection before their writable owner checks the predecessor's lease. A late model publication can also make chat metadata unavailable after database recovery by retaining the expired preparation context.
User Impact
Current-schema agent databases begin native writable admission when the listener binds, independently of subagent restoration. Requests remain fenced until integrity validation and session/model preparation succeed. Metadata refreshes use the Gateway's lifetime and observe final admission, so recovered agents appear in metadata and model listings.
No configuration, schema, stored-data, update, rollback, or supervisor-budget changes are required. Valid clean-close receipts retain their fast path; migration, canary, Doctor, and artifact-preserving checks remain strict.
Why This Change Was Made
The reported cutover had 91 seconds between readiness and stale-owner detection, followed by a 22.104-second database open. Agent leases check PID/start identity when claimed; they have no expiration timer. The previous startup path could finish a full read-only integrity scan, wait for sidecars, and serialize behind other agents before claiming that lease and validating again.
Runtime inspection now checks compatibility and ownership and transfers physical validation to the existing native writable owner. At most two databases open concurrently; secrets/model publication remains serialized through its final admission commit. Authority, deletion, cancellation, and worker-settlement checks remain in place.
The single writable gate retains full
integrity_checkandforeign_key_check. Partial table checks miss shared and orphaned pages, so their plan, batching, and timing machinery are removed. Clean proof still requires matching physical identity, application version, ownership, schema/indexes, and certified release. Production TypeScript delta: +32 LOC (261 added, 229 removed). The requested exclusion-based count is +75 LOC (308 added, 233 removed), including the shared test-instance helper and one wrapper inventory line. The partial-table planner and duplicate scan are deleted; growth preserves bounded native admission separately from serialized model/secrets publication, Gateway-owned metadata refresh, and configured owner/path eligibility.Evidence
A process-cold Linux rig used identical synthetic dirty snapshots, the real built Gateway, native
chat.injectwrites, a killed real lease owner, and no worker preload. The first usable session result had to contain the complete seeded inventory; an empty successful listing was rejected as availability proof.chat.metadata20 seconds after recoveryUNAVAILABLE, expired preparation scopeThe 512 MiB payload fixture produced a 1,585,381,376-byte main database plus a 67,108,864-byte WAL.
Normalized journal/RPC excerpts from process spawn:
The comparable-load large-state cell improves usable admission by 3.720 seconds / 10.5%. The small-state sample is 0.980 seconds slower; this is not a universal boot-time speedup. Another valid large baseline took 50.479 seconds under higher load and is excluded from the improvement claim. OS caches were not flushed. The rig pins base
74db989c268cand measured the runtime published at9f7dbd92. Later fixture/eligibility repairs and the current-main rebase were not rebenchmarked; these numbers remain evidence for that measured revision.Earlier measured candidate:
9f7dbd928dee44c2fc9407ee8d95f7b729ef856c; its original rebase preserved all 27 reviewed/tested file hashes.Testbox provider
blacksmith-testbox, leasetbx_01m4253ma1srfjptmtc99nap3t:node scripts/run-vitest.mjs <focused files> --maxWorkers=1: 146.28 seconds across four shards. Gateway startup: 12 cases, 103.58 seconds.UNAVAILABLEerror in 22.97 seconds. The fixture retains one Gateway/test lifetime because the global test cleanup retires publication listeners between tests.74db989c268c:node scripts/check-changed.mjs --staged; 27 core test graphs, lint (23 files, zero warnings/errors), dead-code scans, import-cycle and database guards passed. Core test types totaled 2,194.9 seconds; complete gate took about 57 minutes. The earlier Testbox had queued for 66 minutes and disappeared. Metadata increment gate on the lease above passed in 22m48.354s: all 27 typecheck groups, lint (three files, zero warnings/errors), dead-code scans and remaining guards passed.sourcePerformanceruntime build passes. Fresh independent review of the complete combined change is clean through P2.Expected next-cutover journal: an unclean predecessor's
agent database stale lease: owner-pid-dead; previous release not observedshould follow listener bind without waiting for a separate full scan or subagent restoration. Dirty admission reportsintegrityGateMode=full, followed byagent database recovered after background inspection and preparation. A valid receipt should retain cached admission. Verify complete session inventory and metadata/model RPCs after recovery, including delayed publications.This is successor-side evidence. The shutdown rig held three model calls, background exec, a PTY, and real worker leases, but the original code still wrote its receipt and closed agent databases by 46.456 seconds. It did not reproduce the missing predecessor receipt. The independent shutdown partial-close change is separate. The rig does not reproduce the production 91-second interval exactly; the next production cutover remains the acceptance check. No live Gateway or deployer was modified.
Rebase validation (lane 407)
Candidate
2c0db987677fdc9b2ae6f7e7ff700d9fbf267a34: the original three commits and two focused gate/fixture repairs, rebased onto3052e3b93a0ad587589e6dcb2d7f6b44d97a1189. A focused follow-up keeps metadata refresh in its owner context and satisfies the current line-cap gate. The listener-time activation and sidecar preparation barrier remain intact. Main's direct-import simplification, close/canary guards, and independence from subagent restoration are preserved. Main already fixes the outbound fixture's state-root mismatch explicitly, so the obsolete ambient stub and diagnostic-only assertion messages were removed from this PR.The current-main line-cap ratchet rejected the four-line growth in
chat-metadata-runtime.ts(714 → 718 counted lines). Its unchanged ACP session reader now lives in the existing session-projection module, with all three callers using that owner. Lint separately enforced the absolute cap at 703 lines, soAsyncLocalStorage.bindnow owns the refresh context directly, removing the snapshot/per-call wrapper. The runtime meets the 700-line cap; the follow-up is net −2 production lines, with no duplicate helper or baseline exception.Fresh proof uses
blacksmith-testbox, profileopenclaw-check, leasetbx_01m42hj2def4hhxca2m77z3ma0. Testbox's shallow seed initially retained a newer Git HEAD despite syncing source. The exact three-commit candidate was imported through a Git bundle, the complete tracked tree was compared, andpnpm install --frozen-lockfilepassed before any test ran. Source hashes were verified before every proof command.openclaw-node-01, lanelane407-rebase-164670.nohup bash /srv/rig/rig-staged-check.sh lane407-rebase-164670 db01dc3de693569e7cc8a6b1fb8ab2bdbc578c31rannode scripts/check-changed.mjs --stagedwith the full candidate patch. It finished withexit=0, approximately 54 minutes (05:36–06:30 UTC). The full 35-file staged tree was verified before and after as6f39c44036740c729162bac1fe0851881e243814, identical to the tested22c1d69ab1decommit tree.The replacement
blacksmith-testboxleasetbx_01m42ndhnnfeppgjnrb36jhwfxeventually became ready and rerantest/scripts/eager-import-closure.test.tsagainst the final staged tree: 17 tests passed, Vitest 15.65 seconds, wrapper 16.42 seconds, complete remote command including source materialization/install 70.513 seconds.Commands use
node scripts/run-vitest.mjs <focused files> --maxWorkers=1andnode scripts/check-changed.mjs --staged --base db01dc3de693569e7cc8a6b1fb8ab2bdbc578c31. No heavy validation ran on the Mac. The earlier benchmark values above were not remeasured by this rebase, and production cutover acceptance remains outstanding.Focused rerun commands
Negative controls retain candidate tests and substitute only pinned-base production owners, with exact restoration and source-hash verification. Handoff substitutes
openclaw-agent-schema-inspection.tsand selectsmain follows its handoff. Integrity substitutes the original database/schema/index/integrity owners and selectsrefuses .* before admitting a dirty database.Final rig gate results from the retained command log:
exit=0Testbox workflow receipts: main focused proof (later cancelled during the repeated gate) and final eager-import proof. Their test successes above are command-level results; the cancelled workflow is not presented as a green aggregate run. Both task-owned leases were stopped.
CI follow-up
Run 37183170428 exposed two separate test-fixture failures:
checks-node-compact-small-5: two desktop-readiness proof fixtures supplied only a/readyzresponse after the shared test-instance owner began requiring/startupzsettlement. One reused a consumed response body; the other exhausted its response queue and waited until its existing 60-second deadline. Both success fixtures now supply distinct, fresh startup responses. Every deadline, retry, redaction, and timing assertion remains unchanged; no production or shared-helper behavior changed.checks-ui-e2e-real-gateway (2/2): the synthetic mergeb82f27f9ba31included main's provider-qualified Automations model values, while the existing test expected bare option IDs. The failure was the initialretiringassertion, before any publication. Main fixed all five selectors in70fc9407fcfb; this branch incorporates that fix through a normal rebase, with no copied upstream production change or extra UI diff.Fixture-only proof on
blacksmith-testbox, leasetbx_01m42tedeby1qz9nrg7qqhe1we:node scripts/run-vitest.mjs test/scripts/desktop-readiness-proof.test.ts --maxWorkers=1passed all four tests, Vitest 21.02 seconds, wrapper 23.14 seconds.node scripts/check-changed.mjs --stagedalso passed, including all four root test type graphs, dead exports, script lint, and changed-test lint (zero warnings/errors). Combined source materialization, install, test and gate command: 401.739 seconds. Independent fixture review was scoped-clean through P2; the lease was stopped before rebasing. The Testbox workflow receipt identifies this lease.The final rebase onto
3052e3b93a0ais patch-identical across all five commits (git range-diffreports=for each). All previously tested PR runtime/test file hashes survived unchanged; only main's wrapper-inventory additions differ. Thus the completed behavioral proof is retained, while the inherited UI selector fix comes from its canonical main owner. Fresh independent review of the complete rebased candidate is scoped-clean through P2.Final exact-head CI 37184663139 completed successfully for
2c0db987677fdc9b2ae6f7e7ff700d9fbf267a34; bothopenclaw/ci-gateprojections are green. GitHub reports the PR merged at 2026-10-04 07:16:51 UTC as3f6c1d3a23b90c52b3bf317afc5291e7f1125e32, verified on current main. All task-owned Testbox leases and the Linux rig worktree were cleaned up.