Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat: attribute turn diffs so git-only changes stop polluting changed files #4249

Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 4 commits intomain fromfeat/attribution-aware-turn-diffsopened View on GitHub

Problem

The changed-files card and per-turn inline diff are derived from full-tree checkpoint snapshots (git diff snap(N-1) snap(N)). That answers "what bytes changed between turn boundaries" — but the card is a review surface, and the moment the agent runs a tree-rewriting git command the two diverge:

  • git pull origin main → hundreds of already-reviewed upstream files listed as agent changes
  • git checkout other-branch → the entire branch delta appears
  • git cherry-pick / git rebase → content authored elsewhere shows up as new

Approach

Keep the snapshot mechanism exactly as-is (it powers revert and is ground truth) and add a read-side attribution layer. We don't need to observe what the agent did — git history records it after the fact:

agent-authored delta = tree delta (snapshots) − foreign-history delta (HEAD movement)
  • Checkpoint commits now record head=<oid> and branch=<name> in their commit message (no schema/ref changes; legacy checkpoints degrade to today's behavior).
  • attributeCheckpointDiff classifies each path in a checkpoint tree delta: a path is git only when its exact blob transition (mode + oid both sides, --no-renames) also appears in the HEAD-movement delta and no commit authored during the turn touched it. Commits are considered turn-authored when their author date ≥ the baseline checkpoint's commit time — cherry-pick/rebase preserve author dates, so replayed foreign commits are correctly demoted, while the agent committing its own edits stays "agent". Merge commits use the combined diff (-c) so only conflict resolutions count as agent work.
  • Fast path: if HEAD didn't move during the turn (the vast majority), no extra git calls beyond two rev-parses at capture, and behavior is identical to today.
  • Fail direction: every ambiguity resolves to "agent" (shown). Attribution errors, truncated output, legacy checkpoints, or pathological commit counts degrade to the unfiltered diff — attribution can add noise but never hides agent work, and never blocks the checkpoint pipeline.

Surfaces

  • Changed-files card: lists agent-authored files only, plus a muted ⎇ Updated via git — N files row for demoted changes (with aggregate +/− stats). A git-only turn shows just that row instead of disappearing.
  • Diff panel: git-attributed file sections are dropped from the patch by default; a banner offers "Show them" / "Hide them" (new includeGitChanges input on getTurnDiff / getFullThreadDiff).
  • OrchestrationCheckpointFile gains an optional origin: "agent" | "git" field.

Testing

  • Unit tests for message metadata round-trip, raw-diff parsing, and path classification (CheckpointAttribution.test.ts)
  • Integration tests against real git repos: no-HEAD-move fast path, branch switch + edit in one turn, own-commit turns, cherry-pick of a pre-existing commit, legacy checkpoints (CheckpointStore.test.ts)
  • Patch filtering tests incl. deletions and binary sections (Diffs.test.ts), partition tests (turnDiffTree.test.ts)
  • Full suites green: server (1551), web (1378), contracts (179), client-runtime (269); typecheck and lint clean

Plan write-up: https://syizveepeikc.postplan.dev

🤖 Generated with Claude Code


Note

Medium Risk Non-trivial git history heuristics and new diff filtering affect what users see; ambiguous cases degrade to unfiltered diffs and legacy checkpoints skip attribution rather than blocking checkpoints.

Overview Turn diffs and changed-files views no longer treat every checkpoint tree delta as agent work when git rewrote the tree (pull, checkout, cherry-pick, rebase). A read-side attribution layer classifies paths as agent vs git, while snapshot capture/revert stays unchanged.

Server: Checkpoint commits embed HEAD oid + branch in commit messages. New attributeCheckpointDiff (VCS → CheckpointStore) compares checkpoint tree deltas to HEAD-movement deltas and turn-authored commits (patch-id disambiguation for cherry-picks/amends). getTurnDiff / getFullThreadDiff run attribution after diffCheckpoints, strip git-attributed file sections by default, accept includeGitChanges, and return optional gitFileCount aligned with the rendered patch. filterUnifiedDiffFiles / path parsing handles renames, binaries, and quoted paths. CheckpointReactor tags turn summary files with optional origin (best-effort; failures leave files unattributed).

Contracts & client: Optional origin on checkpoint files; diff APIs gain includeGitChanges and gitFileCount.

Web: Changed-files card lists agent files only plus a compact “Updated via git” row; diff panel shows a show/hide git changes banner per turn scope.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit bcebb793b030a01319205b58e4d1c4f09bdf4664. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Filter git-attributed file changes from turn diffs to reduce noise in changed files view

  • Checkpoint commits now record HEAD commit OID and branch metadata, enabling GitVcsDriver.attributeCheckpointDiff to classify each changed path as 'agent' or 'git' by comparing tree and history deltas, with conservative fallback to null.
  • CheckpointDiffQuery applies this attribution to filter out git-attributed sections from unified diffs by default; callers pass includeGitChanges: true to see them.
  • CheckpointReactor attaches a per-file origin field to turn summary files, and MessagesTimeline collapses git-origin files into a separate 'Updated via git' row.
  • The diff panel shows a banner when git-attributed files are hidden, with a toggle to reveal them.
  • Behavioral Change: existing checkpoint commits lack the new HEAD metadata, so attribution returns null for legacy checkpoints and all files are treated as agent-authored.
Macroscope summarized bcebb79.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: 133e6086-1c6f-453c-a2e4-e240e58ce87a

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `feat/attribution-aware-turn-diffs`

      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

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

      Approvability

      Verdict: Needs human review

      New feature adding git attribution logic with 3 unresolved medium-severity bugs identified (unborn HEAD handling, past-dated commits, mobile compatibility). The complexity of the attribution algorithm and its impact on what diffs users see warrants human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Cursor Bugbot has reviewed your changes using high effort and found 3 potential issues.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit bcebb793b030a01319205b58e4d1c4f09bdf4664. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -850,0 +888,21 @@
      888+ allowNonZeroExit: true,
      889+ }).pipe(Effect.map((result) => (result.exitCode === 0 ? result.stdout.trimEnd() : null)));
      890+
      891+ const fromMessage = yield* readCommitField(`${input.fromCheckpointRef}^{commit}`, "%B");
      892+ const toMessage = yield* readCommitField(`${input.toCheckpointRef}^{commit}`, "%B");
      893+ if (fromMessage === null || toMessage === null) {
      894+ return null;
      895+ }
      896+ const fromMetadata = parseCheckpointCommitMessage(fromMessage);
      897+ const toMetadata = parseCheckpointCommitMessage(toMessage);
      898+ // Checkpoints captured before attribution metadata existed: unavailable.
      899+ if (fromMetadata === null || toMetadata === null) {
      900+ return null;
      901+ }
      902+
      903+ // HEAD did not move during the turn (or the repo has no commits):
      904+ // every tree change is agent-authored. An empty map means "classified,
      905+ // no git-origin paths".
      906+ if (fromMetadata.headOid === toMetadata.headOid || fromMetadata.headOid === null) {
      907+ return new Map<string, "agent" | "git">();
      908+ }

      Unborn HEAD skips git attribution

      Medium Severity

      The fast path treats any turn that starts with unborn HEAD (head=none) as having no git-origin changes, including when HEAD later points at a real commit. A git pull / git checkout of existing history into a fresh repo therefore keeps every path as agent work, so the changed-files card and diff panel still show the foreign tree as agent edits.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit bcebb793b030a01319205b58e4d1c4f09bdf4664. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -850,0 +988,21 @@
      988+ readonly oid: string;
      989+ readonly isMerge: boolean;
      990+ }
      991+ const turnAuthoredCommits: Array<RangeCommit> = [];
      992+ const rewrittenCommits: Array<RangeCommit> = [];
      993+ for (const line of headRangeResult.stdout.split("\n")) {
      994+ const [oid, authorTime, commitTime, ...parents] = line.trim().split(" ");
      995+ if (!oid || !authorTime || !commitTime) {
      996+ continue;
      997+ }
      998+ const authoredAt = Number(authorTime);
      999+ const committedAt = Number(commitTime);
      1000+ if (!Number.isFinite(authoredAt) || !Number.isFinite(committedAt)) {
      1001+ continue;
      1002+ }
      1003+ const commit: RangeCommit = { oid, isMerge: parents.length > 1 };
      1004+ if (authoredAt >= fromCommitTime) {
      1005+ turnAuthoredCommits.push(commit);
      1006+ } else if (committedAt >= fromCommitTime) {
      1007+ rewrittenCommits.push(commit);
      1008+ }

      Past-dated agent commits demoted to git

      Medium Severity

      Turn commit classification only keeps commits with author or committer time at/after the baseline checkpoint. An agent commit whose author and committer dates both precede that baseline falls into neither bucket, so matching HEAD-movement blob transitions are labeled git and can be filtered out of the review diff, contrary to the fail-toward-agent rule.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit bcebb793b030a01319205b58e4d1c4f09bdf4664. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -173,3 +221,9 @@
      173221 ignoreWhitespace,
      174222 })
      175223 .pipe(Effect.withSpan("checkpoint.turnDiff.diffCheckpoints"));
      224+ const filtered = yield* applyAttributionFilter({
      225+ cwd: workspaceCwd,
      226+ fromCheckpointRef,
      227+ toCheckpointRef,
      228+ diff: rawDiff,
      229+ includeGitChanges: input.includeGitChanges ?? false,

      Mobile diffs hide git changes silently

      Medium Severity

      getTurnDiff / getFullThreadDiff now default includeGitChanges to false, so history-driven sections are stripped for every client. Mobile still builds review file lists from that patch and never sends includeGitChanges or offers a reveal control, so a git-only turn (pull, checkout, rebase) renders as an empty diff with no explanation.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit bcebb793b030a01319205b58e4d1c4f09bdf4664. Configure [here](https://www.cursor.com/dashboard/bugbot).
    5. Closing in favor of #2829 (orchestration V2).

      #2829 deletes the V1 orchestration layer this PR builds on — apps/server/src/orchestration/**, provider/Layers/*Adapter.ts and provider/Services/** are removed and replaced by apps/server/src/orchestration-v2/**, with the IPC surface renamed to ORCHESTRATION_V2_WS_METHODS. The files this PR touches either no longer exist or are rewritten, so it can't be rebased — it would need reimplementing against the V2 adapters.

      This is not a judgement on the change itself. Several of these are real gaps we still want fixed; the base just moved out from under them.

      Once #2829 merges, please rebase onto main, port the change to the V2 equivalent, and reopen (or open a fresh PR). Ping me and I'll prioritise the review.

    6. juliusmarminge closed this

Sign in to join this conversation.