Skip to content

fix: thread partial-progress saves into non-Claude provider phases - #1097

Merged
iamtoruk merged 2 commits into
mainfrom
fix/provider-phase-partial-saves
Aug 22, 2026
Merged

iamtoruk merged 2 commits into
mainfrom
fix/provider-phase-partial-saves

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Summary

  • scanProjectDirs (Claude) has long taken a throttled saveProgress callback (src/parser.ts:1949) so a killed cold parse resumes from a warm cache. parseProviderSources (every other provider — codex, cursor, gemini, and the rest) did not accept it, and only persisted at the whole-provider boundary (a comment near the top of parseProviderSources acknowledged this).
  • On a large single-provider corpus — a multi-GB codex history is the common case — an app-timeout SIGKILL, crash, or force-quit during that phase discarded everything parsed since the last provider finished, so the entire phase restarted from zero on the next run. On slow machines this is a restart-loop amplifier for the field's timeout class.
  • parseProviderSources (src/parser.ts:3023) now accepts the same onFileParsed callback and invokes it once per source, right after that source's cache entry lands and markCacheDirty runs — placed outside the per-file try/catch (mirroring scanProjectDirs' exact placement) so a throttled caller only ever observes a fully-installed entry, never a mid-write one. Both call sites in parseAllSessions now thread the existing saveProgress closure through, on its existing file-count/wall-clock throttle — no new throttle, no new write mechanism.

Correctness / safety

  • Completeness proof: a source's fingerprint is written into section.files[source.path] only after its entire parse (for await (const call of parser.parse())) has finished and the resulting turns/calls are computed — never incrementally. A mid-file kill therefore can never leave a half-parsed file's fingerprint looking complete on resume; the file simply doesn't appear in the cache yet and gets fully re-parsed next run.
  • Two-writer safety: unchanged — partial saves go through the existing session-cache atomic publish path (nonce temp files, envelope rename last). This change only calls that existing path more often, on the same throttle.

Test

tests/provider-phase-partial-save.test.ts drives parseProviderSources directly against a 4-file Kiro fixture:

  1. An uninterrupted reference parse (4/4 calls).
  2. A simulated kill: the callback throws right after the 2nd file's cache entry lands (outside the per-file try/catch, so the throw escapes uncaught — same effect as a real interruption). A snapshot taken at that instant is used as "what actually reached disk."
  3. Resuming from that snapshot only re-parses the 2 remaining files (asserted via callback invocation count) and converges to the same totals as the reference.

Confirmed revert-proof: reverting src/parser.ts alone makes the test fail immediately (parseProviderSources is not a function, since it isn't exported pre-fix).

Real-corpus sanity (read-only source, scratch cache)

Froze a snapshot of a real ~2 GB Claude + ~4 GB codex corpus (1396 codex rollout files) to an isolated HOME/CLAUDE_CONFIG_DIR/CODEX_HOME for a byte-identical comparison:

  • Uninterrupted cold parse: reference totals captured.
  • Fresh cache, kill -9 ~1.5s into the codex phase: cache left with complete: false, 637/1396 codex files captured, no codex-results.v15.json flush marker (proof the kill was genuinely mid-loop, not post-completion).
  • Resume against that same cache dir: log shows exactly 759 pending codex files (1396 - 637), confirming only the unfinished remainder re-parses.
  • Final report payload (minus the generated timestamp) is byte-identical to the uninterrupted reference.

Verification

  • tsc --noEmit: clean
  • npm test: 222 files / 3023 tests passed, 5 skipped, exit 0
  • npm run verify:upgrade: PASSED (parity vs 0.9.20 baseline, serve --stdio, parse-worker determinism, warm-run idempotence, never-lose-across-partial-source-aging all green)

Closes nothing on its own; documents the telemetry/repro findings above.

scanProjectDirs (Claude) has long taken a throttled saveProgress
callback so a killed cold parse resumes from a warm cache;
parseProviderSources (every other provider) only persisted at the
whole-provider boundary. A run killed mid-way through a large single-
provider phase (a multi-GB codex corpus is the common case) discarded
everything parsed since the last provider finished, restarting that
whole phase from zero.

parseProviderSources now accepts the same onFileParsed callback,
invoked once per source right after that source's cache entry lands,
outside the per-file try/catch, mirroring scanProjectDirs' placement
and throttle. A file's fingerprint is only ever set after it fully
parses, so a mid-file kill can never leave a half-parsed file looking
complete on resume.

Verified against a real ~2GB Claude + ~4GB codex corpus (frozen
snapshot): kill -9 mid-codex-phase leaves a genuine partial cache
(no codex-results flush, complete: false), a resume only reparses the
unfinished remainder, and the final report is byte-identical to an
uninterrupted cold parse.
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