ReviewOS

stacks/harness

Attribute the diff to the session, not the working tree

#6
Closed chris opened this 9 days ago ·
9 days ago

/s/:id/diff currently reports the workspace's uncommitted state. If you had edits in flight before the session started, they appear as though the agent made them. The UI says so in words, because a wrong attribution is trusted, but words are a stopgap.

What it needs

A baseline commit recorded when the session opens, then git diff <baseline> instead of git diff HEAD. That also covers the case the current version misses entirely: an agent that commits its work disappears from git diff HEAD.

The baseline cannot be captured in the reducer — that has to stay pure and replayable, and reading git is neither. It follows the same shape as thread.session.set: the runtime captures it and records it through an internal command.

Sketch:

  1. thread.baseline.set internal command + session.baseline event carrying the SHA (and a flag for "not a repository").
  2. SessionState.baseline, projected.
  3. The runtime resolves git rev-parse HEAD when it first creates a driver instance for a session, and records it.
  4. workspaceDiff(path, baseline) diffs against it, falling back to HEAD when there is none — sessions recorded before this change must keep working.

This is the natural first half of the branch-per-session work in M6, and doing them together is probably cheaper than doing either alone.

9 days ago

Done in 3a1e89a.

Measured against the session's first checkpoint rather than a new marker — checkpoints already exist for undo, and the earliest one is the baseline.

The subtlety worth recording: comparing a baseline tree against the live index reports a present-but-untracked file as deleted, because it is in the tree, absent from the index, and git cannot tell you still have it. Snapshotting the working tree the same way the checkpoint does makes it symmetric — and upgrades a new file from untracked with no counts to added with real ones.

Verified live against an agent that committed its work twice: git diff HEAD empty, panel reports session scope with the change.

Sign in to comment on this issue.