Skip to content

fix(memory): drain source writes before releasing failed syncs - #405

Open
Afloat16 wants to merge 1 commit into
simplexai-labs:mainfrom
Afloat16:afloat/chunk-sync-worker-drain
Open

Afloat16 wants to merge 1 commit into
simplexai-labs:mainfrom
Afloat16:afloat/chunk-sync-worker-drain

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Stop claiming new source work after the first failure, wait for in-flight source operations and then propagate the original failure. The per-Agent lock and serialized snapshot now outlive every source write.

A failed indexing snapshot cannot leave stale source writes running concurrently with its next snapshot.

How it was verified

Base: 77abdcb. Node 26.5.0, pnpm 11.7.0.

  • Before: A failed source causes the batch promise to reject and a queued snapshot to start before another source finishes writing; new regression fails on base.

  • After: All 14 tests pass across coordinator and chunk-index suites. Full node-services typecheck and lint pass; make check reached the 180-second execution bound during the broader test suite and is not established.

  • Command: pnpm --filter @linger/node-services exec vitest run tests/memory/chunk-sync-coordinator.test.ts tests/memory/chunk-index.test.ts --maxWorkers=1.

  • Repository-wide gates are not established; the current owning-package fast check is recorded below.

  • Focused tests for the changed behavior

  • make check BASE=<target-ref> or all affected fast checks

  • No contract regeneration required

Current owning-package gate

On exact head 631da2fc624b781076e0f33155e303e55b840423, pnpm --filter @linger/node-services check completed with exit 0 on Linux, Node 26.5.0 and pnpm 11.7.0. Feature-catalog verification, TypeScript checking and lint passed; Vitest finished with 268 files passed, 8 skipped; 2,713 tests passed, 51 skipped. The suite used its normal project configuration, including the real-process lane. Dependencies were installed in this isolated worktree with the frozen lockfile; no source, test, timeout or skip changes were made for the run.

This completes the fast check for the only affected app. Repository-wide and live-service/E2E gates are separate and are not claimed here.

Boundary

The owning behavior documentation is updated. No wire contract or dependency change. The patch is based independently on the stated base.

@Afloat16
Afloat16 marked this pull request as ready for review November 25, 2026 06:01

@linger-review linger-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve (0 findings)

Scope: base main, merge base 77abdcb3; 1 commit, 3 files reviewed (chunk-sync-coordinator.ts, its test, src/memory/README.md). Loaded coderbook. ponytail-review and karpathy-guidelines were not loaded; their checks were applied from the review checklist instead. Reviewed in a separate session.

Findings

None.

Verified as fine

  • Root cause fixed. On the base, Promise.all(workers) rejected as soon as one source failed. That let runAgent's .finally (chunk-sync-coordinator.ts:121-126) and the withDirectoryLock wrapper (chunk-index.ts:296-306) release the Agent while sibling workers were still writing, and those workers kept claiming more indices. The fix catches each source's failure inside its worker, stops new claims through !failed (chunk-sync-coordinator.ts:70), and rethrows only after every worker settles (:84-86). The lock now outlives every source write. The change stays in the coordinator, which owns this behavior; no caller changes.
  • Callers. The only mapSources operation that can reject per source is #syncRawSources (chunk-index.ts:276-291, invalid projection throws). The full reconciliation's agent loop (chunk-index.ts:484-511) and the per-source loop in #syncAgent (chunk-index.ts:571-600) catch inside the operation, so only the rejection of their own failure-recording SQL can reach the new path. syncMyPagesChunkSources also catches per document (my-pages-chunk-sources.ts:108-140).
  • Behavior trade-off, accepted. After a failure, #syncRawSources now skips the remaining unclaimed sources instead of indexing them unlocked in the background. Those sources are still picked up by the next coalesced Raw sync or by the hourly #syncAgent reconciliation, which isolates failures per source (chunk-index.ts:574-598). Indexing them is delayed, not lost.
  • Error identity. A failed flag, rather than failure !== undefined, keeps even an undefined rejection; the second test covers it. The first failure wins, matching the README text.
  • Tests. The new regression test fails on the merge base. I swapped in the base chunk-sync-coordinator.ts and got 1 failed, 3 passed, then restored it. It passes on the head. The test uses deferred promises plus one setImmediate tick for its negative assertion; there are no sleeps.
  • Docs. src/memory/README.md states the new failure semantics in the same PR.
  • PR body claims. "Fails on base" and "14 tests pass across coordinator and chunk-index suites" were both reproduced.
  • Conventions. No CJK in added lines or the commit message. No contract, env, or dependency changes. Conventional commit subject.

Process notes

None. Single commit, no merge or fixup commits.

CI

changes and repository-gate passed. check (web) was still in progress; every other check was skipped by the path plan. CI does not run node-services tests (.github/workflows/ci.yml:11-14), so I ran pnpm --filter @linger/node-services exec vitest run tests/memory/chunk-sync-coordinator.test.ts tests/memory/chunk-index.test.ts locally: 2 files, 14 tests passed. The regression test also fails against the base implementation, as described above.

Automated review by Claude Code


Automated review of 631da2f by Claude Code.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant