Skip to content

fix(mcp): a catch-up the WAL valve stops waits before it starts again - #3354

Merged
colbymchenry merged 1 commit into
mainfrom
claude/issue-3273-valve-retry-backoff
Nov 18, 2026
Merged

colbymchenry merged 1 commit into
mainfrom
claude/issue-3273-valve-retry-backoff

Conversation

@colbymchenry

Copy link
Copy Markdown
Owner

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() in src/mcp/project-lifecycle.ts left caughtUp false. The project's 1 s setInterval and every access then ran activate() → 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

  • New __tests__/project-lifecycle-valve-backoff.test.ts (2 tests, fake timers):
    • after a stop there is no attempt for 5 s, and 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.
  • Red→green: the first test fails on main (3 attempts instead of 1, 4 s after the first stop).
  • 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; the WAL reached 5.7 MB against a 4 MB cap.
    • this branch: 2 stopped catch-ups, 7.6 s apart; the WAL stayed at 3.0 MB.
    • Both arms stored all 400 files within 30 s of the release.
  • Daemon/MCP test files (52) on this commit: 49 passed, 3 skipped files; 468 tests passed, 0 failed.

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

@colbymchenry
colbymchenry force-pushed the claude/issue-3273-valve-retry-backoff branch from 1bdbff5 to 666483f Compare November 17, 2026 23:17
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>
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.

Catch-up reconcile aborts with WalValveAbortError while the query pool serves reads, then restarts from scratch

1 participant