Skip to content

perf(state): reuse retained agent writer admission - #172371

Merged
steipete merged 3 commits into
mainfrom
dbasync/writeradmit
Oct 14, 2026
Merged

steipete merged 3 commits into
mainfrom
dbasync/writeradmit

Conversation

@steipete

@steipete steipete commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Closing an agent's host compatibility handle currently forces database.prepareWrite even 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 readmitSchema option 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

  • Remove unconditional schema readmission after host-handle closure. The retained worker and published schema facts remain authoritative; unsupported out-of-process mutation of a live Gateway-owned database is not polled.
  • Keep physical schema receipt comparison for real tracked in-process DDL, including a raw handle that never borrowed an agent validation receipt. This protects real schema changes without a database query or cross-thread handshake.

Measurement

Completed three alternating pairs (M,C,M,C,M,C), ten warmed turns per run, using base 2120e734ec3cf107d2f1f66ab3526909fee63ecf and reviewed candidate 0d2a393d5777a0338927dbddcdb7fad17140d71a. 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.

Metric Base median [min–max] Candidate median [min–max]
Warmed turn-caused all-thread SQL/turn 117.3 [114.6–118.0] 117.8 [114.6–117.9]
Warmed turn-caused requests/turn 31.8 [31.2–32.5] 32.1 [31.2–32.2]
Warmed turn-caused MAIN SQL/turn 0 [0–0] 0 [0–0]
Raw warmed-window all-thread SQL/turn 143.5 [141.6–148.9] 143.9 [142.7–147.3]
Raw warmed-window requests/turn 41.8 [41.3–45.3] 43.7 [42.7–44.5]
Raw warmed-window MAIN SQL/turn 1.3 [1.3–1.3] 0 [0–0.4]
Whole-workload SQL 4,884 [4,781–4,976] 4,942 [4,869–5,003]
Whole-workload requests 1,057 [1,020–1,099] 1,086 [1,064–1,106]
Warmed prepareWrite requests/turn 0 [0–0] 0 [0–0]
Warmed prepareWrite elapsed/service totals per turn 0 / 0 ms (no events) 0 / 0 ms (no events)

There were no warmed prepareWrite calls 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:

Family Base median [min–max] Candidate median [min–max]
Exact-entry facts 0 [0–0.5] 0.2 [0–0.2]
Actor hydration 0.3 [0–0.3] 0.2 [0–0.2]
Entry-cache snapshot loads 0 [0–0] 0 [0–0]
Row facts 0 [0–0] 0 [0–0]
Token watermark 0.4 [0–0.6] 0.3 [0–0.5]
Context watermark 1 [1–1] 1 [1–1]

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 0d2a393d5777 passed CI run 38648451707, Security Review, and the required openclaw/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 at eaa6938874c3. 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 declares prepare(source, signal) in openclaw-agent-execution-contract.ts, with no readmitSchema option 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).

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

clawsweeper Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T21:18:47.849402Z 1f5197e 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S labels Oct 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +31 to +32
/** Reuse the native owner's published preparation and schema proof. */
prepare(source: AgentDatabaseRequestExecutionSource, signal?: AbortSignal): Promise<void>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

💡 Codex Review

/** Reuse the native owner's published preparation and schema proof. */
prepare(source: AgentDatabaseRequestExecutionSource, signal?: AbortSignal): Promise<void>;

P1 Badge 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

ℹ️ 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".

@steipete

Copy link
Copy Markdown
Contributor Author

Checked the published stable source: v2026.10.3 at 59cb44796b0f already declares prepare(source, signal?: AbortSignal): Promise<void>, and that tag contains no readmitSchema reference under src. The third parameter was an unreleased host-admission option; the released two-argument contract and compatibility type tests remain intact.

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.

@steipete
steipete merged commit 0f446c9 into main Oct 14, 2026
130 of 133 checks passed
@steipete
steipete deleted the dbasync/writeradmit branch October 14, 2026 22:52
@steipete

Copy link
Copy Markdown
Contributor Author

Measurement closeout for merged commit 0f446c95f312f9d1cace100e30b4bc7e45b1e293:

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 prepareWrite request; cold preparation counts and directly joined SQL matched within each pair. The retained-handle regression proves removal of the redundant admission request and preservation of committed state, but this ordinary-turn fixture demonstrates no warmed admission saving or latency benefit. The one authorized extra pair failed at the baseline's five-minute startup deadline before any turns, so its candidate did not run and the attempt is excluded. No further pair was attempted.

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.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 15, 2026
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.
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 size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant