Skip to content

improve: reduce transcript import watermark overhead - #133403

Merged
steipete merged 1 commit into
mainfrom
codex/importer-performance-pass-five
Aug 30, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/importer-performance-pass-five

Conversation

@steipete

@steipete steipete commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

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 candidate 851fe4c1d87828b178d19eebe6381c80740be8ad. The final rebased importer owner and its append/staging/SQL/schema dependencies are byte-identical to that tested candidate.

Synthetic shape Before median After median Wall reduction CPU reduction
One 100,000-event transcript 6085.0ms 5782.8ms 5.0% 6.1%
100 sessions × 100 events 649.5ms 601.8ms 7.4% 6.4%
100 branching sessions × 100 events 965.6ms 925.9ms 4.1% 4.5%

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 stable 2026.7.1-2→candidate 2026.8.1 passed 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.

@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 30, 2026
@steipete
steipete marked this pull request as ready for review August 30, 2026 17:08
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 1:51 PM ET / 17:51 UTC.

ClawSweeper review

What this changes

The PR upserts a transcript projection watermark on initialization and directly updates the known row for later events in the same synchronous import batch.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

No 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
Reviewed head: 6b2ad28c575137866985e20b358c3e059732b941
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused net-negative implementation preserves the established transaction and rebuild boundaries; only ordinary exact-head merge gates remain.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository-state author association is MEMBER, so the external-contributor proof gate does not apply; the PR body nevertheless describes after-fix importer and packaged-upgrade observations for this transaction owner.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository-state author association is MEMBER, so the external-contributor proof gate does not apply; the PR body nevertheless describes after-fix importer and packaged-upgrade observations for this transaction owner.
Evidence reviewed 6 items Introduced write-path change: The verified introduced diff changes only the watermark writer: later known-row writes use UPDATE, while the initialization branch retains INSERT ... ON CONFLICT.
Transaction-local ownership: The batch importer stages and validates source data before entering its synchronous write transaction; its iterator only reads the private stage while the appender retains the transaction-local cursor.
Appender invariant and sibling lifecycle paths: The appender creates the first watermark with UPSERT and uses UPDATE only after its closure holds the returned state; dirty marking and projection rebuilds still call the default UPSERT path.
Findings None None.
Security None None.

How this fits together

Transcript 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
Loading

Decision needed

Question Recommendation
After exact-head checks finish, should the sessions owner approve this durable watermark-write optimization for landing? Approve after green checks: Accept the UPDATE-after-initialization path because the importer stages input before a synchronous transaction and lifecycle paths retain UPSERT.

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

  • Resolve merge risk (P1) - The supplied snapshot still has incomplete exact-head checks, so normal merge gates remain outstanding.
  • Resolve merge risk (P1) - This node_modules-free checkout and unavailable GitHub DNS prevented direct inspection of the installed Kysely implementation; exact-head CI remains the independent dependency-contract check.
  • Complete next step (P2) - No mechanical repair is needed; normal exact-head validation and protected maintainer review remain.
Agent review details

Security

None.

PR surface

Source -5. Total -5 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 29 34 -5
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 29 34 -5

Review metrics

Metric Value Why it matters
Production versus test delta production +29/-34 (net -5); tests 0 The optimization reduces duplicated watermark-value construction while preserving the existing projection behavior tests.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    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.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

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

Labels

Label justifications:

  • P3: This is a small internal import-performance improvement with no demonstrated behavioral change for ordinary sessions.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The repository-state author association is MEMBER, so the external-contributor proof gate does not apply; the PR body nevertheless describes after-fix importer and packaged-upgrade observations for this transaction owner.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-30T17:23:16.378Z sha 851fe4c1d87828b178d19eebe6381c80740be8ad :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Aug 30, 2026
@steipete
steipete force-pushed the codex/importer-performance-pass-five branch from 9343a30 to 6b2ad28 Compare August 30, 2026 17:43
@openclaw-barnacle openclaw-barnacle Bot removed the scripts Repository scripts label Aug 30, 2026
@steipete
steipete merged commit 3988315 into main Aug 30, 2026
246 of 247 checks passed
@steipete
steipete deleted the codex/importer-performance-pass-five branch August 30, 2026 18:04
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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