Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions apps/desktop/e2e/codex-transport.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { test, expect } from "@playwright/test";
import fs from "node:fs";
import path from "node:path";
import { launch, seedHome, tid } from "./support.js";
import { observeElectronErrors, recordElectronStderr } from "../test/support/electron-errors.js";

test("a Codex input pipe failure leaves Settings responsive and reports model discovery failure", async () => {
const { home } = seedHome({ default_backend: "codex" });
const statePath = path.join(home, "app/state.json"), state = JSON.parse(fs.readFileSync(statePath, "utf8"));
const cli = path.join(home, "closed-input-codex.cjs"), calls = path.join(home, "codex-methods.jsonl");
state.settings.codex_bin = cli;
for (const family of ["claude", "opencode", "mimo"]) state.settings[`${family}_bin`] = path.join(home, `missing-${family}`);
fs.writeFileSync(statePath, JSON.stringify(state));
fs.writeFileSync(cli, `#!${process.execPath}
const fs = require('node:fs');
if (process.argv.includes('--version')) { console.log('codex-cli 0.164.0'); process.exit(0); }
if (!process.argv.includes('app-server')) process.exit(2);
let line = ''; const byte = Buffer.alloc(1);
while (!line.endsWith('\\n')) {
try { if (!fs.readSync(0, byte, 0, 1, null)) process.exit(0); line += byte.toString(); }
catch (error) { if (error.code !== 'EAGAIN') throw error; Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 1); }
}
const request = JSON.parse(line);
fs.appendFileSync(${JSON.stringify(calls)}, JSON.stringify({method:request.method})+'\\n');
fs.closeSync(0);
console.log(JSON.stringify({id:request.id,result:{userAgent:'synthetic-closed-input'}}));
setInterval(() => {}, 1000);
`, { mode: 0o755 });
const { app, page } = await launch(home);
const stderr = path.join(test.info().outputDir, `electron-${app.process().pid}.stderr.log`);
recordElectronStderr(app.process(), test.info().outputDir);
await app.evaluate(observeElectronErrors);
try {
const result = await page.evaluate(() => window.modex!.invoke("models:list", { backend: "codex" }));
expect(result.models).toEqual([]);
expect(result.error).toContain("input transport failed");
await tid(page, "open-settings").click();
await expect(tid(page, "settings")).toBeVisible();
await page.getByRole("button", { name: "Coding CLIs", exact: true }).click();
await expect(page.getByText(/Account status unavailable · check in Codex CLI/)).toBeVisible();
await page.getByRole("button", { name: "General", exact: true }).click();
await page.screenshot({ path: test.info().outputPath("settings-after-input-failure.png"), animations: "disabled" });
await tid(page, "settings").getByRole("button", { name: "Cancel", exact: true }).click();
await expect(tid(page, "settings")).toHaveCount(0);
await tid(page, "open-settings").click();
await expect(tid(page, "settings")).toBeVisible();
const methods = fs.readFileSync(calls, "utf8").trim().split("\n").map(line => JSON.parse(line).method);
expect(methods.length).toBeGreaterThan(0);
expect(methods.every(method => method === "initialize")).toBe(true);
} finally { await app.close(); }
expect(fs.readFileSync(stderr, "utf8")).not.toContain("MODEX_E2E_MAIN_EXCEPTION");
});
344 changes: 261 additions & 83 deletions apps/desktop/src/main/engine/backends/codex.ts

Large diffs are not rendered by default.

551 changes: 551 additions & 0 deletions apps/desktop/test/codex-transport.test.ts

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions apps/desktop/test/human-requests-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,36 @@ test("offline image denial is acknowledged without generating an image", async (
assert.equal(fs.readdirSync(thread.cwd).some(name => name.endsWith(".png")), false);
} finally { await runner.dispose(); }
});


test("Codex pipe failure preserves the uncertain answer and blocks deletion until closure", async () => {
const proc = new FakeProcess();
codexAsking(proc, { questions }, "item/tool/requestUserInput", false);
const codex = new CodexBackend("codex", fakeSpawn(proc).spawn), h = await harness(codex);
const sent = h.runner.send(h.thread.id, "synthetic fixture");
let deleting: Promise<void> | undefined;
try {
await waitFor(() => h.runner.items(h.thread.id).some(i => i.kind === "question"));
const card = h.runner.items(h.thread.id).find(i => i.kind === "question")!;
proc.holdStdio = true; proc.ignore.add("SIGKILL");
proc.stdin._write = (_chunk, _encoding, callback) => callback(Object.assign(new Error("private-answer-fault"), { code: "EPIPE" }));
h.runner.answerQuestion(h.thread.id, card.id, { "q-env": ["staging"], "q-token": ["private-answer-token"] });
await waitFor(() => (h.runner.items(h.thread.id).find(i => i.id === card.id) as { delivery?: string }).delivery === "uncertain");
const saved = new Store(h.home).items(h.thread.id).find(i => i.id === card.id) as Extract<ThreadItem, { kind: "question" }>;
assert.equal(saved.delivery, "uncertain"); assert.deepEqual(saved.answers, { "q-env": ["staging"], "q-token": ["(hidden)"] });
assert.equal(saved.withdrawn, undefined);
let deleted = false;
deleting = h.runner.deleteThread(h.thread.id).then(() => { deleted = true; });
await new Promise<void>(resolve => setImmediate(resolve)); h.runner.stop(h.thread.id);
await new Promise<void>(resolve => setImmediate(resolve));
assert.equal(deleted, false); assert.ok(h.store.thread(h.thread.id));
proc.ignore.clear(); proc.close(null, "SIGKILL");
await new Promise<void>(resolve => setImmediate(resolve)); assert.equal(deleted, false);
proc.releaseStdio(); await sent; await deleting;
assert.equal(h.store.thread(h.thread.id), undefined);
assert.equal(JSON.stringify(h.events).includes("private-answer-token"), false);
} finally {
proc.ignore.clear(); proc.close(null, "SIGKILL"); proc.releaseStdio();
await sent; await deleting; await h.runner.dispose(); await codex.dispose();
}
});
16 changes: 15 additions & 1 deletion apps/desktop/test/task-context-checks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ for (const boundary of ["both", "missing-start", "late-start", "outside", "unkno
if (boundary === "symlink-cwd" || boundary === "symlink-cd" || boundary === "symlink-parent") fs.symlinkSync(tmpdir("modex-check-outside-"), path.join(project.path, "external"), "dir");
if (boundary === "cd-inside") fs.mkdirSync(path.join(project.path, "inside"));
let captureCalls = 0, finishStart: (() => void) | undefined;
const capture = new TaskContextCapture();
let scopeReads = 0;
const selectionReads = new Set<string>();
const selectedPaths = new Set(Array.from({ length: boundary === "large-confirmation" ? 1001 : 0 }, (_, i) => `selected-${i}.ts`));
// This case exercises 1,001 synthetic receipts, not OS metadata latency. Real
// canonical scope and its unchanged deadline are covered in task-context-scope.
const capture = new TaskContextCapture(boundary === "large-confirmation" ? { reader: async (cwd, relative) => {
assert.equal(cwd, project.path); assert.ok(selectedPaths.has(relative));
assert.equal(selectionReads.has(relative), false); selectionReads.add(relative);
return { state: "unavailable", reason: "unreadable" };
}, scopeReader: async (cwd, directory) => {
assert.equal(cwd, project.path); assert.equal(directory, project.path);
scopeReads++; return "project";
} } : {});
capture.capture = async (_cwd, targets, source, phase) => {
captureCalls++;
if (boundary === "late-start" && phase === "check-start-observed") await new Promise<void>(resolve => { finishStart = resolve; });
Expand All @@ -41,6 +53,7 @@ for (const boundary of ["both", "missing-start", "late-start", "outside", "unkno
const thread = await runner.createThread(project.id, { backend: "codex", auto: false });
const opened = runner.openContextDraft({ kind: "thread", threadId: thread.id });
const selected = await runner.selectTaskContext(opened, boundary === "large-confirmation" ? Array.from({ length: 1001 }, (_, i) => ({ kind: "file" as const, path: `selected-${i}.ts` })) : [{ kind: "file", path: "README.md" }]);
if (boundary === "large-confirmation") assert.equal(selectionReads.size, 1001, "selection must retain every synthetic missing-file receipt without OS reads");
await runner.send(thread.id, "Check", [], "desktop", selected.binding);
const items = runner.items(thread.id), user = items.find(item => item.kind === "user")!;
assert.ok(user.kind === "user" && user.contextEvidence);
Expand All @@ -56,6 +69,7 @@ for (const boundary of ["both", "missing-start", "late-start", "outside", "unkno
assert.equal(check.eventIds.length, 2); assert.equal(new Set(check.eventIds).size, 2);
assert.equal(check.exitCode, 0); assert.equal(check.relevance, "unestablished");
assert.equal(check.scope, boundary === "outside" || boundary === "cd-outside" || boundary === "symlink-cwd" || boundary === "symlink-cd" || boundary === "symlink-parent" ? "outside" : boundary === "unknown-cwd" || boundary === "relative-cwd" || boundary === "cwd-flag" ? "unknown" : "project");
if (boundary === "large-confirmation") assert.equal(scopeReads, 2, "both native boundaries must establish scope for the intended project");
assert.ok(handlers.has("task:context"), "existing task context needs a scoped read command");
assert.ok(handlers.has("task:check-confirm"), "check relevance requires an explicit main-owned confirmation command");
const confirm = (_thread: string, _turn: string, revision: number, item: string, refs: string[]) => handlers.get("task:check-confirm")!({ threadId: _thread, turnId: _turn, expectedRevision: revision, itemId: item, refIds: refs }) as TaskContextEvidence;
Expand Down
27 changes: 27 additions & 0 deletions docs/reviews/2026-11-14-codex-input-transport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Codex input transport and generation ownership

## Observed failure

PR #525's first merge-queue run `43565223289` tested `81fec064c5ef70ecd8dd827de3811871d2ef1dd6` and failed the Jev contrast Settings-click case. Retained Electron stderr contains an uncaught `write EPIPE` from Codex stdin; the process sample shows `NSAlert runModal`. Injected Writable failures and real subprocess pipes reproduced the uncaught transport error. These observations establish the transport defect, while the original queue timing remains unexplained. The PR remains unmerged and has not been requeued for this repair.

## Candidate behavior

Signed source commits `46764fe9060661f156b30f6e5a764aa57e61f9b9` and `860ecc78c4fbec0cd28d8465e0fa93b5d6567282`, plus this follow-up, install a persistent stdin error handler, settle pending RPCs and initialization write receipts, and report a fixed body-free transport failure with a bounded errno. A failed generation remains owned until its child closes. Broker delivery promises drain before request withdrawal, preserving an accepted answer as uncertain when delivery fails. Stop, disposal and late events cannot release or complete the faulted attempt early.

Every asynchronous read, write, coding setup and terminal-cleanup operation retains its server lease. Health keeps that lease through its outer race before publishing account status. Stale-auth recovery carries the attempt owner to the actual restart/replay decision, prepares only its captured generation before reporting callbacks, and starts no coding turn if reporting fails. Cleanup detaches the old request registries before withdrawal callbacks can initialize a replacement. A latest-issued generation guard prevents old recovery permission returning after an intervening server starts and closes; ordinary recovery after natural closure without a replacement retains its single retry.

## Validation and limits

Meaningful failing controls precede the fixes: queued initialization and post-ready work crossing generations; stale-auth replay after replacement or input failure; old health publication after replacement; replacement initialization rejected by an old withdrawal callback; and old recovery becoming eligible after an intervening generation closed. The no-replacement natural-close control already passed before the latest-issued guard. The first Node fixture using `process.stdin.destroy()` was inconclusive and is retained separately; the valid real-pipe fixture uses synchronous fd0 reads without constructing Node's special stdin stream.

The final affected suite passes 136 cases with 13 explicit opt-in local CLI/live skips and zero failures or cancellations. The actual private Electron regression passes once without retries: a real synthetic Node pipe fails, discovery reports the fixed error, and Settings remains responsive. Main compilation passes. Scoped agent source review found no remaining Critical or Important findings; the reviewer ran no tests or app sessions. Full local qualification, hosted checks, protected queue and independent actual-merge proof remain required. The earlier full run on `46764fe` passed build, workspace typechecks and 2,861 unit cases with 36 skips, then stopped at a stage boundary before E2E because later generation findings superseded it. That run is not a full qualification pass.

Full qualification 2 on signed `017fb244bae02d8c73eb31dfb95dc64e6228cdeb` passed build and workspace typechecks, then stopped in units: 230 worktree and 16 core passes; desktop had 2,598 passes, 30 skips and one failure. The synthetic 1,001-receipt confirmation fixture expected project scope but received unknown scope; remaining unit groups and all E2E were not reached. An isolated diagnostic passed with scope reads below the two-second budget. A controlled 2.1-second OS metadata delay reproduced the exact assertion while the unchanged production deadline returned unknown, consistent with budget expiry in the original loaded run; that original deadline firing was not directly instrumented. A scope-only fixture correction passed 18 focused cases but still failed the slow-metadata control: human selection uses `captureSelection`, whose independent file reader retained the shared scheduler slots while OS reads were delayed. The completed fixture supplies deterministic missing-file results for exactly 1,001 validated unique paths as well as scope metadata for the intended project. It retains the production scheduler and all existing confirmation, verification and saved-state assertions, adding exact path/count and two-scope-read assertions. Main compilation and all 18 context/scope cases pass. The identical 2.1-second slow-realpath control now passes, records zero realpath calls and retains both project-scope results. Other real-directory cases and the separate canonical-path, symlink and deadline tests remain unchanged. Scoped agent source review reports no remaining Critical or Important issue; fresh full qualification remains pending.

## Local qualification on `2069430`

Signed `2069430bff9378843de83038fbcb46cc67f540d4`, tree `bd28d85487a95dabed27fac7e160145d7b89427c`, passed the full build and workspace typechecks. Across its frozen unit groups there are 2,891 passes, 36 explicit skips and one cancellation. The full `pnpm test` invocation stopped when the unchanged Claude-only unconfirmed-stop/worktree test reached its six-second test timeout; the remaining unit groups were then run separately. An isolated diagnostic of that unchanged case passed in 1.43 seconds with all ownership assertions and the six-second bound intact. Its full-run timeout cause is unproven. The Claude backend, runner and test files match main; this does not substitute the diagnostic for a passing full invocation.

Desktop E2E completed with 546 passes, 17 explicit skips, one failure and no retries. The persistence case retained size 960×620 but reopened at 1157,1148 instead of 40,60, matching the position mismatch retained from the earlier CF-7 run on this host; its cause remains unproven. The window-state implementation, main window setup, persistence test and launch helper match main. No assertion, retry setting or Spaces preference changed. The actual Codex pipe-failure regression and both Jev Code Review contrast cases passed in this sequence. Site E2E passed all eight cases and web E2E all four when run separately after the desktop failure. All tracked source bytes stayed unchanged through these runs. The desktop archive contains 192 files and passed ZIP CRC and SHA-256 verification. Local full qualification is not green; fresh hosted qualification and the protected merge queue must validate the candidate before delivery.

Evidence lives outside disposable worktrees in `/Users/buns/Documents/Codex/2026-11-11/modex-closeout/`: the original queue artifacts and diagnosis, all first-failure logs, `codex-consumer-final-source-review.json`, `codex-latest-issued-generation-red.log`, `codex-latest-issued-generation-green-focused.log` and the private Electron results. The app check uses a synthetic Node peer in a private development profile and performs no inference. It does not establish installed-release, live-provider, physical-descendant, device or human acceptance, and no open-issue checkbox is changed on this evidence alone.
Loading
Loading