Skip to content

Commit 37d05a1

Browse files
t3dotggclaude
andcommitted
fix(server): Codex shadow homes share thread writer locks with the main home
Codex 0.165 allows one writer per thread across processes through lock files in <CODEX_HOME>/thread-writer-locks. Shadow homes did not link that directory, so shadow-home and main-home processes could lock in different places and write one rollout at once. Link it as shared, and replace a local copy that a shadow home already created. Keep auth.lock (Codex 0.166+) private, since it guards the shadow home's private auth.json. Before, it caused a shadow-home entry conflict. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 49a9e80 commit 37d05a1

2 files changed

Lines changed: 63 additions & 2 deletions

File tree

‎apps/server/src/provider/Drivers/CodexHomeLayout.test.ts‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,61 @@ it.layer(NodeServices.layer)("CodexHomeLayout", (it) => {
221221
}),
222222
);
223223

224+
it.effect.skipIf(!symlinksSupported)(
225+
"replaces Codex-created local thread writer locks with the shared lock directory",
226+
() =>
227+
Effect.gen(function* () {
228+
const fileSystem = yield* FileSystem.FileSystem;
229+
const path = yield* Path.Path;
230+
const sharedHome = yield* makeTempDir("t3code-codex-shared-");
231+
const shadowRoot = yield* makeTempDir("t3code-codex-shadow-root-");
232+
const shadowHome = path.join(shadowRoot, "shadow");
233+
const shadowLocks = path.join(shadowHome, "thread-writer-locks");
234+
235+
yield* writeTextFile(path.join(shadowLocks, ".coordination.lock"), "");
236+
237+
const layout = yield* resolveCodexHomeLayout(
238+
decodeCodexSettings({
239+
homePath: sharedHome,
240+
shadowHomePath: shadowHome,
241+
}),
242+
);
243+
244+
yield* materializeCodexShadowHome(layout);
245+
246+
expect(yield* fileSystem.readLink(shadowLocks)).toBe(
247+
path.join(sharedHome, "thread-writer-locks"),
248+
);
249+
}),
250+
);
251+
252+
it.effect.skipIf(!symlinksSupported)("keeps the shadow auth lock private", () =>
253+
Effect.gen(function* () {
254+
const fileSystem = yield* FileSystem.FileSystem;
255+
const path = yield* Path.Path;
256+
const sharedHome = yield* makeTempDir("t3code-codex-shared-");
257+
const shadowRoot = yield* makeTempDir("t3code-codex-shadow-root-");
258+
const shadowHome = path.join(shadowRoot, "shadow");
259+
const shadowLock = path.join(shadowHome, "auth.lock");
260+
261+
yield* writeTextFile(path.join(sharedHome, "auth.lock"), "");
262+
yield* writeTextFile(shadowLock, "");
263+
264+
const layout = yield* resolveCodexHomeLayout(
265+
decodeCodexSettings({
266+
homePath: sharedHome,
267+
shadowHomePath: shadowHome,
268+
}),
269+
);
270+
271+
yield* materializeCodexShadowHome(layout);
272+
273+
const lockLinkResult = yield* fileSystem.readLink(shadowLock).pipe(Effect.result);
274+
expect(lockLinkResult._tag).toBe("Failure");
275+
expect(yield* fileSystem.exists(shadowLock)).toBe(true);
276+
}),
277+
);
278+
224279
it.effect.skipIf(!symlinksSupported)(
225280
"accepts Codex-created shadow-local runtime directories",
226281
() =>

‎apps/server/src/provider/Drivers/CodexHomeLayout.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@ const KNOWN_SHARED_DIRECTORIES = [
2626
"cache",
2727
"logs",
2828
"mcp-oauth-locks",
29+
"thread-writer-locks",
2930
] as const;
3031

31-
const PRIVATE_ENTRY_NAMES = new Set(["auth.json", "models_cache.json"]);
32+
// auth.lock guards the shadow home's private auth.json.
33+
const PRIVATE_ENTRY_NAMES = new Set(["auth.json", "auth.lock", "models_cache.json"]);
3234
// Finder maintains metadata separately for each directory, including shadow homes.
3335
const SHADOW_LOCAL_ENTRY_NAMES = new Set(["log", "memories", "tmp", ".DS_Store"]);
3436
// Shadow homes may create local runtime locks first; replace them with shared links because they guard shared state.
35-
const REPLACEABLE_SHARED_RUNTIME_ENTRIES = new Set(["mcp-oauth-locks", ".sqlite-maintenance.lock"]);
37+
const REPLACEABLE_SHARED_RUNTIME_ENTRIES = new Set([
38+
"mcp-oauth-locks",
39+
"thread-writer-locks",
40+
".sqlite-maintenance.lock",
41+
]);
3642

3743
function resolveHomePath(path: Path.Path, home: string, value: string | undefined): string {
3844
const expanded =

0 commit comments

Comments
 (0)