# fix\(server\): reuse Git index metadata during checkpoint capture · PR \#10792 · pingdotgg/t3code

[View on GitCafe](https://git.cafe/pingdotgg/t3code/pull/10792)

Repository: [pingdotgg/t3code](https://git.cafe/pingdotgg/t3code)

Visibility: public

State: merged

Source repository: Unavailable fork

Source branch: fix/checkpoint-index-metadata

Target branch: main

Head commit: bbce314b2b6753c751e1c31412c227ee04f0714f

[Discussion and reviews](https://git.cafe/pingdotgg/t3code/pull/10792)

[Commits](https://git.cafe/pingdotgg/t3code/pull/10792/commits?format=markdown)

[Files changed](https://git.cafe/pingdotgg/t3code/pull/10792/diffs?format=markdown)

## Description

---

## What Changed

Checkpoint capture now seeds its private index from the workspace index and resets it to HEAD while retaining matching file metadata. The existing `git add -A -- .` then avoids rereading unchanged tracked files. The workspace index stays untouched.

Restore a conservative source-index timestamp after the reset, preserving Git's revalidation of racy entries even when `read-tree` rewrites the private index. Discard filesystem-monitor state during the reset. Fall back to the existing fresh-index path if copying or inspection fails, inspection is truncated, or assume-unchanged/skip-worktree flags remain.

## Why

Starting with a fresh index throws away Git's stat cache on every capture. Reusing it reduces unnecessary work in large repositories while preserving scoped staging and snapshot contents.

Related to #3646; independent of the failed-write cleanup in #9809. Builds on the index-reuse approach explored in #8538, with a fresh-index fallback instead of normalizing special flags. Unlike #8301, this keeps native `add -A` staging rather than parsing changed paths. Discussion: https://github.com/pingdotgg/t3code/discussions/9808#discussioncomment-18351271.

## Validation

- 42 tests pass across GitVcsDriver, CheckpointStore, and VcsProcess; server typecheck, targeted lint, and formatting pass.
- The unchanged-file clean-filter regression fails on main and passes here. Tests cover two consecutive captures at root/nested directories, staged/unstaged/deleted/untracked files, special flags, split indexes, missing/corrupt indexes, same-size timestamp-preserving edits with `core.trustctime=false` (including fractional-second rounding and an edit after `read-tree` resets a two-file index), and an unchanged workspace index.
- Five paired complete captures on a 40,000-file fixture (10 modified, one untracked): median **244.1 ms → 71.6 ms (about 3.4× faster)**. Every paired snapshot tree matched and the workspace index remained byte-identical. Baseline: unoptimized driver at `4d06156dd`. Rerun after correcting the timestamp restoration order.

The 30-second timeout is unchanged. Large new or modified files still need hashing; this does not claim to resolve every timeout in #3646.

## Checklist

- [x] This PR is small and focused
- [x] I explained what changed and why

Implemented and verified with GPT-6 Astra through the Codex harness.


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **Bug Fixes**
  - Checkpoint capture now reliably detects same-size file edits, including edits with ambiguous timestamps.
  - Git index state is preserved more accurately during checkpoint capture, including staged changes, file metadata, and timestamps.
  - Improved handling of specially tracked files while retaining fallback behavior for invalid or unsupported index states.
  - Checkpoints continue to preserve deleted, newly added, and otherwise tracked file state.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
