Skip to content
TypeScript

fix(server): fall back when checkpoint fsync is unsupported (#14411)

mohammed shazeb67e05acf817e
diff --git a/apps/server/src/vcs/GitVcsDriver.ts b/apps/server/src/vcs/GitVcsDriver.ts
index 88642ed9d74..5d382f16d2e 100644
--- a/apps/server/src/vcs/GitVcsDriver.ts
+++ b/apps/server/src/vcs/GitVcsDriver.ts
@@ -784,6 +784,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
// an unclean restart can leave 0-byte files under refs/t3/** that break every
// later fetch and push. Checkpoint writes flush before they are published;
// macOS defaults to writeout-only, which does not reach the disk either.
+ // On macOS, VcsProcess retries unsupported full flushes with plain fsync.
const durableWrite = [
"-c",
"core.fsync=objects,reference",
diff --git a/apps/server/src/vcs/VcsProcess.test.ts b/apps/server/src/vcs/VcsProcess.test.ts
index 3e14efd78e8..e5fcd758cc4 100644
--- a/apps/server/src/vcs/VcsProcess.test.ts
+++ b/apps/server/src/vcs/VcsProcess.test.ts
@@ -97,6 +97,98 @@ describe("VcsProcess.run", () => {
}),
);
+ it.effect.each([
+ {
+ stderr: "fatal: fsync error on '.git/objects/a5/tmp_obj_Pseg66': Operation not supported",
+ fsyncMethods: ["fsync", "writeout-only"],
+ },
+ {
+ stderr:
+ "fatal: update_ref failed for ref 'refs/t3/checkpoints/x': cannot update ref 'refs/t3/checkpoints/x': couldn't write '/Volumes/share/.git/refs/t3/checkpoints/x.lock'",
+ fsyncMethods: ["fsync", "writeout-only"],
+ },
+ { stderr: "fatal: Operation not supported", fsyncMethods: ["fsync"] },
+ {
+ stderr:
+ "fatal: update_ref failed for ref 'refs/t3/checkpoints/x': cannot update ref 'refs/t3/checkpoints/x': couldn't write '/Volumes/share/.git/refs/t3/checkpoints/x.lock': Input/output error",
+ fsyncMethods: ["fsync"],
+ },
+ {
+ stderr: "fatal: fsync error on '.git/objects/a5/tmp_obj_Pseg66': Operation not supported",
+ fsyncMethods: ["fsync", "writeout-only"],
+ fallbackFails: true,
+ },
+ {
+ platform: "linux",
+ stderr: "fatal: fsync error on '.git/objects/a5/tmp_obj_Pseg66': Operation not supported",
+ fsyncMethods: ["fsync"],
+ },
+ {
+ operation: baseInput.operation,
+ stderr: "fatal: fsync error on '.git/objects/a5/tmp_obj_Pseg66': Operation not supported",
+ fsyncMethods: ["fsync"],
+ },
+ ] as const)(
+ "falls back to writeout-only only for unsupported fsync on macOS: $stderr",
+ ({ stderr, fsyncMethods, ...scenario }) =>
+ Effect.gen(function* () {
+ const seen: Array<ReadonlyArray<string>> = [];
+ const service = yield* VcsProcess.make.pipe(
+ Effect.provideService(
+ HostProcess.Platform,
+ "platform" in scenario ? scenario.platform : "darwin",
+ ),
+ Effect.provideService(ProcessRunner.ProcessRunner, {
+ run: (input) =>
+ Effect.sync(() => {
+ seen.push(input.args);
+ const failed =
+ input.args.includes("core.fsyncMethod=fsync") ||
+ ("fallbackFails" in scenario && scenario.fallbackFails);
+ return {
+ stdout: "",
+ stderr: failed ? stderr : "",
+ code: ChildProcessSpawner.ExitCode(failed ? 128 : 0),
+ timedOut: false,
+ stdoutTruncated: false,
+ stderrTruncated: false,
+ stdoutInvalidUtf8: false,
+ stderrInvalidUtf8: false,
+ };
+ }),
+ }),
+ );
+ const exit = yield* service
+ .run({
+ ...baseInput,
+ operation:
+ "operation" in scenario
+ ? scenario.operation
+ : VcsProcess.CHECKPOINT_CAPTURE_OPERATION,
+ args: ["-c", "core.fsync=objects,reference", "-c", "core.fsyncMethod=fsync", "add"],
+ })
+ .pipe(Effect.exit);
+ expect(seen).toEqual(
+ fsyncMethods.map((method) => [
+ "-c",
+ "core.fsync=objects,reference",
+ "-c",
+ `core.fsyncMethod=${method}`,
+ "add",
+ ]),
+ );
+ expect(Exit.isSuccess(exit)).toBe(
+ fsyncMethods.length === 2 && !("fallbackFails" in scenario && scenario.fallbackFails),
+ );
+ if (Exit.isFailure(exit)) {
+ expect(Cause.findErrorOption(exit.cause)).toMatchObject({
+ _tag: "Some",
+ value: { _tag: "VcsProcessExitError", exitCode: 128 },
+ });
+ }
+ }),
+ );
+
it.effect.each(["timeout", "spawn"] as const)(
"checkpoint commands do not retry %s failures",
(kind) =>
diff --git a/apps/server/src/vcs/VcsProcess.ts b/apps/server/src/vcs/VcsProcess.ts
index 35694643753..e4eba5f0fb2 100644
--- a/apps/server/src/vcs/VcsProcess.ts
+++ b/apps/server/src/vcs/VcsProcess.ts
@@ -9,6 +9,7 @@ import { ChildProcessSpawner } from "effect/process";
import {
type VcsError,
+ type VcsProcessErrorContext,
VcsProcessExitError,
type VcsProcessExitFailureKind,
VcsProcessMissingExitCodeError,
@@ -162,21 +163,24 @@ const isTransientGitExit = (stderr: string) =>
/unable to create [^\n]*\.lock['"]?: file exists/i.test(stderr) ||
/(?:unable to stat|lstat\(|error: open\()[^\n]+: no such file or directory/i.test(stderr);
+// On macOS, Git's fsync uses F_FULLFSYNC; writeout-only still uses fsync(2).
+// Network mounts can reject F_FULLFSYNC. Ref writes omit errno, so retry their
+// bare write error too; explicit unrelated errors remain failures.
+// Linux writeout-only only starts writeback, so it must not use this fallback.
+const FULL_FSYNC_ARG = "core.fsyncMethod=fsync";
+const WRITEOUT_ONLY_FSYNC_ARG = "core.fsyncMethod=writeout-only";
+const canRetryFullFsync = (stderr: string) =>
+ /fsync error on [^\r\n]+: operation not supported\r?$/im.test(stderr) ||
+ /cannot update ref [^\r\n]+: couldn't write '[^\r\n]+\.lock'\r?$/im.test(stderr);
+
export const make = Effect.gen(function* () {
const processRunner = yield* ProcessRunner.ProcessRunner;
const hostPlatform = yield* HostProcess.Platform;
const vcsProcesses = yield* Semaphore.make(VCS_PROCESS_CONCURRENCY);
const githubProcesses = yield* Semaphore.make(GITHUB_PROCESS_CONCURRENCY);
- const runUnbounded = Effect.fn("VcsProcess.runUnbounded")(function* (input: VcsProcessInput) {
- const baseError = {
- operation: input.operation,
- command: input.command,
- cwd: input.cwd,
- argumentCount: input.args.length,
- };
-
- const result = yield* processRunner
+ const spawn = (input: VcsProcessInput, baseError: VcsProcessErrorContext) =>
+ processRunner
.run({
command: input.command,
args: input.args,
@@ -224,6 +228,35 @@ export const make = Effect.gen(function* () {
),
);
+ const runUnbounded = Effect.fn("VcsProcess.runUnbounded")(function* (input: VcsProcessInput) {
+ const baseError = {
+ operation: input.operation,
+ command: input.command,
+ cwd: input.cwd,
+ argumentCount: input.args.length,
+ };
+
+ let result = yield* spawn(input, baseError);
+
+ if (
+ hostPlatform === "darwin" &&
+ input.operation === CHECKPOINT_CAPTURE_OPERATION &&
+ !input.allowNonZeroExit &&
+ result.code !== null &&
+ result.code !== 0 &&
+ input.command === "git" &&
+ input.args.includes(FULL_FSYNC_ARG) &&
+ canRetryFullFsync(result.stderr)
+ ) {
+ result = yield* spawn(
+ {
+ ...input,
+ args: input.args.map((arg) => (arg === FULL_FSYNC_ARG ? WRITEOUT_ONLY_FSYNC_ARG : arg)),
+ },
+ baseError,
+ );
+ }
+
if (result.code === null) {
return yield* new VcsProcessMissingExitCodeError(baseError);
}