Repository navigation
fix(mcp): a catch-up the WAL valve stops waits before it starts again - #3354
Merged
Merged
Conversation
colbymchenry
force-pushed
the
claude/issue-3273-valve-retry-backoff
branch
from
November 17, 2026 23:17
1bdbff5 to
666483f
Compare
The WAL valve (issue 1539) stops a sync whose write-ahead log can't be checkpointed past its cap while a reader pins frames, which is what the query pool's tool calls do during a big startup catch-up once the catch-up gate times out. The project's 1 s timer and every access then ran activate() again at once. Each retry scanned the project again, stored a file or so before its valve, which starts from a zero baseline, stopped it again, and grew the WAL a little more, for as long as the session kept calling tools. After a stop by the valve, the project now waits before the next attempt: 5 s, doubling with each stop in a row, up to 5 minutes. A catch-up that finishes clears the wait; tool calls meanwhile are served without waiting for one, as after the gate's timeout. Other failures keep their old retry on the next tick, and the log line says when the next attempt comes. Validation: - New project-lifecycle-valve-backoff tests (2): after a stop there is no attempt for 5 s, tool calls don't start one, the next stop waits 10 s, and a finished catch-up ends the attempts; any other failure still retries on the next tick. The first fails on main (3 attempts where 1 was expected, 4 s after the first stop) and passes with the fix. - Daemon simulation on Windows, 1.6.3's bundled Node: 400 edited files, CODEGRAPH_WAL_VALVE_MB=1, and a reader holding a snapshot open for 20 s from before the daemon started. Main: 7 stopped catch-ups about 2 s apart, WAL 5.7 MB at the release against a 4 MB cap. This branch: 2, 7.6 s apart, WAL 3.0 MB. Both stored all 400 files within 30 s of the release. Holding tool calls, or pausing the pool's reads, while a catch-up is near the valve's cap is left for a separate change: it trades the gate's 3 s serve-anyway promise for disk headroom. Fixes #3273 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
colbymchenry
force-pushed
the
claude/issue-3273-valve-retry-backoff
branch
from
November 18, 2026 00:06
666483f to
4faee25
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A catch-up sync that the WAL valve stops now waits before it starts again: 5 s, doubling with each stop in a row, up to 5 minutes. It used to restart on the next 1 s tick and on every tool call.
Root cause
The WAL valve (#1539/#1751) stops a sync whose write-ahead log can't be checkpointed past its cap while a reader pins frames. During a big startup catch-up those readers are the query pool's tool calls, served once the catch-up gate (#905) times out. When a catch-up failed,
ready()insrc/mcp/project-lifecycle.tsleftcaughtUpfalse. The project's 1 ssetIntervaland every access then ranactivate()→cg.sync()again at once.Each retry re-ran change detection over the project. It stored a file or so before its valve stopped it again: a new valve starts from a zero baseline, so its first backpressure check already counts the whole WAL. Each retry also grew the WAL a little more. Store-phase work is committed per file, so retries resume rather than restart, but they come every second.
Fix
When a catch-up fails with the valve's
WAL_VALVE_ABORT, the project records a retry time.ready()returns at once until then: tool calls are served without waiting, as after the gate's timeout, and the timer starts nothing. The wait doubles with each stop in a row and is cleared by a catch-up that finishes. Other failures keep their old retry on the next tick. The log line now ends with "Trying again in Ns."Validation
__tests__/project-lifecycle-valve-backoff.test.ts(2 tests, fake timers):CODEGRAPH_WAL_VALVE_MB=1, and a reader holding a snapshot open for 20 s from before the daemon started.Left out
Holding tool calls at the gate, or pausing the pool's reads, while a catch-up is near the valve's cap (the issue's option 2). It trades the gate's serve-within-3 s promise for disk headroom, so it needs its own change and decision. The issue's option 1, batched commits, already holds for the store phase, which commits per file.
Fixes #3273
Thanks @kiliman for the report and the analysis.
🤖 Generated with Claude Code