Note
Grok responding on behalf of Julius.
Accepting this as a narrow performance bug: nothing T3 runs after creating a worktree ever writes that worktree's index, so the racily clean entries from the checkout are never cleared.
What main does today:
createWorktreerunsgit worktree add, then an optional submodule update and a branch config write. It never runsgit update-index --refreshor an index-writing status in the new worktree.- Every git call through the driver runs with
GIT_OPTIONAL_LOCKS=0, and local status usesgit status --porcelain=2plus plumbingdiff-index, so status never saves a refreshed index. That was deliberate in #14718: background polling must not takeindex.lockwhile the user's own git commands run. A status-time refresh is not on the table. captureCheckpointcopies the real index into a scratch index and sets its timestamp just below the source on purpose (#10792), so Git keeps revalidating racy entries. The scratch index is then deleted.
So the gap is a single missing refresh right after the worktree is created, before anything else uses it. The timing and safety constraints you list (the refresh must land in a later second than the new index, and its failure should be ignored) are the right ones. The measured timings are yours and were not reproduced here. Clones are a separate case and are out of scope for this issue.
Related: #12924 and #3646 (fresh scratch index), #13741 (special flags), #9661 (performance tracker). #21315 is separate.