t3code icon indicating copy to clipboard operation
t3code copied to clipboard

Rewind spends ~40 s deleting checkpoint refs in every repository of a multi-repo project, mostly in `git submodule foreach`

Open hardikg2907 opened this issue 2 days ago • 1 comments

What happened

Rewinding a thread ("Edit from here" / revert) always takes about 20 s or more. The thread is in a project whose folder holds many git repositories.

Diagnosis

Almost all of the time is spent in CheckpointService.discardRepositorySnapshots, after the provider rollback has finished.

  • discardRepositorySnapshots (apps/server/src/orchestration-v2/CheckpointService.ts) runs deleteCheckpointRefs for every repository scope that repositoryScopes discovers in the project folder, 6 at a time (REPOSITORY_SCOPE_CONCURRENCY). In this project that is 102 repositories. The thread has checkpoints in only 25 of them.
  • For each repository, GitVcsDriver.checkpoints.deleteCheckpointRefs (apps/server/src/vcs/GitVcsDriver.ts) runs, in series: a probeWorkTree git call during VCS detection, one git update-ref -d per rolled-back ordinal, and then listSubmodules, which runs git submodule foreach --quiet 'printf "%s\0" "$displaypath"'.
  • git submodule foreach is the expensive part. It took 185 s of the 250 s total git process time in this rewind. None of the 102 repositories has a .gitmodules file, so all of that work finds nothing.
  • On its own, git submodule foreach takes about 0.4–0.5 s per repository on this machine (macOS, git 2.56.0). Inside the rewind it took about 1.9 s per repository, with 6 running in parallel and a system load average of 6–7.

The code is unchanged on main (11 commits ahead of this build).

Possible fixes:

  1. Delete refs only in the repository scopes where the thread actually has checkpoints (the projection already records scope_id per checkpoint).
  2. Skip listSubmodules when the repository has no .gitmodules file.
  3. Delete all refs for a repository in one git update-ref --stdin call instead of one process per ref.

Steps to reproduce

  1. Create a project whose folder (not itself a git repository) holds many git repositories (about 100, up to 3 levels deep), none with submodules.
  2. In a thread in that project, run two or more turns with a Claude agent.
  3. Rewind the thread to an earlier message.
  4. Rewind takes tens of seconds. In server.trace.ndjson, CheckpointService.discardRepositorySnapshots accounts for almost all of the orchestrationV2.checkpointRollback.execute span, with one deleteCheckpointRefs child per discovered repository.

Version

T3 Code Desktop 0.1.14-nightly.20261130.5465 (commit 4d01919e679c), local server, same version. Earlier builds: unknown.

Environment

  • macOS (darwin arm64, 27.2.0)
  • Node v24.22.1
  • git 2.56.0 (Homebrew)
  • Provider: Claude
  • Client surface: desktop app against the local server

Evidence

Span summary from server.trace.ndjson for one rewind:

orchestrationV2.checkpointRollback.execute        44337 ms
  ClaudeAdapterV2.rollbackThread                   1174 ms
  CheckpointService.discardRepositorySnapshots    43099 ms
    deleteCheckpointRefs                    x102, each 1.3–3.9 s, 6 concurrent

Cumulative span time in this trace:
  VcsProcess.spawn                      391 spawns   249774 ms
  GitVcsDriver.listSubmodules           102 calls    185503 ms
  GitVcsDriver.probeWorkTree (detect)    85 calls     15716 ms

One deleteCheckpointRefs span:

2348 ms deleteCheckpointRefs
   107 ms  CheckpointStore.resolveCheckpoints -> GitVcsDriver.probeWorkTree
  2240 ms  GitVcsDriver.checkpoints.deleteCheckpointRefs
     152 ms  git update-ref -d (ordinal 1)
     169 ms  git update-ref -d (ordinal 2)
    1920 ms  GitVcsDriver.listSubmodules (git submodule foreach)

Standalone timing in one of the repositories (no .gitmodules):

git update-ref -d <missing ref>        0.03 s
git submodule foreach --quiet ...      0.36–0.55 s

The retained traces cover about 4 hours and contain one rewind. The user reports that every rewind is slow (about 20 s).

Related issues

  • #39714 "Submodule checkpoints block follow-up messages and new threads on Windows": same listSubmodules cost, but in the checkpoint capture path on Windows, with real submodules. This report is about the rewind clean-up path on macOS, in repositories with no submodules, multiplied by the number of repositories in the project.
  • #40659 "Every message runs the workspace folder scan 3 times in a row": same multi-repo project shape, different cost.

Fix applied or workaround

None applied. A possible workaround is ignoreRepositories in the project's t3.json, but rewind then no longer restores files in the ignored repositories.

Filed by

Claude Code (Claude Opus 5.5, claude-opus-5-5), via the T3 Code triage playbook.

hardikg2907 avatar Nov 30 '26 04:11 hardikg2907

I independently reproduced the Git subprocess cost on Windows with Git 2.51.0.windows.2. I ran the exact submodule foreach --quiet command used by listSubmodules over 24 empty repositories, with six concurrent workers and three runs. It took 8.51–8.90 s of wall time. An index-only git ls-files --stage -z probe on the same repositories took 0.51–0.73 s. Both returned no entries. These are subprocess timings from the same machine while other builds were running, rather than end-to-end rewind timings.

I also checked an initialized submodule as a control. submodule foreach still reported sub after deleting .gitmodules from the working tree, and again after removing .gitmodules from the index while it remained in HEAD. The index still contained the 160000 gitlink. That makes a working-tree .gitmodules existence check unsafe as a skip condition. A scoped index check for gitlinks could preserve foreach for repositories that have submodules or where the probe fails.

STiFLeR7 avatar Nov 30 '26 05:11 STiFLeR7