Repository navigation
fix(core): keep OpenCode data out of filesystem snapshots - #56209
Parker-Fawcett wants to merge 2 commits into
Conversation
When OpenCode's data directory is inside the snapshotted worktree, for example a Git-tracked $HOME, every capture recorded the snapshot store's own new objects, and a revert could delete live store files. Exclude the data directory from capture, remove entries an earlier capture already recorded there, and drop it from files, diff, and restore plans so older trees stay harmless. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
The following comment was made by an LLM, it may be inaccurate: |
There was a problem hiding this comment.
The fix works, and I don't see anything that blocks a merge. I reproduced #55010 through Snapshot.capture and Snapshot.files, with the data directory at <home>/.local/share/opencode inside a Git-tracked home folder and 8 captures after one-line edits. On the base, the store's own entries in each tree grew 22 → 55 → … → 2625, and files returned up to 934 store paths per step. With this change, trees hold only the edited files, and files returns just the edited file. That holds both when the location is the home root and when it's a subdirectory. The new tests in snapshot.test.ts pass here and fail on the base. git.test.ts and bun run typecheck in packages/core pass.
The public API is unchanged: CaptureInput.excludes is an optional field on the internal Git service.
Two small, non-blocking points:
- Only
global.datais excluded. In the same home-folder setup,~/.cache/opencodeand~/.local/state/opencodecan still end up in snapshots and be rewritten by a revert. They don't grow the store the way the data directory did, so leaving them for later is fine. - When the data directory is inside the worktree, the stale-entry
ls-filesruns on every capture. Running it once per store, next tosweepTemporaryIndexes/ensureSnapshotConfig, would also work, since the exclusion keeps the entries from coming back. This only matters for that setup.
|
Thanks for checking both the home-root and subdirectory cases.
🤖 Addressed by Claude Code |
Keep dev's early returns and precomputed diff paths in Snapshot.files and Snapshot.diff, together with this branch's data directory filter. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Issue for this PR
Closes #55010
Type of change
What does this PR do?
When OpenCode's data directory is inside the snapshotted worktree, for example a Git-tracked
$HOME, each capture recorded the snapshot store's own new objects, so the store kept growing. Those paths also came back fromSnapshot.files, so a revert could delete live store files. In a local test, reverting one step removed 32 of 34 of them.The snapshot now works out where
global.datasits relative to the worktree, by real path, and::(exclude,literal)pathspec;files,diff, and restore plans, so trees captured before this change can't touch the data directory.Nothing changes when the data directory is outside the worktree.
How did you verify your code works?
snapshot.test.ts, with the data dir at<home>/.local/share/opencode, reached through a symlink:files/diff, and that the next capture cleans the index.dev. Removing any one part of the fix (exclusion, cleanup, filtering, or the real-path lookup) makes at least one of them fail.--rerun-each 10 --randomizeand use about 30 git spawns.packages/core: full-suite failures are identical todevon my machine (30, all from macOS Bash 3.2 and ripgrep in my environment).bun typecheckand rootbun run checkpass.Screenshots / recordings
N/A
Checklist
🤖 Generated with Claude Code
Added by the opencode bot (AI-generated).
Related: #51836, #16336, #36093