Skip to content

fix(sessions): Knowledge calls still fail mid-turn while the session's own bookkeeping publishes - #166758

Merged
jalehman merged 1 commit into
mainfrom
fix/generation-reads-identity-preserving
Oct 7, 2026
Merged

jalehman merged 1 commit into
mainfrom
fix/generation-reads-identity-preserving

Conversation

@jalehman

@jalehman jalehman commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: memory-slot tools (for example Knowledge) still fail intermittently mid-turn with memory audience currency is unavailable; retry the operation / SESSION_DELIVERY_GENERATION_UNAVAILABLE while the session's own turn bookkeeping is being written.

User Impact

User impact: long agent turns that read or write memory no longer hit sporadic currency failures caused by their own activity, usage, or cache-state writes. A real reset, replacement, or deletion of the session still makes memory access unavailable while it publishes and then revokes it.

Why This Change Was Made

Session writes commit on a SQLite worker and are installed on the Gateway main thread afterwards. While any publication on a session row was pending, synchronous generation reads treated the session's sessionId and lifecycleRevision as unknown, even for metadata writes that cannot change them. #166419 made memory hosts join pending publications before provider calls and tool execution, but memory plugins also check currency synchronously between their own awaits (Knowledge re-resolves its principal after each internal await), and a long turn writes its own row constantly, so those checks kept failing.

The worker that commits a publication now proves, from the committed previous and current rows, which sessions keep both sessionId and lifecycleRevision (generationUnchangedKeys, beside the existing sharingUnchangedKeys). Synchronous generation reads ignore pending publications that carry that proof. Prepared reads (prepareRead) still join every pending publication, so owners that order effects after a session's in-flight write, such as subagent cancellation and provider readiness, are unchanged. Created, deleted, archived, and membership-invalidated rows carry no proof, and publication paths that do not supply it keep the existing fence. The prepared-change record registry and its read helpers move into session-accessor.sqlite-entry-cache-publication-state.ts to keep the publication owner within its line cap; the publication module re-exports them, so importers are unchanged.

Evidence

Live failure on a Gateway running #166419 and #166417: one 54-minute Knowledge ingestion turn hit nine transient currency is unavailable failures interleaved with successful Knowledge calls.

  • New real-SQLite cases in session-accessor.sqlite-generation-readiness.test.ts reproduce it: a synchronous assertMemoryAudienceCurrent during a held identity-preserving publication, for the session itself and for a child audience whose parent's write is in flight. All three fail on main with the exact production error and pass here. A held reset still fails the synchronous check and then revokes; prepared reads still wait for both kinds.
  • Existing tests that encoded the old behavior were updated only where the held write keeps the incarnation (session-accessor.sqlite-replacement-publication.test.ts, the metadata cases of the readiness test); reset, replacement, and late-writer cases keep their assertions. Subagent cancellation ordering tests (subagent-control.metadata-publication, subagent-control.warm-preparation) pass unchanged.
  • Suites: src/config/sessions, src/infra/outbound, src/agents/subagents/registry, src/cron/isolated-agent, memory audience/provider/tool tests all pass. src/acp/runtime/session-meta.legacy-migration.test.ts timed out under a concurrent heavy test run on the same host and passes 14/14 run alone (90 s).
  • session-accessor.sqlite-generation-readiness.test.ts --maxWorkers=1: about 29 s wall on a loaded laptop.

🤖 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 docs Improvements or additions to documentation size: M labels Oct 7, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 5:55 PM ET / 21:55 UTC (Revision 2).

ClawSweeper review

What this changes

The PR keeps memory and session-generation checks available while bookkeeping writes preserve the session’s identity, while retaining reset fencing and prepared-read ordering.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix: current main still fences synchronous generation checks during identity-preserving publications. No introduced correctness defect was found, and the real SQLite worker-boundary evidence supports the internal-reliability proof exception.

Priority: P1
Reviewed head: 9cabc8f29e7cf7d6dbf7767c991e8d67901fc85a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful production-boundary coverage and no blocking finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The reported after-fix SQLite harness exercises the actual session publication owner and real worker client with held result delivery: synchronous metadata checks succeed, prepared reads wait, and reset controls reject then revoke. This satisfies scoped internal-reliability proof; mocked provider health is supplemental and does not demonstrate a live Knowledge service. No persisted data-model contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The reported after-fix SQLite harness exercises the actual session publication owner and real worker client with held result delivery: synchronous metadata checks succeed, prepared reads wait, and reset controls reject then revoke. This satisfies scoped internal-reliability proof; mocked provider health is supplemental and does not demonstrate a live Knowledge service. No persisted data-model contract changes.
Evidence reviewed 11 items Pinned introduction and repository identity: The origin identifies openclaw/openclaw. The reviewed introduction is 3856df4..9cabc8f; endpoint drift was not attributed to this PR. Final git status remained clean.
Current main still needs the fix: Fetched main still implements readGeneration using pending(false), which fences every unsuperseded pending entry publication. The merged memory-readiness repair addresses preparation, but does not remove this synchronous between-await failure.
Worker-owned identity proof: The receipt producer compares the previous row with the final persisted row and excludes archived and membership-invalidated keys. Created or removed rows cannot acquire generationUnchangedKeys. All three modified publication consumers carry the worker receipt into the existing publication owner.
Findings None None.
Security None None.

How this fits together

The session storage owner publishes SQLite worker writes into retained Gateway facts. Memory audiences and message-delivery guards consume those facts to check that their session incarnation remains current.

flowchart TD
  A[Session bookkeeping or reset] --> B[SQLite worker]
  B --> C[Compare previous and committed identity]
  C --> D[Publication owner]
  D --> E[Synchronous generation check]
  D --> F[Prepared read waits for settlement]
  E --> G[Continue or reject memory access]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +50, Tests +106, Docs +13. Total +169 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 7 106 56 +50
Tests 2 121 15 +106
Docs 2 16 3 +13
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 243 74 +169

Review metrics

Metric Value Why it matters
Production versus regression coverage production net +50 LOC; tests net +106 LOC Production growth carries the worker-proved identity invariant through existing publication owners; regression coverage exercises held writes and reset controls.

Technical review

Best possible solution:

Keep generation availability decisions in the session publication owner, using worker-proved incarnation preservation while retaining reset revocation and effect-ordering waits.

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

Yes, from source: hold delivery of an identity-preserving session worker write and call the retained audience’s synchronous currency check. Current main fences that path; the contributor reports matching before/after regression results, which this review did not execute.

Is this the best way to solve the issue?

Yes. Worker-proved identity preservation is the narrow repair, and the inspected implementation leaves prepared-read ordering, sharing checks, session binding, and reset revocation intact.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The reported after-fix SQLite harness exercises the actual session publication owner and real worker client with held result delivery: synchronous metadata checks succeed, prepared reads wait, and reset controls reject then revoke. This satisfies scoped internal-reliability proof; mocked provider health is supplemental and does not demonstrate a live Knowledge service. No persisted data-model contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • remove rating: 🦞 diamond lobster: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P1: The reported failure interrupts memory-tool workflows during real long-running agent turns despite the earlier readiness repair.
  • 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): The reported after-fix SQLite harness exercises the actual session publication owner and real worker client with held result delivery: synchronous metadata checks succeed, prepared reads wait, and reset controls reject then revoke. This satisfies scoped internal-reliability proof; mocked provider health is supplemental and does not demonstrate a live Knowledge service. No persisted data-model contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The reported after-fix SQLite harness exercises the actual session publication owner and real worker client with held result delivery: synchronous metadata checks succeed, prepared reads wait, and reset controls reject then revoke. This satisfies scoped internal-reliability proof; mocked provider health is supplemental and does not demonstrate a live Knowledge service. No persisted data-model contract changes.

Evidence

What I checked:

  • Pinned introduction and repository identity: The origin identifies openclaw/openclaw. The reviewed introduction is 3856df4..9cabc8f; endpoint drift was not attributed to this PR. Final git status remained clean. (9cabc8f29e7c)
  • Current main still needs the fix: Fetched main still implements readGeneration using pending(false), which fences every unsuperseded pending entry publication. The merged memory-readiness repair addresses preparation, but does not remove this synchronous between-await failure. (src/config/sessions/session-accessor.sqlite-entry-cache-publication-state.ts:236, 2c9c6c868855)
  • Worker-owned identity proof: The receipt producer compares the previous row with the final persisted row and excludes archived and membership-invalidated keys. Created or removed rows cannot acquire generationUnchangedKeys. All three modified publication consumers carry the worker receipt into the existing publication owner. (src/config/sessions/session-accessor.sqlite-replacement-state.ts:103, 9cabc8f29e7c)
  • Ordering and revocation remain intact: Only synchronous generation reads consume the new proof. prepareRead still joins every unsuperseded pending publication; sharing and membership reads retain their fences. Generation settlement still permanently revokes changed incarnations, and memory callers retain invocation-session binding and final currency checks. (src/config/sessions/session-accessor.sqlite-entry-cache-publication-state.ts:223, 9cabc8f29e7c)
  • Production-boundary fault injection: The harness delegates acquisition, execution, SQL, admission, and settlement to the actual production executor and worker client. It holds delivery only after scope.execute returns. The body reports before/after failures and passes for synchronous audience checks, including parent lineage; inspected assertions verify metadata availability, pending prepared reads, and reset rejection followed by permanent revocation. Provider health is mocked, so this establishes the internal session-publication contract rather than a live Knowledge-service run. (src/config/sessions/session-accessor.sqlite-replacement-publication.test-support.ts:21, 9cabc8f29e7c)
  • After-fix checks and negative controls: The direct synchronous case holds a real worker publication, checks audience currency during the hold, releases delivery, and checks again. Its reset control reports unavailable while held and no longer current after settlement. The delegated-child case additionally verifies that reset prevents provider invocation. Contributor-reported validation was inspected but not independently executed during this read-only review. (src/config/sessions/session-accessor.sqlite-generation-readiness.test.ts:350, 9cabc8f29e7c)

Likely related people:

  • jalehman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • 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 (1 earlier review cycle)
  • reviewed 2026-10-07T21:47:26.238Z sha 329d8a9 :: needs changes before merge. :: none

…ntity-preserving publications

While any publication on a session row was pending, synchronous generation reads
(delivery, subagent control, cron roots, memory audiences) treated the session's
sessionId and lifecycleRevision as unknown and failed closed, even for metadata
writes that cannot change them. Long agent turns write their own row
constantly, so a memory plugin's synchronous currency check between its own
awaits intermittently failed with "memory audience currency is unavailable".

Committed publications now carry generationUnchangedKeys, proved from the
committed previous and current rows; synchronous generation reads ignore pending
publications that prove the session's incarnation unchanged. Prepared reads
still join every pending publication, so owners that order effects after a
session's in-flight write (subagent cancellation, provider readiness) are
unchanged. Created, deleted, archived, and membership-invalidated rows carry no
proof, and publication paths that do not supply it keep the existing fence. The
prepared-change record registry and its readers move beside the other
publication state to keep the publication owner within its line cap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@jalehman
jalehman force-pushed the fix/generation-reads-identity-preserving branch from 329d8a9 to 9cabc8f Compare October 7, 2026 21:49
@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: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Oct 7, 2026
@jalehman
jalehman merged commit 3f59128 into main Oct 7, 2026
127 checks passed
@jalehman
jalehman deleted the fix/generation-reads-identity-preserving branch October 7, 2026 22:10
@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
…ntity-preserving publications (openclaw#166758)

While any publication on a session row was pending, synchronous generation reads
(delivery, subagent control, cron roots, memory audiences) treated the session's
sessionId and lifecycleRevision as unknown and failed closed, even for metadata
writes that cannot change them. Long agent turns write their own row
constantly, so a memory plugin's synchronous currency check between its own
awaits intermittently failed with "memory audience currency is unavailable".

Committed publications now carry generationUnchangedKeys, proved from the
committed previous and current rows; synchronous generation reads ignore pending
publications that prove the session's incarnation unchanged. Prepared reads
still join every pending publication, so owners that order effects after a
session's in-flight write (subagent cancellation, provider readiness) are
unchanged. Created, deleted, archived, and membership-invalidated rows carry no
proof, and publication paths that do not supply it keep the existing fence. The
prepared-change record registry and its readers move beside the other
publication state to keep the publication owner within its line cap.
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 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: M 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