Skip to content

perf(auto-reply): prepare initial reply snapshots through the session readers - #165295

Merged
steipete merged 1 commit into
mainfrom
dbasync/replysnap
Oct 5, 2026
Merged

steipete merged 1 commit into
mainfrom
dbasync/replysnap

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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.

Successful main-thread SQL Before After
Moved snapshots, ten warmed turns 160 0
Moved snapshots, first turn 18 0
Moved snapshots, whole workload 210 0
Aggregate warmed mean per turn 209.4 195.0
Aggregate first turn 831 831
Aggregate workload 7,638 7,552

The exercised initial callers at session.ts:309 and session.ts:545 each 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 locked executions 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.

  • Focused tests: 360 passed across 19 files, --maxWorkers=1, 1592.64 s wall on the loaded host. This includes runtime-process-build-graph.test.ts, get-reply.imports.test.ts, and session-history-read.imports.test.ts.
  • Final standalone 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.
  • Final cancellation regression: 1 passed, 36.87 s wall.
  • Indirect consumer routing audit: all selected native slash/status/authorization, model selection, heartbeat, binding, conversation-kind, conflict-retry, and hook consumers passed under their existing projects; no routing changes were necessary.
  • Madge: 0 cycles, 49.64 s. Database-worker ratchet: passed against the pinned base.
  • Codex autoreview through P2, high reasoning, Ultrafast: scoped-clean, no accepted/actionable findings.
  • SDK diff completed in 1310.15 s: no added/removed entrypoints and no direct export changes. It reports 128 reachable closure-hash changes from one conservative * reset-module declaration. The renderer treats the indexed coding-tools type import as a whole module and recursively follows unrelated declarations through command/shared-types and 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:

  • CI run 37257887706 passed: 78 successful jobs and 24 skipped jobs, with no failed tests; successful-job durations total 17,149 CI seconds. Both the Actions gate and Security Review openclaw/ci-gate status passed.
  • Additional indirect-worker routing proof: node scripts/run-vitest.mjs src/auto-reply/reply/get-reply.fast-path.runtime.test.ts --maxWorkers=1 passed all 3 tests (178.28 s wall); node scripts/run-vitest.mjs src/auto-reply/reply.block-streaming.test.ts --maxWorkers=1 passed its test (170.38 s wall). Both pass under the existing auto-reply project; no routing edits are needed.
  • Released SDK check reconfirmed against v2026.9.8: neither changed internal callable is exposed by SDK exports or api.runtime; public getReplyFromConfig remains asynchronous.
  • The published-driver update cell is not required for this diff: updater, Doctor, service lifecycle, migration, plugin loading, worker protocol, and stored-data contracts are unchanged. Existing session-reader transport is reused.
  • ClawSweeper completed on the candidate head with no actionable findings.

@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Oct 5, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 4, 2026, 11:36 PM ET / October 5, 2026, 03:36 UTC (Revision 3).

ClawSweeper review

What this changes

The 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
Reviewed head: a8bf1cd5f1815280c582d67420ed6500a753da4e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-preserving patch has strong recorded boundary proof and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured candidate-bound Gateway workload exercises the changed ordinary reply snapshot callers through real SQLite workers and records zero moved caller-thread SQL with successful turns and shutdown; focused regressions cover the remaining callers and replacement/conflict cases. No stored-data contract changes require migration proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured candidate-bound Gateway workload exercises the changed ordinary reply snapshot callers through real SQLite workers and records zero moved caller-thread SQL with successful turns and shutdown; focused regressions cover the remaining callers and replacement/conflict cases. No stored-data contract changes require migration proof.
Evidence reviewed 10 items Pinned introduction and merge ownership: Reviewed the merge-base-to-head introduced changes. The raw test-merge record has the pinned main parent followed by the exact PR head; its result retains main's terminal-error import change rather than removing it.
Current main still needs this cutover: Fetched main's initial snapshot function still invokes the synchronous entry reader. The merged lifecycle prerequisite explicitly identifies initial reply snapshots as remaining debt: #164922.
Existing reader and writer ownership preserved: Initial preparation reuses the commit preparation's exact-row worker reader and physical-source validation. The commit path retains authoritative rereads, revision checks, conflict handling, and the synchronous commit guard; incognito and maintenance selection remains with the existing native owner.
Findings None None.
Security None None.

How this fits together

Reply 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +20, Tests +19, Docs +10. Total +49 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 7 53 33 +20
Tests 5 74 55 +19
Docs 1 10 0 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 137 88 +49

Review metrics

Metric Value Why it matters
Recorded snapshot SQL placement Ten warmed turns: 160 → 0 caller-thread statements; first turn: 18 → 0 The workload measures the changed read boundary directly, without establishing a latency improvement.

Technical review

Best 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.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded runtime performance improvement with preserved user behavior and no demonstrated urgent regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured candidate-bound Gateway workload exercises the changed ordinary reply snapshot callers through real SQLite workers and records zero moved caller-thread SQL with successful turns and shutdown; focused regressions cover the remaining callers and replacement/conflict cases. No stored-data contract changes require migration proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured candidate-bound Gateway workload exercises the changed ordinary reply snapshot callers through real SQLite workers and records zero moved caller-thread SQL with successful turns and shutdown; focused regressions cover the remaining callers and replacement/conflict cases. No stored-data contract changes require migration proof.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-05T03:07:53.355Z sha a8bf1cd :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T03:13:57.204Z sha a8bf1cd :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 077f28f into main Oct 5, 2026
175 of 178 checks passed
@steipete
steipete deleted the dbasync/replysnap branch October 5, 2026 04:26
@steipete

steipete commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant