Skip to content

Commit 790d49c

Browse files
author
SomSamantray
committed
fix(companion): harden stopAtFirstPositional and retry progress phase
Arm stopOptions when unrecognized dash tokens become positional so -m in prompts is not consumed as --model. Emit progress phase retrying (not failed) for willRetry app-server errors.
1 parent ce4ac23 commit 790d49c

4 files changed

Lines changed: 70 additions & 2 deletions

File tree

‎plugins/codex/scripts/lib/args.mjs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ export function parseArgs(argv, config = {}) {
5050
}
5151

5252
positionals.push(token);
53+
if (config.stopAtFirstPositional) {
54+
stopOptions = true;
55+
}
5356
continue;
5457
}
5558

@@ -72,6 +75,9 @@ export function parseArgs(argv, config = {}) {
7275
}
7376

7477
positionals.push(token);
78+
if (config.stopAtFirstPositional) {
79+
stopOptions = true;
80+
}
7581
}
7682

7783
return { options, positionals };

‎plugins/codex/scripts/lib/codex.mjs‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,12 +539,16 @@ function applyTurnNotification(state, message) {
539539
emitProgress(
540540
state.onProgress,
541541
`Codex error (retrying): ${message.params.error?.message ?? "unknown error"}`,
542-
"failed"
542+
resolveErrorProgressPhase(message.params)
543543
);
544544
break;
545545
}
546546
state.error = message.params.error;
547-
emitProgress(state.onProgress, `Codex error: ${message.params.error.message}`, "failed");
547+
emitProgress(
548+
state.onProgress,
549+
`Codex error: ${message.params.error.message}`,
550+
resolveErrorProgressPhase(message.params)
551+
);
548552
break;
549553
case "turn/completed":
550554
if ((message.params.threadId ?? null) !== state.threadId) {
@@ -766,6 +770,10 @@ export function shouldStoreTurnError(params = {}) {
766770
return Boolean(params.error) && params.willRetry !== true;
767771
}
768772

773+
export function resolveErrorProgressPhase(params = {}) {
774+
return params.willRetry === true ? "retrying" : "failed";
775+
}
776+
769777
export function buildResultStatus(turnState) {
770778
if (turnState.error) {
771779
return 1;

‎tests/args.test.mjs‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,44 @@ test("parseArgs honors -- passthrough before stopAtFirstPositional matters", ()
4141
assert.equal(result.options.model, undefined);
4242
assert.equal(result.positionals.join(" "), "-m pytest");
4343
});
44+
45+
test("stopAtFirstPositional stops after unrecognized long option becomes positional", () => {
46+
const result = parseArgs(["--write", "--coverage", "run", "-m", "pytest"], {
47+
...TASK_CONFIG,
48+
stopAtFirstPositional: true
49+
});
50+
51+
assert.equal(result.options.write, true);
52+
assert.equal(result.options.model, undefined);
53+
assert.equal(result.positionals.join(" "), "--coverage run -m pytest");
54+
});
55+
56+
test("without stopAtFirstPositional unrecognized long then -m still sets model", () => {
57+
const result = parseArgs(["--write", "--coverage", "run", "-m", "pytest"], TASK_CONFIG);
58+
59+
assert.equal(result.options.write, true);
60+
assert.equal(result.options.model, "pytest");
61+
assert.equal(result.positionals.join(" "), "--coverage run");
62+
});
63+
64+
test("stopAtFirstPositional stops after unrecognized short option becomes positional", () => {
65+
const result = parseArgs(["--write", "-z", "-m", "pytest"], {
66+
...TASK_CONFIG,
67+
stopAtFirstPositional: true
68+
});
69+
70+
assert.equal(result.options.write, true);
71+
assert.equal(result.options.model, undefined);
72+
assert.equal(result.positionals.join(" "), "-z -m pytest");
73+
});
74+
75+
test("stopAtFirstPositional still parses recognized flags before first positional", () => {
76+
const result = parseArgs(["--write", "--model", "spark", "fix it"], {
77+
...TASK_CONFIG,
78+
stopAtFirstPositional: true
79+
});
80+
81+
assert.equal(result.options.write, true);
82+
assert.equal(result.options.model, "spark");
83+
assert.equal(result.positionals.join(" "), "fix it");
84+
});

‎tests/codex-turn-status.test.mjs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,22 @@ import test from "node:test";
33

44
import {
55
buildResultStatus,
6+
resolveErrorProgressPhase,
67
shouldStoreTurnError
78
} from "../plugins/codex/scripts/lib/codex.mjs";
89

10+
test("resolveErrorProgressPhase uses retrying for willRetry errors", () => {
11+
assert.equal(
12+
resolveErrorProgressPhase({
13+
willRetry: true,
14+
error: { message: "x" }
15+
}),
16+
"retrying"
17+
);
18+
assert.equal(resolveErrorProgressPhase({ error: { message: "x" } }), "failed");
19+
assert.equal(resolveErrorProgressPhase({}), "failed");
20+
});
21+
922
test("shouldStoreTurnError ignores retriable app-server errors", () => {
1023
assert.equal(
1124
shouldStoreTurnError({

0 commit comments

Comments
 (0)