Skip to content

fix(snapshot): honor snapshot:false in restore/revert/patch/diff#3

Merged
ranxianglei merged 1 commit into
masterfrom
fix/snapshot-disabled-still-restores
Jun 23, 2026
Merged

fix(snapshot): honor snapshot:false in restore/revert/patch/diff#3
ranxianglei merged 1 commit into
masterfrom
fix/snapshot-disabled-still-restores

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Problem

The snapshot: false config was only half-implemented. The enabled() guard existed on track() and cleanup(), but was missing from restore(), revert(), patch(), diff(), and diffFull(). These operations still ran git read-tree + checkout-index on stored snapshot hashes even when snapshots were explicitly disabled.

This caused crashes on large sessions (e.g. 1800+ messages, 165 tracked file changes) when restoring snapshots exceeded resource limits — particularly under spawned/non-TUI contexts (opencode run, systemd-launched processes).

Root cause

Asymmetry in the config gate:

Function Had guard?
cleanup() yes
track() yes
restore() no (crashes here)
revert() no
patch() no
diff() no
diffFull() no

The config docstring already promises "undoing or reverting will not undo/redo file changes" when snapshot:false, but the implementation broke that promise.

Fix

Add if (!(yield* enabled())) return to all five unguarded operations, placed outside locked() so the semaphore isn't acquired when disabled (matches track()'s pattern). Each returns a typed empty result appropriate to its signature.

Verification

  • Build passes smoke test (v1.14.41), no type errors
  • The previously-crashing session (1807 messages) now loads and runs normally via opencode run --session — replied to prompts and executed tool calls without the snapshot restore crash
  • Confirmed under both interactive shell and spawned (awork/systemd) contexts

The snapshot:false config only gated tracking (track/cleanup) but not
the restore/revert/patch/diff/diffFull operations. These still ran git
read-tree + checkout-index on any stored snapshot hash, crashing on
large sessions (e.g. 1800+ messages with 165 file changes) where the
snapshot restore exceeded resource limits under spawned (non-TUI)
contexts.

The config docstring promises 'undoing or reverting will not undo/redo
file changes' when snapshot:false, but the implementation broke that
promise. Add the missing enabled() guard to all five operations so the
config fully disables snapshot filesystem mutations regardless of caller
(TUI, opencode run, HTTP API, spawned processes).
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot closed this Jun 23, 2026
@ranxianglei ranxianglei reopened this Jun 23, 2026
@ranxianglei ranxianglei merged commit d572591 into master Jun 23, 2026
3 of 12 checks passed
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.

1 participant