Skip to content

perf(sessions): bound transcript append writer residency - #171540

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-micro-transcript-append-sql-20260919
Oct 14, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-micro-transcript-append-sql-20260919

Conversation

@steipete

@steipete steipete commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Large transcript append streams progressively slow the agent database writer and can exhaust its heap, delaying other session writes behind it.

User Impact

Appends keep bounded writer residency while preserving exact persisted transcript bytes, commit receipts, retry identity, model-context navigation, and byte accounting. Slow transaction warnings now include context.payloadBytes for the primary prepared event/message (or summed turn messages; optional initialization/header excluded). No schema, stored format, or configuration changes.

Why This Change Was Made

The append owner added full parsed events to both the actor payload map and navigation. Residency then serialized the entire retained state on every settlement to enforce its 8 MiB budget. Large bodies therefore caused increasing JavaScript work, eviction/re-hydration, and eventually worker heap exhaustion. phases.sqlMs includes JavaScript executed inside the transaction; it is not a sum of SQLite statement timings.

Reuse the existing memory actor navigation projector for durable appends. Build detached receipts first, retain exact context byte metadata, then discard settled payload bodies at the residency owner. Retry reads use the existing canonical SQLite fallback. Remove the obsolete resident-payload rewrite loop and move message identity lookup into its existing owner.

Production LOC: +42 (153 added / 111 removed, excluding tests/support/docs). The required new payload-size diagnostic contract needs command-shape handling and forwarding through worker transaction contexts; the navigation projector and identity lookup are moves. This adds no second cache or residency mechanism.

Evidence

Synthetic production-shaped fixture on an isolated 128-core Linux sandbox: 5,000 sessions, 6,000 retained runs, approvals/cron/projects/worktrees; initial agent database 4,641,595,392 bytes. All commands restricted to allocated CPUs 64–127, 64 GiB memory, nice/idle I/O, isolated state. No production databases or services accessed. Node 26.8.2. Actual durable actor transport and writer worker; 6 MiB cache-TTL events. Five initial append samples excluded for lazy startup/warmup.

Measurement Before After
Sequential append writer phase, p50 / p99 (35 samples, matched 11-event sessions) 63.90 / 112.96 ms 22.72 / 70.80 ms
Sequential append round trip, p50 / p99 77.04 / 133.90 ms 32.57 / 83.58 ms
20 simultaneous appends: queue-to-worker-start wait, p50 / p99 (matched 2-event sessions) 443.40 / 887.82 ms 435.57 / 702.10 ms
Same burst: writer phase, p50 / p99 36.44 / 86.44 ms 25.22 / 67.38 ms

Queue measurement includes actor dispatch/admission and worker serialization, rather than isolating only SQLite reservation wait. No individual SQLite statement exceeded 50 ms during these measured runs. In an 80-event session stress case the old worker exhausted its heap on append 56 (preceding writer-phase p99 189.80 ms); the changed worker completed all 80 appends on a matched 80-event session, p50 27.54 ms / p99 104.79 ms after warmup. The median improvement is clear; the stress p99 narrowly exceeds 100 ms. This does not reproduce or claim to eliminate every reported 0.94–1.44 s production hold, nor qualify a 43 GB cold database. Payload attribution will help distinguish remaining causes.

Regression fails on the old retention behavior: reading another session forces the large append actor to rehydrate. Changed behavior preserves residency, exact receipt/stored bytes, UTF-8 byte totals, ancestry, and warm/cold context equivalence. Existing rewrite, receipt, append-postimage, kernel, context-metadata, memory-history, and transcript-payload contracts passed focused checks.

Local proof: changed-file oxfmt, changed-file repo oxlint, git diff --check; focused pnpm test <files> --maxWorkers=1 only. Final residency/kernel: 7 passed; rewrite/receipt/append-postimage: 17 passed; earlier context-metadata/memory-history/payload contracts passed. No Testbox/Crabbox lease: operator policy assigns full typecheck, suites, and closure gates to PR CI.

Review: independent subagent review (autoreview route unavailable), scoped clean at P2+. Autoreview refused because its requested provider did not match operator config; config unchanged. Full PR CI passed on the corrected head.

CI follow-up: initial head 43dc994ee299e17ab0553f3be4a2a01b8a089438 passed every selected broad gate except assertion-safety. Its existing safety note was above the projection call rather than the nested assertion. Commit c21b2437b187 places the note immediately beside the same assertion; no behavior/types/assertions changed. Targeted check-assertion-safety-ratchet now passes, changed-file formatting/lint pass, and the independent reviewer approved the exact correction. This failure was caused by this diff and was fixed; it is not being treated as inherited. Full CI run 38499135883 and the required repository review gate passed on corrected head c21b2437b187eb153660457567330ad75e92b579. Merged as a15b5c7109401c35c8fad9edeb3e28de913f7e0f.

Keep settled append bodies in receipts and canonical SQLite rather than actor residency. Reuse the existing navigation projector and carry exact context byte metadata through settlement. Large append streams stay bounded instead of serializing retained history or exhausting the writer heap.

Report primary append payloadBytes in slow SQLite hold diagnostics. SQL phase timing includes JavaScript work inside the transaction. No schema or transcript format changes.

Validated focused residency, kernel, context metadata, memory history, payload, rewrite, receipt, and append postimage contracts. Independent subagent review clean after autoreview route refusal. Team-shaped synthetic 4.6 GB database: 6 MiB append worker p50 63.9 to 22.7 ms, round-trip p99 133.9 to 83.6 ms.
@clawsweeper

clawsweeper Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review October 14, 2026 01:51
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-14T01:56:49.337148Z 43dc994 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M labels Oct 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 43dc994ee2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +71 to +75
if (
command.type !== "session.actor.appendTranscriptEvent" &&
command.type !== "session.actor.appendToolResult"
) {
return undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Attribute payloads for every turn-writing phase

When a large user or assistant message is persisted through session.actor.acceptInput, session.actor.adoptRun, or the turn-bearing form of session.actor.completeTurn, this guard returns before inspecting the command's turn or append, even though those phases execute the same transcript writers. Their slow-transaction warnings therefore omit context.payloadBytes, leaving the primary production paths that can incur large-payload holds without the attribution introduced by this change; handle every phase whose contract can carry a SessionTurnPlan or SessionActorAppend.

Useful? React with 👍 / 👎.

@steipete
steipete merged commit a15b5c7 into main Oct 14, 2026
130 of 131 checks passed
@steipete
steipete deleted the steipete/perf-micro-transcript-append-sql-20260919 branch October 14, 2026 02:23
vincentkoc added a commit that referenced this pull request Oct 14, 2026
* commit '976cc974fab1912c696d1101bd17a1abf05eb77e': (82 commits)
  perf(sessions): reuse rows after unrelated plugin reloads (#171519)
  fix(doctor): treat an explicit Skill Workshop deny as an opt-out (#171314)
  perf(sessions): bound transcript append writer residency (#171540)
  fix(workboard): a review card with done parents cannot be claimed (#171414)
  fix: reduce New Session typing lag after models load (#171530)
  test(gateway): isolate external auth refresh fixture writes
  perf(plugins): filter agent event subscriptions by phase before cloning (#171534)
  refactor(ui): render retained chat panes with Solid (#169835)
  fix(ui): match rail pin icon size and selection fill to rail buttons (#171517)
  fix(auth): move bundled inference and logout SQLite into workers (#171510)
  fix(ci): include desktop staging tests in Knip graph
  test(ui): await terminal panel commit before handoff readiness
  fix(update): reclaim runtimes under protected systemd user managers (#171488)
  fix(sdk): account for async model auth preparation
  fix(update): release the writer during delayed host admission (#171493)
  fix(update): resume progress after offline maintenance (#171454)
  fix: identify update snapshot failures before activation (#171457)
  fix(memory): recover worker-backed managers after terminal worker loss (#171494)
  fix(talk): keep accepted agent work after client failures (#171377)
  fix(qa): generate canonical Code Mode matrix config (#171520)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…1540)

* perf(sessions): bound transcript append writer residency

Keep settled append bodies in receipts and canonical SQLite rather than actor residency. Reuse the existing navigation projector and carry exact context byte metadata through settlement. Large append streams stay bounded instead of serializing retained history or exhausting the writer heap.

Report primary append payloadBytes in slow SQLite hold diagnostics. SQL phase timing includes JavaScript work inside the transaction. No schema or transcript format changes.

Validated focused residency, kernel, context metadata, memory history, payload, rewrite, receipt, and append postimage contracts. Independent subagent review clean after autoreview route refusal. Team-shaped synthetic 4.6 GB database: 6 MiB append worker p50 63.9 to 22.7 ms, round-trip p99 133.9 to 83.6 ms.

* fix(ci): attach navigation safety note to its assertion
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 size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant