Skip to content

perf(sessions): reuse actor projection receipts for history reads - #170127

Merged
steipete merged 5 commits into
mainfrom
dbasync/projsnap
Oct 12, 2026
Merged

steipete merged 5 commits into
mainfrom
dbasync/projsnap

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Warmed session-history reads repeat projection metadata queries after the session actor has already computed the same facts.

User Impact

Reduces SQLite work for warmed history reads without changing transcript contents, persistence, retention, permissions, or update behavior. No migration or operator action is required.

Why This Change Was Made

Warmed history consumers repeatedly query transcript projection metadata that the session actor already owns. Publish that compact projection with the actor's existing hot postimage and carry it on the existing history-worker request. The worker uses the existing session-scoped write receipt to select those facts; cold or invalidated actors still use the canonical SQL reader. Transcript bodies remain bounded SQL reads, and no worker request or independent cache is added. Trajectory append/trim now declares its empty session write scope: it changes only trajectory rows, so unrelated runtime bookkeeping no longer expires session receipts.

Append, rewrite, rewind, reset, compaction, archive/restore and index rebuild all update actor facts or invalidate their existing write scopes. The regressions cover stale receipts after those writer classes, postimage publication, request-local consumption, and trajectory append/trim preserving transcript receipts before a real transcript write invalidates them. Schemas, stored bytes, retention, permissions and update behavior are unchanged.

Removed rechecks and retained boundaries

  • Skip the combined projection snapshot recheck (watermark generation, transcript timestamp, active counts, indexed sequence, leaf, rebuild state and latest reset) when the actor's committed facts cover the read. Accepted edge: a read overlapping a subsequent writer may observe the preceding projection until its next read; no new cross-thread handshake is introduced.
  • Cold-marker reads stay: rewrite prepare/commit protect transcript data, and the integrated snapshot-consistency fix requires each new native snapshot to select its own marker before reading rows. The matched baseline includes that fix; this PR makes no cold-marker change.
  • T1 in the projection reader remains 1 → 1, with no new MAIN SQL. The adjacent trajectory append kernel retains its existing 3 T1 call sites (3 → 3); ordinary durable writes already use the worker, while unbound process-held incognito and native maintenance/deletion scopes retain native custody. They cannot be reopened by a durable worker without their separate owner cutover. readSnapshotEventRows also serves the process-held incognito SQLite owner and the synchronous SDK catalog-title API shipped in v2026.10.2. Moving that call requires the separate incognito custody/API cutover; it is not falsely classified as worker-only.

Measurement

Shared harness v2, one matched baseline/candidate pair under the campaign's relaxed testing policy: base 8cee6f65b819 → head 48f429d610cce. Each run completed ten warmed turns, all with causal SQL/request coverage. Both used Node 24.19.0, SQLite 3.53.3, identical harness sources and isolated Linux Testboxes with 99.75% idle CPU before the run. The baseline includes the landed hydration and cold-marker fixes.

Warmed metric Baseline Candidate Change
All-thread statements, median [min–max] 214 [214–219] 203 [203–203] −11
Logical requests, median [min–max] 50 [50–51] 46 [46–46] −4
All-thread statements, mean 216.0 203.0 −13.0
Logical requests, mean 50.4 46.0 −4.4
MAIN statements/turn 0 0 0
Background statements/minute 982.72 938.33 −44.39
Legacy window statements/turn 239.7 226.0 −13.7
Shared family, statements/turn Baseline Candidate Change
Projection snapshot 4.0 1.0 −3.0
Cold marker 2.0 2.0 0
Exact-entry facts 5.0 4.0 −1.0
Actor hydration 4.0 2.0 −2.0
Entry-cache snapshots 0 0 0
Row facts primary 0 0 0
Watermark 1.0 1.0 0
Hot watermark 0 0 0

Attributable session savings are 6 statements and 3 requests per turn: three fewer projection queries, one fewer exact-entry read and two fewer actor hydrations; actual history requests fall 9→8 (readEntryResult disappears), and actor requests fall 11→9. Every other history operation keeps its request count. The remaining observed saving is 7 statements/1.4 requests from auth-profile helper reads (2.4→1.0 requests); treat that as scheduling/cache variation, not a promised benefit of this PR. Removing SQL inside an existing request is not counted as a request saving. No shared family increases, and both lane family targets are met. The retained projection read is the write-side patch predicate; cold-marker checks protect rewrite data.

Whole-workload statements fall 7,282→7,093 and requests 1,271→1,212; whole-workload MAIN stays 1,100 (including boot admission), while warmed MAIN remains zero. Baseline/candidate live workload times are 45.7/47.7 seconds; these instrumented runs do not establish a latency improvement.

Evidence

Two Codex review rounds completed with no unresolved P0/P1 finding. The CI follow-up fixes a type-import cycle, a widened file-target test fixture, and missing wrapper inventory entries. On final head 48f429d610cce, the ten new receipt cases pass in CI (1.081 seconds combined case time; 96–126 ms per case; 141.03-second enclosing 17-file shard). The existing actor tests (15 cases) and replica tests (11 cases) also pass. The focused wrapper inventory test passes. An intermittent savepoint database-lock failure did not reproduce in focused baseline or candidate runs; it remains recorded separately from confirmed inherited failures. Final-head CI passes production and test types, all lint lanes, source contracts, Madge (zero cycles), and the T1/dialect ratchets. The security review passes. The aggregate CI gate remains red on inherited test failures. Knip has no findings in touched files: its 34 production findings match scheduled main, its 22 full-tree findings reproduce exactly on baseline 8cee6f65b819, and its script scan passes with zero entries. The remaining Copilot fixture failure reproduces identically on baseline and candidate (36 failed tests, one pass). Local preflight uses changed-file format/lint and diff sanity; focused baseline/candidate runs diagnose unmatched CI failures, and local Knip completes its inherited-finding classification. No update cell is required because this change does not touch update, Doctor, schema/migrations, plugin loading or service lifecycle.

Changed-file format/lint and git diff --check pass. Diff: 14 files, +633/−68 lines: production +208/−68, tests +413/−0, documentation/inventory +12/−0.

Inherited CI evidence

Final-head CI and security review. The following untouched failures match scheduled main or the focused baseline comparison. No failing check is described as passing.

Test family Baseline evidence
message-tool.internal-source-reply.integration.test.ts Matching main failure
legacy-main-session-migration.test.ts Matching main failure
session-accessor.sqlite-replacement-receipts.test.ts Matching main failure
session-history-worker-errors.test.ts Matching main failure
session-accessor.pending-inputs.test.ts Matching main failure
session-accessor.test.ts Matching main failure
heartbeat-runner.webchat-exec-completion.test.ts Matching main failure
server-methods.canonical-validation.test.ts Matching main failure
session-cost-usage-cache.creation-race.test.ts Matching main failure
embedded-agent-runner.run-embedded-agent.finalization-scope.test.ts Matching main failure
attempt-transcript-journal.test.ts Focused pnpm test extensions/copilot/src/attempt-transcript-journal.test.ts --maxWorkers=1 on 8cee6f65b819 and 48f429d610cce: identical 36 failures / 1 pass; runtime-config preparation error. Wall times 610.22 s / 444.37 s include cold worker compilation.

Knip: 34 production findings match scheduled main; all 22 full-tree findings reproduce exactly on baseline 8cee6f65b819 with the repository’s pinned Knip runner and config. Script exports pass. None of the findings are in touched files.

Publish compact projection metadata with actor hot postimages and carry it through existing history worker requests. Add stale-after-write coverage for transcript mutation classes. Replica accessor integration follows the pending hydration owner change.
@clawsweeper

clawsweeper Bot commented Oct 12, 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 size: L labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR carries committed actor projection facts into history-worker reads and preserves session receipts across trajectory-only writes.

Example: Read a warmed session containing user message "question" and assistant message "answer".

  • Before: The history reader queries projection metadata again before reading transcript rows.
  • After: A valid actor receipt supplies the metadata, while bounded transcript rows still come from SQL.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The ownership approach is useful and the known integration defect is repaired, but executed behavior evidence remains limited and two CI failure signatures remain unclassified.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored internal optimization is outside the contributor proof gate; its body leaves the warm-history measurement pending and supplies no executed performance result.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Warm history operations repeat metadata reads for facts already held by the session actor.
Reason: The maintainer-authored direction extends established ownership with no new configuration or public API and retains the existing fallback.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this useful maintainer-authored performance PR open; the prior wrapper finding is fixed, and no new actionable patch defect was established.

Priority: P2
Reviewed head: 48f429d610cce5e20542414e5342987645a90944

Before merge

  • Complete next step - Compare the session-accessor session-rebound failure and cache-creation offline-maintenance failures with the base, then resolve any demonstrated patch-caused failure or record their inherited classification.

Findings

None.

Tests

  • Missing end-to-end proof: No executed warm-history baseline/candidate trace or base-fail/head-pass receipt-regression result was supplied; the added tests describe in-process SQLite coverage.
Agent review details

How this fits together

The session writer publishes actor postimages to the host replica; existing history-worker requests carry their projection receipts, and the worker returns bounded transcript results using validated facts or the canonical SQL fallback.

flowchart LR
A[Session writer] --> B[Actor postimage]
B --> C[Host replica]
C --> D[History worker request]
D --> E[Scoped receipt validation]
E --> F[Actor facts or SQL fallback]
F --> G[Bounded transcript result]
Loading

Technical review

Best possible solution:

Reuse the existing actor's committed projection receipts while preserving scoped invalidation, bounded SQL payload reads, and the canonical fallback.

Do we have a high-confidence way to reproduce the issue?

Current-main source establishes the redundant projection query outside actor transactions; this review ran no target code and does not establish a measured performance gain.

Is this the best way to solve the issue?

The change coherently extends existing actor ownership and receipt invalidation instead of adding a competing cache, while preserving SQL payload bounds and cold or invalidated fallbacks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 70eb60085510.

Provenance checked

Testing

Proof path: none.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 18e1e80 adds src/config/sessions/session-actor-replica.ts:100 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 18e1e80ede63; files: src/config/sessions/session-actor-replica.ts)
  • Vincent Koc: Raw commit 932846b adds src/config/sessions/session-accessor.sqlite-projection-read.ts:5 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 932846b521c0; files: src/config/sessions/session-accessor.sqlite-projection-read.ts)

PR surface

Source +140, Tests +413, Docs +9, Other +3. Total +565 across 14 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 11 208 68 +140
Tests 1 413 0 +413
Docs 1 9 0 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 1 3 0 +3
Total 14 633 68 +565

Review metrics

Metric Value Why it matters
Production versus test growth Production +208/−68, net +140; tests +413/−0. Production growth carries compact facts through existing owners; the tests cover receipt reuse, mutation invalidation, request isolation, and trajectory-only writes.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove merge-risk: 🚨 automation: Current PR review selected no merge-risk labels.

Label justifications:

  • P2: This is a focused internal performance improvement without an established urgent user-facing regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record the declared warm-history baseline/candidate measurement through the production worker path.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-12T19:05:02.313Z sha b19b8ff :: needs changes before merge. :: [P2] Include both new modules in the PR wrapper inventory
  • reviewed 2026-10-12T19:20:52.045Z sha 0c39b35 :: needs changes before merge. :: [P2] Include both new modules in the PR wrapper inventory

Reviewed October 12, 2026, 3:43 PM ET / 19:43 UTC (Revision 3).

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 12, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. labels Oct 12, 2026
@steipete
steipete merged commit e9df67c into main Oct 12, 2026
140 of 149 checks passed
@steipete
steipete deleted the dbasync/projsnap branch October 12, 2026 20:18
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…enclaw#170127)

Publish compact projection facts with the session actor hot postimage and carry them through existing history-worker requests. Reuse committed session write receipts, and preserve them across trajectory-only writes. Cold or invalidated readers retain the canonical SQL path.

The matched live harness attributes six fewer SQL statements and three fewer worker requests per warmed turn to session reads. Projection snapshot reads fall from four to one; warmed main-thread SQL remains zero. Add stale-after-write regressions across transcript writer classes.

Retain cold-marker checks that protect rewrite data. The remaining synchronous incognito and shipped catalog-title API paths need a separate custody/API cutover. Exact-head static and focused checks pass apart from documented inherited Knip findings; remaining CI test failures reproduce on main or the baseline.
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 P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant