Skip to content

perf(sessions): reuse committed transcript publication tokens - #169627

Merged
steipete merged 9 commits into
mainfrom
dbasync/pubtokens
Oct 12, 2026
Merged

steipete merged 9 commits into
mainfrom
dbasync/pubtokens

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Session metadata publication reselects transcript watermarks that the writer already knows, and transcript edits reselect the generation they just created.

User Impact

This reduces SQLite work during ordinary turns without changing session or transcript behavior. It changes no schema, retention, public API, or update contract.

Why This Change Was Made

Carry the transcript token in the existing exact-entry selection and committed entry postimage. A transcript append in the same transaction supersedes the selected token through the existing staged authority owner. Publication consumes that postimage. Transcript rewrites return their minted generation directly; steering-only rewrites preserve the existing generation and acquire it only for callers that need it.

Removed checks and accepted edges:

  • The post-write publication watermark reread is removed when the writer provides the token. The receipt describes that committed write; a later in-process write publishes its own receipt rather than retroactively changing this one.
  • The generation reread immediately after a rewrite is removed. The committed token belongs to that rewrite; subsequent writes publish subsequent tokens.

The predicate comparison across a detached edit remains, as do the existing authority checks at transcript mutation boundaries.

Evidence

One live baseline/candidate SQL harness pair ran in order M1,C1 against integrated main cde0f8844503f332dcdc1aa1a5453a9a7294d6b8 and final head ca134ccd4c392fe1e8f5b000dcf5b48a940da19d. The shared workload is unchanged except for the copied workload's output directory; source-mapped builds and all fixture, calibration, and conservation checks passed. Relaxed testing v6 replaces the original three-pair requirement.

Warmed metric (10 turns) Base Candidate
All-thread statements, median [min–max] 356 [309–533] 348 [300–491]
All-thread requests, median [min–max] 111 [97–152] 110.5 [97–132]
MAIN statements, median [min–max] 0 [0–2] 0 [0–2]
All-thread statements, mean 378.0 354.5
All-thread requests, mean 116.8 111.8
MAIN statements, mean 0.2 0.2

Observed warmed means fall by 23.5 statements (6.2%) and 5.0 requests (4.3%). The direct owner deltas are session.entry.patch.commit 44.3 → 37.0 statements with 6 requests unchanged, and session.messageRewrite.commit 10 → 9 statements with 1 request unchanged. The exact eliminated reads total 8.0 statements per warmed turn: 6 publication watermark reads in entry patch commit, 1 in lifecycle projection, and 1 rewrite-generation read. These operations keep the same 6/1/1 requests, with no extra IPC. Background memory/index and maintenance scheduling also contributes to the whole-turn difference; this is not a claim that all 23.5 statements or 5 requests come from pubtokens.

Whole workload: 10,144 → 9,996 statements; 2,152 → 2,122 requests; 1,997 → 2,001 MAIN statements. First-turn requests are 188 → 197, while whole-workload requests fall by 30; this is phase redistribution, not a raw whole-workload increase. Warmed counts do not increase. The heavily loaded host makes latency comparisons unsuitable. Both runs recorded the same two shutdown-only BEGIN IMMEDIATE lock errors during idle database release, and the same two unresolved boot request targets; the candidate also recorded one recovered boot-time lock refusal in unchanged config revision loading. All remain included in totals. Neither run recorded a SQL error during first or warmed turns. The two warmed MAIN statements in each run were unchanged secret-store reads. No live user state was used.

Two Codex autoreview rounds completed with no actionable P0–P2 findings. Final-head ClawSweeper review also has no findings. The second reviewed the selector extraction, type-import cycle repair, and steering-only generation fallback. No ClawSweeper wait is requested under the campaign's relaxed landing rules.

Static inventory: publication/rewrite lane owners have 0 → 0 T1 calls. Shared legacy entry/read/write helpers retain 12 → 12 T1 sites (the selector extraction moves one site without adding one). No shared helper is relabeled worker-only.

Current integrated head: targeted oxfmt, basic oxlint, and git diff --check pass. Exact-head CI run 38210838469 passed, including production/test types, lint, source contracts/export collisions, Madge (zero cycles), worker/dialect ratchets, and changed-owner tests. Earlier Knip export scans reported identical unrelated findings on baseline and candidate; no pubtokens export finding was introduced.

Earlier remote proof passed core and sessions test typechecks, full-diff type-aware lint, Madge, export collisions, and both database ratchets. Knip findings matched the baseline exactly. The remote run was stopped and the lease released under v6 after the entry-writes suite reported a failure; CI reproduced that result as an incorrect test expectation: the session header occupies sequence 0, so the first message is sequence 1. Commit 33a8834f5066f corrects the assertion without changing production code. Commit 30e110e6e7e16 also adds the extracted selector to the PR wrapper source inventory, fixing the closure tests in the next CI attempt. Commit ca134ccd4c392 corrects the rewrite regression assertion to select the edited message instead of the session header. All final-head CI tests pass. No test-suite pass is claimed for the interrupted remote run.

Production TypeScript: +194/-125 lines (includes moving the shared selector to a sibling module). Tests: +86/-5. Documentation: +8/-0. Tooling inventory: +1/-0 to include the extracted selector. No SDK surface or published-driver update cell applies.

Landing uses the campaign-authorized exact-head REST squash fallback after native review preparation spent over twenty minutes in local worktree scans. The owned operation was stopped and its exact lock recovered before fallback; no native merge request was submitted.

@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: M labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 maintainer review before merge.

What this changes

This PR carries committed transcript watermarks and rewrite generations through existing writer results instead of selecting them again.

Example: Append the first user message to session entry-postimage, then publish its metadata.

  • Before: Publication rereads the transcript watermark with maximum sequence 1 because the session header occupies sequence 0.
  • After: Publication uses the writer's retained watermark with maximum sequence 1.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful owner-directed optimization with focused storage coverage, resolved prior findings, and passing exact-head CI; workload-level savings remain unmeasured in the supplied evidence.
Proof confidence 🦐 gold shrimp (3/6) Maintainer-authored internal performance work is outside the ordinary contributor-proof gate; supplied tests exercise real SQLite owners in process, while the announced live SQL comparison has no completed results.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Ordinary session operations repeat SQLite reads for transcript facts already established by their writer.
Reason: The maintainer supplies the direction and accepts committed-write receipt semantics without adding settings or changing public contracts.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: current main still performs the targeted rereads, the previous findings are resolved, and no actionable introduced defect was found.

Priority: P2
Reviewed head: ca134ccd4c392fe1e8f5b000dcf5b48a940da19d

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Completed real-Gateway baseline/candidate SQL results and a recorded base-fail/head-pass run of the added performance assertions are not supplied.
Agent review details

How this fits together

Session SQLite owners receive metadata patches and transcript edits, commit canonical state, and publish facts to session readers and derived caches.

flowchart TD
A[Session operation] --> B[SQLite transaction owner]
B --> C[Exact entry selection]
B --> D[Transcript mutation]
C --> E[Committed writer result]
D --> E
E --> F[Session publication and caches]
Loading

Technical review

Best possible solution:

Reuse transaction-owned transcript tokens through existing writer results while preserving exact-row comparisons and lifecycle guards.

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

Current-main source directly shows the publication watermark read and post-rewrite generation read targeted by this PR; no target code was executed during this review.

Is this the best way to solve the issue?

Carrying facts from the synchronous writer fits existing ownership and avoids a parallel cache or persistence mechanism.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Exact-entry selection keeps the original intent (38ced6e: Share selected entry and side-table facts through turn completion instead of repeating database work.)
  • Committed postimage publication keeps the original intent (8fe6ac8: Publish exact writer-established entry and side-table facts without rereading them.)
  • Activity-summary publication watermark keeps the original intent (da965e0: Carry transaction-established facts through publication while retaining transcript-derived cache validation.)
  • Steering-only transcript rewrites keeps the original intent (b0e5f30: Preserve running-turn admissions for steering metadata while genuine transcript changes invalidate stale admissions.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit da965e0 adds src/config/sessions/session-accessor.sqlite-replacement-state.ts:123 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: da965e09656e; files: src/config/sessions/session-accessor.sqlite-replacement-state.ts)

PR surface

Source +69, Tests +81, Docs +8, Other +1. Total +159 across 12 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 8 194 125 +69
Tests 2 86 5 +81
Docs 1 8 0 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 12 289 130 +159

Review metrics

Metric Value Why it matters
Production versus test changes Production TypeScript +194/-125; tests +86/-5 Production growth includes extracting the existing selector and carrying committed tokens; tests check persisted token equality and eliminated rereads.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A focused session-storage performance improvement without a demonstrated production 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.

Rank-up moves

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

  • Publish the completed baseline/candidate SQL comparison with ordinary-turn statement and request counts.

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 (4 earlier review cycles)
  • reviewed 2026-10-12T05:22:14.780Z sha 322341a :: needs changes before merge. :: [P2] Include the transcript header in the expected watermark
  • reviewed 2026-10-12T05:41:26.553Z sha 33a8834 :: needs changes before merge. :: [P2] Include the extracted selector in the PR wrapper inventory
  • reviewed 2026-10-12T06:02:42.380Z sha 30e110e :: needs changes before merge. :: [P2] Select the rewritten message instead of the transcript header
  • reviewed 2026-10-12T06:19:18.790Z sha ca134cc :: needs maintainer review before merge. :: none

Reviewed October 12, 2026, 2:37 AM ET / 06:37 UTC (Revision 5).

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. label Oct 12, 2026
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 12, 2026
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. label Oct 12, 2026
@clawsweeper clawsweeper Bot added 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. and removed 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
@steipete
steipete merged commit c8ee8a7 into main Oct 12, 2026
153 checks passed
@steipete
steipete deleted the dbasync/pubtokens branch October 12, 2026 06:47
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
…aw#169627)

Carry transaction-owned transcript watermarks through entry postimages and return rewrite generations directly. Preserve detached-edit predicates and mutation authority checks while removing redundant post-write reads.
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: 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