Repository navigation
perf(state): reuse retained agent writer admission - #172371
Conversation
Avoid a forced database.prepareWrite request when a host compatibility handle closes but its worker remains admitted. Reuse published physical schema facts while preserving repair after tracked in-process DDL, cold admission, FIFO ordering and committed state.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1476a58df8
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /** Reuse the native owner's published preparation and schema proof. */ | ||
| prepare(source: AgentDatabaseRequestExecutionSource, signal?: AbortSignal): Promise<void>; |
There was a problem hiding this comment.
Preserve the released third prepare argument
When a third-party TypeScript plugin calls the documented publicationSource.execution.prepare(source, signal, { readmitSchema: true }), this narrowed SDK-exported signature now fails compilation with TS2554 after upgrade. src/plugin-sdk/sqlite-runtime.ts re-exports OpenClawAgentDatabaseExecution and derives the publication execution shape from this method, while the active agent-execution-preparation-released-signature compatibility record explicitly promises the optional third argument without migration or deprecation. Keep the optional parameter in the public type and implementation even if it is now ignored internally.
AGENTS.md reference: AGENTS.md:L55-L57
Useful? React with 👍 / 👎.
💡 Codex Reviewopenclaw/src/state/openclaw-agent-execution-admission-contract.ts Lines 31 to 32 in 1476a58 When a third-party TypeScript plugin calls the documented AGENTS.md reference: AGENTS.md:L55-L57 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Checked the published stable source: v2026.10.3 at 59cb44796b0f already declares The review did identify stale wording in the compatibility record and migration documentation. This PR corrects those descriptions to match the published contract and retained worker ownership. It does not add an ignored argument for an unreleased option. |
|
Measurement closeout for merged commit Three complete alternating pairs passed (60 warmed turns total). Warmed turn-caused SQL/requests were 117.3 [114.6–118.0] / 31.8 [31.2–32.5] on base and 117.8 [114.6–117.9] / 32.1 [31.2–32.2] on the reviewed candidate. MAIN remained zero. Exact-entry reads rose by 0.2 SQL/turn; their triggering invalidation is unproved. Count non-regression is not established. The PR body now contains the complete raw-window, whole-workload, shared-family, and admission-operation tables and attribution limits. Neither head issued a warmed All six accepted runs used the same private harness copy with the arbitrary depth cutoff removed from nested subagent-receipt parsing; an earlier parser-failed attempt was excluded. The shared harness was unchanged. These results were finalized after merge, and the unresolved shared-family increase remains a follow-up rather than a claimed non-regression pass. |
Avoid a forced database.prepareWrite request after an agent host compatibility handle closes while its worker remains admitted. Reuse the native owner's published preparation and physical schema facts while preserving repair after tracked in-process DDL, cold admission, FIFO ordering, and committed state. Unsupported foreign-process mutations of a live Gateway-owned database are not polled. No schema or released SDK contract changes. Warmed-turn performance is reported separately in the pull request.
What Problem This Solves
Closing an agent's host compatibility handle currently forces
database.prepareWriteeven when its worker and schema admission remain live. The extra request re-enters writer admission and schema refresh before the next write.Reuse the retained native owner's preparation. Remove the
readmitSchemaoption throughout the internal execution path. The owner consumes its published physical schema facts so tracked in-process DDL still triggers repair; cold admission, replacement-file validation, FIFO ordering, and write settlement retain their existing owners. No schema, durability, shipped SDK, or service lifecycle contract changes.The motivating trace's 161.6 ms request included 123.7 ms after posting and before worker receipt. That interval does not establish schema execution or broker queueing as the cause. This change removes an unnecessary request where a retained worker is already admitted; the completed ordinary-turn fixture did not exercise that removed path or demonstrate whole-turn savings.
Removed check and accepted edge case
Measurement
Completed three alternating pairs (M,C,M,C,M,C), ten warmed turns per run, using base
2120e734ec3cf107d2f1f66ab3526909fee63ecfand reviewed candidate0d2a393d5777a0338927dbddcdb7fad17140d71a. Values below are medians [min–max] of the three run means. All six fixtures passed. The one allowed supplemental pair failed on the baseline before any turns: Gateway readiness exceeded the five-minute startup deadline. Its candidate half did not run, and the failed attempt is excluded from the comparison. No further pair was attempted.prepareWriterequests/turnprepareWriteelapsed/service totals per turnThere were no warmed
prepareWritecalls on either head, so the elapsed/service ratio is N/A, not a measured speedup. Each run had two cold preparations; their directly joined SQL totals were 38 on both heads in pairs 1 and 3 and 37 on both heads in pair 2. The measured owner-operation delta is therefore zero requests and zero SQL. The retained-handle regression, rather than the ordinary warmed fixture, proves removal of the redundant request.Shared-family warmed SQL/turn:
Measurement conclusion remains unresolved: warmed medians increased by 0.5 SQL and 0.3 requests/turn, and exact-entry facts increased by 0.2 SQL/turn. The traces do not contain the receipt invalidations/token transitions needed to prove the specific triggering write; these increases are not claimed as a passed non-regression gate or dismissed as noise. Nearby background backfill/reclamation is observed but does not establish causation. This PR was already merged before measurement closeout; this section records the remaining evidence gap rather than retroactively claiming a pass.
Whole-workload MAIN is exactly 476 on every run. The raw warmed MAIN difference is delayed startup plugin-lease checks moving between startup/first-turn/warmed windows, not eliminated MAIN work. Apparent first-turn causal SQL reduction (277 [277–284] to 258 [258–278]) is also not a proven saving: the second cold preparation is turn-tagged in all baselines but background-tagged in candidate pairs 1 and 3.
Pre-run host load ranged approximately 88–156 on 32 cores (supplemental attempt: 160), so no wall-time or latency improvement is claimed. A private copy of the shared harness removed an arbitrary recursion-depth cutoff in the subagent-receipt parser after one excluded attempt failed to recognize a valid nested receipt. The shared harness was unchanged, and all six accepted runs used the same corrected parser. Raw fixture logs are not published.
T1 in the touched host admission/execution modules: 0 → 0. This change adds no SQL and does not move statements between threads. CI passed the worker and dialect ratchets.
Evidence
The existing retained-worker test now verifies that handle eviction sends no extra prepare request, that committed state survives the reopen, and that a repaired schema also returns to request-free admission. Existing tracked-DDL, rollback, replacement, ownership, and revoked-receipt coverage remains. Obsolete forced-readmission assertions were removed from the retained creation-witness test.
Codex autoreview round 1 is scoped-clean at P0–P2; round 2 is scoped-clean at P0–P1 for the compatibility prose correction. Changed-file type-aware oxlint, canonical formatting, and git diff --check pass. The focused admission suite passed all 32 tests. Final head
0d2a393d5777passed CI run 38648451707, Security Review, and the requiredopenclaw/ci-gate. CI covered changed/compact tests, production/test types, lint, source/export contracts, Madge, and worker/dialect ratchets.Knip is nonzero with inherited findings: eight production findings match completed main job 116084501762 at
e589d87d7b7e; all 17 full-tree findings match that scan or scheduled-main job 116121040220 ateaa6938874c3. Finding files are unchanged between those main revisions, the integrated base, and this candidate. The nine additional UI exports were exposed by main’s removal of their Lit presentation fixture. The script-export scan passed with zero findings.The remote check:changed attempt never reached lease allocation and was stopped after local staging made no useful progress; no remote pass is claimed. Its covered gates use successful PR CI, with uncovered checks run serially through the local campaign semaphore. No update/Doctor/migration/plugin-loading/service lifecycle contract changes, so the update cell does not apply.
The removed third prepare argument is reachable through the current sqlite-runtime SDK type but never shipped in stable. The latest stable v2026.10.3 (
59cb44796b0f1f0daa0e37af8b1495abb45d9bc1) already declaresprepare(source, signal)inopenclaw-agent-execution-contract.ts, with noreadmitSchemaoption anywhere under src; this patch retains that shipped signature. The scoped sqlite-runtime SDK API comparison completed: four affected exports, no added or removed exports, and the expected preparation-signature change. It also records an unrelated generated Kysely outbox-column difference: the base render consumed artifacts from the later integrated-main install, while the saved candidate render predates it. The tracked schema is byte-identical within both the original and integrated base/candidate pairs, so that generated-artifact difference is not caused by this patch. This is not a full transitive SDK-surface audit. The stale optional-third-argument description in the compatibility record and migration documentation is corrected; the released compatibility record stays active.LOC: production +18/−21 (net −3), tests +41/−2 (net +39), documentation +7/−2 (net +5).