Skip to content

improve(sessions): reuse reply projection watermark - #169753

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

steipete merged 5 commits into
mainfrom
dbasync/watermark

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Reply-tail anchor reads query the retained transcript watermark immediately before loading a projection that already contains the same generation and last sequence.

User Impact

No user-visible behavior or storage change. Each reply-tail read avoids one redundant SQLite statement while preserving payload reads and live authority checks.

Why This Change Was Made

Build the optional watermark result inside the existing anchor projection callback. It consumes the projection's generation and raw sequence from the same SQLite snapshot. Standalone reads and early context-authority checks retain their existing behavior; cold or unavailable projections keep their existing failure path.

Removed check and accepted edge: the separate retained-watermark SELECT reconfirmed facts from the same transaction; the admitted projection is authoritative for that snapshot. A later append is observed by the next read rather than by reopening this snapshot.

The live trace showed the warmed reply-tail reads use history workers, so this PR stays at that existing owner boundary. It introduces no cache, fencing, worker handshake, request, or schema change.

Evidence

One live baseline/candidate pair, ten warmed turns each, using the shared synthetic workload on base 9a1b712a9b80a86d124a417301b2328405a31a98 and production head 00f8195a6820baa5b18ef94c631d2c40b272b40c. The final commit only repairs a test assertion. The shared harness was untouched; a private copy adds payload-free worker-request counting and external-storage output.

Warmed per-turn mean Base Candidate Delta
All-thread SQL statements 318.3 377.9 +59.6
Worker requests 85.1 103.0 +17.9
MAIN SQL statements 0.6 0.4 -0.2
Retained watermark SELECT, all callers 1.0 6.0 +5.0
Projection snapshot SELECT, all callers 5.1 7.0 +1.9
Cold-marker SELECT, all callers 3.0 3.5 +0.5

Warmed median [min–max]: statements 316 [304–346] → 363 [333–501]; requests 84.5 [81–96] → 100 [89–126]; MAIN 0 [0–2] → 0 [0–2]. Whole workload: 9,661 / 1,739 → 10,117 / 1,881 statements/requests. First turn: 1,003 → 1,208 statements; boot+connect+first turn: 4,118 → 4,075. Host load at run start was 68 vs 150; warmed median duration 6.93s vs 10.51s. Raw totals are timing-sensitive and do not establish a whole-turn reduction.

Per-operation attribution establishes the saving independently of that noise:

Warmed operation / caller (10 turns) Base Candidate
transcript-anchors requests 10 10
Anchor-kernel statements, including BEGIN/COMMIT 160 150
Anchor-kernel retained-watermark SELECT 10 0
Anchor-kernel projection SELECT 10 10
Anchor-kernel cold-marker SELECT 0 0
Unchanged session-row activity-summary watermark SELECT 0 50
Unchanged entry-patch predicate watermark SELECT 0 10
Unchanged entry-patch predicate projection SELECT 0 10
Other active-projection callers 41 50
Unchanged cold export/read SELECT 10 15
Cold rewrite/patch SELECT 20 20

The changed operation adds no statements or requests and saves exactly one statement per invocation. The extra family reads belong to unchanged activity-summary, row-facts, and patch-predicate owners. Activity-summary-source requests ran 1 → 10, row-facts 30 → 50, and entry-patch prepare/commit 20/50 → 30/60. Landing uses the campaign's ATTRIBUTION OVER RAW rule; the broader projection/cold families remain follow-up work at those owners.

All 13 conversational turns, child completion, cron, compaction, and shutdown succeeded. The candidate harness's final all-RPC assertion failed because the later control-plane mentions.dismiss returned UNAVAILABLE. This is outside the changed transcript path and did not truncate the measured turns. No fixture children remained after shutdown.

Regression exercises the existing reader's reply-tail selection, verifies current payload/watermark after a native append, and covers cold-marker refusal plus restored hot reads. It requires one projection SELECT and zero additional watermark SELECTs for each successful read. CI found a cumulative counter assertion that included fixture writes; the final test-only commit scopes it to the restored read.

Basic targeted oxlint, oxfmt, and git diff --check: pass. Final-head CI run 38229858798 and openclaw/ci-gate: pass, including all Node shards, production/test types, type-aware lint, source contracts/export collisions, Madge, and worker/dialect ratchets. The changed test file passes 13/13 in 44.60s wrapper wall time (42.86s Vitest); the new regression takes 0.524s. Its CI shard took 206s including setup and sibling files.

CI intentionally omits Knip on ordinary PRs. All three repository Knip export scans pass with zero findings on the integrated head: production 333s, full-tree 496s, scripts 335s. The same scanner arguments ran through the repository runner with a longer tool timeout after an initial full-tree timeout. The first production scan found three unrelated exports already fixed on main (PreparedCronRunReceiptClaim, ComposerRunStatusContent, ChatPaneVersionsMenu), so main 93e87378063af was integrated without conflicts as head ab0d4a6c04b0. The two changed TypeScript files are identical before/after integration; frozen install passed. The SQL pair is reused under the campaign integration rule.

Codex autoreview: scoped-clean P0–P2 for production and append regression (second and final round), with no actionable findings. The later cold-transition assertions and their CI counter repair were reviewed locally. One earlier CI run exposed a cumulative test counter that included fixture writes; the repaired assertions measure each read's delta.

Production LOC +13/−9, regression +99/−0, docs +8/−0. The touched kernel has 0 → 0 counted T1 primitives; the integrated-head CI worker ratchet reports 541 → 541 globally (T1-compat 2 → 2). No inventory reclassification. This lane removes a history-worker re-check. SDK untouched. No published-driver update cell applies: update, Doctor, schema, plugin loading, and service lifecycle are unchanged.

@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 reuses the current transcript projection’s watermark when reading reply-tail anchors.

Example: Inspect the answer-run reply tail at transcript sequence 4.

  • Before: The reader separately queries the watermark before loading the projection and answer payload.
  • After: The same projection supplies maxSeq 4 and the payload; a subsequent append is observed as maxSeq 5.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct optimization with relevant live measurements supporting the narrow query saving.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied live Gateway workload exercises reply-tail reads through history workers on production head 00f8195 and reports one fewer kernel statement per invocation with all conversational turns completing; the reviewed production kernel is identical, and the later mentions.dismiss failure is outside the measured transcript operation.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Ordinary reply inspection performs an unnecessary SQLite read.
Reason: The established feature owner continues the existing optimization direction with a measured per-operation saving and little added complexity.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR provides a focused, measured optimization absent from current main, with no actionable correctness or security findings.

Priority: P2
Reviewed head: ab0d4a6c04b0ef37ae2902fd26e6acdbcf675bec

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: A base-failing/head-passing execution of the added regression is not supplied.
Agent review details

How this fits together

Gateway reply inspection requests anchors, payloads, and a watermark from the retained history reader, then consumes the snapshot under existing session and run-authority checks.

flowchart TD
A[Gateway reply inspection] --> B[Retained history reader]
B --> C[SQLite transaction]
C --> D[Current transcript projection]
D --> E[Anchors payloads and watermark]
E --> F[Current authority checks]
F --> G[Reply delivery decision]
Loading

Technical review

Best possible solution:

Reuse the admitted projection watermark while preserving standalone readers, cold-storage refusal, and delivery-authority checks.

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

Current-main source establishes the duplicate watermark read, corroborated by the supplied live per-operation counts; no target code was executed during this review.

Is this the best way to solve the issue?

The patch removes redundant work at the existing snapshot owner without adding another cache, transport request, or authority mechanism.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit d94fe35 adds src/config/sessions/session-transcript-anchor-read.kernel.ts:69 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d94fe35027e7; files: src/config/sessions/session-transcript-anchor-read.kernel.ts)

PR surface

Source +4, Tests +99, Docs +8. Total +111 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 13 9 +4
Tests 1 99 0 +99
Docs 1 8 0 +8
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 120 9 +111

Review metrics

Metric Value Why it matters
Production versus test LOC Production +13/−9; tests +99/−0 The regression covers query elimination, payload preservation, append freshness, and cold refusal without adding a production test seam.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A narrow internal performance improvement with no demonstrated urgent user regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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-12T08:28:19.249Z sha 906215f :: needs changes before merge. :: [P2] Explain isolation for both new history-eviction mocks | [P2] Include the new module in the trusted wrapper inventory
  • reviewed 2026-10-12T08:48:08.536Z sha 00f8195 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-12T09:12:16.028Z sha 4020415 :: needs maintainer review before merge. :: none

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

@steipete steipete changed the title improve(sessions): reuse resident transcript facts during reads improve(sessions): reuse reply projection watermark Oct 12, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Oct 12, 2026
@steipete
steipete merged commit 29fc232 into main Oct 12, 2026
125 checks passed
@steipete
steipete deleted the dbasync/watermark branch October 12, 2026 09:48
steipete added a commit that referenced this pull request Oct 12, 2026
The incognito owner-boundary fixture required a combined watermark SQL query
retired by 29fc232 (#169753). Observe the actual transcript read while
preserving delivered-result and durable/incognito ownership assertions.
No production behavior or test cases change.

Red-main proof: the original whole file reproduces the exact CI failure
(44 pass, 1 fail; 118.275s wall). The candidate passes all 45 cases in
80.011s wall with maxWorkers=1; the existing projection watermark freshness
regression passes in 28.112s. Targeted types, typed lint, formatting,
ratchets, assertion safety, and fresh independent P2 review pass.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
Return the optional reply-tail watermark from the admitted projection snapshot, removing the redundant retained-watermark read. Preserve standalone reads, live context authority, and cold-projection refusal.

Cover fresh reads after append and cold-marker transitions. Live operation attribution reduces reply-tail SQL from 16 to 15 statements with one worker request in both cases.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
The incognito owner-boundary fixture required a combined watermark SQL query
retired by 83e8e72 (openclaw#169753). Observe the actual transcript read while
preserving delivered-result and durable/incognito ownership assertions.
No production behavior or test cases change.

Red-main proof: the original whole file reproduces the exact CI failure
(44 pass, 1 fail; 118.275s wall). The candidate passes all 45 cases in
80.011s wall with maxWorkers=1; the existing projection watermark freshness
regression passes in 28.112s. Targeted types, typed lint, formatting,
ratchets, assertion safety, and fresh independent P2 review pass.
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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