Repository navigation
fix(server): checkpoint repository scopes walk the project folder once per turn - #40671
juliusmarminge merged 3 commits into
Conversation
…e per turn CheckpointService.repositoryScopes asked WorkspaceFolders for the thread's folders and, in parallel, for its submodules. submodules read the same folders again through forThread, so every turn start and every checkpoint capture ran the full project folder scan twice. submodules now takes the folders the caller already has. Refs pingdotgg#40659 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…dupe-workspace-scan
…odule discovery Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
EvidenceSame Windows Server 2025 machine, separate checkouts and fresh databases. Generate the reported 604-entry fixture without t3.json, add it through the CLI, then run ten threads with two replay turns each. All 20 turns completed on each commit with both expected replies. Every capture processed both child repository scopes.
Recordings present timestamped CLI output at 12x, followed by the captured trace measurements. Across five consecutive four-turn blocks, retaining every sample:
Each reduction exceeds the combined ranges of the block medians. Capture scan time also fell from 372.4 to 227.5 ms across individual samples, exceeding either side's full scan-time range (53.9 and 49.1 ms). Base used two scans in all 40 repositoryScopes calls; head used one in all 40. Capture changed from two scans to one in all 20 samples. Turn start changed from three scans in all base samples to two in 18 head samples; two head samples also performed a separate ProjectService.syncFolders refresh and therefore had three total scans. Those refreshes remain in the timings. A supplementary run used one ordinary child repository and one declared initialized submodule. On both commits, checkpoint refs at ordinals 0, 1, and 2 preserved the exact synthetic README changes in both repositories. Driver script, measurement analysis, checkpoint-content verifier, and complete evidence with sanitized spans, samples, contents, and rendering scripts. Not shown:
|



Problem
Every message runs the project folder scan more often than it needs to (#40659). Part of that is a plain repeat inside one method:
CheckpointService.repositoryScopescallsWorkspaceFolders.forThread(input)andWorkspaceFolders.submodules(input)in parallel, andsubmodulescallsforThread(input)again with the same input. Both calls walk the whole project folder.repositoryScopesruns at turn start and again at checkpoint capture, so each turn pays for two walks it doesn't need. In a project with hundreds of top-level entries, each walk takes seconds (the issue measured about 2.3 s).Change
WorkspaceFolders.submodulestakes optionalfolders, which are the thread'sforThreadfolders. It reads them again only when the caller doesn't pass them.CheckpointService.repositoryScopesresolves the thread's folders once and passes them tosubmodules.repositoryScopesgets the same folders and submodules as before. Both lists now come from one read, so they always match.Scope
A bug fix for a real performance problem, reported in #40659. This PR fixes only the repeated walk inside
repositoryScopes. It does not cover:ignoreRepositories: ["."]point, which fix(server): folder discovery skips the walk when t3.json ignores the whole project #40664 (now merged) fixes. Without that setting the repeat below still happens on every project;RuntimePolicyV2.resolveandCheckpointServiceacross a turn. That needs a cache or a turn-level handoff, which is a design decision for maintainers.So this is
Refs #40659, notFixes.Verification
Focused test (
CheckpointService.test.ts, "walks the project folder once to find a thread's repositories and submodules"). It runs the realWorkspaceFolderslayer over a real temp folder that holds a child repository with a submodule, and counts directory reads of the project root.origin/main:AssertionError: expected 2 to equal 1End to end with the real server. I ran
scripts/dev-runner.ts dev:serverwith a temp T3 home and the freedevReplayprovider. The project was a temp repository with 600 top-level folders (each holding 4 subfolders), two child repositories and the issue'st3.json({"ignoreRepositories": ["."]}). I rant3 project add,t3 thread start ... --provider devReplay --model multi-turn --wait, thent3 thread send ... --wait. Then I countedWorkspaceFolders.scanspans inserver.trace.ndjsonby ancestor. Both turns completed with the expected replies on both builds.origin/main:This branch:
Scans drop from 3 to 2 per turn start, and from 2 to 1 per checkpoint capture.
Other checks
vp run typecheck(apps/server): passes.vp staged(fmt, lint, knip): passes.vp test runonCheckpointService.test.ts,CheckpointCaptureService.test.ts,RuntimePolicy.test.ts,WorkspaceFolders.test.tsandCheckpointRollbackService.taskFolder.test.ts. Those last two files have 10 cases that fail on this Windows machine withEPERM: operation not permitted, symlink, while creating their symlink fixtures and before any code under test runs. This includes the existingsubmodulescase withoutfolders, so CI's run of those cases is the check I could not do here. Everything else passes.Written by Claude Opus 5.5 in Claude Code via T3 Code.
🤖 Generated with Claude Code