Skip to content

fix(opencode): handle snapshot exclude write failure gracefully - #42517

Open
MoerAI wants to merge 2 commits into
anomalyco:devfrom
MoerAI:fix/snapshot-exclude-write-37493
Open

fix(opencode): handle snapshot exclude write failure gracefully#42517
MoerAI wants to merge 2 commits into
anomalyco:devfrom
MoerAI:fix/snapshot-exclude-write-37493

Conversation

@MoerAI

@MoerAI MoerAI commented Aug 14, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #37493

Type of change

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

What does this PR do?

sync() in packages/opencode/src/snapshot/index.ts wrote the snapshot's info/exclude with Effect.orDie. That promotes a recoverable write failure into a defect, and because sync() runs inside add() -> track()/patch(), the defect escapes into the session and kills the turn the user is in the middle of.

Refreshing that exclude file is advisory, so it shouldn't be able to do that. Every other git step in this file already degrades instead of dying - stage(), add(), patch() and cleanup() all log a warning and carry on. sync() now does the same: the ensureDir + write are wrapped together, and a failure logs failed to write snapshot exclude and continues. Ignored files are still filtered separately by ignore() in add(), so a stale exclude file doesn't leak gitignored files into the snapshot.

Only the v1 path is touched - packages/core/src/snapshot.ts already handles this.

How did you verify your code works?

Added git info exclude write failure keeps tracking alive to test/snapshot/snapshot.test.ts. It forces the write to fail by turning <gitdir>/info/exclude into a directory. On current dev that test dies with AlreadyExists: FileSystem.writeFile (...); with the fix track() returns a hash. Full file is 54 pass / 3 skip / 0 fail.

To confirm it outside the test runner I ran the real CLI against a throwaway git repo with the same directory planted:

  • before: opencode debug snapshot track exits 1 with Error: Unexpected error
  • after: exits 0, prints the new hash, and the log has
    level=WARN message="failed to write snapshot exclude" target="..." error="PlatformError: AlreadyExists: FileSystem.writeFile (...)"

bun run typecheck in packages/opencode is clean.

Screenshots / recordings

Not a UI change.

Checklist

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

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential duplicate found:

Why it's related: PR #37494 appears to address the exact same issue (closes #37493) with an identical fix approach. Both PRs handle the snapshot exclude write failure gracefully by converting from Effect.orDie to logging a warning and continuing instead of crashing the session.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(snapshot): handle info/exclude write failure gracefully instead of crashing session

1 participant