Skip to content

fix(cli): read session history from the canonical store, not a retired file - #132185

Merged
steipete merged 4 commits into
mainfrom
steipete/cli-history-canonical-sqlite
Aug 29, 2026
Merged

steipete merged 4 commits into
mainfrom
steipete/cli-history-canonical-sqlite

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

A CLI session that lives only in SQLite projected as an empty conversation. transcript-file-resolve returns the session key as a process-local routing token, but CLI history still treated it as a filesystem path: it resolved a JSONL file, ran a runtime migration over it, and its catch deliberately suppressed ENOENT by returning []. Nothing recorded that the history had not been found — it simply looked empty.

Every downstream consumer inherited that emptiness: hook history, reseed history, context-engine bootstrap, the presence check, and the embedded fallback marker. The runner then selected only the current prompt, so a fresh CLI session that needed prior compacted context silently ran without it.

Reproduced against real SQLite: with a session holding a user message, a compaction summary, and a tail message, the canonical SessionManager.open(target).buildSessionContext() returns all three while the CLI readers return {"cliHistory":[],"cliReseed":[],"contextEngineMessages":[],"cliHasTranscript":false,"reseedPrompt":null}.

Why This Change Was Made

This is the repo's worst bug class — an action ending in no visible outcome and no recorded reason — and it comes from reading a retired storage shape at runtime. The architecture rules are explicit that core runtime consumes only current canonical shapes, and that retired shapes normalize in doctor/migration code, never behind a runtime fallback reader.

So the retired reader is deleted, not kept as a fallback. All five CLI callers now pass the session target they had already selected; the embedded attempt passes its own; cron shares its explicit per-prompt target across user persistence and the CLI path. Presence comes from the transcript watermark — a recorded fact — rather than a file's existence.

User Impact

CLI sessions resume with their real prior context, including compaction summaries, instead of starting effectively blank. Raw-reseed eligibility, summary pinning, and bounded truncation notices are preserved exactly.

Evidence

  • Failing-first reproduction against real SQLite owner APIs, as above.
  • 523 tests green at this head across the touched suites: session-history, prepare, cli-runner.reliability, attempt-execution, cron session-key isolation, live-model-switch, model-registry, and commands/agent.
  • check-changed clean apart from an oxfmt: command not found PATH artifact in the worktree; formatting verified directly with the repo binary (17/17 files correct).
  • Production LOC: +170 / −518 = −348 net.

@clawsweeper

clawsweeper Bot commented Aug 28, 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 docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Aug 28, 2026
@steipete
steipete marked this pull request as ready for review August 28, 2026 22:56
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Aug 28, 2026
@clawsweeper

clawsweeper Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 1:04 AM ET / 05:04 UTC.

ClawSweeper review

What this changes

The branch replaces retired JSONL session-history reads with canonical SQLite history across CLI preparation, hooks, retries, embedded dispatch, and cron execution, with focused regressions and documentation.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

The prior embedded-dispatch blocker is fixed at the current head, and the canonical SQLite reader is consistently propagated through the inspected CLI paths. This member-authored, maintainer-labeled PR remains necessary because current main does not contain the repair; exact-head CI should finish before merge.

Priority: P1
Reviewed head: 7183bdf6e92b1a62f617f1f8acc3d7bc27449cf5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has a coherent owner-boundary repair and resolves the prior dispatch finding, with exact-head CI still pending.
Proof confidence 🌊 off-meta tidepool Not applicable: The PR is member-authored, so the external-contributor proof gate does not apply; its body nevertheless reports a real SQLite reproduction and focused regression runs.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The PR is member-authored, so the external-contributor proof gate does not apply; its body nevertheless reports a real SQLite reproduction and focused regression runs.
Evidence reviewed 7 items Base defect: The pinned base reads a resolved session file, migrates/parses JSONL, and treats a missing file as empty history; the PR removes that retired runtime path.
Canonical owner boundary: The new shared reader waits for projection and reads bounded active-context or message-tail data using the supplied canonical session target; reseeding preserves compaction and reset semantics.
Prior finding resolved: The orchestrator now forwards the lane-admitted target to embedded CLI dispatch; the lane controller adds the writer and lifecycle claim before that dispatch, and the dispatch forwards the target to the CLI runner.
Findings None None.
Security None None.

How this fits together

CLI-backed agent turns load persisted conversation context for hooks, fresh-session reseeding, and context-engine maintenance. The resolved session target identifies the canonical SQLite transcript that each entry point must carry through to those consumers.

flowchart LR
  A[Agent or cron turn] --> B[Resolved session target]
  B --> C[CLI preparation]
  C --> D[Canonical SQLite transcript]
  D --> E[History and compaction context]
  B --> F[Embedded CLI dispatch]
  F --> C
  E --> G[CLI agent response]
Loading

Before merge

  • Resolve merge risk (P1) - This changes the persisted-session context boundary for existing CLI runs; wait for the incomplete exact-head CI matrix to validate context-engine, embedded-dispatch, and cron paths together.
Agent review details

Security

None.

PR surface

Source -301, Tests -455, Docs 0, Other 0. Total -756 across 26 files.

View PR surface stats
Area Files Added Removed Net
Source 13 233 534 -301
Tests 11 608 1063 -455
Docs 1 2 2 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 26 844 1600 -756

Review metrics

Metric Value Why it matters
Production versus test delta production +178/−511 (net −333); tests/support +663/−1086 The repair removes the retired runtime reader while adding SQLite-owner and dispatch-boundary coverage.

Stored data model

Persistent data-model change detected: serialized state: src/agents/cli-runner/session-history.ts, unknown-data-model-change: src/agents/cli-runner/session-history.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete exact-head session validation (recommended)
    Let the pending exact-head checks validate the cross-cutting SQLite history paths before merging this persistence-boundary change.

Technical review

Best possible solution:

Use the canonical SQLite transcript as the sole CLI-history source, preserve the admitted target through every production entry point, and merge after exact-head validation completes.

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

Yes, at source level: the pinned base’s file-based reader returns empty history for absent JSONL, while the new SQLite-backed fixtures exercise the same consumers with canonical stored history. This read-only review did not independently execute the reproduction.

Is this the best way to solve the issue?

Yes. Reusing the canonical bounded transcript projections removes the retired storage reader at its owner boundary, and the former embedded-dispatch omission is now covered by the lane composition test.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5d3bd15130a2.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR is member-authored, so the external-contributor proof gate does not apply; its body nevertheless reports a real SQLite reproduction and focused regression runs.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The repaired behavior prevents ordinary CLI-backed agent turns from silently losing prior session context.
  • merge-risk: 🚨 session-state: The branch changes which persisted transcript history is supplied to resumed and freshly seeded CLI sessions.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR is member-authored, so the external-contributor proof gate does not apply; its body nevertheless reports a real SQLite reproduction and focused regression runs.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Git blame attributes the shared SQLite reader to the initial repair and the dispatch propagation to the current head. (role: introduced the canonical-history repair; confidence: high; commits: c2b7d5159354, 7183bdf6e92b; files: src/agents/cli-runner/session-history.ts, src/agents/embedded-agent-runner/run-orchestrator.ts)
  • Vincent Koc: Blame identifies this contributor on the existing embedded-run and session-history framework surrounding the repair. (role: recent adjacent contributor; confidence: medium; commits: b12d926ce24e; files: src/agents/embedded-agent-runner/run-orchestrator.ts, src/agents/cli-runner/session-history.ts)

Rank-up moves

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

  • Wait for the pending exact-head checks covering the changed session paths.

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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-08-28T23:08:00.837Z sha 1324162 :: found issues before merge. :: [P1] Pass the resolved session target to embedded CLI dispatch
  • reviewed 2026-08-29T03:32:15.458Z sha c65c055 :: needs changes before merge. :: [P1] Forward the resolved session target to embedded CLI dispatch
  • reviewed 2026-08-29T04:08:51.156Z sha 52699c6 :: found issues before merge. :: [P1] Forward the resolved session target through embedded CLI dispatch

@steipete
steipete force-pushed the steipete/cli-history-canonical-sqlite branch from 1324162 to c65c055 Compare August 29, 2026 03:24
@steipete steipete self-assigned this Aug 29, 2026
…d file

`transcript-file-resolve` returns the session key as a process-local routing
token, but CLI history still treated it as a filesystem path: it resolved a
JSONL file, ran a runtime migration over it, and suppressed ENOENT by returning
an empty list. A session that lives only in SQLite therefore projected as an
empty conversation, and the runner fell back to the current prompt alone. Hook
history, reseed history, context-engine bootstrap, and the embedded fallback
marker all inherited that silent emptiness.

All five CLI callers now pass the session target they had already selected, and
the embedded attempt passes its own; cron shares its explicit per-prompt target
across user persistence and the CLI path. Presence comes from the transcript
watermark rather than a file's existence, and history comes from the canonical
bounded active-context reader, preserving raw-reseed eligibility, summary
pinning, and truncation notices.

The retired JSONL reader, its path resolution, and its runtime migration are
deleted rather than kept as a fallback: runtime consumes only the canonical
shape. Net production -348 lines.
…arget

The lifecycle test still encoded the retired storage premise, asserting the
loader was called with sessionFile/sessionKey/agentId. It now supplies a real
session target on the prepared fixture and asserts that exact target is
forwarded, which is the invariant the repair actually establishes.
Use vaporeon-alpha under the existing test provider in the persisted
assistant-message fixture. Production behavior and assertions are unchanged.

Validation: 59 attempt-execution tests passed, including SQLite assistant
history detection, abandoned branches, and reset boundaries.
Carry the selected SQLite transcript target through embedded CLI dispatch and context-engine bootstrap/finalization. Keep custom-store transcript mirrors with that owner and retain the post-admission writer claim.

Extend real SQLite and lifecycle regressions for PR #132185. Local behavioral tests and autoreview pass. The full changed-files gate is blocked by missing playwright-core; the additional fault-sequence E2E setup is blocked by missing @lit/context.
@steipete
steipete force-pushed the steipete/cli-history-canonical-sqlite branch from 52699c6 to 7183bdf Compare August 29, 2026 04:57
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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. labels Aug 29, 2026
@steipete
steipete merged commit 015546c into main Aug 29, 2026
241 checks passed
@steipete
steipete deleted the steipete/cli-history-canonical-sqlite branch August 29, 2026 05:09
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 30, 2026
…d file (openclaw#132185)

* fix(cli): read session history from the canonical store, not a retired file

`transcript-file-resolve` returns the session key as a process-local routing
token, but CLI history still treated it as a filesystem path: it resolved a
JSONL file, ran a runtime migration over it, and suppressed ENOENT by returning
an empty list. A session that lives only in SQLite therefore projected as an
empty conversation, and the runner fell back to the current prompt alone. Hook
history, reseed history, context-engine bootstrap, and the embedded fallback
marker all inherited that silent emptiness.

All five CLI callers now pass the session target they had already selected, and
the embedded attempt passes its own; cron shares its explicit per-prompt target
across user persistence and the CLI path. Presence comes from the transcript
watermark rather than a file's existence, and history comes from the canonical
bounded active-context reader, preserving raw-reseed eligibility, summary
pinning, and truncation notices.

The retired JSONL reader, its path resolution, and its runtime migration are
deleted rather than kept as a fallback: runtime consumes only the canonical
shape. Net production -348 lines.

* test(cli): assert the context engine receives the forwarded session target

The lifecycle test still encoded the retired storage premise, asserting the
loader was called with sessionFile/sessionKey/agentId. It now supplies a real
session target on the prepared fixture and asserts that exact target is
forwarded, which is the invariant the repair actually establishes.

* test(cli): name the synthetic fallback-history model fixture

Use vaporeon-alpha under the existing test provider in the persisted
assistant-message fixture. Production behavior and assertions are unchanged.

Validation: 59 attempt-execution tests passed, including SQLite assistant
history detection, abandoned branches, and reset boundaries.

* fix(cli): preserve canonical targets across dispatch and lifecycle

Carry the selected SQLite transcript target through embedded CLI dispatch and context-engine bootstrap/finalization. Keep custom-store transcript mirrors with that owner and retain the post-admission writer claim.

Extend real SQLite and lifecycle regressions for PR openclaw#132185. Local behavioral tests and autoreview pass. The full changed-files gate is blocked by missing playwright-core; the additional fault-sequence E2E setup is blocked by missing @lit/context.
alfredjbclaw added a commit to alfredjbclaw/openclaw that referenced this pull request Sep 1, 2026
Upstream openclaw#132185 moved bounded CLI history onto SessionManager.openBounded,
so this branch's fallback tail reader lost its last caller. The barrel
re-exports kept deadcode:exports satisfied, hiding that nothing — not even a
test — called loadTranscriptTailWindowSync or transcriptTailOmitsBranchControlSync.

Removes both functions, their private helpers, and the re-export lines. No
production caller existed, so behavior is unchanged.
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 gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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