Skip to content

fix(memory): Knowledge calls fail mid-turn after unrelated session activity - #166419

Merged
jalehman merged 3 commits into
mainfrom
fix/memory-audience-readiness
Oct 7, 2026
Merged

jalehman merged 3 commits into
mainfrom
fix/memory-audience-readiness

Conversation

@jalehman

@jalehman jalehman commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: memory-slot tools (for example Knowledge) fail mid-turn with memory audience currency is unavailable; retry the operation / SESSION_DELIVERY_GENERATION_UNAVAILABLE when unrelated session or registry activity happens during the turn.

User Impact

User impact: long agent turns that read or write memory no longer lose access partway through because another session, agent database, or session group changed. Retrying within the same turn could never recover, so long ingestion and research runs stalled.

Why This Change Was Made

Since the memory audience moved into the host (#162176), each memory call checks a session generation lease. Three unrelated events left that lease permanently unavailable for the rest of the turn:

  • any agent-database registry topology publication, even for databases the session never read;
  • catalog-only session-group edits (sessions.groups.*), which were announced as full session changes;
  • a write to the session's own row that was still being published when the memory call ran.

This change limits registry invalidation to the candidate sources the lease actually witnessed, marks group edits catalog-only, and has the memory host wait for admitted publications of the audience's sessions (and its delegating parents) before the synchronous final currency check. A real incarnation change (new session id or lifecycle revision) still revokes the audience, and cancellation still aborts the wait.

Evidence

Live failure: a Granola-to-Knowledge ingestion session on a main Gateway hit the error repeatedly while reads and writes in the same session succeeded moments earlier and later.

Live after-fix proof (fsn1 Gateway, dd619529b24 plus this PR and #166417, systemd user service, Knowledge as the memory slot), in a fresh dashboard session on agent main:

Step (one agent turn) Result
knowledge_status ok, scope conversation:<session>
sleep 75; meanwhile sessions.groups.put with the unchanged catalog, sessions.patch relabeling this same session, and sessions.create of a sibling session all three committed during the sleep
knowledge_status again ok, same scope
knowledge_records(limit: 1) ok

The session's lifecycle revision was unchanged across the turn. Revocation still applies: after sessions.reset on the parent, its existing subagent's next knowledge_status failed with Knowledge access unavailable: trusted agent/session authority is required.

  • Retained child authority through the new wait, against the real SQLite session owner and memory provider adapter (session-accessor.sqlite-generation-readiness.test.ts): a delegated child audience is minted through the real lineage walk, then its parent's publication is held mid-flight. While held, the child's read is pending (not failed, provider not called). A parent metadata write lets the read reach the provider afterwards; a parent reset (same session id, new lifecycle revision) rejects it with no provider I/O and the audience stays revoked. Both cases fail against main production code and pass here; the file runs in 29 s wall with --maxWorkers=1 (23 s Vitest).
  • Plugin tools keep their existing cancellation contract: an already-aborted call still runs the tool, and a retired plugin runtime still reports that it is no longer active (tools.optional.test.ts, 76/76).
  • The new regression tests fail on main (16 failures across session-delivery-generation.registry.test.ts, session-accessor.sqlite-generation-readiness.test.ts, memory-audience.test.ts, memory-provider-runtime.test.ts, sessions-groups.test.ts) and pass with this change (94/94 across those files).
  • pnpm test src/config/sessions/session-delivery-generation.registry.test.ts --maxWorkers=1: 64 s wall, about 19 s of test time on a loaded laptop; each case exercises real SQLite registry publications, which is the boundary under test. src/plugins/memory-audience.test.ts --maxWorkers=1: 72 s wall on the same host.
  • Revocation still wins over the new waits: memory-audience.test.ts covers a child revoked after a parent reset or removal, parent reset/release/abort while a publication wait is pending, and a child publication when the parent rejects preparation; memory-provider-runtime.test.ts rejects an audience presented by a different session. Registry tests use real SQLite publications for removal, reassignment, ABA, rollback, and changes during preparation.
  • No stored data or schema changes: memory audience records live in process memory (WeakMaps keyed by host-minted audience objects) and are rebuilt on every turn; nothing is persisted, migrated, or read back across upgrades.
  • node scripts/check-changed.mjs --base dd619529b24: passed (format, core typecheck graphs, lint, dead-export scans, guards).

🤖 Generated with Claude Code

@clawsweeper

clawsweeper Bot commented Oct 7, 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 gateway Gateway runtime size: L labels Oct 7, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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 Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 7, 2026, 5:26 AM ET / 09:26 UTC (Revision 6).

ClawSweeper review

What this changes

The PR keeps memory tools available during unrelated session activity by narrowing registry invalidation and waiting for relevant session publications before checking authority.

Merge readiness

⛔ Blocked before merge - 1 item remains

This PR remains necessary: pinned main still invalidates memory authority after unrelated activity. No blocking patch defect remains, and the previous migration concern does not apply because no stored-data contract changes.

Priority: P1
Reviewed head: 55398734fc9c08a146df0c64b4f18c273ef4481b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with relevant live evidence, meaningful production-boundary regressions, and no remaining blocking findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Captured live Knowledge results exercise successful memory calls across unrelated publications and denial after parent reset. The real SQLite owner, lineage resolver, and provider adapter additionally exercise the held-publication window, allowing metadata settlement while rejecting reset authority before provider invocation; the provider body only counts calls. No stored-data contract changes require migration proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Captured live Knowledge results exercise successful memory calls across unrelated publications and denial after parent reset. The real SQLite owner, lineage resolver, and provider adapter additionally exercise the held-publication window, allowing metadata settlement while rejecting reset authority before provider invocation; the provider body only counts calls. No stored-data contract changes require migration proof.
Evidence reviewed 10 items Pinned introduced patch: Reviewed the introduced production changes and all six changed test or test-support files between the supplied main and head identities. The verified test merge has those exact main/head parents; no base-only changes were attributed to this PR.
Current-main defect remains: Main unconditionally marks a generation lease invalid on any topology publication, before considering its agent or source. Its memory provider boundaries also lack the new publication preparation. The related merged cron repair addresses lifecycle revision rotation rather than these triggers.
Final authority checks remain: The provider adapter prepares relevant publications, then synchronously checks caller, audience, cancellation, and provider lifetime immediately before invoking the provider. It repeats preparation and checks before returning results. Tool execution retains its invocation guard after the memory-owner-only wait.
Findings None None.
Security None None.

How this fits together

OpenClaw’s memory host grants access from trusted session lineage and supplies it to memory providers and tools. Session publications update those grants, allowing unchanged sessions to continue while rejecting reset or released sessions.

flowchart TD
  A[Agent memory request] --> B[Host session audience]
  C[Session and registry publications] --> D[Relevant publication readiness]
  B --> D
  D --> E[Current authority check]
  E -->|Valid| F[Memory provider or tool]
  E -->|Revoked| G[Access denied]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +167, Tests +652. Total +819 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 7 183 16 +167
Tests 6 655 3 +652
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 838 19 +819

Review metrics

Metric Value Why it matters
Production versus regression growth production +167 net lines; tests and test support +652 net lines Production growth implements scoped registry witnesses and publication readiness; most growth protects invalidation and revocation behavior.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/plugins/memory-audience.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: canonical
Canonical: #166419
Summary: This PR owns unrelated-publication readiness; the related merged work addresses distinct feature, cron, and test-fixture responsibilities.

Members:

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

Technical review

Best possible solution:

Keep publication readiness in the existing session authority owner while preserving synchronous revocation checks at every memory effect boundary.

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

Yes, source establishes a focused path: mint a memory audience, publish unrelated registry topology, then invoke its memory tool on pinned main. Contributor live evidence and failing baseline regressions corroborate it; this review did not execute the path.

Is this the best way to solve the issue?

Yes. Reusing the existing publication and registry owners repairs transient unavailability without weakening incarnation revocation or creating another authority mechanism.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Reported real ingestion and research turns lose memory-tool access mid-turn after unrelated session activity.
  • 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 live Knowledge results exercise successful memory calls across unrelated publications and denial after parent reset. The real SQLite owner, lineage resolver, and provider adapter additionally exercise the held-publication window, allowing metadata settlement while rejecting reset authority before provider invocation; the provider body only counts calls. No stored-data contract changes require migration proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. Captured live Knowledge results exercise successful memory calls across unrelated publications and denial after parent reset. The real SQLite owner, lineage resolver, and provider adapter additionally exercise the held-publication window, allowing metadata settlement while rejecting reset authority before provider invocation; the provider body only counts calls. No stored-data contract changes require migration proof.

Evidence

What I checked:

  • Pinned introduced patch: Reviewed the introduced production changes and all six changed test or test-support files between the supplied main and head identities. The verified test merge has those exact main/head parents; no base-only changes were attributed to this PR. (55398734fc9c)
  • Current-main defect remains: Main unconditionally marks a generation lease invalid on any topology publication, before considering its agent or source. Its memory provider boundaries also lack the new publication preparation. The related merged cron repair addresses lifecycle revision rotation rather than these triggers. (src/config/sessions/session-delivery-generation.ts:135, 5077ad4f99aa)
  • Final authority checks remain: The provider adapter prepares relevant publications, then synchronously checks caller, audience, cancellation, and provider lifetime immediately before invoking the provider. It repeats preparation and checks before returning results. Tool execution retains its invocation guard after the memory-owner-only wait. (src/plugins/memory-provider-adapter.ts:45, 55398734fc9c)
  • Allowed and revoked child boundary coverage: The new regression mints child authority through the real lineage walk and holds a real SQLite parent publication. Metadata settlement permits the bound provider call; a same-ID parent reset rejects it with zero provider invocations and leaves the audience stale. The provider body is a call-count stub, not a live backend; the contributor reports both cases fail against main and pass here. (src/config/sessions/session-accessor.sqlite-generation-readiness.test.ts:208, 55398734fc9c)
  • Captured live after-fix evidence: The supplied PR body records a real systemd Gateway using Knowledge: within one turn, status succeeds before and after committed group-catalog, same-session metadata, and sibling-session changes; a records read also succeeds. A parent reset subsequently denies its child’s Knowledge call. The captured comment fix(memory): Knowledge calls fail mid-turn after unrelated session activity #166419 (comment) explains the deterministic held-publication boundary coverage. This is contributor evidence, not a reviewer-executed run.
  • No migration boundary: Audience records remain WeakMap-held process state. The added registry witnesses and prepared-source list are lease-local; the patch changes no DDL, migration, serialized session fields, config defaults, or public plugin signatures. Existing group persistence operations are unchanged. This resolves the prior review’s migration-proof concern. (src/plugins/memory-audience.ts:45, 55398734fc9c)

Likely related people:

  • Josh Lehman: Raw commit a9f6758 adds src/plugins/memory-audience.ts:113 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a9f675839a0d; files: src/plugins/memory-audience.ts)
  • Peter Steinberger: 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-10-07T03:20:49.198Z sha 0b1c1c9 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-07T06:28:48.309Z sha 0b1c1c9 :: needs real behavior proof before merge. :: [P2] Scope the abort precheck to memory preparation
  • reviewed 2026-10-07T06:41:33.455Z sha 95447ca3ba1bbeb2d509579eefe3953923c52d57 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-07T07:29:14.418Z sha a57551b :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-07T07:45:29.045Z sha a57551b :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Oct 7, 2026
@jalehman
jalehman force-pushed the fix/memory-audience-readiness branch 2 times, most recently from 60da0ed to a57551b Compare October 7, 2026 07:14
@jalehman

jalehman commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

On the remaining proof item (parent reset during the publication wait, "before real memory I/O"):

  • The rejection is enforced in the host, upstream of every provider. bindMemoryProvider (memory-provider-adapter.ts) awaits prepareMemoryCallerRead and then runs the synchronous assertMemoryCallerCurrent before it calls any provider method, and again before it returns a result. Tool execution for the memory-slot owner goes through the same audience preparation in tool-factory-runtime.ts, and invoke() keeps the existing liveness and currency checks. A provider, mocked or real, is only reached after that check passes, so "no provider call" is the same as "no memory I/O" for every provider.
  • session-accessor.sqlite-generation-readiness.test.ts exercises that path with the real SQLite session owner, a real held publication, the real lineage walk for the child audience, and the real bindMemoryProvider adapter. Only the provider body is a stub, and it is used solely to count calls. With a parent reset held mid-publication, the child's read is pending, then rejected, and the provider is never invoked. With a parent metadata write instead, the read proceeds after the publication settles. Both cases fail on main production code.
  • Reproducing this window against a live Gateway is not deterministic: the gap between an admitted publication and its settlement is a few microseconds, and nothing outside the process can hold it open. The live fsn1 run in the body covers the observable outcomes on either side of it (reads succeed across unrelated publications; a parent reset denies the child's next Knowledge call).
  • No stored data changes: audience records are in-process only.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 7, 2026
jalehman and others added 3 commits October 7, 2026 02:19
Scope registry topology invalidation to witnessed candidate sources and keep catalog-only changes out of session authority invalidation. Join admitted session publications at memory host boundaries while retaining synchronous final guards and cancellation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Memory-slot readiness no longer throws an already-aborted signal before the
tool runs. Plugin tools still receive an aborted signal and own cancellation,
and a retired plugin runtime still reports that it is no longer active before
any abort reason. Only the memory-slot owner waits for audience publications.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Exercise the real SQLite session owner and memory provider adapter with a
delegated child audience while its parent's admitted publication is held. A
parent metadata write lets the read reach the provider after it settles; a
parent reset rejects the read before any provider I/O.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jalehman
jalehman force-pushed the fix/memory-audience-readiness branch from a57551b to 5539873 Compare October 7, 2026 09:20
@jalehman
jalehman merged commit 7492616 into main Oct 7, 2026
119 checks passed
@jalehman
jalehman deleted the fix/memory-audience-readiness branch October 7, 2026 09:32
@jalehman

jalehman commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 8, 2026
…tivity (openclaw#166419)

* fix(memory): preserve audience authority across unrelated publications

Scope registry topology invalidation to witnessed candidate sources and keep catalog-only changes out of session authority invalidation. Join admitted session publications at memory host boundaries while retaining synchronous final guards and cancellation.

* fix(plugins): keep plugin tool cancellation and liveness order

Memory-slot readiness no longer throws an already-aborted signal before the
tool runs. Plugin tools still receive an aborted signal and own cancellation,
and a retired plugin runtime still reports that it is no longer active before
any abort reason. Only the memory-slot owner waits for audience publications.

* test(memory): prove retained child audiences wait on parent publications

Exercise the real SQLite session owner and memory provider adapter with a
delegated child audience while its parent's admitted publication is held. A
parent metadata write lets the read reach the provider after it settles; a
parent reset rejects the read before any provider I/O.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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