Skip to content

feat(plugin-sdk): public transcript watermark API for context engines - #167481

Merged
jalehman merged 9 commits into
mainfrom
feat/context-engine-transcript-api
Oct 17, 2026
Merged

jalehman merged 9 commits into
mainfrom
feat/context-engine-transcript-api

Conversation

@jalehman

@jalehman jalehman commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Related: #160613

What Problem This Solves

Context-engine plugins can't track the transcript incrementally through a supported API. The watermark reader lives in a private-local SDK subpath with no types and no compatibility promise. When a transcript rewrite re-issues entry ids, plugins can't tell which new entry replaced which old one.

User Impact

Context-engine plugins get a typed public subpath, openclaw/plugin-sdk/context-engine-transcript-runtime. It provides a visible-message delta reader with an opaque cursor, documented reset reasons, an optional start at the latest same-session reset, and supersedesEntryId on messages that a rewrite re-appended. Lossless Claw uses this to replace per-turn full-transcript reconciliation, which measured 0.3–28.5 s per turn on large sessions, with millisecond delta reads (lossless-claw#1238). Existing callers see no change: default cursors and results are unchanged.

Why This Change Was Made

  • supersedesEntryId:

    • Branch-and-reappend rewrites (tool-result truncation, chat edits, rewriteTranscriptEntries) now record the replaced entry id in each re-appended message envelope. Repeated rewrites form a chain.
    • The field is optional, stored in event_json like appendMode, and has no schema or index change. Plain appends never carry it.
    • Rewrites made before this change have no marker.
  • Public subpath: it exports only five things:

    • readSessionTranscriptVisibleMessageDelta;
    • its params and result types;
    • SessionTranscriptMessageEntry;
    • SessionTranscriptReadFenceError.

    The params accept only agentId, sessionId, sessionKey and storePath, plus the cursor and page limits. session-transcript-runtime stays private-local and gains no exports.

  • start: "reset-window":

    • A fresh cursor begins at the latest same-session reset rather than position 0. It drains the tail kept by a preserve-tail reset, then everything after the reset row.
    • A later reset returns the new reason session_reset. Only reset-window cursors produce it.
    • The default "transcript" start encodes cursors exactly as before.
    • A newer reset outranks rewrite and generation changes. When both happen between reads, the reader reports session_reset, not anchor_missing or generation_mismatch. Cursors record the reset row's entry id, so resets can be compared across generation rotations.
  • SDK surface budget: raised by one entry point, five exports and one callable export over current main (153 / 3666 / 2128). A maintainer approved this.

Not covered: exposing the reset entry's id. This change also does not close the plugin-side race in #160613, where a reset can land between a read and the plugin's commit. session_reset makes that race detectable but does not close it.

Evidence

  • src/plugin-sdk/context-engine-transcript-runtime.test.ts imports through the public subpath against a real SQLite store. It covers:
    • a preserve-tail reset with paired and orphan tool results, drained across pages;
    • the default start still returning pre-reset history;
    • resuming after an append;
    • the fence cutoff, and the fence error when a cursor is already past it;
    • a clear reset producing session_reset while a default cursor continues.
  • transcript-rewrite.test.ts checks that every re-appended message carries supersedesEntryId equal to its source id, in both the visible read and the delta page. It checks that plain appends do not, and that a second rewrite after reload chains to the first copies. The test fails with the production change reverted.
  • After rebasing onto current main (2026-10-11):
    • pnpm tsgo:core: clean.
    • pnpm plugin-sdk:check-exports and pnpm plugin-sdk:surface:check: pass.
    • git diff --check: clean.
    • Focused suites: transcript-rewrite 30/30, the public subpath 2/2, active-events and visible-delta all pass.
  • SDK API diff against origin/main: 160 affected exports. Apart from the new subpath, every change is the optional supersedesEntryId field on SessionMessageEntry, reached through types that reference it. Acknowledgement digest: b903fecb (against merge base 599d0dec55e, after rebasing onto current main).
  • Review follow-up: real-store regressions for a rewrite followed by a clear reset, and for an in-place edit followed by a reset. Both fail on the previous head. check:database-worker-ratchet reports no growth in main-thread call sites. The max-lines, line-cap, assertion-safety, timeout-race and mock-export ratchets all pass.
  • Before rebasing: oxlint, oxfmt, docs link/anchor/MDX checks and the SDK subpath export check were clean.
  • Lossless used the cursor reader against copies of a production store (14.5k and 15.3k visible messages). Resuming with nothing new took 1.4–9.3 ms, against 3.5–28.5 s per call for full reconciliation.
  • Live proof on a Gateway serving this branch with Lossless as the context engine: see the PR comment "Live proof on e395e4550dd".
  • Failures inherited from main and not caused by this PR. Each fails identically on clean main at 599d0dec55e, reproduced locally:

Rebase onto main (d59a9b8ec84, 2026-10-17)

The branch was 5,422 commits behind. Conflicts were resolved as follows:

  • transcript-rewrite.test.ts: kept main's refactored file. The supersedesEntryId test still lives in transcript-rewrite-plugin-reads.test.ts.
  • SDK docs table and surface budgets: kept main's rows and budgets, then added this PR's row and its +1 entrypoint, +5 export and +1 function increments (156 / 3805 / 2206).

Main moved underneath the branch in two places, and two commits on top adapt to that:

  • fix(sessions): carry reset entry ids through prepared projection facts. Main now prepares latestIndexedReset from actor receipts without SQL (perf(sessions): reuse actor projection receipts for history reads #170127, perf(sessions): keep append receipts independent of transcript length #172462). Without this change, reset-window cursors read through that path would lose the reset entry id they compare across generation rotations, and core typecheck would fail. The facts type is now the single owner of the reset shape.
  • refactor(sessions): move closed reset intervals into a sibling module. session-accessor.sqlite-reset-window.ts reached 706 counted lines against its 700-line cap. resolveClosedResetInterval, which has one consumer (history-interval), moved unchanged to session-accessor.sqlite-closed-reset-interval.ts together with its worker-only classification. The visible delta core's private range, metadata and payload helpers are registered under its existing T3 inventory evidence. The SQLite worker ratchet reports no T1 growth.

Evidence on 9215147d9d9

  • pnpm test src/plugin-sdk/context-engine-transcript-runtime.test.ts src/agents/embedded-agent-runner/transcript-rewrite-plugin-reads.test.ts src/agents/embedded-agent-runner/transcript-rewrite.test.ts: 20 passed; 49 s wall time.

  • Ten sibling suites covering the visible delta, the cursor, projection facts, the bounded session manager and the transcript runtime: 100 passed; 65 s wall time.

  • Six history-read suites covering closed intervals (history events, legacy history events, reset-boundary race, reset header, query plan, input visibility): 31 passed; 21 s wall time.

  • pnpm check:changed: typecheck (core, extensions, scripts, test), the line-cap ratchet, the SQLite worker and dialect ratchets, the Plugin SDK exports and surface budget, plugin boundaries and format all pass.

  • Upgrade compatibility from published 2026.10.4 to this PR passes all 16 checks: settings, legacy transcript rows and default cursors are preserved, and supersedesEntryId survives a rewrite and a restart. See the upgrade proof.

  • Autoreview (codex gpt-5.6-sol, high, whole branch against origin/main) is clean: "patch is correct (0.98)", with no actionable findings.

  • PostgreSQL retained tail (b590695131b). Retained reset-window positions now go through jsonArrayElements with a BIGINT cast instead of SQLite's json_each. The new test src/infra/database-engine/context-engine-transcript-reset-window.postgres.test.ts fails without the fix (operator does not exist: bigint = json) and passes with it on local PostgreSQL 17.11.

  • Incognito parity (2676daa4bb4). The memory-actor reader now honors start: "reset-window": retained tail with tool pairs, then the suffix, with session_reset ranking first. Incognito rewrites now record supersedesEntryId. Two new public-reader tests in session-manager-incognito.test.ts fail without the fix and pass with it.

These gates still fail, and each fails identically on plain main, which this PR doesn't touch:

  • max-lines suppressions in ui/src/pages/{config,sessions} state files. The ratchet fails when main is compared against itself.
  • The infra tsgo shard root count (732 > 720). That shard covers only src/infra and src/media, and this PR changes no files there.
  • 20 dead exports and 38 max-lines lint errors. None of these files are in this PR's diff.

Inherited CI failures on 81dc4eb941b

Run 39031145558 had two red checks. Each failed the same way locally on the PR's exact base, d59a9b8ec84, without this PR:

Inherited CI failures on e04f6acc172

Run 39034822708 merged into main 42be4a448d7. Two new extension failures appeared there, and both are inherited from #175459:

  • checks-node-changed-extensions-bundle-17: extensions/discord/src/monitor/ingress.test.ts › "does not normalize or dispatch before the durable append completes" fails with expected "vi.fn()" to be called 1 times, but got 0 times.
  • checks-node-changed-extensions-bundle-11: extensions/signal/src/signal-ingress.test.ts › "propagates durable append failure before dispatch scheduling" fails with promise resolved "undefined" instead of rejecting.

Locally, both files pass on this PR's head, which sits on d59a9b8ec84 (15 passed). Both fail on plain main 42be4a448d7 (2 failed, 13 passed), and the same split holds for #175459 itself:

  • f966b28d497, the parent of perf(channels): claim idle ingress during durable admission #175459: 15 passed.

  • 3f76f0b62d1, "perf(channels): claim idle ingress during durable admission" (perf(channels): claim idle ingress during durable admission #175459): 2 failed.

  • PostgreSQL conformance (infra): src/infra/database-engine/git-backup.postgres.test.ts timed out after 120 s. The next test in the file then hit GatewayStateOwnerContentionError, which is fallout from the hung test.

    • The same PR code passed both PostgreSQL jobs in run 39031145558.
    • The last five scheduled main runs pass this job.
    • The test file is unchanged between the two merge bases.
    • This PR touches no database-engine, backup or PostgreSQL code.
    • This looks intermittent; it was not reproduced locally because PostgreSQL isn't available on this host.

Both ingress failures are fixed by #175579, now merged. The memory-core bundle-25 failure is fixed by #175566, now merged.

Inherited CI failure on d8f956937aa

  • checks-node-changed-compact-small-17: src/gateway/worker-environments/provider-crabbox-runtime-preflight.test.ts fails 15 of 25 tests.
    • Locally the file fails 15/25 on main 0f1c1247ca1 and passes 25/25 on this PR's head, which sits on d59a9b8ec84.
    • CI fails the same way on newer main 9513b30b786 (run 39041733748).
    • This PR touches no worker-environment or Crabbox code.

@clawsweeper

clawsweeper Bot commented Oct 8, 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 scripts Repository scripts agents Agent runtime and tooling plugin: file-transfer size: L labels Oct 8, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Adds a typed public transcript delta API with reset-aware cursors and replacement identifiers for rewritten messages.

Example: A context engine bootstraps after a clear reset with 40 transcript messages, including two post-reset messages.

  • Before: A fresh default drain returns all 40 messages.
  • After: A reset-window drain returns the two post-reset messages.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The scoped API change is supported by behavior and upgrade evidence with no remaining finding; overall scope remains partial relative to the broader reset-admission request.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Supplied output exercises a real Gateway reset and the built public reader against its copied transcript, including rewrite markers and Lossless reconciliation; later real-store regressions cover PostgreSQL retained tails and incognito parity, while the published-release Doctor upgrade preserves existing data and cursors.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Partial
User problem: Context engines otherwise depend on an unsupported reader and expensive full-history reconciliation, with ambiguous rewrite identities and pre-reset bootstrap history.
Reason: The maintainer-authored direction provides a narrow generic SDK capability for a demonstrated consumer and accurately uses Related rather than claiming complete reset-admission support.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it provides a useful supported transcript API, the prior findings are addressed, and no new actionable defect was found. Exact-head CI is still running.

Priority: P2
Reviewed head: d8f956937aa370ba38d440633d0b8105c2efcb93

Before merge

None.

Findings

None.

Agent review details

How this fits together

Context-engine plugins pass session identity, paging limits, and an optional cursor to the SDK; existing transcript owners return bounded message pages or explicit discontinuity results.

flowchart LR
  Plugin[Context engine plugin] --> SDK[Public transcript SDK]
  SDK --> Owner[Existing transcript read owner]
  Owner --> SQL[SQLite or PostgreSQL projection]
  Owner --> Memory[Incognito memory actor]
  SQL --> Page[Message page or reset result]
  Memory --> Page
  Page --> Plugin
Loading

Technical review

Best possible solution:

Land this supported cursor slice through the normal gates while retaining final reset-admission work in its existing follow-up.

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

This is an API feature: current-main source confirms the missing supported reset-window contract, and supplied Gateway and SDK output demonstrates the intended behavior.

Is this the best way to solve the issue?

The narrow facade reuses existing transcript owners, preserves default cursor behavior, and records replacement identity at the rewrite producer.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Generation-aware visible cursors keeps the original intent (4534446: Provide bounded, branch-safe incremental transcript reads with generation-aware discontinuities.)
  • Transcript read ownership keeps the original intent (d94fe35: Move transcript reads into retained database-worker owners while preserving source identity and admission fences.)
  • Atomic branch rewrites keeps the original intent (b0ae5b6: Publish complete replacement branches atomically and preserve their selected ancestry through resets and later appends.)
  • History and context reset selection keeps the original intent (34a430f: Keep reset history closed across compactions while distinguishing history presentation from model-context accounting.)
  • Prepared projection facts keeps the original intent (e9df67c: Reuse actor projection receipts instead of repeating transcript metadata queries.)
  • Portable transcript SQL keeps the original intent (93e8fe3: Run transcript readers on PostgreSQL as well as SQLite while retaining established semantics.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: Reviewed the merge-base-to-head hunks, including SDK exports, reset-window selection, rewrite markers, tests, documentation, and wrapper inventory. (src/plugin-sdk/context-engine-transcript-runtime.ts:4, d8f956937aa3)
  • Current main still lacks this contract: Current main's visible delta reader has no reset-window argument, and its cursor has no reset-boundary fields; the public subpath and replacement markers are absent. (src/plugin-sdk/session-transcript-runtime.ts:348, 38f411fbe793)
  • Previous findings resolved: The head includes portable numeric array expansion, incognito reset-window reads and rewrite markers, and the previously missing memory-reader wrapper component. (scripts/pr-lib/wrapper-components.txt:2539, d8f956937aa3)
  • Behavior proof and consumer credit: The author's live-proof comment records a real Gateway reset, built public-SDK reads against a private copy of the resulting database, persisted rewrite markers, and Lossless Claw reconciliation without duplicate imports; it explicitly distinguishes copied-store rewrites from running-Gateway rewrites. (e395e4550ddd)
  • Published-release upgrade proof: Read the complete upgrade comment, including its previously omitted script tail: published 2026.10.4 data passes through Doctor, preserves gateway.port=18999 and legacy rows, resumes published cursors, and retains rewrite markers across restart. (e04f6acc172d)
  • Feature history: Merged history identifies Josh Lehman's generation-aware cursor foundation and Peter Steinberger's subsequent worker, projection-receipt, incognito, and portable-SQL work. (src/plugin-sdk/session-transcript-runtime.ts, 38f411fbe793)

Likely related people:

  • Peter Steinberger: Raw commit e9df67c adds src/config/sessions/session-transcript-projection-facts.ts:19 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e9df67c62d00; files: src/config/sessions/session-transcript-projection-facts.ts)

PR surface

Source +359, Tests +769, Docs +146, Config +4, Other +23. Total +1301 across 40 files. Added test files: 3.

View PR surface stats
Area Files Added Removed Net
Source 21 663 304 +359
Tests 6 770 1 +769
Docs 6 151 5 +146
Config 1 4 0 +4
Generated 0 0 0 0
Other 6 29 6 +23
Total 40 1617 316 +1301

Review metrics

Metric Value Why it matters
Public SDK expansion 1 subpath, 5 exports, 1 callable export A narrow supported surface serves the demonstrated context-engine consumer without exposing transcript mutation APIs.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove merge-risk: 🚨 automation: Current PR review merge-risk labels are merge-risk: 🚨 compatibility.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a bounded context-engine integration improvement with concrete incremental-read and reset-selection value.
  • merge-risk: 🚨 compatibility: The PR establishes a supported public SDK contract and extends persisted message envelopes; the maintainer-authored direction and published-release upgrade proof address the compatibility gate.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-09T00:18:29.677Z sha e395e4550ddd81ea8859167046d88c7063f8b749 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-09T04:24:27.398Z sha 212b3a5 :: blocked before merge. :: none
  • reviewed 2026-10-11T12:10:07.834Z sha 2a59327 :: needs changes before merge. :: none
  • reviewed 2026-10-11T12:30:03.022Z sha 2a59327 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-11T12:55:54.811Z sha 2a59327 :: blocked before merge. :: none
  • reviewed 2026-10-17T13:32:51.850Z sha e04f6ac :: needs changes before merge. :: [P2] Use portable numeric array expansion for retained positions
  • reviewed 2026-10-17T14:13:28.129Z sha b590695 :: needs changes before merge. :: [P2] Honor reset-window cursors in the incognito reader | [P2] Record replacement IDs in incognito rewrites too
  • reviewed 2026-10-17T14:34:10.238Z sha 2676daa :: needs changes before merge. :: [P2] Include the extracted memory reader in the wrapper inventory

Reviewed October 17, 2026, 10:45 AM ET / 14:45 UTC (Revision 10).

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 9, 2026
@jalehman

jalehman commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Live proof on e395e4550dd

This responds to the review's "Missing end-to-end proof" item. Lossless-claw at 1c77bf8 was loaded as the context engine on a Gateway serving this head (openclaw --version → 2026.9.9 (e395e45), 22 plugins, no plugin load errors). All traffic went through a throwaway subagent session, not a user session.

Method. The transcript was produced live by real turns on openai/gpt-6-astra (embedded runtime), followed by a real sessions.reset (reason: "reset"). Reads and the rewrite then ran against a private copy of the agent database taken right after the live run, so nothing outside the throwaway session was written. Each call goes through this head's built dist/plugin-sdk/context-engine-transcript-runtime.js. The rewrite uses the runtime's rewriteTranscriptEntriesInSessionManager, the same path that tool-result truncation, replay repair, and server-endpoint compaction call.

Clear reset (/reset), live transcript:

Read Entries
start: "transcript" 40 (pre-reset history plus the post-reset exchange)
start: "reset-window" 2 (post-reset user + assistant only)

Persisted rewrite of the post-reset assistant entry 0854899e:

A. reset-window, maxMessages=1 (cursor C_mid): user 4dcd79b0
B. reset-window drain (cursor C_end):          user 4dcd79b0, assistant 0854899e
C. rewriteTranscriptEntriesInSessionManager(0854899e): changed=true rewrittenEntries=1
D. resume C_mid: assistant 23f603fb supersedes=0854899e  "after-reset (rewritten in place)"
E. resume C_end: <reset reason=anchor_missing>
F. drain from E's fresh cursor: user 4dcd79b0, assistant 23f603fb supersedes=0854899e
G. start=transcript fresh read: 40 entries
  • D: a cursor whose anchor survives the rewrite receives the re-appended copy with supersedesEntryId set.
  • E–F: a cursor anchored on the rewritten entry gets anchor_missing. The fresh cursor that comes with that reset still starts at the reset window (2 entries, not 40), which is the precedence fix in e395e45.

Plugin consumption. I fed step F's entries and Lossless's stored rows for the post-reset conversation into Lossless's real resync planner (planResync). It plans one restamp, of stored row seq 12 (0854899e) to the new id, with unimportedBeforeAnchor=0. So the rewrite is observed as an id restamp with no duplicate row.

What this live run also showed. Lossless 1c77bf8 still reads through session-transcript-runtime without start: "reset-window". On the live /reset, its first bootstrap ran before the post-reset message became visible, and it re-imported all 10 pre-reset rows into the new conversation (origin=fresh visible=38 postResetStart=0 imported=10). The host side was correct: chat.history and the reset-window read both return only the post-reset window. Filed as Martian-Engineering/lossless-claw#1244. Adopting this subpath and reset-window (Martian-Engineering/lossless-claw#1240) fixes it outright.

Not covered live:

  • Preserve-tail resets (idle, daily, stale cron) need session expiry, which I could not trigger without changing the shared Gateway config. They are covered only by context-engine-transcript-runtime.test.ts.
  • A rewrite inside the running Gateway itself. This deployment does not reach a rewrite producer for a throwaway session. Code-mode exec externalizes large tool results, so overflow truncation never fires, and Lossless owns compaction, so server-endpoint compaction is skipped. That is why step C ran on the copy.

Tests at this head: src/plugin-sdk/context-engine-transcript-runtime.test.ts (2 passed) and src/agents/embedded-agent-runner/transcript-rewrite-plugin-reads.test.ts (3 passed).

CI: checks-node-changed-2 failed only extensions/qa-lab/src/gateway-kill-restart-send.e2e.test.ts (SIGKILL recovery timeout after 120 s), which does not touch this change. I re-ran the failed job.

@jalehman
jalehman force-pushed the feat/context-engine-transcript-api branch from e395e45 to 212b3a5 Compare October 9, 2026 04:16
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 9, 2026
@jalehman
jalehman force-pushed the feat/context-engine-transcript-api branch from 212b3a5 to 2a59327 Compare October 11, 2026 11:56
@clawsweeper clawsweeper Bot added the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Oct 11, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 17, 2026
…sessions

Incognito sessions read and rewrite through the memory actor, which the
reset-window and supersedesEntryId changes had not reached. A fresh
reset-window drain returned pre-reset history and later resets never
reported session_reset, and incognito rewrites returned copies without
the entry id they replace.

Move the memory visible-delta reader into its own module and give it the
SQLite core's contract: reset-window cursors record the latest reset,
drain its retained tail with paired tool results, then the suffix, and
rank a newer reset first. Share the reset-boundary comparison through the
cursor owner. Carry supersedesEntryId through the memory append envelope
and the returned rewrite entries.
@jalehman

Copy link
Copy Markdown
Contributor Author

Incognito parity in 2676daa4bb4

This addresses both open review items: "Honor reset-window cursors in the incognito reader" and "Record replacement IDs in incognito rewrites too".

Reset-window reads

  • readSessionActorMemoryVisibleDelta now lives in its own module, session-actor-memory-visible-delta.ts, and follows the SQLite delta core's contract:
    • fresh reset-window cursors record the latest reset (raw seq plus entry id);
    • a cursor not yet past the reset drains the retained tail, keeping paired tool results and dropping orphans, then the suffix;
    • a newer reset ranks above generation and anchor discontinuities and returns session_reset;
    • a cursor that saw a reset after the current-turn admission throws the read-fence error.
  • Fence handling is otherwise unchanged. The memory window is already cut at the admission, so its latest reset honors the fence.
  • The reset-boundary comparison and the fresh-cursor stamping now live once, in the cursor owner session-accessor.sqlite-visible-cursor.ts, as hasVisibleResetBoundaryChanged and withVisibleResetBoundary. The SQLite core calls the same helpers.
  • The memory navigation exposes the all-role retained tail (retainedMessages). The history view still uses keptMessages, which is user and assistant only.

Rewrite markers

  • The memory session.transcript.rewrite handler passes supersedesEntryId: source.id to the memory append, which writes it into the envelope, and sets it on the returned entries.
  • SessionManager copies those entries into its loaded view with Object.assign, so a reopened view matches the stored rows and later rewrites chain.

Tests are in src/agents/sessions/session-manager-incognito.test.ts and use the public session-transcript-runtime readers on an incognito session.

Test Without the fix With the fix
Reset-window drain with a retained tool pair and an orphan, then a later reset reporting session_reset Fails: 8 ids, including pre-reset history, instead of 5 Passes
Repeated incognito rewrites chain supersedesEntryId across both readers Fails: markers missing Passes

The whole file passes 12/12 in 17 s wall time.

Other checks

  • 19 files across the memory actor, the incognito session manager, the SDK reset-window, visible-delta, rewrite-read and cursor suites: 175 passed.
  • The PostgreSQL retained-tail test still passes on local PostgreSQL 17.11.
  • tsgo:core and the agents-sessions test typecheck graph pass.
  • The SQLite dialect, line-cap and SQLite worker ratchets pass.
  • Type-aware oxlint and oxfmt pass.
  • The max-lines suppression ratchet reports only main's existing ui/ files.

@jalehman

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. and removed merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Oct 17, 2026
@jalehman

Copy link
Copy Markdown
Contributor Author

Wrapper inventory in d8f956937aa

This addresses "Include the extracted memory reader in the wrapper inventory": src/config/sessions/session-actor-memory-visible-delta.ts is now listed in scripts/pr-lib/wrapper-components.txt.

pnpm test test/scripts/eager-import-closure.test.ts --maxWorkers=1 failed 2 of 19 before the change ("Missing runtime imports" and "resolves wrapper package exports … from the extracted dependency context") and passes 19/19 after it.

The earlier session-accessor.sqlite-closed-reset-interval.ts extraction is outside the wrapper's eager closure, as is its source module, so it needs no entry.

@jalehman

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 automation 🚨 May affect CI, automerge, proof capture, label sync, or maintainer automation. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 17, 2026
@jalehman
jalehman merged commit cadffe5 into main Oct 17, 2026
254 of 257 checks passed
@jalehman
jalehman deleted the feat/context-engine-transcript-api branch October 17, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. plugin: file-transfer proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: XL 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