fix(runner): persist codex home in session pvc (#242)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { accessSync, constants as fsConstants, readdirSync, readFileSync } from "node:fs";
|
||||
import { chmod, copyFile, mkdir } from "node:fs/promises";
|
||||
import { chmod, copyFile, mkdir, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import * as readline from "node:readline";
|
||||
import type { BackendEvent, BackendProfile, BackendTurnResult, CommandRecord, FailureKind, InitialPromptAssembly, JsonRecord, JsonValue, RunRecord, TerminalStatus } from "../common/types.js";
|
||||
@@ -852,6 +852,7 @@ async function prepareProjectedCodexHome(codexHome: string, projectedHome: strin
|
||||
await copyFile(path.join(projectedHome, fileName), path.join(codexHome, fileName));
|
||||
await chmod(path.join(codexHome, fileName), 0o600);
|
||||
}
|
||||
await normalizeCopiedCodexConfig(codexHome);
|
||||
return null;
|
||||
} catch (error) {
|
||||
const payload = {
|
||||
@@ -875,6 +876,29 @@ async function prepareProjectedCodexHome(codexHome: string, projectedHome: strin
|
||||
}
|
||||
}
|
||||
|
||||
async function normalizeCopiedCodexConfig(codexHome: string): Promise<void> {
|
||||
const configPath = path.join(codexHome, "config.toml");
|
||||
const modelCatalogPath = path.join(codexHome, "model-catalog.json");
|
||||
if (!fileReadable(modelCatalogPath).readable) return;
|
||||
let configToml = "";
|
||||
try {
|
||||
configToml = readFileSync(configPath, "utf8");
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
const normalized = configToml.replace(
|
||||
/(^\s*model_catalog_json\s*=\s*")([^"]+)("\s*$)/mu,
|
||||
(_match, prefix: string, _oldValue: string, suffix: string) => `${prefix}${tomlBasicStringValue(modelCatalogPath)}${suffix}`,
|
||||
);
|
||||
if (normalized === configToml) return;
|
||||
await writeFile(configPath, normalized, { mode: 0o600 });
|
||||
await chmod(configPath, 0o600);
|
||||
}
|
||||
|
||||
function tomlBasicStringValue(value: string): string {
|
||||
return value.replace(/\\/gu, "\\\\").replace(/"/gu, "\\\"");
|
||||
}
|
||||
|
||||
function codexHomeReadiness(codexHome: string, profile: BackendProfile): BackendTurnResult | null {
|
||||
const auth = fileReadable(`${codexHome}/auth.json`);
|
||||
const config = fileReadable(`${codexHome}/config.toml`);
|
||||
|
||||
Reference in New Issue
Block a user