Skip to content

feat(memory): retain transcript policy lineage - #123545

Closed
galiniliev wants to merge 1 commit into
openclaw:memory-permissions-p2a-integrationfrom
galiniliev:memory-permissions-p2b-integration
Closed

galiniliev wants to merge 1 commit into
openclaw:memory-permissions-p2a-integrationfrom
galiniliev:memory-permissions-p2b-integration

Conversation

@galiniliev

Copy link
Copy Markdown
Contributor

What Problem This Solves

Memory-enabled transcripts could retain scoped content as raw events without enough durable, current authorization evidence to safely replay, search, derive, archive, or restore it after a lifecycle transition. That leaves revocation, resource expiry, session rebinding, and cross-session copies vulnerable to stale historical grants or unverified provenance.

Why This Change Was Made

This Phase 2B layer makes the transcript companion the canonical retention boundary. It atomically stores immutable policy-set, actor, delivery, exposure, subject, and transition evidence; every reader revalidates the stable policy and resource state at use time. Session lifecycle owners now establish cross-session transition provenance, while unconfirmed archives and legacy imports remain quarantined.

User Impact

Operators retain ordinary conversations, while scoped-memory transcript content disappears from memory recall as soon as its policy, resource, identity, or lineage is no longer valid. Confirmed archives preserve exact authorized lineage; raw legacy archives cannot regain memory visibility merely because they are imported.

Evidence

  • Blacksmith Testbox tbx_01kzzhjsz3x1fsrrrm035egekp:
    • pnpm test src/config/sessions/session-accessor.sqlite-archive.worker.test.ts src/config/sessions/session-transcript-policy-archive.test.ts src/config/sessions/session-transcript-memory-policy.test.ts src/config/sessions/session-accessor.parent-fork.test.ts src/config/sessions/session-accessor.conformance.test.ts src/plugins/memory-run-exposure-ledger.test.ts extensions/memory-core/src/session-ingestion.test.ts
    • Passed: 104 runtime-config tests and 10 plugin-ledger tests.
  • Focused coverage proves atomic event/companion rollback, full event-class evidence, stable policy revision and revocation-epoch revalidation, resource expiry withdrawal, same-session and cross-session lineage, checkpoint/fork lifecycle behavior, archive export/confirmed-import rollback, durable token-free delegation facts, and enforced archive-ingestion quarantine.
  • oxfmt --check passed across all 22 changed files; git diff --check passed.
  • Structured Codex autoreview (--mode local) reported: autoreview clean: no accepted/actionable findings reported.
  • The Phase 2B Definition-of-Done checklist is marked with linked source/test evidence in docs/concepts/2026-07-29-memory-impl-plan.md.

Scope and review notes

  • Base: memory-permissions-p2a-integration at b5c0418ba68; head: 3122cda8551. This stack was deliberately not rebased onto main.
  • Production LOC: +2,301/-102 (net +2,199), plus schema/types. This growth establishes the required durable authorization owner boundary, immutable archive envelope, and transaction-contained transition proof. Tests: +1,012/-9. Docs: +23/-8.
  • Remote tsgo reaches only pre-existing failures outside this diff in src/agents/memory-egress-admission.ts, src/auto-reply/dispatch.ts, and extensions/codex/src/app-server/run-attempt-connection.ts; the Phase 2B transition query typing errors were fixed before commit.

@clawsweeper

clawsweeper Bot commented Aug 14, 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.

@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 Aug 14, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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. P1 High-priority user-facing bug, regression, or broken workflow. 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 Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 27, 2026, 10:07 AM ET / 14:07 UTC (Revision 8).

ClawSweeper review

What this changes

The branch stores policy and identity lineage beside SQLite transcript events and carries that lineage through reads, search, session copies, and archives.

Warning

SQLite table change

This PR modifies persisted SQLite tables in src/state/openclaw-agent-schema.sql. Prefer a design that avoids changing persisted SQLite tables. If the change is necessary, verify migration and upgrade compatibility against an existing database before merge.

Merge readiness

⛔ Blocked before merge - 11 items remain

Keep this protected draft open. Durable per-event memory policy lineage is absent from current main and the latest release, so the branch retains distinct value, but it is not ready to land.

Priority: P2
Reviewed head: 3122cda8551c27191e1de9d88cb0ff35a37aa41b
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Substantial owner-level work and focused tests are present, but real authority proof, upgrade evidence, and two correctness repairs remain.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: Authority-chain proof required: the changed SQLite transcript owner persists authority through copies and confirmed import, but the PR body supplies focused tests and checks rather than an observed allowed and nearest-forbidden read/search/archive result through the production owner. Show a real per-agent database trace with authorized content, altered archive bytes, and revoked or differently bound authority before final I/O; redact private details. Updating the PR body should trigger review, or a maintainer can request @clawsweeper re-review. Existing-state database reopening and older-reader use are also unproven. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: Authority-chain proof required: the changed SQLite transcript owner persists authority through copies and confirmed import, but the PR body supplies focused tests and checks rather than an observed allowed and nearest-forbidden read/search/archive result through the production owner. Show a real per-agent database trace with authorized content, altered archive bytes, and revoked or differently bound authority before final I/O; redact private details. Updating the PR body should trigger review, or a maintainer can request @clawsweeper re-review. Existing-state database reopening and older-reader use are also unproven. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 11 items Introduced search defect: The PR orders and limits FTS candidates before its new JavaScript policy filter; rejected top-ranked matches can consume the entire page.
Current-policy rejection: The postfilter can remove candidates after policy revision, resource expiry, or lineage checks; the tests exercise revocation and expiry separately from ranked pagination.
SQLite query contract: Official SQLite FTS5 documentation says lower bm25 scores rank better; its SELECT documentation says LIMIT bounds rows returned by that SELECT. Sources: https://www.sqlite.org/fts5.html and https://www.sqlite.org/lang_select.html.
Findings 2 actionable findings [P2] Fill search pages after authorization filtering
[P2] Bind imported archive bytes to trusted lineage
Security Needs attention Archive metadata can relabel modified event content: The importer trusts event bytes and policy references from the same archive envelope. Its final current-policy check does not authenticate those bytes against the original authorized event; the API is not yet called from production, so this is a latent boundary rather than a demonstrated live exploit.

How this fits together

OpenClaw stores each agent's session transcript in SQLite. Memory policy facts enter with transcript writes; session replay, search, and archive operations later decide which events remain visible.

flowchart LR
A[Memory policy facts] --> B[Transcript writer]
B --> C[Agent SQLite events and lineage]
C --> D{Current authority valid?}
D -->|Yes| E[Replay and search]
D -->|No| F[Hidden events]
C --> G[Session copies and archives]
Loading

Decision needed

Question Recommendation
Should per-event scoped-memory lineage remain a core SQLite responsibility on current main, with the retired checkpoint path omitted? Retain narrow core persistence: Keep opaque policy facts atomic with transcript events, move the patch to current session owners, and require the compatibility and authority proof before landing.

Why: The staged design assigns atomic persistence to core, but its base is unmerged and current main intentionally retired one lifecycle path; that scope needs an explicit owner choice.

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: Authority-chain proof required: the changed SQLite transcript owner persists authority through copies and confirmed import, but the PR body supplies focused tests and checks rather than an observed allowed and nearest-forbidden read/search/archive result through the production owner. Show a real per-agent database trace with authorized content, altered archive bytes, and revoked or differently bound authority before final I/O; redact private details. Updating the PR body should trigger review, or a maintainer can request @clawsweeper re-review. Existing-state database reopening and older-reader use are also unproven. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Fill search pages after authorization filtering (P2) - The SQL query limits ranked FTS rows before readAuthorizedTranscriptEventSeqs removes revoked, expired, or invalid-lineage matches. Enough invalid top matches hide a later authorized result and can make truncated false. Page ranked candidates until limit + 1 authorized hits are known, and cover that ordering in a regression test.
  • Bind imported archive bytes to trusted lineage (P2) - Late finding on this unchanged head: the importer appends archive-supplied event JSON, compares stored bytes back to that same input, then promotes its archive-supplied policy references. Altering a canonical event while retaining valid metadata can therefore make the internal confirmed-import API authorize content that was never exported. Bind bytes and original exposure ownership to trusted provenance before promotion; no production caller currently exposes this API.
  • Resolve security concern: Archive metadata can relabel modified event content - The importer trusts event bytes and policy references from the same archive envelope. Its final current-policy check does not authenticate those bytes against the original authorized event; the API is not yet called from production, so this is a latent boundary rather than a demonstrated live exploit.
  • Resolve merge risk (P1) - The PR's version-16 Phase 2A base is unmerged, while current main uses a newer agent database and has retired checkpoints; the clean test merge proves only the stacked base, not a current-main integration.
  • Resolve merge risk (P1) - Previously authorized Phase 2A rows have no new detail, policy-member, or resource companions and become unreadable under the new reader. A populated-database reopen and older-reader compatibility check are still missing.
  • Resolve merge risk (P1) - A revoked, expired, or pending event blocks archive-backed deletion; one such candidate can abort the history eviction pass and leave its disk budget unmet. No maintainer has accepted that operator impact.
  • Resolve merge risk (P1) - The new authority-bearing archive import lacks final-effect proof for modified archive content and for a revoked or differently bound subject.
  • Complete next step (P2) - Repair authorized search pagination and archive provenance, demonstrate authority and existing-database behavior, then obtain the current-main core ownership decision.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.

Findings

  • [P2] Fill search pages after authorization filtering — src/config/sessions/session-transcript-search.ts:156-163
  • [P2] Bind imported archive bytes to trusted lineage — src/config/sessions/session-transcript-policy-archive.ts:321-335
  • [medium] Archive metadata can relabel modified event content — src/config/sessions/session-transcript-policy-archive.ts:321
Agent review details

Security

Needs attention: No supply-chain surface changes were found; the new internal archive importer has an unresolved authorization-integrity contract.

PR surface

Source +2132, Tests +1003, Docs +15, Generated +67. Total +3217 across 22 files.

View PR surface stats
Area Files Added Removed Net
Source 15 2234 102 +2132
Tests 5 1012 9 +1003
Docs 1 23 8 +15
Config 0 0 0 0
Generated 1 67 0 +67
Other 0 0 0 0
Total 22 3336 119 +3217

Review metrics

Metric Value Why it matters
Production versus test LOC production +2,132; tests +1,003; generated types +67; docs +15 The production growth builds a durable authorization boundary, so its core ownership and upgrade behavior warrant review.
Persisted schema surface 6 tables added; 0 existing columns changed; 0 schema-version bumps Same-version companion storage requires proof that existing and downgraded readers remain safe.

Stored data model

Persistent data-model change detected: database schema: src/state/openclaw-agent-schema.sql, migration/backfill/repair: extensions/memory-core/src/session-ingestion.ts, unknown-data-model-change: src/plugins/memory-run-exposure-ledger.ts, unknown-data-model-change: src/plugins/memory-run-exposure.ts, unknown-data-model-change: src/state/openclaw-agent-schema.sql, vector/embedding metadata: src/plugins/memory-run-exposure-ledger.ts, and 1 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Integrate and prove the active paths (recommended)
    Adapt the lineage owner to current main, fix authorized search pagination, establish trusted archive provenance, and prove fresh and existing database behavior.
  2. Accept archive retention stalls
    Maintainers may explicitly retain blocked archive-backed eviction with a documented operator recovery path after the independent correctness and authority defects are fixed.
  3. Keep the stack paused
    Leave the draft open while the unmerged Phase 2A base and current session architecture have no agreed integration path.

Technical review

Best possible solution:

Integrate one transcript-lineage owner into current session storage, with authorized-result pagination, trusted archive provenance, a nonblocking quarantine outcome, and demonstrated existing-database compatibility.

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

Yes for the introduced search defect: place revoked top-ranked matches ahead of an authorized match with a small limit. The source proves the underfilled page path; this read-only review did not execute it.

Is this the best way to solve the issue?

No, not as submitted. Atomic core persistence is a plausible owner boundary, but the search page, archive authority contract, and current-main integration need repair before this is the best landing shape.

Full review comments:

  • [P2] Fill search pages after authorization filtering — src/config/sessions/session-transcript-search.ts:156-163
    The SQL query limits ranked FTS rows before readAuthorizedTranscriptEventSeqs removes revoked, expired, or invalid-lineage matches. Enough invalid top matches hide a later authorized result and can make truncated false. Page ranked candidates until limit + 1 authorized hits are known, and cover that ordering in a regression test.
    Confidence: 0.97
  • [P2] Bind imported archive bytes to trusted lineage — src/config/sessions/session-transcript-policy-archive.ts:321-335
    Late finding on this unchanged head: the importer appends archive-supplied event JSON, compares stored bytes back to that same input, then promotes its archive-supplied policy references. Altering a canonical event while retaining valid metadata can therefore make the internal confirmed-import API authorize content that was never exported. Bind bytes and original exposure ownership to trusted provenance before promotion; no production caller currently exposes this API.
    Confidence: 0.86
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.88

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7cd8ee862c7d.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is significant but unshipped memory hardening with bounded patch defects and an unresolved integration choice.
  • merge-risk: 🚨 compatibility: The new reader requires companion rows absent from existing Phase 2A databases, and no populated upgrade proof is supplied.
  • merge-risk: 🚨 session-state: Policy revocation can block archive-backed session reclamation, while the branch also changes cross-session transcript lineage.
  • merge-risk: 🚨 security-boundary: The proposed confirmed importer promotes archive-supplied lineage without authenticating the archived event bytes against their original authority.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Authority-chain proof required: the changed SQLite transcript owner persists authority through copies and confirmed import, but the PR body supplies focused tests and checks rather than an observed allowed and nearest-forbidden read/search/archive result through the production owner. Show a real per-agent database trace with authorized content, altered archive bytes, and revoked or differently bound authority before final I/O; redact private details. Updating the PR body should trigger review, or a maintainer can request @clawsweeper re-review. Existing-state database reopening and older-reader use are also unproven. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

Security concerns:

  • [medium] Archive metadata can relabel modified event content — src/config/sessions/session-transcript-policy-archive.ts:321
    The importer trusts event bytes and policy references from the same archive envelope. Its final current-policy check does not authenticate those bytes against the original authorized event; the API is not yet called from production, so this is a latent boundary rather than a demonstrated live exploit.
    Confidence: 0.86

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • vincentkoc: 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.

  • Page FTS candidates until the requested authorized result count is known and add the revoked-ranking regression.
  • Authenticate confirmed-import lineage and show allowed, altered-archive, and revoked final effects through the SQLite owner.
  • Adapt the stack to current main, prove populated-database upgrade and downgrade behavior, and obtain the core ownership decision.

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 (7 earlier review cycles)
  • reviewed 2026-08-14T07:33:11.102Z sha 3122cda :: needs real behavior proof before merge. :: [P1] Install the companion group on same-version databases | [P2] Apply authorization filtering before limiting search candidates
  • reviewed 2026-08-19T04:26:48.546Z sha 0d20184 :: found issues before merge. :: [P1] Keep the npm 12 installer acceptance check
  • reviewed 2026-08-19T09:42:32.209Z sha 3122cda :: found issues before merge. :: [P2] Fetch enough candidates after authorization filtering
  • reviewed 2026-09-02T03:12:39.591Z sha 3122cda :: found issues before merge. :: [P2] Fetch enough candidates after authorization filtering
  • reviewed 2026-09-03T01:28:25.572Z sha 3122cda :: blocked before merge. :: [P2] Fetch enough candidates after authorization filtering
  • reviewed September 27, 2026, 10:07 AM ET / 14:07 UTC (Revision 6) sha unknown :: needs real behavior proof before merge. :: [P2] Fill search pages after authorization filtering | [P2] Bind imported archive bytes to trusted lineage
  • reviewed September 27, 2026, 10:07 AM ET / 14:07 UTC (Revision 7) sha unknown :: needs real behavior proof before merge. :: [P2] Fill search pages after authorization filtering | [P2] Bind imported archive bytes to trusted lineage

@galiniliev
galiniliev force-pushed the memory-permissions-p2b-integration branch from 3122cda to 0d20184 Compare August 19, 2026 04:20
@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: nostr Channel integration: nostr channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: whatsapp-web Channel integration: whatsapp-web app: android App: android app: ios App: ios app: macos App: macos labels Aug 19, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for the PR. We're closing older pull requests that have gone stale against current main.

This draft has had no commits since August 14 and changes persisted SQLite tables without the required migration proof. Please open a fresh PR against current main if this phase is still planned.

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: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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.

2 participants