Skip to content
TypeScript

fix(server): Codex shadow homes replace stray sqlite maintenance locks (#17663)

Julius Marminge140ee145ac33
diff --git a/apps/server/src/provider/Drivers/CodexHomeLayout.test.ts b/apps/server/src/provider/Drivers/CodexHomeLayout.test.ts
index 2c78ffd1866..5323b6a2667 100644
--- a/apps/server/src/provider/Drivers/CodexHomeLayout.test.ts
+++ b/apps/server/src/provider/Drivers/CodexHomeLayout.test.ts
@@ -140,6 +140,34 @@ it.layer(NodeServices.layer)("CodexHomeLayout", (it) => {
}),
);
+ it.effect.skipIf(!symlinksSupported)(
+ "replaces a Codex-created local sqlite maintenance lock with the shared lock",
+ () =>
+ Effect.gen(function* () {
+ const fileSystem = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ const sharedHome = yield* makeTempDir("t3code-codex-shared-");
+ const shadowRoot = yield* makeTempDir("t3code-codex-shadow-root-");
+ const shadowHome = path.join(shadowRoot, "shadow");
+ const sharedLock = path.join(sharedHome, ".sqlite-maintenance.lock");
+ const shadowLock = path.join(shadowHome, ".sqlite-maintenance.lock");
+
+ yield* writeTextFile(sharedLock, "");
+ yield* writeTextFile(shadowLock, "");
+
+ const layout = yield* resolveCodexHomeLayout(
+ decodeCodexSettings({
+ homePath: sharedHome,
+ shadowHomePath: shadowHome,
+ }),
+ );
+
+ yield* materializeCodexShadowHome(layout);
+
+ expect(yield* fileSystem.readLink(shadowLock)).toBe(sharedLock);
+ }),
+ );
+
it.effect.skipIf(!symlinksSupported)(
"replaces Codex-created local MCP OAuth locks with the shared lock directory",
() =>
diff --git a/apps/server/src/provider/Drivers/CodexHomeLayout.ts b/apps/server/src/provider/Drivers/CodexHomeLayout.ts
index d38951d501e..9d4410da984 100644
--- a/apps/server/src/provider/Drivers/CodexHomeLayout.ts
+++ b/apps/server/src/provider/Drivers/CodexHomeLayout.ts
@@ -30,7 +30,9 @@ const KNOWN_SHARED_DIRECTORIES = [
const PRIVATE_ENTRY_NAMES = new Set(["auth.json", "models_cache.json"]);
const SHADOW_LOCAL_ENTRY_NAMES = new Set(["log", "memories", "tmp"]);
-const REPLACEABLE_SHARED_RUNTIME_DIRECTORIES = new Set(["mcp-oauth-locks"]);
+// Codex creates these runtime locks itself when it starts in a shadow home before the shared
+// home has one. They guard shared state, so a local copy is replaced with the shared link.
+const REPLACEABLE_SHARED_RUNTIME_ENTRIES = new Set(["mcp-oauth-locks", ".sqlite-maintenance.lock"]);
function resolveHomePath(path: Path.Path, home: string, value: string | undefined): string {
const expanded =
@@ -241,7 +243,7 @@ const ensureSymlink = Effect.fn("CodexHomeLayout.ensureSymlink")(function* (inpu
);
if (state._tag === "NotSymlink") {
- if (!REPLACEABLE_SHARED_RUNTIME_DIRECTORIES.has(input.entryName)) {
+ if (!REPLACEABLE_SHARED_RUNTIME_ENTRIES.has(input.entryName)) {
return yield* new CodexShadowHomeEntryConflictError({
sharedHomePath: input.sharedHomePath,
effectiveHomePath: input.effectiveHomePath,