From 37bbae623c2e9d72bf78ea528aca041aa15f8f78 Mon Sep 17 00:00:00 2001 From: "muspi-merol-review[bot]" <349105566+muspi-merol-review[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 23:21:00 +0000 Subject: [PATCH] Ignore non-object stderr when reading Codex events --- scripts/hosted-review.test.ts | 14 ++++++++++++++ scripts/run-review.sh | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/scripts/hosted-review.test.ts b/scripts/hosted-review.test.ts index 52c3fe5..a235e1a 100644 --- a/scripts/hosted-review.test.ts +++ b/scripts/hosted-review.test.ts @@ -81,6 +81,11 @@ await Bun.write(process.argv[process.argv.indexOf('--output-last-message')+1],JS await Bun.write(process.env.CODEX_HOME+'/auth.json',JSON.stringify({tokens:{refresh_token:'refreshed'}})); console.log(JSON.stringify({type:'thread.started',thread_id:'test-thread'})); console.log(JSON.stringify({type:'item.completed',item:{type:'agent_message',text:JSON.stringify(verdict)}})); +if(mode==='stderr-after-verdict') { + console.log(JSON.stringify({type:'turn.completed',usage:{input_tokens:17,output_tokens:3}})); + console.error('42'); + process.exitCode=1; +} `); const event = join(temp, "event.json"), config = join(temp, "config.toml"), auth = join(temp, "auth.json"); writeFileSync(event, JSON.stringify({ action: "opened", sender: {login:"author",type:"User"}, pull_request: {number:7,head:{sha:head}} })); @@ -313,6 +318,15 @@ test.each(["stale-verdict", "moved-on-retry", "moved-on-retry-error"])("hosted % expect(existsSync(join(setup.temp, "reviews"))).toBe(false); }); +test("a non-object stderr line leaves the recovered verdict, thread and usage intact", () => { + const setup = fixture("stderr-after-verdict"), result = setup.run(); + expect(result.exitCode).toBe(0); + expect(JSON.parse(readFileSync(join(setup.temp, "review.json"), "utf8")).conclusion).toBe("success"); + expect(readFileSync(join(setup.state, "last-thread-id"), "utf8").trim()).toBe("test-thread"); + expect(result.stdout.toString()).toContain("17 input, 0% cached ยท 3 output"); + expect(existsSync(join(setup.temp, "retried"))).toBe(false); +}); + test("an invalid verdict on the current head still retries and reports the failure", () => { const setup = fixture("invalid-verdict"), result = setup.run(); expect(result.exitCode).not.toBe(0); diff --git a/scripts/run-review.sh b/scripts/run-review.sh index a2043cb..aa5f7c1 100644 --- a/scripts/run-review.sh +++ b/scripts/run-review.sh @@ -150,10 +150,10 @@ if grep -Eq '^(Error: .*|.*"type":"(error|turn\.failed)".*)(unsupported_persiste fresh < /dev/null 2>&1 | tee "$RUNNER_TEMP/codex.jsonl" | log && ran=1 fi # A turn that fails after the review is complete, such as when the provider is at capacity for the next turn, still leaves the verdict it produced. -[ "$AGENT" = true ] || [ "$ran" = 1 ] || jq -Rrs '[split("\n")[] | fromjson? // empty | select(.type == "item.completed" and .item.type == "agent_message") | .item.text] | last // empty' \ +[ "$AGENT" = true ] || [ "$ran" = 1 ] || jq -Rrs '[split("\n")[] | fromjson? | objects | select(.type == "item.completed" and .item.type == "agent_message") | .item.text] | last // empty' \ < "$RUNNER_TEMP/codex.jsonl" > "$RUNNER_TEMP/review.json" # Recorded before the verdict check, so a fresh review can resume the thread it just started. -jq -Rrs '[split("\n")[] | fromjson? // empty | select(.type == "thread.started")] | first | .thread_id // empty' \ +jq -Rrs '[split("\n")[] | fromjson? | objects | select(.type == "thread.started")] | first | .thread_id // empty' \ < "$RUNNER_TEMP/codex.jsonl" > "$CODEX_HOME/last-thread-id" # A successfully resumed thread remembers the policy and pre-run compaction count in its next snapshot. if [ "$ran" = 1 ] && [ -s "$CODEX_HOME/last-thread-id" ]; then @@ -192,7 +192,7 @@ fi # The line and the turns the price reads come from one pass, so the price judges the same turns the counts describe. { read -r usage; read -r turns; } < <(jq -Rrs ' def h: if . >= 1000000 then "\(. / 100000 | round / 10)M" elif . >= 1000 then "\(. / 100 | round / 10)k" else "\(.)" end; - [split("\n")[] | fromjson? // empty | select(.type == "turn.completed") | .usage] as $turns + [split("\n")[] | fromjson? | objects | select(.type == "turn.completed") | .usage] as $turns | ($turns | map(.input_tokens) | add // 0) as $input | ($turns | map(.cached_input_tokens) | add // 0) as $cached | ($turns | map(.output_tokens) | add // 0) as $output