Skip to content

Commit 304e5b8

Browse files
committed
fix(codex): close the undefined and false-lock fallback gaps in failure wording
1 parent d18aa52 commit 304e5b8

4 files changed

Lines changed: 29 additions & 9 deletions

File tree

‎src/cli/index.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
describeHistoryJobFailure,
77
resolveCodexHistoryJobTarget,
88
runCodexHistoryJob,
9-
type CodexHistoryJobOutcome,
109
} from "../codex/history-job";
1110
import { reconcileJournal } from "../codex/journal";
1211
import {
@@ -789,10 +788,7 @@ async function handleRecoverHistory() {
789788
: { rows: 0, files: 0, failed: true as const };
790789
if (r.failed) {
791790
console.error(
792-
`⚠️ Recovery SKIPPED: ${describeHistoryJobFailure(
793-
outcome as Extract<CodexHistoryJobOutcome, { kind: "blocked" | "failed" }>,
794-
"recover-legacy",
795-
)}`,
791+
`⚠️ Recovery SKIPPED: ${describeHistoryJobFailure(outcome, "recover-legacy")}`,
796792
);
797793
process.exit(1);
798794
}

‎src/codex/history-job.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,19 @@ export function deriveCodexHistoryOperation(intent: {
145145
* denial, or a dead worker is a different problem with a different remedy.
146146
*/
147147
export function describeHistoryJobFailure(
148-
outcome: Extract<CodexHistoryJobOutcome, { kind: "blocked" | "failed" }>,
148+
outcome: CodexHistoryJobOutcome,
149149
surface: "apply" | "restore" | "recover-legacy",
150150
legacyMode = false,
151151
): string {
152+
// Callers only invoke this after observing a failure flag, but that flag is
153+
// derived from "not converged", which also covers "skipped". Naming those
154+
// two kinds keeps a widened or miscast call site from printing `undefined`.
155+
if (outcome.kind === "skipped") {
156+
return "the history operation was skipped; no failure was recorded.";
157+
}
158+
if (outcome.kind === "converged") {
159+
return "the history job reported no failure; run 'ocx doctor' if this is unexpected.";
160+
}
152161
if (outcome.kind === "blocked") {
153162
switch (outcome.reason) {
154163
case "busy":

‎src/codex/inject.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,16 @@ function failedHistoryRestoreFromOutcome(
12771277
);
12781278
case "desired_disabled":
12791279
case "desired_enabled":
1280-
return failedHistoryRestore();
1280+
// Unreachable today: the async restore caller intercepts both desired-
1281+
// state reasons before this mapper runs. If that ever changes, name
1282+
// the actual cause instead of falling back to the lock wording this
1283+
// function exists to get rid of (issue #1191).
1284+
return failedHistoryRestore(
1285+
undefined,
1286+
outcome.reason === "desired_disabled"
1287+
? "Codex integration is disabled, so the history operation was skipped."
1288+
: "Codex integration is enabled, so the history operation was skipped.",
1289+
);
12811290
}
12821291
}
12831292
if (outcome.historyFailureReason === "busy") return failedHistoryRestore("busy");
@@ -1614,11 +1623,10 @@ export function getCodexConfigPath(): string {
16141623
* reason names itself instead of blaming the Codex app/IDE.
16151624
*/
16161625
function formatApplyHistoryFailure(outcome: CodexHistoryJobOutcome, legacyMode: boolean): string {
1617-
const failure = outcome as Extract<CodexHistoryJobOutcome, { kind: "blocked" | "failed" }>;
16181626
const headline = legacyMode
16191627
? "Codex resume history sync SKIPPED"
16201628
: outcome.kind === "blocked" && outcome.reason === "busy"
16211629
? "Codex resume history migration deferred"
16221630
: "Codex resume history NOT changed";
1623-
return ` ⚠️ ${headline}: ${describeHistoryJobFailure(failure, "apply", legacyMode)}\n`;
1631+
return ` ⚠️ ${headline}: ${describeHistoryJobFailure(outcome, "apply", legacyMode)}\n`;
16241632
}

‎tests/codex-history-job.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ test("the failure wording names the real reason instead of always blaming the Co
114114

115115
const timeout = { kind: "failed", reason: "timeout", message: "history_worker_timeout" } as const;
116116
expect(describeHistoryJobFailure(timeout, "restore")).toContain("timed out");
117+
118+
// Callers flag failure as "not converged", which also covers these two
119+
// kinds; the wording must name them rather than returning undefined.
120+
const skipped = { kind: "skipped" } as const;
121+
expect(describeHistoryJobFailure(skipped, "recover-legacy")).toContain("skipped");
122+
const converged = { kind: "converged", rows: 0, files: 0 } as const;
123+
expect(describeHistoryJobFailure(converged, "apply")).toContain("no failure");
117124
});
118125

119126
test("skip resolves without spawning a thread and writes nothing", async () => {

0 commit comments

Comments
 (0)