Skip to content

fix(memory-wiki): prevent partial failures during concurrent agent writes - #103408

Merged
steipete merged 2 commits into
mainfrom
codex/memory-wiki-vault-transactions
Jul 11, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/memory-wiki-vault-transactions

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #103400

Related: #91828, #94443, #98787, #103349

What Problem This Solves

Fixes an issue where simultaneous agent turns writing one Memory Wiki vault could report wiki_apply failure after the primary page had already been committed. Under a local 8+8 support/marketing email burst, six of 16 tool calls failed during compile even though all 16 synthesis pages existed afterward.

Why This Change Was Made

The complete wiki_apply mutation-plus-compile sequence now runs through a reentrant queue keyed by the resolved vault path. Writes to one agent vault are serialized, while different agent vaults remain parallel; standalone compiles use the same coordinator. Bridge/source-sync coalescing and cross-process CLI/Gateway coordination remain separate work.

User Impact

Bursty email ingestion and other concurrent agent turns can update the same Memory Wiki vault without partial-success tool errors or lost disjoint metadata. Support and marketing agents with separate vaults still write concurrently and remain isolated.

AI-assisted: yes. The implementation was source-reviewed, behavior-tested through a real local Gateway/tool loop, and passed the repository's structured autoreview.

Evidence

Before-fix local product path:

  • Isolated loopback Gateway, deterministic local Responses model, real Gmail hook routing, real agent sessions, and real wiki_apply calls.
  • Eight support plus eight marketing emails submitted concurrently.
  • 16 synthesis pages committed, but 6 wiki_apply calls failed during compile (path changed during read / unable to resolve opened file path).

After-fix replay of the same workload:

  • 16/16 tool calls completed.
  • 16/16 synthesis pages present.
  • Support and marketing compiled digests each contained all eight new pages.
  • Zero cross-vault markers and zero wiki_apply failures.

Focused local proof:

node scripts/run-vitest.mjs \
  extensions/memory-wiki/src/mutation-coordinator.test.ts \
  extensions/memory-wiki/src/apply.test.ts \
  extensions/memory-wiki/src/compile.test.ts

Test Files  3 passed (3)
Tests       32 passed (32)

Blacksmith Testbox through Crabbox (tbx_01kx56fg3xhjypxg7k9megebb2):

corepack pnpm test:extension memory-wiki
Test Files  36 passed (36)
Tests       290 passed (290)

corepack pnpm check:changed
passed: extension typecheck, extension test typecheck, lint, database-first guard,
runtime sidecar guard, and runtime import-cycle check

Autoreview:

autoreview clean: no accepted/actionable findings reported
overall: patch is correct (0.88)

@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. P1 High-priority user-facing bug, regression, or broken workflow. labels Jul 10, 2026
@clawsweeper

clawsweeper Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed July 10, 2026, 6:44 AM ET / 10:44 UTC.

Summary
The PR adds a reentrant process-local queue per resolved Memory Wiki vault and serializes complete wiki_apply mutation-plus-compile operations while allowing distinct vaults to run concurrently.

PR surface: Source +56, Tests +153, Docs +1. Total +210 across 6 files.

Reproducibility: yes. at high confidence from source and supplied live proof: current main performs a page mutation followed by an uncoordinated whole-vault compile, and the real sixteen-call Gateway workload observed six compile-stage failures.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: extensions/memory-wiki/src/apply.test.ts, unknown-data-model-change: extensions/memory-wiki/src/mutation-coordinator.test.ts, vector/embedding metadata: CHANGELOG.md, vector/embedding metadata: extensions/memory-wiki/src/apply.test.ts, vector/embedding metadata: extensions/memory-wiki/src/apply.ts, vector/embedding metadata: extensions/memory-wiki/src/compile.ts, and 2 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #103400
Summary: This PR is the direct candidate fix for the linked concurrent wiki_apply issue; the referenced Memory Wiki pull requests address adjacent filesystem and bridge races.

Members:

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

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Remove the CHANGELOG.md edit and refresh the draft branch against current main.

Risk before merge

  • [P1] The coordinator is intentionally process-local, so simultaneous writes from separate CLI and Gateway processes remain outside this fix.
  • [P1] Other Memory Wiki mutation flows remain separate transaction owners and may require later coordination if an equivalent same-vault race is demonstrated.
  • [P1] The draft branch currently conflicts with current main because it edits the release-owned changelog.

Maintainer options:

  1. Decide the mitigation before merge
    Keep the focused same-process wiki_apply transaction, remove the release-owned changelog edit, refresh the branch cleanly, and treat broader cross-process or sibling mutation coordination as separately reproduced work.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P2] The protected maintainer-labeled draft needs normal maintainer branch handling; ClawSweeper should not create a separate repair job for the one-line release-file cleanup.

Security
Cleared: The patch changes only in-process scheduling and tests, without altering filesystem guard policy, dependencies, permissions, secrets, artifact downloads, or code-execution sources.

Review findings

  • [P3] Remove the release-owned changelog entry — CHANGELOG.md:28
Review details

Best possible solution:

Keep the focused same-process wiki_apply transaction, remove the release-owned changelog edit, refresh the branch cleanly, and treat broader cross-process or sibling mutation coordination as separately reproduced work.

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

Yes at high confidence from source and supplied live proof: current main performs a page mutation followed by an uncoordinated whole-vault compile, and the real sixteen-call Gateway workload observed six compile-stage failures.

Is this the best way to solve the issue?

Yes for the demonstrated same-process wiki_apply bug: a reentrant per-vault transaction is narrower and more reliable than retrying individual compile failures, while broader coordination remains explicitly separate.

Full review comments:

  • [P3] Remove the release-owned changelog entry — CHANGELOG.md:28
    CHANGELOG.md is maintained by the release workflow, so this PR-specific entry creates the current merge conflict and bypasses release-note ownership. Keep the user-impact wording in the PR body or commit context and remove this line from the branch.
    Confidence: 0.99

Overall correctness: patch is correct
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P1: The PR addresses a reproduced agent workflow where concurrent tool calls report failure after partially committing Memory Wiki state.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix output from a real local Gateway, Gmail-hook, session, and wiki_apply workload, with focused tests and Testbox validation; private values appear appropriately omitted.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides after-fix output from a real local Gateway, Gmail-hook, session, and wiki_apply workload, with focused tests and Testbox validation; private values appear appropriately omitted.

Label justifications:

  • P1: The PR addresses a reproduced agent workflow where concurrent tool calls report failure after partially committing Memory Wiki state.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster 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 PR body provides after-fix output from a real local Gateway, Gmail-hook, session, and wiki_apply workload, with focused tests and Testbox validation; private values appear appropriately omitted.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix output from a real local Gateway, Gmail-hook, session, and wiki_apply workload, with focused tests and Testbox validation; private values appear appropriately omitted.
Evidence reviewed

PR surface:

Source +56, Tests +153, Docs +1. Total +210 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 58 2 +56
Tests 2 153 0 +153
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 212 2 +210

What I checked:

  • Current-main failure boundary: Current main writes the requested page and then compiles the shared vault without a transaction covering both phases, allowing concurrent same-vault calls to interleave after partial commit. (extensions/memory-wiki/src/apply.ts:362, 29d018f0af5e)
  • Focused transaction implementation: The PR wraps the entire apply operation in a per-vault coordinator, while the compile wrapper re-enters the active transaction instead of deadlocking. (extensions/memory-wiki/src/mutation-coordinator.ts:15, f66649fb781b)
  • Coordinator regression coverage: The added tests cover same-vault serialization, distinct-vault parallelism, nested reentry, and detached work that resumes after its inherited transaction has ended. (extensions/memory-wiki/src/mutation-coordinator.test.ts:12, f66649fb781b)
  • Real behavior proof: The PR reports a real local Gateway and Gmail-hook workload with six of sixteen compile-stage failures before the patch and sixteen of sixteen successful isolated writes and digests afterward; the GitHub proof check passed. (f66649fb781b)
  • Current-main necessity: Since the PR base, current main has no changes in apply.ts, compile.ts, or apply.test.ts, so the central concurrency fix has not been independently implemented. (extensions/memory-wiki/src/apply.ts:362, 29d018f0af5e)
  • Branch conflict source: The three-way merge preview shows the branch conflict is the PR-authored CHANGELOG.md entry; the Memory Wiki source and tests merge cleanly against current main. (CHANGELOG.md:28, f66649fb781b)

Likely related people:

  • vincentkoc: Introduced the wiki_apply mutation tool and original ingest/compile pipeline that defines the transaction now being coordinated. (role: introduced behavior; confidence: high; commits: d624ec3a0bab, 516a43f9f28c; files: extensions/memory-wiki/src/apply.ts, extensions/memory-wiki/src/compile.ts)
  • steipete: Recently carried the Memory Wiki agent-vault isolation and current integration work that made the concurrent same-vault workload concrete. (role: recent area contributor; confidence: high; commits: 98b8c8c4ae29, 4a4a32a5de15; files: extensions/memory-wiki/src/apply.ts, extensions/memory-wiki/src/compile.ts, extensions/memory-wiki/src/config.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@steipete
steipete force-pushed the codex/memory-wiki-vault-transactions branch from f66649f to 8247ebf Compare July 11, 2026 01:12
@steipete
steipete marked this pull request as ready for review July 11, 2026 01:13
@steipete
steipete merged commit d6f07f3 into main Jul 11, 2026
90 checks passed
@steipete
steipete deleted the codex/memory-wiki-vault-transactions branch July 11, 2026 01:22
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: memory-wiki maintainer Maintainer-authored PR 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.

Memory Wiki wiki_apply partially succeeds under concurrent agent writes

1 participant