Skip to content

Commit a3cc039

Browse files
fix(server): limit checkpoint batch flushing to macOS and Windows
1 parent 68fa527 commit a3cc039

3 files changed

Lines changed: 80 additions & 81 deletions

File tree

‎apps/server/src/vcs/GitVcsDriver.test.ts‎

Lines changed: 73 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as NodeServices from "@effect/platform-node/NodeServices";
2+
import * as HostProcess from "@t3tools/shared/HostProcess";
23
import * as Cause from "effect/Cause";
34
import * as Clock from "effect/Clock";
45
import * as Duration from "effect/Duration";
@@ -1149,76 +1150,80 @@ it.effect("GitVcsDriver forwards execute env to the VCS process", () => {
11491150
);
11501151
});
11511152

1152-
it.effect("GitVcsDriver flushes checkpoint objects and refs to disk before publishing them", () => {
1153-
const observedArgs: ReadonlyArray<string>[] = [];
1153+
it.effect.each([
1154+
{ platform: "linux", fsyncMethods: ["fsync"] },
1155+
{ platform: "darwin", fsyncMethods: ["fsync", "batch"] },
1156+
{ platform: "win32", fsyncMethods: ["fsync", "batch"] },
1157+
] as const)(
1158+
"GitVcsDriver flushes checkpoint objects and refs to disk before publishing them on $platform",
1159+
({ platform, fsyncMethods }) => {
1160+
const observedArgs: ReadonlyArray<string>[] = [];
11541161

1155-
return Effect.gen(function* () {
1156-
const driver = yield* GitVcsDriver.makeVcsDriverShape();
1162+
return Effect.gen(function* () {
1163+
const driver = yield* GitVcsDriver.makeVcsDriverShape();
11571164

1158-
yield* driver.checkpoints.captureCheckpoint({
1159-
cwd: "/repo",
1160-
checkpointRef: CheckpointRef.make("refs/t3/checkpoints/thread/turn/1"),
1161-
});
1165+
yield* driver.checkpoints.captureCheckpoint({
1166+
cwd: "/repo",
1167+
checkpointRef: CheckpointRef.make("refs/t3/checkpoints/thread/turn/1"),
1168+
});
11621169

1163-
const writeCommands = ["add", "write-tree", "commit-tree", "update-ref"];
1164-
const writes = observedArgs.filter((args) =>
1165-
writeCommands.some((command) => args.includes(command)),
1166-
);
1167-
assert.strictEqual(writes.length, 4);
1168-
for (const args of writes) {
1169-
const command = args.findIndex((arg) => writeCommands.includes(arg));
1170-
for (const setting of [
1171-
"core.fsync=objects,reference",
1172-
"core.fsyncMethod=fsync",
1173-
"core.fsyncMethod=batch",
1174-
]) {
1175-
const index = args.indexOf(setting);
1176-
assert.strictEqual(args[index - 1], "-c", args.join(" "));
1177-
assert.isBelow(index, command);
1178-
}
1179-
assert.isBelow(
1180-
args.indexOf("core.fsyncMethod=fsync"),
1181-
args.indexOf("core.fsyncMethod=batch"),
1170+
const writeCommands = ["add", "write-tree", "commit-tree", "update-ref"];
1171+
const writes = observedArgs.filter((args) =>
1172+
writeCommands.some((command) => args.includes(command)),
11821173
);
1183-
}
1184-
assert.deepStrictEqual(observedArgs.at(-1), [
1185-
"-C",
1186-
"/repo",
1187-
"-c",
1188-
"core.fsync=objects,reference",
1189-
"-c",
1190-
"core.fsyncMethod=fsync",
1191-
"-c",
1192-
"core.fsyncMethod=batch",
1193-
"update-ref",
1194-
"refs/t3/checkpoints/thread/turn/1",
1195-
"commit0000",
1196-
]);
1197-
}).pipe(
1198-
Effect.provide(
1199-
Layer.mergeAll(
1200-
NodeServices.layer,
1201-
Layer.mock(VcsProcess.VcsProcess)({
1202-
run: (input) =>
1203-
Effect.sync(() => {
1204-
observedArgs.push(input.args);
1205-
const stdout = input.args.includes("write-tree")
1206-
? "tree0000\n"
1207-
: input.args.includes("commit-tree")
1208-
? "commit0000\n"
1209-
: input.args.includes("--git-common-dir")
1210-
? ".git\n"
1211-
: "";
1212-
return {
1213-
exitCode: ChildProcessSpawner.ExitCode(0),
1214-
stdout,
1215-
stderr: "",
1216-
stdoutTruncated: false,
1217-
stderrTruncated: false,
1218-
};
1219-
}),
1220-
}),
1174+
assert.strictEqual(writes.length, 4);
1175+
for (const args of writes) {
1176+
const command = args.findIndex((arg) => writeCommands.includes(arg));
1177+
assert.deepStrictEqual(
1178+
args.filter((arg) => arg.startsWith("core.fsyncMethod=")),
1179+
fsyncMethods.map((method) => `core.fsyncMethod=${method}`),
1180+
);
1181+
for (const setting of [
1182+
"core.fsync=objects,reference",
1183+
...fsyncMethods.map((method) => `core.fsyncMethod=${method}`),
1184+
]) {
1185+
const index = args.indexOf(setting);
1186+
assert.strictEqual(args[index - 1], "-c", args.join(" "));
1187+
assert.isBelow(index, command);
1188+
}
1189+
}
1190+
assert.deepStrictEqual(observedArgs.at(-1), [
1191+
"-C",
1192+
"/repo",
1193+
"-c",
1194+
"core.fsync=objects,reference",
1195+
...fsyncMethods.flatMap((method) => ["-c", `core.fsyncMethod=${method}`]),
1196+
"update-ref",
1197+
"refs/t3/checkpoints/thread/turn/1",
1198+
"commit0000",
1199+
]);
1200+
}).pipe(
1201+
Effect.provideService(HostProcess.Platform, platform),
1202+
Effect.provide(
1203+
Layer.mergeAll(
1204+
NodeServices.layer,
1205+
Layer.mock(VcsProcess.VcsProcess)({
1206+
run: (input) =>
1207+
Effect.sync(() => {
1208+
observedArgs.push(input.args);
1209+
const stdout = input.args.includes("write-tree")
1210+
? "tree0000\n"
1211+
: input.args.includes("commit-tree")
1212+
? "commit0000\n"
1213+
: input.args.includes("--git-common-dir")
1214+
? ".git\n"
1215+
: "";
1216+
return {
1217+
exitCode: ChildProcessSpawner.ExitCode(0),
1218+
stdout,
1219+
stderr: "",
1220+
stdoutTruncated: false,
1221+
stderrTruncated: false,
1222+
};
1223+
}),
1224+
}),
1225+
),
12211226
),
1222-
),
1223-
);
1224-
});
1227+
);
1228+
},
1229+
);

‎apps/server/src/vcs/GitVcsDriver.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as NodeBuffer from "node:buffer";
22

3+
import * as HostProcess from "@t3tools/shared/HostProcess";
34
import * as Context from "effect/Context";
45
import * as Crypto from "effect/Crypto";
56
import * as DateTime from "effect/DateTime";
@@ -526,6 +527,7 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
526527
const path = yield* Path.Path;
527528
const vcsProcess = yield* VcsProcess.VcsProcess;
528529
const crypto = yield* Crypto.Crypto;
530+
const hostPlatform = yield* HostProcess.Platform;
529531
const capabilities = {
530532
kind: "git" as const,
531533
supportsWorktrees: true,
@@ -785,15 +787,17 @@ export const makeVcsDriverShape = Effect.fn("makeGitVcsDriverShape")(function* (
785787
// later fetch and push. Checkpoint writes flush before they are published;
786788
// macOS defaults to writeout-only, which does not reach the disk either.
787789
// Set fsync first: Git 2.36 ignores unknown batch without resetting the method.
788-
// Git 2.37+ batches object flushes per command; refs still get a full flush.
790+
// Git documents batch/fsync equivalence on macOS HFS+/APFS and Windows NTFS/ReFS;
791+
// keep per-object fsync on other platforms. Batch still fully flushes refs.
789792
// On macOS, VcsProcess retries unsupported full flushes with plain fsync.
790793
const durableWrite = [
791794
"-c",
792795
"core.fsync=objects,reference",
793796
"-c",
794797
"core.fsyncMethod=fsync",
795-
"-c",
796-
"core.fsyncMethod=batch",
798+
...(hostPlatform === "darwin" || hostPlatform === "win32"
799+
? ["-c", "core.fsyncMethod=batch"]
800+
: []),
797801
] as const;
798802

799803
const checkpoints: VcsDriver.VcsCheckpointOps = {

‎apps/server/src/vcs/VcsProcess.test.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -137,16 +137,6 @@ describe("VcsProcess.run", () => {
137137
"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'",
138138
fsyncMethods: ["batch", "writeout-only"],
139139
},
140-
{
141-
platform: "linux",
142-
stderr: "fatal: fsync error on '.git/objects/bulk_fsync_Pseg66': Operation not supported",
143-
fsyncMethods: ["batch"],
144-
},
145-
{
146-
stderr: "fatal: fsync error on '.git/objects/bulk_fsync_Pseg66': Operation not supported",
147-
fsyncMethods: ["batch", "writeout-only"],
148-
fallbackFails: true,
149-
},
150140
] as const)(
151141
"falls back to writeout-only only for unsupported flushes on macOS ($fsyncMethods): $stderr",
152142
({ stderr, fsyncMethods, ...scenario }) =>

0 commit comments

Comments
 (0)