Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(projects): turn changes and diffs cover tracked repositories #35923

Closedjuliusmarmingewants to merge 1 commit intot3/multi-repo-1-tracked-repos fromrefs/pull/35923/headopened View on GitHub

juliusmarmingecommented

Layer 2 of 4 of the multi-repository rebuild (discussion #7041). Stacked on layer 1.

A thread in a wrapper folder that is not a Git repository showed no changes on any turn, and edits to repositories inside or next to the project folder never reached the diff panel.

What changed

  • A checkpoint scope per repository. Each tracked repository a turn changes gets its own scope under the thread's root scope. Records are sparse: a clean repository costs one git status per turn and writes nothing, and its baseline is created only when it turns out to have changed. A clone inside a Git project folder is excluded from that folder's checkpoint, so nothing is counted twice.
  • Turn diffs. ThreadTurnDiff carries a patch per repository. Single-repository payloads are unchanged.
  • Web. The turn card groups changed files by repository, the diff panel shows every repository with a repository filter, and a wrapper folder that tracks repositories no longer offers "Initialize Git".
  • Mobile. Review lists repository files with a repository filter; the feed pill shows totals across repositories.
  • Old clients. A repository scope uses the existing manual kind plus a repositoryPath field, because released clients reject a kind they do not know.
  • A Git bug found on the way. listAuthoredPaths passed --since=@<epoch>, which Git reads as "now" for small values. It now uses --max-age.

Before and after

Before, the same turn in a wrapper folder showed no changed files and no diff. After:

Turn card grouping changed files under api and web

Diff panel with All repositories selected

Cost

On a fixture with 31 tracked repositories (one with 5,000 files): a warm turn start adds no Git call for repositories, and a turn end that changed three of them takes about 0.5 s. Snapshotting every repository every turn took 1.9 s.

Known limits

  • If the server restarts in the middle of a turn, a repository the agent committed everything in during that turn shows no files for it.
  • Edits made between turns are attributed to the next turn, as for the project folder today.
  • Working-tree and branch diffs in the diff panel still cover only the thread's own folder; turn diffs are the source for repositories.

Proof

  • vp run check:changed: format, lint, knip, typecheck pass; 1,876 of 1,877 tests pass. The failure is ProjectService.test.ts > returns the deleted project when a completed delete is retried, which fails the same way on this machine without this stack's ProjectService.ts change.
  • A real Claude Haiku turn in a wrapper folder with two repositories: captures above.
  • Mobile: typecheck and unit tests only. Not run on a device.

Created with Claude Fable 5.2 in Claude Code, running in T3 Code, with subagents for the parallel build.

🤖 Generated with Claude Code

    1. tanstack-source added labelsfeature

    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. github-actions[bot](GitHub profile, opens in a new tab)commented

      This PR changes the test suite by +29 test cases (browser +1, unit +21, server +7).

      Keep tests that would fail for a real reason, and test logic below the UI where it can be. See Testing.

    4. @@ -0,0 +68,21 @@
      68+const NO_REPOSITORY_CHANGES: ReadonlyArray<TurnRepositoryChanges> = Object.freeze([]);
      69+const NO_TURN_REPOSITORY_CHANGES: ReadonlyMap<
      70+ RunId,
      71+ ReadonlyArray<TurnRepositoryChanges>
      72+> = new Map();
      73+
      74+export function isRepositoryCheckpointScope(
      75+ scope: Pick<OrchestrationV2CheckpointScope, "repositoryPath">,
      76+): boolean {
      77+ return typeof scope.repositoryPath === "string";
      78+}
      79+
      80+/** Scopes whose checkpoints belong to a repository, never to the thread's own timeline. */
      81+export function repositoryCheckpointScopeIds(
      82+ scopes: ReadonlyArray<Pick<OrchestrationV2CheckpointScope, "id" | "repositoryPath">>,
      83+): ReadonlySet<CheckpointScopeId> {
      84+ return new Set(scopes.flatMap((scope) => (isRepositoryCheckpointScope(scope) ? [scope.id] : [])));
      85+}
      86+
      87+function pathSegments(path: string): { root: string; segments: string[] } | undefined {
      88+ const normalized = path.replaceAll("\\", "/");
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium state/threadRepositories.ts:88

      On POSIX, a repository path containing a literal backslash produces an incorrect relativePath (for example, /work/api\client becomes api/client), so ChangedFilesTree.groupDiffPath generates links for the wrong directory. pathSegments replaces backslashes for every path; normalize them only when the path is Windows-style.

      -  const normalized = path.replaceAll("\\", "/");
      +  const normalized = /^[a-zA-Z]:[\\/]/.test(path) ? path.replaceAll("\\", "/") : path;
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @packages/client-runtime/src/state/threadRepositories.ts around line 88:
      
      On POSIX, a repository path containing a literal backslash produces an incorrect `relativePath` (for example, `/work/api\client` becomes `api/client`), so `ChangedFilesTree.groupDiffPath` generates links for the wrong directory. `pathSegments` replaces backslashes for every path; normalize them only when the path is Windows-style.
      @@ -416,3 +450,4 @@
      416450 selectedSection,
      417451 draftMessage,
      418452 draftContext,
      453+ repositoryFilter:
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium review/ReviewSheet.tsx:453

      Toggling a file in a repository-filtered view deletes the persisted viewed and expanded IDs for files in other repositories. repositoryFilter limits reviewFiles to the selected repository, while useReviewFileVisibility persists state under the whole section and filters cached IDs against its files input; preserve IDs outside the filtered inventory when toggling, or provide the hook the full-section file inventory.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/mobile/src/features/review/ReviewSheet.tsx around line 453:
      
      Toggling a file in a repository-filtered view deletes the persisted viewed and expanded IDs for files in other repositories. `repositoryFilter` limits `reviewFiles` to the selected repository, while `useReviewFileVisibility` persists state under the whole section and filters cached IDs against its `files` input; preserve IDs outside the filtered inventory when toggling, or provide the hook the full-section file inventory.
      @@ -741,3 +777,11 @@
      741777 }
      742778 }, [collapseScopeKey, selectedFilePath, selectedFileRevealRequestId, revealDiffFile]);
      743779
      780+ // A tracked repository's file is named from the thread's folder; on disk it belongs to the
      781+ // repository's own folder, which may sit outside the thread's.
      782+ const repositoryFileTarget = (filePath: string) => {
      783+ const match = repositorySectionForPath(repositorySections, filePath);
      784+ if (match === null) return null;
      785+ return {
      786+ path: match.path,
      787+ insideThreadFolder: !match.section.relativePath.startsWith(".."),
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium components/DiffPanel.tsx:787

      A repository whose relativePath is ..api is treated as outside the thread folder, so clicking ..api/file.ts sets threadRef to null and opens the external editor instead of the in-app file viewer. startsWith("..") matches any two-dot prefix; restrict the check to .. or ../.

      Suggested change
      787- insideThreadFolder: !match.section.relativePath.startsWith(".."),
      787+ insideThreadFolder: match.section.relativePath !== ".." && !match.section.relativePath.startsWith("../"),
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/web/src/components/DiffPanel.tsx around line 787:
      
      A repository whose `relativePath` is `..api` is treated as outside the thread folder, so clicking `..api/file.ts` sets `threadRef` to `null` and opens the external editor instead of the in-app file viewer. `startsWith("..")` matches any two-dot prefix; restrict the check to `..` or `../`.
    5. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs Human Approval

      Macroscope's review found this PR requires human approval — Turn changes and diffs now span tracked repositories on web and mobile. Initialized submodules are also included automatically without configuring tracked folders, requiring human confirmation of the expanded default snapshot and review scope.

      Needs human approval because:

      • 8 blocking correctness issues found at or above your repo's Minimum Blocking Severity
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    6. github-actions[bot](GitHub profile, opens in a new tab)commented

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire—5.0 KiB—6.8 KiB✅
      CodexThread snapshot wire—3.8 KiB—4.9 KiB✅
      CodexLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      CodexLive turn WebSocket decoded—21.5 KiB—24.4 KiB✅
      CodexLive turn messages—1—8✅
      ClaudeTotal thread wire—5.0 KiB—6.8 KiB✅
      ClaudeThread snapshot wire—3.8 KiB—4.9 KiB✅
      ClaudeLive turn WebSocket wire—1.2 KiB—2.0 KiB✅
      ClaudeLive turn WebSocket decoded—21.9 KiB—24.4 KiB✅
      ClaudeLive turn messages—1—8✅

      Other scenarios

      No main baseline exists yet for these 64 scenario measurements.

      All 64 scenario measurements
      ProviderScenarioMetricMain baselineThis PRImpactPR ceiling
      Codexshort turn resumeWebSocket decoded—10.5 KiB—12.7 KiB✅
      Codexshort turn resumeWebSocket messages—2—2✅
      Codexlong turn running, cold openHTTP decoded—281.7 KiB—302.7 KiB✅
      Codexlong turn running, cold openrows—75—75✅
      Codexlong turn running, history pageHTTP decoded—92.4 KiB—107.4 KiB✅
      Codexlong turn running, history pagerows—75—75✅
      Codexlong turn finished, cold openHTTP decoded—381.5 KiB—410.2 KiB✅
      Codexlong turn finished, cold openrows—151—151✅
      Codexlong turn finished, socket cold openWebSocket decoded—381.6 KiB—410.2 KiB✅
      Codexlong turn finished, socket cold openWebSocket messages—2—2✅
      Codexlong turn finished, socket cold openrows—151—151✅
      Codexlong turn finished, work pageHTTP decoded—186.2 KiB—200.2 KiB✅
      Codexlong turn finished, work pagerows—150—150✅
      Codexidle thread resumeWebSocket decoded—65 B—200 B✅
      Codexidle thread resumeWebSocket messages—1—1✅
      Codexfleet shell snapshotHTTP decoded—42.4 KiB—53.7 KiB✅
      Codexfleet shell snapshotrows—27—27✅
      Codexfleet shell subscribeWebSocket decoded—65 B—200 B✅
      Codexfleet shell subscribeWebSocket messages—1—1✅
      Codexfleet shell resume checkHTTP decoded—18 B—100 B✅
      Codexfleet shell resume checkrows—0—0✅
      Codexstale shell reloadHTTP decoded—42.4 KiB—53.7 KiB✅
      Codexstale shell reloadrows—27—27✅
      Codexstale shell resumeWebSocket decoded—140 B—400 B✅
      Codexstale shell resumeWebSocket messages—2—2✅
      Codexstale todo list cold openHTTP decoded—72.4 KiB—83.0 KiB✅
      Codexstale todo list cold openrows—75—75✅
      Codexstale todo list cold opennodes—2—4✅
      Codexstale todo list cold opensubagents—2—4✅
      Codexstale todo list cold openplans—1—2✅
      Codexstale todo list cold openproviderTurns—1—2✅
      Codexstale todo list cold opencheckpoints—1—2✅
      Claudeshort turn resumeWebSocket decoded—10.6 KiB—12.7 KiB✅
      Claudeshort turn resumeWebSocket messages—2—2✅
      Claudelong turn running, cold openHTTP decoded—283.3 KiB—302.7 KiB✅
      Claudelong turn running, cold openrows—75—75✅
      Claudelong turn running, history pageHTTP decoded—93.4 KiB—107.4 KiB✅
      Claudelong turn running, history pagerows—75—75✅
      Claudelong turn finished, cold openHTTP decoded—384.2 KiB—410.2 KiB✅
      Claudelong turn finished, cold openrows—151—151✅
      Claudelong turn finished, socket cold openWebSocket decoded—384.3 KiB—410.2 KiB✅
      Claudelong turn finished, socket cold openWebSocket messages—2—2✅
      Claudelong turn finished, socket cold openrows—151—151✅
      Claudelong turn finished, work pageHTTP decoded—188.1 KiB—200.2 KiB✅
      Claudelong turn finished, work pagerows—150—150✅
      Claudeidle thread resumeWebSocket decoded—66 B—200 B✅
      Claudeidle thread resumeWebSocket messages—1—1✅
      Claudefleet shell snapshotHTTP decoded—43.0 KiB—53.7 KiB✅
      Claudefleet shell snapshotrows—27—27✅
      Claudefleet shell subscribeWebSocket decoded—66 B—200 B✅
      Claudefleet shell subscribeWebSocket messages—1—1✅
      Claudefleet shell resume checkHTTP decoded—18 B—100 B✅
      Claudefleet shell resume checkrows—0—0✅
      Claudestale shell reloadHTTP decoded—43.0 KiB—53.7 KiB✅
      Claudestale shell reloadrows—27—27✅
      Claudestale shell resumeWebSocket decoded—140 B—400 B✅
      Claudestale shell resumeWebSocket messages—2—2✅
      Claudestale todo list cold openHTTP decoded—73.4 KiB—83.0 KiB✅
      Claudestale todo list cold openrows—75—75✅
      Claudestale todo list cold opennodes—2—4✅
      Claudestale todo list cold opensubagents—2—4✅
      Claudestale todo list cold openplans—1—2✅
      Claudestale todo list cold openproviderTurns—1—2✅
      Claudestale todo list cold opencheckpoints—1—2✅

      Baseline: unavailable · PR result: a4e4a8c · Source CI: failure

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    7. @@ -1576,0 +1654,21 @@
      1654+ const lines = status.stdout.split("\n").filter((line) => line.length > 0);
      1655+ if (lines.some((line) => !line.startsWith("# "))) return null;
      1656+ const head = lines.find((line) => line.startsWith("# branch.oid "))?.slice(13);
      1657+ if (head === undefined || !/^[0-9a-f]{40,64}$/.test(head)) return null;
      1658+ return (yield* hasFlaggedIndexEntries(cwd)) ? null : head;
      1659+ }),
      1660+
      1661+ captureHeadCheckpoint: Effect.fn("GitVcsDriver.checkpoints.captureHeadCheckpoint")(
      1662+ function* (input) {
      1663+ const operation = VcsProcess.CHECKPOINT_CAPTURE_OPERATION;
      1664+ const commit = yield* execute({
      1665+ operation,
      1666+ cwd: input.cwd,
      1667+ args: [
      1668+ ...durableWrite,
      1669+ "commit-tree",
      1670+ `${input.head}^{tree}`,
      1671+ "-p",
      1672+ input.head,
      1673+ "-m",
      1674+ `t3 checkpoint ref=${input.checkpointRef}`,
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High vcs/GitVcsDriver.ts:1674

      After a clean baseline is captured on branch A, switching to branch B makes branch-only additions and deletions appear as the turn's edits because the baseline has no HEAD-move trailer or turn-start parent. captureHeadCheckpoint creates a commit with only the t3 checkpoint ref=... message, so a later dirty captureCheckpoint cannot recover the switch and resolveTurnStart falls back to the original A snapshot. Preserve the reflog position in clean baselines and apply the same switch handling when creating clean end-capture checkpoints.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/server/src/vcs/GitVcsDriver.ts around line 1674:
      
      After a clean baseline is captured on branch A, switching to branch B makes branch-only additions and deletions appear as the turn's edits because the baseline has no HEAD-move trailer or turn-start parent. `captureHeadCheckpoint` creates a commit with only the `t3 checkpoint ref=...` message, so a later dirty `captureCheckpoint` cannot recover the switch and `resolveTurnStart` falls back to the original A snapshot. Preserve the reflog position in clean baselines and apply the same switch handling when creating clean end-capture checkpoints.
      @@ -163,3 +336,7 @@
      163336 });
      164337 }
      165338
      339+ const nested = hasRepositories
      340+ ? yield* nestedScopePaths([
      341+ toScope,
      342+ ...projection.checkpointScopes.filter(
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High checkpointing/CheckpointDiffQuery.ts:342

      Requesting an earlier turn silently drops its changes under a subfolder that became a tracked repository later. nestedScopePaths includes that later scope, so its paths are excluded from the historical root patch, while repositoryDiffRange has no checkpoints in the earlier range to provide a replacement patch. Build exclusions from repository scopes that existed when the requested turn was captured, preserving capture-time ownership.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/server/src/checkpointing/CheckpointDiffQuery.ts around line 342:
      
      Requesting an earlier turn silently drops its changes under a subfolder that became a tracked repository later. `nestedScopePaths` includes that later scope, so its paths are excluded from the historical root patch, while `repositoryDiffRange` has no checkpoints in the earlier range to provide a replacement patch. Build exclusions from repository scopes that existed when the requested turn was captured, preserving capture-time ownership.
    8. @@ -155,0 +224,21 @@
      224+ onClick={() => {
      225+ setCollapsed(!collapsed);
      226+ syncTimelineLayout();
      227+ }}
      228+ >
      229+ <ChevronRightIcon
      230+ aria-hidden="true"
      231+ className={cn(
      232+ "size-3.5 shrink-0 text-muted-foreground/70 transition-transform group-hover:text-foreground/80",
      233+ !collapsed && "rotate-90",
      234+ )}
      235+ />
      236+ <FolderGit2Icon className="size-3.5 shrink-0 text-muted-foreground/75" />
      237+ <span className="truncate font-mono text-2xs text-foreground/90">{group.name}</span>
      238+ {hasNonZeroStat(group.totals) && (
      239+ <span className="ml-auto shrink-0 font-mono text-3xs tabular-nums">
      240+ <DiffStatLabel additions={group.totals.additions} deletions={group.totals.deletions} />
      241+ </span>
      242+ )}
      243+ </button>
      244+ {collapsed ? null : group.note !== undefined ? (
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium chat/ChangedFilesTree.tsx:244

      Clicking “Expand all folders” leaves a collapsed repository section closed, so files such as src/a.ts remain hidden; “Collapse all folders” likewise leaves open sections visible. The section’s contents are controlled only by local collapsed, not allDirectoriesExpanded; synchronize the section state when the global setting changes while preserving its initial expanded state.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/web/src/components/chat/ChangedFilesTree.tsx around line 244:
      
      Clicking “Expand all folders” leaves a collapsed repository section closed, so files such as `src/a.ts` remain hidden; “Collapse all folders” likewise leaves open sections visible. The section’s contents are controlled only by local `collapsed`, not `allDirectoriesExpanded`; synchronize the section state when the global setting changes while preserving its initial expanded state.
    9. @@ -240,0 +285,21 @@
      285+ : Effect.succeed([]),
      286+ ),
      287+ );
      288+ },
      289+ { concurrency: DETECTION_CONCURRENCY },
      290+ ),
      291+ ),
      292+ Effect.map((found) => found.flat()),
      293+ );
      294+
      295+ const submodulesOf = Effect.fnUntraced(function* (
      296+ roots: ReadonlyArray<{ readonly path: string; readonly identity: string }>,
      297+ ) {
      298+ const found = yield* Effect.forEach(roots, submodulesBelow, {
      299+ concurrency: DETECTION_CONCURRENCY,
      300+ });
      301+ const taken = new Set(roots.map((root) => root.path));
      302+ return found
      303+ .flat()
      304+ .filter((folder) => !taken.has(folder.path))
      305+ .slice(0, THREAD_SUBMODULES_MAX);
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High workspace/WorkspaceFolders.ts:305

      Repeated path = child entries in nested .gitmodules files make submodules() perform exponential recursive reads and accumulate results before returning at most THREAD_SUBMODULES_MAX folders, which can stall checkpoint discovery. The .slice() runs only after submodulesBelow finishes; enforce a shared visited set or traversal budget before recursing.

      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/server/src/workspace/WorkspaceFolders.ts around line 305:
      
      Repeated `path = child` entries in nested `.gitmodules` files make `submodules()` perform exponential recursive reads and accumulate results before returning at most `THREAD_SUBMODULES_MAX` folders, which can stall checkpoint discovery. The `.slice()` runs only after `submodulesBelow` finishes; enforce a shared visited set or traversal budget before recursing.
      @@ -750,3 +786,11 @@
      750786 }
      751787 }, [collapseScopeKey, selectedFilePath, selectedFileRevealRequestId, revealDiffFile]);
      752788
      789+ // A tracked repository's file is named from the thread's folder; on disk it belongs to the
      790+ // repository's own folder, which may sit outside the thread's.
      791+ const repositoryFileTarget = (filePath: string) => {
      792+ const match = repositorySectionForPath(repositorySections, filePath);
      793+ if (match === null) return null;
      794+ return {
      795+ path: match.path,
      796+ insideThreadFolder: !match.section.relativePath.startsWith(".."),
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium components/DiffPanel.tsx:796

      Clicking a file title for a tracked repository on another Windows drive does nothing instead of opening the editor: relativePath is an absolute path such as D:/api, but this check treats it as inside the thread folder, so openDiffFile passes it with the thread cwd and resolveDiffPathForWorkspace rejects it. Detect absolute paths and check for an exact .. path segment so cross-drive repositories are routed outside while internal directories like ..tools remain inside.

      Suggested change
      796- insideThreadFolder: !match.section.relativePath.startsWith(".."),
      796+ insideThreadFolder:
      797+ !/^(?:[A-Za-z]:[\\/]|[\\/])/.test(match.section.relativePath) &&
      798+ !match.section.relativePath.split(/[\\/]/).includes(".."),
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/web/src/components/DiffPanel.tsx around line 796:
      
      Clicking a file title for a tracked repository on another Windows drive does nothing instead of opening the editor: `relativePath` is an absolute path such as `D:/api`, but this check treats it as inside the thread folder, so `openDiffFile` passes it with the thread cwd and `resolveDiffPathForWorkspace` rejects it. Detect absolute paths and check for an exact `..` path segment so cross-drive repositories are routed outside while internal directories like `..tools` remain inside.
    10. Landed as part of #35925 (60863edc4), which carried the whole stack onto main after the tracking model was reworked. Closing this layer as superseded.

    11. juliusmarminge closed this

Sign in to join this conversation.