Skip to content

fix(sessions): rewind and switch without copying the transcript - #198903

Closed
obviyus wants to merge 10 commits into
mainfrom
openclaw/ember-crab
Closed

obviyus wants to merge 10 commits into
mainfrom
openclaw/ember-crab

Conversation

@obviyus

@obviyus obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Rewind and branch switch copied the entire transcript into a new session id just to append one ~200-byte leaf control row. On a production session with ~57k events (~357 MB) this:

#198786 bounded the worker memory of that copy. This change removes the copy for rewind and branch switch.

Why This Change Was Made

Why it copied. #110660 rotated the transcript identity so a stale live writer could not erase the leaf repoint with a snapshot replace. transcriptWriteScopeIsCurrent compares sessionId for every writer, while owner/lifecycle/writer-run fences are optional, so rotation was the only unconditional fence. Full snapshot replace is now test-support only; production writers append or use the suffix compare-and-swap.

New design.

  • Rewind/switch run one write transaction: validate the target with index seeks only (identity rows, active-path rows, one event row), rotate the transcript generation, append the one leaf row to the existing transcript, and repoint the active-path projection incrementally through the projection owner's suffix replacement. The index is never left dirty.
  • Fences that replace the identity rotation: transcript generation (delta cursors, context version, SessionManager.transcriptVersion, prompt cache), transcript_updated_at (suffix CAS), and a rotated lifecycleRevision (owner-fenced writers and local workspace custody, which compared (sessionId, lifecycleRevision) only).
  • Fork still creates a new session from a prefix and uses fix(sessions): keep large rewinds from exhausting the shared database worker #198786's bounded streaming reader as the single prefix-copy owner.
  • The memory-actor install owner (incognito/unbound sessions) follows the same identity contract.
  • Usage: rewound turns were really billed, so selectBilledTranscriptEvents (now the single owner for the three usage scans) bills the active path plus the selected and displaced path of every leaf control, minus inheritedThrough, and keeps the flat-transcript fallback.
  • Control UI: rewindChatHistory restores the composer as soon as sessions.rewind resolves, then reloads history and branches without blocking the refill.
  • Both catch blocks in sessions-rewind.ts now log the real failure cause; the client message is unchanged.

Contract change. A rewind or branch switch keeps sessionId; previousSessionId is no longer set by them. The Control UI already detects the cut from content (windowReset, decreased totals, entry publication), so no UI detection change was needed.

Evidence

Benchmark (ocx test, vitest from source; base side via ocx base merge-base), synthetic transcript shaped like production (~6.25 KB average event, some ~250 KB events):

Events (raw JSON) main rewind Branch rewind, first in process Branch rewind, warm Bytes written main → branch First chat.history after rewind main → branch
1,000 (6.1 MB) 746 ms 661 ms 23 ms 1.53 MB → 144 KB rebuilding → 1 ms
10,000 (61.4 MB) 4,284 ms 637 ms 20 ms 14.2 MB → 177 KB rebuilding → 1 ms
57,144 (351 MB) 12,367 ms 723 ms 24 ms 96.3 MB → 173 KB rebuilding → 1 ms

main = merge base d98f18ff7c3d (includes #198786). The branch's first-in-process time is flat across sizes: it is worker start (entry read, cold-restore check and commit round trips), the same cost a session-entry control write pays. Warm rewinds are the steady state. main's first read after the cut was measured on the pre-rebase base 896cc0cc44d7; #198786 does not change index rebuild.

End to end (ocx test, real Gateway RPC on an isolated throwaway gateway, 57,144 events, mock provider): rewind 190 ms, first chat.history 17 ms (no retry), second rewind 43 ms, branch switch 40 ms; the next model turn contains the new prompt and none of the rewound messages.

Stale-writer race test (session-accessor.sqlite-message-cut-fence.test.ts, ocx test): fails with the new fence removed (the stale append is admitted onto the pre-cut tail), passes with it.

Usage parity, base vs branch on the same histories via the real rewind/switch/fork path (ocx base merge-base / ocx test): identical for every scenario (16 / 16 / 39 / 55 cumulative; 206, 15, 75, 75, 35, 72 for the rebuilt fixtures). A legacy copied pair produced by base's own rewind reports 70 tokens on both sides, so sessions rewound before this change are not double counted.

Tests (ocx test): message-cut (incl. fence, native, native-binding, content, branches), sessions-rewind (incl. local-workspace, handoff, incognito, image-context), server-close rewind, usage (worker-refresh, rollup-scan, owner-attribution, legacy-copy-upgrade), #198786's oversized-history regression (now exercised through fork, plus an in-place rewind of the same transcript that succeeds), and the Control UI chat-history suites. Assertions that encoded the copy mechanism were rewritten to assert the same behavior through the new contract; every changed usage expectation was taken from a base measurement. tsgo:core, oxfmt, oxlint clean.

Packaging: ocx build --dts and pnpm test:install:smoke are blocked on this head by an inherited main failure in check-cli-bootstrap-imports (agents/identity-file.worker.js: 240 evaluated modules exceeds budget 220). The identical failure reproduces on the unmodified merge base d98f18ff7c3d; this PR does not touch that worker's import graph.

Follow-ups (not in this PR): other whole-transcript loads remain in parent fork, reset boundary, transcript mirror, session-manager reload, cost reporting and memory capture.

obviyus and others added 10 commits November 14, 2026 19:13
`sessions.rewind`, `sessions.fork` and `sessions.branches.switch` answered
UNAVAILABLE with a generic retry message and discarded the thrown error, so a
failing history mutation left no diagnosable trace. A production session with
~57k transcript events / ~357 MB could only be diagnosed by reading the SQLite
worker's own crash output.

Record the raw cause at both refusal points (upstream presence preparation and
the local mutation) and keep the client-facing message unchanged. The helper
lives in its own module because `sessions-rewind.ts` is already at the 700-line
oxlint ceiling.

Co-authored-by: obviyus <[email protected]>
Rewind and branch switch created a new session id and copied the whole
transcript tree into it, appending one ~200-byte `leaf` control. The copy also
required hydrating every event into the SQLite worker, so a session with ~57k
events / ~357 MB exhausted the worker heap and the RPC failed with UNAVAILABLE.

Rewind and switch now append the `leaf` control to the existing transcript in
one write transaction and keep their session id. Validation reads only what the
cut needs through index seeks: the target identity row, its active-path row, one
event payload for the role and editor text, and the active leaf. Cost no longer
depends on transcript size.

The session id was the only unconditional fence against writers holding pre-cut
state, so it is replaced by two fences every consumer already checks:
`transcript_rewrite_watermarks.generation` rotates, and the append bumps
`session_windows.transcript_updated_at` strictly, which fails the
compare-and-swap in `replaceTranscriptSuffixEventsSync`. The lifecycle revision
now rotates for in-place cuts too, which retires live local-workspace custody
and owner-fenced transcript writers. Local workspace custody therefore transfers
on the (session id, lifecycle revision) pair instead of the session id alone.

Fork is unchanged: it legitimately creates a session from a prefix.

Existing assertions that required a new session id or `previousSessionId`
encoded the copy's identity rotation, not rewind behavior, and are updated to
the generation/lifecycle contract.

Incomplete: the in-memory session actor is a second message-cut install owner
and still rotates the session id, and the local-workspace tests still encode
session-id custody transfer. See
~/Developer/.agents/handoffs/rewind-constant-cost/REPORT.md.

Co-authored-by: obviyus <[email protected]>
Rewind and branch switch created a new session id and copied the whole
transcript tree into it to append one ~200-byte `leaf` control. The copy needed
every event in the SQLite worker, so a session with ~57k events / ~351 MB
exhausted the worker heap and the RPC answered UNAVAILABLE. Smaller sessions
succeeded but held the write transaction for seconds and then left the active
path projection dirty, so the next `chat.history` was refused while it rebuilt.

Both message-cut install owners, the SQLite accessor and the in-memory session
actor, now append the `leaf` control to the existing transcript and keep the
session id. Validation reads only the target identity row, its active-path row,
one event payload for the role and editor text, and the active leaf, all through
existing indexes. The active-path projection is repointed incrementally in the
same transaction: the removed suffix after the common ancestor plus the selected
branch back to it, through the projection owner's existing suffix replacement.
A lagging projection still falls back to its reconcile owner.

The session id was the only unconditional fence against writers holding pre-cut
state, so it is replaced by fences the same writers already check: the transcript
generation rotates, the append bumps `session_windows.transcript_updated_at`
strictly, which fails the compare-and-swap in `replaceTranscriptSuffixEventsSync`,
and the lifecycle revision rotates, which retires owner-fenced transcript writers
and live local-workspace custody. Custody therefore transfers on the
(session id, lifecycle revision) pair instead of the session id alone.

The Control UI needed no detection change: `windowReset`, the decreased message
total and the ordinary entry publication are all content-derived. It now refills
the composer as soon as `sessions.rewind` resolves instead of after the history
and branch reloads.

Fork is unchanged: it legitimately creates a session from a prefix.

Measured with ocx test, base via ocx base merge-base, rewinding the newest user
message. Warm rewind 23/20/20 ms at 1k/10k/57k events and 144/177/173 KB written,
against 677/2358/11416 ms and 1.5/14.2/96.3 MB on the base commit; the first
history read after the cut is 1 ms here and refused as "rebuilding" on the base.
Gateway RPC end to end at 57k: rewind 190 ms, first `chat.history` 17 ms, second
rewind 43 ms, branch switch 40 ms.

Assertions that required a new session id, `previousSessionId` or a deferred
projection encoded the copy, not rewind behavior, and move to the generation,
lifecycle and incremental-repoint contract.

Known open decision: usage now reports a rewound session without the rewound
turns' tokens, because the usage scan follows the active path and no retired
window remains. `usage.sessions-usage-owner-attribution.integration.test.ts`
retains the previous contract and stays red to mark it.

Co-authored-by: obviyus <[email protected]>
An in-place rewind or branch switch leaves a completed turn off the active path,
and the usage scan counted only that path, so tokens that were really spent
disappeared from Usage. Before in-place cuts the same total came from the retired
copy, which kept counting the path that was active when it was retired.

`selectBilledTranscriptEvents` now owns that selection for every usage scan: the
active path plus every path a leaf control selected or displaced, minus paths an
upstream transcript already counted. A sibling branch that was never active is
not reachable that way and stays unbilled, matching the retired-copy accounting.
The three usage scans that each repeated
`dropInheritedTranscriptEvents(records, selectVisibleTranscriptEvents(records))`
now call that one owner.

Parity against the merge base, same rewind / branch switch / fork scenarios under
`ocx test` on `ocx base merge-base` and here: every reported token total matches
exactly (16 / 16 / 39 / 55 across the four scan points).

`planSessionMessageCut` becomes fork-only, since both install owners now reach it
only for a fork. Its rewind/switch whole-tree arms, `validateBranchTip`,
`uniqueEntryId` and the `copyPrefix` parameter are removed.

`session-cost-usage-worker-refresh.test.ts` keeps its assertions and is red in
five cases: it specifies the copy accounting model at unit level, which this
change replaces. See the handoff report for each case and its numbers.

Co-authored-by: obviyus <[email protected]>
Folds the read-only message-cut preflight into the reader module that owns the
indexed reads, and drops the speculative active-path predecessor fallback: an
append chains onto the active tip, so a target on the active path has its stored
parent on that path. Returns the projection facts columns to the rebuild module
that already owned them, instead of a separate extraction.

Adds the legacy upgrade test for the billing rule. Rows captured by running
switch-then-rewind on the merge base through ocx base merge-base, where each cut
copied the whole tree: the family reports 70 tokens there and 70 here, so
billing historically active paths does not recount a turn a copied window
already billed. Verified end to end first by replaying the dumped rows through
`sessions.usage` on both sides.

Co-authored-by: obviyus <[email protected]>
Rewind and branch switch append one leaf control to the existing transcript, so
the usage fixtures that encoded the retired copy no longer describe any real
history. Each rebuilt fixture is an in-place transcript, and every expected
total is what the base commit reports for the same user history through the real
rewind/switch path.

- worker-refresh: switch fixtures now use planInPlaceSessionMessageCut with the
  memory cut reader; the leaf-control rows bill the displaced branch (206, 15,
  35, 75, 75).
- worker-refresh: drop the test that counted a switch-created copy transcript.
- rollup-scan: rows carry the id and parent link a real appender writes, and the
  side append is the custom audit row the real writer appends without a parentId.

Co-authored-by: obviyus <[email protected]>
selectBilledTranscriptEvents replaced selectVisibleTranscriptEvents in the usage
scanners but dropped its flat fallback, so a transcript whose canonical rows
carry no id billed nothing: no path reaches an id-less row. Restore the same
rule the visible-event owner applies, which bills the whole transcript when no
path exists and no leaf control claims one.

Base reports 72 tokens for eight such rows; the new test asserts that number and
passes on 896cc0c.

Co-authored-by: obviyus <[email protected]>
Both delayed-receipt cases asserted that the stored row carried a new sessionId
once C3's transaction committed. Rewind and switch no longer rotate the session
id, so the same checkpoint now asserts the new incarnation the in-place cut
installs: the session id is unchanged, and the lifecycle revision and the
transcript generation are rotated, which are the fences that retire pre-cut
readers and writers. The settlement subject is untouched: the binding, the
identity publication and the native subscription are still asserted to be
unreleased at the gate and released only after the receipt arrives.

Co-authored-by: obviyus <[email protected]>
#198786 bounded the shared worker's heap during history cuts by reading the
navigation projection and streaming retained events one at a time. Rewind and
branch switch no longer copy anything, so only fork still needs that reader.

- fork keeps the bounded reader and all three budgets (8 MiB per event, 8 MiB
  retained, 100k events); its prefix copy is the single remaining prefix-copy
  owner, so no second implementation exists.
- the oversized-history regression now forks, which is the cut that reads
  payloads, and additionally asserts that an in-place rewind of the same
  oversized transcript succeeds.
- drop the reader's payloadBytes total: its only consumer was the non-fork
  synchronous-rebuild decision, which the in-place path replaced with a
  projection repoint.
- drop the per-event budget on the retired whole-transcript rewind preflight,
  which the indexed validator replaced.
- the memory benchmark verifies the in-place contract it now exercises: the
  session id is unchanged, one leaf control row was appended, and every pre-cut
  row still holds its payload.
- docs: rewind and branch switch keep the conversation and only move its active
  branch; the copy budget documents fork.

Co-authored-by: obviyus <[email protected]>
OpenClaw-Publication: 78055507-b9bf-869d-95f7-fabd1c672bd6
@clawsweeper

clawsweeper Bot commented Nov 14, 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 app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts size: XL labels Nov 14, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 14, 2026
@clawsweeper

clawsweeper Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR makes rewind and branch switching update the existing transcript instead of copying it into a new session.

Example: Rewind a conversation containing 57,144 events and about 351 MB of transcript data.

  • Before: The operation copies the transcript and can leave history unavailable while its index rebuilds.
  • After: The intended path appends one leaf control, updates the active projection, and restores the composer before history reload finishes.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The supplied Gateway measurements support the direction, but introduced correctness defects block merge; persisted transcript generations, session lifecycleRevision, and local workspace lifecycle_revision also lack a latest-stable upgrade run with existing data and settings preserved.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🧂 unranked krab (1/6) 6 actionable review findings remain.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Rewinding large conversations blocks other database work and delays history and composer recovery.
Reason: The reported production latency and measured reduction justify removing the copy, and maintainer authorship supplies direction approval.

Merge readiness

⛔ Blocked before merge - 8 items remain

Keep open: this useful performance repair has introduced memory, navigation, and workspace-preflight defects that block merge.

Priority: P2
Reviewed head: abdca14f8e40ac22d5abec74d14c3c27063032f0

Before merge

  • [P1] Stream branch payloads instead of collecting them all (P1) - Switching to a branch below the 4,000-event divergence limit loads every full event_json into one rows array before processing it. A valid branch containing 1,000 one-MiB events therefore materializes roughly one GiB in the shared worker, exceeding its 512-MiB heap and failing unrelated requests. These events fit the preceding implementation's per-event budget and were streamed individually. Bound retained bytes through the existing projection owner instead of bounding only event count.
  • [P1] Resolve the canonical predecessor before rewinding (P1) - identity.parent_id stores the raw payload parent, whereas scanSessionTranscriptTree normalizes parentless continuations, leaf references, and reset boundaries. For a supported older transcript containing u1 → a1 followed by parentless user u2, the active projection includes all three rows but u2's identity parent is null. Rewinding u2 now selects an empty branch instead of retaining u1 and a1. Read the predecessor from the active-path projection and preserve canonical navigation when traversing inactive branches.
  • [P2] Rotate the memory transcript generation for in-place cuts (P2) - The memory path installs the same session ID and appends a leaf without rotating transcript generation. selectSessionActorMemoryWindow preserves the existing transcript for that ID, and appendRaw/writeEvent reuses its generation. Consequently a pre-cut raw-delta cursor is accepted as an ordinary append cursor instead of receiving generation_mismatch, unlike the SQLite path and the replacement invalidation contract described by this PR. Rotate the memory version and watermark together through the memory owner.
  • [P1] Finish semantic preflight before retiring a workspace (P1) - When the projection needs reconciliation, this returns undefined, which callers interpret as permission to continue into prepareMessageCutLocalWorkspace. An invalid entry selection during that rebuilding interval can therefore retire the retained runtime before the committing planner rejects it. This reintroduces the invalid-request workspace interruption fixed by fix: invalid Rewind requests interrupt retained sandbox sessions #190219. Obtain a trustworthy preflight result or return a retryable refusal before workspace retirement.
  • [P2] Execute indexed workspace preflight in a database worker (P2) - Despite its name, mutateSessionHistoryInWorker is invoked from the isMainThread routing branch. The new synchronous refuseInPlaceSessionMessageCut call opens a read-only database and executes SQL and payload decoding on that Gateway thread for every worktree rewind or switch. The previous loadSessionTranscriptEvents path awaited worker-owned reads. Route this preflight through the existing worker operation; the repository's database rules explicitly prohibit adding main-thread database access.
  • [P2] Include the new reader in the trusted wrapper inventory (P2) - This runtime import reaches session-message-cut-target.ts from files extracted by scripts/pr, but the new module is absent from scripts/pr-lib/wrapper-components.txt. The extracted wrapper cannot resolve that dependency. Exact-head eager-import-closure CI reports this precise missing path. Add the dependency to the extraction inventory and verify the extracted runtime closure.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.
  • Explain or restore the original intent of Workspace validation before retirement - f833631: Invalid selections must leave retained runtimes and workspace edits untouched.

Findings

  • [P1] [P1] Stream branch payloads instead of collecting them all — src/config/sessions/session-transcript-active-path-repoint.ts:157-166
  • [P1] [P1] Resolve the canonical predecessor before rewinding — src/config/sessions/session-message-cut-target.ts:160-164
  • [P2] [P2] Rotate the memory transcript generation for in-place cuts — src/config/sessions/session-actor-memory-fork.ts:222-224

Provenance

  • Workspace validation before retirement changes intended behavior without addressing why it exists (f833631: Invalid selections must leave retained runtimes and workspace edits untouched.)

Tests

  • Missing end-to-end proof: Provide the changed flow through an isolated Gateway with a real agent/model and Control UI evidence of early composer restoration, redacting credentials, IPs, and non-public endpoints.
Agent review details

How this fits together

Control UI history actions call Gateway session RPCs, which coordinate workspace settlement and session storage mutations; transcript projections feed history and model context, while usage scanners retain billed turns.

flowchart TD
  A[Control UI history action] --> B[Gateway session RPC]
  B --> C[Workspace settlement]
  B --> D[Session cut planner]
  D --> E[SQLite or memory actor]
  E --> F[History and model context]
  E --> G[Usage accounting]
Loading

Technical review

Best possible solution:

Keep the in-place design while preserving canonical navigation, bounded payload processing, memory-generation invalidation, and worker-owned preflight.

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

Current main visibly copies the transcript for rewind and switch, matching the supplied large-history report; review findings follow reachable source paths, without executing target code.

Is this the best way to solve the issue?

Removing the copy addresses the expensive operation directly, but the replacement must preserve the existing navigation and lifecycle owners rather than assuming raw identities provide equivalent semantics.

Full review comments:

  • [P1] [P1] Stream branch payloads instead of collecting them all — src/config/sessions/session-transcript-active-path-repoint.ts:157-166
    Switching to a branch below the 4,000-event divergence limit loads every full event_json into one rows array before processing it. A valid branch containing 1,000 one-MiB events therefore materializes roughly one GiB in the shared worker, exceeding its 512-MiB heap and failing unrelated requests. These events fit the preceding implementation's per-event budget and were streamed individually. Bound retained bytes through the existing projection owner instead of bounding only event count.
    Confidence: 0.99
  • [P1] [P1] Resolve the canonical predecessor before rewinding — src/config/sessions/session-message-cut-target.ts:160-164
    identity.parent_id stores the raw payload parent, whereas scanSessionTranscriptTree normalizes parentless continuations, leaf references, and reset boundaries. For a supported older transcript containing u1 → a1 followed by parentless user u2, the active projection includes all three rows but u2's identity parent is null. Rewinding u2 now selects an empty branch instead of retaining u1 and a1. Read the predecessor from the active-path projection and preserve canonical navigation when traversing inactive branches.
    Confidence: 0.99
  • [P2] [P2] Rotate the memory transcript generation for in-place cuts — src/config/sessions/session-actor-memory-fork.ts:222-224
    The memory path installs the same session ID and appends a leaf without rotating transcript generation. selectSessionActorMemoryWindow preserves the existing transcript for that ID, and appendRaw/writeEvent reuses its generation. Consequently a pre-cut raw-delta cursor is accepted as an ordinary append cursor instead of receiving generation_mismatch, unlike the SQLite path and the replacement invalidation contract described by this PR. Rotate the memory version and watermark together through the memory owner.
    Confidence: 0.98
  • [P1] [P1] Finish semantic preflight before retiring a workspace — src/config/sessions/session-message-cut-target.ts:234-238
    When the projection needs reconciliation, this returns undefined, which callers interpret as permission to continue into prepareMessageCutLocalWorkspace. An invalid entry selection during that rebuilding interval can therefore retire the retained runtime before the committing planner rejects it. This reintroduces the invalid-request workspace interruption fixed by fix: invalid Rewind requests interrupt retained sandbox sessions #190219. Obtain a trustworthy preflight result or return a retryable refusal before workspace retirement.
    Confidence: 0.99
  • [P2] [P2] Execute indexed workspace preflight in a database worker — src/config/sessions/session-message-cut.ts:100-108
    Despite its name, mutateSessionHistoryInWorker is invoked from the isMainThread routing branch. The new synchronous refuseInPlaceSessionMessageCut call opens a read-only database and executes SQL and payload decoding on that Gateway thread for every worktree rewind or switch. The previous loadSessionTranscriptEvents path awaited worker-owned reads. Route this preflight through the existing worker operation; the repository's database rules explicitly prohibit adding main-thread database access.
    Confidence: 0.99
  • [P2] [P2] Include the new reader in the trusted wrapper inventory — src/config/sessions/session-actor-memory-fork.ts:30
    This runtime import reaches session-message-cut-target.ts from files extracted by scripts/pr, but the new module is absent from scripts/pr-lib/wrapper-components.txt. The extracted wrapper cannot resolve that dependency. Exact-head eager-import-closure CI reports this precise missing path. Add the dependency to the extraction inventory and verify the extracted runtime closure.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Transcript identity rotation changes intended behavior with a stated reason (0acece4: The original feature rotated identity to prevent stale SessionManager snapshot writes from undoing a rewind.)
  • Bounded history copying changes intended behavior with a stated reason (b62210f: Large cuts exhausted the shared worker; navigation projection and single-event hydration bounded retained memory.)
  • Usage lineage and copied-history exclusion keeps the original intent (f31477f: Copied transcript paths must count once across source and successor windows.)
  • Composer replacement ownership keeps the original intent (bc6c22e: Rewind completion must preserve newer composer edits, attachments, and competing-pane drafts.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/config/sessions/session-accessor.sqlite-message-cut.test.ts src/config/sessions/session-accessor.sqlite-message-cut-fence.test.ts src/config/sessions/session-actor-memory-fork.test.ts src/config/sessions/session-lifecycle-memory.test.ts
  • pnpm test src/gateway/server-methods/sessions-rewind.local-workspace.test.ts src/gateway/server-methods/sessions-rewind.local-workspace-handoff.test.ts src/gateway/server-methods/sessions-rewind.incognito.test.ts
  • pnpm test src/infra/session-cost-usage-worker-refresh.test.ts src/infra/session-cost-usage-rollup-scan.test.ts src/infra/session-cost-usage.legacy-copy-upgrade.test.ts
  • pnpm test test/scripts/eager-import-closure.test.ts
  • pnpm check:changed

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit bc6c22e adds ui/src/pages/chat/chat-history-actions.ts:229 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: bc6c22ebafe3; files: ui/src/pages/chat/chat-history-actions.ts)

PR surface

Source +643, Tests +235, Docs +2, Other +12. Total +892 across 34 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 17 928 285 +643
Tests 15 417 182 +235
Docs 1 4 2 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 1 23 11 +12
Total 34 1372 480 +892

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: This addresses substantial latency in large-history navigation; the preceding merged repair already bounds the original copy's worker memory.
  • add merge-risk: 🚨 session-state: Raw-parent navigation and incomplete memory invalidation can produce incorrect history-cut behavior.
  • add merge-risk: 🚨 availability: Branch switching can materialize enough payload data to exhaust the shared database worker.
  • add merge-risk: 🚨 automation: The new runtime dependency is absent from the trusted PR wrapper extraction inventory.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦐 gold shrimp and patch quality is 🧂 unranked krab.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This addresses substantial latency in large-history navigation; the preceding merged repair already bounds the original copy's worker memory.
  • merge-risk: 🚨 session-state: Raw-parent navigation and incomplete memory invalidation can produce incorrect history-cut behavior.
  • merge-risk: 🚨 availability: Branch switching can materialize enough payload data to exhaust the shared database worker.
  • merge-risk: 🚨 automation: The new runtime dependency is absent from the trusted PR wrapper extraction inventory.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦐 gold shrimp and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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.

Reviewed November 14, 2026, 9:30 AM ET / 14:30 UTC.

@obviyus

obviyus commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator Author

Superseded by #198929 (same change plus the CI fixes; the publisher could not extend this branch).

@obviyus obviyus closed this Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant