Repository navigation
improve(sessions): reuse reply projection watermark - #169753
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR reuses the current transcript projection’s watermark when reading reply-tail anchors. Example: Inspect the answer-run reply tail at transcript sequence 4.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +4, Tests +99, Docs +8. Total +111 across 3 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)
Reviewed October 12, 2026, 5:41 AM ET / 09:41 UTC (Revision 4). |
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.
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.
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.
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
9a1b712a9b80a86d124a417301b2328405a31a98and production head00f8195a6820baa5b18ef94c631d2c40b272b40c. 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 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:
transcript-anchorsrequestsThe 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.dismissreturned 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 andopenclaw/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 main93e87378063afwas integrated without conflicts as headab0d4a6c04b0. 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.