Skip to content

feat(memory): backfill retained session transcripts - #115162

Merged
steipete merged 15 commits into
mainfrom
feat/memory-session-backfill
Jul 28, 2026
Merged

steipete merged 15 commits into
mainfrom
feat/memory-session-backfill

Conversation

@steipete

@steipete steipete commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Related: #114819

Additional instructions

Allow edits from maintainers is enabled for this repository-owned branch.

What Problem This Solves

The provenance-gated memory system landed in #114819, but retained and archived session transcripts still had no bounded operator path into the dreaming ingestion pipeline. Useful older owner-authored facts therefore remained outside the per-day corpus, claim convergence, and gated short-term staging flow.

Why This Change Was Made

Adds openclaw memory session-backfill, a dry-run-by-default command that walks retained SQLite transcript identities and optionally supplied archive files through the dreaming ingestion primitives landed by #114819. It preserves per-day corpus files, source-line provenance, canonical claim-hash convergence, ingestion caps and checkpoints, and provenance-gated staging rather than creating a parallel memory writer.

--apply stages trusted candidates and writes reversible diary blocks; --rem writes deterministic diary previews without staging; --rollback clears the shared grounded backfill artifacts; and --archive-files treats caller-supplied files conservatively. The command never writes MEMORY.md or USER.md. This PR was AI-assisted and reviewed with the repository autoreview workflow.

User Impact

Operators can preview and selectively ingest useful retained session history without promoting it directly into durable memory. Repeated runs are bounded and idempotent, retained SQLite identities are opt-in at the corpus seam, foreign archives cannot self-assert owner trust, and durable promotion remains a separate dreaming or memory promote decision.

Evidence

  • Rebases the 12-commit backfill stack onto the memory-system landing commit 28630a9a6501 from feat(memory): provenance-gated memory with dreaming on by default #114819, then adds two focused reconciliation fixes for current-main SQLite identity handling and REM/apply mutual exclusion.
  • Blacksmith Testbox tbx_01kym3dbvh74ha1my7vksbtdx0 / https://github.com/openclaw/openclaw/actions/runs/30349869899:
    • pnpm test extensions/memory-core/src/session-backfill.test.ts: 11/11 passed.
    • pnpm test extensions/memory-core/src/cli.test.ts: 75/75 passed.
    • pnpm test packages/memory-host-sdk/src/host/session-files.test.ts: 38/38 passed.
    • pnpm test extensions/memory-core/src/dreaming-narrative.test.ts: 29/29 passed.
    • pnpm docs:check-mdx: passed across 758 files.
    • node scripts/check-changed.mjs -- <16 changed files>: passed all core/extension typecheck, lint, SDK-surface, max-lines, database-first, and architecture lanes on the final tree (20m37s).
  • Final branch autoreview: clean, with no accepted/actionable findings. One valid P2 found during review (--rem --apply could stage despite preview-only semantics) was fixed and regression-tested. Two non-actionable findings were rejected against direct evidence: TSGo had already proven the claimed duplicate property did not exist, and current main explicitly defines SQLite as the only runtime session store while legacy JSONL import remains doctor-owned.
  • The first hosted exact-head run found two narrow guard failures: a stale generated docs map and four production-unused exports. Both were repaired; deadcode:dependencies, deadcode:exports, docs:map:check, and docs:check-mdx then passed on Blacksmith Testbox run https://github.com/openclaw/openclaw/actions/runs/30355485044.
  • Deferral history: the changed-files gate was intentionally deferred while this branch still sat on the pre-integration memory base, where it would have re-evaluated the already-landed integration and max-lines changes. After feat(memory): provenance-gated memory with dreaming on by default #114819 merged, the branch was explicitly rebased onto origin/main; the final exact-head gate now passes without removing or restoring max-lines baseline entries.

Redacted runtime proof (real retained-session data)

https://gist.github.com/steipete/8cf515b9ba777ef3b010127bfe3e054b

Run from this PR's head against a copy of a live gateway state directory containing
today's real retained SQLite session transcripts (synthetic QA conversation content):

  • proof-1-dryrun.txt — default dry-run enumerates 1 day / 42 owner-turn candidates,
    stages nothing.
  • proof-2-apply-rerun-rollback.txt — --apply stages 42; the immediate rerun stages
    0 ("No new hash-untracked trusted session candidates" — per-message hash tracking makes
    reruns idempotent); --rollback removes exactly the 42 staged entries and 1 diary
    block, restoring the pre-apply state.

Maintainer decision: SDK seam confirmed

includeRetainedSqlite on the memory-host session-transcript corpus reader is approved
as a supported ADDITIVE contract: opt-in, default-off (nightly ingestion behavior
unchanged), retained entries surfaced as a distinct artifact kind. Same additive-contract
policy as recorded on #114819.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-core Extension: memory-core size: XL maintainer Maintainer-authored PR labels Jul 28, 2026
@steipete
steipete marked this pull request as ready for review July 28, 2026 11:28
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 28, 2026
@clawsweeper

clawsweeper Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 28, 2026, 8:04 AM ET / 12:04 UTC.

ClawSweeper review

What this changes

Adds a dry-run-by-default openclaw memory session-backfill command that reads retained SQLite session transcripts and optional archive files through Memory Core’s existing provenance-gated dreaming and short-term staging workflow.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this PR open for explicit maintainer handling: it is protected by the maintainer label and adds an operator-facing retained-session ingestion path plus an additive Memory Host SDK contract. The supplied redacted runtime proof now demonstrates dry-run, apply, idempotent rerun, and rollback behavior; no discrete patch defect was established in this review. Likely related people: steipete (high confidence), based on the merged provenance-gated memory redesign and this follow-on implementation.

Priority: P2
Reviewed head: 8461e5d647f88e734e29f6f00cf9db38658e8dc1
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The PR has focused tests, successful required checks, explicit contract rationale, and useful runtime proof; a final current-main refresh is the material remaining confidence step.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (linked_artifact): The PR body links redacted after-fix terminal evidence from a copied live gateway state directory showing dry-run, apply, zero-work idempotent rerun, and rollback restoration; private transcript content is not exposed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The PR body links redacted after-fix terminal evidence from a copied live gateway state directory showing dry-run, apply, zero-work idempotent rerun, and rollback restoration; private transcript content is not exposed.
Evidence reviewed 6 items Current diary-artifact boundary: Current main owns the shared grounded backfill diary section in the dreaming narrative module; the PR extends that same owner rather than adding a parallel writer. The current implementation’s backfill writer starts at line 593. (raw.githubusercontent.com)
PR uses the existing ingestion seam: The proposed session-backfill module imports the established session-ingestion caps, hash tracking, corpus rendering, checkpoint reads, and checkpoint writes from dreaming-phases, keeping retention processing on the existing bounded pipeline.
Additive SDK contract: The PR introduces includeRetainedSqlite?: boolean on the session-transcript corpus reader, defaulting to the existing active-session behavior unless the new backfill caller opts in; the PR body records explicit approval of this additive seam.
Findings None None.
Security None None.

How this fits together

Memory Core turns eligible session content into a daily corpus, then uses dreaming to derive staged memory candidates and reversible diary entries before any later durable promotion. This PR adds an operator-triggered path for retained transcript identities while keeping ordinary nightly ingestion default-off for that extra history.

flowchart LR
  A[Retained SQLite transcripts] --> B[Session backfill command]
  C[Optional archive files] --> B
  B --> D[Ownership and provenance gates]
  D --> E[Existing dreaming ingestion]
  E --> F[Daily corpus and checkpoints]
  E --> G[Short-term staged candidates]
  E --> H[Reversible diary blocks]
  G --> I[Later memory promotion]
Loading

Decision needed

Question Recommendation
Should the protected retained-session backfill feature land after a current-main refresh that reconfirms the default-off SDK option and shared rollback semantics? Refresh and land the documented contract: Rebase or validate the clean merge result on current main, rerun focused session-backfill proof, and retain includeRetainedSqlite as opt-in with the documented shared rollback behavior.

Why: The implementation is a new CLI capability that reads retained session state and writes shared ingestion artifacts; the PR body records the intended contract, but the protected maintainer label requires an explicit human merge decision on the final base.

Before merge

  • Resolve merge risk (P1) - The PR is behind current main; before merge, refresh the merge result and re-run the focused retained-session, CLI, and diary/rollback proofs against that exact head.
  • Resolve merge risk (P1) - includeRetainedSqlite is a new supported plugin-facing corpus option and the command writes shared grounded backfill artifacts, so maintainers should retain the explicit default-off and shared-rollback contract rather than allowing later callers to treat it as an unrestricted history reader.
Agent review details

Security

None.

PR surface

Source +958, Tests +533, Docs +60. Total +1551 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 12 975 17 +958
Tests 2 533 0 +533
Docs 3 61 1 +60
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 1569 18 +1551

Review metrics

Metric Value Why it matters
Plugin-facing corpus option 1 added opt-in option includeRetainedSqlite changes the supported session-corpus reader contract while preserving the existing default path.
Operator state modes 4 command modes Dry-run, apply, REM preview, and rollback each touch different staging or diary-state boundaries and need final-head proof.

Stored data model

Persistent data-model change detected: migration/backfill/repair: docs/docs_map.md, migration/backfill/repair: extensions/memory-core/src/cli-rem.runtime.ts, migration/backfill/repair: extensions/memory-core/src/cli.ts, migration/backfill/repair: extensions/memory-core/src/session-backfill.test.ts, serialized state: extensions/memory-core/src/session-backfill.test.ts, serialized state: extensions/memory-core/src/session-backfill.ts, and 12 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Refresh final-head proof (recommended)
    Rebase or validate the three-way merge on current main and rerun retained-session enumeration, apply/rerun idempotency, and rollback coverage before merging.
  2. Accept the existing base only
    Maintain the recorded additive SDK and shared-artifact contract without a current-main refresh, accepting the remaining drift risk.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Refresh the branch on current main and attach focused proof for default dry-run, apply, idempotent rerun, and rollback against the final merge result.

Technical review

Best possible solution:

Rebase or merge-refresh this branch onto current main, preserve the opt-in SDK contract and documented shared rollback semantics, then land only with fresh focused proof covering dry-run, apply, idempotent rerun, and rollback on the final merge result.

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

Not applicable: this PR introduces a new operator command rather than fixing a reported current-main failure. The supplied redacted runtime transcript provides an after-fix execution path for the new behavior.

Is this the best way to solve the issue?

Yes, conditionally: routing retained transcripts through the existing provenance-gated ingestion and staging primitives is preferable to a parallel memory writer, provided the final merge result preserves the opt-in reader and shared-artifact contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 89b6d85cdd86.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body links redacted after-fix terminal evidence from a copied live gateway state directory showing dry-run, apply, zero-work idempotent rerun, and rollback restoration; private transcript content is not exposed.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦪 silver shellfish.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded but substantial operator-facing memory capability with persisted session and staging-state effects.
  • merge-risk: 🚨 compatibility: The PR adds an opt-in Memory Host SDK corpus option and must preserve active-session-only behavior for existing callers.
  • merge-risk: 🚨 session-state: The command enumerates retained session identities and writes ingestion checkpoints, staged candidates, and reversible diary artifacts.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Sufficient (linked_artifact): The PR body links redacted after-fix terminal evidence from a copied live gateway state directory showing dry-run, apply, zero-work idempotent rerun, and rollback restoration; private transcript content is not exposed.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body links redacted after-fix terminal evidence from a copied live gateway state directory showing dry-run, apply, zero-work idempotent rerun, and rollback restoration; private transcript content is not exposed.

Evidence

What I checked:

  • Current diary-artifact boundary: Current main owns the shared grounded backfill diary section in the dreaming narrative module; the PR extends that same owner rather than adding a parallel writer. The current implementation’s backfill writer starts at line 593. (raw.githubusercontent.com) (extensions/memory-core/src/dreaming-narrative.ts:593, 89b6d85cdd86)
  • PR uses the existing ingestion seam: The proposed session-backfill module imports the established session-ingestion caps, hash tracking, corpus rendering, checkpoint reads, and checkpoint writes from dreaming-phases, keeping retention processing on the existing bounded pipeline. (extensions/memory-core/src/session-backfill.ts:1, 8461e5d647f8)
  • Additive SDK contract: The PR introduces includeRetainedSqlite?: boolean on the session-transcript corpus reader, defaulting to the existing active-session behavior unless the new backfill caller opts in; the PR body records explicit approval of this additive seam. (packages/memory-host-sdk/src/host/session-transcript-corpus.ts:26, 8461e5d647f8)
  • Real behavior proof: The PR body links a redacted run against a copied live gateway state directory: dry-run finds 42 owner-turn candidates and stages none; apply stages 42; an immediate rerun stages zero; rollback removes the 42 staged entries and one diary block. (8461e5d647f8)
  • Merged feature provenance: The merged provenance-gated dreaming redesign is the explicitly related architectural predecessor, and this branch is rebased on its merge commit 28630a9a6501dd3835d1cf5660eb5dd9c337d3bc. (extensions/memory-core/src/dreaming-phases.ts:2051, 28630a9a6501)
  • Current-base refresh needed: GitHub reports this PR as cleanly mergeable but behind its base; the checked-out current main is 89b6d85cdd862d3315927abcc604c9e128e67314, later than the PR base recorded in the review context, so final merge proof should be refreshed on the current merge result. (89b6d85cdd86)

Likely related people:

  • steipete: Authored the related merged provenance-gated Memory Core redesign and all listed commits in this retained-session follow-on, including the retained-identity reconciliation and final CI-guard repair. (role: merged feature owner and recent area contributor; confidence: high; commits: 28630a9a6501, 5f5f3bd161cb, 0efc7aa70d8a; files: extensions/memory-core/src/session-backfill.ts, extensions/memory-core/src/dreaming-phases.ts, packages/memory-host-sdk/src/host/session-transcript-corpus.ts)

Rank-up moves

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

  • Refresh the clean merge result on current main and attach the focused final-head proof for the four command modes.

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 (2 earlier review cycles)
  • reviewed 2026-07-28T11:33:58.771Z sha 8702506 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-28T11:43:54.256Z sha 8461e5d :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Jul 28, 2026
@steipete steipete self-assigned this Jul 28, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete
steipete merged commit f0bf74b into main Jul 28, 2026
132 of 135 checks passed
@steipete
steipete deleted the feat/memory-session-backfill branch July 28, 2026 12:12
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 29, 2026
* feat(memory): enumerate retained session transcripts

* feat(memory): add session transcript backfill

* test(memory): cover session backfill workflows

* docs(memory): document session transcript backfill

* fix(memory): preserve oldest session backfill ordering

* fix(memory): harden session archive backfill

* test(memory): prove owner-turn provenance gating

* fix(memory): persist session backfill progress

* fix(memory): preserve ranged backfill progress

* fix(memory): order per-file backfill candidates

* fix(memory): retain paged backfill diary entries

* fix(memory): preserve rem backfill diary history

* fix(memory): adapt backfill to retained session identity

* fix(memory): keep rem backfill preview-only

* fix(memory): satisfy backfill CI guards
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: memory-core Extension: memory-core 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. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant