Skip to content

perf(sessions): retain creation receipts for first-turn reads - #169727

Merged
steipete merged 4 commits into
mainfrom
dbasync/firstturn
Oct 12, 2026
Merged

steipete merged 4 commits into
mainfrom
dbasync/firstturn

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A new session's first entry reads could go back to SQLite even though creation had just published the complete committed entry. The bounded session actor replica only consumed those receipts for cells that already existed.

User Impact

No user-visible behavior or durability change. New-session readers can reuse the creation owner's committed entry immediately. User-input acceptance and assistant-output commits remain separate; there is no schema, SDK, update, or retention change.

Why This Change Was Made

Seed a missing entry cell from the existing full-entry receipt, using its physical identity, incarnation, and writer token. Existing cells keep their current update/invalidation path. The existing 128-entry / 8 MiB bounds and native-write invalidation still apply. No new cache, worker operation, SQL statement, or synchronous database access is added.

Removed check/read: the first entry-cache miss after a complete creation receipt no longer requires a replacement read. Accepted edge case: eviction or an intervening write can still cause a normal cache miss and worker read. No security or user-data effect-boundary check is removed. The cache-dependent synthetic mid-worker-grant revocation branch is deleted: a private flag flip is not owner revocation, and a retained read need not reach that grant. Real recovery-source validation, late-output authority, and SQL-free grants remain covered. The SDK concurrency test no longer requires two projection worker reads; its retained contract is FIFO and one persisted idempotent message.

Evidence

One isolated live baseline/candidate pair uses a private copy of the shared SQL harness. Both creations are separated from their first turns, the ten warmed turns are unchanged, and the unrelated delegation/cron/compaction suffix is omitted. Synthetic local streaming provider only. Baseline: 9b97574500bea3825579d1c57cfc124870b99b8c; candidate: 25bf6c6dcf8e870717079ac5ca368940d902d17c.

Phase Baseline statements / requests / MAIN Candidate statements / requests / MAIN
Second creation 49 / 14 / 0 50 / 14 / 0
Second-session first turn 446 / 128 / 2 382 / 109 / 0
Warmed turn, median [min–max] 315 [266–371] / 101.5 [85–128] / 0 [0–2] 318 [292–351] / 101.5 [93–111] / 0 [0–0]

Candidate warmed averages: 320.7 statements / 101.8 requests / 0 MAIN. First-turn excess over the warmed average falls from 121.4 to 61.3 statements (49.5%). The raw warmed median rises three statements while the average falls 3.9. Under ATTRIBUTION OVER RAW this is scheduling noise: the changed owner adds no SQL or requests, and its entry-read family decreases. A supplementary candidate was interrupted by the coordinator transport restart and is excluded from the measurement. Whole scoped workload falls 7970 → 7760 statements and 1538 → 1481 requests.

The baseline warmed averages are 324.6 statements / 103.1 requests / 0.4 MAIN. The first-turn excess is 121.4 statements / 24.9 requests. These raw turn differences include unchanged memory/projection scheduling and are not all attributable to this cache change. In the first paired second-session turn, session.entry.read falls from 21 statements / 7 requests to 18 / 4; the new cell also changes when existing row-projection work settles. Across the complete measured workload, session.entry.read falls from 218 statements / 70 requests to 205 / 57; during the ten warmed turns it falls from 174 / 54 to 166 / 46. These attributed savings, rather than the larger raw turn delta, are the causal claim. Largest families: domain publication +48.9 statements (including initial metadata append +17, memory source replacement +15.7, embedding cache +7.9), entry patch commits +13, activity summaries +11.4, actor transcript appends +8, history page +8, model context +7. Full actor hydration itself contributes less than one excess statement, so this change reuses the existing entry replica rather than introducing new actor initialization machinery.

  • T1 native SQLite sites and calls in the touched production owner: 0 → 0.
  • Regression uses the real async creation and patch writers, then deletion, and checks the retained entry after each transition. PR CI owns test execution and static gates under relaxed testing v6.
  • Local oxfmt, basic oxlint, and git diff --check: pass. CI attempt 2 at the measured production head passed all static jobs: types, lint, source contracts, architecture/Madge, Knip/boundaries, and T1/dialect/worker ratchets. The 12-test receipt suite passed in 6.88s (8.21s file wrapper). At 67c2f06869258, all behavioral shards and build-artifact smoke passed. Changed-file proof: receipt 12/12 in 9.83s (11.79s wrapper), writer claim 4/4 in 27.28s (62.48s wrapper, including preparation), SDK transcript 13/13 in 16.27s (18.62s wrapper).
  • Codex autoreview: two completed assessments, production scoped clean at P0–P2 and final test cleanup scoped clean at P0–P1. Preparation interruptions produced no assessment.
  • SDK public surface and published-driver update cell: not applicable; the SDK file change is test-only.

LOC: production +26 / −0; tests +93 / −107 (net −14), including the new receipt regression and removal of cache-dependent test machinery. Total net +12.

Follow-ups: initial metadata append setup in session-manager-metadata.worker.ts, initial activity summary scans, and coalescing memory source refreshes. These involve other lifecycle owners and are not folded into this bounded receipt fix.

Review disposition: the ClawSweeper P2 about a cache-dependent private revocation trigger is addressed by deleting that obsolete synthetic recheck branch under LESS PARANOID, retaining real recovery-source and late-output authority proof. No replacement timing gate is added. Raw-trace publication and another full measurement are not required under relaxed testing v6; the completed isolated live pair is retained as the behavior evidence.

Inherited CI failure confirmed on pinned main 4fcac11846800494f7b25f795d039be1ed505a62: attempt-transcript-lifecycle-prepare.test.ts → uses a stale-version postimage once without replaying a durable append (incognito=false) throws Session actor version changed before command admission (30.462s). The test injects a superseded actor epoch and expects retry machinery removed by #169651; this PR changes neither that test nor that command path. The focused main diagnostic was stopped after capturing this matching failure, not reported as a completed suite.

Integration: merged main 7c4ff5ae0a4c4ddfa8763ff53d8fae416d22f4bf without conflicts. The production diff is unchanged. CI had exposed TS2532 in the main-only #169744 test at session-entry-patch.authority.test.ts: two assertions dereferenced the fixture's optional entry. They now assert the expected initial/committed objects directly, preserving row presence and fixing the type errors. Final integrated-head CI at 1df9c15e64eab02e98de6cb24fa74e032a852a7d is green: run 38227187417, including all tests, types, lint, source contracts, architecture/Madge, Knip/boundaries, and database ratchets. No CI exception is needed. The earlier production-type job was canceled by fail-fast, not a diagnosed production error.

Final focused proof: receipt 12/12, 8.54s (10.22s wrapper); writer claim 4/4, 24.59s (59.72s wrapper with preparation); SDK transcript 13/13, 20.22s (22.77s wrapper). Owner attribution: session-actor-replica.ts:ensureReplicaSubscription retains the committed postimage; session-entry-read-writable.ts:readSessionEntryInWorker consumes it and eliminates the redundant session.entry.read request on a retained hit.

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

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR seeds missing session replica cells from complete committed receipts so first-turn entry reads can reuse them.

Example: Create agent:main:first-reader with sessionId first-reader-session and label created, then read its entry.

  • Before: The missing replica cell requires a worker read despite the complete creation receipt.
  • After: The reader reuses the committed entry while freshness checks pass; subsequent patches and deletion update or invalidate it.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is focused and source-reviewed without an actionable finding; performance evidence is summarized rather than independently inspectable.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body reports an isolated first-turn comparison with fewer attributed entry-read requests, while source inspection and the real-writer regression support receipt retention and invalidation without independently inspectable live traces.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: A new session's first turn repeats database work for entry facts its creation writer already committed.
Reason: The maintainer-authored direction makes a focused improvement through the established owner while preserving public behavior, storage, configuration, and update semantics.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR provides a focused optimization absent from current main, and no actionable correctness or security defect was found.

Priority: P2
Reviewed head: 1df9c15e64eab02e98de6cb24fa74e032a852a7d

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The reported live first-turn comparison has no inspectable execution trace, and an executed base-fail/head-pass comparison for the added regression is not supplied.
Agent review details

How this fits together

The bounded session replica consumes committed writer receipts and supplies entry facts to session readers, which retain authority checks and worker fallback.

flowchart LR
 A[Session creation writer] --> B[Committed entry receipt]
 B --> C[Bounded session replica]
 C --> D[Session entry reader]
 D --> E[Worker read on miss]
 F[Later storage writes] --> C
Loading

Technical review

Best possible solution:

Retain complete receipts through the existing bounded replica while preserving freshness validation, authority checks, writer ordering, and cold-read fallback.

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

Current main's subscriber only updates existing cells, so a complete creation receipt cannot seed an absent cell; no target code was executed during this read-only review.

Is this the best way to solve the issue?

Reusing the established replica addresses the redundant read without adding another cache, SQL operation, public API, or persistence contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 97775a426a35.

Provenance checked

  • Shared entry replica keeps the original intent (3bbc221: Unify entry facts under the bounded actor replica while preserving complete receipt coverage, invalidation, and worker fallback.)
  • Publication iteration keeps the original intent (dcb8c0e: Visit original cells once because receipt installation reorders the LRU map.)
  • Recovery worker-grant test changes intended behavior with a stated reason (e95e11c: Move asynchronous reads off the Gateway thread while preserving source checks and keeping source SQL outside worker grants.)
  • SDK transcript concurrency test keeps the original intent (9f6cbe9: Observe actual writer enqueue and lock entry rather than assuming preparation order, preserving exclusion and one persisted message.)
  • Patch receipt assertions keeps the original intent (31a4b92: Verify candidate transfer with final commit admission and distinguish precommit from committed state.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 3bbc221 adds src/config/sessions/session-actor-replica.ts:80 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3bbc221d1c8c; files: src/config/sessions/session-actor-replica.ts)

PR surface

Source +26, Tests -14. Total +12 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 26 0 +26
Tests 4 93 107 -14
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 119 107 +12

Review metrics

Metric Value Why it matters
Production versus test code Production +26/−0; tests +93/−107 The production growth extends the existing receipt owner; tests add real-writer coverage and remove cache-dependent machinery.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded session-read performance improvement without an established user-facing outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 (3 earlier review cycles)
  • reviewed 2026-10-12T07:53:25.867Z sha 25bf6c6 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-12T08:02:45.340Z sha 25bf6c6 :: needs changes before merge. :: [P2] Make recovery revocation independent of a worker cache miss
  • reviewed 2026-10-12T08:56:25.045Z sha 67c2f06 :: needs changes before merge. :: none

Reviewed October 12, 2026, 5:14 AM ET / 09:14 UTC (Revision 4).

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 12, 2026
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M and removed size: S labels 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. labels Oct 12, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@steipete
steipete merged commit 18e1e80 into main Oct 12, 2026
138 checks passed
@steipete
steipete deleted the dbasync/firstturn branch October 12, 2026 09:16
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…aw#169727)

Seed missing bounded session replica entries from complete committed write receipts. Reuse the creation owner's entry facts while preserving existing update invalidation and effect boundaries.

Remove cache-dependent test scaffolding and fix optional-entry assertions in the patch receipt test. The live pair reduces the second-session first turn from 446 statements / 128 requests to 382 / 109; directly attributed entry-read work drops by 13 statements and 13 requests across the workload.

Validation: exact-head CI 38227187417 passed all tests and static gates; two Codex review assessments passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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