Skip to content

refactor: simplify transcript reads and recovery state - #135392

Merged
steipete merged 2 commits into
mainfrom
codex/refactor-transcript-memory-loc
Sep 1, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/refactor-transcript-memory-loc

Conversation

@steipete

@steipete steipete commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Related: #135326

What Problem This Solves

Maintainer-requested cleanup around the large-transcript memory work. Session reads and full-message recovery had overlapping representations and cache bookkeeping that made their ownership harder to maintain.

Why This Change Was Made

Use the active SQLite projection's canonical type, row parser, and generation reader across transcript readers. Usage and previews consume the raw payloads they actually need, removing redundant metadata projection and the private visitor's ignored options. Reset-window validity now lives only on its cache entry.

Control UI recovery reuses the existing map-version mechanism instead of sorting and joining a signature on each render. Disconnect clears the captured map before replacing it: the clear fences pending completions, while the new identity invalidates guarded rows on reconnect. Per-message revisions retain their existing retry budget.

The CLI login fixture also uses a checked view of the optional TTY property it temporarily owns, avoiding a type assertion while retaining exact descriptor restoration and typed deletion.

User Impact

No intended behavior change. Streaming scans remain inside the SQLite read snapshot, full-message recovery keeps its three automatic attempts plus manual retry, and recovered bodies remain owned by the presentation that uses them. Cursor/reset semantics, display metadata, config, and persistent storage are unchanged.

Evidence

  • 464 tests passed across 15 files, covering active/history/byte-size readers, reset/compaction markers, visitor and parse failure cleanup, usage/previews, artifact RPCs, MCP reconstruction, and UI recovery/render invalidation. Added same-controller reconnect coverage for both pending and loaded messages, and exercised automatic retry exhaustion followed by manual recovery.
  • Full changed checks passed, including core/test/UI typechecks, formatting, lint, unused exports, database guards, and runtime import cycles. Fresh Codex review was scoped-clean at the configured P0 threshold.
  • CI regression reproduced and repaired: the exact core test-type stripe failed with TS2790 before the fixture repair and passed afterward. Another 133 auth/CLI tests passed, including the real registered login command. After fix(cli): make the auth-login test's isTTY override actually optional #135407 independently fixed the same fixture on main, the required rebase retained this branch's checked property view. All 51 focused artifact/auth integration tests passed again on the refreshed candidate.
  • Runtime and Control UI builds passed on Node 24.19.0. The built UI passed its asset-budget checks.
  • Real Gateway + Chromium replay: 64 messages of roughly 400 KB each, all 64 full-message requests completed, then navigation through three other sessions and away from chat. Both before and after retained 0 large recovered bodies / 0 body bytes after teardown; no browser errors. The before run used the retained fix: reduce memory retained by transcript scans and chat views #135326 build, whose affected production modules match this branch's base; the after run used the rebuilt candidate.
  • Six real CLI calls passed: enriched session listing, bounded previews, a 25.6 MB transcript artifact scan, and artifact list/get/download. The downloaded synthetic file matched its original eight bytes. Separate reader probes preserved full usage totals of 64 input / 64 output and bounded-tail totals of 20 / 20, with three bounded previews.
  • Current-main integration verified: rebased onto ee9e22b5215, including main's attachment-only reply fix. All core reader production files and PR test files remain byte-identical to the preceding candidate. 125 focused tests in seven files and four real-browser reply scenarios passed on e6c2c88f97e; fresh Codex autoreview was scoped-clean at the configured P0 threshold. Earlier integration also rebuilt the Gateway and passed six real CLI calls using an artifact stored only in openclawDisplayContent; list/get/download returned the original eight bytes.
Scope Added Removed Net
Production 119 266 −147
Tests 68 31 +37
Assertion baseline 2 3 −1
Total 189 300 −111

Before, with the memory fix already present:

Before refactor: recovered full messages

After:

After refactor: recovered full messages

After leaving chat, with every chat pane disconnected:

After refactor: chat panes disconnected

Recorded candidate replay:

transcript-refactor-after-video.webm

@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Sep 1, 2026
@steipete
steipete force-pushed the codex/refactor-transcript-memory-loc branch from 8263f74 to 342bba6 Compare September 1, 2026 17:41
@openclaw-barnacle openclaw-barnacle Bot added the cli CLI command changes label Sep 1, 2026
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Ready-to-land verification for 36edcc49714c6a522f257f02276248b3d1d0b31e.

The refactor removes 147 production lines and 111 lines overall. Canonical SQLite row parsing/generation and the existing UI map-version mechanism replace duplicate state; snapshot boundaries, pending-load fencing, reconnect invalidation, and the retry budget remain covered. Native review artifacts and the fresh Codex review are clean.

The real Gateway/Chromium replay recovered all 64 large messages and retained zero large recovered bodies after teardown. All six real CLI calls passed, including the artifact download. The 11 production files match the live-tested candidate byte-for-byte after the branch refresh. Screenshots and video are in the PR body.

The first merge build found the TS2790 fixture error from #135355. The repaired fixture now expresses its optional owned TTY property with a checked local type and keeps typed deletion and exact descriptor restoration. The same test-type stripe passes; 464 transcript/UI tests and 133 additional auth/CLI tests passed, with the final login fixture integration rerun.

Local verification commands
node --import ./scripts/tsx.mjs scripts/test-projects.mts --maxWorkers=2 \
  src/config/sessions/session-accessor.sqlite-active-events.test.ts \
  src/config/sessions/session-accessor.sqlite-history-events.test.ts \
  src/config/sessions/session-accessor.sqlite-byte-size.test.ts \
  src/gateway/session-transcript-readers.test.ts \
  src/gateway/session-transcript-readers.markers.test.ts \
  src/gateway/session-utils.fs.test.ts \
  src/gateway/session-transcript-message.test.ts \
  src/gateway/mcp-app-reconstruction.test.ts \
  src/gateway/server-methods/artifacts.test.ts \
  src/gateway/server-methods/artifacts-session-resolution.test.ts \
  src/gateway/server-methods/artifacts.managed-lifecycle.test.ts \
  ui/src/pages/chat/chat-thread.test.ts \
  ui/src/pages/chat/components/chat-transcript-recovery.test.ts \
  ui/src/pages/chat/components/chat-transcript-render.test.ts \
  ui/src/pages/chat/components/chat-transcript-invalidation.test.ts

node scripts/check-changed.mjs --base da9137384c4
node scripts/run-tsgo-core-test-shards.mjs --stripe 4/5 --concurrency 2
node --import ./scripts/tsx.mjs scripts/test-projects.mts --maxWorkers=2 \
  src/cli/models-cli.auth-login.integration.test.ts \
  src/cli/models-cli.test.ts \
  src/commands/models/auth.test.ts \
  src/commands/models/auth-logout.test.ts
node --import ./scripts/tsx.mjs scripts/test-projects.mts --maxWorkers=2 \
  src/cli/models-cli.auth-login.integration.test.ts

Hosted CI run 33539517666 completed successfully on this exact head: 248 checks passed, 37 skipped, none pending or failing. scripts/pr review-validate-artifacts 135392 and OPENCLAW_TESTBOX=1 scripts/pr prepare-run 135392 both passed; preparation preserved the same head.

The latest ClawSweeper message reports that review has started; no findings or Rank-up moves have been published. The independent review and changed-surface proof are complete. The performance proof covers preserved streaming/bounded reads and zero retained large recovered bodies after teardown.

@steipete
steipete force-pushed the codex/refactor-transcript-memory-loc branch 2 times, most recently from b95d970 to cd5a939 Compare September 1, 2026 19:30
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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. labels Sep 1, 2026
@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 4:26 PM ET / 20:26 UTC.

ClawSweeper review

What this changes

This PR consolidates SQLite transcript-reader helpers, removes ignored transcript-scan options, and uses versioned map invalidation for Control UI full-message recovery.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this maintainer-authored, maintainer-labeled refactor open. The introduced change preserves the transcript projection and per-presentation recovery ownership boundaries, but its verified test merge is against the older base and current main has since changed the same central paths.

Priority: P3
Reviewed head: cd5a939c7dd2edb06f39b67d3494dcc5f3177658

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is well-scoped and preserves the reviewed base behavior, but current-main overlap requires a refreshed integration pass.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository state identifies the author as a MEMBER, so external-contributor proof is not a gate; the supplied PR body nevertheless describes a real Gateway and Chromium replay of recovery and teardown.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository state identifies the author as a MEMBER, so external-contributor proof is not a gate; the supplied PR body nevertheless describes a real Gateway and Chromium replay of recovery and teardown.
Evidence reviewed 6 items Canonical projection ownership: The active projection now owns the shared row parser and generation reader; the same parser preserves visible-message ordinals and rejects rows without a message position.
Reader and caller behavior: Display reads still use the metadata-preserving projection, while usage, previews, artifact lookup, and MCP reconstruction consume raw payload fields they actually require.
Recovery lifecycle: Projection updates version every recovery-map mutation, and disconnect clears then replaces the map so stale asynchronous completions cannot publish into a reconnected presentation.
Findings None None.
Security None None.

How this fits together

SQLite transcript projections feed Gateway readers used by artifact lookup and MCP app reconstruction. The Control UI then renders that transcript and holds recovered full-message text only for the active chat presentation.

flowchart LR
  A[Stored transcript events] --> B[Active SQLite projection]
  B --> C[Gateway transcript readers]
  C --> D[Artifacts and MCP reconstruction]
  B --> E[Control UI transcript]
  E --> F[Presentation recovery map]
  F --> G[Rendered chat rows]
Loading

Before merge

  • Resolve merge risk (P1) - Current main has materially changed the session and chat paths since this PR's base, while the verified test merge is only against that older base; rebase and exact-head validation are needed before landing.
  • Complete next step (P2) - No mechanical defect was found; maintainer-owned current-main rebase and exact-head validation are required because the same integration surfaces have moved.
Agent review details

Security

None.

PR surface

Source -147, Tests +37, Other -1. Total -111 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 11 119 266 -147
Tests 5 68 31 +37
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 2 3 -1
Total 17 189 300 -111

Review metrics

Metric Value Why it matters
Production versus test delta production +119/-266 (net -147); tests +68/-31 (net +37); assertion baseline +2/-3 The refactor substantially reduces production duplication while adding focused recovery coverage.

Stored data model

Persistent data-model change detected: persistent cache schema: src/gateway/mcp-app-reconstruction.ts, persistent cache schema: src/gateway/server-methods/artifacts.ts, serialized state: src/config/sessions/session-accessor.sqlite-active-events.ts, serialized state: src/config/sessions/session-accessor.sqlite-active-projection.ts, unknown-data-model-change: src/config/sessions/session-accessor.sqlite-active-events.ts, unknown-data-model-change: src/config/sessions/session-accessor.sqlite-active-projection.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Rebase the simplification onto current main, retain the canonical projection and presentation-owned recovery lifecycle, and validate the resolved integration on the resulting exact head.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Rebase the simplification onto current main, retain the canonical projection and presentation-owned recovery lifecycle, and validate the resolved integration on the resulting exact head.

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

Not applicable: this PR is a refactor and the review checked preservation of existing transcript and recovery behavior rather than a new defect report.

Is this the best way to solve the issue?

Yes on the reviewed base: it consolidates duplicated projection logic at the owning boundaries; current-main integration must be refreshed before that judgment can cover a merge.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 75bcd267f5e7.

Labels

Label changes:

  • add P3: This is a behavior-preserving maintainer cleanup rather than a reported user-facing regression.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository state identifies the author as a MEMBER, so external-contributor proof is not a gate; the supplied PR body nevertheless describes a real Gateway and Chromium replay of recovery and teardown.

Label justifications:

  • P3: This is a behavior-preserving maintainer cleanup rather than a reported user-facing regression.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Repository state identifies the author as a MEMBER, so external-contributor proof is not a gate; the supplied PR body nevertheless describes a real Gateway and Chromium replay of recovery and teardown.

Evidence

What I checked:

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase onto current main and rerun the focused transcript-reader, artifact, and Control UI recovery validation on the resulting exact head.

Rating scale

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

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

Workflow

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

@steipete
steipete force-pushed the codex/refactor-transcript-memory-loc branch from cd5a939 to e6c2c88 Compare September 1, 2026 21:11
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the current-main integration concern and rank-up move on e6c2c88f97e6b30f27186cd42e2b4f46b0052520.

The branch is rebased onto ee9e22b5215fd69c0176852235999500bd1b7961. This includes #135393's attachment-only reply support in the shared UI projection. All core transcript-reader production files and PR test files remain byte-identical to the preceding reviewed candidate. The combined code passed 125 focused tests across seven files covering transcript reads, markers, artifacts, recovery, rendering, reply previews, and final-message action ownership. Four real-browser scenarios also passed: assistant/user × document/image-only replies, including the transmitted reply reference and navigation back to the source. Fresh Codex autoreview was scoped-clean at the configured P0 threshold.

The stored-data warning is not a schema or migration change. The active projection now owns the same existing row parser and generation query; the event JSON, sequence/position arithmetic, database queries, serializers, index producers, and write paths are unchanged. The reset-window fields removed here belonged only to an unexported in-memory window; generation and indexed sequence remain on its authoritative cache entry with the same invalidation rules. No stored representation changes or data rewrites are introduced, so no migration is needed.

Production remains −147 lines, tests +37, and the assertion baseline −1, for −111 lines overall. The prior head passed all CI, including both Windows jobs; the rebased head is receiving its own CI run before native prepare and merge.

@steipete
steipete merged commit 0ac1855 into main Sep 1, 2026
291 checks passed
@steipete
steipete deleted the codex/refactor-transcript-memory-loc branch September 1, 2026 21:25
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 2, 2026
* refactor: simplify transcript reads and recovery state

* test: type the temporary stdin property at its fixture owner
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 cli CLI command changes gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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