Skip to content

fix(core): read session diffs from earlier snapshot stores - #61180

Open
Namit2003 wants to merge 1 commit into
anomalyco:devfrom
Namit2003:snapshot-store-fallback
Open

Namit2003 wants to merge 1 commit into
anomalyco:devfrom
Namit2003:snapshot-store-fallback

Conversation

@Namit2003

@Namit2003 Namit2003 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #60857

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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/diff fails with bad object and 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 when from and to are 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.ts that fail without the fix. bun run check and the core tests pass.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

snapshot: /session/:id/diff returns 500 "bad object" for turns captured before a project ID change

1 participant