Skip to content

fix(memory): honor turn tool policy during automatic recall - #126482

Merged
joshavant merged 6 commits into
mainfrom
security/memory-recall-authority
Aug 20, 2026
Merged

joshavant merged 6 commits into
mainfrom
security/memory-recall-authority

Conversation

@joshavant

Copy link
Copy Markdown
Collaborator
Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.

What Problem This Solves

Fixes an issue where automatic memory enrichment could still retrieve context for a turn after the turn's finalized tool policy removed memory access.

Why This Change Was Made

Prompt enrichment that reads memory now runs in a host-authorized phase after restrictive prompt hooks and tool policy have finalized the callable tool surface. The authority is bound to the turn, revalidated around asynchronous retrieval, and included in recall cache ownership. Active Memory and LanceDB use the same host-owned boundary across embedded, CLI, Copilot, and Codex runtimes.

User Impact

Turns without memory access no longer receive automatic recalled context. Authorized memory workflows continue to recall normally. No configuration, protocol, or default changes are required.

Evidence

  • Focused core, hook, Active Memory, and LanceDB coverage: 483 tests passed.
  • pnpm check:changed
  • Pre-commit structured review: no actionable findings.

@clawsweeper

clawsweeper Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 19, 2026
@clawsweeper

clawsweeper Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 19, 2026, 10:12 PM ET / August 20, 2026, 02:12 UTC.

ClawSweeper review

What this changes

Adds a post-policy prompt-enrichment phase so automatic memory recall only runs when the finalized turn tool policy permits it.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open for explicit SDK/security-owner acceptance and exact-head CI. The current head fixes the prior handler-boundary finding: authority is checked before and after each authorized handler, and the new two-handler regression prevents a later recall handler from starting after closure.

Priority: P1
Reviewed head: 3869538a8a5f064433c026a1be46cb89954d3df3
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch addresses the prior blocker with focused lifecycle coverage, while the public authority contract still needs owner confirmation.
Proof confidence 🌊 off-meta tidepool Not applicable: Repository state identifies this as a member-authored PR, so the external-contributor proof gate does not apply; focused regression coverage is present.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Repository state identifies this as a member-authored PR, so the external-contributor proof gate does not apply; focused regression coverage is present.
Evidence reviewed 7 items Current-main defect: Current main runs every before-prompt hook in one modifying-hook pass, while Active Memory is registered in that phase; a restrictive later hook therefore cannot prevent an already-started recall.
Post-policy separation: The PR excludes authority-requiring handlers from the ordinary phase and dispatches them only through the authority-bound phase.
Prior finding addressed: The dispatcher asserts authority before each handler and after it returns; the latter assertion prevents a closed first handler from allowing another handler to run.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw --help

Result: PASS (completed)

pnpm openclaw --help
runner@runnervmzvulz:/tmp/clawsweeper-live-proof-126482-4R7wZ6/target$ pnpm openclaw --help
$ node scripts/run-node.mjs --help
pnpm openclaw --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 98.92 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

[tsdown-build] invocation 2/2 finished in 13.2s
[plugin-control-plane-loads] verified 36 built modules with native require and checked doctor closures
runtime-postbuild: 10 phases completed in 4255ms (slowest: built plugin control-plane loads 3465ms)

OpenClaw 2026.8.1 (3869538) — All your chats, one OpenClaw.

Usage: openclaw [options] [command]

Options:
  --container ‹name›   Run the CLI inside a running Podman/Docker container named ‹name› (default: env OPENCLAW_CONTAINER)
  --dev                Dev profile: isolate state under ~/.openclaw-dev, default gateway port 19001, and shift derived ports (browser/canvas)
  -h, --help           Display help for command
  --log-level ‹level›  Global log level override for file + console 
… output truncated …

Assertions:

  • PASS expect_output: Usage:

How this fits together

Prompt construction first applies ordinary policy hooks, then invokes opted-in enrichment hooks with the final callable tool surface. Memory plugins use that short-lived authority to decide whether recalled context may enter the model prompt.

flowchart LR
A[Incoming turn] --> B[Ordinary prompt hooks]
B --> C[Final tool policy]
C --> D[Authorized enrichment hooks]
D --> E[Memory recall]
E --> F[Final model prompt]
Loading

Decision needed

Question Recommendation
Should requiresToolAuthority and ephemeral ctx.toolAuthority become a supported public Plugin SDK contract for third-party prompt-enrichment hooks? Approve the generic authority contract: Accept the documented opt-in phase as the shared mechanism for policy-bound prompt enrichment across bundled and third-party plugins.

Why: The PR intentionally expands a plugin-facing authority boundary; source and docs establish the implementation, but do not establish owner acceptance of the permanent security contract.

Before merge

  • Resolve merge risk (P1) - The public Plugin SDK gains an authority-bearing hook option and context capability; its durable third-party contract needs explicit SDK/security-owner acceptance before merge.
  • Resolve merge risk (P1) - Production code grows by 353 net lines across the hook runner and four runtime paths, so exact-head CI should confirm the cross-runtime integration.
  • Complete next step (P2) - This protected, maintainer-associated PR needs explicit owner approval of its new authority-bearing Plugin SDK contract and exact-head green checks.
Agent review details

Security

None.

PR surface

Source +353, Tests +402, Docs +56, Other 0. Total +811 across 32 files.

View PR surface stats
Area Files Added Removed Net
Source 19 603 250 +353
Tests 11 549 147 +402
Docs 1 73 17 +56
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 32 1226 415 +811

Review metrics

Metric Value Why it matters
Production versus test delta production +353, tests/support +402, docs +56 The large but focused increase centralizes one authority phase across runtime callers instead of adding memory-specific policy exceptions.
Plugin authority surface 1 hook option and 1 ephemeral context capability added These are new plugin-facing compatibility and security-boundary commitments.

Stored data model

Persistent data-model change detected: serialized state: extensions/active-memory/recall-state.ts, unknown-data-model-change: extensions/memory-lancedb/auto-recall.ts, unknown-data-model-change: extensions/memory-lancedb/index.test.ts, unknown-data-model-change: extensions/memory-lancedb/index.ts, vector/embedding metadata: extensions/memory-core/index.ts, vector/embedding metadata: extensions/memory-lancedb/auto-recall.ts, and 1 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Confirm the public authority contract (recommended)
    Have the SDK/security owner approve the documented opt-in authority boundary before merging this compatibility-sensitive API expansion.
  2. Pause the API expansion
    Do not merge if maintainers prefer memory recall to use an internal owner seam rather than a new third-party hook capability.

Technical review

Best possible solution:

Adopt one generic post-policy authority phase only with explicit SDK/security-owner signoff, then retain the allowed/denied and closure regressions as the canonical contract.

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

Yes—current main’s single prompt-hook dispatch lets automatic recall start before a later restrictive tool policy settles; the PR’s focused hook tests model the restricted and closed-turn sequences.

Is this the best way to solve the issue?

Yes technically: a generic post-policy hook phase is cleaner than provider-specific recall guards, subject to maintainer acceptance of the new public authority contract.

AGENTS.md: found and applied where relevant.

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

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: Repository state identifies this as a member-authored PR, so the external-contributor proof gate does not apply; focused regression coverage is present.
  • remove rating: 🦪 silver shellfish: 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: Without the repair, a turn that removes memory tools can still receive automatically recalled context.
  • merge-risk: 🚨 compatibility: The PR expands the public prompt-hook registration and context contract used by plugins.
  • merge-risk: 🚨 security-boundary: The new capability determines whether an opted-in plugin may retrieve memory for an active turn.
  • 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: Repository state identifies this as a member-authored PR, so the external-contributor proof gate does not apply; focused regression coverage is present.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Current-main blame attributes the ordinary prompt-hook dispatcher and both automatic-memory hook locations to the same source snapshot. (role: current-main hook and memory-path source owner; confidence: medium; commits: 513ec6218c92; files: src/plugins/hooks.ts, extensions/active-memory/index.ts, extensions/memory-lancedb/index.ts)

Rank-up moves

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

  • Obtain explicit SDK/security-owner acceptance of the new plugin authority contract.
  • Wait for exact-head required checks to finish green.

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-08-19T23:53:59.761Z sha 6ba3753 :: found issues before merge. :: [P1] Bind authorized enrichment to host lifecycle authority | [P1] Reject restrictive Codex policy before running recall
  • reviewed 2026-08-20T00:13:50.526Z sha 3cbfa44 :: found issues before merge. :: [P1] Bind recall authority to the host run lifecycle | [P1] Reject restrictive Codex policy before enriching memory | [P1] Gate the new hook option on a newer host API
  • reviewed 2026-08-20T00:57:44.892Z sha a455ccf :: found issues before merge. :: [P1] Document the authorized prompt-hook contract
  • reviewed 2026-08-20T01:26:23.715Z sha b468d49 :: found issues before merge. :: [P1] Revalidate authority between authorized handlers
  • reviewed 2026-08-20T01:41:45.075Z sha eebfd36 :: found issues before merge. :: [P1] Revalidate authority between authorized handlers

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 20, 2026
@joshavant

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 20, 2026
@joshavant

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Aug 20, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 20, 2026
@joshavant

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@joshavant

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 20, 2026
@joshavant
joshavant merged commit 29cfd19 into main Aug 20, 2026
230 checks passed
@joshavant
joshavant deleted the security/memory-recall-authority branch August 20, 2026 02:21
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 20, 2026
…#126482)

* fix(memory): bind prompt recall to turn tool policy

* test(plugins): update hook contract inventory

* fix(memory): bind recall to active run lifecycle

* docs(plugins): define prompt authority contract

* test(plugins): track prompt authority type guard

* fix(plugins): revalidate prompt authority per handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation extensions: active-memory extensions: codex extensions: copilot extensions: memory-core Extension: memory-core extensions: memory-lancedb Extension: memory-lancedb 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. 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