Repository navigation
improve: reduce transcript import watermark overhead - #133403
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 1:51 PM ET / 17:51 UTC. ClawSweeper reviewWhat this changesThe PR upserts a transcript projection watermark on initialization and directly updates the known row for later events in the same synchronous import batch. Merge readinessNo blocking correctness finding: the direct UPDATE is reached only after this synchronous appender has a watermark state, while initialization, dirty marking, and rebuilds retain UPSERT. Keep this maintainer-authored, protected PR open until its exact-head checks complete and a maintainer reviews the durable-state optimization. Priority: P3 Review scores
Verification
How this fits togetherTranscript imports store session events, active-message projections, full-text search rows, and a per-session watermark in one SQLite transaction. The watermark tells later history and search readers whether the projection is current or requires a rebuild. flowchart LR
A[Staged transcript events] --> B[Synchronous import transaction]
B --> C[Transcript event rows]
B --> D[Projection appender]
D --> E{Watermark row known?}
E -->|No| F[Upsert initial watermark]
E -->|Yes| G[Update watermark]
D --> H[Active rows and search index]
F --> I[History and search readers]
G --> I
Decision needed
Why: The patch changes the write operation for persisted projection state; source supports its invariant, but the protected maintainer workflow requires an explicit landing judgment. Before merge
Agent review detailsSecurityNone. PR surfaceSource -5. Total -5 across 1 file. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the bounded query-shape optimization after exact-head CI is green and a sessions owner confirms the transaction-local row-existence invariant remains the intended contract. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR optimizes an existing deterministic import path rather than reporting a user-facing failure. Is this the best way to solve the issue? Yes. The existing appender is the owner that knows whether a prior write created the watermark row, so selecting UPDATE there avoids repeated conflict resolution without widening another lifecycle path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d0c1369ad1b5. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
9343a30 to
6b2ad28
Compare
What Problem This Solves
Large session imports repeatedly construct and execute projection-watermark UPSERTs even after the synchronous append owner knows that row exists. This change reduces import elapsed time by 4.1–7.4% in matched synthetic workloads.
Why This Change Was Made
Use UPDATE for a proven-existing watermark, while retaining UPSERT for initialization, dirty marking and rebuilds. The private writer maps its six fields once; the appender passes its actual optional prior state instead of fabricating an initial watermark. Every write remains in its original order and transaction.
No schema, index, cache, public API, configuration, dependency, durability, concurrency, recovery or visibility change. This is a bounded query optimization under the database-schema review checkpoint, not a store redesign. The worker's claim-fenced publication path is unchanged. Production +29/-34 (net−5); tests unchanged.
User Impact
Lower CPU and elapsed time during large imports, without changing stored history, identity ownership, search results or migration behavior.
Evidence
Matched Node 24.19.0/SQLite3.53.3 runs: three fresh processes per side and shape, interleaved before/after, on one isolated worker. Baseline
86b6ec0afa2c64d2019ffdb681760b433b2e10b1; runtime-tested candidate851fe4c1d87828b178d19eebe6381c80740be8ad. The final rebased importer owner and its append/staging/SQL/schema dependencies are byte-identical to that tested candidate.All nine pairs matched persisted-data SHA-256 digests across transcript bytes, identities, windows, active positions, watermark counts/cursor/dirty state and FTS. A separate 10k-event SQL trace retained all 100,034 calls: 10,001 watermark UPSERTs became one initial UPSERT plus 10,000 UPDATEs. Those were the only changed SQL shapes. Before/after Node CPU profiles completed separately from timing samples. Local timings were excluded because the host was saturated.
Blacksmith Testbox
tbx_01m19t750tgr25hnnwbcb442hc, worker run, was stopped after artifact collection. Packaged stable2026.7.1-2→candidate2026.8.1passed with 4,800 sessions, 1,227,946 events and 10,000 cron jobs across five complete state assertions. Automatic migration was checked immediately after the updater, before standalone Doctor; repeat Doctor took 38s under its 60s budget. Eight Gateway history samples across two agents/600 messages matched after restart. The synthetic plugin fixture required its existing capability consent; this proves automatic migration, not unattended update-channel switching.37 focused owner/sibling tests passed: importer rollback/deduplication/exact handoff, active projections, replacement ownership, context eligibility and projection rebuilds, including 100k-message bounded reads and interrupted/concurrent publication. Core types, guards, formatting, lint and Codex review passed. Existing behavior tests plus paired SQL/data proof cover the optimization without adding an implementation-shaped test.
The initial CI run exposed the unrelated native-runner batch-cancel race. It reproduced locally; upstream #133356 landed the same root-cause repair using the existing CLI wait helper while this PR was being validated. This PR was rebased onto that repair and retains only the importer change. Local broad tooling validation also reproduced three unchanged-baseline failures: two parser cases because the shared Vitest installation lacks the checked-in patch, and a cache-clear timeout. Shared pako/shiki/tslog declarations also block aggregate local type gates. Shared dependencies were not modified and no assertions/timeouts were weakened; clean CI on the final head is required before landing.
Final validation: CI33326072465 completed successfully on
6b2ad28c575137866985e20b358c3e059732b941. Fresh Codex review is clean. The latest ClawSweeper review was read in full: its pending CI, packaged-upgrade and dependency-contract confirmations are satisfied. Installed Kysely source was inspected directly in addition to the passing types and real SQL proof. Maintainer assessment: proceed with this bounded optimization under the existing synchronous appender ownership contract; it changes no material persistence semantics or store operating model.