Repository navigation
fix(sessions): Knowledge calls still fail mid-turn while the session's own bookkeeping publishes - #166758
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: needs maintainer review before merge. Reviewed October 7, 2026, 5:55 PM ET / 21:55 UTC (Revision 2). ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherThe 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]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +50, Tests +106, Docs +13. Total +169 across 11 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
…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]>
329d8a9 to
9cabc8f
Compare
|
Merged via squash.
|
…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.
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_UNAVAILABLEwhile 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
sessionIdandlifecycleRevisionas 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
sessionIdandlifecycleRevision(generationUnchangedKeys, beside the existingsharingUnchangedKeys). 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 intosession-accessor.sqlite-entry-cache-publication-state.tsto 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 unavailablefailures interleaved with successful Knowledge calls.session-accessor.sqlite-generation-readiness.test.tsreproduce it: a synchronousassertMemoryAudienceCurrentduring a held identity-preserving publication, for the session itself and for a child audience whose parent's write is in flight. All three fail onmainwith 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.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.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.tstimed 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