Skip to content

Commit bb4c4a4

Browse files
committed
fix(ci): stop Windows suite hang and ACL-timeout start abort
Keep background-shell term grace timers ref'd so Bun Windows fires them during unresolved drain, tolerate icacls timeouts on config writes so the data plane can still start, and inject test fsync for directory spill order.
1 parent 15534e0 commit bb4c4a4

4 files changed

Lines changed: 39 additions & 8 deletions

File tree

‎src/adapters/cursor/native-exec-shell.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,14 @@ function waitForBackgroundShellClose(entry: BackgroundShellEntry): Promise<boole
335335
if (backgroundShells.get(entry.shellId) !== entry) return Promise.resolve(true);
336336
return new Promise(resolveWait => {
337337
let settled = false;
338+
// Do not unref: shutdown/drain awaits this grace window. On Bun Windows,
339+
// an unref'd timer that is the sole waiter never fires and hangs the suite
340+
// (and windows-latest job) until the runner timeout.
338341
const timer = backgroundShellRuntime.setTimer(() => {
339342
if (settled) return;
340343
settled = true;
341344
resolveWait(false);
342345
}, CURSOR_BACKGROUND_SHELL_TERM_GRACE_MS);
343-
unrefTimer(timer);
344346
void entry.closePromise.then(() => {
345347
if (settled) return;
346348
settled = true;

‎src/config.ts‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,29 @@ function isMissingPathError(error: unknown): boolean {
103103
return (error as NodeJS.ErrnoException | undefined)?.code === "ENOENT";
104104
}
105105

106+
/** True when required NTFS harden failed closed on a transient icacls timeout. */
107+
function isWindowsAclTimeoutError(error: unknown): boolean {
108+
const message = error instanceof Error ? error.message : String(error);
109+
return /timed out|previous attempt timed out/i.test(message);
110+
}
111+
106112
export function atomicWriteFile(path: string, content: string, io: AtomicWriteIO = {
107113
write: (target, value) => writeFileSync(target, value, { encoding: "utf-8", mode: 0o600 }),
108114
harden: target => {
109115
try { chmodSync(target, 0o600); } catch { /* platform may ignore chmod */ }
110-
if (process.platform === "win32") hardenSecretPath(target, { required: true });
116+
if (process.platform === "win32") {
117+
try {
118+
hardenSecretPath(target, { required: true });
119+
} catch (err) {
120+
// Data-plane invariant: ACL timeout must not abort atomic config writes /
121+
// server start (management-auth catches the same class of failure).
122+
if (!isWindowsAclTimeoutError(err)) throw err;
123+
console.warn(
124+
"[opencodex] atomic config write ACL harden timed out:",
125+
err instanceof Error ? err.message : err,
126+
);
127+
}
128+
}
111129
},
112130
rename: renameAtomicFile,
113131
truncate: target => truncateSync(target, 0),
@@ -1527,7 +1545,16 @@ function configMutationDatabasePath(): string {
15271545
try { chmodSync(dir, 0o700); } catch { /* best-effort on existing dir */ }
15281546
}
15291547
if (process.platform === "win32") {
1530-
hardenSecretDir(dir, { required: true });
1548+
try {
1549+
hardenSecretDir(dir, { required: true });
1550+
} catch (err) {
1551+
// Match management-auth: ACL timeout must not abort process start / data plane.
1552+
if (!isWindowsAclTimeoutError(err)) throw err;
1553+
console.warn(
1554+
"[opencodex] config mutation directory ACL harden timed out:",
1555+
err instanceof Error ? err.message : err,
1556+
);
1557+
}
15311558
}
15321559
const path = join(dir, CONFIG_MUTATION_DB_FILENAME);
15331560
recordOwnedConfigPath(dir, path);

‎tests/responses-state.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,9 @@ describe("Responses previous_response_id state", () => {
603603

604604
test("does not swap a resident row to a stub before fsync and no-replace publication succeed", () => {
605605
const events: string[] = [];
606-
setSpillIoForTest({ record: event => events.push(event) });
606+
// Inject fsync: Windows often rejects fsync on directory handles; the production
607+
// path is best-effort, but this test still needs a deterministic event order.
608+
setSpillIoForTest({ record: event => events.push(event), fsync: () => {} });
607609
setResponseStateByteCapForTests(1_024);
608610
rememberLarge("resp_durable_order", "x".repeat(8_000));
609611
expect(events).toEqual(["write", "fsync", "close", "harden", "publish", "dir-fsync", "stub-swap"]);
@@ -612,7 +614,7 @@ describe("Responses previous_response_id state", () => {
612614
test("directory fsync follows spill unlink", () => {
613615
const ref = writeResponseSpillDurably("resp_unlink_order", { createdAt: Date.now(), items: ["x"] });
614616
const events: string[] = [];
615-
setSpillIoForTest({ record: event => events.push(event) });
617+
setSpillIoForTest({ record: event => events.push(event), fsync: () => {} });
616618
deleteResponseSpill(ref);
617619
expect(events).toEqual(["dir-fsync"]);
618620
});

‎tests/shutdown-drain.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ describe("background shell shutdown drain", () => {
118118
test("shell drain rejection or unresolved termination still calls server.stop", async () => {
119119
const unresolvedChild = installShutdownShell();
120120
setBackgroundShellRuntimeForTests({
121+
// Keep the timer ref'd: drain awaits unresolved termination, and Bun
122+
// Windows will not fire an unref'd sole waiter (hangs windows-latest).
121123
setTimer(callback) {
122-
const timer = setTimeout(callback, 0);
123-
timer.unref?.();
124-
return timer;
124+
return setTimeout(callback, 0);
125125
},
126126
});
127127
const unresolvedServer = fakeServer();

0 commit comments

Comments
 (0)