Repository navigation
feat(memory): resolve the memory audience in the host - #162176
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed October 2, 2026, 6:12 PM ET / 22:12 UTC (Revision 13). ClawSweeper reviewWhat this changesThe host determines each turn’s private or conversation memory access, carries it through memory providers, tools and hooks, and reports native provider health. Merge readiness⛔ Blocked before merge - 1 item remains This remains distinct, useful work beyond the merged provider runtime. Earlier findings are resolved, and the recorded interface and upgrade decisions cover the current change; no new blocking defect was identified. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw’s memory subsystem supplies recalled information to agent turns. The host uses trusted sender facts and stored parent-session lineage to determine which memory a provider may expose. flowchart TD
A[Trusted agent turn] --> B[Selected memory provider]
B --> C[Legacy memory path]
B --> D[Validate session lineage]
D --> E[Private or conversation audience]
E --> F[Provider and tool currency guards]
F --> G[Memory results and prompt recall]
Before merge
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep memory partition selection and revocation with the host, while providers enforce visibility using the supplied live audience and legacy providers retain their established behavior. Do we have a high-confidence way to reproduce the issue? Not applicable as a feature request; the supplied runtime traces directly exercise the new memory audience behavior and its rejection cases. Is this the best way to solve the issue? Yes. Centralizing audience resolution and currency with the host avoids competing provider-side authority logic, and the recorded decisions cover the interface and upgrade tradeoff. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 99f1f78b6bcf. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (12 earlier review cycles; latest 8 shown)
|
7eea7b5 to
d6608bb
Compare
1e94828 to
579d7df
Compare
579d7df to
a58687c
Compare
d6608bb to
3e6aa3b
Compare
a58687c to
2538b39
Compare
3e6aa3b to
9b89d7a
Compare
Fold the real session-owner audience test into the shared real-lineage fixture, drop the spawn lineage unit test that the real-SQLite spawn tests already cover, share spawn parameters, and remove cases that only mirrored implementation (log text, mock passthrough, per-kind passthrough).
What Problem This Solves
Memory providers have to re-derive whether a caller acts for the owner privately or for one conversation, walking spawn lineage through session lookups themselves.
User Impact
When a native memory provider owns the slot, the host resolves a
MemoryAudienceper turn and hands it to the provider, the provider's own tools, hooks and Codex dynamic tools. Recall never serves one audience's results to another, andopenclaw doctor/statusreport a native provider's health.When Memory Core or a
runtime-only (V1) plugin owns the slot, nothing changes: no audience is minted, there are no lineage reads or leases, no upgrade warning, and unrelated plugin tools are never gated by memory currency.Upgrade behavior (accepted by maintainer decision below): under a native provider, spawned sessions created before lineage receipts existed get no memory audience. They fail closed, and a warning tells the operator to respawn; respawning restores access. Top-level sessions and Memory Core/V1 installs are unaffected.
Why This Change Was Made
Every spawn producer stamps a trusted lineage receipt. That covers
sessions_spawn,sessions.create, ACP, and realtime consults (meeting bot, voice call, FaceTime). Owner status comes only from trusted host facts. The host mints audiences from exact lineage, reading parent rows on the session read worker with a lease on each hop's incarnation.Audience currency is enforced at every memory boundary:
assertCurrentthat includes audience currency, checked before and afteropen().prependContextand before caching.close().Fixes in this revision:
deterministicRecallToolNamegate.recallToolNamesdeclaration, with every declared tool allowed. The SDK guide now documents this.conversationaudience instead of a spurious legacy warning.run-attempt.prompt-hook-audience.test.ts, which fails without the fix.sessions.listunchanged: the spawn receipt is stored in an unprojectedspawnedBySessionIdfield, so main's existingparentSessionIdfield and its consumers are untouched.Evidence
Live proof on an isolated Gateway through real entry points, with the real Knowledge plugin as the native provider and a deterministic model. Proof build
e57ddfeeaadon maind7fd9a7dea1; it is runtime-identical to the pushed tips. The pushed tips were rebased onto newer main through a mechanical method-list conflict, andprotocol:checkplus the method-list and memory Gateway tests pass on them.Results and redacted traces
Build: stack ; candidate
e57ddfeeaad(base for upgrade/compat cells:d7fd9a7dea1). Isolated Gateway on its own port,HOME,OPENCLAW_STATE_DIRandOPENCLAW_CONFIG_PATHunder a scratch directory, launched withenv -i(no provider credentials, no access to the operator's~/.openclaw).Harness (real entry points, deterministic model):
chat.sendRPC (operator withoperator.admin, as the Control UI owner connects) and through the bundledqa-channelplugin polling the repository's QA bus (group conversation, non-owner senderstranger). Children are created by the model calling the realsessions_spawntool; resets usesessions.reset./v1/chat/completionsserver configured as a normalmodels.providersentry. It emits the tool calls named in the user message (through the default Tool Searchtool_callsurface) and can hold a response on a named gate so a reset can land between audience minting and tool dispatch. Admission, tool dispatch, flush planning and compaction are all product code.feat/provider-neutral-memory, built against this OpenClaw build) with its own store under the isolated state dir. A pass-through tap module loads Knowledge's unmodified entry and records, at the provider boundary, the host-suppliedmemoryAudience/memoryFlusheach provideropen/search/get/candidatescall and Knowledge tool execution received and whether Knowledge returned or refused. It never changes arguments, results or errors.[provider]lines below come from it;[model#n]lines are what the Gateway sent to the model (including any Active MemoryprependContext);[gateway]lines are the Gateway's own file log.main/direct chats so lane-1 trigger recall (provider.candidates→prependContext) is observable.<uuid#n>).Results
owner-privateand gets owner recordsconversationaudience; owner records absent; no owner-partition I/Oconversationaudience; no owner-private access and no respawn warningprependContextis publishedprependContextpublished (control without reset publishes it)1. Owner-direct session
Commands (operator
chat.sendtomain, model directives in the message):Decision point: the turn's audience is
owner-private; Knowledge resolves the private partition (scope=private), returns the owner record, accepts the owner-only recall approval, and the next owner turn's Active Memory lane-1 lookup publishes the approved summary asprependContext.2. Conversation isolation (qa-channel group, non-owner)
Command: QA bus
POST /v1/inbound/message {conversation:{id:"proof-room",kind:"group"}, senderId:"stranger", text:"…grep / lookup by exact title / record by the owner record id / recall clear / status"}.Decision point: the group root's durable
chatType=groupyields aconversationaudience bound to that session key and id. Knowledge resolves the conversation partition, so the owner record is absent to search, exact lookup and exact read by id; the owner-only recall tool refuses; no provider call during the case carries an owner-private audience; and no recall summary is injected.2b. Group-rooted spawned child
Commands: qa-channel group
proof-room, non-owner senderstranger:@@tool sessions_spawn {task:'GROUPCHILD ready\n@@tool knowledge_grep {…}\n@@tool knowledge_status {}'}.3. Lineage, then reset of a captured ancestor
3a. Child inherits, ancestor reset, next child turn
Commands:
chat.send main "@@tool sessions_spawn {task:'CHILD-A…\n@@tool knowledge_grep {…}', cleanup:'keep'}", thensessions.reset {key:<main-session-key>}, thenchat.send <child> "Status check on the lisbon launch please.\n@@tool knowledge_grep {…}".Before the reset (child turn):
After the reset (child turn):
Decision point: lineage resolution re-reads the parent row and finds the recorded parent incarnation gone, so no audience is minted. Knowledge refuses both the Active Memory provider open and the tool (no partition is opened), and the prompt carries only Active Memory's "skipped" note, not the owner summary.
3b. Reset lands between audience minting and the tool call
Commands: spawn
CHILD-C;chat.send <child> "…\n@@gate childc\n@@tool knowledge_grep {…}"(model holds its first response);sessions.reset {key:<main-session-key>}; release the gate.While held (audience already minted for the child turn):
After the ancestor reset and release:
Decision point: the host's plugin-tool invocation guard (
bindPluginToolCallbacks→ the tool factory context'sassertInvocationCurrent) callsassertMemoryAudienceCurrentbefore the plugin'sexecute; the parent's generation lease is revoked, so the call fails withmemory audience is no longer currentbefore Knowledge's tool body runs (the tap records no execution). Note that a reset of the spawning parent aborts an in-flight spawn task outright (AbortError taskKind=spawn), so this case uses a continuation turn in the child, which the parent reset does not abort.3c. Active Memory recall in flight when the captured ancestor is reset
Commands: spawn
CHILD-E; positive controlchat.send <child> "What did we decide previously about the venue?"; then with the scripted model holding the deep-recall sub-agent's final summary (POST /control {recallGate}, released after itsknowledge_grepreturned),chat.send <child> "Do you remember what we discussed earlier about the venue?",sessions.reset {key:<main-session-key>}, release.Positive control (no reset): the deep-recall summary is published to the child's turn:
Held (recall sub-agent searched with the child's inherited audience; its summary is pending):
After the ancestor reset and release:
Decision point: the recall sub-agent still finishes (
done status=ok summaryChars=…), but Active Memory rechecks the turn's audience currency immediately before publishing; the parent incarnation captured by the child's audience is gone, so nothing is published to the child's turn (no deep summary, no lane-1 summary).4. Legacy spawned row (upgrade)
Commands: base build
d7fd9a7dea1:chat.send main "@@tool sessions_spawn {task:'LEGACY-CHILD ready', cleanup:'keep'}"; stop. Candidate build on the same state dir with Knowledge selected: owner saves a record;chat.send <legacy child> "@@tool knowledge_grep {…}"; thenchat.send main "@@tool sessions_spawn {task:'RESPAWNED-CHILD\n@@tool knowledge_grep {…}'}".Spawned by the pre-PR build:
Legacy child on the candidate:
Respawned child:
Decision point: the row has
spawnedBybut neitherspawnedBySenderIsOwnernorparentSessionLifecycleRevision, so resolution denies with the operator-visible WARN and Knowledge refuses. A child respawned by the candidate carries the receipts and gets the owner audience back.Case 10 (partial tool policy), same build: with one of Knowledge's declared recall tools denied by tool policy, Active Memory made 0 trigger lookups and injected nothing. The control run made 2 lookups and injected the recalled summary once.
Regression tests (real SQLite, worker reads and leases where lineage is involved), each failing before its fix:
Gates on the final tree:
tsgolanes,check:architecture,protocol:check, plugin-sdk checks,docs:check-mdxand focused vitest (48 files): passtest(memory): consolidate memory audience tests, tests only): removed duplicate and implementation-mirroring cases (−261 test lines, two fewer test files). The 10 affected files pass locally; thetsgocore-test and extensions-test lanes pass on Testbox.check-changed: lint fails only on inheritedmax-lineserrors in files with identical counts on mainDifferential compatibility vs main for Memory Core and V1 configurations: no differences outside #162175's intended list.
Inherited CI failures
CI on
ac370e8edd5failed one test that was this PR's:src/talk/agent-consult-runtime.test.tsstrictly compared the consult child's session entry, which now intentionally carries the parent's lineage receipt.a3c9bbdfc24fixes it, and that test passes in CI ona3c9bbdfc24.CI on
a3c9bbdfc24fails 4 shards, none caused by this PR. It touches none of these files, and main has no later change to them.compact-large-33-2src/plugins/host-hook-cleanup.session-store.test.ts, two cases (SQLite file bytes differ after cleanup)0dc63eecadd(main with #162175) in a clean worktree: 2 failed, 18 passed.compact-small-12-2src/gateway/server-methods/sessions-list-persisted-worker.test.ts("Auth profile read owner was revoked")0dc63eecaddin a clean worktree: 1 failed, 2 passed.compact-small-8-1src/config/sessions/conversation-registry.test.ts(database is locked)0dc63eecaddin a clean worktree: the same 2 cases.compact-large-19-1src/gateway/github-repository-publication-restart.test.ts(database is locked)As on #162175, these are agent-database lifecycle and locking failures currently on main.