Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/opencode/src/snapshot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ const layer: Layer.Layer<Service, never, FSUtil.Service | AppProcess.Service | C
]
.filter(Boolean)
.join("\n")
yield* fs.ensureDir(path.join(state.gitdir, "info")).pipe(Effect.orDie)
yield* fs.writeFileString(target, text ? `${text}\n` : "").pipe(Effect.orDie)
// Refreshing the exclude file is advisory, so a failure must not take the session down.
yield* Effect.gen(function* () {
yield* fs.ensureDir(path.join(state.gitdir, "info"))
yield* fs.writeFileString(target, text ? `${text}\n` : "")
}).pipe(Effect.catch((error) => Effect.logWarning("failed to write snapshot exclude", { target, error })))
})

// Reuse the hashes for the git storage between the original repo and snapshot
Expand Down
23 changes: 23 additions & 0 deletions packages/opencode/test/snapshot/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ import { $ } from "bun"
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
import { FSUtil } from "@opencode-ai/core/fs-util"
import { Global } from "@opencode-ai/core/global"
import { Hash } from "@opencode-ai/core/util/hash"
import fs from "fs/promises"
import path from "path"
import { Effect, Fiber, Layer } from "effect"
import { Snapshot } from "../../src/snapshot"
import {
disposeAllInstances,
provideInstance,
requireInstance,
testInstanceStoreLayer,
TestInstance,
tmpdirScoped,
Expand Down Expand Up @@ -647,6 +650,26 @@ it.instance(
{ git: true },
)

it.instance(
"git info exclude write failure keeps tracking alive",
Effect.gen(function* () {
const tmp = yield* bootstrap()
const snapshot = yield* Snapshot.Service
const before = yield* snapshot.track()
expect(before).toBeTruthy()
// Make the snapshot exclude write fail: a directory can never be overwritten by a file.
const ctx = yield* requireInstance
const gitdir = path.join(Global.Path.data, "snapshot", ctx.project.id, Hash.fast(ctx.worktree))
yield* rm(path.join(gitdir, "info", "exclude"))
yield* mkdirp(path.join(gitdir, "info", "exclude"))
yield* write(`${tmp.path}/after.txt`, "after content")
const after = yield* snapshot.track()
expect(after).toBeTruthy()
}),
{ git: true },
{ timeout: 60000 },
)

it.instance(
"concurrent file operations during patch",
withTrackedSnapshot(({ tmp, snapshot, before }) =>
Expand Down
Loading