Repository navigation
Conversation
The snapshot store path includes the project ID, which changes when a repository gains a remote. Trees captured under the earlier ID stay in that store, so diffing an older turn failed with "bad object" and /session/:id/diff returned HTTP 500. When the current store lacks a compared tree, rerun the diff with every earlier store for the same worktree as a per-command alternate object directory, so `from` and `to` may come from different stores. If Git confirms a tree is in no store, return an empty diff; inspection and filesystem failures still surface as errors. Closes anomalyco#60857
There was a problem hiding this comment.
Looks good. I reproduced #60857 on the base by running its script from source with a local mock model: after git remote add, session.diff returned HTTP 500 with fatal: bad object <tree>. With this change, the same call returns the earlier turn's diff. test/snapshot.test.ts passes, and both new tests fail without the fix. git.test.ts and session-diff.test.ts pass, and tsc -b on packages/core is clean.
The fallback only runs after a diff has failed, so the normal path has no extra cost. A store git can't read still fails instead of returning []. The alternates apply to that one command only, and quoted entries are handled correctly with the platform separator.
Public API: unchanged. Git.tree.missing, the optional alternates input and the inspect operation are internal to packages/core.
The one remaining gap is the one you already mention: Snapshot.restore still can't revert turns captured before the ID change. It fails the same way on the base, so it fits a follow-up.
Related: #57985
Issue for this PR
Closes #60857
Type of change
What does this PR do?
The snapshot store path includes the project ID, which changes when a repo gains a remote. Older turns point at trees in the old store, so
/session/:id/difffails withbad objectand returns a 500.When the current store is missing a tree, the diff reruns with the other stores for the same worktree passed as
GIT_ALTERNATE_OBJECT_DIRECTORIES, which works even whenfromandtoare in different stores. If the trees are in no store, it returns an empty diff. Other git or filesystem errors still fail.Revert (
Snapshot.restore) has the same problem; I'll fix it in a follow-up.How did you verify your code works?
Reproduced the 500 locally by adding a remote, then confirmed the fix returns the diff. Added tests in
snapshot.test.tsthat fail without the fix.bun run checkand the core tests pass.Screenshots / recordings
N/A
Checklist