-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix: fail loud when a write task lands zero workspace writes #532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hopp2it
wants to merge
1
commit into
openai:main
Choose a base branch
from
hopp2it:fix/write-task-zero-writes-fail-loud
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import fs from "node:fs"; | ||
| import path from "node:path"; | ||
| import test from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
| import { fileURLToPath } from "node:url"; | ||
|
|
||
| import { buildEnv, installFakeCodex } from "./fake-codex-fixture.mjs"; | ||
| import { initGitRepo, makeTempDir, run } from "./helpers.mjs"; | ||
| import { resolveStateDir } from "../plugins/codex/scripts/lib/state.mjs"; | ||
|
|
||
| const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); | ||
| const SCRIPT = path.join(ROOT, "plugins", "codex", "scripts", "codex-companion.mjs"); | ||
|
|
||
| function setupRepo() { | ||
| const repo = makeTempDir(); | ||
| initGitRepo(repo); | ||
| fs.writeFileSync(path.join(repo, "README.md"), "hello\n"); | ||
| run("git", ["add", "README.md"], { cwd: repo }); | ||
| run("git", ["commit", "-m", "init"], { cwd: repo }); | ||
| return repo; | ||
| } | ||
|
|
||
| function readLatestJob(workspace) { | ||
| const stateDir = resolveStateDir(workspace); | ||
| const state = JSON.parse(fs.readFileSync(path.join(stateDir, "state.json"), "utf8")); | ||
| const jobFile = path.join(stateDir, "jobs", `${state.jobs[0].id}.json`); | ||
| return JSON.parse(fs.readFileSync(jobFile, "utf8")); | ||
| } | ||
|
|
||
| test("write task that lands zero workspace writes finishes failed with a zero-write notice", () => { | ||
| const repo = setupRepo(); | ||
| const binDir = makeTempDir(); | ||
| installFakeCodex(binDir); | ||
|
|
||
| const result = run("node", [SCRIPT, "task", "--write", "please implement the fix"], { | ||
| cwd: repo, | ||
| env: buildEnv(binDir) | ||
| }); | ||
|
|
||
| assert.notEqual(result.status, 0, "zero-write write task should exit non-zero"); | ||
| assert.match(result.stdout, /zero workspace writes/i); | ||
| const job = readLatestJob(repo); | ||
| assert.equal(job.status, "failed"); | ||
| assert.equal(job.result.degraded, "zero-writes"); | ||
| }); | ||
|
|
||
| test("write task with apply_patch file changes stays completed", () => { | ||
| const repo = setupRepo(); | ||
| const binDir = makeTempDir(); | ||
| installFakeCodex(binDir, "task-write-file-change"); | ||
|
|
||
| const result = run("node", [SCRIPT, "task", "--write", "please implement the fix"], { | ||
| cwd: repo, | ||
| env: buildEnv(binDir) | ||
| }); | ||
|
|
||
| assert.equal(result.status, 0, result.stderr); | ||
| const job = readLatestJob(repo); | ||
| assert.equal(job.status, "completed"); | ||
| assert.equal(job.result.degraded ?? null, null); | ||
| }); | ||
|
|
||
| test("write task with shell-only writes stays completed", () => { | ||
| const repo = setupRepo(); | ||
| const binDir = makeTempDir(); | ||
| installFakeCodex(binDir, "task-shell-write"); | ||
|
|
||
| const result = run("node", [SCRIPT, "task", "--write", "please implement the fix"], { | ||
| cwd: repo, | ||
| env: buildEnv(binDir) | ||
| }); | ||
|
|
||
| assert.equal(result.status, 0, result.stderr); | ||
| assert.ok(fs.existsSync(path.join(repo, "shell-write.txt")), "fixture should have written into the workspace"); | ||
| const job = readLatestJob(repo); | ||
| assert.equal(job.status, "completed"); | ||
| assert.equal(job.result.degraded ?? null, null); | ||
| }); | ||
|
|
||
| test("write task that only modifies an already-dirty tracked file stays completed", () => { | ||
| const repo = setupRepo(); | ||
| fs.appendFileSync(path.join(repo, "README.md"), "dirty before task\n"); | ||
| const binDir = makeTempDir(); | ||
| installFakeCodex(binDir, "task-shell-write-existing"); | ||
|
|
||
| const result = run("node", [SCRIPT, "task", "--write", "please implement the fix"], { | ||
| cwd: repo, | ||
| env: buildEnv(binDir) | ||
| }); | ||
|
|
||
| assert.equal(result.status, 0, result.stderr); | ||
| const job = readLatestJob(repo); | ||
| assert.equal(job.status, "completed"); | ||
| assert.equal(job.result.degraded ?? null, null); | ||
| }); | ||
|
|
||
| test("read-only task with zero writes stays completed", () => { | ||
| const repo = setupRepo(); | ||
| const binDir = makeTempDir(); | ||
| installFakeCodex(binDir); | ||
|
|
||
| const result = run("node", [SCRIPT, "task", "summarize the repo"], { | ||
| cwd: repo, | ||
| env: buildEnv(binDir) | ||
| }); | ||
|
|
||
| assert.equal(result.status, 0, result.stderr); | ||
| const job = readLatestJob(repo); | ||
| assert.equal(job.status, "completed"); | ||
| assert.equal(job.result.degraded ?? null, null); | ||
| }); | ||
|
|
||
| test("write task in a non-git workspace skips zero-write detection", () => { | ||
| const workspace = makeTempDir(); | ||
| const binDir = makeTempDir(); | ||
| installFakeCodex(binDir); | ||
|
|
||
| const result = run("node", [SCRIPT, "task", "--write", "please implement the fix"], { | ||
| cwd: workspace, | ||
| env: buildEnv(binDir) | ||
| }); | ||
|
|
||
| assert.equal(result.status, 0, result.stderr); | ||
| const job = readLatestJob(workspace); | ||
| assert.equal(job.status, "completed"); | ||
| assert.equal(job.result.degraded ?? null, null); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For degraded write tasks that finish in the background, the follow-up path is usually
/codex:result; howeverrenderStoredJobResult()prefersstoredJob.result.rawOutputoverstoredJob.rendered, so adding the warning only torenderedmeans that command prints the model's original success-sounding final response with no zero-write banner even though the job is marked failed. This makes the new "fail loud" behavior disappear outside the initial foreground output.Useful? React with 👍 / 👎.