Skip to content

feat: bound transcript reads across replacements - #110374

Merged
jalehman merged 12 commits into
mainfrom
josh/clawdbot-d02.1.9.1.40-db6-generation-cursors
Jul 18, 2026
Merged

jalehman merged 12 commits into
mainfrom
josh/clawdbot-d02.1.9.1.40-db6-generation-cursors

Conversation

@jalehman

@jalehman jalehman commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

AI-assisted: implementation, tests, and review were completed with Codex; the author understands and validated the change.

What Problem This Solves

Transcript consumers currently must load complete transcripts or treat sequence numbers as resumable watermarks. Sequence numbers become ambiguous when a transcript is destructively replaced and resequenced from zero, while full reads create avoidable allocation and latency on large transcripts. Context engines also need branch-safe visible messages without independently reconstructing OpenClaw's transcript tree.

Why This Change Was Made

This adds the smallest generation-aware foundation: schema v13 stores one durable token for each materialized raw transcript, append preserves it, and destructive replacement rotates it. Bounded Plugin SDK reads expose separate raw-event and visible-message cursor contracts. Both limit pages by count and stored JSONL bytes; the visible cursor reuses the existing materialized active projection and reports typed reset or projection-unavailable outcomes. The only production adopter remains optional active-memory transcript inspection. Codex/Copilot mirrors, core HTTP/SSE history, transcript repair, and complete-artifact recall remain unchanged.

Changes walkthrough

Surface Change
src/state/openclaw-agent-schema.sql Adds STRICT generation state in schema v13
src/state/openclaw-agent-db.ts Backfills one token per existing transcript
src/config/sessions/session-accessor.sqlite-transcript-state.ts Owns generation creation and rotation
src/config/sessions/session-accessor.sqlite-delta.ts Implements bounded generation-aware raw pages
src/config/sessions/session-accessor.sqlite-active-events.ts Implements bounded forward visible-message pages
src/config/sessions/session-accessor.* Exposes storage-neutral cursor contracts
src/plugin-sdk/session-transcript-runtime.ts Publishes raw and visible cursor APIs
extensions/active-memory/transcript.ts Bounds optional transcript inspection reads
src/**/*.test.ts Proves migration, cursor, lifecycle, and query plans
scripts/bench-transcript-cursors.ts Benchmarks 100k-event bootstrap and delta paths
docs/plugins/* Documents cursor semantics and read bounds

User Impact

Plugin developers can resume bounded raw transcript reads across appends and receive an explicit reset after replacement. Context engines can independently consume bounded, branch-safe visible messages from oldest to newest, persist an opaque cursor, resume linear appends, and rebuild on a typed reset without duplicating active-branch rules. A rebuilding projection returns a typed unavailable result. Active-memory inspection no longer materializes a complete raw transcript before applying its limits. Core session restoration and user-facing history behavior do not change.

Evidence

  • File-era doctor import reaches schema v13 and materializes a generation in one invocation.
  • Existing v8, v9, v10, and v11 migration fixtures converge to schema v13; a direct v12 fixture proves existing main-era databases receive the generation table and backfill in one invocation.
  • Query-plan assertions pin generation lookup, forward raw ranges, visible metadata/payload pages, normalized parent lookup, and frontier lookup to existing indexes without transcript scans or temporary ordering.
  • Focused SDK/projection/query-plan tests pass: 22 SDK tests, 8 active-projection tests, and 2 query-plan tests.
  • A public-SDK context-engine lifecycle test proves bounded bootstrap, append resume, replacement reset, and rebuild.
  • Plugin SDK surface, generated Kysely schema, docs MDX, formatting, and git diff --check pass.
  • pnpm check:changed passes on Blacksmith Testbox, including schema/API generation, SDK budgets, full typecheck, lint, database-first guards, and import-cycle checks.
  • Mandatory autoreview is clean with no accepted/actionable findings (0.88 confidence); strict maintainability review is also clean.

100k-event benchmark on Blacksmith Testbox, 12 runs:

Operation p50 p95
Bounded bootstrap (1,000 events) 0.936 ms 2.855 ms
Active-memory bounds (2,000 events) 1.613 ms 4.466 ms
20-event frontier delta 0.083 ms 0.321 ms
Full 100,020-event read 51.690 ms 56.518 ms

Explicit follow-ups, not part of this PR: indexed fact helpers with concrete callers, visible HTTP/SSE keyset pagination, and any further internal caller adoption.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation scripts Repository scripts commands Command implementations plugin: file-transfer size: L maintainer Maintainer-authored PR labels Jul 18, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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. labels Jul 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed July 18, 2026, 2:38 PM ET / 18:38 UTC.

Summary
The branch adds generation-aware, count- and byte-bounded raw and visible transcript cursor APIs, persists transcript generations in the agent SQLite database, and makes active-memory inspection use bounded raw reads.

PR surface: Source +747, Tests +862, Docs +4, Config 0, Generated +14, Other +191. Total +1818 across 32 files.

Reproducibility: not applicable. This PR adds a new bounded transcript cursor capability rather than fixing a currently documented failing behavior. The supplied lifecycle and benchmark evidence is useful implementation proof, but it is not a current-main bug reproduction.

Review metrics: 1 noteworthy metric.

  • Persistent/API surface: 1 agent-schema version bump; 1 new durable table; 2 public SDK cursor readers. These are durable upgrade and external-plugin contract commitments, not an isolated active-memory optimization.

Stored data model
Persistent data-model change detected: database schema: src/commands/doctor-session-sqlite.test.ts, database schema: src/state/openclaw-agent-db.test.ts, database schema: src/state/openclaw-agent-schema.generated.ts, database schema: src/state/openclaw-agent-schema.sql, migration/backfill/repair: src/commands/doctor-session-sqlite.test.ts, migration/backfill/repair: src/state/openclaw-agent-db.test.ts, and 27 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: canonical
Canonical: #110374
Summary: This PR is the stated foundation for two distinct stacked transcript-performance follow-ups, rather than a duplicate of either one.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🦞 diamond lobster
Patch quality: 🦐 gold shrimp
Result: needs maintainer review before merge.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Obtain an explicit maintainer decision on whether these cursor APIs are a permanent Plugin SDK contract.
  • Revise the persistence design to keep the additive generation table out of the agent schema-version bump, or obtain an explicit exception with upgrade rationale.

Risk before merge

  • [P1] Merging the v13 bump upgrades existing agent databases for an additive table and can make downgrade or mixed-version recovery depend on a migration that repository policy says should remain version-neutral.
  • [P1] Publishing opaque raw and visible cursor contracts creates a Plugin SDK compatibility commitment for cursor reset, projection availability, byte limits, and persisted plugin state before maintainers have accepted that API direction.

Maintainer options:

  1. Narrow the change before merge (recommended)
    Remove the schema-version bump and defer the public cursor exports, leaving only a bounded internal owner path if that can satisfy active-memory safely.
  2. Accept a supported SDK contract
    A maintainer can explicitly sponsor the cursor contract, then require a version-neutral additive migration design and focused downgrade/upgrade contract coverage.
  3. Pause the parent stack
    Pause this PR and its dependent transcript proposals until the platform direction is approved, rather than merging an API foundation without committed consumers.

Next step before merge

  • [P2] A human must decide the durable database and Plugin SDK contract direction; no narrow automated repair can safely make that product choice.

Maintainer decision needed

  • Question: Should OpenClaw establish generation-aware raw and visible transcript cursors as permanent public Plugin SDK APIs, with persistent generation state, or keep bounded transcript reading internal until concrete owner plugins require a shared contract?
  • Rationale: The implementation can be mechanically tested, but only maintainers can choose whether these exported cursor semantics and persisted upgrade behavior are a supported long-term platform contract.
  • Likely owner: steipete — This is an architecture and public-platform decision spanning agent persistence, plugin compatibility, and the linked follow-up stack.
  • Options:
    • Keep the scope internal (recommended): Retain or rework the active-memory bounded read behind an owner-specific/internal seam and defer public cursors plus durable generation state until a concrete shared caller requires them.
    • Sponsor the public contract: Explicitly accept the raw and visible cursor APIs, document their reset and upgrade guarantees, and revise persistence to follow the additive-table migration policy before merge.
    • Pause the stack: Close or pause this foundation and its dependent proposals until maintainers define a transcript pagination and plugin API roadmap.

Security
Cleared: The diff adds no dependency source, lifecycle hook, secret handling, workflow permission, or artifact-execution surface; the primary concerns are persisted-state and Plugin SDK compatibility.

Review findings

  • [P1] Keep the additive generation table out of a schema-version bump — package.json:7
  • [P1] Obtain approval before exporting transcript cursor APIs — src/plugin-sdk/session-transcript-runtime.ts:67-77
Review details

Best possible solution:

Keep bounded active-memory reading narrowly owned for now, and split any durable generation-backed public cursor API into a maintainer-sponsored design that uses the repository’s additive-table migration policy and defines the permanent Plugin SDK contract.

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

Not applicable: this PR adds a new bounded transcript cursor capability rather than fixing a currently documented failing behavior. The supplied lifecycle and benchmark evidence is useful implementation proof, but it is not a current-main bug reproduction.

Is this the best way to solve the issue?

No: bounded reads are a valid goal, but the branch is not yet the best solution because it commits to a public Plugin SDK and a schema-version migration before maintainers choose that platform direction. A narrower owner-local read path or a sponsored API design is safer.

Full review comments:

  • [P1] Keep the additive generation table out of a schema-version bump — package.json:7
    The new table is additive, but this line upgrades every existing agent database to v13. Repository policy requires additive tables to use an idempotent feature-owned ensure and reserve schema bumps for changes older readers cannot tolerate; otherwise users who downgrade can encounter an unnecessary version barrier.
    Confidence: 0.98
  • [P1] Obtain approval before exporting transcript cursor APIs — src/plugin-sdk/session-transcript-runtime.ts:67-77
    These new exports create permanent Plugin SDK contracts for persisted cursors, reset reasons, projection availability, and bounds. The only production adopter is active-memory and the linked consumers are still follow-up proposals, so a maintainer must first accept this public API direction rather than landing it as an implementation-only change.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1ca6b6ff6722.

Label changes

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: This is a substantial performance/platform improvement, but the evidence does not show an emergency regression in current user workflows.
  • merge-risk: 🚨 compatibility: The PR advances the agent database schema and exports new Plugin SDK APIs that third-party plugins may persist and depend on.
  • merge-risk: 🚨 session-state: Transcript replacement now rotates persistent generation state and changes how consumers must recover from cursor discontinuities.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body provides after-fix Blacksmith live benchmark output plus bounded bootstrap, append, replacement-reset, and rebuild lifecycle evidence; no additional contributor proof is required for this review cycle.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix Blacksmith live benchmark output plus bounded bootstrap, append, replacement-reset, and rebuild lifecycle evidence; no additional contributor proof is required for this review cycle.
Evidence reviewed

PR surface:

Source +747, Tests +862, Docs +4, Config 0, Generated +14, Other +191. Total +1818 across 32 files.

View PR surface stats
Area Files Added Removed Net
Source 15 771 24 +747
Tests 8 869 7 +862
Docs 2 6 2 +4
Config 1 1 1 0
Generated 3 15 1 +14
Other 3 193 2 +191
Total 32 1855 37 +1818

What I checked:

  • Additive schema policy: The repository policy says a purely additive SQLite table must not bump the schema version; it should be lazily ensured by the feature and folded into a later natural migration. This branch changes the agent version from 12 to 13 for the new session_transcript_generations table. (package.json:7, 69e4633bed67)
  • Persisted migration surface: The branch backfills a generation for existing transcript sessions during agent-database startup, so the version bump affects upgraded local state rather than only fresh databases. (src/state/openclaw-agent-db-schema.ts:513, 69e4633bed67)
  • Public Plugin SDK contract: The branch adds exported raw and visible transcript cursor parameter/result types and reader APIs under the public session-transcript-runtime SDK subpath. Repository policy treats plugin API additions as compatibility-sensitive and requires a maintainer-visible contract decision. (src/plugin-sdk/session-transcript-runtime.ts:67, 69e4633bed67)
  • Only current production adopter: The branch changes active-memory to call the new raw-delta reader, while the PR description states that other proposed consumers remain follow-up work. That leaves the broad public cursor surface without a demonstrated current multi-plugin contract need. (extensions/active-memory/transcript.ts:127, 69e4633bed67)
  • Prior review continuity: The immediately preceding ClawSweeper review at cb90b4670f9f67c4c4944305982e8d379aac0b61 identified the same schema-version and Plugin SDK direction blockers; the latest head still contains both surfaces. (src/state/openclaw-agent-db-contract.ts:17, 69e4633bed67)

Likely related people:

  • jalehman: Authored the branch's transcript-generation and cursor commits and the two explicitly stacked follow-up proposals that depend on this foundation; this is proposal ownership rather than current-main ownership. (role: proposed transcript-stack author; confidence: medium; commits: d46eaed7fd1d, 6c674b898f05, aa85b785251c; files: src/config/sessions/session-accessor.sqlite-delta.ts, src/config/sessions/session-accessor.sqlite-active-events.ts, src/plugin-sdk/session-transcript-runtime.ts)
  • steipete: The remaining blocker is acceptance of a durable SQLite migration and public Plugin SDK direction rather than a narrow implementation defect; current-main feature-history attribution could not be completed because read-only inspection commands were unavailable. (role: likely architecture decision owner; confidence: low; files: AGENTS.md, src/state/openclaw-agent-db-contract.ts, src/plugin-sdk/session-transcript-runtime.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-18T04:37:05.251Z sha e84b451 :: found issues before merge. :: [P1] Obtain approval before advancing the agent DB schema | [P1] Obtain an SDK contract decision for raw transcript cursors
  • reviewed 2026-07-18T05:19:10.573Z sha e84b451 :: found issues before merge. :: [P1] Obtain approval before advancing the agent DB schema | [P1] Obtain an SDK contract decision for raw transcript cursors
  • reviewed 2026-07-18T14:08:58.086Z sha b628667 :: found issues before merge. :: [P1] Obtain approval before advancing the agent DB schema | [P1] Obtain an SDK contract decision for raw transcript cursors
  • reviewed 2026-07-18T14:32:42.840Z sha cf8eeb1a0ee00deb543e9ad4e1fa471b0c687c6d :: found issues before merge. :: [P1] Obtain approval before advancing the agent DB schema | [P1] Obtain an SDK contract decision for raw transcript cursors
  • reviewed 2026-07-18T14:41:35.294Z sha 7ff4bab :: found issues before merge. :: [P1] Obtain approval before advancing the agent DB schema | [P1] Obtain an SDK contract decision for raw transcript cursors
  • reviewed 2026-07-18T15:13:30.004Z sha cc26482 :: found issues before merge. :: [P1] Obtain approval before advancing the agent DB schema | [P1] Obtain an SDK contract decision for raw transcript cursors
  • reviewed 2026-07-18T17:30:49.395Z sha 90b909d :: found issues before merge. :: [P1] Keep the additive generation table out of a schema-version bump | [P1] Obtain approval for the public transcript cursor contract
  • reviewed 2026-07-18T17:49:03.635Z sha cb90b46 :: found issues before merge. :: [P1] Keep the additive generation table out of a schema-version bump | [P1] Obtain a Plugin SDK contract decision before exporting cursors

@jalehman
jalehman marked this pull request as ready for review July 18, 2026 04:15
@jalehman jalehman self-assigned this Jul 18, 2026
@jalehman
jalehman force-pushed the josh/clawdbot-d02.1.9.1.40-db6-generation-cursors branch from e84b451 to b628667 Compare July 18, 2026 14:04
@jalehman
jalehman force-pushed the josh/clawdbot-d02.1.9.1.40-db6-generation-cursors branch 2 times, most recently from cf8eeb1 to 7ff4bab Compare July 18, 2026 14:37
@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Jul 18, 2026
@jalehman jalehman changed the title feat: bound raw transcript reads across replacements feat: bound transcript reads across replacements Jul 18, 2026
@jalehman
jalehman force-pushed the josh/clawdbot-d02.1.9.1.40-db6-generation-cursors branch from 9d744d0 to 90b909d Compare July 18, 2026 17:27
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 18, 2026
jalehman added 3 commits July 18, 2026 11:29
Refs clawdbot-d02.1.9.1.40-db6.1
Refs clawdbot-d02.1.9.1.40-db6.2
Refs clawdbot-d02.1.9.1.40-db6.3
@jalehman
jalehman force-pushed the josh/clawdbot-d02.1.9.1.40-db6-generation-cursors branch from cb90b46 to 69e4633 Compare July 18, 2026 18:34
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 18, 2026
@jalehman
jalehman merged commit 4534446 into main Jul 18, 2026
128 of 130 checks passed
@jalehman
jalehman deleted the josh/clawdbot-d02.1.9.1.40-db6-generation-cursors branch July 18, 2026 18:41
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 19, 2026
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations docs Improvements or additions to documentation maintainer Maintainer-authored PR 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. 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: ⏳ 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