From abe8bf533af4658f078826b4a23a6754160128c7 Mon Sep 17 00:00:00 2001 From: ranxianglei Date: Tue, 23 Jun 2026 17:21:24 +0800 Subject: [PATCH] fix(snapshot): honor snapshot:false in restore/revert/patch/diff 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). --- packages/opencode/src/snapshot/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/opencode/src/snapshot/index.ts b/packages/opencode/src/snapshot/index.ts index 22398e43f1..2e6e3b27df 100644 --- a/packages/opencode/src/snapshot/index.ts +++ b/packages/opencode/src/snapshot/index.ts @@ -316,6 +316,7 @@ export const layer: Layer.Layer< }) const patch = Effect.fnUntraced(function* (hash: string) { + if (!(yield* enabled())) return { hash, files: [] } return yield* locked( Effect.gen(function* () { yield* add() @@ -349,6 +350,7 @@ export const layer: Layer.Layer< }) const restore = Effect.fnUntraced(function* (snapshot: string) { + if (!(yield* enabled())) return return yield* locked( Effect.gen(function* () { log.info("restore", { commit: snapshot }) @@ -375,6 +377,7 @@ export const layer: Layer.Layer< }) const revert = Effect.fnUntraced(function* (patches: Patch[]) { + if (!(yield* enabled())) return return yield* locked( Effect.gen(function* () { const ops: { hash: string; file: string; rel: string }[] = [] @@ -490,6 +493,7 @@ export const layer: Layer.Layer< }) const diff = Effect.fnUntraced(function* (hash: string) { + if (!(yield* enabled())) return "" return yield* locked( Effect.gen(function* () { yield* add() @@ -510,6 +514,7 @@ export const layer: Layer.Layer< }) const diffFull = Effect.fnUntraced(function* (from: string, to: string) { + if (!(yield* enabled())) return [] return yield* locked( Effect.gen(function* () { type Row = {