Skip to content

fix: keep session history private and recall current - #149529

Merged
steipete merged 3 commits into
mainfrom
codex/session-history-cleanup
Sep 16, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/session-history-cleanup

Conversation

@steipete

@steipete steipete commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Closes #118437

What Problem This Solves

Fixes stale session recall and usage totals, cross-agent usage counting in shared stores, retained private-history access after deletion, and repeated history reloads during message bursts.

User Impact

Session history keeps its sharing rules, same-size transcript edits appear in recall after restart, and configured-store usage totals stay current and scoped to the requested agent. Exact imported multiline transcripts remain readable after archival. No configuration change or schema migration is required.

Memory indexing uses transcript revisions for freshness while preserving source activity for temporal ranking and message provenance. Existing source hashes refresh after content verification; unchanged chunks are retained. Forced rebuilds restore cold transcripts through the existing storage owner. A failed restore preserves the published index and retry state.

Direct reads of a deleted session's retained transcript require operator.admin when no live logical entry remains. Task history keeps its separate authorization and binding checks. This closes the reproduced private-history leak without granting access from a retained identifier alone.

Why This Change Was Made

History publication rechecks current sharing authority. Usage refresh carries its original store and logical agent throughout the operation. Archive attribution uses the existing SQLite sibling family and preserves lexical store locators when deduplicating physical aliases. The archive reader retains its compact-JSON fast path while accepting exact multiline imports.

SSE invalidations share pending refreshes while preserving inline event order and a trailing read for changes during an active read. Multi-session statistics use the existing batch API; single-session lookups keep the cheaper point query. Redundant scans, copies, and worker error plumbing are removed. With the temporal-ranking repair included, production code is 13 lines larger overall (464 added, 451 removed).

Unregistered legacy artifacts retain the existing file-reader accounting behavior. Their headers and filenames do not establish a reliable agent owner; this change filters authoritative archive registrations without guessing ownership or discarding historical usage.

Evidence

Current head 8ad19dd69ff6e051c1ae6fa8ca1f00f08da5860d and baseline 6cf521932af06af674a90e2319ccbd6212261e5d were freshly built and compared in one Linux Blacksmith Testbox invocation. All 37 candidate checks passed; baseline passed 20/37. The command completed successfully and the lease was stopped. The candidate production build passed in 5m 6.8s.

Actual built Gateway/CLI checks cover cursor paging, anchors, retained privacy, SSE, configured/shared usage, real archival across fixed JSON/shared SQLite/symlink stores, cold recall, equal-size edits, and legacy source-hash convergence. The eight clock/upgrade checks verify preserved activity and provenance, correct keyword ranking, fresh recall after offline edits, unchanged chunk rows for metadata-only upgrades, and a clean subsequent startup.

Measurement Baseline Candidate
400 hot-session inventory median, 9 samples 7.920 ms 5.466 ms
40 cold + 360 hot inventory median, 9 samples 8.309 ms 4.580 ms
SSE frames for 100 updates 100 35
Duplicate SSE frames 65 0
Last SSE frame latency 614.246 ms 512.329 ms
Ordinary HTTP page median, 15 samples 4.736 ms 7.028 ms
Ordinary HTTP page p95, 15 samples 19.444 ms 9.561 ms

The strongest gains are inventory work and update bursts. The ordinary HTTP median increased in this run while its p95 decreased; these samples do not establish a general single-page latency improvement. The ordinary HTTP query path is unchanged apart from parsing its URL once.

  • Focused Gateway, storage, usage, and memory regressions pass, including all 22 archive ownership cases. Empty artifact discovery makes zero archive queries; a shared SQLite file makes one, and two siblings make two even with an alias.
  • The clock repair passes 129 focused tests plus six required guard tests. The complete selected changed gate passes, including all four type lanes, both linters, dead-export/import-cycle checks, and storage guards.
  • Independent Codex review found no actionable P0–P2 findings, including the final dual-clock repair. ClawSweeper's current-head review also found no code or security defect.
  • Current-head CI passed, including its final aggregate gate. Exact run metadata confirms the completed successful run is attached to this head.

CI caught the temporal-ranking regression before landing; its five failures were repaired without changing their expectations. One earlier cold Gateway fixture import exceeded its existing setup deadline and passed on an exact rerun with the unchanged deadline. Live proof uses synthetic sessions and proxy identities without inference or an external identity-provider exchange. Legacy-hash proof seeds the verified old index format rather than running an old published binary; lexical/hybrid modes are covered by focused tests.

@clawsweeper

clawsweeper Bot commented Sep 15, 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.

@steipete
steipete force-pushed the codex/session-history-cleanup branch from a7c7c34 to a1ed7e1 Compare September 15, 2026 23:57
@steipete
steipete marked this pull request as ready for review September 15, 2026 23:58
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. 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. labels Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 15, 2026, 11:00 PM ET / September 16, 2026, 03:00 UTC (Revision 6).

ClawSweeper review

What this changes

The PR tightens session-history access, repairs memory recall freshness and configured-store usage totals, supports multiline archived records, and coalesces streamed-history refreshes.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains useful, protected implementation work. The earlier archive-ownership finding is addressed, and the requested current-head upgrade and ranking results are now supplied. No blocking code defect was found.

Priority: P2
Reviewed head: 8ad19dd69ff6e051c1ae6fa8ca1f00f08da5860d

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful repair with focused regression coverage and specific current-head behavioral results, with no remaining actionable code finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Captured current-head Linux Gateway/CLI results cover retained-history denial, configured/shared-store accounting, cold recall recovery, equal-size edits, legacy-hash convergence, and preserved temporal ranking. They satisfy the previous specific proof follow-up; raw linked-log inspection remains a disclosed reviewer limitation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Captured current-head Linux Gateway/CLI results cover retained-history denial, configured/shared-store accounting, cold recall recovery, equal-size edits, legacy-hash convergence, and preserved temporal ranking. They satisfy the previous specific proof follow-up; raw linked-log inspection remains a disclosed reviewer limitation.
Evidence reviewed 10 items Verified introduction boundary: The recorded test merge has the pinned base followed by the exact reviewed head as parents. Its comparison against that base contains the session, memory, usage, documentation, and test changes; the unrelated Codex and UI changes are base drift.
History authority and publication: Direct retained reads require admin authority when the logical entry is absent. Live entries are checked before loading and again before publication, including identity and lifecycle changes. The retained-sharing test covers denial before and after deletion, permitted admin access, and loss of admin authority during awaited preparation.
Separate task-history authorization: The retained task-history caller validates current task access, transcript binding, configured store, and active request immediately before publishing. The internal retained-session argument is not exposed as an unchecked wire parameter.
Findings None None.
Security None None.

How this fits together

OpenClaw stores conversation transcripts in SQLite and retained archives. Gateway history readers, memory indexing, and usage accounting consume those records to produce conversation views, recall results, and spending totals.

flowchart TD
  A[Conversation updates] --> B[SQLite transcripts and archives]
  B --> C[Current access checks]
  C --> D[Gateway history responses]
  B --> E[Memory freshness and indexing]
  E --> F[Recall results]
  B --> G[Store and agent scoped accounting]
  G --> H[Usage totals]
Loading

Before merge

  • Resolve merge risk (P1) - Non-admin clients that directly read a deleted session's retained transcript will now be denied; the maintainer explicitly confirms this privacy repair, while separately authorized task history remains supported.
  • Resolve merge risk (P1) - The raw Testbox trace could not be inspected through this environment's download allowlist; the detailed captured results remain the available behavioral evidence.
Agent review details

Security

None.

PR surface

Source +13, Tests +694, Docs +10, Other 0. Total +717 across 30 files.

View PR surface stats
Area Files Added Removed Net
Source 14 464 451 +13
Tests 13 715 21 +694
Docs 2 12 2 +10
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 30 1192 475 +717

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +13 lines; tests net +693 lines The small production increase supports separate freshness and activity clocks, while most growth exercises history, archival, usage, and recall regressions.

Stored data model

Persistent data-model change detected: unknown-data-model-change: extensions/memory-core/src/memory/manager-session-sync-ops.ts, unknown-data-model-change: extensions/memory-core/src/memory/manager-source-sync-ops.ts, unknown-data-model-change: packages/memory-host-sdk/src/host/session-files.ts, vector/embedding metadata: extensions/memory-core/src/memory/manager-session-sync-ops.ts, vector/embedding metadata: extensions/memory-core/src/memory/manager-session-sync-state.ts, vector/embedding metadata: extensions/memory-core/src/session-ingestion.ts, and 1 more. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #118437
Summary: This PR is the explicit candidate fix for the configured-store usage issue; its additional history and recall repairs extend beyond that report.

Members:

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

Merge-risk options

Maintainer options:

  1. Retain the documented privacy boundary (recommended)
    Accept the explicitly confirmed restriction on direct non-admin retained-history reads while preserving the separately authorized task-history path.

Technical review

Best possible solution:

Retain the maintainer-confirmed history boundary and existing storage owners, with revision-based recall freshness that preserves activity ranking and upgrades derived hashes without replacing unchanged chunks.

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

Yes, source establishes the equal-size transcript rewrite and configured-store accounting paths, with concrete baseline/candidate observations supplied in the discussion. This read-only review did not execute them locally.

Is this the best way to solve the issue?

Yes. The patch extends the existing transcript, sharing, and accounting owners, preserves content/provenance clocks, and refreshes derived metadata through conditional writes without introducing another storage or authorization owner.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. Captured current-head Linux Gateway/CLI results cover retained-history denial, configured/shared-store accounting, cold recall recovery, equal-size edits, legacy-hash convergence, and preserved temporal ranking. They satisfy the previous specific proof follow-up; raw linked-log inspection remains a disclosed reviewer limitation.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: This repairs bounded session-history, recall, and configured-store accounting defects without evidence of a widespread runtime outage.
  • merge-risk: 🚨 compatibility: Direct retained-history access intentionally becomes unavailable to non-admin callers after logical session deletion.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; 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. Sufficient (live_output): Captured current-head Linux Gateway/CLI results cover retained-history denial, configured/shared-store accounting, cold recall recovery, equal-size edits, legacy-hash convergence, and preserved temporal ranking. They satisfy the previous specific proof follow-up; raw linked-log inspection remains a disclosed reviewer limitation.
  • proof: sufficient: Contributor real behavior proof is sufficient. Captured current-head Linux Gateway/CLI results cover retained-history denial, configured/shared-store accounting, cold recall recovery, equal-size edits, legacy-hash convergence, and preserved temporal ranking. They satisfy the previous specific proof follow-up; raw linked-log inspection remains a disclosed reviewer limitation.

Evidence

What I checked:

  • Verified introduction boundary: The recorded test merge has the pinned base followed by the exact reviewed head as parents. Its comparison against that base contains the session, memory, usage, documentation, and test changes; the unrelated Codex and UI changes are base drift. (71b0f50eb404)
  • History authority and publication: Direct retained reads require admin authority when the logical entry is absent. Live entries are checked before loading and again before publication, including identity and lifecycle changes. The retained-sharing test covers denial before and after deletion, permitted admin access, and loss of admin authority during awaited preparation. (src/gateway/server-methods/chat-history-handler.ts:189, 8ad19dd69ff6)
  • Separate task-history authorization: The retained task-history caller validates current task access, transcript binding, configured store, and active request immediately before publishing. The internal retained-session argument is not exposed as an unchecked wire parameter. (src/gateway/server-methods/task-history.ts:111, 8ad19dd69ff6)
  • Memory upgrade preserves content and activity: Source synchronization compares the content hash separately from the SQLite revision prefix and conditionally updates existing source metadata without replacing unchanged chunks. Export activity and provenance clocks remain separate from the mutation watermark; cold restoration uses the existing transcript owner. (extensions/memory-core/src/memory/manager-source-sync-ops.ts:303, 8ad19dd69ff6)
  • Earlier archive finding addressed: Archive attribution now enumerates the existing durable sibling-store family and deduplicates physical aliases while retaining lexical locators. Registered archives are filtered by logical agent. Regression coverage includes shared SQLite, fixed JSON, and symlink stores before and after archival; unregistered legacy accounting is explicitly retained. (src/infra/session-cost-usage-collection.ts:98, 8ad19dd69ff6)
  • Current-main necessity: Inspected main still compares memory startup freshness using activity and size without the new transcript revision check. Its usage-cache entrypoint also lacks the branch's explicit configured-store propagation. (extensions/memory-core/src/memory/manager-session-sync-state.ts:60, b09af220ef31)

Likely related people:

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

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 (5 earlier review cycles)
  • reviewed 2026-09-16T00:07:13.773Z sha a1ed7e1a82b962df45ef298edd3c9e9e8b424dc8 :: needs real behavior proof before merge. :: [P2] Resolve archive owners across sibling store databases
  • reviewed 2026-09-16T00:21:27.305Z sha a1ed7e1a82b962df45ef298edd3c9e9e8b424dc8 :: needs real behavior proof before merge. :: [P2] Resolve archive owners across sibling store databases
  • reviewed 2026-09-16T01:05:54.167Z sha ebcc811967b3c1b47513a8310339795e5fcbea21 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-16T01:20:43.524Z sha 6af7924da7ea711970706ff42cd6498ebb71c30c :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-16T02:25:24.042Z sha 8ad19dd :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Sep 16, 2026
@steipete
steipete force-pushed the codex/session-history-cleanup branch from ebcc811 to 6af7924 Compare September 16, 2026 01:13
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime extensions: memory-core Extension: memory-core size: XL maintainer Maintainer-authored PR labels Sep 16, 2026
Preserve retained-history sharing, configured-store usage and logical ownership, multiline archived records, and memory freshness across rewrites and cold rebuilds. Coalesce history stream invalidations and batch multi-session statistics while removing redundant production code.
Resolve registered archive owners through the existing bounded SQLite family, deduplicating physical files while preserving lexical store ownership semantics. Cover fixed JSON selectors and shared symlink locators; retain existing unregistered legacy-file compatibility.
Track transcript mutation separately from session activity. Verify legacy source hashes before refreshing metadata, preserve unchanged chunks, and retain content and provenance clocks for recall and ingestion.
@steipete
steipete force-pushed the codex/session-history-cleanup branch from 6af7924 to 8ad19dd Compare September 16, 2026 02:14
@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. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 16, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Current-head validation is complete for 8ad19dd69ff6e051c1ae6fa8ca1f00f08da5860d: the full CI run passed, and the Linux Testbox comparison passed all 37 candidate checks against 20/37 on the freshly built baseline. The wrapper exited successfully and the lease is stopped. The PR body contains the final measurements and limitations.

The real CLI upgrade checks detected the legacy bare hash, verified content before updating its revision, preserved every unchanged chunk row, and started clean afterward. A same-size offline rewrite produced one new recall hit and zero stale hits. Both ranking checks retained the expected old/fresh score ratio of 0.7071067812, with original activity and provenance timestamps preserved. This uses the verified old index format, not an old published binary.

The retained-history boundary is the intended privacy repair: without a live logical session, direct retained reads require operator.admin; separately authorized task history retains its existing binding checks. The live non-admin request stayed denied before and after deletion, and focused tests cover admin access and authorization loss before publication. No further source defect remains from review.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Sep 16, 2026
@steipete
steipete merged commit 7009eb0 into main Sep 16, 2026
215 checks passed
@steipete
steipete deleted the codex/session-history-cleanup branch September 16, 2026 03:33
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 16, 2026
* fix: keep session history private and recall current

Preserve retained-history sharing, configured-store usage and logical ownership, multiline archived records, and memory freshness across rewrites and cold rebuilds. Coalesce history stream invalidations and batch multi-session statistics while removing redundant production code.

* fix: attribute archives across sibling session stores

Resolve registered archive owners through the existing bounded SQLite family, deduplicating physical files while preserving lexical store ownership semantics. Cover fixed JSON selectors and shared symlink locators; retain existing unregistered legacy-file compatibility.

* fix: preserve memory recall recency after transcript edits

Track transcript mutation separately from session activity. Verify legacy source hashes before refreshing metadata, preserve unchanged chunks, and retain content and provenance clocks for recall and ingestion.
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 gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

[Bug]: usage and cost totals are empty when session.store is configured

1 participant