Skip to content

Commit 07a3246

Browse files
committed
fix(sync): never inject or touch the journal in external-provider catalog-only mode
1 parent a834141 commit 07a3246

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

‎src/codex/sync.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,21 @@ export async function syncModelsToCodex(
139139

140140
if (externalProvider) {
141141
if (catalogEvenWhenNotInjected) {
142-
// External providers own config.toml, so the injection below is only a
143-
// courtesy. The catalog is still refreshed: the side profile consumes it.
142+
// External providers own config.toml, and the injector removes the OpenCodex
143+
// journal for external providers (inject.ts). This explicit catalog-only sync
144+
// must not touch config, journal, or history, so refresh the catalog/cache and
145+
// return without injection.
144146
applyProxyEnv(config);
145147
const refreshed = await refreshCatalogForSync(config, deps, undefined, log);
146-
const result = await deps.injectCodexConfig(p, config, {});
147-
if (result.success) log?.log(result.message);
148-
else log?.error(result.message);
149-
reportCodexHomeTarget(log, deps.collectCodexHomeDiagnostic ?? collectOrcaCodexHomeDiagnostic);
148+
const message = refreshed.catalogWritten || refreshed.cacheSynced
149+
? "External provider owns config.toml; catalog and models cache refreshed, Codex config/journal untouched."
150+
: "External provider owns config.toml; catalog refresh skipped, Codex config/journal untouched.";
150151
return {
151-
status: "applied",
152-
ok: result.success,
152+
status: "catalog-only",
153+
ok: true,
153154
...refreshed,
154-
message: result.message,
155+
message,
155156
...(refreshed.comboOmissions.length > 0 ? { comboOmissions: refreshed.comboOmissions } : {}),
156-
...(result.nativeSubagentDefaultsWarning ? { nativeSubagentDefaultsWarning: result.nativeSubagentDefaultsWarning } : {}),
157157
};
158158
}
159159
const result = await deps.injectCodexConfig(p, config, {});

‎tests/codex-sync-api.test.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,12 @@ describe("GUI/CLI Codex sync backend", () => {
261261
expect(result.message).toContain("Codex config untouched");
262262
});
263263

264-
test("explicit sync refreshes the catalog before preserving an external provider", async () => {
264+
test("explicit sync refreshes the catalog without injecting or touching the journal for an external provider", async () => {
265265
let refreshed = 0;
266266
let injectCalls = 0;
267+
const journalPath = join(TEST_CODEX_HOME, "opencodex-journal.json");
268+
const journalBytes = Buffer.from(JSON.stringify({ injectedOpenaiBaseUrl: "http://127.0.0.1:1/v1" }));
269+
writeFileSync(journalPath, journalBytes);
267270
const result = await syncModelsToCodex(10100, config, null, {
268271
admitCodexWrite: admittedSync,
269272
refreshCodexModelCatalog: async () => {
@@ -285,15 +288,17 @@ describe("GUI/CLI Codex sync backend", () => {
285288
}, { catalogEvenWhenNotInjected: true });
286289

287290
expect(refreshed).toBe(1);
288-
expect(injectCalls).toBe(1);
291+
expect(injectCalls).toBe(0);
292+
expect(readFileSync(journalPath)).toEqual(journalBytes);
289293
expect(result).toMatchObject({
290-
status: "applied",
294+
status: "catalog-only",
291295
ok: true,
292296
added: 2,
293297
catalogExists: true,
294298
catalogWritten: true,
295299
cacheSynced: true,
296300
});
301+
expect(String(result.message)).toContain("journal untouched");
297302
});
298303

299304
/**

0 commit comments

Comments
 (0)