Repository navigation
perf(auto-reply): prepare initial reply snapshots through the session readers - #165295
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, 11:36 PM ET / October 5, 2026, 03:36 UTC (Revision 3). ClawSweeper reviewWhat this changesThe PR moves initial reply-session snapshots through the existing worker reader, awaits them in reply and native-confirmation callers, and updates regression coverage and documentation. Merge readiness✅ Ready for maintainer review Keep open: current main still performs these initial reads synchronously, and the merged related work leaves this cutover outstanding. No actionable introduced defect was found. Priority: P2 Review scores
Verification
How this fits togetherReply initialization reads the current session, related sessions, and stored model parent before selecting reply state. The existing lifecycle writer then rereads authoritative state, checks revisions and current authority, and publishes committed results. flowchart TD
A[Inbound reply or native confirmation] --> B[Capture physical session store]
B --> C[Existing session worker reader]
C --> D[Current and related row snapshot]
D --> E[Validate source and prepare reply]
E --> F[Lifecycle writer checks current state]
F --> G[Committed session and reply state]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +20, Tests +19, Docs +10. Total +49 across 13 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Use the existing worker reader for durable preparation while preserving snapshot consistency, native-scope ownership, and the lifecycle writer's final authority checks. Do we have a high-confidence way to reproduce the issue? Yes: current main's initial snapshot function directly executes synchronous SQLite reads, and the captured before/after Gateway workload measures that boundary. This review independently inspected source but did not execute the workload. Is this the best way to solve the issue? Yes: reusing the already-established worker reader and shared source validation is a focused cutover that preserves the existing writer and native-only contracts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 94f1e932eedc. 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
History |
|
Merged via squash.
|
What Problem This Solves
Reply startup still read its initial current, related, and stored model-parent rows synchronously on the Gateway thread after the commit-side snapshot had moved to workers.
Why This Change Was Made
All five initial snapshot call sites now await the existing session history reader, including preprocessing, ordinary reply initialization, fast slash commands, and native-runtime confirmation. Initial and commit preparation share the existing physical-source capture and validation. The current row, declared related rows, and stored model parent retain one snapshot; the lifecycle writer still performs its authoritative reread, revision checks, transaction/commit grants, and acknowledged publication.
The internal synchronous facade is gone; no released SDK wrapper is required. This adds no service, cache, worker command, schema, retention, or durability change. A type-only import now points to its existing leaf owner to fix an inherited Madge cycle found by the required gate.
Related: #164922, #164682, #164989, #165027. Known overlap: #162433 touches the reply ownership area; this PR keeps minimal hunks and does not adopt or restructure that draft's design.
User Impact
Durable reply preparation moves these reads off the caller thread without changing session selection or commit authority. No configuration or update migration is required. Process-held incognito and maintenance retain their existing native owner; worker failure never selects that path. Existing synchronous live-authority reads, including the native-confirmation commit guard at
src/gateway/server-methods/chat-send-session.ts:618, remain outside this snapshot cutover; no SQL was added to grants and no zero-SQL claim is made for whole grants.Production: +53 / -33 / net +20, 86 changed lines across seven production files. Five test files and the worker-access documentation also changed. 0 new
OPENCLAW_*names. Static T1 inventory remains 887 → 887 because the shared native kernel retains other admitted consumers.Evidence
Baseline:
5ae6497da4f2f7cf4e3494c1de7a126d9f719940. Candidate:a8bf1cd5f1815280c582d67420ed6500a753da4e.The unchanged sqlmeasure3 harness ran with source maps and isolated synthetic state on both revisions. All 13 top-level turns plus child, RPCs, cron, compaction, and graceful shutdown passed.
The exercised initial callers at
session.ts:309andsession.ts:545each contributed 80 → 0 warmed statements: transaction 30, exact rows 20, participant projection 10, canonical key 10, and freshness 10. The authoritative commit reread receives no savings credit. The fixed workload did not exercise the other three snapshot callers; focused tests cover those paths.Aggregate counts include background/settling work and are noisy. Instrumented harness wall time was 73.7 → 220.6 s under changing host contention, so no latency improvement is claimed. Failed
database is lockedexecutions were excluded: baseline 2 main connection + 1 worker shutdown; candidate 1 main connection + 2 worker shutdown. They caused no failed turn or RPC.The real SQL-observer regression failed on the original code with 18 caller-thread SQL observations and passes after the cutover. It covers current, related, stored-parent, missing, and unrelated rows. Physical-store replacement is rejected during both initial and commit preparation; stale writer conflicts retain the existing no-replay behavior.
--maxWorkers=1, 1592.64 s wall on the loaded host. This includesruntime-process-build-graph.test.ts,get-reply.imports.test.ts, andsession-history-read.imports.test.ts.pnpm test src/config/sessions/session-accessor.reply-init-selection.test.ts --maxWorkers=1: 6 passed, 102.69 s wall (79.04 s Vitest duration, including 29.74 s compiled-worker preparation). The file uses the real worker reader/writer to prove SQL placement, snapshot consistency, stale-commit behavior, and physical replacement; mocks cannot prove those contracts. The added initial-replacement case took 2.75 s.*reset-module declaration. The renderer treats the indexed coding-tools type import as a whole module and recursively follows unrelated declarations throughcommand/shared-typesand the accessor barrel. Current and v2026.9.8 source confirm no callable snapshot method is exposed; no synchronous compatibility wrapper or baseline exception was added.node scripts/check-changed.mjs --base 5ae6497da4f2f7cf4e3494c1de7a126d9f719940: passed, 2084.87 s wall, including core/type-test graphs, formatting, lint, unused-export scans, schema/legacy guards, and runtime cycles. Final source-map Gateway build also passed.Landing validation at the same candidate head:
openclaw/ci-gatestatus passed.node scripts/run-vitest.mjs src/auto-reply/reply/get-reply.fast-path.runtime.test.ts --maxWorkers=1passed all 3 tests (178.28 s wall);node scripts/run-vitest.mjs src/auto-reply/reply.block-streaming.test.ts --maxWorkers=1passed its test (170.38 s wall). Both pass under the existing auto-reply project; no routing edits are needed.api.runtime; publicgetReplyFromConfigremains asynchronous.