From 5ac3a111cef16698cd523852e142865f2a659e63 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sat, 26 Sep 2026 21:22:45 -0700 Subject: [PATCH 01/40] docs(plan): OpenCode agents start under load (#1355) Co-Authored-By: Claude Opus 5.5 --- ...09-27-opencode-serve-startup-under-load.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 docs/plans/2026-09-27-opencode-serve-startup-under-load.md diff --git a/docs/plans/2026-09-27-opencode-serve-startup-under-load.md b/docs/plans/2026-09-27-opencode-serve-startup-under-load.md new file mode 100644 index 000000000..d5bc0297d --- /dev/null +++ b/docs/plans/2026-09-27-opencode-serve-startup-under-load.md @@ -0,0 +1,25 @@ +# OpenCode agents start under load: the serve readiness wait measures the right thing (#1355) + +## Problem +`orchestration_create_agent` with kind `opencode` failed three times in about an hour on 2026-09-26/27, from three workers, with "Timed out waiting for …/opencode serve to report its URL". I also hit it on #1352's reviewer c. The load average was 40–70 each time. + +The only deadline on this path is `SpawnedServer`'s `startupTimeoutMs`, a package default of 10 s. The app never passes one: `opencodeSession.ts` builds `OpencodeHeadless` without it, and nothing in the app wraps `headless.start()` in a deadline of its own. + +## Evidence (reproduced on the real bundled binary, OpenCode 1.18.31) +Measured as time to the listen line, with `scratchpad/octime.mjs`: it spawns `opencode serve --hostname 127.0.0.1 --port 0` and times stdout. +- **Idle machine** (load average about 4): 0.57 s, 0.73 s, 0.86 s. +- **Under contention:** 16 CPU burners at nice 10, on a machine other workers were already loading: 43.1 s, 16.7 s, 18.3 s. **Every run became ready.** +- **Conclusion:** the server is healthy but CPU-starved. A fixed 10 s wall-clock deadline sized for an idle machine kills it. + +A hung server (alive, never listening) has not been observed. The existing exit path already fails fast when the process dies (`serve exited before readiness`). + +## Decision (defaults) +- **The app sets the readiness wait to 120 s** by passing `startupTimeoutMs` to `OpencodeHeadless`. The app spawns and owns the process, and the package takes the value as an option, so the fix belongs in the app and needs no package change. + - **Why 120 s:** it is about 3× the worst measured healthy start under load (43 s). It still bounds an alive-but-never-listening server, so the ceiling only bites on a real hang. + - A dead server still fails at once through the exit path, so a crash is not slowed down. +- **Considered and deferred:** a CPU-progress watchdog (fail when the child's CPU time stops rising). It would tell a hang from starvation sooner, but it needs a per-platform CPU probe of a child process (`ps` on macOS/Linux, something else on Windows) and would itself be slow under load. The fixed ceiling covers the observed failure; the watchdog is only worth building if a real hang is recorded. +- **Not the same cause:** #1009 (the opencode-terminal live suite waits for a permission condition) is a different wait. + +## Tests +- **`opencodeSession`:** the spawned headless gets the load-tolerant `startupTimeoutMs`. A test double stands in for `opencode-headless`'s constructor, the true edge here. The package's `SpawnedServer.test.ts` already covers the option's behaviour. +- **Real mechanism:** an OpenCode session started against a stub `opencode` binary that reports its URL after 11 s (past the old deadline) reaches the server instead of rejecting. From ce6482d79d04b82fd3b0458d055b602837ca21ab Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sat, 26 Sep 2026 22:00:39 -0700 Subject: [PATCH 02/40] fix(opencode): wait out a slow but healthy serve start instead of killing it at 10 s The package's serve readiness default (10 s) was sized for an idle machine. Measured on the bundled binary, a healthy server reported its URL in 0.6-0.9 s idle but 16.7-43.1 s under load, so orchestration's OpenCode agents failed to spawn. The app owns the process and now passes a 120 s wait; a server that dies still fails at once. Refs #1355 (the orchestration bridge deadline is #1370) Co-Authored-By: Claude Opus 5.5 --- .../opencodeServeStartup.system.test.ts | 41 +++++++++++++++++++ .../runtime/opencodeSession.readiness.test.ts | 17 +++++++- .../opencode/runtime/opencodeSession.ts | 22 ++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 src/providers/opencode/runtime/opencodeServeStartup.system.test.ts diff --git a/src/providers/opencode/runtime/opencodeServeStartup.system.test.ts b/src/providers/opencode/runtime/opencodeServeStartup.system.test.ts new file mode 100644 index 000000000..f06b98622 --- /dev/null +++ b/src/providers/opencode/runtime/opencodeServeStartup.system.test.ts @@ -0,0 +1,41 @@ +import { chmodSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { join } from 'node:path' + +import { afterEach, expect, it } from 'vitest' +import { SpawnedServer } from 'opencode-headless' + +import { OPENCODE_SERVE_STARTUP_TIMEOUT_MS } from './opencodeSession.js' + +// #1355, on the real readiness mechanism: SpawnedServer spawns a real child +// and waits for its listen line. The stub stands in for a CPU-starved but +// healthy `opencode serve` (the real binary took 16.7-43.1 s under load, +// 0.6-0.9 s idle): it prints the same listen line OpenCode prints, 11 s late. +// Under the package's 10 s default that start was killed; under the app's +// wait it succeeds. +const dirs: string[] = [] +afterEach(() => { for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true }) }) + +function slowServe(delayMs: number): string { + const dir = mkdtempSync(join(tmpdir(), 'opencode-slow-serve-')) + dirs.push(dir) + const bin = join(dir, 'opencode') + writeFileSync(bin, `#!/usr/bin/env node +setTimeout(() => { console.log('opencode server listening on http://127.0.0.1:4096') }, ${delayMs}) +setInterval(() => {}, 1000) +`) + chmodSync(bin, 0o755) + return bin +} + +it('waits out a slow but healthy serve start', async () => { + const server = new SpawnedServer({ binary: slowServe(11_000), cwd: tmpdir(), startupTimeoutMs: OPENCODE_SERVE_STARTUP_TIMEOUT_MS }) + const info = await server.start() + expect(info.url).toBe('http://127.0.0.1:4096') + await server.stop() +}, 30_000) + +it('is what the package default killed', async () => { + const server = new SpawnedServer({ binary: slowServe(11_000), cwd: tmpdir() }) + await expect(server.start()).rejects.toThrow('to report its URL') +}, 30_000) diff --git a/src/providers/opencode/runtime/opencodeSession.readiness.test.ts b/src/providers/opencode/runtime/opencodeSession.readiness.test.ts index 1d4a29765..be5304a18 100644 --- a/src/providers/opencode/runtime/opencodeSession.readiness.test.ts +++ b/src/providers/opencode/runtime/opencodeSession.readiness.test.ts @@ -3,12 +3,17 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' const headlessControl = vi.hoisted(() => ({ exitDuringStart: false, stop: vi.fn(async (): Promise => {}), + options: [] as Array>, })) vi.mock('opencode-headless', async () => { const { EventEmitter } = await import('node:events') return { OpencodeHeadless: class FakeOpencodeHeadless extends EventEmitter { + constructor(options: Record) { + super() + headlessControl.options.push(options) + } readonly screen = new EventEmitter() readonly committed = new EventEmitter() readonly semantic = new EventEmitter() @@ -22,7 +27,7 @@ vi.mock('opencode-headless', async () => { } }) -import { OpencodeSession } from './opencodeSession.js' +import { OPENCODE_SERVE_STARTUP_TIMEOUT_MS, OpencodeSession } from './opencodeSession.js' describe('OpencodeSession composer readiness', () => { beforeEach(() => { @@ -57,4 +62,14 @@ describe('OpencodeSession composer readiness', () => { expect(started).not.toHaveBeenCalled() expect(headlessControl.stop).toHaveBeenCalledTimes(1) }) + + // #1355: the package's serve readiness default (10 s) was sized for an idle + // machine; under load a healthy server took 16.7-43.1 s to report its URL + // (plan evidence). The app owns the process and passes its own wait. + it('gives the spawned server the load-tolerant startup wait', async () => { + headlessControl.options.length = 0 + await new OpencodeSession({ cwd: '/tmp/project' }).start() + expect(headlessControl.options.at(-1)).toMatchObject({ startupTimeoutMs: OPENCODE_SERVE_STARTUP_TIMEOUT_MS }) + expect(OPENCODE_SERVE_STARTUP_TIMEOUT_MS).toBeGreaterThan(43_100) + }) }) diff --git a/src/providers/opencode/runtime/opencodeSession.ts b/src/providers/opencode/runtime/opencodeSession.ts index 5cc864755..98b43bb3c 100644 --- a/src/providers/opencode/runtime/opencodeSession.ts +++ b/src/providers/opencode/runtime/opencodeSession.ts @@ -114,6 +114,26 @@ export interface OpencodeSession { ): boolean } +/** + * How long a spawned `opencode serve` may take to report its URL (#1355). + * + * WHY the app sets it rather than taking the package's 10 s default: that + * default was sized for an idle machine. Measured on the bundled binary + * (OpenCode 1.18.31), the server reports its URL in 0.6-0.9 s idle, but + * 16.7 s, 18.3 s and 43.1 s under CPU contention like a worker fleet's + * (plan: docs/plans/2026-09-27-opencode-serve-startup-under-load.md), and + * every one of those starts was healthy. The fixed deadline killed healthy + * servers, so orchestration's OpenCode reviewers failed to spawn under load. + * + * 120 s is about 3x the worst healthy start measured. The ceiling only has to + * bound a server that stays alive but never listens, a hang no recording has + * shown. A server that DIES still fails at once through the package's exit + * path, so a real crash is not slowed down. A CPU-progress watchdog would tell + * a hang from starvation sooner; it needs a per-platform child CPU probe, and + * is only worth it if a real hang is ever recorded. + */ +export const OPENCODE_SERVE_STARTUP_TIMEOUT_MS = 120_000 + export class OpencodeSession extends EventEmitter implements AgentSession { private headless: OpencodeHeadless | null = null private exited = false @@ -172,6 +192,8 @@ export class OpencodeSession extends EventEmitter implements AgentSession { cwd: this.cwd, binary: this.binary, env, + // See OPENCODE_SERVE_STARTUP_TIMEOUT_MS (#1355). + startupTimeoutMs: OPENCODE_SERVE_STARTUP_TIMEOUT_MS, // Resume replays that session's committed history inside start() // (publishSessionMessages), which is why every listener below is // attached BEFORE start() is awaited — otherwise the replayed From bdfa24b64e110baeea596b284ab80e3aa5f5b331 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sat, 26 Sep 2026 23:37:02 -0700 Subject: [PATCH 03/40] test(opencode): pin the package's startup-wait forwarding and the constant's margin #1367 review a: dropping OpencodeHeadless's forwarding of startupTimeoutMs, or a 44 s constant, left every test green. The orchestration bridge's own 30 s create-agent deadline is filed as #1370; this PR becomes Refs #1355. Co-Authored-By: Claude Opus 5.5 --- ...-09-27-opencode-serve-startup-under-load.md | 5 +++++ .../opencodeServeStartup.system.test.ts | 18 +++++++++++++++++- .../runtime/opencodeSession.readiness.test.ts | 5 ++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/plans/2026-09-27-opencode-serve-startup-under-load.md b/docs/plans/2026-09-27-opencode-serve-startup-under-load.md index d5bc0297d..e57be2fca 100644 --- a/docs/plans/2026-09-27-opencode-serve-startup-under-load.md +++ b/docs/plans/2026-09-27-opencode-serve-startup-under-load.md @@ -23,3 +23,8 @@ A hung server (alive, never listening) has not been observed. The existing exit ## Tests - **`opencodeSession`:** the spawned headless gets the load-tolerant `startupTimeoutMs`. A test double stands in for `opencode-headless`'s constructor, the true edge here. The package's `SpawnedServer.test.ts` already covers the option's behaviour. - **Real mechanism:** an OpenCode session started against a stub `opencode` binary that reports its URL after 11 s (past the old deadline) reaches the server instead of rejecting. + +## Round 1 review decisions (#1367) +- **a (major): orchestration still loses a start slower than 30 s.** The bridge rejects `create-agent` at 30 s with an unknown outcome. The late-adopted child never gets its bootstrap prompt. This is the orchestration bridge's own deadline, pre-existing and shared by every provider, so it is filed as #1370 and not changed here. Changing it means choosing between late bootstrap delivery and MCP-client timeouts. With this PR, starts that finish between 10 and 30 s now succeed through orchestration too; two of the three recorded contended starts took 16.7 and 18.3 s. So this PR is `Refs #1355`, and #1355 stays open until #1370 lands. +- **a (minor): the package's forwarding was untested.** A system test now goes through `OpencodeHeadless` (`resolveServerUrl` → `SpawnedServer`) with the app's option, and dropping the forwarding fails it. +- **a (surviving mutant): 44 s passed the margin check.** The test now requires at least twice the worst healthy start measured. diff --git a/src/providers/opencode/runtime/opencodeServeStartup.system.test.ts b/src/providers/opencode/runtime/opencodeServeStartup.system.test.ts index f06b98622..fc6d93574 100644 --- a/src/providers/opencode/runtime/opencodeServeStartup.system.test.ts +++ b/src/providers/opencode/runtime/opencodeServeStartup.system.test.ts @@ -3,7 +3,7 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, expect, it } from 'vitest' -import { SpawnedServer } from 'opencode-headless' +import { OpencodeHeadless, SpawnedServer } from 'opencode-headless' import { OPENCODE_SERVE_STARTUP_TIMEOUT_MS } from './opencodeSession.js' @@ -39,3 +39,19 @@ it('is what the package default killed', async () => { const server = new SpawnedServer({ binary: slowServe(11_000), cwd: tmpdir() }) await expect(server.start()).rejects.toThrow('to report its URL') }, 30_000) + +// #1367 review a (surviving mutation): the app hands the wait to +// OpencodeHeadless, not to SpawnedServer, so the package's forwarding is part +// of the fix. Dropping it put structured panes back on the 10 s default while +// both tests above stayed green. This goes through the same package method a +// structured start uses (resolveServerUrl -> SpawnedServer) with the app's +// option, and stops before the SDK connects (the stub serves no API). +it('forwards the wait through OpencodeHeadless to the spawned serve', async () => { + const headless = new OpencodeHeadless({ binary: slowServe(11_000), cwd: tmpdir(), startupTimeoutMs: OPENCODE_SERVE_STARTUP_TIMEOUT_MS }) + try { + const url = await (headless as unknown as { resolveServerUrl(): Promise }).resolveServerUrl() + expect(url).toBe('http://127.0.0.1:4096') + } finally { + await headless.stop() + } +}, 30_000) diff --git a/src/providers/opencode/runtime/opencodeSession.readiness.test.ts b/src/providers/opencode/runtime/opencodeSession.readiness.test.ts index be5304a18..7e92e5a4b 100644 --- a/src/providers/opencode/runtime/opencodeSession.readiness.test.ts +++ b/src/providers/opencode/runtime/opencodeSession.readiness.test.ts @@ -70,6 +70,9 @@ describe('OpencodeSession composer readiness', () => { headlessControl.options.length = 0 await new OpencodeSession({ cwd: '/tmp/project' }).start() expect(headlessControl.options.at(-1)).toMatchObject({ startupTimeoutMs: OPENCODE_SERVE_STARTUP_TIMEOUT_MS }) - expect(OPENCODE_SERVE_STARTUP_TIMEOUT_MS).toBeGreaterThan(43_100) + // At least twice the worst healthy start measured (43.1 s), the margin the + // constant's comment claims; merely above it (#1367 review a: 44 s passed) + // would fail the next slightly slower machine. + expect(OPENCODE_SERVE_STARTUP_TIMEOUT_MS).toBeGreaterThanOrEqual(2 * 43_100) }) }) From 38ef62003c140cfabe7b2b5c25b34e1e44ffd1f0 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sat, 26 Sep 2026 23:56:01 -0700 Subject: [PATCH 04/40] test(opencode): the slow-serve tests wait as long as the app does #1367 review b: a fixed 30 s test budget could fail on a loaded runner while the app (120 s) would still be waiting. The positive cases now follow OPENCODE_SERVE_STARTUP_TIMEOUT_MS. Co-Authored-By: Claude Opus 5.5 --- .../runtime/opencodeServeStartup.system.test.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/providers/opencode/runtime/opencodeServeStartup.system.test.ts b/src/providers/opencode/runtime/opencodeServeStartup.system.test.ts index fc6d93574..79da3f06f 100644 --- a/src/providers/opencode/runtime/opencodeServeStartup.system.test.ts +++ b/src/providers/opencode/runtime/opencodeServeStartup.system.test.ts @@ -16,6 +16,12 @@ import { OPENCODE_SERVE_STARTUP_TIMEOUT_MS } from './opencodeSession.js' const dirs: string[] = [] afterEach(() => { for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true }) }) +// WHY the positive cases' test budget follows the product deadline (#1367 +// review b): they assert "the app keeps waiting", so the test must never give +// up before the app would. A fixed 30 s let a loaded runner fail them while +// SpawnedServer would still have waited; this only fails when the app would. +const WAITS_LIKE_THE_APP = OPENCODE_SERVE_STARTUP_TIMEOUT_MS + 10_000 + function slowServe(delayMs: number): string { const dir = mkdtempSync(join(tmpdir(), 'opencode-slow-serve-')) dirs.push(dir) @@ -33,7 +39,7 @@ it('waits out a slow but healthy serve start', async () => { const info = await server.start() expect(info.url).toBe('http://127.0.0.1:4096') await server.stop() -}, 30_000) +}, WAITS_LIKE_THE_APP) it('is what the package default killed', async () => { const server = new SpawnedServer({ binary: slowServe(11_000), cwd: tmpdir() }) @@ -54,4 +60,4 @@ it('forwards the wait through OpencodeHeadless to the spawned serve', async () = } finally { await headless.stop() } -}, 30_000) +}, WAITS_LIKE_THE_APP) From 8f7a5ec606566b25d882f7274d9adb1f7077ba99 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 00:13:07 -0700 Subject: [PATCH 05/40] test(opencode): pin the startup wait's ceiling and the rejected-start rollback #1367 review c: a 1_200_000 constant and removing the rollback's headless.stop() both left every test green. Co-Authored-By: Claude Opus 5.5 --- .../runtime/opencodeSession.readiness.test.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/providers/opencode/runtime/opencodeSession.readiness.test.ts b/src/providers/opencode/runtime/opencodeSession.readiness.test.ts index 7e92e5a4b..e639e6d2e 100644 --- a/src/providers/opencode/runtime/opencodeSession.readiness.test.ts +++ b/src/providers/opencode/runtime/opencodeSession.readiness.test.ts @@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' const headlessControl = vi.hoisted(() => ({ exitDuringStart: false, + rejectStart: null as Error | null, stop: vi.fn(async (): Promise => {}), options: [] as Array>, })) @@ -19,6 +20,7 @@ vi.mock('opencode-headless', async () => { readonly semantic = new EventEmitter() async start(): Promise { if (headlessControl.exitDuringStart) this.emit('exit', { exitCode: 17 }) + if (headlessControl.rejectStart) throw headlessControl.rejectStart } async stop(): Promise { await headlessControl.stop() @@ -32,6 +34,7 @@ import { OPENCODE_SERVE_STARTUP_TIMEOUT_MS, OpencodeSession } from './opencodeSe describe('OpencodeSession composer readiness', () => { beforeEach(() => { headlessControl.exitDuringStart = false + headlessControl.rejectStart = null headlessControl.stop.mockClear() }) @@ -74,5 +77,20 @@ describe('OpencodeSession composer readiness', () => { // constant's comment claims; merely above it (#1367 review a: 44 s passed) // would fail the next slightly slower machine. expect(OPENCODE_SERVE_STARTUP_TIMEOUT_MS).toBeGreaterThanOrEqual(2 * 43_100) + // And at most about four times it (#1367 review c): the wait is also how + // long a serve that stays alive but never listens holds the pane on + // "starting". A stray zero (1_200_000) would make that twenty minutes. + expect(OPENCODE_SERVE_STARTUP_TIMEOUT_MS).toBeLessThanOrEqual(4 * 43_100) + }) + + // #1367 review c: a start that rejects after the server is already up (a + // resume whose history replay fails) must stop the server it spawned. With + // the longer wait this rollback is where every rejected start ends, and + // without it a live `opencode serve` child outlives the pane that owned it. + it('stops the server when startup rejects', async () => { + headlessControl.rejectStart = new Error('history replay failed') + const session = new OpencodeSession({ cwd: '/tmp/project' }) + await expect(session.start()).rejects.toThrow('history replay failed') + expect(headlessControl.stop).toHaveBeenCalledTimes(1) }) }) From 90f2a4d216affd9b1dd707dedaf95ce5fa640b93 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 02:22:43 -0700 Subject: [PATCH 06/40] fix(feed-debug): a forget that races a queued append leaves no per-session state behind #1207: an append queued before forgetFeedDebugSession, and not started yet, ran afterwards and wrote the per-session id, epoch and cap maps back; nothing removed them again (a few numbers per closed session, unbounded). Each append captures a per-session token when queued; forget retires it, and an append that finds its token gone once it has run deletes that state again. The token map is cleared by the same forget. Red before on the reviewer's 100-session probe with real queue ordering. Co-Authored-By: Claude Opus 5.5 --- ...2026-09-27-feed-debug-forget-generation.md | 12 +++++ src/main/storage/feedDebugLog.test.ts | 19 +++++++ src/main/storage/feedDebugLog.ts | 49 ++++++++++++++++++- 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 docs/plans/2026-09-27-feed-debug-forget-generation.md diff --git a/docs/plans/2026-09-27-feed-debug-forget-generation.md b/docs/plans/2026-09-27-feed-debug-forget-generation.md new file mode 100644 index 000000000..38d9d9cec --- /dev/null +++ b/docs/plans/2026-09-27-feed-debug-forget-generation.md @@ -0,0 +1,12 @@ +# Feed-debug per-session state survives a forget that races a queued append (#1207) + +## Problem +`feedDebugLog.ts` keeps three per-session maps: `lastWrittenFeedDebugId`, `lastWrittenFeedDebugEpoch` and `feedDebugCapState`. `forgetFeedDebugSession` deletes them synchronously. But an append that was queued before the forget, and had not started yet, ran afterwards and wrote them back. Queue settlement only reaps `feedDebugWriteQueues`, so the state stayed for the life of the process. The #1111 reviewer's probe: 100 sessions, 100 dead entries in each map. + +## Fix +- **A per-session token,** captured by each append when it is queued. `forget` deletes it. +- **When an append finishes** (in a `finally`, so a failed write counts too), a token that is no longer current means the session was forgotten meanwhile. The append then deletes the three maps again. +- **The token map is cleared by the same forget,** so it cannot grow either. + +## Test +Real queue ordering, no mocks of the queue: append then forget for 100 sessions, and await the writes. The three maps and the token map must be back to their prior sizes. It was red before the fix (105 vs 5 in each map), and removing the drop is red again. diff --git a/src/main/storage/feedDebugLog.test.ts b/src/main/storage/feedDebugLog.test.ts index 9ba00c476..d030bcee1 100644 --- a/src/main/storage/feedDebugLog.test.ts +++ b/src/main/storage/feedDebugLog.test.ts @@ -155,3 +155,22 @@ describe('#770 — a reload does not re-open a capped log', () => { } }) }) + +// #1207 (the #1111 reviewer's probe, real queue ordering): an append queued +// BEFORE forgetFeedDebugSession, and not started yet, used to run afterwards +// and write the per-session maps back. Nothing removed them again: a few +// numbers per closed session, forever. +describe('forget racing a queued append (#1207)', () => { + it('leaves no per-session state behind for 100 sessions forgotten right after an append', async () => { + const { feedDebugSessionStateSizesForTest } = await import('./feedDebugLog.js') + const before = feedDebugSessionStateSizesForTest() + const writes: Array> = [] + for (let i = 0; i < 100; i++) { + const sessionId = `forget-race-${i}` + writes.push(queueFeedDebugAppend(sessionId, [entry(1)], 1_789_000_000_000).catch(() => undefined)) + forgetFeedDebugSession(sessionId) + } + await Promise.all(writes) + expect(feedDebugSessionStateSizesForTest()).toEqual(before) + }) +}) diff --git a/src/main/storage/feedDebugLog.ts b/src/main/storage/feedDebugLog.ts index a7502b07a..6fca98a0b 100644 --- a/src/main/storage/feedDebugLog.ts +++ b/src/main/storage/feedDebugLog.ts @@ -122,6 +122,34 @@ const lastWrittenFeedDebugId = new Map() */ const lastWrittenFeedDebugEpoch = new Map() +/** + * One token per live session, captured by each append when it is QUEUED + * (#1207). forgetFeedDebugSession deletes it. + * + * WHY: an append queued before the forget, and not started yet, used to run + * afterwards and write the three maps above back; queue settlement only reaps + * `feedDebugWriteQueues`, so they stayed for the life of the process (a few + * numbers per closed session, unbounded). An append that finds its token gone + * once it has run belongs to a forgotten session and deletes that state again. + * The token map is cleared by the same forget, so it stays bounded too. + */ +const feedDebugSessionTokens = new Map() + +function feedDebugSessionToken(sessionId: string): object { + let token = feedDebugSessionTokens.get(sessionId) + if (!token) { + token = {} + feedDebugSessionTokens.set(sessionId, token) + } + return token +} + +function dropFeedDebugSessionState(sessionId: string): void { + lastWrittenFeedDebugId.delete(sessionId) + lastWrittenFeedDebugEpoch.delete(sessionId) + feedDebugCapState.delete(sessionId) +} + // One shape for both the first tombstone and the doubling refreshes so // readers grep for a single `__feedDebugCapped` marker. `fileBytesAtCap` is // the counter value at emit time — on a refresh row it reflects the file @@ -163,9 +191,19 @@ export function queueFeedDebugAppend( epochMs?: number, ): Promise { const previous = feedDebugWriteQueues.get(sessionId) ?? Promise.resolve() + const token = feedDebugSessionToken(sessionId) const next = previous .catch(() => {}) .then(async () => { + try { + await writeQueuedFeedDebugAppend() + } finally { + // Forgotten while this append waited or ran: the state it wrote + // belongs to a closed session (#1207, see feedDebugSessionTokens). + if (feedDebugSessionTokens.get(sessionId) !== token) dropFeedDebugSessionState(sessionId) + } + }) + async function writeQueuedFeedDebugAppend(): Promise { if (entries.length === 0) return if (epochMs !== undefined) { const knownEpoch = lastWrittenFeedDebugEpoch.get(sessionId) @@ -362,7 +400,7 @@ export function queueFeedDebugAppend( `tombstone ${capState.tombstoneWritten ? 'written' : 'write FAILED (will retry)'}, ` + 'dropping further appends this run', ) - }) + } feedDebugWriteQueues.set(sessionId, next) // Reap the queue entry once it settles — but only if no NEWER @@ -383,6 +421,11 @@ export function queueFeedDebugAppend( return next } +/** Sizes of the per-session maps, for the #1207 leak test only. */ +export function feedDebugSessionStateSizesForTest(): { ids: number; epochs: number; caps: number; tokens: number } { + return { ids: lastWrittenFeedDebugId.size, epochs: lastWrittenFeedDebugEpoch.size, caps: feedDebugCapState.size, tokens: feedDebugSessionTokens.size } +} + /** Drop in-memory bookkeeping for a session that has ended. The * on-disk JSONL is intentionally LEFT IN PLACE — debug bundles for * long-since-closed panes still benefit from reading the trail. The @@ -393,6 +436,10 @@ export function forgetFeedDebugSession(sessionId: string): void { // there might be an in-flight write that still owns the chain. // The settle-time reaper in queueFeedDebugAppend handles the queue // entry; what we own here is the cursor. + // + // Retiring the token tells any append queued before this call (and still + // pending) to delete what it writes (#1207). + feedDebugSessionTokens.delete(sessionId) lastWrittenFeedDebugId.delete(sessionId) lastWrittenFeedDebugEpoch.delete(sessionId) // Drop the cap-state entry too. If the same sessionId is re-registered later From e88684200a3106d9567f255170d6ce810f8fad82 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 02:40:01 -0700 Subject: [PATCH 07/40] fix(feed-debug): cap remembered sessions so late appends after forget stay bounded (#1392 review) An append arriving after forgetFeedDebugSession minted a new token and kept its state forever. The token map is now also a recency list capped at 256; eviction forgets the oldest session. Adds failure-path, re-registration and repeated-unknown-size tests that kill the reviewers' surviving mutations. Co-Authored-By: Claude Opus 5.5 --- src/main/storage/feedDebugLog.test.ts | 47 +++++++++++++++++++++++++++ src/main/storage/feedDebugLog.ts | 46 +++++++++++++++++++++----- 2 files changed, 85 insertions(+), 8 deletions(-) diff --git a/src/main/storage/feedDebugLog.test.ts b/src/main/storage/feedDebugLog.test.ts index d030bcee1..f9173e71a 100644 --- a/src/main/storage/feedDebugLog.test.ts +++ b/src/main/storage/feedDebugLog.test.ts @@ -174,3 +174,50 @@ describe('forget racing a queued append (#1207)', () => { expect(feedDebugSessionStateSizesForTest()).toEqual(before) }) }) + +// #1392 review a: an append that ARRIVES after the forget (late renderer +// flush, or any id the IPC handler accepts) mints a new token and keeps its +// state; no second forget comes. The recency cap is what bounds that. +describe('late appends after forget (#1392)', () => { + it('keeps per-session state bounded for 300 sessions that append after their forget', async () => { + for (let i = 0; i < 300; i++) { + const sessionId = `late-${i}` + forgetFeedDebugSession(sessionId) + await queueFeedDebugAppend(sessionId, [entry(1)], 1_789_000_000_000) + } + const { feedDebugSessionStateSizesForTest } = await import('./feedDebugLog.js') + const sizes = feedDebugSessionStateSizesForTest() + for (const size of Object.values(sizes)) expect(size).toBeLessThanOrEqual(256) + }) +}) + +// #1392 reviews a+b: the committed probe only covered successful writes. +describe('forget racing a queued append, other interleavings (#1392)', () => { + it('drops state after a forgotten append fails its size check', async () => { + const { feedDebugSessionStateSizesForTest } = await import('./feedDebugLog.js') + statResult = { mode: 'throw', code: 'EACCES' } + const write = queueFeedDebugAppend('forget-fail', [entry(1)], 1_789_000_000_000) + forgetFeedDebugSession('forget-fail') + await expect(write).rejects.toThrow() + expect(feedDebugSessionStateSizesForTest('forget-fail')).toEqual({ ids: 0, epochs: 0, caps: 0, tokens: 0 }) + }) + + it('lets a re-registered id write its first row after an old append of the same id', async () => { + // Same id, same epoch: if the old append's cleanup only checked that SOME + // token exists, it would keep its cursor and the new generation's id 1 + // would be filtered as already written. + const first = queueFeedDebugAppend('reregistered', [entry(1)], 7_000) + forgetFeedDebugSession('reregistered') + const second = queueFeedDebugAppend('reregistered', [entry(1)], 7_000) + await Promise.all([first, second]) + const lines = (await readFile(logPath('reregistered'), 'utf8')).trim().split('\n') + expect(lines).toHaveLength(2) + }) + + it('keeps rejecting while the size stays unknown', async () => { + forgetFeedDebugSession('still-unknown') + statResult = { mode: 'throw', code: 'EACCES' } + await expect(queueFeedDebugAppend('still-unknown', [entry(1)], 1_000)).rejects.toThrow() + await expect(queueFeedDebugAppend('still-unknown', [entry(2)], 1_000)).rejects.toThrow() + }) +}) diff --git a/src/main/storage/feedDebugLog.ts b/src/main/storage/feedDebugLog.ts index 6fca98a0b..0314f46c6 100644 --- a/src/main/storage/feedDebugLog.ts +++ b/src/main/storage/feedDebugLog.ts @@ -131,15 +131,41 @@ const lastWrittenFeedDebugEpoch = new Map() * `feedDebugWriteQueues`, so they stayed for the life of the process (a few * numbers per closed session, unbounded). An append that finds its token gone * once it has run belongs to a forgotten session and deletes that state again. - * The token map is cleared by the same forget, so it stays bounded too. + * The token map is cleared by the same forget. + * + * The token alone is NOT a bound (#1392 review a). An append that ARRIVES + * after the forget (the renderer's flush timer and teardown flush run + * independently of the process exit that triggers the forget, and the IPC + * handler accepts any id) mints a fresh token and keeps its state, and no + * second forget ever comes. Main has no liveness oracle here short of + * coupling this storage module to the session manager, so the map is also a + * RECENCY list capped at MAX_REMEMBERED_FEED_DEBUG_SESSIONS: every queued + * append moves its session to the end (same token object, so identity checks + * still hold), and past the cap the least recently appended session is + * forgotten exactly as forgetFeedDebugSession would. That makes the leak + * bounded whatever the interleaving: at most the cap's worth of a few + * numbers, not "zero", for late appends. + * + * Evicting a session that is in fact still live is harmless in practice: + * the cap state re-primes from the file on disk (the fail-closed stat + * path), the epoch simply re-registers, and the only thing lost is the + * de-dup cursor, so a double send racing that exact moment could write a + * duplicate debug row. 256 is far above the number of agents anyone runs + * at once, so this only trims closed sessions. */ const feedDebugSessionTokens = new Map() +const MAX_REMEMBERED_FEED_DEBUG_SESSIONS = 256 function feedDebugSessionToken(sessionId: string): object { - let token = feedDebugSessionTokens.get(sessionId) - if (!token) { - token = {} - feedDebugSessionTokens.set(sessionId, token) + const token = feedDebugSessionTokens.get(sessionId) ?? {} + // delete + set moves the id to the end of the Map's insertion order. + feedDebugSessionTokens.delete(sessionId) + feedDebugSessionTokens.set(sessionId, token) + for (const oldest of feedDebugSessionTokens.keys()) { + if (feedDebugSessionTokens.size <= MAX_REMEMBERED_FEED_DEBUG_SESSIONS) break + // An append of the evicted session still in its queue will see its token + // gone when it settles and drop what it wrote, as after a forget. + forgetFeedDebugSession(oldest) } return token } @@ -421,9 +447,13 @@ export function queueFeedDebugAppend( return next } -/** Sizes of the per-session maps, for the #1207 leak test only. */ -export function feedDebugSessionStateSizesForTest(): { ids: number; epochs: number; caps: number; tokens: number } { - return { ids: lastWrittenFeedDebugId.size, epochs: lastWrittenFeedDebugEpoch.size, caps: feedDebugCapState.size, tokens: feedDebugSessionTokens.size } +/** Sizes of the per-session maps (or, given an id, whether each map holds + * it), for the #1207/#1392 leak tests only. The per-id form exists because + * whole-map sizes stop being comparable once the recency cap starts + * evicting other tests' sessions. */ +export function feedDebugSessionStateSizesForTest(sessionId?: string): { ids: number; epochs: number; caps: number; tokens: number } { + const count = (map: Map) => (sessionId === undefined ? map.size : Number(map.has(sessionId))) + return { ids: count(lastWrittenFeedDebugId), epochs: count(lastWrittenFeedDebugEpoch), caps: count(feedDebugCapState), tokens: count(feedDebugSessionTokens) } } /** Drop in-memory bookkeeping for a session that has ended. The From 1cb7de03dab9c9f2429616318069ce56736aeaa2 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 02:44:55 -0700 Subject: [PATCH 08/40] fix(codex): keep wrapped exec_command results in resumed history (#1321) Codex never persists exec_command_end (codex-rs rollout policy: transient; 0 in 2,541 local rollouts), so dropping the wrapped function_call_output removed the only copy of every exec_command result and exit status. Co-Authored-By: Claude Opus 5.5 --- .../2026-09-27-codex-exec-wrapped-output.md | 23 +++++ .../codex/renderer/transcript/entries.ts | 39 ++++++--- .../transcript/execWrappedOutput.test.ts | 83 +++++++++++++++++++ .../codex/renderer/transcript/rollout.ts | 32 ++++++- .../wrapped-exec-command-output.json | 83 +++++++++++++++++++ tsconfig.web.json | 1 + 6 files changed, 247 insertions(+), 14 deletions(-) create mode 100644 docs/plans/2026-09-27-codex-exec-wrapped-output.md create mode 100644 src/providers/codex/renderer/transcript/execWrappedOutput.test.ts create mode 100644 testing/fixtures/codex-exec-output/wrapped-exec-command-output.json diff --git a/docs/plans/2026-09-27-codex-exec-wrapped-output.md b/docs/plans/2026-09-27-codex-exec-wrapped-output.md new file mode 100644 index 000000000..6a20c6bb1 --- /dev/null +++ b/docs/plans/2026-09-27-codex-exec-wrapped-output.md @@ -0,0 +1,23 @@ +# Codex exec_command results survive in resumed history (#1321) + +## Evidence +- **Census of 2,541 local rollouts.** It found 85,355 `function_call_output` lines whose output is wrapped: `Chunk ID:`, `Wall time:`, `Process exited with code N`, `Original token count:`, then `Output:`. It found **0** `exec_command_end` events in any file. +- **Codex never writes that event.** codex-rs `rollout/src/policy.rs` puts `EventMsg::ExecCommandEnd` under "Transient, non-durable events". +- **The drop rule.** `mapCodexRolloutToFeedEntries` drops every wrapped output that has an exit line (`isCodexExecWrapperOutput`), on the stated belief that "the correlated `exec_command_end` event carries the same result". That belief is false, so the dropped line was the only copy. Every `exec_command` card in resumed history showed no output and no exit status. That covers Codex through 0.144: `exec_command` wrapped outputs occur in 0.1xx through 0.144, and 0.15x uses the `exec` tool. +- **A second bug.** The predicate searched the WHOLE string for "Process exited with code". A still-running chunk whose command output contains those words was dropped too. + +## Change +- **Header-only parsing.** `codexExecWrapperExitCode(output)` reads the exit code from the header only, the part before `\nOutput:\n`. It returns null for unwrapped output and for a still-running chunk. +- **Keep the result.** A wrapped, finished output now maps to a tool result with: + - the stripped output (possibly empty); + - `is_error = exitCode !== 0`; + - the same `codex` metadata the event branch produces (`kind: 'exec_command_end'`, `exitCode`, empty `parsedCmd` and `command`, null `cwd`). + + So the command adapter reads it as the native transport it is: exit-proven, the output owned, and an empty success absorbed by the row dispatcher as before. +- **Comments corrected.** The stale comments that say the wrapper comes from, or is duplicated by, `exec_command_end` are fixed. + +## Tests +`execWrappedOutput.test.ts` runs three real 0.132.0 pairs (exit 0 with output, exit 1, exit 0 with no output) through the real mapper and the real `fromCodexCommandOperation`, plus a still-running chunk whose body contains the exit words. All four are red on main. + +## Not in scope +The 0.15x `exec` tool's `custom_tool_call_output` results are a different carrier, already handled by the code-mode envelope path. diff --git a/src/providers/codex/renderer/transcript/entries.ts b/src/providers/codex/renderer/transcript/entries.ts index 7fd5b8c90..ebe096acf 100644 --- a/src/providers/codex/renderer/transcript/entries.ts +++ b/src/providers/codex/renderer/transcript/entries.ts @@ -133,8 +133,11 @@ function partToBlock(part: ResultPart): { type: string; text?: string; [key: str } } -/** Codex's `exec_command_end` wraps its output in a "Chunk ID: …\nOutput:\n" - * envelope. The user never wants to see that wrapper — strip it. */ +/** Codex's `exec_command` result (the `function_call_output` rollout line, + * through 0.144) wraps its output in a "Chunk ID: …\nOutput:\n" + * envelope. The user never wants to see that wrapper — strip it. (This used + * to say the envelope came from `exec_command_end`; that event is never + * persisted, #1321.) */ export function stripCodexExecWrapper(output: string): string { const marker = '\nOutput:\n' const idx = output.indexOf(marker) @@ -142,15 +145,29 @@ export function stripCodexExecWrapper(output: string): string { return output.slice(idx + marker.length) } -/** True for ANY exec-wrapped output ("Chunk ID: …" with a "Process exited - * with code …" line), stdout or not. The rollout mapper drops these - * `function_call_output` lines because the correlated `exec_command_end` - * event carries the same result, with exit code and command, and renders - * the card; keeping both would duplicate it. (This comment used to say - * "only the wrapper and nothing else", which the code never did; #1298 - * review B.) */ -export function isCodexExecWrapperOutput(output: string): boolean { - return output.startsWith('Chunk ID:') && output.includes('\nProcess exited with code ') +/** The exit code in an exec-wrapped output's header ("Chunk ID: …" … + * "Process exited with code N" … "Output:"), or null when the output is not + * wrapped or the process was still running ("Process running with session + * ID …", a partial chunk a later write_stdin/poll continues). + * + * WHY only the header is read: the body is the command's own bytes, and a + * command can print "Process exited with code 0" itself (a cat of a captured + * transcript). The old `includes` test scanned the whole string. + * + * WHY this replaced `isCodexExecWrapperOutput` (#1321): that predicate made the + * rollout mapper DROP every wrapped result, on the belief that a correlated + * `exec_command_end` event carried the same result. Codex never persists that + * event: codex-rs `rollout/src/policy.rs` lists `EventMsg::ExecCommandEnd` + * under transient events, and a census of 2,541 local rollouts found 0 of + * them against 85,355 wrapped outputs with an exit line. The drop therefore + * removed the ONLY copy of every `exec_command` result (Codex through 0.144) + * from resumed history, and the card showed no output or exit status. */ +export function codexExecWrapperExitCode(output: string): number | null { + if (!output.startsWith('Chunk ID:')) return null + const outputMarker = output.indexOf('\nOutput:\n') + const header = outputMarker === -1 ? output : output.slice(0, outputMarker) + const match = /\nProcess exited with code (-?\d+)(?:\n|$)/.exec(header) + return match ? Number(match[1]) : null } /** Build a Claude-shaped assistant Entry containing a single diff --git a/src/providers/codex/renderer/transcript/execWrappedOutput.test.ts b/src/providers/codex/renderer/transcript/execWrappedOutput.test.ts new file mode 100644 index 000000000..2fc64992c --- /dev/null +++ b/src/providers/codex/renderer/transcript/execWrappedOutput.test.ts @@ -0,0 +1,83 @@ +import { describe, expect, it } from 'vitest' + +import fixture from '../../../../../testing/fixtures/codex-exec-output/wrapped-exec-command-output.json' + +import { fromCodexCommandOperation } from '@providers/codex/renderer/adapters/command' +import { mapCodexRolloutToFeedEntries } from '@providers/codex/renderer/transcript/rollout' +import type { ToolResultBlock, ToolUseBlock } from '@shared/types/transcript' + +// #1321: the rollout mapper dropped every wrapped exec_command result, on the +// belief that an `exec_command_end` event carried it. Codex never persists that +// event (codex-rs rollout policy: transient), so resumed history lost the only +// copy of the output and the exit status. Each case is a REAL 0.132.0 pair +// (see the fixture's `evidence`), mapped by the real mapper and read by the +// real command adapter the card uses. +type Case = { cliVersion: string; records: Array> } +const cases = fixture.cases as unknown as Record<'ok' | 'fail' | 'empty', Case> + +function mapPair(name: keyof typeof cases): { toolUse: ToolUseBlock; result: ToolResultBlock | null } { + const entries = cases[name].records.flatMap(record => mapCodexRolloutToFeedEntries(record)) + const blocks = entries.flatMap(entry => { + const content = (entry as { message?: { content?: unknown } }).message?.content + return Array.isArray(content) ? content as Array> : [] + }) + const toolUse = blocks.find(block => block.type === 'tool_use') as ToolUseBlock | undefined + const result = blocks.find(block => block.type === 'tool_result') as ToolResultBlock | undefined + if (!toolUse) throw new Error(`fixture case ${name} has no tool_use`) + return { toolUse, result: result ?? null } +} + +describe('wrapped exec_command results in resumed history (#1321)', () => { + it('keeps a successful result, without the wrapper, with its exit code', () => { + const { toolUse, result } = mapPair('ok') + expect(result).not.toBeNull() + expect(result!.tool_use_id).toBe(toolUse.id) + expect(result!.is_error).toBe(false) + expect(String(result!.content)).not.toContain('Chunk ID:') + expect(String(result!.content)).toMatch(/^x+\nx+/) + + const operation = fromCodexCommandOperation({ toolUse, result }) + expect(operation?.model.exitCode).toBe(0) + expect(operation?.model.output).toBe(result!.content) + expect(operation?.ownsResult).toBe(true) + }) + + it('keeps a failed result and reports it as failed with the real exit code', () => { + const { toolUse, result } = mapPair('fail') + expect(result?.is_error).toBe(true) + + const operation = fromCodexCommandOperation({ toolUse, result }) + expect(operation?.model.exitCode).toBe(1) + expect(operation?.model.status).toBe('failure') + }) + + it('keeps an empty successful result as proof the command finished', () => { + // Without a result the card cannot tell `mkdir` that printed nothing from + // a command interrupted before its result was written. + const { toolUse, result } = mapPair('empty') + expect(result).not.toBeNull() + expect(result!.content).toBe('') + + const operation = fromCodexCommandOperation({ toolUse, result }) + expect(operation?.model.exitCode).toBe(0) + expect(operation?.model.status).not.toBe('running') + }) + + it('reads the exit code from the header only, never from the command output', () => { + // A command can print the header's words itself (a cat of a captured + // transcript). A still-running chunk has no exit line in its header. + const running = { + type: 'response_item', + timestamp: '2026-07-09T21:40:40.079Z', + payload: { + type: 'function_call_output', + call_id: 'call-running', + output: 'Chunk ID: aaaaaa\nWall time: 1.0000 seconds\nProcess running with session ID 1\nOriginal token count: 9\nOutput:\nx\nProcess exited with code 0\n', + }, + } + const [entry] = mapCodexRolloutToFeedEntries(running) + const block = ((entry as { message: { content: Array> } }).message.content)[0]! + expect(block.codex).toBeUndefined() + expect(block.content).toBe('x\nProcess exited with code 0\n') + }) +}) diff --git a/src/providers/codex/renderer/transcript/rollout.ts b/src/providers/codex/renderer/transcript/rollout.ts index 15debb708..8f4e1acc7 100644 --- a/src/providers/codex/renderer/transcript/rollout.ts +++ b/src/providers/codex/renderer/transcript/rollout.ts @@ -9,7 +9,7 @@ import { codexToolResultEntry, codexToolUseEntry, codexOutputText, - isCodexExecWrapperOutput, + codexExecWrapperExitCode, parseCodexJson, stripCodexExecWrapper, } from '@providers/codex/renderer/transcript/entries' @@ -324,6 +324,13 @@ export function mapCodexRolloutToFeedEntries(entry: Record): En // its result was persisted. The provider renderer absorbs this empty // result after it has updated the command card, so retaining terminal // evidence does not reintroduce a blank standalone row. + // + // WHERE this event comes from (#1321): not from rollouts. codex-rs + // persists `ExecCommandEnd` as a transient event, and 0 of 2,541 local + // rollouts contain one. The durable carrier of an exec_command result is + // the wrapped `function_call_output` below, which is stamped with this + // same metadata. This branch stays for any stream that does carry the + // event; the existing mapper tests feed it directly. return [ codexToolResultEntry( uuid, @@ -434,9 +441,28 @@ export function mapCodexRolloutToFeedEntries(entry: Record): En return [codexToolResultEntry(uuid, timestamp, payload.call_id, structured)] } const output = stripCodexExecWrapper(structured) - if (!output.trim() || isCodexExecWrapperOutput(structured)) { - return [] + const exitCode = codexExecWrapperExitCode(structured) + if (exitCode !== null) { + // A finished exec: the wrapper is the durable carrier of the result AND + // its exit status (#1321; see codexExecWrapperExitCode for why nothing + // else in the rollout carries them). It is stamped with the same + // `exec_command_end` metadata the live event produced, so the command + // card reads it as the native transport it is: bytes are the command's + // own, is_error and exitCode come from the real exit line. An EMPTY + // successful result is kept on purpose, exactly as for the event: it is + // the only proof the command finished rather than being interrupted, + // and the row dispatcher absorbs it once the card has its status. + return [ + codexToolResultEntry(uuid, timestamp, payload.call_id, output, exitCode !== 0, { + kind: 'exec_command_end', + parsedCmd: [], + command: [], + cwd: null, + exitCode, + }), + ] } + if (!output.trim()) return [] return [codexToolResultEntry(uuid, timestamp, payload.call_id, output)] } diff --git a/testing/fixtures/codex-exec-output/wrapped-exec-command-output.json b/testing/fixtures/codex-exec-output/wrapped-exec-command-output.json new file mode 100644 index 000000000..f34623664 --- /dev/null +++ b/testing/fixtures/codex-exec-output/wrapped-exec-command-output.json @@ -0,0 +1,83 @@ +{ + "evidence": "Three real Codex 0.132.0 rollout pairs (exec_command function_call + its function_call_output), one per result class: exit 0 with output, exit 1 with output, exit 0 with no output. Keys, types, call ids, timestamps, ordinals and the whole wrapper header (Chunk ID, Wall time, Process exited with code N, Original token count, Output:) are verbatim. The command, workdir and output body are replaced by the same number of x characters (newlines kept). Corpus census for #1321 (2,541 local rollouts): 85,355 wrapped function_call_output lines carry a \"Process exited with code\" header and 0 files contain an exec_command_end event; codex-rs rollout/src/policy.rs lists EventMsg::ExecCommandEnd under transient, never-persisted events.", + "cases": { + "ok": { + "cliVersion": "0.132.0", + "records": [ + { + "timestamp": "2026-07-09T21:40:39.633Z", + "ordinal": 9, + "type": "response_item", + "payload": { + "type": "function_call", + "name": "exec_command", + "arguments": "{\"cmd\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"workdir\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"yield_time_ms\":1000,\"max_output_tokens\":6000}", + "call_id": "call_3ovvxxP4PmRN2neyj08yspZS" + } + }, + { + "timestamp": "2026-07-09T21:40:40.079Z", + "ordinal": 10, + "type": "response_item", + "payload": { + "type": "function_call_output", + "call_id": "call_3ovvxxP4PmRN2neyj08yspZS", + "output": "Chunk ID: c9e6a2\nWall time: 0.2793 seconds\nProcess exited with code 0\nOriginal token count: 31\nOutput:\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + } + } + ] + }, + "fail": { + "cliVersion": "0.132.0", + "records": [ + { + "timestamp": "2026-07-09T21:40:57.469Z", + "ordinal": 64, + "type": "response_item", + "payload": { + "type": "function_call", + "name": "exec_command", + "arguments": "{\"cmd\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"workdir\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"yield_time_ms\":1000,\"max_output_tokens\":12000}", + "call_id": "call_QdUm1WS8k6b7rVq4ifm4hqzI" + } + }, + { + "timestamp": "2026-07-09T21:40:58.271Z", + "ordinal": 66, + "type": "response_item", + "payload": { + "type": "function_call_output", + "call_id": "call_QdUm1WS8k6b7rVq4ifm4hqzI", + "output": "Chunk ID: 3039c0\nWall time: 0.6442 seconds\nProcess exited with code 1\nOriginal token count: 136\nOutput:\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + } + } + ] + }, + "empty": { + "cliVersion": "0.132.0", + "records": [ + { + "timestamp": "2026-07-09T20:39:14.481Z", + "ordinal": 30, + "type": "response_item", + "payload": { + "type": "function_call", + "name": "exec_command", + "arguments": "{\"cmd\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"workdir\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",\"yield_time_ms\":1000,\"max_output_tokens\":12000}", + "call_id": "call_DSkiWNmdsFlz6ohXiLrovEiZ" + } + }, + { + "timestamp": "2026-07-09T20:39:14.723Z", + "ordinal": 33, + "type": "response_item", + "payload": { + "type": "function_call_output", + "call_id": "call_DSkiWNmdsFlz6ohXiLrovEiZ", + "output": "Chunk ID: fc3db1\nWall time: 0.0670 seconds\nProcess exited with code 0\nOriginal token count: 0\nOutput:\n" + } + } + ] + } + } +} \ No newline at end of file diff --git a/tsconfig.web.json b/tsconfig.web.json index 264b218b2..676106982 100644 --- a/tsconfig.web.json +++ b/tsconfig.web.json @@ -57,6 +57,7 @@ // tests read the real pasted-prompt row rather than an invented one. "testing/fixtures/prompt-acceptance/*.json", "testing/fixtures/transcript-disconnect/*.json", + "testing/fixtures/codex-exec-output/*.json", "src/control-sdk/**/*", "src/renderer/**/*", // Renderer specs use the DOM matchers installed by the Vitest setup module. The setup lived From 49b7f5b272d0d214511b1c84d893581ed19eeecc Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 02:52:17 -0700 Subject: [PATCH 09/40] fix(feed-debug): release a session's state when its runtime is gone, not by a cap (#1392 review round 2) The 256-session LRU cap broke three ways under review: evicting a session mid-stat resolved its append without writing, eviction reset a capped file's drop count, and a stalled stat held evicted state past the bound. A remembered-forgotten set fails too: a same-id wake makes the id live again. The renderer now releases an id (debug:forget-feed-log) once its runtime is removed, which is the only point no further append can follow. The cap and its test are gone; the failure-path, re-registration and repeated-unknown-size tests stay. Co-Authored-By: Claude Opus 5.5 --- src/main/ipc/debug.ts | 14 +++++- src/main/storage/feedDebugLog.test.ts | 16 ------- src/main/storage/feedDebugLog.ts | 47 ++++++++----------- src/preload/api/debug.ts | 5 ++ .../useFeedDebugPersist.renderer.test.tsx | 35 +++++++++++++- .../hook/persistence/useFeedDebugPersist.ts | 23 +++++++++ 6 files changed, 94 insertions(+), 46 deletions(-) diff --git a/src/main/ipc/debug.ts b/src/main/ipc/debug.ts index b5d0452b2..c662b10d7 100644 --- a/src/main/ipc/debug.ts +++ b/src/main/ipc/debug.ts @@ -1,6 +1,6 @@ import { ipcMain } from 'electron' -import { queueFeedDebugAppend } from '@main/storage/feedDebugLog.js' +import { forgetFeedDebugSession, queueFeedDebugAppend } from '@main/storage/feedDebugLog.js' import type { FeedDebugPersistEntry } from '@main/storage/feedDebugLog.js' import { saveDebugBundle } from '@main/storage/debugBundle.js' import type { SaveDebugBundleParams, SaveDebugBundleResult } from '@main/storage/debugBundle.js' @@ -49,6 +49,18 @@ export function registerDebugIpc( }, ) + // The renderer's release of a feed-debug log whose pane is gone (#1392). + // Main forgets on process exit too, but a pane outlives its process (a + // same-id wake reuses the id) and keeps appending, which re-creates the + // per-session state; only the renderer knows when no append can follow. + // Any append it queued earlier is already in the per-session queue (IPC + // order is preserved and the append handler queues synchronously), and its + // token makes it drop what it writes. + ipcMain.handle('debug:forget-feed-log', (_evt, params: { sessionId?: unknown }) => { + if (typeof params?.sessionId !== 'string' || params.sessionId.length === 0) return + forgetFeedDebugSession(params.sessionId) + }) + ipcMain.handle( 'debug:save-bundle', async (_evt, params: SaveDebugBundleParams): Promise => { diff --git a/src/main/storage/feedDebugLog.test.ts b/src/main/storage/feedDebugLog.test.ts index f9173e71a..a161950ac 100644 --- a/src/main/storage/feedDebugLog.test.ts +++ b/src/main/storage/feedDebugLog.test.ts @@ -175,22 +175,6 @@ describe('forget racing a queued append (#1207)', () => { }) }) -// #1392 review a: an append that ARRIVES after the forget (late renderer -// flush, or any id the IPC handler accepts) mints a new token and keeps its -// state; no second forget comes. The recency cap is what bounds that. -describe('late appends after forget (#1392)', () => { - it('keeps per-session state bounded for 300 sessions that append after their forget', async () => { - for (let i = 0; i < 300; i++) { - const sessionId = `late-${i}` - forgetFeedDebugSession(sessionId) - await queueFeedDebugAppend(sessionId, [entry(1)], 1_789_000_000_000) - } - const { feedDebugSessionStateSizesForTest } = await import('./feedDebugLog.js') - const sizes = feedDebugSessionStateSizesForTest() - for (const size of Object.values(sizes)) expect(size).toBeLessThanOrEqual(256) - }) -}) - // #1392 reviews a+b: the committed probe only covered successful writes. describe('forget racing a queued append, other interleavings (#1392)', () => { it('drops state after a forgotten append fails its size check', async () => { diff --git a/src/main/storage/feedDebugLog.ts b/src/main/storage/feedDebugLog.ts index 0314f46c6..8dc0711a1 100644 --- a/src/main/storage/feedDebugLog.ts +++ b/src/main/storage/feedDebugLog.ts @@ -133,39 +133,30 @@ const lastWrittenFeedDebugEpoch = new Map() * once it has run belongs to a forgotten session and deletes that state again. * The token map is cleared by the same forget. * - * The token alone is NOT a bound (#1392 review a). An append that ARRIVES - * after the forget (the renderer's flush timer and teardown flush run - * independently of the process exit that triggers the forget, and the IPC - * handler accepts any id) mints a fresh token and keeps its state, and no - * second forget ever comes. Main has no liveness oracle here short of - * coupling this storage module to the session manager, so the map is also a - * RECENCY list capped at MAX_REMEMBERED_FEED_DEBUG_SESSIONS: every queued - * append moves its session to the end (same token object, so identity checks - * still hold), and past the cap the least recently appended session is - * forgotten exactly as forgetFeedDebugSession would. That makes the leak - * bounded whatever the interleaving: at most the cap's worth of a few - * numbers, not "zero", for late appends. + * An append that ARRIVES after the forget mints a fresh token and keeps its + * state; that is correct when the pane is still open (a same-id wake reuses + * the id, see sessionManager's agentPtyAttachCounts note), and the renderer + * releases the id when the pane really goes away (`debug:forget-feed-log`, + * sent by useFeedDebugPersist after the session's runtime is removed). That + * release, not a cap here, is what bounds these maps (#1392). * - * Evicting a session that is in fact still live is harmless in practice: - * the cap state re-primes from the file on disk (the fail-closed stat - * path), the epoch simply re-registers, and the only thing lost is the - * de-dup cursor, so a double send racing that exact moment could write a - * duplicate debug row. 256 is far above the number of agents anyone runs - * at once, so this only trims closed sessions. + * WHY not a cap on remembered sessions: round 2 of review found an LRU cap + * broke three ways. Evicting a session whose append was inside its `stat` + * deleted the cap placeholder its identity check relies on, so the append + * resolved WITHOUT writing and the renderer advanced its cursor past lost + * rows; eviction reset a capped file's drop count, so its next tombstone + * under-reported drops by orders of magnitude; and appends already queued for + * evicted ids kept their state while a stalled `stat` held them. A remembered + * set of FORGOTTEN ids fails too: the same-id wake makes a forgotten id live + * again, and every one of its appends would be treated as late. */ const feedDebugSessionTokens = new Map() -const MAX_REMEMBERED_FEED_DEBUG_SESSIONS = 256 function feedDebugSessionToken(sessionId: string): object { - const token = feedDebugSessionTokens.get(sessionId) ?? {} - // delete + set moves the id to the end of the Map's insertion order. - feedDebugSessionTokens.delete(sessionId) - feedDebugSessionTokens.set(sessionId, token) - for (const oldest of feedDebugSessionTokens.keys()) { - if (feedDebugSessionTokens.size <= MAX_REMEMBERED_FEED_DEBUG_SESSIONS) break - // An append of the evicted session still in its queue will see its token - // gone when it settles and drop what it wrote, as after a forget. - forgetFeedDebugSession(oldest) + let token = feedDebugSessionTokens.get(sessionId) + if (!token) { + token = {} + feedDebugSessionTokens.set(sessionId, token) } return token } diff --git a/src/preload/api/debug.ts b/src/preload/api/debug.ts index 7f5821ff9..ced81ef05 100644 --- a/src/preload/api/debug.ts +++ b/src/preload/api/debug.ts @@ -29,6 +29,11 @@ export const debugApi = { }): Promise => ipcRenderer.invoke('debug:append-feed-log', params), + /** Release main's per-session feed-debug state for a pane that is gone + * (#1392). Sent once, after the renderer's last possible append. */ + forgetFeedDebugLog: (params: { sessionId: string }): Promise => + ipcRenderer.invoke('debug:forget-feed-log', params), + saveDebugBundle: (params: SaveDebugBundleParams): Promise => ipcRenderer.invoke('debug:save-bundle', params), diff --git a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx index ea2a4f7cb..50b789eed 100644 --- a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx +++ b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx @@ -9,11 +9,13 @@ import { useFeedDebugPersist } from './useFeedDebugPersist' const originalApiDescriptor = Object.getOwnPropertyDescriptor(window, 'api') const append = vi.fn<(input: Parameters[0]) => Promise>() +const forget = vi.fn<(input: Parameters[0]) => Promise>() beforeEach(() => { vi.useFakeTimers() append.mockReset().mockResolvedValue(undefined) - Object.defineProperty(window, 'api', { configurable: true, value: { appendFeedDebugLog: append } }) + forget.mockReset().mockResolvedValue(undefined) + Object.defineProperty(window, 'api', { configurable: true, value: { appendFeedDebugLog: append, forgetFeedDebugLog: forget } }) }) afterEach(() => { @@ -272,3 +274,34 @@ describe('feed debug persistence cadence and durability', () => { expect(append).toHaveBeenCalledTimes(2) }) }) + +// #1392: main forgets a session's feed-debug state at PROCESS exit, but the +// pane outlives the process and its later appends re-create that state. Only +// the renderer knows when a session can never append again: its runtime is +// gone. Then, and only then, it releases the id to main. +describe('releasing a session whose runtime is gone (#1392)', () => { + it('forgets a removed session once, after its last flush, and keeps live ones', async () => { + const refs = makeRefs({ a: add(emptyRuntime(), 'a row'), b: add(emptyRuntime(), 'b row') }) + renderHook(() => useFeedDebugPersist(refs)) + await advance(1_000) + expect(append).toHaveBeenCalledTimes(2) + expect(forget).not.toHaveBeenCalled() + + // Pane `a` closes: its runtime is removed. + refs.latestRuntimesRef.current = { b: refs.latestRuntimesRef.current.b! } + await advance(1_000) + expect(forget).toHaveBeenCalledExactlyOnceWith({ sessionId: 'a' }) + expect(refs.persistedFeedDebugIdRef.current).not.toHaveProperty('a') + expect(refs.persistedFeedDebugIdRef.current.b).toBe(1) + + await advance(3_000) + expect(forget).toHaveBeenCalledTimes(1) + }) + + it('does not forget a session that never had a runtime while mounted', async () => { + const refs = makeRefs({}) + renderHook(() => useFeedDebugPersist(refs)) + await advance(2_000) + expect(forget).not.toHaveBeenCalled() + }) +}) diff --git a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts index f591bde09..1c222c8aa 100644 --- a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts +++ b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts @@ -130,10 +130,33 @@ export function useFeedDebugPersist(refs: WorkspaceRefs): void { }) } + // Sessions this hook has seen a runtime for. A session whose runtime is + // gone (pane closed, or replaced by a new id) can never append again, so + // it is released here: its flush cursors, and main's per-session state + // (#1392). Main's own forget runs at PROCESS exit, but the pane outlives + // the process (exit rows, a same-id wake) and its later appends + // re-created that state with nothing left to forget it. + // + // Entries not yet flushed when the runtime was removed are lost, as they + // were before: this changes only what is forgotten, not what is written. + const known = new Set() + const releaseGone = (): void => { + const runtimes = refs.latestRuntimesRef.current + for (const sessionId of known) { + if (runtimes[sessionId]) continue + known.delete(sessionId) + delete refs.persistedFeedDebugIdRef.current[sessionId] + delete refs.inFlightFeedDebugIdRef.current[sessionId] + void window.api.forgetFeedDebugLog({ sessionId }).catch(() => {}) + } + } + const flush = (): void => { for (const [sessionId, runtime] of Object.entries(refs.latestRuntimesRef.current)) { + known.add(sessionId) flushSession(sessionId, runtime) } + releaseGone() } // WHY an interval independent of runtimes: busy agents replace that map From c053f52d150d80e14f4a53e580d340deedf8a1a9 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 03:01:35 -0700 Subject: [PATCH 10/40] fix(codex): running exec chunks are not successes; keep one terminal carrier per call (review a) Co-Authored-By: Claude Opus 5.5 --- .../2026-09-27-codex-exec-wrapped-output.md | 8 +- .../codex/renderer/adapters/command.ts | 23 ++++-- .../codex/renderer/transcript/entries.ts | 30 ++++++-- .../transcript/execWrappedOutput.test.ts | 73 ++++++++++++++++++- .../codex/renderer/transcript/mapper.ts | 41 ++++++++++- .../codex/renderer/transcript/rollout.ts | 20 +++-- 6 files changed, 172 insertions(+), 23 deletions(-) diff --git a/docs/plans/2026-09-27-codex-exec-wrapped-output.md b/docs/plans/2026-09-27-codex-exec-wrapped-output.md index 6a20c6bb1..b9c7cb395 100644 --- a/docs/plans/2026-09-27-codex-exec-wrapped-output.md +++ b/docs/plans/2026-09-27-codex-exec-wrapped-output.md @@ -2,7 +2,7 @@ ## Evidence - **Census of 2,541 local rollouts.** It found 85,355 `function_call_output` lines whose output is wrapped: `Chunk ID:`, `Wall time:`, `Process exited with code N`, `Original token count:`, then `Output:`. It found **0** `exec_command_end` events in any file. -- **Codex never writes that event.** codex-rs `rollout/src/policy.rs` puts `EventMsg::ExecCommandEnd` under "Transient, non-durable events". +- **Current Codex never writes that event.** codex-rs `rollout/src/policy.rs` puts `EventMsg::ExecCommandEnd` under "Transient, non-durable events". rust-v0.107.0 through v0.131.0 did persist it in extended-history mode (review a), and none of the local rollouts use that mode. - **The drop rule.** `mapCodexRolloutToFeedEntries` drops every wrapped output that has an exit line (`isCodexExecWrapperOutput`), on the stated belief that "the correlated `exec_command_end` event carries the same result". That belief is false, so the dropped line was the only copy. Every `exec_command` card in resumed history showed no output and no exit status. That covers Codex through 0.144: `exec_command` wrapped outputs occur in 0.1xx through 0.144, and 0.15x uses the `exec` tool. - **A second bug.** The predicate searched the WHOLE string for "Process exited with code". A still-running chunk whose command output contains those words was dropped too. @@ -21,3 +21,9 @@ ## Not in scope The 0.15x `exec` tool's `custom_tool_call_output` results are a different carrier, already handled by the code-mode envelope path. + +## Review a (round 1) +- **P1: a running chunk read as a success.** A wrapper whose header says "Process running with session ID N" is a partial chunk. The command's exit arrives on a later `write_stdin` result with another call_id. The adapter's native branch claimed `exitProven: true` for every result, so the card said success. The mapper now marks such a chunk `codex.kind: 'exec_command_running'`, and the adapter does not claim a proven exit for it, so it shows `unknown`. A first attempt, "no exit code means unproven", also flipped synthetic Git-formatter test results that carry no metadata. The explicit mark keeps the change to the one shape the review found. Correlating the later `write_stdin` exit back to the card by session id is a separate feature, not done here. +- **P2: two carriers.** In extended-history rollouts, one call can have both the event and the wrapper. `createCodexTranscriptEntryMapper` keeps the first exec terminal result per call_id, remembering the last 512 per stream. A pair split across a history page boundary is not caught. +- **P3: no `Output:` marker.** Without the LF `\nOutput:\n` marker the wrapper is not parsed, so no exit claim and no stripping. None of the 85,355 local wrappers lacks it. +- **Unpinned metadata.** The exact `codex` metadata is now asserted, which kills the kind/parsedCmd/command/cwd mutations. diff --git a/src/providers/codex/renderer/adapters/command.ts b/src/providers/codex/renderer/adapters/command.ts index 147792180..511c9a7cf 100644 --- a/src/providers/codex/renderer/adapters/command.ts +++ b/src/providers/codex/renderer/adapters/command.ts @@ -708,13 +708,22 @@ function commandResultEvidence( output: materialized, exitCode: nativeExit, failed, - // Native exec_command_end results always carry exit-derived evidence: - // rollout.ts computes is_error from `exit_code !== 0 || status === - // 'failed'` and stamps codex.exitCode. is_error === false is therefore a - // proven success on THIS transport — unlike code-mode - // custom_tool_call_output, whose is_error never reflects the inner - // command. - exitProven: true, + // Native exec_command_end results carry exit-derived evidence: + // rollout.ts computes is_error from the exit code on both terminal + // carriers (the exec_command_end event, and the wrapped + // function_call_output with a "Process exited with code N" header) and + // stamps codex.exitCode. is_error === false is therefore a proven + // success on THIS transport — unlike code-mode custom_tool_call_output, + // whose is_error never reflects the inner command. + // + // EXCEPT a still-running chunk (#1395 review a, P1). A wrapper whose + // header says "Process running with session ID N" is partial: the + // command goes on in that session, and its exit arrives on a later + // write_stdin result with a different call_id, which this card cannot + // see. rollout.ts marks it `exec_command_running`. Claiming success for + // it painted long-running and later-failing commands green (9,896 such + // chunks in the local corpus); its honest state is "unknown". + exitProven: codex?.kind === 'exec_command_running' ? failed : true, running: false, owned: true, } diff --git a/src/providers/codex/renderer/transcript/entries.ts b/src/providers/codex/renderer/transcript/entries.ts index ebe096acf..44e6c4c80 100644 --- a/src/providers/codex/renderer/transcript/entries.ts +++ b/src/providers/codex/renderer/transcript/entries.ts @@ -156,20 +156,40 @@ export function stripCodexExecWrapper(output: string): string { * * WHY this replaced `isCodexExecWrapperOutput` (#1321): that predicate made the * rollout mapper DROP every wrapped result, on the belief that a correlated - * `exec_command_end` event carried the same result. Codex never persists that - * event: codex-rs `rollout/src/policy.rs` lists `EventMsg::ExecCommandEnd` - * under transient events, and a census of 2,541 local rollouts found 0 of - * them against 85,355 wrapped outputs with an exit line. The drop therefore + * `exec_command_end` event carried the same result. Current Codex never + * persists that event (codex-rs `rollout/src/policy.rs` lists + * `EventMsg::ExecCommandEnd` as transient), and a census of 2,541 local + * rollouts found 0 of them against 85,355 wrapped outputs with an exit line. + * (rust-v0.107.0 through v0.131.0 did persist it in extended-history mode; + * the transcript mapper keeps the first of the two carriers.) The drop therefore * removed the ONLY copy of every `exec_command` result (Codex through 0.144) * from resumed history, and the card showed no output or exit status. */ export function codexExecWrapperExitCode(output: string): number | null { if (!output.startsWith('Chunk ID:')) return null + // WHY the marker is required (#1395 review a, P3): without it there is no + // header/body boundary, so the "header" would be the whole string and the + // unstripped wrapper would render as a finished result's output. Every one + // of 85,355 finished local wrappers has the LF marker; anything else is not + // a shape we have seen, and it falls back to a plain result with no exit + // claim (the adapter then shows an unproven outcome, not a success). const outputMarker = output.indexOf('\nOutput:\n') - const header = outputMarker === -1 ? output : output.slice(0, outputMarker) + if (outputMarker === -1) return null + const header = output.slice(0, outputMarker) const match = /\nProcess exited with code (-?\d+)(?:\n|$)/.exec(header) return match ? Number(match[1]) : null } +/** True for a wrapped exec output whose header says the process is still + * running ("Process running with session ID N"): a partial chunk whose exit + * arrives later, on a write_stdin result with another call_id. Header only, + * for the same reason as codexExecWrapperExitCode. */ +export function isCodexExecWrapperRunning(output: string): boolean { + if (!output.startsWith('Chunk ID:')) return false + const outputMarker = output.indexOf('\nOutput:\n') + if (outputMarker === -1) return false + return /\nProcess running with session ID \S+(?:\n|$)/.test(output.slice(0, outputMarker)) +} + /** Build a Claude-shaped assistant Entry containing a single * tool_use block. The `id` / `name` / `input` match Claude's * tool-use contract so downstream row renderers don't need a diff --git a/src/providers/codex/renderer/transcript/execWrappedOutput.test.ts b/src/providers/codex/renderer/transcript/execWrappedOutput.test.ts index 2fc64992c..a42801c16 100644 --- a/src/providers/codex/renderer/transcript/execWrappedOutput.test.ts +++ b/src/providers/codex/renderer/transcript/execWrappedOutput.test.ts @@ -3,6 +3,7 @@ import { describe, expect, it } from 'vitest' import fixture from '../../../../../testing/fixtures/codex-exec-output/wrapped-exec-command-output.json' import { fromCodexCommandOperation } from '@providers/codex/renderer/adapters/command' +import { createCodexTranscriptEntryMapper } from '@providers/codex/renderer/transcript/mapper' import { mapCodexRolloutToFeedEntries } from '@providers/codex/renderer/transcript/rollout' import type { ToolResultBlock, ToolUseBlock } from '@shared/types/transcript' @@ -35,6 +36,11 @@ describe('wrapped exec_command results in resumed history (#1321)', () => { expect(result!.is_error).toBe(false) expect(String(result!.content)).not.toContain('Chunk ID:') expect(String(result!.content)).toMatch(/^x+\nx+/) + // The exact metadata the event carrier stamps (#1395 review a: kind, + // parsedCmd, command and cwd were unpinned; `kind` drives row absorption). + expect((result as unknown as { codex: unknown }).codex).toEqual({ + kind: 'exec_command_end', parsedCmd: [], command: [], cwd: null, exitCode: 0, + }) const operation = fromCodexCommandOperation({ toolUse, result }) expect(operation?.model.exitCode).toBe(0) @@ -77,7 +83,72 @@ describe('wrapped exec_command results in resumed history (#1321)', () => { } const [entry] = mapCodexRolloutToFeedEntries(running) const block = ((entry as { message: { content: Array> } }).message.content)[0]! - expect(block.codex).toBeUndefined() + // Marked running, with no exit claimed from the body's words. + expect(block.codex).toEqual({ kind: 'exec_command_running' }) expect(block.content).toBe('x\nProcess exited with code 0\n') }) + + // A still-running chunk, as the fixture's real header shape with the + // "running" line Codex writes in its place (9,896 in the local corpus). + // Paired with the fixture's real exec_command call, so the adapter sees a + // genuine invocation. + const okCall = cases.ok.records[0]! + const runningPair = () => [ + okCall, + { + type: 'response_item', + timestamp: '2026-07-09T21:40:40.079Z', + payload: { + type: 'function_call_output', + call_id: (okCall.payload as { call_id: string }).call_id, + output: 'Chunk ID: aaaaaa\nWall time: 1.0000 seconds\nProcess running with session ID 42\nOriginal token count: 1\nOutput:\nworking\n', + }, + }, + ] + + it('does not paint a still-running command as a success (#1395 review a, P1)', () => { + const entries = runningPair().flatMap(record => mapCodexRolloutToFeedEntries(record)) + const blocks = entries.flatMap(entry => (entry as { message: { content: Array> } }).message.content) + const toolUse = blocks.find(block => block.type === 'tool_use') as unknown as ToolUseBlock + const result = blocks.find(block => block.type === 'tool_result') as unknown as ToolResultBlock + + const operation = fromCodexCommandOperation({ toolUse, result }) + // Its exit arrives on a later write_stdin result this card cannot see. + expect(operation?.model.status).toBe('unknown') + expect(operation?.model.exitCode).toBeNull() + }) + + it('keeps one result when a rollout persisted both carriers for a call (#1395 review a, P2)', () => { + // rust-v0.107.0..v0.131.0 persisted exec_command_end in extended-history + // mode, next to the always-durable wrapped output, with the same call_id. + const [call, output] = cases.ok.records + const callId = (call!.payload as { call_id: string }).call_id + const event = { + type: 'event_msg', + timestamp: '2026-07-09T21:40:40.000Z', + payload: { type: 'exec_command_end', call_id: callId, exit_code: 0, aggregated_output: 'ok\n' }, + } + const mapper = createCodexTranscriptEntryMapper() + const results = [call!, event, output!] + .flatMap(record => mapper.map(record).entries) + .flatMap(entry => (entry as { message: { content: Array> } }).message.content) + .filter(block => block.type === 'tool_result') + expect(results).toHaveLength(1) + expect(results[0]!.content).toBe('ok\n') + }) + + it('makes no exit claim for a wrapper without its Output marker (#1395 review a, P3)', () => { + const headerOnly = { + type: 'response_item', + timestamp: '2026-07-09T21:40:40.079Z', + payload: { + type: 'function_call_output', + call_id: 'call-header-only', + output: 'Chunk ID: aaaaaa\nWall time: 0.1000 seconds\nProcess exited with code 1\nOriginal token count: 0', + }, + } + const [entry] = mapCodexRolloutToFeedEntries(headerOnly) + const block = (entry as { message: { content: Array> } }).message.content[0]! + expect(block.codex).toBeUndefined() + }) }) diff --git a/src/providers/codex/renderer/transcript/mapper.ts b/src/providers/codex/renderer/transcript/mapper.ts index e800c1f4c..0bfbf3634 100644 --- a/src/providers/codex/renderer/transcript/mapper.ts +++ b/src/providers/codex/renderer/transcript/mapper.ts @@ -28,10 +28,36 @@ import { } from './rollout' import { codexEventType, codexTurnIdFromEventPayload } from './eventCursor' +// How many exec terminal results a mapper remembers for de-duplication. A +// duplicate carrier sits next to its twin (same turn), so a small window is +// enough, and it keeps a live session's mapper from growing without bound. +const EXEC_TERMINAL_MEMORY = 512 + export function createCodexTranscriptEntryMapper( initialTurnCursor: string | null = null, ): TranscriptEntryMapper { let turnCursor = initialTurnCursor + // WHY (#1395 review a, P2): one exec_command can have TWO terminal carriers. + // The wrapped function_call_output is always durable. The exec_command_end + // event is transient in current Codex, but rust-v0.107.0 through v0.131.0 + // persisted it in extended-history mode (app-server + // `persist_extended_history`). Both carry the same call_id, and both map to + // an `exec_command_end` result, so the feed would get two result rows for + // one card, and the card would take whichever came last. The first carrier + // wins; the other is dropped. Scoped to this mapper's stream: a history + // page starts a new mapper, so a pair split across a page boundary is not + // caught (none in the local corpus, which has no persisted event at all). + const execTerminalCalls = new Set() + const keepFirstExecTerminal = (entry: ReturnType[number]): boolean => { + const callId = execTerminalCallId(entry) + if (callId === null) return true + if (execTerminalCalls.has(callId)) return false + execTerminalCalls.add(callId) + if (execTerminalCalls.size > EXEC_TERMINAL_MEMORY) { + execTerminalCalls.delete(execTerminalCalls.values().next().value as string) + } + return true + } return { map(raw: Record): MappedTranscriptEntry { const turnContextId = codexTurnIdFromRollout(raw) @@ -39,9 +65,9 @@ export function createCodexTranscriptEntryMapper( const payloadTurnId = codexTurnIdFromEventPayload(raw) if (payloadTurnId !== null) turnCursor = payloadTurnId - const entries = mapCodexRolloutToFeedEntries(raw).map(entry => - stampCodexTurnId(entry, turnCursor), - ) + const entries = mapCodexRolloutToFeedEntries(raw) + .filter(keepFirstExecTerminal) + .map(entry => stampCodexTurnId(entry, turnCursor)) const marker = codexHistoryMarker(raw) const eventType = codexEventType(raw) @@ -84,3 +110,12 @@ export { extractCodexProviderSessionId } from './entries' export function isCodexTypedUserPrompt(_entry: unknown, text: string): boolean { return !text.startsWith('<') } + +/** The call id of an exec terminal result (either carrier), or null. */ +function execTerminalCallId(entry: ReturnType[number]): string | null { + const content = (entry as { message?: { content?: unknown } }).message?.content + if (!Array.isArray(content) || content.length !== 1) return null + const block = content[0] as { type?: unknown; tool_use_id?: unknown; codex?: { kind?: unknown } } + if (block.type !== 'tool_result' || typeof block.tool_use_id !== 'string') return null + return block.codex?.kind === 'exec_command_end' ? block.tool_use_id : null +} diff --git a/src/providers/codex/renderer/transcript/rollout.ts b/src/providers/codex/renderer/transcript/rollout.ts index 8f4e1acc7..84805315b 100644 --- a/src/providers/codex/renderer/transcript/rollout.ts +++ b/src/providers/codex/renderer/transcript/rollout.ts @@ -10,6 +10,7 @@ import { codexToolUseEntry, codexOutputText, codexExecWrapperExitCode, + isCodexExecWrapperRunning, parseCodexJson, stripCodexExecWrapper, } from '@providers/codex/renderer/transcript/entries' @@ -325,12 +326,13 @@ export function mapCodexRolloutToFeedEntries(entry: Record): En // result after it has updated the command card, so retaining terminal // evidence does not reintroduce a blank standalone row. // - // WHERE this event comes from (#1321): not from rollouts. codex-rs - // persists `ExecCommandEnd` as a transient event, and 0 of 2,541 local - // rollouts contain one. The durable carrier of an exec_command result is - // the wrapped `function_call_output` below, which is stamped with this - // same metadata. This branch stays for any stream that does carry the - // event; the existing mapper tests feed it directly. + // WHERE this event comes from (#1321): almost never a rollout. Current + // codex-rs treats `ExecCommandEnd` as transient, and 0 of 2,541 local + // rollouts contain one. rust-v0.107.0 through v0.131.0 persisted it in + // extended-history mode (app-server `persist_extended_history`), next to + // the always-durable wrapped `function_call_output` below, which is + // stamped with this same metadata. createCodexTranscriptEntryMapper + // keeps the first of the two for a call_id (#1395 review a). return [ codexToolResultEntry( uuid, @@ -462,6 +464,12 @@ export function mapCodexRolloutToFeedEntries(entry: Record): En }), ] } + if (isCodexExecWrapperRunning(structured)) { + // A partial chunk of a command still running (#1395 review a, P1). Its + // bytes are real output; its outcome is not known yet, so it is marked + // for the command adapter, which then shows "unknown" instead of success. + return [codexToolResultEntry(uuid, timestamp, payload.call_id, output, false, { kind: 'exec_command_running' })] + } if (!output.trim()) return [] return [codexToolResultEntry(uuid, timestamp, payload.call_id, output)] } From bd76b4bff5899fda6280ef195e262a2c64526952 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 03:03:47 -0700 Subject: [PATCH 11/40] fix(feed-debug): write through a forget during the first size check; retry unacknowledged releases (#1392 review round 3) A process-exit forget landing during the first stat dropped the batch and resolved, so the renderer skipped rows that were never written. The append now re-installs its placeholder and writes; the retired token drops the state afterwards. A release main did not acknowledge is retried next tick. Adds IPC handler tests and an in-flight reservation test. Co-Authored-By: Claude Opus 5.5 --- src/main/ipc/debug.test.ts | 27 +++++++++++++++++ src/main/storage/feedDebugLog.test.ts | 29 ++++++++++++++++++- src/main/storage/feedDebugLog.ts | 12 ++++++-- .../useFeedDebugPersist.renderer.test.tsx | 29 +++++++++++++++++++ .../hook/persistence/useFeedDebugPersist.ts | 14 +++++++-- 5 files changed, 104 insertions(+), 7 deletions(-) diff --git a/src/main/ipc/debug.test.ts b/src/main/ipc/debug.test.ts index 6574264d1..b67e8db22 100644 --- a/src/main/ipc/debug.test.ts +++ b/src/main/ipc/debug.test.ts @@ -4,6 +4,7 @@ const harness = vi.hoisted(() => ({ handlers: new Map unknown>(), order: [] as string[], queueFeedDebugAppend: vi.fn<(sessionId: string, entries: unknown[], epochMs?: number) => Promise>(async () => {}), + forgetFeedDebugSession: vi.fn<(sessionId: string) => void>(), saveDebugBundle: vi.fn(async () => { harness.order.push('save') return { bundlePath: '/tmp/test-bundle' } @@ -27,6 +28,7 @@ vi.mock('@main/storage/debugBundleLog.js', () => ({ })) vi.mock('@main/storage/feedDebugLog.js', () => ({ queueFeedDebugAppend: harness.queueFeedDebugAppend, + forgetFeedDebugSession: harness.forgetFeedDebugSession, })) vi.mock('@main/storage/proxyEventsReader.js', () => ({ readProxyEventsForBundle: vi.fn(async () => null), @@ -172,3 +174,28 @@ describe('debug:append-feed-log forwarding (#770)', () => { .rejects.toThrow('unknown size') }) }) + +// #1392: the renderer's release of a closed pane's feed-debug log. +describe('debug:forget-feed-log', () => { + const forgetHandler = () => { + registerDebugIpc({} as never, {} as never) + const handler = harness.handlers.get('debug:forget-feed-log') + if (!handler) throw new Error('debug:forget-feed-log was not registered') + return handler + } + + it('forgets the named session in main', () => { + harness.forgetFeedDebugSession.mockClear() + forgetHandler()({}, { sessionId: 'closed-pane' }) + expect(harness.forgetFeedDebugSession).toHaveBeenCalledExactlyOnceWith('closed-pane') + }) + + it.each([undefined, null, {}, { sessionId: '' }, { sessionId: 7 }, { sessionId: ['a'] }])( + 'ignores malformed input %j', + params => { + harness.forgetFeedDebugSession.mockClear() + expect(() => forgetHandler()({}, params)).not.toThrow() + expect(harness.forgetFeedDebugSession).not.toHaveBeenCalled() + }, + ) +}) diff --git a/src/main/storage/feedDebugLog.test.ts b/src/main/storage/feedDebugLog.test.ts index a161950ac..6a5fe0968 100644 --- a/src/main/storage/feedDebugLog.test.ts +++ b/src/main/storage/feedDebugLog.test.ts @@ -10,7 +10,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' // `.then` advances the cursor and never resends. The comment described an // intention the code did not implement, and nothing was watching. -let statResult: { mode: 'real' } | { mode: 'throw'; code: string } = { mode: 'real' } +let statResult: { mode: 'real' } | { mode: 'throw'; code: string } | { mode: 'hold'; gate: Promise; reached: () => void } = { mode: 'real' } let stateDir = '' vi.mock('node:fs/promises', async () => { @@ -19,6 +19,11 @@ vi.mock('node:fs/promises', async () => { ...real, default: real, stat: async (path: Parameters[0]) => { + if (statResult.mode === 'hold') { + const held = statResult + held.reached() + await held.gate + } if (statResult.mode === 'throw') { const err = new Error('stat refused') as NodeJS.ErrnoException err.code = statResult.code @@ -205,3 +210,25 @@ describe('forget racing a queued append, other interleavings (#1392)', () => { await expect(queueFeedDebugAppend('still-unknown', [entry(2)], 1_000)).rejects.toThrow() }) }) + +// #1392 review a, round 3: process exit forgets the session while the pane +// (and its log) stay live. A forget landing during the first `stat` used to +// drop the batch and RESOLVE, so the renderer advanced its cursor past rows +// that were never written. +describe('a forget during the first size check (#1392)', () => { + it('still writes the batch, then leaves no state behind', async () => { + const { feedDebugSessionStateSizesForTest } = await import('./feedDebugLog.js') + let release!: () => void + let reached!: () => void + const atStat = new Promise(resolve => { reached = resolve }) + statResult = { mode: 'hold', gate: new Promise(resolve => { release = resolve }), reached } + const write = queueFeedDebugAppend('exit-during-stat', [entry(1)], 1_000) + await atStat + forgetFeedDebugSession('exit-during-stat') + statResult = { mode: 'real' } + release() + await write + expect(await readFile(logPath('exit-during-stat'), 'utf8')).toContain('"id":1') + expect(feedDebugSessionStateSizesForTest('exit-during-stat')).toEqual({ ids: 0, epochs: 0, caps: 0, tokens: 0 }) + }) +}) diff --git a/src/main/storage/feedDebugLog.ts b/src/main/storage/feedDebugLog.ts index 8dc0711a1..37dbfc8a4 100644 --- a/src/main/storage/feedDebugLog.ts +++ b/src/main/storage/feedDebugLog.ts @@ -284,9 +284,15 @@ export function queueFeedDebugAppend( feedDebugCapState.set(sessionId, capState) const startingBytes = await loadInitialFileBytes(filePath) if (feedDebugCapState.get(sessionId) !== capState) { - // forgetFeedDebugSession ran during the stat await — the session is - // gone. Drop this final batch rather than resurrect state for it. - return + // forgetFeedDebugSession ran during the stat await. This used to + // `return`, dropping the batch, and that RESOLVED the IPC: the + // renderer advanced its cursor past rows that were never written + // (#1392 review a, round 3). The forget comes from PROCESS exit + // while the pane, and its log, are still live, so the rows are + // real. Write them: re-install this placeholder (appends are + // serialized per session, so nothing else can own it) and let the + // retired token drop the state again when this append settles. + feedDebugCapState.set(sessionId, capState) } if (startingBytes === null) { // Unknown on-disk size (stat failed, not-ENOENT). Fail CLOSED: diff --git a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx index 50b789eed..79400aec4 100644 --- a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx +++ b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx @@ -298,6 +298,35 @@ describe('releasing a session whose runtime is gone (#1392)', () => { expect(forget).toHaveBeenCalledTimes(1) }) + it('retries a release main did not acknowledge', async () => { + const refs = makeRefs({ a: add(emptyRuntime(), 'a row') }) + renderHook(() => useFeedDebugPersist(refs)) + await advance(1_000) + forget.mockRejectedValueOnce(new Error('ipc down')) + refs.latestRuntimesRef.current = {} + await advance(1_000) + await advance(1_000) + expect(forget).toHaveBeenCalledTimes(2) + await advance(2_000) + expect(forget).toHaveBeenCalledTimes(2) + }) + + it('drops the in-flight reservation, so a re-added id can flush again', async () => { + const pending = deferred() + append.mockReturnValueOnce(pending.promise) + const refs = makeRefs({ a: add(emptyRuntime(), 'first') }) + renderHook(() => useFeedDebugPersist(refs)) + await advance(1_000) + expect(refs.inFlightFeedDebugIdRef.current.a).toBe(1) + refs.latestRuntimesRef.current = {} + await advance(1_000) + expect(refs.inFlightFeedDebugIdRef.current).not.toHaveProperty('a') + refs.latestRuntimesRef.current = { a: add(emptyRuntime(), 'new generation') } + await advance(1_000) + expect(append).toHaveBeenCalledTimes(2) + pending.resolve() + }) + it('does not forget a session that never had a runtime while mounted', async () => { const refs = makeRefs({}) renderHook(() => useFeedDebugPersist(refs)) diff --git a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts index 1c222c8aa..553563498 100644 --- a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts +++ b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts @@ -139,15 +139,23 @@ export function useFeedDebugPersist(refs: WorkspaceRefs): void { // // Entries not yet flushed when the runtime was removed are lost, as they // were before: this changes only what is forgotten, not what is written. + // + // An id leaves `known` only once main has ACKNOWLEDGED the release: a + // failed IPC is retried on the next tick (#1392 review a, round 3), or + // main would keep that session's state until the process exits. + // `releasing` stops a slow acknowledgement from sending it twice. const known = new Set() + const releasing = new Set() const releaseGone = (): void => { const runtimes = refs.latestRuntimesRef.current for (const sessionId of known) { - if (runtimes[sessionId]) continue - known.delete(sessionId) + if (runtimes[sessionId] || releasing.has(sessionId)) continue delete refs.persistedFeedDebugIdRef.current[sessionId] delete refs.inFlightFeedDebugIdRef.current[sessionId] - void window.api.forgetFeedDebugLog({ sessionId }).catch(() => {}) + releasing.add(sessionId) + void window.api.forgetFeedDebugLog({ sessionId }) + .then(() => { if (!refs.latestRuntimesRef.current[sessionId]) known.delete(sessionId) }, () => {}) + .finally(() => releasing.delete(sessionId)) } } From 84ef2f1a405ee4870c45ce80762045c97b8bca30 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 03:20:13 -0700 Subject: [PATCH 12/40] fix(feed-debug): keep a capped file's drop count across a rebuilt cap state; scope a release to its lifetime (#1392 review round 4) A rebuilt cap state now seeds its drop count from the file's last tombstone, so the last marker stays within 2x of the truth. A late release ACK no longer retires a later lifetime of the same id, a synchronous throw from a partial API becomes a retried rejection, and slow-ACK duplicate suppression is pinned. Co-Authored-By: Claude Opus 5.5 --- src/main/storage/feedDebugLog.test.ts | 46 +++++++++++++++++++ src/main/storage/feedDebugLog.ts | 43 ++++++++++++++++- .../useFeedDebugPersist.renderer.test.tsx | 44 ++++++++++++++++++ .../hook/persistence/useFeedDebugPersist.ts | 22 ++++++++- 4 files changed, 152 insertions(+), 3 deletions(-) diff --git a/src/main/storage/feedDebugLog.test.ts b/src/main/storage/feedDebugLog.test.ts index 6a5fe0968..fada13e35 100644 --- a/src/main/storage/feedDebugLog.test.ts +++ b/src/main/storage/feedDebugLog.test.ts @@ -232,3 +232,49 @@ describe('a forget during the first size check (#1392)', () => { expect(feedDebugSessionStateSizesForTest('exit-during-stat')).toEqual({ ids: 0, epochs: 0, caps: 0, tokens: 0 }) }) }) + +// #1392 review a, round 4: cap state is rebuilt whenever a session is +// forgotten and appends again. A rebuilt state started its drop count at 0, +// so its tombstone reported 1 drop after an earlier row had reported 1,000. +describe('a rebuilt cap state keeps the file\'s drop count', () => { + async function cappedFileWithMarker(sessionId: string, drops: number) { + await mkdir(join(stateDir, 'feed-debug'), { recursive: true }) + await writeFile(logPath(sessionId), '') + await truncate(logPath(sessionId), 128 * 1024 * 1024) + await writeFile(logPath(sessionId), JSON.stringify({ sessionId, __feedDebugCapped: true, droppedEntriesSoFar: drops }) + '\n', { flag: 'a' }) + } + async function lastMarkerDrops(sessionId: string): Promise { + const handle = await open(logPath(sessionId), 'r') + try { + const size = (await handle.stat()).size + const tail = Buffer.alloc(4096) + await handle.read(tail, 0, 4096, size - 4096) + const rows = tail.toString('utf8').split('\n').filter(row => row.includes('__feedDebugCapped')) + return (JSON.parse(rows.at(-1)!) as { droppedEntriesSoFar: number }).droppedEntriesSoFar + } finally { + await handle.close() + } + } + + it('after a forget and a new append', async () => { + await cappedFileWithMarker('capped-rebuilt', 1_000) + forgetFeedDebugSession('capped-rebuilt') + await queueFeedDebugAppend('capped-rebuilt', [entry(1)], 1_000) + expect(await lastMarkerDrops('capped-rebuilt')).toBeGreaterThanOrEqual(1_001) + }) + + it('after a forget during the first size check', async () => { + await cappedFileWithMarker('capped-during-stat', 1_000) + let release!: () => void + let reached!: () => void + const atStat = new Promise(resolve => { reached = resolve }) + statResult = { mode: 'hold', gate: new Promise(resolve => { release = resolve }), reached } + const write = queueFeedDebugAppend('capped-during-stat', [entry(1)], 1_000) + await atStat + forgetFeedDebugSession('capped-during-stat') + statResult = { mode: 'real' } + release() + await write + expect(await lastMarkerDrops('capped-during-stat')).toBeGreaterThanOrEqual(1_001) + }) +}) diff --git a/src/main/storage/feedDebugLog.ts b/src/main/storage/feedDebugLog.ts index 37dbfc8a4..0d958365b 100644 --- a/src/main/storage/feedDebugLog.ts +++ b/src/main/storage/feedDebugLog.ts @@ -1,4 +1,4 @@ -import { mkdir, stat, writeFile } from 'fs/promises' +import { mkdir, open, stat, writeFile } from 'fs/promises' import { join } from 'path' import { FEED_DEBUG_DIR } from '@main/storage/paths.js' @@ -74,6 +74,44 @@ async function loadInitialFileBytes(filePath: string): Promise { } } +// The drop count of the last tombstone row in an already-capped file, or 0. +// +// WHY (#1392 review a, round 4): cap state is process-local and is rebuilt +// whenever a session is forgotten and appends again (process exit with the +// pane still open, a same-id wake, a forget during the first `stat`). A +// rebuilt state started at `droppedEntries: 0`, so its first tombstone +// reported 1 drop after an earlier row had reported thousands, and the LAST +// marker in the file, which the doubling rule promises is within 2x of the +// truth, understated it by orders of magnitude. Re-statting bytes restores the +// size decision; this restores the count. Only the file's tail is read (the +// tombstone rows are the last lines of a capped file), and any failure falls +// back to 0, the old behaviour. +const TOMBSTONE_TAIL_BYTES = 64 * 1024 +async function readLastTombstoneDrops(filePath: string, size: number): Promise { + try { + const handle = await open(filePath, 'r') + try { + const length = Math.min(size, TOMBSTONE_TAIL_BYTES) + const buffer = Buffer.alloc(length) + await handle.read(buffer, 0, length, size - length) + const lines = buffer.toString('utf8').split('\n') + for (let i = lines.length - 1; i >= 0; i--) { + if (!lines[i]!.includes('"__feedDebugCapped":true')) continue + // From the row's first `{`: a tail can start mid-row, and a file that + // was preallocated or torn can carry NUL bytes before the row. + const row = lines[i]!.slice(lines[i]!.indexOf('{')) + const drops = (JSON.parse(row) as { droppedEntriesSoFar?: unknown }).droppedEntriesSoFar + return typeof drops === 'number' && Number.isFinite(drops) && drops > 0 ? drops : 0 + } + } finally { + await handle.close() + } + } catch { + // Unreadable tail or a torn row: the pre-#1392 count of 0. + } + return 0 +} + // Per-session feed-debug log writer. // // Why a per-session serialized queue instead of fire-and-forget writes: @@ -312,6 +350,9 @@ export function queueFeedDebugAppend( throw new Error(`feed-debug: unknown size for ${sessionId}, refusing to append`) } capState.bytesWritten = startingBytes + if (startingBytes >= MAX_FEED_DEBUG_FILE_BYTES) { + capState.droppedEntries = await readLastTombstoneDrops(filePath, startingBytes) + } } // Already capped in a prior batch — count, drop, and keep the on-disk diff --git a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx index 79400aec4..a6687fb4b 100644 --- a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx +++ b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx @@ -327,6 +327,50 @@ describe('releasing a session whose runtime is gone (#1392)', () => { pending.resolve() }) + it('sends one release while its acknowledgement is pending', async () => { + const ack = deferred() + forget.mockReturnValueOnce(ack.promise) + const refs = makeRefs({ a: add(emptyRuntime(), 'a row') }) + renderHook(() => useFeedDebugPersist(refs)) + await advance(1_000) + refs.latestRuntimesRef.current = {} + await advance(4_000) + expect(forget).toHaveBeenCalledTimes(1) + ack.resolve() + await advance(2_000) + expect(forget).toHaveBeenCalledTimes(1) + }) + + it('does not let a late acknowledgement retire a later lifetime of the same id', async () => { + const ack = deferred() + forget.mockReturnValueOnce(ack.promise) + const first = add(emptyRuntime(), 'first lifetime') + const refs = makeRefs({ a: first }) + renderHook(() => useFeedDebugPersist(refs)) + await advance(1_000) + refs.latestRuntimesRef.current = {} + await advance(1_000) + expect(forget).toHaveBeenCalledTimes(1) + // The id comes back and appends (main re-creates its state), then goes + // away again, all before the first release is acknowledged. + refs.latestRuntimesRef.current = { a: add(emptyRuntime(), 'second lifetime') } + await advance(1_000) + expect(append).toHaveBeenCalledTimes(2) + refs.latestRuntimesRef.current = {} + ack.resolve() + await advance(2_000) + expect(forget).toHaveBeenCalledTimes(2) + }) + + it('does not throw from the interval when the API lacks the release method', async () => { + Object.defineProperty(window, 'api', { configurable: true, value: { appendFeedDebugLog: append } }) + const refs = makeRefs({ a: add(emptyRuntime(), 'a row') }) + renderHook(() => useFeedDebugPersist(refs)) + await advance(1_000) + refs.latestRuntimesRef.current = {} + await expect(advance(3_000)).resolves.toBeUndefined() + }) + it('does not forget a session that never had a runtime while mounted', async () => { const refs = makeRefs({}) renderHook(() => useFeedDebugPersist(refs)) diff --git a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts index 553563498..3b28ce3d4 100644 --- a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts +++ b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts @@ -144,8 +144,20 @@ export function useFeedDebugPersist(refs: WorkspaceRefs): void { // failed IPC is retried on the next tick (#1392 review a, round 3), or // main would keep that session's state until the process exits. // `releasing` stops a slow acknowledgement from sending it twice. + // + // A release covers only the lifetime it was SENT for (#1392 review b, + // round 4): if the id reappears (and appends, re-creating main's state) + // while an acknowledgement is still in flight, that late ACK must not + // retire the later lifetime. `seenSinceRelease` records a reappearance; + // the ACK then leaves the id in `known`, and the next absence sends a new + // release. + // + // Known residual: a release that fails during the hook's own teardown + // (workspace unmount) has no later tick to retry it. Main keeps that one + // session's few numbers until it exits. const known = new Set() const releasing = new Set() + const seenSinceRelease = new Set() const releaseGone = (): void => { const runtimes = refs.latestRuntimesRef.current for (const sessionId of known) { @@ -153,8 +165,13 @@ export function useFeedDebugPersist(refs: WorkspaceRefs): void { delete refs.persistedFeedDebugIdRef.current[sessionId] delete refs.inFlightFeedDebugIdRef.current[sessionId] releasing.add(sessionId) - void window.api.forgetFeedDebugLog({ sessionId }) - .then(() => { if (!refs.latestRuntimesRef.current[sessionId]) known.delete(sessionId) }, () => {}) + seenSinceRelease.delete(sessionId) + // Promise.resolve().then: a synchronous throw (a test double without + // the method) becomes a rejection, retried like any failed release, + // instead of escaping the interval with `releasing` held. + void Promise.resolve() + .then(() => window.api.forgetFeedDebugLog({ sessionId })) + .then(() => { if (!seenSinceRelease.has(sessionId)) known.delete(sessionId) }, () => {}) .finally(() => releasing.delete(sessionId)) } } @@ -162,6 +179,7 @@ export function useFeedDebugPersist(refs: WorkspaceRefs): void { const flush = (): void => { for (const [sessionId, runtime] of Object.entries(refs.latestRuntimesRef.current)) { known.add(sessionId) + if (releasing.has(sessionId)) seenSinceRelease.add(sessionId) flushSession(sessionId, runtime) } releaseGone() From 99ac38a6b1ed1e8ce4e6a25605dd1a1f5e0b8773 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 03:32:56 -0700 Subject: [PATCH 13/40] fix(feed-debug): persist a capped session's unmarked drops before forgetting them (#1392 review b round 5) Drops are written only at a doubling, so each forget discarded up to half; repeated forgets made the last marker a fraction of the truth. Forget now chains a final marker on the session's write queue. A crash still loses the unmarked drops (stated). Co-Authored-By: Claude Opus 5.5 --- src/main/storage/feedDebugLog.test.ts | 18 +++++++++++++ src/main/storage/feedDebugLog.ts | 38 ++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/main/storage/feedDebugLog.test.ts b/src/main/storage/feedDebugLog.test.ts index fada13e35..c47dfb1dc 100644 --- a/src/main/storage/feedDebugLog.test.ts +++ b/src/main/storage/feedDebugLog.test.ts @@ -263,6 +263,24 @@ describe('a rebuilt cap state keeps the file\'s drop count', () => { expect(await lastMarkerDrops('capped-rebuilt')).toBeGreaterThanOrEqual(1_001) }) + // Review b, round 5: drops are only persisted at a doubling, so a forget + // discarded up to half of them. Three forget cycles of 1 + 999 drops each + // on a file marked at 1,000 used to leave a last marker of 1,003 for 4,000 + // true drops. + it('across repeated forgets, the last marker stays within 2x of the true drops', async () => { + await cappedFileWithMarker('capped-cycles', 1_000) + let id = 0 + for (let cycle = 0; cycle < 3; cycle++) { + forgetFeedDebugSession('capped-cycles') + await queueFeedDebugAppend('capped-cycles', [entry(++id)], 1_000) + await queueFeedDebugAppend('capped-cycles', Array.from({ length: 999 }, () => entry(++id)), 1_000) + } + forgetFeedDebugSession('capped-cycles') + await queueFeedDebugAppend('capped-cycles', [], 1_000) + await new Promise(resolve => setTimeout(resolve, 20)) + expect(await lastMarkerDrops('capped-cycles')).toBeGreaterThanOrEqual(4_000) + }) + it('after a forget during the first size check', async () => { await cappedFileWithMarker('capped-during-stat', 1_000) let release!: () => void diff --git a/src/main/storage/feedDebugLog.ts b/src/main/storage/feedDebugLog.ts index 0d958365b..c628c6310 100644 --- a/src/main/storage/feedDebugLog.ts +++ b/src/main/storage/feedDebugLog.ts @@ -284,7 +284,7 @@ export function queueFeedDebugAppend( const freshEntries = entries.filter(entry => entry.id > lastWritten) if (freshEntries.length === 0) return await mkdir(FEED_DEBUG_DIR, { recursive: true }) - const filePath = join(FEED_DEBUG_DIR, `${sanitizeSessionIdForPath(sessionId)}.jsonl`) + const filePath = feedDebugFilePath(sessionId) // Per-file cap bookkeeping. The counter is process-local: the on-disk // file might already contain bytes from a previous run (feed-debug lives @@ -499,6 +499,41 @@ export function feedDebugSessionStateSizesForTest(sessionId?: string): { ids: nu * long-since-closed panes still benefit from reading the trail. The * unified sweep in storage/debugRetention.ts is what eventually * deletes the file. */ +function feedDebugFilePath(sessionId: string): string { + return join(FEED_DEBUG_DIR, `${sanitizeSessionIdForPath(sessionId)}.jsonl`) +} + +/** + * Write the drops a capped session counted since its last on-disk marker, + * before its in-memory count is forgotten (#1392 review b, round 5). + * + * WHY: drops are persisted only at a doubling, so up to half of them live + * only in memory. Every forget (process exit with the pane open, a same-id + * wake, the renderer's release) used to discard them, and a session that + * crossed a few forgets reported a fraction of its true total in its last + * marker, breaking the 2x promise. Chained on the session's write queue so it + * lands after any append already queued, which makes it the file's LAST + * marker (the one readLastTombstoneDrops and forensics read). Best effort: a + * failed write loses only what the old code always lost. + * + * Residual: a crash or a kill of main still loses the unmarked drops. Only a + * write per drop could avoid that, which is what the doubling rule exists to + * prevent. + */ +function flushUnmarkedDrops(sessionId: string, capState: FeedDebugCapState | undefined): void { + if (!capState?.tombstoneWritten || capState.droppedEntries <= capState.lastTombstoneDrops) return + const line = buildTombstoneLine(sessionId, capState) + const previous = feedDebugWriteQueues.get(sessionId) ?? Promise.resolve() + const next = previous + .catch(() => {}) + .then(() => writeFile(feedDebugFilePath(sessionId), line, { encoding: 'utf8', flag: 'a' })) + .catch(() => {}) + feedDebugWriteQueues.set(sessionId, next) + void next.then(() => { + if (feedDebugWriteQueues.get(sessionId) === next) feedDebugWriteQueues.delete(sessionId) + }) +} + export function forgetFeedDebugSession(sessionId: string): void { // We never delete `feedDebugWriteQueues` synchronously here — // there might be an in-flight write that still owns the chain. @@ -514,5 +549,6 @@ export function forgetFeedDebugSession(sessionId: string): void { // in this process, we'll re-stat the on-disk file and prime a fresh counter; // never carrying stale cap state across "session forgotten" boundaries keeps // the map from growing unbounded across long-lived main processes. + flushUnmarkedDrops(sessionId, feedDebugCapState.get(sessionId)) feedDebugCapState.delete(sessionId) } From d14fb4262c4e614d9dc5f35ec8c10dfb502a2131 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 03:34:38 -0700 Subject: [PATCH 14/40] fix(feed-debug): harden the tombstone tail reader (#1392 review a round 5) Seed from any non-empty file (a marker can land below the cap), accept only rows whose parsed top level is a tombstone, skip torn rows instead of giving up, and close a torn last row before this session's first write. Co-Authored-By: Claude Opus 5.5 --- src/main/storage/feedDebugLog.test.ts | 51 ++++++++++++++++++++++- src/main/storage/feedDebugLog.ts | 58 ++++++++++++++++++++------- 2 files changed, 93 insertions(+), 16 deletions(-) diff --git a/src/main/storage/feedDebugLog.test.ts b/src/main/storage/feedDebugLog.test.ts index c47dfb1dc..515e1d4bc 100644 --- a/src/main/storage/feedDebugLog.test.ts +++ b/src/main/storage/feedDebugLog.test.ts @@ -249,8 +249,17 @@ describe('a rebuilt cap state keeps the file\'s drop count', () => { const size = (await handle.stat()).size const tail = Buffer.alloc(4096) await handle.read(tail, 0, 4096, size - 4096) - const rows = tail.toString('utf8').split('\n').filter(row => row.includes('__feedDebugCapped')) - return (JSON.parse(rows.at(-1)!) as { droppedEntriesSoFar: number }).droppedEntriesSoFar + const tailSize = Math.min(size, 16_384) + const wide = Buffer.alloc(tailSize) + await handle.read(wide, 0, tailSize, size - tailSize) + const markers = wide.toString('utf8').split('\n').flatMap(row => { + try { + const parsed = JSON.parse(row.slice(row.indexOf('{'))) as { __feedDebugCapped?: unknown; droppedEntriesSoFar?: number } + return parsed.__feedDebugCapped === true ? [parsed.droppedEntriesSoFar ?? 0] : [] + } catch { return [] } + }) + void tail + return markers.at(-1) ?? -1 } finally { await handle.close() } @@ -281,6 +290,44 @@ describe('a rebuilt cap state keeps the file\'s drop count', () => { expect(await lastMarkerDrops('capped-cycles')).toBeGreaterThanOrEqual(4_000) }) + // Round-5 review a: the tail reader's three blind spots. + it('below the cap: a marker written by an oversized entry keeps its count', async () => { + await mkdir(join(stateDir, 'feed-debug'), { recursive: true }) + await writeFile(logPath('below-cap'), '') + await truncate(logPath('below-cap'), 128 * 1024 * 1024 - 500) + await writeFile(logPath('below-cap'), '\n', { flag: 'a' }) + const big = (id: number) => ({ ...entry(id), summary: 'x'.repeat(1_000) }) + await queueFeedDebugAppend('below-cap', [big(1)], 1_000) + forgetFeedDebugSession('below-cap') + await queueFeedDebugAppend('below-cap', [big(2)], 1_000) + expect(await lastMarkerDrops('below-cap')).toBeGreaterThanOrEqual(2) + }) + + it('an ordinary row carrying the marker text in its data does not hide the real marker', async () => { + await cappedFileWithMarker('marker-in-data', 1_000) + await writeFile(logPath('marker-in-data'), JSON.stringify({ sessionId: 'marker-in-data', id: 9, data: { __feedDebugCapped: true, note: 'ordinary entry' } }) + '\n', { flag: 'a' }) + forgetFeedDebugSession('marker-in-data') + await queueFeedDebugAppend('marker-in-data', [entry(1)], 1_000) + expect(await lastMarkerDrops('marker-in-data')).toBeGreaterThanOrEqual(1_001) + }) + + it('a torn final row neither hides the earlier marker nor swallows the next row', async () => { + await cappedFileWithMarker('torn-tail', 1_000) + await writeFile(logPath('torn-tail'), '{"sessionId":"torn-tail","__feedDebugCapped":true,"droppedEntriesSoFar":20', { flag: 'a' }) + forgetFeedDebugSession('torn-tail') + await queueFeedDebugAppend('torn-tail', [entry(1)], 1_000) + expect(await lastMarkerDrops('torn-tail')).toBeGreaterThanOrEqual(1_001) + }) + + it('finds a marker behind several KiB of later rows', async () => { + await cappedFileWithMarker('rows-after-marker', 1_000) + const rows = Array.from({ length: 80 }, (_, i) => JSON.stringify({ sessionId: 'rows-after-marker', id: 100 + i, summary: 'y'.repeat(100) }) + '\n').join('') + await writeFile(logPath('rows-after-marker'), rows, { flag: 'a' }) + forgetFeedDebugSession('rows-after-marker') + await queueFeedDebugAppend('rows-after-marker', [entry(1)], 1_000) + expect(await lastMarkerDrops('rows-after-marker')).toBeGreaterThanOrEqual(1_001) + }) + it('after a forget during the first size check', async () => { await cappedFileWithMarker('capped-during-stat', 1_000) let release!: () => void diff --git a/src/main/storage/feedDebugLog.ts b/src/main/storage/feedDebugLog.ts index c628c6310..dd978bb9a 100644 --- a/src/main/storage/feedDebugLog.ts +++ b/src/main/storage/feedDebugLog.ts @@ -74,7 +74,8 @@ async function loadInitialFileBytes(filePath: string): Promise { } } -// The drop count of the last tombstone row in an already-capped file, or 0. +// The drop count of the file's last tombstone row (0 if none), and whether +// the file ends with a complete row. // // WHY (#1392 review a, round 4): cap state is process-local and is rebuilt // whenever a session is forgotten and appends again (process exit with the @@ -83,33 +84,53 @@ async function loadInitialFileBytes(filePath: string): Promise { // reported 1 drop after an earlier row had reported thousands, and the LAST // marker in the file, which the doubling rule promises is within 2x of the // truth, understated it by orders of magnitude. Re-statting bytes restores the -// size decision; this restores the count. Only the file's tail is read (the -// tombstone rows are the last lines of a capped file), and any failure falls -// back to 0, the old behaviour. +// size decision; this restores the count. Only the file's tail is read, and +// any failure falls back to 0, the old behaviour. const TOMBSTONE_TAIL_BYTES = 64 * 1024 -async function readLastTombstoneDrops(filePath: string, size: number): Promise { +async function readFileTail(filePath: string, size: number): Promise<{ drops: number; endsWithNewline: boolean }> { + // Round-5 review a hardened this reader three ways: + // - it runs for ANY non-empty file, not only one at the cap: an entry too + // big to fit can write a short marker and leave the file BELOW the cap; + // - a row counts only if its PARSED top level is a tombstone. An ordinary + // entry can carry the marker text inside `data`, and a substring match + // let it hide the real marker; + // - an unparsable row (torn by a failed append) is skipped, not fatal, so + // an earlier complete marker is still found. + // Cost: one read of at most 64 KiB per session per process, at its first + // append. A marker further back than that (more than 64 KiB of ordinary + // rows written after it) is not found, which is the old behaviour. + const result = { drops: 0, endsWithNewline: true } try { const handle = await open(filePath, 'r') try { const length = Math.min(size, TOMBSTONE_TAIL_BYTES) const buffer = Buffer.alloc(length) await handle.read(buffer, 0, length, size - length) + result.endsWithNewline = length === 0 || buffer[length - 1] === 0x0a const lines = buffer.toString('utf8').split('\n') for (let i = lines.length - 1; i >= 0; i--) { - if (!lines[i]!.includes('"__feedDebugCapped":true')) continue + const line = lines[i]! + if (!line.includes('__feedDebugCapped')) continue // From the row's first `{`: a tail can start mid-row, and a file that // was preallocated or torn can carry NUL bytes before the row. - const row = lines[i]!.slice(lines[i]!.indexOf('{')) - const drops = (JSON.parse(row) as { droppedEntriesSoFar?: unknown }).droppedEntriesSoFar - return typeof drops === 'number' && Number.isFinite(drops) && drops > 0 ? drops : 0 + let row: { __feedDebugCapped?: unknown; droppedEntriesSoFar?: unknown } + try { + row = JSON.parse(line.slice(line.indexOf('{'))) + } catch { + continue + } + if (row.__feedDebugCapped !== true) continue + const drops = row.droppedEntriesSoFar + result.drops = typeof drops === 'number' && Number.isFinite(drops) && drops > 0 ? drops : 0 + break } } finally { await handle.close() } } catch { - // Unreadable tail or a torn row: the pre-#1392 count of 0. + // Unreadable tail: the pre-#1392 count of 0. } - return 0 + return result } // Per-session feed-debug log writer. @@ -350,8 +371,17 @@ export function queueFeedDebugAppend( throw new Error(`feed-debug: unknown size for ${sessionId}, refusing to append`) } capState.bytesWritten = startingBytes - if (startingBytes >= MAX_FEED_DEBUG_FILE_BYTES) { - capState.droppedEntries = await readLastTombstoneDrops(filePath, startingBytes) + if (startingBytes > 0) { + const tail = await readFileTail(filePath, startingBytes) + capState.droppedEntries = tail.drops + if (!tail.endsWithNewline) { + // A torn last row (a failed append) has no newline, so this + // session's first row would be glued onto it and neither would + // parse. Close the torn row first. Best effort: if this fails the + // append below fails the same way and the renderer retries. + await writeFile(filePath, '\n', { encoding: 'utf8', flag: 'a' }) + capState.bytesWritten += 1 + } } } @@ -513,7 +543,7 @@ function feedDebugFilePath(sessionId: string): string { * crossed a few forgets reported a fraction of its true total in its last * marker, breaking the 2x promise. Chained on the session's write queue so it * lands after any append already queued, which makes it the file's LAST - * marker (the one readLastTombstoneDrops and forensics read). Best effort: a + * marker (the one readFileTail and forensics read). Best effort: a * failed write loses only what the old code always lost. * * Residual: a crash or a kill of main still loses the unmarked drops. Only a From 63553e5c312abfd8633dcf8528085f6a5271b1df Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 03:43:34 -0700 Subject: [PATCH 15/40] fix(codex): unparsed wrappers are unknown; the fuller wrapper wins over a persisted event (review b) Co-Authored-By: Claude Opus 5.5 --- .../2026-09-27-codex-exec-wrapped-output.md | 7 ++- .../codex/renderer/adapters/command.ts | 6 +- .../codex/renderer/transcript/entries.ts | 4 +- .../transcript/execWrappedOutput.test.ts | 58 ++++++++++++++----- .../codex/renderer/transcript/mapper.ts | 49 ++++++++++------ .../codex/renderer/transcript/rollout.ts | 12 +++- 6 files changed, 98 insertions(+), 38 deletions(-) diff --git a/docs/plans/2026-09-27-codex-exec-wrapped-output.md b/docs/plans/2026-09-27-codex-exec-wrapped-output.md index b9c7cb395..ba0b6c08b 100644 --- a/docs/plans/2026-09-27-codex-exec-wrapped-output.md +++ b/docs/plans/2026-09-27-codex-exec-wrapped-output.md @@ -2,7 +2,7 @@ ## Evidence - **Census of 2,541 local rollouts.** It found 85,355 `function_call_output` lines whose output is wrapped: `Chunk ID:`, `Wall time:`, `Process exited with code N`, `Original token count:`, then `Output:`. It found **0** `exec_command_end` events in any file. -- **Current Codex never writes that event.** codex-rs `rollout/src/policy.rs` puts `EventMsg::ExecCommandEnd` under "Transient, non-durable events". rust-v0.107.0 through v0.131.0 did persist it in extended-history mode (review a), and none of the local rollouts use that mode. +- **Current Codex never writes that event.** codex-rs `rollout/src/policy.rs` puts `EventMsg::ExecCommandEnd` under "Transient, non-durable events". rust-v0.107.0 through v0.136.0 did persist it in extended-history mode (review a), and none of the local rollouts use that mode. - **The drop rule.** `mapCodexRolloutToFeedEntries` drops every wrapped output that has an exit line (`isCodexExecWrapperOutput`), on the stated belief that "the correlated `exec_command_end` event carries the same result". That belief is false, so the dropped line was the only copy. Every `exec_command` card in resumed history showed no output and no exit status. That covers Codex through 0.144: `exec_command` wrapped outputs occur in 0.1xx through 0.144, and 0.15x uses the `exec` tool. - **A second bug.** The predicate searched the WHOLE string for "Process exited with code". A still-running chunk whose command output contains those words was dropped too. @@ -27,3 +27,8 @@ The 0.15x `exec` tool's `custom_tool_call_output` results are a different carrie - **P2: two carriers.** In extended-history rollouts, one call can have both the event and the wrapper. `createCodexTranscriptEntryMapper` keeps the first exec terminal result per call_id, remembering the last 512 per stream. A pair split across a history page boundary is not caught. - **P3: no `Output:` marker.** Without the LF `\nOutput:\n` marker the wrapper is not parsed, so no exit claim and no stripping. None of the 85,355 local wrappers lacks it. - **Unpinned metadata.** The exact `codex` metadata is now asserted, which kills the kind/parsedCmd/command/cwd mutations. + +## Review b (round 2) +- **P2: a wrapper with no LF `Output:` marker still painted success.** The mapper returned a plain, metadata-less result, and the native adapter proves every unmarked result. Any `Chunk ID:` wrapper whose header cannot be parsed is now marked `exec_command_unparsed` and kept whole; the adapter shows `unknown` for it, as for `exec_command_running`. Test: that wrapper, through the adapter, shows `unknown` with a null exit. +- **P2: first-carrier dedupe kept the truncated event.** The persisted event's `aggregated_output` is sanitized to 10,000 bytes, and extended mode persisted it through v0.136.0, not v0.131.0. The wrapper now wins. An event that arrives after its wrapper is dropped. A wrapper that follows its event is kept, and later-wins `buildToolResultIndex` hands the card the wrapper. Codex emits the event before the function result (`ToolEventEmitter::finish`). +- **P2: page and burst boundaries bypass the per-mapper memory.** Accepted and documented. Across a boundary both results are kept and later-wins decides, which again favours the wrapper in Codex's emit order. No local rollout has both carriers. diff --git a/src/providers/codex/renderer/adapters/command.ts b/src/providers/codex/renderer/adapters/command.ts index 511c9a7cf..c03842be0 100644 --- a/src/providers/codex/renderer/adapters/command.ts +++ b/src/providers/codex/renderer/adapters/command.ts @@ -722,8 +722,10 @@ function commandResultEvidence( // write_stdin result with a different call_id, which this card cannot // see. rollout.ts marks it `exec_command_running`. Claiming success for // it painted long-running and later-failing commands green (9,896 such - // chunks in the local corpus); its honest state is "unknown". - exitProven: codex?.kind === 'exec_command_running' ? failed : true, + // chunks in the local corpus); its honest state is "unknown". The same + // holds for a wrapper whose header could not be parsed + // (`exec_command_unparsed`, #1395 review b). + exitProven: codex?.kind === 'exec_command_running' || codex?.kind === 'exec_command_unparsed' ? failed : true, running: false, owned: true, } diff --git a/src/providers/codex/renderer/transcript/entries.ts b/src/providers/codex/renderer/transcript/entries.ts index 44e6c4c80..1331b392b 100644 --- a/src/providers/codex/renderer/transcript/entries.ts +++ b/src/providers/codex/renderer/transcript/entries.ts @@ -160,8 +160,8 @@ export function stripCodexExecWrapper(output: string): string { * persists that event (codex-rs `rollout/src/policy.rs` lists * `EventMsg::ExecCommandEnd` as transient), and a census of 2,541 local * rollouts found 0 of them against 85,355 wrapped outputs with an exit line. - * (rust-v0.107.0 through v0.131.0 did persist it in extended-history mode; - * the transcript mapper keeps the first of the two carriers.) The drop therefore + * (rust-v0.107.0 through v0.136.0 did persist it in extended-history mode; + * the transcript mapper then prefers this wrapper, the fuller carrier.) The drop therefore * removed the ONLY copy of every `exec_command` result (Codex through 0.144) * from resumed history, and the card showed no output or exit status. */ export function codexExecWrapperExitCode(output: string): number | null { diff --git a/src/providers/codex/renderer/transcript/execWrappedOutput.test.ts b/src/providers/codex/renderer/transcript/execWrappedOutput.test.ts index a42801c16..b016b5dd8 100644 --- a/src/providers/codex/renderer/transcript/execWrappedOutput.test.ts +++ b/src/providers/codex/renderer/transcript/execWrappedOutput.test.ts @@ -118,23 +118,36 @@ describe('wrapped exec_command results in resumed history (#1321)', () => { expect(operation?.model.exitCode).toBeNull() }) - it('keeps one result when a rollout persisted both carriers for a call (#1395 review a, P2)', () => { - // rust-v0.107.0..v0.131.0 persisted exec_command_end in extended-history - // mode, next to the always-durable wrapped output, with the same call_id. - const [call, output] = cases.ok.records - const callId = (call!.payload as { call_id: string }).call_id - const event = { - type: 'event_msg', - timestamp: '2026-07-09T21:40:40.000Z', - payload: { type: 'exec_command_end', call_id: callId, exit_code: 0, aggregated_output: 'ok\n' }, - } + // Extended-history rollouts (through rust-v0.136.0) can persist the event + // next to the always-durable wrapper, with the same call_id. The wrapper is + // the fuller carrier (the event's aggregated_output is sanitized to 10,000 + // bytes), so it must be the result the card ends up with (#1395 reviews a, + // b). The feed's result index is later-wins. + const cardResult = (records: Array>) => { const mapper = createCodexTranscriptEntryMapper() - const results = [call!, event, output!] + const results = records .flatMap(record => mapper.map(record).entries) .flatMap(entry => (entry as { message: { content: Array> } }).message.content) .filter(block => block.type === 'tool_result') + return { results, card: results.at(-1) } + } + const [okCallRecord, okOutputRecord] = cases.ok.records + const truncatedEvent = { + type: 'event_msg', + timestamp: '2026-07-09T21:40:40.000Z', + payload: { type: 'exec_command_end', call_id: (okCallRecord!.payload as { call_id: string }).call_id, exit_code: 0, aggregated_output: 'truncated\n' }, + } + const wrapperBody = () => String((okOutputRecord!.payload as { output: string }).output).split('\nOutput:\n')[1] + + it('hands the card the wrapper when the event came first (#1395 review b)', () => { + const { card } = cardResult([okCallRecord!, truncatedEvent, okOutputRecord!]) + expect(card!.content).toBe(wrapperBody()) + }) + + it('drops an event that arrives after its wrapper (#1395 review b)', () => { + const { results } = cardResult([okCallRecord!, okOutputRecord!, truncatedEvent]) expect(results).toHaveLength(1) - expect(results[0]!.content).toBe('ok\n') + expect(results[0]!.content).toBe(wrapperBody()) }) it('makes no exit claim for a wrapper without its Output marker (#1395 review a, P3)', () => { @@ -149,6 +162,25 @@ describe('wrapped exec_command results in resumed history (#1321)', () => { } const [entry] = mapCodexRolloutToFeedEntries(headerOnly) const block = (entry as { message: { content: Array> } }).message.content[0]! - expect(block.codex).toBeUndefined() + expect(block.codex).toEqual({ kind: 'exec_command_unparsed' }) + }) + + it('shows an unparsed wrapper as unknown, never a success (#1395 review b)', () => { + const unparsed = { + type: 'response_item', + timestamp: '2026-07-09T21:40:40.079Z', + payload: { + type: 'function_call_output', + call_id: (okCall.payload as { call_id: string }).call_id, + output: 'Chunk ID: aaaaaa\r\nWall time: 0.1000 seconds\r\nProcess exited with code 1\r\nOriginal token count: 0\r\nOutput:\r\nfailed\r\n', + }, + } + const blocks = [okCall, unparsed].flatMap(record => mapCodexRolloutToFeedEntries(record)) + .flatMap(entry => (entry as { message: { content: Array> } }).message.content) + const toolUse = blocks.find(block => block.type === 'tool_use') as unknown as ToolUseBlock + const result = blocks.find(block => block.type === 'tool_result') as unknown as ToolResultBlock + const operation = fromCodexCommandOperation({ toolUse, result }) + expect(operation?.model.status).toBe('unknown') + expect(operation?.model.exitCode).toBeNull() }) }) diff --git a/src/providers/codex/renderer/transcript/mapper.ts b/src/providers/codex/renderer/transcript/mapper.ts index 0bfbf3634..ae68ca274 100644 --- a/src/providers/codex/renderer/transcript/mapper.ts +++ b/src/providers/codex/renderer/transcript/mapper.ts @@ -37,26 +37,39 @@ export function createCodexTranscriptEntryMapper( initialTurnCursor: string | null = null, ): TranscriptEntryMapper { let turnCursor = initialTurnCursor - // WHY (#1395 review a, P2): one exec_command can have TWO terminal carriers. - // The wrapped function_call_output is always durable. The exec_command_end - // event is transient in current Codex, but rust-v0.107.0 through v0.131.0 - // persisted it in extended-history mode (app-server - // `persist_extended_history`). Both carry the same call_id, and both map to - // an `exec_command_end` result, so the feed would get two result rows for - // one card, and the card would take whichever came last. The first carrier - // wins; the other is dropped. Scoped to this mapper's stream: a history - // page starts a new mapper, so a pair split across a page boundary is not - // caught (none in the local corpus, which has no persisted event at all). - const execTerminalCalls = new Set() - const keepFirstExecTerminal = (entry: ReturnType[number]): boolean => { + // WHY (#1395 reviews a and b): one exec_command can have TWO terminal + // carriers. The wrapped function_call_output is always durable. The + // exec_command_end event is transient in current Codex, but the + // extended-history policy persisted it through rust-v0.136.0 (0.137.0 is + // transient again). Both carry the same call_id and both map to an + // `exec_command_end` result. + // + // The WRAPPER wins, because it is the fuller one: the persisted event's + // aggregated_output is sanitized to 10,000 bytes (rollout policy.rs), while + // the wrapper keeps the whole model-visible output. The feed's result index + // is later-wins (buildToolResultIndex), and Codex emits the end event BEFORE + // the function result (core tools/events.rs ToolEventEmitter::finish), so: + // - event first, wrapper later: both are kept, and the wrapper wins the + // index (the command card owns and absorbs both result rows); + // - wrapper first, event later: the event is dropped here, so a late, + // truncated event cannot replace the wrapper. + // A first version kept whichever came FIRST, which kept the truncated event + // (review b). The memory is per mapper, and history pages, previews and + // live bursts each build their own; across such a boundary both results + // are kept and later-wins decides, which again favours the wrapper in + // Codex's own emit order. No local rollout (0 of 2,555) has both carriers. + const wrapperResolvedCalls = new Set() + const keepExecTerminal = (raw: Record) => (entry: ReturnType[number]): boolean => { const callId = execTerminalCallId(entry) if (callId === null) return true - if (execTerminalCalls.has(callId)) return false - execTerminalCalls.add(callId) - if (execTerminalCalls.size > EXEC_TERMINAL_MEMORY) { - execTerminalCalls.delete(execTerminalCalls.values().next().value as string) + if (raw.type === 'response_item') { + wrapperResolvedCalls.add(callId) + if (wrapperResolvedCalls.size > EXEC_TERMINAL_MEMORY) { + wrapperResolvedCalls.delete(wrapperResolvedCalls.values().next().value as string) + } + return true } - return true + return !wrapperResolvedCalls.has(callId) } return { map(raw: Record): MappedTranscriptEntry { @@ -66,7 +79,7 @@ export function createCodexTranscriptEntryMapper( if (payloadTurnId !== null) turnCursor = payloadTurnId const entries = mapCodexRolloutToFeedEntries(raw) - .filter(keepFirstExecTerminal) + .filter(keepExecTerminal(raw)) .map(entry => stampCodexTurnId(entry, turnCursor)) const marker = codexHistoryMarker(raw) diff --git a/src/providers/codex/renderer/transcript/rollout.ts b/src/providers/codex/renderer/transcript/rollout.ts index 84805315b..3ebae976f 100644 --- a/src/providers/codex/renderer/transcript/rollout.ts +++ b/src/providers/codex/renderer/transcript/rollout.ts @@ -328,11 +328,11 @@ export function mapCodexRolloutToFeedEntries(entry: Record): En // // WHERE this event comes from (#1321): almost never a rollout. Current // codex-rs treats `ExecCommandEnd` as transient, and 0 of 2,541 local - // rollouts contain one. rust-v0.107.0 through v0.131.0 persisted it in + // rollouts contain one. rust-v0.107.0 through v0.136.0 persisted it in // extended-history mode (app-server `persist_extended_history`), next to // the always-durable wrapped `function_call_output` below, which is // stamped with this same metadata. createCodexTranscriptEntryMapper - // keeps the first of the two for a call_id (#1395 review a). + // prefers the wrapper, the fuller carrier (#1395 reviews a, b). return [ codexToolResultEntry( uuid, @@ -470,6 +470,14 @@ export function mapCodexRolloutToFeedEntries(entry: Record): En // for the command adapter, which then shows "unknown" instead of success. return [codexToolResultEntry(uuid, timestamp, payload.call_id, output, false, { kind: 'exec_command_running' })] } + if (structured.startsWith('Chunk ID:')) { + // A wrapper whose header we could not parse (no LF `Output:` marker, a + // CRLF header, an unknown status line). None of 95,251 local wrappers + // has such a shape, but if one appears its outcome is unknown, not a + // success (#1395 review b): the bytes are kept whole, since there is no + // proven header/body boundary to strip at. + return [codexToolResultEntry(uuid, timestamp, payload.call_id, structured, false, { kind: 'exec_command_unparsed' })] + } if (!output.trim()) return [] return [codexToolResultEntry(uuid, timestamp, payload.call_id, output)] } From 0c435f041d8cd1d7fce1c735214b65cba15a96fb Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 03:56:19 -0700 Subject: [PATCH 16/40] fix(conversations): read Codex 0.157 UserMessage items when the index is unavailable (#1363) Co-Authored-By: Claude Opus 5.5 --- ...6-09-27-codex-conversations-usermessage.md | 16 ++ src/main/conversations/sources/codex.ts | 41 ++++- .../sources/codex.userMessage0157.test.ts | 64 +++++++ .../codex-0157/typed-prompt-head.json | 166 ++++++++++++++++++ tsconfig.node.json | 2 + 5 files changed, 286 insertions(+), 3 deletions(-) create mode 100644 docs/plans/2026-09-27-codex-conversations-usermessage.md create mode 100644 src/main/conversations/sources/codex.userMessage0157.test.ts create mode 100644 testing/fixtures/conversations/codex-0157/typed-prompt-head.json diff --git a/docs/plans/2026-09-27-codex-conversations-usermessage.md b/docs/plans/2026-09-27-codex-conversations-usermessage.md new file mode 100644 index 000000000..7910463c3 --- /dev/null +++ b/docs/plans/2026-09-27-codex-conversations-usermessage.md @@ -0,0 +1,16 @@ +# Codex 0.157 prompts survive the conversation catalog's no-index fallback (#1363) + +## Evidence +- **The fallback reader.** Without a usable `state_N.sqlite` (missing, failing schema validation, or a rollout the index does not cover), `CodexConversationSource` reads each rollout's head with `readRolloutHead`. That took prompt text ONLY from `event_msg:{type:"user_message"}`. +- **What 0.157 writes instead.** 120 recent local 0.15x rollouts all carry `event_msg:item_completed` with `item.type: 'UserMessage'`: 149 items, each `content: [{type:'text', text, text_elements}]`. None carries a legacy `user_message`. The issue's census found 233 of 233 0.157.x files without the legacy event. +- **Effect.** Every 0.157 row on the degraded path had `userTexts: []`. It was classified `empty` and hidden from the default listing, or lost its label and user activity. + +## Change +`readRolloutHead` also reads `UserMessage` items: the joined text parts, with their record timestamp as user activity. +- **Why the item, not the role-user `response_item`.** Codex builds the item only for what the user sent. The injected AGENTS.md and environment context are role-user response items too, and the item leaves them out, as the index does. +- **Why a file uses one carrier.** Legacy events and items are collected apart. A file with any legacy event uses those alone, so a rollout carrying both shapes never lists its prompt twice. + +## Tests (`codex.userMessage0157.test.ts`) +The fixture `testing/fixtures/conversations/codex-0157/typed-prompt-head.json` is a real 0.157.1 rollout head: `session_meta`, three role-user response items (AGENTS.md, context, the prompt) and the first typed prompt's `UserMessage` item. Text is redacted to the same length. It runs through the real `CodexConversationSource`, with no index beside it. +1. The row's `userTexts` is exactly the typed prompt, not the injected context, and user activity is set. Red on main (`[]`). +2. The same head plus a legacy `user_message` for the same prompt lists it once. Listing both carriers fails this test. diff --git a/src/main/conversations/sources/codex.ts b/src/main/conversations/sources/codex.ts index 5a25536ca..5a4afa01d 100644 --- a/src/main/conversations/sources/codex.ts +++ b/src/main/conversations/sources/codex.ts @@ -89,6 +89,23 @@ function isSubagentSource(row: IndexRow): boolean { * contract for a fallback path is not worth a cross-repository change. */ async function readRolloutHead(file: string): Promise { const out: RolloutHead = { cwd: null, gitBranch: null, createdAt: null, originator: null, source: null, userTexts: [], lastUserAt: null } + // Two carriers of a typed prompt, kept apart and chosen at the end (#1363). + // Codex up to 0.14x writes `event_msg:user_message`. Codex 0.157 writes + // none: a typed prompt is `event_msg:item_completed` with + // `item.type: 'UserMessage'` (every one of 120 local 0.15x rollouts, 149 + // items, none with a legacy event). The UserMessage item, not the role-user + // response_item next to it, because Codex builds the item only for what the + // user sent: the injected AGENTS.md and environment context are role-user + // response items too, and the item leaves them out, as the index does. A + // file that has the legacy event uses it alone, so a rollout carrying both + // shapes can never list its prompts twice. + const legacy: { texts: string[]; lastAt: number | null } = { texts: [], lastAt: null } + const items: { texts: string[]; lastAt: number | null } = { texts: [], lastAt: null } + const note = (into: typeof legacy, text: string, timestamp: unknown) => { + if (into.texts.length < 6) into.texts.push(text) + const ts = typeof timestamp === 'string' ? Date.parse(timestamp) : NaN + if (Number.isFinite(ts)) into.lastAt = ts + } let records = 0 for await (const record of streamJsonl>(file)) { if (!record) continue @@ -102,9 +119,10 @@ async function readRolloutHead(file: string): Promise { out.originator = typeof payload.originator === 'string' ? payload.originator : null out.source = typeof payload.source === 'string' ? payload.source : payload.source ? JSON.stringify(payload.source) : null } else if (record.type === 'event_msg' && payload?.type === 'user_message' && typeof payload.message === 'string') { - if (out.userTexts.length < 6) out.userTexts.push(payload.message) - const ts = typeof record.timestamp === 'string' ? Date.parse(record.timestamp) : NaN - if (Number.isFinite(ts)) out.lastUserAt = ts + note(legacy, payload.message, record.timestamp) + } else if (record.type === 'event_msg' && payload?.type === 'item_completed') { + const text = userMessageItemText(payload.item) + if (text) note(items, text, record.timestamp) } // WHY the limit is unconditional: a rollout whose first two hundred // records hold no user event (exec runs, synthesized transcripts) has @@ -112,9 +130,26 @@ async function readRolloutHead(file: string): Promise { // files to the end made discovery cost the size of the store. if (records >= HEAD_RECORD_LIMIT) break } + const chosen = legacy.texts.length > 0 ? legacy : items + out.userTexts = chosen.texts + out.lastUserAt = chosen.lastAt return out } +/** The text of a 0.157 `UserMessage` turn item (`{type, id, content: [{type: + * 'text', text, text_elements}]}`), or null for any other item. Image parts + * carry no text and are skipped; a message of only images has no label. */ +function userMessageItemText(value: unknown): string | null { + const item = asRecord(value) + if (item?.type !== 'UserMessage' || !Array.isArray(item.content)) return null + const text = item.content + .map(part => asRecord(part)) + .filter(part => part?.type === 'text' && typeof part.text === 'string') + .map(part => part!.text as string) + .join('') + return text.length > 0 ? text : null +} + export class CodexConversationSource implements ConversationSource { readonly provider = 'codex' as const private downgradeReason: string | null = null diff --git a/src/main/conversations/sources/codex.userMessage0157.test.ts b/src/main/conversations/sources/codex.userMessage0157.test.ts new file mode 100644 index 000000000..e6506fde1 --- /dev/null +++ b/src/main/conversations/sources/codex.userMessage0157.test.ts @@ -0,0 +1,64 @@ +import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises' +import { tmpdir } from 'node:os' +import { join } from 'node:path' +import { afterEach, expect, it } from 'vitest' + +import fixture from '../../../../testing/fixtures/conversations/codex-0157/typed-prompt-head.json' + +import { resolveFamily } from '../family.js' +import { CodexConversationSource } from './codex.js' + +// #1363: without a usable index (state_N.sqlite missing or failing schema +// validation, or a rollout the index does not cover) the source reads each +// rollout's head, and it took prompt text ONLY from `event_msg:user_message`. +// Codex 0.157 writes none: a typed prompt is a role-user response_item plus +// `event_msg:item_completed` with `item.type: 'UserMessage'`. Every 0.157 +// row came back with no prompt, was classified `empty`, and was hidden from +// the default listing. The input is a REAL 0.157.1 rollout head (see the +// fixture's evidence), with no index beside it, through the real source. + +type Record = { type: string; payload?: { type?: string; id?: string; item?: { type?: string; content?: Array<{ type: string; text?: string }> } } } +const records = fixture.records as Record[] +const threadId = records[0]!.payload!.id! +const typedPrompt = records + .find(record => record.payload?.type === 'item_completed' && record.payload.item?.type === 'UserMessage')! + .payload!.item!.content!.filter(part => part.type === 'text').map(part => part.text).join('') + +const dirs: string[] = [] +afterEach(async () => { for (const dir of dirs.splice(0)) await rm(dir, { recursive: true, force: true }) }) + +it('reads a 0.157 typed prompt from its UserMessage item when there is no index', async () => { + const codexHome = await mkdtemp(join(tmpdir(), 'codex-0157-home-')) + dirs.push(codexHome) + const day = join(codexHome, 'sessions', '2026', '09', '27') + await mkdir(day, { recursive: true }) + await writeFile(join(day, `rollout-2026-09-27T03-06-42-${threadId}.jsonl`), records.map(record => JSON.stringify(record)).join('\n') + '\n') + + const source = new CodexConversationSource({ codexHome }) + const family = await resolveFamily('/fixture/repo', 'everywhere', { listWorktrees: async () => [] }) + const rows = await source.discover({ scope: 'everywhere', family }) + const row = rows.find(candidate => candidate.nativeId === threadId) + + expect(source.lastDowngradeReason()).not.toBeNull() + expect(row).toBeDefined() + // Exactly the typed prompt: not the injected AGENTS.md or environment + // context that precede it as role-user response items. + expect(row!.userTexts).toEqual([typedPrompt]) + expect(row!.lastUserActivityAt).not.toBeNull() +}) + +it('lists a rollout carrying both shapes once, from the legacy event', async () => { + // A file that has `event_msg:user_message` uses it alone, so a rollout + // written with both carriers never shows its prompt twice. + const codexHome = await mkdtemp(join(tmpdir(), 'codex-0157-home-')) + dirs.push(codexHome) + const day = join(codexHome, 'sessions', '2026', '09', '27') + await mkdir(day, { recursive: true }) + const legacy = { timestamp: '2026-09-27T10:20:24.186Z', type: 'event_msg', payload: { type: 'user_message', message: typedPrompt } } + await writeFile(join(day, `rollout-2026-09-27T03-06-42-${threadId}.jsonl`), [...records, legacy].map(record => JSON.stringify(record)).join('\n') + '\n') + + const source = new CodexConversationSource({ codexHome }) + const family = await resolveFamily('/fixture/repo', 'everywhere', { listWorktrees: async () => [] }) + const row = (await source.discover({ scope: 'everywhere', family })).find(candidate => candidate.nativeId === threadId) + expect(row!.userTexts).toEqual([typedPrompt]) +}) diff --git a/testing/fixtures/conversations/codex-0157/typed-prompt-head.json b/testing/fixtures/conversations/codex-0157/typed-prompt-head.json new file mode 100644 index 000000000..50e509c14 --- /dev/null +++ b/testing/fixtures/conversations/codex-0157/typed-prompt-head.json @@ -0,0 +1,166 @@ +{ + "evidence": "A real Codex 0.157.1 rollout head (#1363): session_meta, every role-user response_item before the first typed prompt (Codex-injected context such as AGENTS.md, and the typed prompt itself), and the first typed prompt's event_msg item_completed (item.type UserMessage). Codex 0.157 writes no event_msg user_message. Keys, types, roles, the CLI version, originator, timestamps and uuid ids are verbatim; every other string is replaced by the same number of x characters (newlines kept).", + "cliVersion": "0.157.1", + "records": [ + { + "timestamp": "2026-09-27T10:06:42.920Z", + "ordinal": 0, + "type": "session_meta", + "payload": { + "creator_user_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "creator_account_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "session_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "id": "01a0e254-c7c2-73b1-bb9f-56a463914585", + "timestamp": "2026-09-27T10:06:42.167Z", + "cwd": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "runtime_workspace_roots": [ + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + ], + "originator": "codex-tui", + "cli_version": "0.157.1", + "source": "xxx", + "thread_source": "xxxx", + "model_provider": "openai", + "base_instructions": { + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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", + "context_window": { + "window_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + }, + "git": { + "commit_hash": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "repository_url": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + } + } + }, + { + "timestamp": "2026-09-27T10:06:45.967Z", + "ordinal": 5, + "type": "response_item", + "payload": { + "type": "message", + "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "role": "user", + "content": [ + { + "type": "input_text", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxx\nxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxx" + }, + { + "type": "input_text", + "text": "xxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxx" + } + ], + "internal_chat_message_metadata_passthrough": { + "turn_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "create_time": 1790503605.944404, + "content_item_kinds": [ + "xxxxxxxxxxxxxxxxxxxxxx", + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + ] + } + } + }, + { + "timestamp": "2026-09-27T10:06:46.180Z", + "ordinal": 8, + "type": "response_item", + "payload": { + "type": "message", + "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "role": "user", + "content": [ + { + "type": "input_text", + "text": "xxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxx" + } + ], + "internal_chat_message_metadata_passthrough": { + "turn_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "create_time": 1790503606.180568, + "content_item_kinds": [ + "xxxxxxxxx" + ] + } + }, + "metadata": { + "client_authored": false, + "user_input_order": 0, + "mcp_attribution": { + "status": "xxxx" + } + } + }, + { + "timestamp": "2026-09-27T10:20:24.183Z", + "ordinal": 291, + "type": "response_item", + "payload": { + "type": "message", + "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "role": "user", + "content": [ + { + "type": "input_text", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + } + ], + "internal_chat_message_metadata_passthrough": { + "turn_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "create_time": 1790504424.182083, + "content_item_kinds": [ + "xxxxxxxxx" + ] + } + }, + "metadata": { + "client_authored": false, + "user_input_order": 6, + "mcp_attribution": { + "status": "xxxxxxxx", + "sources": [ + { + "server_name": "xxxxxxxxxx", + "tool_name": "xxxxxxxx", + "first_turn_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + }, + { + "server_name": "xxxxxxxxxx", + "tool_name": "xxxxxxxxxxx", + "first_turn_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + } + ] + } + } + }, + { + "timestamp": "2026-09-27T10:20:24.185Z", + "ordinal": 292, + "type": "event_msg", + "payload": { + "type": "item_completed", + "thread_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "turn_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "item": { + "type": "UserMessage", + "id": "01a0e261-52f6-7542-a5b7-e74b78ff1264", + "client_id": "xxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "text_elements": [] + } + ] + }, + "started_at_ms": 1790504424185, + "completed_at_ms": 1790504424185 + } + } + ] +} \ No newline at end of file diff --git a/tsconfig.node.json b/tsconfig.node.json index 7567c9cd7..c48aa16a0 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -79,6 +79,8 @@ // The corpus installer is imported by system tests under src/main; a // composite project must list every module its files reach. "testing/support/conversations/**/*", + // Recorded Codex 0.157 rollout head for the no-index fallback (#1363). + "testing/fixtures/conversations/codex-0157/*.json", "packages/agent-transcript-parser/src/**/*", // Pull only the Node-safe dictation package surfaces into the app // typecheck. The package root also exports browser recording helpers, and From d419803e8c72c0387f35833291c215a055ea72ad Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 04:13:58 -0700 Subject: [PATCH 17/40] test(setup): install a working DOM Storage when Node 25's placeholder shadows happy-dom's (#1212) Co-Authored-By: Claude Opus 5.5 --- .../2026-09-27-node25-renderer-storage.md | 14 ++++++++++ .../app/storageEnvironment.renderer.test.ts | 12 +++++++++ testing/setup/renderer.ts | 6 +++++ testing/setup/storage.ts | 27 +++++++++++++++++++ testing/unit/setupStorage.test.ts | 23 ++++++++++++++++ 5 files changed, 82 insertions(+) create mode 100644 docs/plans/2026-09-27-node25-renderer-storage.md create mode 100644 src/renderer/src/app/storageEnvironment.renderer.test.ts create mode 100644 testing/setup/storage.ts create mode 100644 testing/unit/setupStorage.test.ts diff --git a/docs/plans/2026-09-27-node25-renderer-storage.md b/docs/plans/2026-09-27-node25-renderer-storage.md new file mode 100644 index 000000000..46ae529ec --- /dev/null +++ b/docs/plans/2026-09-27-node25-renderer-storage.md @@ -0,0 +1,14 @@ +# Renderer tests on Node 25: a working DOM Storage (#1212) + +**Reproduced** with `/opt/homebrew/bin/node` v25.5.0: `recentCommandHistory.renderer.test.ts` fails with `window.localStorage.clear is not a function` and a read of `undefined`. Node warns "`--localstorage-file` was provided without a valid path". + +**Cause.** Node 25 enables Web Storage by default. Without `--localstorage-file` its `globalThis.localStorage` is a half-initialised placeholder. Because the global already exists, Vitest's happy-dom environment leaves it in place, so renderer code talks to Node's broken storage instead of the DOM's. + +**Fix.** `testing/setup/storage.ts` `installWorkingStorage()` is called from the renderer setup file. It puts a happy-dom `Storage` on `localStorage` / `sessionStorage` wherever the existing one has no `clear`. On Node 22/24 it is a no-op. + +**Tests.** +- `testing/unit/setupStorage.test.ts` pins the repair against a stand-in with Node 25's shape, because CI runs Node 24. +- `src/renderer/src/app/storageEnvironment.renderer.test.ts` checks that the renderer environment's storage works. +- Verified on Node 25.5.0 and 24.14.1. Without the fix, the storage-using renderer tests fail 1 of 4 files on Node 25. + +**Out of scope.** Any other Node 25 incompatibility in the full suite; this issue is the storage setup. diff --git a/src/renderer/src/app/storageEnvironment.renderer.test.ts b/src/renderer/src/app/storageEnvironment.renderer.test.ts new file mode 100644 index 000000000..9daf5e296 --- /dev/null +++ b/src/renderer/src/app/storageEnvironment.renderer.test.ts @@ -0,0 +1,12 @@ +import { expect, it } from 'vitest' + +// #1212: under Node 25 the global localStorage was Node's half-initialised Web +// Storage (no clear, reads undefined) instead of happy-dom's. +// testing/setup/renderer.ts installs a working one; this checks the renderer +// test environment really has it. +it('leaves the test environment with a working storage', () => { + expect(typeof window.localStorage.clear).toBe('function') + window.localStorage.setItem('probe', '1') + expect(window.localStorage.getItem('probe')).toBe('1') + window.localStorage.clear() +}) diff --git a/testing/setup/renderer.ts b/testing/setup/renderer.ts index 7e99ea5af..ce8dcc4f9 100644 --- a/testing/setup/renderer.ts +++ b/testing/setup/renderer.ts @@ -2,6 +2,12 @@ import '@testing-library/jest-dom/vitest' import { cleanup } from '@testing-library/react' import { afterEach } from 'vitest' +import { installWorkingStorage } from './storage' + +// Node 25's half-initialised Web Storage would otherwise shadow happy-dom's +// (#1212); see installWorkingStorage. +installWorkingStorage(globalThis) + // WHY this file exists even though today's renderer smoke test barely needs // setup: // diff --git a/testing/setup/storage.ts b/testing/setup/storage.ts new file mode 100644 index 000000000..461b153be --- /dev/null +++ b/testing/setup/storage.ts @@ -0,0 +1,27 @@ +import { Storage } from 'happy-dom' + +/** + * Put a working DOM Storage on `target` wherever the existing one is not a + * Storage (#1212). + * + * WHY: Node 25 ships Web Storage on by default. Without `--localstorage-file` + * its `globalThis.localStorage` is a half-initialised object (no `clear`, + * reads return undefined, plus the warning "`--localstorage-file` was provided + * without a valid path"). Because the global already exists, Vitest's + * happy-dom environment does not replace it, so renderer code and tests talk + * to Node's broken storage instead of the DOM's. On Node 22/24, happy-dom's + * storage is already in place and this changes nothing. + * + * "Working" is judged by `clear` being a function: Node 25's placeholder lacks + * it, and every real Storage has it. + */ +export function installWorkingStorage(target: object): Array<'localStorage' | 'sessionStorage'> { + const replaced: Array<'localStorage' | 'sessionStorage'> = [] + for (const name of ['localStorage', 'sessionStorage'] as const) { + const current = (target as Record)[name] as { clear?: unknown } | undefined + if (typeof current?.clear === 'function') continue + Object.defineProperty(target, name, { configurable: true, writable: true, value: new Storage() }) + replaced.push(name) + } + return replaced +} diff --git a/testing/unit/setupStorage.test.ts b/testing/unit/setupStorage.test.ts new file mode 100644 index 000000000..e6d926c91 --- /dev/null +++ b/testing/unit/setupStorage.test.ts @@ -0,0 +1,23 @@ +import { expect, it } from 'vitest' + +import { installWorkingStorage } from '../setup/storage' + +// #1212: Node 25's default Web Storage is a placeholder without `clear` that +// returns undefined on read. CI runs Node 24, where the real global is fine, +// so this pins the repair against a stand-in with Node 25's shape. +it('replaces a storage without clear by a working DOM Storage', () => { + const target = { localStorage: { getItem: () => undefined }, sessionStorage: {} } + expect(installWorkingStorage(target)).toEqual(['localStorage', 'sessionStorage']) + const storage = (target as unknown as { localStorage: Storage }).localStorage + storage.setItem('k', 'v') + expect(storage.getItem('k')).toBe('v') + storage.clear() + expect(storage.length).toBe(0) +}) + +it('leaves a working storage in place', () => { + const working = { clear: () => {} } + const target = { localStorage: working, sessionStorage: working } + expect(installWorkingStorage(target)).toEqual([]) + expect(target.localStorage).toBe(working) +}) From 25b1a2f4afc59fbca4a829883a39ab37a8978687 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 04:16:52 -0700 Subject: [PATCH 18/40] build: list the renderer storage setup in the web tsconfig (#1212) Co-Authored-By: Claude Opus 5.5 --- tsconfig.web.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tsconfig.web.json b/tsconfig.web.json index 264b218b2..04fa7d6d6 100644 --- a/tsconfig.web.json +++ b/tsconfig.web.json @@ -64,6 +64,7 @@ // could not see its `expect` augmentation. Include the one shared setup instead of adding // matcher imports to individual specs and letting the two test environments drift. "testing/setup/renderer.ts", + "testing/setup/storage.ts", // These fixture exporters import canonical renderer/shared boundaries on // purpose: recorded corpora must be minimized by the same privacy and // identity rules the app uses. Keep them in the web project so callback From b2f2238f904746a8383cb10341290fbffab2a408 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 05:15:04 -0700 Subject: [PATCH 19/40] fix(conversations): merge both prompt carriers, tail activity, image-only prompts; contiguous fixture (reviews a, b) Co-Authored-By: Claude Opus 5.5 --- ...6-09-27-codex-conversations-usermessage.md | 8 + src/main/conversations/sources/codex.ts | 139 +++++++-- .../sources/codex.userMessage0157.test.ts | 96 +++--- .../codex-0157/typed-prompt-head.json | 293 ++++++++++++++---- 4 files changed, 411 insertions(+), 125 deletions(-) diff --git a/docs/plans/2026-09-27-codex-conversations-usermessage.md b/docs/plans/2026-09-27-codex-conversations-usermessage.md index 7910463c3..830ce2ccf 100644 --- a/docs/plans/2026-09-27-codex-conversations-usermessage.md +++ b/docs/plans/2026-09-27-codex-conversations-usermessage.md @@ -14,3 +14,11 @@ The fixture `testing/fixtures/conversations/codex-0157/typed-prompt-head.json` is a real 0.157.1 rollout head: `session_meta`, three role-user response items (AGENTS.md, context, the prompt) and the first typed prompt's `UserMessage` item. Text is redacted to the same length. It runs through the real `CodexConversationSource`, with no index beside it. 1. The row's `userTexts` is exactly the typed prompt, not the injected context, and user activity is set. Red on main (`[]`). 2. The same head plus a legacy `user_message` for the same prompt lists it once. Listing both carriers fails this test. + +## Reviews a and b (round 1) +- **Carriers merged, not "legacy wins".** A file with both carriers can hold a prompt only the items have. Both are read in file order, and the same prompt written by both counts once: each carrier consumes a pending match from the other. These are the two carriers Codex's own index reads (`rust-v0.157.1 state/src/extract.rs`). +- **Activity from the tail.** When the 200-record head is truncated, a bounded 512 KiB tail pass takes the newest user timestamp. In 33 of 61 local 0.157.0 files a later prompt lay past the head, one 46.8 h later. `headTruncated` is set as for Claude and Pi. +- **Text and images.** Parts are joined with no separator, as Codex's `UserMessageItem::message()` does. An image-only message reads `[Image]`, Codex's preview text. +- **Comment narrowed.** Older CLIs' UserMessage items can hold injected context or command wrappers. The index lists those too, and `firstUnwrappedPrompt` and classify decide what labels a row. +- **Fixture rebuilt as a CONTIGUOUS real head.** It holds all 10 records from `session_meta` through the first UserMessage of the one local 0.157 file whose first prompt is typed. The expected length and timestamp are recorded independently in the fixture. Composed cases say they are composed. +- **Filed, not fixed here (pre-existing):** #1418 (0.149–0.151 rollouts with no prompt event) and #1419 (search matches injected context). diff --git a/src/main/conversations/sources/codex.ts b/src/main/conversations/sources/codex.ts index 5a4afa01d..e933beee1 100644 --- a/src/main/conversations/sources/codex.ts +++ b/src/main/conversations/sources/codex.ts @@ -1,5 +1,5 @@ import { existsSync } from 'node:fs' -import { readdir, stat } from 'node:fs/promises' +import { open, readdir, stat } from 'node:fs/promises' import { join } from 'node:path' import type { ConversationPrompt } from '@shared/conversations/types.js' @@ -70,6 +70,8 @@ type RolloutHead = { source: string | null userTexts: string[] lastUserAt: number | null + /** The head hit its record bound with no user text (as for Claude and Pi). */ + headTruncated?: boolean } function isSubagentSource(row: IndexRow): boolean { @@ -89,24 +91,36 @@ function isSubagentSource(row: IndexRow): boolean { * contract for a fallback path is not worth a cross-repository change. */ async function readRolloutHead(file: string): Promise { const out: RolloutHead = { cwd: null, gitBranch: null, createdAt: null, originator: null, source: null, userTexts: [], lastUserAt: null } - // Two carriers of a typed prompt, kept apart and chosen at the end (#1363). - // Codex up to 0.14x writes `event_msg:user_message`. Codex 0.157 writes - // none: a typed prompt is `event_msg:item_completed` with - // `item.type: 'UserMessage'` (every one of 120 local 0.15x rollouts, 149 - // items, none with a legacy event). The UserMessage item, not the role-user - // response_item next to it, because Codex builds the item only for what the - // user sent: the injected AGENTS.md and environment context are role-user - // response items too, and the item leaves them out, as the index does. A - // file that has the legacy event uses it alone, so a rollout carrying both - // shapes can never list its prompts twice. - const legacy: { texts: string[]; lastAt: number | null } = { texts: [], lastAt: null } - const items: { texts: string[]; lastAt: number | null } = { texts: [], lastAt: null } - const note = (into: typeof legacy, text: string, timestamp: unknown) => { - if (into.texts.length < 6) into.texts.push(text) + // Two carriers of a user prompt (#1363). Codex up to 0.14x wrote + // `event_msg:user_message`; 0.157 writes none, and a prompt is + // `event_msg:item_completed` with `item.type: 'UserMessage'` (414 of 416 + // local 0.157 files; the other two are native subagents with no prompt). + // These are exactly the two carriers Codex's own index reads for + // `first_user_message` (rust-v0.157.1 state/src/extract.rs); it ignores the + // role-user response_item, which also carries injected context. WHY both are + // read and merged, not "legacy wins" (#1407 reviews a and b): a file with + // both carriers (a session resumed across writer versions) could then lose + // a prompt only the items hold. The same prompt written by both carriers is + // counted once: each carrier consumes a pending match from the other. + // What older CLIs put in UserMessage items (sometimes injected context or a + // command wrapper) is what the index lists too; firstUnwrappedPrompt and + // classify decide what is a label, as for every other source. + const pending = { legacy: new Map(), item: new Map() } + const noteUser = (carrier: 'legacy' | 'item', text: string, timestamp: unknown) => { + const other = carrier === 'legacy' ? pending.item : pending.legacy + const matched = other.get(text) ?? 0 + if (matched > 0) { + other.set(text, matched - 1) + } else { + const own = pending[carrier] + own.set(text, (own.get(text) ?? 0) + 1) + if (out.userTexts.length < 6) out.userTexts.push(text) + } const ts = typeof timestamp === 'string' ? Date.parse(timestamp) : NaN - if (Number.isFinite(ts)) into.lastAt = ts + if (Number.isFinite(ts)) out.lastUserAt = Math.max(out.lastUserAt ?? ts, ts) } let records = 0 + let truncated = false for await (const record of streamJsonl>(file)) { if (!record) continue records++ @@ -118,36 +132,98 @@ async function readRolloutHead(file: string): Promise { out.createdAt = typeof payload.timestamp === 'string' && Number.isFinite(Date.parse(payload.timestamp)) ? Date.parse(payload.timestamp) : null out.originator = typeof payload.originator === 'string' ? payload.originator : null out.source = typeof payload.source === 'string' ? payload.source : payload.source ? JSON.stringify(payload.source) : null - } else if (record.type === 'event_msg' && payload?.type === 'user_message' && typeof payload.message === 'string') { - note(legacy, payload.message, record.timestamp) - } else if (record.type === 'event_msg' && payload?.type === 'item_completed') { - const text = userMessageItemText(payload.item) - if (text) note(items, text, record.timestamp) + } else { + const user = userPromptOf(record, payload) + if (user !== null) noteUser(user.carrier, user.text, record.timestamp) } // WHY the limit is unconditional: a rollout whose first two hundred // records hold no user event (exec runs, synthesized transcripts) has // nothing further up the file the head can label it by, and reading such // files to the end made discovery cost the size of the store. - if (records >= HEAD_RECORD_LIMIT) break + if (records >= HEAD_RECORD_LIMIT) { + truncated = true + break + } + } + if (truncated) { + // WHY a tail pass (#1407 reviews a and b): the listing sorts by user + // activity, and a head-bounded read reported the last prompt within the + // first 200 records. In 33 of 61 local 0.157.0 files a later prompt lay + // beyond them (one 46.8 hours later), so a live session sorted days too + // old. The newest prompt is near the end of the file, so reading a + // bounded tail finds it at a fixed cost; the head keeps the labels. + const tailAt = await newestUserTimestampInTail(file) + if (tailAt !== null) out.lastUserAt = Math.max(out.lastUserAt ?? tailAt, tailAt) + out.headTruncated = out.userTexts.length === 0 } - const chosen = legacy.texts.length > 0 ? legacy : items - out.userTexts = chosen.texts - out.lastUserAt = chosen.lastAt return out } +// Bytes read from the end of a rollout for the newest user timestamp. A +// Codex turn's own records (reasoning, tool calls, outputs) fill this many +// bytes long before the next prompt in the usual case; a prompt further back +// than this keeps the head's time, which is at worst the old behaviour. +const TAIL_ACTIVITY_BYTES = 512 * 1024 + +async function newestUserTimestampInTail(file: string): Promise { + let handle + try { + handle = await open(file, 'r') + const { size } = await handle.stat() + const start = Math.max(0, size - TAIL_ACTIVITY_BYTES) + const buffer = Buffer.alloc(size - start) + await handle.read(buffer, 0, buffer.length, start) + const lines = buffer.toString('utf8').split('\n') + // The first line of a mid-file window is partial; the last may be too. + if (start > 0) lines.shift() + let newest: number | null = null + for (const line of lines) { + if (!line.includes('"user_message"') && !line.includes('"UserMessage"')) continue + let record: Record + try { + record = JSON.parse(line) as Record + } catch { + continue + } + if (userPromptOf(record, asRecord(record.payload)) === null) continue + const ts = typeof record.timestamp === 'string' ? Date.parse(record.timestamp) : NaN + if (Number.isFinite(ts)) newest = Math.max(newest ?? ts, ts) + } + return newest + } catch { + return null + } finally { + await handle?.close().catch(() => {}) + } +} + +/** The user prompt a rollout record carries, and through which carrier. */ +function userPromptOf(record: Record, payload: Record | null): { carrier: 'legacy' | 'item'; text: string } | null { + if (record.type !== 'event_msg' || !payload) return null + if (payload.type === 'user_message' && typeof payload.message === 'string') return { carrier: 'legacy', text: payload.message } + if (payload.type === 'item_completed') { + const text = userMessageItemText(payload.item) + if (text !== null) return { carrier: 'item', text } + } + return null +} + /** The text of a 0.157 `UserMessage` turn item (`{type, id, content: [{type: - * 'text', text, text_elements}]}`), or null for any other item. Image parts - * carry no text and are skipped; a message of only images has no label. */ + * 'text', text, text_elements}]}`), or null for any other item. Text parts + * are joined with no separator, as Codex's own UserMessageItem::message() + * does (protocol/src/items.rs). A message of only images reads `[Image]`, + * Codex's own preview text (protocol.rs user_message_preview), so an + * image-only prompt is still a prompt (#1407 review b). */ function userMessageItemText(value: unknown): string | null { const item = asRecord(value) if (item?.type !== 'UserMessage' || !Array.isArray(item.content)) return null - const text = item.content - .map(part => asRecord(part)) - .filter(part => part?.type === 'text' && typeof part.text === 'string') + const parts = item.content.map(part => asRecord(part)).filter(part => part !== null) + const text = parts + .filter(part => part!.type === 'text' && typeof part!.text === 'string') .map(part => part!.text as string) .join('') - return text.length > 0 ? text : null + if (text.length > 0) return text + return parts.some(part => part!.type !== 'text') ? '[Image]' : null } export class CodexConversationSource implements ConversationSource { @@ -217,6 +293,7 @@ export class CodexConversationSource implements ConversationSource { userTexts: head.userTexts, createdAt: head.createdAt, lastUserActivityAt: head.lastUserAt, + ...(head.headTruncated ? { headTruncated: true } : {}), activitySource: head.lastUserAt !== null ? 'tail' : null, mtime, promptCount: null, diff --git a/src/main/conversations/sources/codex.userMessage0157.test.ts b/src/main/conversations/sources/codex.userMessage0157.test.ts index e6506fde1..b293fc116 100644 --- a/src/main/conversations/sources/codex.userMessage0157.test.ts +++ b/src/main/conversations/sources/codex.userMessage0157.test.ts @@ -11,54 +11,80 @@ import { CodexConversationSource } from './codex.js' // #1363: without a usable index (state_N.sqlite missing or failing schema // validation, or a rollout the index does not cover) the source reads each // rollout's head, and it took prompt text ONLY from `event_msg:user_message`. -// Codex 0.157 writes none: a typed prompt is a role-user response_item plus -// `event_msg:item_completed` with `item.type: 'UserMessage'`. Every 0.157 -// row came back with no prompt, was classified `empty`, and was hidden from -// the default listing. The input is a REAL 0.157.1 rollout head (see the -// fixture's evidence), with no index beside it, through the real source. +// Codex 0.157 writes none: a prompt is `event_msg:item_completed` with +// `item.type: 'UserMessage'`. Every 0.157 row came back with no prompt, was +// classified `empty`, and was hidden from the default listing. +// +// The fixture is a REAL, CONTIGUOUS 0.157.1 rollout head (see its evidence), +// with its expected first prompt recorded independently of the parser under +// test. The later cases compose synthetic records AROUND that real head, and +// say so. -type Record = { type: string; payload?: { type?: string; id?: string; item?: { type?: string; content?: Array<{ type: string; text?: string }> } } } -const records = fixture.records as Record[] -const threadId = records[0]!.payload!.id! -const typedPrompt = records - .find(record => record.payload?.type === 'item_completed' && record.payload.item?.type === 'UserMessage')! - .payload!.item!.content!.filter(part => part.type === 'text').map(part => part.text).join('') +type Rec = Record +const records = fixture.records as Rec[] +const threadId = (records[0]!.payload as { id: string }).id +const expected = fixture.expected +const at = (offsetMs: number) => new Date(Date.parse(expected.firstPromptTimestamp) + offsetMs).toISOString() +const userMessage = (timestamp: string, content: Array>): Rec => ({ + timestamp, type: 'event_msg', payload: { type: 'item_completed', item: { type: 'UserMessage', id: `u-${timestamp}`, content } }, +}) +const legacyMessage = (timestamp: string, message: string): Rec => ({ timestamp, type: 'event_msg', payload: { type: 'user_message', message } }) +const text = (value: string) => ({ type: 'text', text: value, text_elements: [] }) const dirs: string[] = [] afterEach(async () => { for (const dir of dirs.splice(0)) await rm(dir, { recursive: true, force: true }) }) -it('reads a 0.157 typed prompt from its UserMessage item when there is no index', async () => { +async function discoverRow(lines: Rec[]) { const codexHome = await mkdtemp(join(tmpdir(), 'codex-0157-home-')) dirs.push(codexHome) - const day = join(codexHome, 'sessions', '2026', '09', '27') + const day = join(codexHome, 'sessions', '2026', '09', '24') await mkdir(day, { recursive: true }) - await writeFile(join(day, `rollout-2026-09-27T03-06-42-${threadId}.jsonl`), records.map(record => JSON.stringify(record)).join('\n') + '\n') - + await writeFile(join(day, `rollout-2026-09-24T22-40-13-${threadId}.jsonl`), lines.map(line => JSON.stringify(line)).join('\n') + '\n') const source = new CodexConversationSource({ codexHome }) const family = await resolveFamily('/fixture/repo', 'everywhere', { listWorktrees: async () => [] }) const rows = await source.discover({ scope: 'everywhere', family }) - const row = rows.find(candidate => candidate.nativeId === threadId) - expect(source.lastDowngradeReason()).not.toBeNull() - expect(row).toBeDefined() - // Exactly the typed prompt: not the injected AGENTS.md or environment - // context that precede it as role-user response items. - expect(row!.userTexts).toEqual([typedPrompt]) - expect(row!.lastUserActivityAt).not.toBeNull() + return rows.find(candidate => candidate.nativeId === threadId)! +} + +it('reads a 0.157 prompt from its UserMessage item when there is no index', async () => { + const row = await discoverRow(records) + // Exactly the prompt: not the injected AGENTS.md or environment context + // that precede it as role-user response items in the real head. + expect(row.userTexts).toEqual(['x'.repeat(expected.firstPromptLength)]) + expect(row.lastUserActivityAt).toBe(Date.parse(expected.firstPromptTimestamp)) }) -it('lists a rollout carrying both shapes once, from the legacy event', async () => { - // A file that has `event_msg:user_message` uses it alone, so a rollout - // written with both carriers never shows its prompt twice. - const codexHome = await mkdtemp(join(tmpdir(), 'codex-0157-home-')) - dirs.push(codexHome) - const day = join(codexHome, 'sessions', '2026', '09', '27') - await mkdir(day, { recursive: true }) - const legacy = { timestamp: '2026-09-27T10:20:24.186Z', type: 'event_msg', payload: { type: 'user_message', message: typedPrompt } } - await writeFile(join(day, `rollout-2026-09-27T03-06-42-${threadId}.jsonl`), [...records, legacy].map(record => JSON.stringify(record)).join('\n') + '\n') +it('keeps both carriers\' prompts, counting a prompt written by both once', async () => { + // A session resumed across writer versions (#1407 reviews a and b): the + // legacy event and the item for prompt A, then an item for prompt B only. + const row = await discoverRow([ + ...records, + legacyMessage(at(1000), 'prompt A'), + userMessage(at(1001), [text('prompt A')]), + userMessage(at(2000), [text('prompt B')]), + ]) + expect(row.userTexts).toEqual(['x'.repeat(expected.firstPromptLength), 'prompt A', 'prompt B']) + expect(row.lastUserActivityAt).toBe(Date.parse(at(2000))) +}) - const source = new CodexConversationSource({ codexHome }) - const family = await resolveFamily('/fixture/repo', 'everywhere', { listWorktrees: async () => [] }) - const row = (await source.discover({ scope: 'everywhere', family })).find(candidate => candidate.nativeId === threadId) - expect(row!.userTexts).toEqual([typedPrompt]) +it('joins text parts with no separator and labels an image-only prompt', async () => { + // Codex's UserMessageItem::message() joins parts with no separator, and its + // preview text for an image-only message is `[Image]`. + const row = await discoverRow([ + ...records, + userMessage(at(1000), [text('two '), text('parts')]), + userMessage(at(2000), [{ type: 'image', image_url: 'data:image/png;base64,AAAA' }]), + ]) + expect(row.userTexts.slice(1)).toEqual(['two parts', '[Image]']) +}) + +it('takes user activity from the tail when the head bound hides a later prompt', async () => { + // 33 of 61 local 0.157.0 files have a prompt past the 200-record head; one + // came 46.8 hours after the first. The listing sorts by this time. + const filler = Array.from({ length: 300 }, (_, i) => ({ timestamp: at(10 + i), type: 'event_msg', payload: { type: 'token_count', info: null } })) + const later = at(46.8 * 3600 * 1000) + const row = await discoverRow([...records, ...filler, userMessage(later, [text('much later prompt')])]) + expect(row.userTexts).toEqual(['x'.repeat(expected.firstPromptLength)]) + expect(row.lastUserActivityAt).toBe(Date.parse(later)) }) diff --git a/testing/fixtures/conversations/codex-0157/typed-prompt-head.json b/testing/fixtures/conversations/codex-0157/typed-prompt-head.json index 50e509c14..99879f375 100644 --- a/testing/fixtures/conversations/codex-0157/typed-prompt-head.json +++ b/testing/fixtures/conversations/codex-0157/typed-prompt-head.json @@ -1,23 +1,28 @@ { - "evidence": "A real Codex 0.157.1 rollout head (#1363): session_meta, every role-user response_item before the first typed prompt (Codex-injected context such as AGENTS.md, and the typed prompt itself), and the first typed prompt's event_msg item_completed (item.type UserMessage). Codex 0.157 writes no event_msg user_message. Keys, types, roles, the CLI version, originator, timestamps and uuid ids are verbatim; every other string is replaced by the same number of x characters (newlines kept).", + "evidence": "A real, CONTIGUOUS Codex 0.157.1 rollout head (#1363, rebuilt for #1407 reviews a and b): all 10 records from session_meta through the first event_msg item_completed whose item.type is UserMessage, in file order, nothing removed or reordered. It is the one local 0.157 file whose first UserMessage is a typed prompt; the other 421 open with an orchestration hand-off. Codex 0.157 writes no event_msg user_message. Keys, types, roles, CLI version, originator, model provider, timestamps and uuid ids are verbatim; every other string is replaced by the same number of x characters (newlines kept).", "cliVersion": "0.157.1", + "expected": { + "firstPromptLength": 464, + "firstPromptTimestamp": "2026-09-25T05:44:03.249Z", + "records": 10 + }, "records": [ { - "timestamp": "2026-09-27T10:06:42.920Z", + "timestamp": "2026-09-25T05:44:02.541Z", "ordinal": 0, "type": "session_meta", "payload": { "creator_user_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "creator_account_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "session_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "id": "01a0e254-c7c2-73b1-bb9f-56a463914585", - "timestamp": "2026-09-27T10:06:42.167Z", - "cwd": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "creator_account_id": "f7f95f2c-542f-40da-b18e-fc45515cd355", + "session_id": "01a0d714-17ae-7631-888c-d700ca83e9e9", + "id": "01a0d714-17ae-7631-888c-d700ca83e9e9", + "timestamp": "2026-09-25T05:40:13.376Z", + "cwd": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "runtime_workspace_roots": [ - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ], "originator": "codex-tui", - "cli_version": "0.157.1", + "cli_version": "0.157.0", "source": "xxx", "thread_source": "xxxx", "model_provider": "openai", @@ -30,45 +35,116 @@ }, "history_mode": "xxxxxxxxx", "context_window": { - "window_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "window_id": "01a0d714-17ae-7631-888c-d7131e28e97a" }, "git": { "commit_hash": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "branch": "xxxx", "repository_url": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" } } }, { - "timestamp": "2026-09-27T10:06:45.967Z", - "ordinal": 5, + "timestamp": "2026-09-25T05:44:02.542Z", + "ordinal": 1, + "type": "event_msg", + "payload": { + "type": "task_started", + "turn_id": "01a0d717-96c1-7560-8ed0-755abd10c976", + "root_turn_id": "01a0d717-96c1-7560-8ed0-755abd10c976", + "started_at": 1790315042, + "model_context_window": 258400, + "collaboration_mode_kind": "xxxxxxx" + } + }, + { + "timestamp": "2026-09-25T05:44:03.199Z", + "ordinal": 2, "type": "response_item", "payload": { "type": "message", "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "role": "user", + "role": "developer", "content": [ { "type": "input_text", - "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxx\nxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxx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turn_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "create_time": 1790503605.944404, + "turn_id": "01a0d717-96c1-7560-8ed0-755abd10c976", + "create_time": 1790315043.199817, "content_item_kinds": [ - "xxxxxxxxxxxxxxxxxxxxxx", - "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxx", + "xxxxxxxxxxxxxxxxxxxxxxxx", + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ] } + }, + "metadata": { + "client_authored": false, + "mcp_attribution": { + "status": "xxxx" + } } }, { - "timestamp": "2026-09-27T10:06:46.180Z", - "ordinal": 8, + "timestamp": "2026-09-25T05:44:03.199Z", + "ordinal": 3, + "type": "response_item", + "payload": { + "type": "message", + "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "role": "developer", + "content": [ + { + "type": "input_text", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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{ + "timestamp": "2026-09-25T05:44:03.200Z", + "ordinal": 4, + "type": "response_item", + "payload": { + "type": "message", + "id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "role": "developer", + "content": [ + { + "type": "input_text", + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + } + ], + "internal_chat_message_metadata_passthrough": { + "turn_id": "01a0d717-96c1-7560-8ed0-755abd10c976", + "create_time": 1790315043.199818, + "content_item_kinds": [ + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + ] + } + } + }, + { + "timestamp": "2026-09-25T05:44:03.200Z", + "ordinal": 5, "type": "response_item", "payload": { "type": "message", @@ -77,28 +153,139 @@ "content": [ { "type": "input_text", - "text": "xxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxx\nxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxx" + }, + { + "type": "input_text", + "text": "xxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxx" } ], "internal_chat_message_metadata_passthrough": { - "turn_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "create_time": 1790503606.180568, + "turn_id": "01a0d717-96c1-7560-8ed0-755abd10c976", + "create_time": 1790315043.199819, "content_item_kinds": [ - "xxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxx", + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ] } - }, - "metadata": { - "client_authored": false, - "user_input_order": 0, - "mcp_attribution": { - "status": "xxxx" + } + }, + { + "timestamp": "2026-09-25T05:44:03.202Z", + "ordinal": 6, + "type": "world_state", + "payload": { + "full": true, + "state": { + "agents_md": { + "directory": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "text": "xxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + }, + "apps_instructions": false, + "collaboration_mode": { + "mode": "xxxxxxx", + "model": "xxxxxxxxx", + "instructions": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + }, + "context_window_guidance": "", + "environments": { + "environments": { + "local": { + "cwd": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "status": "xxxxxxxxx", + "shell": "xxx" + } + }, + "current_date": "xxxxxxxxxx", + "timezone": "xxxxxxxxxxxxxxxxxxx", + "filesystem": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + }, + "environments_instructions": false, + "git_attribution": false, + "host_skills": { + "body": "\nxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nxxxxxxxx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xxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", + "includeInstructions": true + }, + "managed_developer_instructions": {}, + "model": "xxxxxxxxx", + "multi_agent_mode": { + "mode": "xxxxxxxxxxxxxxxxxxx", + "usage_hint_hash": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + }, + "multi_agent_usage_hint": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "permissions": { + "instructions": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "approved_command_prefixes": [ + [ + "xxx", + "xxxx", + "xxxxxx" + ], + [ + "xx", + "xx", + "xxxxxxxxxxxxxxxxxxx" + ], + [ + "xxxxxxx", + "xxxxxxxxxxxxxxxxxxxxxxx", + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + ] + ] + }, + "persistent_mode": {}, + "plugins_instructions": false, + "realtime": { + "active": false + }, + "skills": { + "includeInstructions": true + } } } }, { - "timestamp": "2026-09-27T10:20:24.183Z", - "ordinal": 291, + "timestamp": "2026-09-25T05:44:03.203Z", + "ordinal": 7, + "type": "turn_context", + "payload": { + "turn_id": "01a0d717-96c1-7560-8ed0-755abd10c976", + "root_turn_id": "01a0d717-96c1-7560-8ed0-755abd10c976", + "disabled_plugin_ids": [], + "cwd": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "workspace_roots": [ + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + ], + "current_date": "xxxxxxxxxx", + "timezone": "xxxxxxxxxxxxxxxxxxx", + "approval_policy": "xxxxx", + "approvals_reviewer": "xxxx", + "sandbox_policy": { + "type": "danger-full-access" + }, + "permission_profile": { + "type": "disabled" + }, + "model": "xxxxxxxxx", + "comp_hash": "xxxx", + "personality": "xxxxxxxxx", + "collaboration_mode": { + "mode": "xxxxxxx", + "settings": { + "model": "xxxxxxxxx", + "reasoning_effort": "xxxx", + "developer_instructions": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" + } + }, + "multi_agent_version": "xx", + "realtime_active": false, + "effort": "xxxx", + "summary": "xxxx" + } + }, + { + "timestamp": "2026-09-25T05:44:03.248Z", + "ordinal": 8, "type": "response_item", "payload": { "type": "message", @@ -107,12 +294,12 @@ "content": [ { "type": "input_text", - "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxx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xxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" } ], "internal_chat_message_metadata_passthrough": { - "turn_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "create_time": 1790504424.182083, + "turn_id": "01a0d717-96c1-7560-8ed0-755abd10c976", + "create_time": 1790315043.248249, "content_item_kinds": [ "xxxxxxxxx" ] @@ -120,46 +307,34 @@ }, "metadata": { "client_authored": false, - "user_input_order": 6, + "user_input_order": 0, "mcp_attribution": { - "status": "xxxxxxxx", - "sources": [ - { - "server_name": "xxxxxxxxxx", - "tool_name": "xxxxxxxx", - "first_turn_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - }, - { - "server_name": "xxxxxxxxxx", - "tool_name": "xxxxxxxxxxx", - "first_turn_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" - } - ] + "status": "xxxx" } } }, { - "timestamp": "2026-09-27T10:20:24.185Z", - "ordinal": 292, + "timestamp": "2026-09-25T05:44:03.249Z", + "ordinal": 9, "type": "event_msg", "payload": { "type": "item_completed", - "thread_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "turn_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "thread_id": "01a0d714-17ae-7631-888c-d700ca83e9e9", + "turn_id": "01a0d717-96c1-7560-8ed0-755abd10c976", "item": { "type": "UserMessage", - "id": "01a0e261-52f6-7542-a5b7-e74b78ff1264", - "client_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", + "id": "01a0d717-99b0-7503-a3cf-6863399ec492", + "client_id": "3ca40c42-52a0-4681-8695-109056c9bf86", "content": [ { "type": "text", - "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxx\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "text_elements": [] } ] }, - "started_at_ms": 1790504424185, - "completed_at_ms": 1790504424185 + "started_at_ms": 1790315043249, + "completed_at_ms": 1790315043249 } } ] From da06c8ceb120451b54361316fcdb7ae00f8790b4 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 05:20:49 -0700 Subject: [PATCH 20/40] docs(plan): AI Workspace write whose status save fails (#1285) Co-Authored-By: Claude Opus 5.5 --- ...09-27-ai-workspace-write-status-warning.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docs/plans/2026-09-27-ai-workspace-write-status-warning.md diff --git a/docs/plans/2026-09-27-ai-workspace-write-status-warning.md b/docs/plans/2026-09-27-ai-workspace-write-status-warning.md new file mode 100644 index 000000000..9890e1965 --- /dev/null +++ b/docs/plans/2026-09-27-ai-workspace-write-status-warning.md @@ -0,0 +1,22 @@ +# An AI Workspace write whose status save fails is reported as done (#1285) + +## Problem +`AiWorkspaceRegistry.writeFile` first replaces the user's file on disk (`atomicWriteTextFile`), then refreshes the entry status. The refresh saves registry state, and a save must first make any preservation copy it owes (#1260: rows the load could not read are copied aside before a save drops them). +- **When the copy is blocked** (for example, a directory sits on `ai-workspaces.json.invalid-.json`), the save throws. `writeFile` then returned `{ ok: false, error: "is a directory" }` although the file was written. +- **What that caused.** An agent or the editor told "failed" retries (converging through the version conflict) or reports a failure that did not happen. +- **Cosmetic.** Refused saves relayed the raw errno text, with no hint that clearing the copy path unblocks them. + +## Evidence +- **The sequence** was reproduced and confirmed by #1260 review B (round 2), and recorded as residual #1285 (steering q24). The owed-copy state itself comes from the real registry file: `testing/fixtures/ai-workspace/real-workspaces-2026-09-25.json`, two real workspaces from the owner's `ai-workspaces.json`. The existing #1260 tests make that state owe a copy by marking one real workspace malformed, and block the copy with a directory. +- **The only consumer** of the write result is the renderer editor over IPC (`src/main/ipc/aiWorkspace.ts` → `AiWorkspaceEditor.tsx`). There is no MCP tool on this path. + +## Decisions (defaults) +1. **A failed status refresh after a successful write does not fail the write.** It returns `ok: true` with an optional `warning` on the success branch of `AiWorkspaceWriteFileResult`, documented as "the file IS written; do not retry". It logs the error, and still emits `file-written` to every workspace holding the file. +2. **The owed-copy invariant is unchanged.** The state file is still never saved while a copy is owed. +3. **A refused save explains itself.** `preserveOwedCopy` rewrites a copy failure: "AI Workspace storage needs attention: N unreadable row(s) must be copied aside before saving, and the copy next to could not be written (). Clear whatever occupies that copy path to continue." Only the errno code is kept, not the raw text. + +## Tests (fail-first, `AiWorkspaceRegistry.test.ts`) +The input is the real recorded workspace state. One real entry is pointed at a temp file (the recorded paths are redacted), and one real workspace is made malformed so a copy is owed. The copy path is blocked with a directory. +- `writeFile` puts the new text on disk and returns `ok: true` with a status warning. The state file is unchanged. Red without the fix: `{ ok: false, error: 'is a directory' }`. +- A following `create` is refused with the actionable message. +- Mutations: dropping the warning, and misreporting the write as failed, each fail the first test. From 57ffbb6b4e27912b23f6ad3fa80885a1b284dafc Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 05:21:14 -0700 Subject: [PATCH 21/40] docs(commands): plan reporting a refused clipboard write (#1250 row 9) Co-Authored-By: Claude Opus 5.5 --- .../2026-09-27-copy-last-response-failure.md | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 docs/plans/2026-09-27-copy-last-response-failure.md diff --git a/docs/plans/2026-09-27-copy-last-response-failure.md b/docs/plans/2026-09-27-copy-last-response-failure.md new file mode 100644 index 000000000..7d00be1d6 --- /dev/null +++ b/docs/plans/2026-09-27-copy-last-response-failure.md @@ -0,0 +1,27 @@ +# Copy commands say when the clipboard refused (#1250 row 9) + +Short plan: a bug with a known root cause. The row comes from `temp/quality-loop/hunt-c3.md` (row 9, P3). #1250 is a batch issue, so this PR is `Refs #1250`. + +## Outcome +**Copy Last Response** shows "Copied to clipboard" only when the copy happened. When `navigator.clipboard.writeText` rejects (the document is not focused, or permission is denied), it says so in fixed words. The sibling **Copy Resume Command** failure shows fixed words, not the raw DOMException text. + +## Root cause (verified in source, origin/main) +- `paneCommands.ts` `copy-last-assistant.run`: `void navigator.clipboard.writeText(text)`, then an unconditional "Copied to clipboard" toast. A rejection is an unhandled promise, and the toast lies. +- `sessionCommands.ts` `copy-resume-command.run`: catches, but renders `copy failed: ${err.message}` (raw browser text, q22). + +## Design (contract) +- `copy-last-assistant.run` awaits the write. On success: "Copied to clipboard". On rejection: "Couldn't copy to the clipboard. Click into the app and try again." + - Clipboard writes need a focused document; the palette or context menu can leave focus elsewhere. +- `copy-resume-command` uses the same failure sentence. The success toast is unchanged. +- The sentence is a constant: `CLIPBOARD_WRITE_FAILED` in `features/workspace/commands/clipboardFailure.ts`. + +## Tests +New `paneCommands.copy.renderer.test.ts`. The runtime entries are the recorded bundle `testing/fixtures/rendering-bundles/2026-05-20T19-11-51-193-d4a44a16.json`; the clipboard is stubbed (the one edge). +- A rejecting write shows the failure sentence, never "Copied". +- A resolving write shows "Copied to clipboard". +- The resume command's rejection shows the fixed sentence, without the raw text. +- Red on main. + +## Out of scope +- #1250's other rows. +- Debug-panel copy buttons (developer surfaces). From ba94fef3d9e48d14e0f6ed86dfe5abc6d783e18c Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 05:21:19 -0700 Subject: [PATCH 22/40] test(ai-workspace): a write whose status save fails must report the write (#1285), red Co-Authored-By: Claude Opus 5.5 --- .../aiWorkspace/AiWorkspaceRegistry.test.ts | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/main/aiWorkspace/AiWorkspaceRegistry.test.ts b/src/main/aiWorkspace/AiWorkspaceRegistry.test.ts index 4b710796c..bdd6cce38 100644 --- a/src/main/aiWorkspace/AiWorkspaceRegistry.test.ts +++ b/src/main/aiWorkspace/AiWorkspaceRegistry.test.ts @@ -287,3 +287,51 @@ describe('malformed rows in a real registry (#1246)', () => { expect(await registry.list()).toHaveLength(2) }) }) + +// #1285 (residual of #1260 review B, round 2): the registry owes a +// preservation copy of rows it could not read, and that copy is blocked (a +// directory sits on its path). The user's file write succeeds; only the status +// refresh that follows it, which saves state and so must make the owed copy +// first, fails. Reporting the WRITE as failed told the editor (and an agent) +// that the edit had not landed when it had. +// +// The state is the REAL recorded registry (two workspaces from the owner's +// ai-workspaces.json). Its paths are redacted, so one real entry is pointed at +// a temp file; one real workspace is made malformed, exactly as the #1260 +// owed-copy tests do, so a copy is owed. +describe('a write whose status refresh cannot be saved (#1285)', () => { + it('reports the write as done, with a warning, when only the status save fails', async () => { + const recorded = JSON.parse(await readFile(join(import.meta.dirname, + '../../../testing/fixtures/ai-workspace/real-workspaces-2026-09-25.json'), 'utf8')) as { + state: { workspaces: Array> } + } + const state = recorded.state + const root = await mkdtemp(join(tmpdir(), 'agent-code-ai-workspace-owed-')) + tempRoots.push(root) + const filePath = join(root, 'attached.txt') + await writeFile(filePath, 'v1') + state.workspaces[0]!.entries[0]!.path = filePath + state.workspaces[0]!.entries[0]!.projectRoot = root + state.workspaces[1]!.updatedAt = 1789000000 + const statePath = join(root, 'ai-workspaces.json') + const source = JSON.stringify(state) + await writeFile(statePath, source) + const { createHash } = await import('node:crypto') + const { mkdir } = await import('fs/promises') + await mkdir(join(root, `ai-workspaces.json.invalid-${createHash('sha256').update(source).digest('hex').slice(0, 16)}.json`)) + + const registry = new AiWorkspaceRegistry(statePath) + const target = await realpath(filePath) + const result = await registry.writeFile({ path: target, text: 'v2' }) + + // The write landed, and the result says so, with the status failure as a + // warning rather than as the outcome. + expect(await readFile(target, 'utf8')).toBe('v2') + expect(result).toMatchObject({ ok: true, path: target }) + expect((result as { warning?: string }).warning).toMatch(/saved.*status/i) + // The stored state was not rewritten: the owed copy still blocks saves. + expect(await readFile(statePath, 'utf8')).toBe(source) + // A refused save says why and how to unblock it, not the raw errno text. + await expect(registry.create({ name: 'Blocked' })).rejects.toThrow(/needs attention.*Clear whatever occupies/s) + }) +}) From 462a2e22ecfe725147f25f8e8a9393018bddcbf1 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 05:22:13 -0700 Subject: [PATCH 23/40] fix(ai-workspace): a write whose status save fails is reported as done, with a warning (#1285) Co-Authored-By: Claude Opus 5.5 --- src/main/aiWorkspace/AiWorkspaceRegistry.ts | 29 +++++++++++++++++++-- src/mcp/shared/aiWorkspaceTypes.ts | 12 ++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/main/aiWorkspace/AiWorkspaceRegistry.ts b/src/main/aiWorkspace/AiWorkspaceRegistry.ts index 7572e6671..e1567b3e6 100644 --- a/src/main/aiWorkspace/AiWorkspaceRegistry.ts +++ b/src/main/aiWorkspace/AiWorkspaceRegistry.ts @@ -413,7 +413,20 @@ export class AiWorkspaceRegistry extends EventEmitter { conflictKind: result.conflictKind, } } - await this.refreshEntriesForPath(target) + // WHY a failed status refresh does not fail the write (#1285): the + // user's file is already replaced on disk by this point. The refresh + // saves registry state, and a save can be refused (a preservation + // copy it owes is blocked; see preserveOwedCopy). Returning + // `ok: false` then told an agent its edit had not landed, so it + // retried or reported a failure that never happened. The write is + // reported as done, and the stale status is a warning. + let warning: string | undefined + try { + await this.refreshEntriesForPath(target) + } catch (err) { + warning = `The file was saved, but its AI Workspace status could not be updated: ${errorMessage(err)}` + console.warn('[ai-workspace] status refresh after a write failed:', err) + } // One physical file can be curated into several workspaces. Every // visible consumer needs the write signal; choosing an arbitrary first // workspace would leave the others showing stale buffer metadata. @@ -431,6 +444,7 @@ export class AiWorkspaceRegistry extends EventEmitter { mtimeMs: result.stat.mtimeMs, size: result.stat.size, version: result.version, + ...(warning ? { warning } : {}), } }) } catch (err) { @@ -605,7 +619,18 @@ export class AiWorkspaceRegistry extends EventEmitter { private async preserveOwedCopy(): Promise { if (!this.owedCopy) return const { text, setAside } = this.owedCopy - const copy = await preserveInvalidBytes(`${this.stateFile}.invalid`, text) + // WHY the error is rewritten (#1285): the raw errno text ("is a + // directory") told the user nothing about why every save was refused or + // how to unblock it. Saves stay refused until the copy exists, because + // the next save drops the unreadable rows. + const copy = await preserveInvalidBytes(`${this.stateFile}.invalid`, text).catch(err => { + const code = (err as NodeJS.ErrnoException).code + throw new Error( + `AI Workspace storage needs attention: ${setAside} unreadable row(s) must be copied aside before saving, ` + + `and the copy next to ${this.stateFile} could not be written${code ? ` (${code})` : ''}. ` + + 'Clear whatever occupies that copy path to continue.', + ) + }) this.owedCopy = null console.warn(`[ai-workspace] set aside ${setAside} malformed row(s); original preserved at ${copy}`) } diff --git a/src/mcp/shared/aiWorkspaceTypes.ts b/src/mcp/shared/aiWorkspaceTypes.ts index 61ef7c9a5..c8d7710ee 100644 --- a/src/mcp/shared/aiWorkspaceTypes.ts +++ b/src/mcp/shared/aiWorkspaceTypes.ts @@ -100,7 +100,17 @@ export type AiWorkspaceWriteFileParams = { } export type AiWorkspaceWriteFileResult = - | { ok: true; path: string; mtimeMs: number; size: number; version: string } + | { + ok: true + path: string + mtimeMs: number + size: number + version: string + /** The file IS written, but a follow-up step failed: today, saving the + * refreshed file status (#1285). Never set when the write itself + * failed; a caller must not retry the write because of it. */ + warning?: string + } | { ok: false error: string From 589d42a98c70bd5c3113ce5a40ea15ad1d2c2b89 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 05:30:46 -0700 Subject: [PATCH 24/40] fix(ai-workspace): show the storage warning, guard change emits, cause-specific advice (review a) Co-Authored-By: Claude Opus 5.5 --- ...09-27-ai-workspace-write-status-warning.md | 8 ++++ .../aiWorkspace/AiWorkspaceRegistry.test.ts | 44 ++++++++++++++++-- src/main/aiWorkspace/AiWorkspaceRegistry.ts | 46 ++++++++++++++++--- .../ai-workspace/ui/AiWorkspaceEditor.tsx | 13 +++++- 4 files changed, 100 insertions(+), 11 deletions(-) diff --git a/docs/plans/2026-09-27-ai-workspace-write-status-warning.md b/docs/plans/2026-09-27-ai-workspace-write-status-warning.md index 9890e1965..1b8526b3b 100644 --- a/docs/plans/2026-09-27-ai-workspace-write-status-warning.md +++ b/docs/plans/2026-09-27-ai-workspace-write-status-warning.md @@ -20,3 +20,11 @@ The input is the real recorded workspace state. One real entry is pointed at a t - `writeFile` puts the new text on disk and returns `ok: true` with a status warning. The state file is unchanged. Red without the fix: `{ ok: false, error: 'is a directory' }`. - A following `create` is refused with the actionable message. - Mutations: dropping the warning, and misreporting the write as failed, each fail the first test. + +## Review a (round 1) +- **The editor showed no warning.** It now keeps a separate `storageWarning`, set from the write result on both Save and Overwrite and cleared by the next write that has no warning. It is shown through the file list's existing alert (`error ?? storageWarning`). It cannot ride `error`, because `loadWorkspace` clears that after every save. +- **The warning is fixed text.** `AI_WORKSPACE_STATUS_NOT_SAVED` is main's own sentence; the raw cause goes only to the log. +- **A throwing `changed` listener no longer fails a landed write.** Each emit is guarded, so every other workspace still hears about the write. +- **Advice matches the cause.** An occupied copy path (EISDIR/EEXIST/ENOTDIR), a missing folder (ENOENT), a permission or read-only refusal, and a full disk each get their own advice. +- **Tests added:** the file reads back after the warning; an ordinary write carries no warning; a throwing listener still gives `ok: true`, and the listener is still called; ENOENT advice. The always-warn, unguarded-emit and wrong-advice mutations each fail. +- **Not tested:** the editor's display of the notice is not covered at the component level (there is no AiWorkspaceEditor renderer harness). The change there is three lines, and it is stated in the body. diff --git a/src/main/aiWorkspace/AiWorkspaceRegistry.test.ts b/src/main/aiWorkspace/AiWorkspaceRegistry.test.ts index bdd6cce38..65f8108b1 100644 --- a/src/main/aiWorkspace/AiWorkspaceRegistry.test.ts +++ b/src/main/aiWorkspace/AiWorkspaceRegistry.test.ts @@ -3,7 +3,7 @@ import { tmpdir } from 'os' import { dirname, join } from 'path' import { afterEach, describe, expect, it } from 'vitest' -import { AiWorkspaceRegistry } from './AiWorkspaceRegistry.js' +import { AI_WORKSPACE_STATUS_NOT_SAVED, AiWorkspaceRegistry } from './AiWorkspaceRegistry.js' const tempRoots: string[] = [] @@ -328,10 +328,48 @@ describe('a write whose status refresh cannot be saved (#1285)', () => { // warning rather than as the outcome. expect(await readFile(target, 'utf8')).toBe('v2') expect(result).toMatchObject({ ok: true, path: target }) - expect((result as { warning?: string }).warning).toMatch(/saved.*status/i) + expect((result as { warning?: string }).warning).toBe(AI_WORKSPACE_STATUS_NOT_SAVED) + // The file stays fully usable: it reads back through the registry. + expect(await registry.readFile(target)).toMatchObject({ ok: true, text: 'v2' }) // The stored state was not rewritten: the owed copy still blocks saves. expect(await readFile(statePath, 'utf8')).toBe(source) // A refused save says why and how to unblock it, not the raw errno text. - await expect(registry.create({ name: 'Blocked' })).rejects.toThrow(/needs attention.*Clear whatever occupies/s) + await expect(registry.create({ name: 'Blocked' })).rejects.toThrow(/needs attention.*\(EISDIR\).*already occupies the copy path/s) + }) + + it('warns on no ordinary write, and tells every workspace even when a listener throws', async () => { + // #1416 review a: a throwing `changed` listener (the production one + // broadcasts to every window) turned a landed write into `ok: false`, + // and stopped the second workspace hearing about it. + const { registry, filePath } = await registryWithAttachedFile('v1') + await registry.list() + const heard: string[] = [] + registry.on('changed', (event: { workspaceId: string }) => { + heard.push(event.workspaceId) + throw new Error('event delivery failed') + }) + const result = await registry.writeFile({ path: filePath, text: 'v2' }) + expect(result).toMatchObject({ ok: true }) + expect(result).not.toHaveProperty('warning') + expect(await readFile(filePath, 'utf8')).toBe('v2') + expect(heard).toEqual(['workspace-1']) + }) + + it('gives advice that matches the cause when the owed copy cannot be written', async () => { + // A missing state folder is not "something occupies the path". + const root = await mkdtemp(join(tmpdir(), 'agent-code-ai-workspace-enoent-')) + tempRoots.push(root) + const stateDir = join(root, 'state') + const { mkdir } = await import('fs/promises') + await mkdir(stateDir) + const statePath = join(stateDir, 'ai-workspaces.json') + const source = JSON.stringify({ workspaces: [null] }) + await writeFile(statePath, source) + const { createHash } = await import('node:crypto') + await mkdir(join(stateDir, `ai-workspaces.json.invalid-${createHash('sha256').update(source).digest('hex').slice(0, 16)}.json`)) + const registry = new AiWorkspaceRegistry(statePath) + await registry.list() + await rm(stateDir, { recursive: true }) + await expect(registry.create({ name: 'Blocked' })).rejects.toThrow(/\(ENOENT\).*folder holding .* is missing/s) }) }) diff --git a/src/main/aiWorkspace/AiWorkspaceRegistry.ts b/src/main/aiWorkspace/AiWorkspaceRegistry.ts index e1567b3e6..c49edb355 100644 --- a/src/main/aiWorkspace/AiWorkspaceRegistry.ts +++ b/src/main/aiWorkspace/AiWorkspaceRegistry.ts @@ -161,6 +161,12 @@ export interface AiWorkspaceRegistry { emit(event: 'changed', payload: AiWorkspaceChangeEvent): boolean } +/** The fixed warning a write returns when the file is written but the + * registry could not save its status (#1285). Exported so the editor and + * tests read one sentence. */ +export const AI_WORKSPACE_STATUS_NOT_SAVED = + 'The file was saved, but AI Workspace could not save its status. Other AI Workspace changes will fail until its storage is fixed.' + export class AiWorkspaceRegistry extends EventEmitter { private readonly workspaces = new Map() private loadPromise: Promise | null = null @@ -420,22 +426,35 @@ export class AiWorkspaceRegistry extends EventEmitter { // `ok: false` then told an agent its edit had not landed, so it // retried or reported a failure that never happened. The write is // reported as done, and the stale status is a warning. + // + // The warning is a FIXED sentence (#1416 review a): the editor shows + // it, and a raw filesystem message never belongs on a user-visible + // surface. The cause goes to the log. let warning: string | undefined try { await this.refreshEntriesForPath(target) } catch (err) { - warning = `The file was saved, but its AI Workspace status could not be updated: ${errorMessage(err)}` + warning = AI_WORKSPACE_STATUS_NOT_SAVED console.warn('[ai-workspace] status refresh after a write failed:', err) } // One physical file can be curated into several workspaces. Every // visible consumer needs the write signal; choosing an arbitrary first // workspace would leave the others showing stale buffer metadata. + // + // Each emit is guarded (#1416 review a): a listener that throws (the + // production one broadcasts to every window) must neither turn this + // landed write into `ok: false`, the #1285 failure on another step, + // nor stop the remaining workspaces from hearing about it. for (const workspace of this.workspaces.values()) { if (workspace.entries.some(entry => entry.path === target)) { - this.emit('changed', { - workspaceId: workspace.workspaceId, - kind: 'file-written', - }) + try { + this.emit('changed', { + workspaceId: workspace.workspaceId, + kind: 'file-written', + }) + } catch (err) { + console.warn('[ai-workspace] a file-written listener failed:', err) + } } } return { @@ -625,10 +644,23 @@ export class AiWorkspaceRegistry extends EventEmitter { // the next save drops the unreadable rows. const copy = await preserveInvalidBytes(`${this.stateFile}.invalid`, text).catch(err => { const code = (err as NodeJS.ErrnoException).code + // WHY the advice depends on the code (#1416 review a): "clear what + // occupies the path" is only true when something occupies it. A + // missing directory, a permission or read-only refusal and a full disk + // each need a different fix, and advice for the wrong one sends the + // user looking for an occupant that does not exist. + const advice = code === 'EISDIR' || code === 'EEXIST' || code === 'ENOTDIR' + ? `Something already occupies the copy path next to ${this.stateFile}; move it away to continue.` + : code === 'ENOENT' + ? `The folder holding ${this.stateFile} is missing; restore it to continue.` + : code === 'EACCES' || code === 'EPERM' || code === 'EROFS' + ? `The folder holding ${this.stateFile} is not writable; fix its permissions to continue.` + : code === 'ENOSPC' + ? 'The disk is full; free some space to continue.' + : `Check that the folder holding ${this.stateFile} is writable to continue.` throw new Error( `AI Workspace storage needs attention: ${setAside} unreadable row(s) must be copied aside before saving, ` + - `and the copy next to ${this.stateFile} could not be written${code ? ` (${code})` : ''}. ` + - 'Clear whatever occupies that copy path to continue.', + `and the copy could not be written${code ? ` (${code})` : ''}. ${advice}`, ) }) this.owedCopy = null diff --git a/src/renderer/src/features/ai-workspace/ui/AiWorkspaceEditor.tsx b/src/renderer/src/features/ai-workspace/ui/AiWorkspaceEditor.tsx index bd4781d3d..abd0b0463 100644 --- a/src/renderer/src/features/ai-workspace/ui/AiWorkspaceEditor.tsx +++ b/src/renderer/src/features/ai-workspace/ui/AiWorkspaceEditor.tsx @@ -75,6 +75,15 @@ export function AiWorkspaceEditor({ workspaceId, visible, onClose, toolbarAction const [loading, setLoading] = useState(true) const [saveAllPending, setSaveAllPending] = useState(false) const [error, setError] = useState(() => cached?.error ?? null) + // WHY a separate, retained notice (#1285, #1416 review a): a write can land + // while the registry fails to save its status (a preservation copy it owes + // is blocked). The file is saved, so this is not the tab's error, but the + // user must learn that AI Workspace storage is blocked, since every later + // collection change will be refused. It cannot ride `error`: loadWorkspace, + // which runs after every save, clears that. It lasts until a write comes + // back without the warning. The text is main's fixed sentence, never a raw + // filesystem message. + const [storageWarning, setStorageWarning] = useState(null) const [fileOrder, setFileOrder] = useState(() => cached?.fileOrder ?? []) const [openFiles, setOpenFiles] = useState>( () => cached?.openFiles ?? {}, @@ -554,6 +563,7 @@ export function AiWorkspaceEditor({ workspaceId, visible, onClose, toolbarAction }) return null } + if (mountedRef.current) setStorageWarning(result.warning ?? null) applyOpenFiles(prev => { const current = prev[entryId] if (!current || current.generation !== buffer.generation) return prev @@ -760,6 +770,7 @@ export function AiWorkspaceEditor({ workspaceId, visible, onClose, toolbarAction } }) if (result.ok) { + if (mountedRef.current) setStorageWarning(result.warning ?? null) await revalidateEntryAfterWrite(entryId, entry.path, buffer.generation) } else { entryReadGenerationRef.current.set( @@ -794,7 +805,7 @@ export function AiWorkspaceEditor({ workspaceId, visible, onClose, toolbarAction title={workspace?.name ?? 'AI Workspace'} entries={workspace?.entries ?? []} loading={loading} - error={error} + error={error ?? storageWarning} activeEntryId={activeFilePath} onOpenEntry={entry => void openEntry(entry)} onRefresh={() => void refreshWorkspace()} From 690e634cf37f644cab8893afa62d435bd82cba22 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 05:32:33 -0700 Subject: [PATCH 25/40] fix(commands): copy commands say when the clipboard refused (#1250 row 9) Copy Last Response awaited nothing and always said Copied; it now awaits the write and shows a fixed failure sentence on rejection. Copy Resume Command's failure uses the same sentence instead of the raw DOMException text. Co-Authored-By: Claude Opus 5.5 --- .../workspace/commands/clipboardFailure.ts | 7 ++ .../copyCommands.clipboard.renderer.test.ts | 86 +++++++++++++++++++ .../workspace/commands/paneCommands.ts | 14 ++- .../workspace/commands/sessionCommands.ts | 8 +- 4 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 src/renderer/src/features/workspace/commands/clipboardFailure.ts create mode 100644 src/renderer/src/features/workspace/commands/copyCommands.clipboard.renderer.test.ts diff --git a/src/renderer/src/features/workspace/commands/clipboardFailure.ts b/src/renderer/src/features/workspace/commands/clipboardFailure.ts new file mode 100644 index 000000000..3c9914dcf --- /dev/null +++ b/src/renderer/src/features/workspace/commands/clipboardFailure.ts @@ -0,0 +1,7 @@ +// What a copy command says when the clipboard refused the write (#1250 row 9). +// +// WHY fixed words: the rejection is a DOMException whose message is browser +// text ("Document is not focused."), and user-visible text is curated (q22). +// WHY this advice: Electron's clipboard write needs a focused document, and +// the usual cause is focus left elsewhere by the palette or a context menu. +export const CLIPBOARD_WRITE_FAILED = "Couldn't copy to the clipboard. Click into the app and try again." diff --git a/src/renderer/src/features/workspace/commands/copyCommands.clipboard.renderer.test.ts b/src/renderer/src/features/workspace/commands/copyCommands.clipboard.renderer.test.ts new file mode 100644 index 000000000..031997b29 --- /dev/null +++ b/src/renderer/src/features/workspace/commands/copyCommands.clipboard.renderer.test.ts @@ -0,0 +1,86 @@ +import { readFileSync } from 'node:fs' + +import { afterEach, describe, expect, it, vi } from 'vitest' + +import { emptyRuntime } from '@renderer/session-runtime/state' +import type { CommandContext } from '@renderer/features/command-palette/types' +import type { Workspace } from '@renderer/workspace/hook' +import { CLIPBOARD_WRITE_FAILED } from '@renderer/features/workspace/commands/clipboardFailure' +import { paneCommands } from '@renderer/features/workspace/commands/paneCommands' +import { sessionCommands } from '@renderer/features/workspace/commands/sessionCommands' +import { oneLaneStage } from '@renderer/workspace/testing/stageFixtures' + +// #1250 row 9: Copy Last Response wrote to the clipboard fire-and-forget and +// said "Copied to clipboard" whatever happened, so a refused write (Electron +// refuses when the document is not focused) was silent under a toast that said +// the opposite. The resume-command copy did catch, but showed the raw +// DOMException text (q22). +// +// The runtime entries are a RECORDED session (a Codex rendering bundle). The +// clipboard is the one replaced edge: its rejection is the case under test. + +const bundle = JSON.parse(readFileSync('testing/fixtures/rendering-bundles/2026-05-20T19-11-51-193-d4a44a16.json', 'utf8')) as { + input: { provider: string; entries: unknown[] } +} + +const originalClipboard = Object.getOwnPropertyDescriptor(navigator, 'clipboard') +afterEach(() => { + if (originalClipboard) Object.defineProperty(navigator, 'clipboard', originalClipboard) + else Reflect.deleteProperty(navigator, 'clipboard') +}) + +function stubClipboard(writeText: (text: string) => Promise) { + Object.defineProperty(navigator, 'clipboard', { configurable: true, value: { writeText: vi.fn(writeText) } }) +} + +function context(kind: string) { + const toasts: string[] = [] + const ctx = { + workspace: { + state: { + activeTabId: 'tab', + stage: oneLaneStage('agent'), + pinnedSessionIds: [], + sessions: { agent: { cwd: '/projects/app', kind, providerSessionId: 'provider-abc', projectId: 'tab', joinedAt: 0 } }, + tabs: [{ id: 'tab' }], + }, + getRuntime: () => ({ ...emptyRuntime(), entries: bundle.input.entries }), + showPaneToast: (_sessionId: string, message: string) => { toasts.push(message) }, + } as unknown as Workspace, + ui: { closePalette: vi.fn() }, + flags: {}, + } as unknown as CommandContext + return { ctx, toasts } +} + +const copyLast = paneCommands.find(command => command.id === 'copy-last-assistant')! +const copyResume = sessionCommands.find(command => command.id === 'copy-resume-command')! + +describe('copy commands and a refused clipboard', () => { + const refused = () => Promise.reject(new DOMException('Document is not focused.', 'NotAllowedError')) + + it('says a refused Copy Last Response did not copy, and never claims it did', async () => { + stubClipboard(refused) + const { ctx, toasts } = context(bundle.input.provider) + await copyLast.run(ctx) + expect(toasts).toEqual([CLIPBOARD_WRITE_FAILED]) + }) + + it('says Copied only after the clipboard took the recorded response', async () => { + let written = '' + stubClipboard(async text => { written = text }) + const { ctx, toasts } = context(bundle.input.provider) + await copyLast.run(ctx) + expect(written.length).toBeGreaterThan(0) + expect(toasts).toEqual(['Copied to clipboard']) + }) + + it('says a refused resume-command copy in fixed words, not the browser text', async () => { + stubClipboard(refused) + const { ctx, toasts } = context('claude') + expect(copyResume.when?.(ctx)).toBe(true) + await copyResume.run(ctx) + expect(toasts).toEqual([CLIPBOARD_WRITE_FAILED]) + expect(toasts.join(' ')).not.toContain('not focused') + }) +}) diff --git a/src/renderer/src/features/workspace/commands/paneCommands.ts b/src/renderer/src/features/workspace/commands/paneCommands.ts index 009999f9c..faca0b74a 100644 --- a/src/renderer/src/features/workspace/commands/paneCommands.ts +++ b/src/renderer/src/features/workspace/commands/paneCommands.ts @@ -15,6 +15,7 @@ import { commandTargetSessionId } from '@renderer/workspace/hook/selectors/comma import { submitActiveComposer } from '@renderer/workspace/tile-tree/TileLeaf/composerEnterRegistry' import { sessionHasTranscript } from '@renderer/workspace/transcriptAvailability' import { isWorkingAgent } from '@renderer/workspace/agentFollow' +import { CLIPBOARD_WRITE_FAILED } from '@renderer/features/workspace/commands/clipboardFailure' // DELETED with the unified layout (#992) — see RETIRED_COMMAND_IDS in // catalog.test.ts for the ledger: @@ -454,14 +455,23 @@ export const paneCommands: CommandDef[] = [ // its committed entries, so there is a real last response to copy. return sessionHasTranscript(workspace.state.sessions[sessionId]) }, - run: ({ workspace, target }) => { + run: async ({ workspace, target }) => { const sessionId = commandTarget({ workspace, target }) if (!sessionId) return const runtime = workspace.getRuntime(sessionId) const kind = workspace.state.sessions[sessionId]?.kind ?? DEFAULT_PROVIDER const text = extractLastAssistantText(runtime.entries, kind) if (text) { - void navigator.clipboard.writeText(text) + // WHY awaited (#1250 row 9): the write used to be fire-and-forget + // with "Copied" shown unconditionally, so a refused write (an + // unfocused document) was an unhandled rejection under a toast that + // said the opposite. + try { + await navigator.clipboard.writeText(text) + } catch { + workspace.showPaneToast(sessionId, CLIPBOARD_WRITE_FAILED) + return + } workspace.showPaneToast(sessionId, 'Copied to clipboard') return } diff --git a/src/renderer/src/features/workspace/commands/sessionCommands.ts b/src/renderer/src/features/workspace/commands/sessionCommands.ts index 905804847..80ddcf0d5 100644 --- a/src/renderer/src/features/workspace/commands/sessionCommands.ts +++ b/src/renderer/src/features/workspace/commands/sessionCommands.ts @@ -1,4 +1,5 @@ import { commandTarget } from '@renderer/features/command-palette/commandTarget' +import { CLIPBOARD_WRITE_FAILED } from '@renderer/features/workspace/commands/clipboardFailure' import { clonedMcpOverrides } from '@renderer/workspace/mcpDomains' import { DEFAULT_PROVIDER, effectiveProviderRuntime, isAgentProviderKind } from '@shared/types/providerKind' import { getRendererProviderCapabilities } from '@providers/registry.renderer.capabilities' @@ -775,9 +776,10 @@ export const sessionCommands: CommandDef[] = [ try { await navigator.clipboard.writeText(command) workspace.showPaneToast(sessionId, `copied resume command · ${command}`, 5000) - } catch (err) { - const msg = (err as Error)?.message ?? String(err) - workspace.showPaneToast(sessionId, `copy failed: ${msg}`, 4000) + } catch { + // Fixed words (q22, #1250 row 9): the rejection's message is browser + // text, not something written for the user. + workspace.showPaneToast(sessionId, CLIPBOARD_WRITE_FAILED, 4000) } }, contextMenu: { group: 'copy', order: 10 }, From a1d5b8b9e5cecef31d2594b16498d9d943b6ba6a Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 05:33:55 -0700 Subject: [PATCH 26/40] fix(feed-debug): keep release bookkeeping across persistence toggles (#1392 review c) The release sets lived in the persistence effect, so switching persistence off discarded them and a pane closed across the toggle was never released. They now live in a ref, and releasing runs while persistence is off (it writes nothing to disk). Co-Authored-By: Claude Opus 5.5 --- .../useFeedDebugPersist.renderer.test.tsx | 29 +++++++++++++++++ .../hook/persistence/useFeedDebugPersist.ts | 32 ++++++++++++------- 2 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx index 18b64135c..64443b901 100644 --- a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx +++ b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx @@ -377,6 +377,35 @@ describe('releasing a session whose runtime is gone (#1392)', () => { await expect(advance(3_000)).resolves.toBeUndefined() }) + // Review c: switching persistence off destroyed the release bookkeeping, so + // a pane closed across the toggle was never released, one leaked entry per + // such session for the life of main. + it('releases a session that closed while persistence was off', async () => { + const refs = makeRefs({ a: add(emptyRuntime(), 'persisted row') }) + renderHook(() => useFeedDebugPersist(refs)) + await advance(1_000) + expect(append).toHaveBeenCalledTimes(1) + act(() => { useDevDebugConfig.setState({ enabled: false, sessionRecordingEnabled: false }) }) + refs.latestRuntimesRef.current = {} + await advance(2_000) + expect(forget).toHaveBeenCalledExactlyOnceWith({ sessionId: 'a' }) + expect(append).toHaveBeenCalledTimes(1) + }) + + it('releases it after persistence is switched back on too', async () => { + const refs = makeRefs({ a: add(emptyRuntime(), 'persisted row') }) + renderHook(() => useFeedDebugPersist(refs)) + await advance(1_000) + forget.mockRejectedValue(new Error('ipc down')) + act(() => { useDevDebugConfig.setState({ enabled: false, sessionRecordingEnabled: false }) }) + refs.latestRuntimesRef.current = {} + await advance(1_000) + forget.mockResolvedValue(undefined) + act(() => { useDevDebugConfig.setState({ enabled: true, sessionRecordingEnabled: false }) }) + await advance(2_000) + expect(forget.mock.calls.at(-1)).toEqual([{ sessionId: 'a' }]) + }) + it('does not forget a session that never had a runtime while mounted', async () => { const refs = makeRefs({}) renderHook(() => useFeedDebugPersist(refs)) diff --git a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts index c3579487b..61c7b057b 100644 --- a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts +++ b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts @@ -95,8 +95,16 @@ export function useFeedDebugPersist(refs: WorkspaceRefs): void { // still wrote one last batch to disk). const enabledRef = useRef(enabled) enabledRef.current = enabled + // The release bookkeeping (see releaseGone) lives in a ref, not in the + // effect: the effect re-runs whenever persistence is switched on or off, + // and a set recreated there forgot every id it was tracking, so a pane + // closed across a persistence toggle was never released (#1392 review c). + const releaseStateRef = useRef({ + known: new Set(), + releasing: new Set(), + seenSinceRelease: new Set(), + }) useEffect(() => { - if (!enabled) return const flushSession = (sessionId: SessionId, runtime: SessionRuntime): void => { if (runtime.feedDebugLog.length === 0) return const lastPersistedId = refs.persistedFeedDebugIdRef.current[sessionId] ?? 0 @@ -180,15 +188,15 @@ export function useFeedDebugPersist(refs: WorkspaceRefs): void { // the ACK then leaves the id in `known`, and the next absence sends a new // release. // - // Known residuals: a release that fails during the hook's own teardown - // (workspace unmount) has no later tick to retry it; and this effect only - // runs while persistence is on (#767), so a session removed while - // persistence is off is not released. Either way main keeps that one - // session's few numbers until it exits (main only has state for sessions - // that appended while persistence was on). - const known = new Set() - const releasing = new Set() - const seenSinceRelease = new Set() + // Releasing keeps running while persistence is OFF (#767): it writes + // nothing to disk, it only tells main to forget, and a session that + // appended while persistence was on still has state in main after the + // user switches persistence off (#1392 review c). + // + // Known residual: a release that fails during the hook's own teardown + // (workspace unmount) has no later tick to retry it. Main keeps that one + // session's few numbers until it exits. + const { known, releasing, seenSinceRelease } = releaseStateRef.current const releaseGone = (): void => { const runtimes = refs.latestRuntimesRef.current for (const sessionId of known) { @@ -211,7 +219,8 @@ export function useFeedDebugPersist(refs: WorkspaceRefs): void { for (const [sessionId, runtime] of Object.entries(refs.latestRuntimesRef.current)) { known.add(sessionId) if (releasing.has(sessionId)) seenSinceRelease.add(sessionId) - flushSession(sessionId, runtime) + // Disk writes only while persistence is on; releases always. + if (enabled) flushSession(sessionId, runtime) } releaseGone() } @@ -231,6 +240,7 @@ export function useFeedDebugPersist(refs: WorkspaceRefs): void { // Not when persistence was just switched off: the user asked for no // more disk writes. if (enabledRef.current) flush() + else releaseGone() } }, [ enabled, From 47b7fb31ea97b7c17bd7f5e5315398cd06a65546 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 05:36:31 -0700 Subject: [PATCH 27/40] test(setup): replace any storage that is not happy-dom's, including Node 25 file-backed storage (#1408 review c) Co-Authored-By: Claude Opus 5.5 --- .../src/app/storageEnvironment.renderer.test.ts | 7 +++++++ testing/setup/storage.ts | 11 +++++++---- testing/unit/setupStorage.test.ts | 16 ++++++++++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/renderer/src/app/storageEnvironment.renderer.test.ts b/src/renderer/src/app/storageEnvironment.renderer.test.ts index 9daf5e296..c9e45a46b 100644 --- a/src/renderer/src/app/storageEnvironment.renderer.test.ts +++ b/src/renderer/src/app/storageEnvironment.renderer.test.ts @@ -4,6 +4,13 @@ import { expect, it } from 'vitest' // Storage (no clear, reads undefined) instead of happy-dom's. // testing/setup/renderer.ts installs a working one; this checks the renderer // test environment really has it. +// Review c of #1408: with --localstorage-file, Node 25's storage is +// file-backed and was kept, so a file could start with another process's keys. +it('starts every test file with an empty DOM storage', () => { + expect(window.localStorage.length).toBe(0) + expect(window.sessionStorage.length).toBe(0) +}) + it('leaves the test environment with a working storage', () => { expect(typeof window.localStorage.clear).toBe('function') window.localStorage.setItem('probe', '1') diff --git a/testing/setup/storage.ts b/testing/setup/storage.ts index 461b153be..9c24914b5 100644 --- a/testing/setup/storage.ts +++ b/testing/setup/storage.ts @@ -12,14 +12,17 @@ import { Storage } from 'happy-dom' * to Node's broken storage instead of the DOM's. On Node 22/24, happy-dom's * storage is already in place and this changes nothing. * - * "Working" is judged by `clear` being a function: Node 25's placeholder lacks - * it, and every real Storage has it. + * "Working" means happy-dom's own Storage (review c of #1408). A check for + * `clear` accepted Node 25's FILE-backed storage too: with + * `--localstorage-file` (on the command line or in NODE_OPTIONS) Node's + * storage is complete, so it stayed in place and a test read values another + * process had written to that file instead of the DOM's fresh, empty + * storage. Anything that is not a happy-dom Storage is replaced. */ export function installWorkingStorage(target: object): Array<'localStorage' | 'sessionStorage'> { const replaced: Array<'localStorage' | 'sessionStorage'> = [] for (const name of ['localStorage', 'sessionStorage'] as const) { - const current = (target as Record)[name] as { clear?: unknown } | undefined - if (typeof current?.clear === 'function') continue + if ((target as Record)[name] instanceof Storage) continue Object.defineProperty(target, name, { configurable: true, writable: true, value: new Storage() }) replaced.push(name) } diff --git a/testing/unit/setupStorage.test.ts b/testing/unit/setupStorage.test.ts index e6d926c91..ec741012c 100644 --- a/testing/unit/setupStorage.test.ts +++ b/testing/unit/setupStorage.test.ts @@ -1,5 +1,7 @@ import { expect, it } from 'vitest' +import { Storage } from 'happy-dom' + import { installWorkingStorage } from '../setup/storage' // #1212: Node 25's default Web Storage is a placeholder without `clear` that @@ -15,9 +17,19 @@ it('replaces a storage without clear by a working DOM Storage', () => { expect(storage.length).toBe(0) }) -it('leaves a working storage in place', () => { - const working = { clear: () => {} } +it('leaves happy-dom storage in place', () => { + const working = new Storage() const target = { localStorage: working, sessionStorage: working } expect(installWorkingStorage(target)).toEqual([]) expect(target.localStorage).toBe(working) }) + +// Review c: with --localstorage-file, Node 25's storage is COMPLETE (it has +// clear) but file-backed, so a test would read another process's values. +it('replaces a complete but non-DOM storage, such as Node 25 file-backed storage', () => { + const stale = new Map([['probe', 'stale']]) + const fileBacked = { getItem: (key: string) => stale.get(key) ?? null, setItem: () => {}, clear: () => {}, key: () => null, length: 1, removeItem: () => {} } + const target = { localStorage: fileBacked, sessionStorage: fileBacked } + expect(installWorkingStorage(target)).toEqual(['localStorage', 'sessionStorage']) + expect((target as unknown as { localStorage: Storage }).localStorage.getItem('probe')).toBeNull() +}) From d8f1eae680f0ed844675fa119ebdfe817ebc74e6 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 05:39:48 -0700 Subject: [PATCH 28/40] fix(ai-workspace): report blocked storage on every load, correct ENOTDIR/EROFS advice (review b) Co-Authored-By: Claude Opus 5.5 --- ...09-27-ai-workspace-write-status-warning.md | 8 ++++ .../aiWorkspace/AiWorkspaceRegistry.test.ts | 44 ++++++++++++++++++- src/main/aiWorkspace/AiWorkspaceRegistry.ts | 29 +++++++++--- src/mcp/shared/aiWorkspaceTypes.ts | 5 +++ .../ai-workspace/ui/AiWorkspaceEditor.tsx | 11 +++-- 5 files changed, 86 insertions(+), 11 deletions(-) diff --git a/docs/plans/2026-09-27-ai-workspace-write-status-warning.md b/docs/plans/2026-09-27-ai-workspace-write-status-warning.md index 1b8526b3b..57c2111bc 100644 --- a/docs/plans/2026-09-27-ai-workspace-write-status-warning.md +++ b/docs/plans/2026-09-27-ai-workspace-write-status-warning.md @@ -28,3 +28,11 @@ The input is the real recorded workspace state. One real entry is pointed at a t - **Advice matches the cause.** An occupied copy path (EISDIR/EEXIST/ENOTDIR), a missing folder (ENOENT), a permission or read-only refusal, and a full disk each get their own advice. - **Tests added:** the file reads back after the warning; an ordinary write carries no warning; a throwing listener still gives `ok: true`, and the listener is still called; ENOENT advice. The always-warn, unguarded-emit and wrong-advice mutations each fail. - **Not tested:** the editor's display of the notice is not covered at the component level (there is no AiWorkspaceEditor renderer harness). The change there is three lines, and it is stated in the body. + +## Review b (round 1) +- **The notice was lost on a workspace switch, and never shown if the switch happened mid-write.** The editor held it only in React state. It is now durable in main: `get` returns a runtime-only `storageWarning` (`AI_WORKSPACE_STORAGE_BLOCKED`) while a copy is owed and its last attempt failed. The flag is set when the copy fails and cleared when it succeeds, and it is never persisted. `loadWorkspace` sets the editor's notice from it on every load, so a remount shows it again. The write-result warning still sets it immediately. +- **Wrong advice for ENOTDIR and EROFS.** ENOTDIR now gets the generic advice, since it means a component of the folder path is a file. EROFS gets its own read-only-volume advice. +- **Surviving mutations, now killed:** + - appending the raw error text to the refusal (asserted absent); + - stopping the fan-out after the first workspace (two-workspace test); + - dropping `get`'s notice. diff --git a/src/main/aiWorkspace/AiWorkspaceRegistry.test.ts b/src/main/aiWorkspace/AiWorkspaceRegistry.test.ts index 65f8108b1..30bca1771 100644 --- a/src/main/aiWorkspace/AiWorkspaceRegistry.test.ts +++ b/src/main/aiWorkspace/AiWorkspaceRegistry.test.ts @@ -3,7 +3,7 @@ import { tmpdir } from 'os' import { dirname, join } from 'path' import { afterEach, describe, expect, it } from 'vitest' -import { AI_WORKSPACE_STATUS_NOT_SAVED, AiWorkspaceRegistry } from './AiWorkspaceRegistry.js' +import { AI_WORKSPACE_STATUS_NOT_SAVED, AI_WORKSPACE_STORAGE_BLOCKED, AiWorkspaceRegistry } from './AiWorkspaceRegistry.js' const tempRoots: string[] = [] @@ -334,7 +334,21 @@ describe('a write whose status refresh cannot be saved (#1285)', () => { // The stored state was not rewritten: the owed copy still blocks saves. expect(await readFile(statePath, 'utf8')).toBe(source) // A refused save says why and how to unblock it, not the raw errno text. - await expect(registry.create({ name: 'Blocked' })).rejects.toThrow(/needs attention.*\(EISDIR\).*already occupies the copy path/s) + const refusal = await registry.create({ name: 'Blocked' }).then(() => null, (err: Error) => err.message) + expect(refusal).toMatch(/needs attention.*\(EISDIR\).*already occupies the copy path/s) + // Only the code, never the raw filesystem message. + expect(refusal).not.toMatch(/illegal operation|is a directory/i) + + // #1416 review b: every LOAD reports the blocked storage, so an editor + // that remounts (a workspace switch) still shows it. + const workspaceId = state.workspaces[0]!.workspaceId as string + expect((await registry.get(workspaceId))?.storageWarning).toBe(AI_WORKSPACE_STORAGE_BLOCKED) + // Unblocked: the next save writes the copy and the notice clears. + await rm(join(root, `ai-workspaces.json.invalid-${createHash('sha256').update(source).digest('hex').slice(0, 16)}.json`), { recursive: true }) + await registry.create({ name: 'Now' }) + expect((await registry.get(workspaceId))?.storageWarning).toBeUndefined() + // It was never persisted. + expect(await readFile(statePath, 'utf8')).not.toContain('storageWarning') }) it('warns on no ordinary write, and tells every workspace even when a listener throws', async () => { @@ -355,6 +369,32 @@ describe('a write whose status refresh cannot be saved (#1285)', () => { expect(heard).toEqual(['workspace-1']) }) + it('tells every workspace holding the file, even when the first listener call throws', async () => { + const root = await mkdtemp(join(tmpdir(), 'agent-code-ai-workspace-fanout-')) + tempRoots.push(root) + const filePath = join(root, 'shared.txt') + await writeFile(filePath, 'v1') + const entry = (entryId: string) => ({ + entryId, path: filePath, projectRoot: root, title: 'shared.txt', attachedAt: '2026-01-01T00:00:00.000Z', + status: { exists: true, readable: true, staleReason: null, size: 2, mtimeMs: null }, + }) + const workspace = (workspaceId: string) => ({ + workspaceId, name: workspaceId, createdAt: '2026-01-01T00:00:00.000Z', updatedAt: '2026-01-01T00:00:00.000Z', entries: [entry(`${workspaceId}-e`)], + }) + const statePath = join(root, 'ai-workspaces.json') + await writeFile(statePath, JSON.stringify({ workspaces: [workspace('ws-a'), workspace('ws-b')] })) + const registry = new AiWorkspaceRegistry(statePath) + await registry.list() + const heard: string[] = [] + registry.on('changed', (event: { workspaceId: string }) => { + heard.push(event.workspaceId) + throw new Error('event delivery failed') + }) + const result = await registry.writeFile({ path: await realpath(filePath), text: 'v2' }) + expect(result).toMatchObject({ ok: true }) + expect(heard.sort()).toEqual(['ws-a', 'ws-b']) + }) + it('gives advice that matches the cause when the owed copy cannot be written', async () => { // A missing state folder is not "something occupies the path". const root = await mkdtemp(join(tmpdir(), 'agent-code-ai-workspace-enoent-')) diff --git a/src/main/aiWorkspace/AiWorkspaceRegistry.ts b/src/main/aiWorkspace/AiWorkspaceRegistry.ts index c49edb355..f06726104 100644 --- a/src/main/aiWorkspace/AiWorkspaceRegistry.ts +++ b/src/main/aiWorkspace/AiWorkspaceRegistry.ts @@ -167,11 +167,19 @@ export interface AiWorkspaceRegistry { export const AI_WORKSPACE_STATUS_NOT_SAVED = 'The file was saved, but AI Workspace could not save its status. Other AI Workspace changes will fail until its storage is fixed.' +/** The fixed notice `get` carries while saves are blocked by an owed copy. */ +export const AI_WORKSPACE_STORAGE_BLOCKED = + 'AI Workspace cannot save changes until its storage is fixed: rows it could not read must be copied aside first, and that copy cannot be written.' + export class AiWorkspaceRegistry extends EventEmitter { private readonly workspaces = new Map() private loadPromise: Promise | null = null /** The loaded file while set-aside rows are not yet preserved; see load(). */ private owedCopy: { text: string; setAside: number } | null = null + // True after the owed copy last FAILED to be written, false once it is + // written. `get` reports it (see AI_WORKSPACE_STORAGE_BLOCKED): a save is + // refused exactly while a copy is owed and cannot be made. + private copyBlocked = false private saveQueue: Promise = Promise.resolve() private readonly knownFilePaths = new Set() private readonly gitContextCache = new Map< @@ -268,7 +276,9 @@ export class AiWorkspaceRegistry extends EventEmitter { await this.ensureLoaded() const workspace = this.workspaces.get(workspaceId) if (!workspace) return null - return await this.refreshWorkspace(workspaceId) + const record = await this.refreshWorkspace(workspaceId) + // A copy, so the runtime-only field never reaches the persisted record. + return this.owedCopy && this.copyBlocked ? { ...record, storageWarning: AI_WORKSPACE_STORAGE_BLOCKED } : record } async attachFile(params: AiWorkspaceAttachFileParams): Promise { @@ -643,27 +653,34 @@ export class AiWorkspaceRegistry extends EventEmitter { // how to unblock it. Saves stay refused until the copy exists, because // the next save drops the unreadable rows. const copy = await preserveInvalidBytes(`${this.stateFile}.invalid`, text).catch(err => { + this.copyBlocked = true const code = (err as NodeJS.ErrnoException).code // WHY the advice depends on the code (#1416 review a): "clear what // occupies the path" is only true when something occupies it. A // missing directory, a permission or read-only refusal and a full disk // each need a different fix, and advice for the wrong one sends the // user looking for an occupant that does not exist. - const advice = code === 'EISDIR' || code === 'EEXIST' || code === 'ENOTDIR' + // ENOTDIR is NOT an occupant (#1416 review b): it means a component of + // the folder path is a file, so it falls to the generic advice. A + // read-only volume cannot be fixed by permissions. + const advice = code === 'EISDIR' || code === 'EEXIST' ? `Something already occupies the copy path next to ${this.stateFile}; move it away to continue.` : code === 'ENOENT' ? `The folder holding ${this.stateFile} is missing; restore it to continue.` - : code === 'EACCES' || code === 'EPERM' || code === 'EROFS' + : code === 'EACCES' || code === 'EPERM' ? `The folder holding ${this.stateFile} is not writable; fix its permissions to continue.` - : code === 'ENOSPC' - ? 'The disk is full; free some space to continue.' - : `Check that the folder holding ${this.stateFile} is writable to continue.` + : code === 'EROFS' + ? `The folder holding ${this.stateFile} is on a read-only volume; AI Workspace cannot save there.` + : code === 'ENOSPC' + ? 'The disk is full; free some space to continue.' + : `Check that the folder holding ${this.stateFile} exists and is writable to continue.` throw new Error( `AI Workspace storage needs attention: ${setAside} unreadable row(s) must be copied aside before saving, ` + `and the copy could not be written${code ? ` (${code})` : ''}. ${advice}`, ) }) this.owedCopy = null + this.copyBlocked = false console.warn(`[ai-workspace] set aside ${setAside} malformed row(s); original preserved at ${copy}`) } diff --git a/src/mcp/shared/aiWorkspaceTypes.ts b/src/mcp/shared/aiWorkspaceTypes.ts index c8d7710ee..7f9e9f0b3 100644 --- a/src/mcp/shared/aiWorkspaceTypes.ts +++ b/src/mcp/shared/aiWorkspaceTypes.ts @@ -37,6 +37,11 @@ export type AiWorkspaceRecord = { createdAt: string updatedAt: string entries: AiWorkspaceFileEntry[] + /** Runtime only, never persisted (#1285, #1416 review b): set by `get` while + * AI Workspace cannot save, because a preservation copy it owes cannot be + * written. Every load sees it, so a remounted editor (or an agent) learns + * that changes will be refused, not only the view that saw a failed write. */ + storageWarning?: string } export type AiWorkspaceSummary = { diff --git a/src/renderer/src/features/ai-workspace/ui/AiWorkspaceEditor.tsx b/src/renderer/src/features/ai-workspace/ui/AiWorkspaceEditor.tsx index abd0b0463..b80da9707 100644 --- a/src/renderer/src/features/ai-workspace/ui/AiWorkspaceEditor.tsx +++ b/src/renderer/src/features/ai-workspace/ui/AiWorkspaceEditor.tsx @@ -80,9 +80,10 @@ export function AiWorkspaceEditor({ workspaceId, visible, onClose, toolbarAction // is blocked). The file is saved, so this is not the tab's error, but the // user must learn that AI Workspace storage is blocked, since every later // collection change will be refused. It cannot ride `error`: loadWorkspace, - // which runs after every save, clears that. It lasts until a write comes - // back without the warning. The text is main's fixed sentence, never a raw - // filesystem message. + // which runs after every save, clears that. It is set from the write + // result AND from every load (main's `storageWarning`), so it survives a + // remount. The text is main's fixed sentence, never a raw filesystem + // message. const [storageWarning, setStorageWarning] = useState(null) const [fileOrder, setFileOrder] = useState(() => cached?.fileOrder ?? []) const [openFiles, setOpenFiles] = useState>( @@ -200,6 +201,10 @@ export function AiWorkspaceEditor({ workspaceId, visible, onClose, toolbarAction } setWorkspace(next) setError(next ? null : 'AI Workspace not found') + // The durable source of the storage notice (#1416 review b): main + // reports it on every load, so a remounted editor (a workspace switch) + // still shows it, and so does one that missed the write's own result. + setStorageWarning(next?.storageWarning ?? null) return next } catch (err) { if ( From d3f1a6bf0255b22ca3973d0ba7f4a8b99c1a2179 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 05:45:25 -0700 Subject: [PATCH 29/40] fix(clipboard): Browser Pocket and the pickers say a refused copy; one shared sentence (#1421 review) Co-Authored-By: Claude Opus 5.5 --- .../2026-09-27-copy-last-response-failure.md | 9 ++++++++ .../browser-pocket/ui/pick.renderer.test.ts | 11 +++++++++ .../src/features/browser-pocket/ui/pick.ts | 11 ++++++++- .../copyCommands.clipboard.renderer.test.ts | 23 +++++++++++++++++-- .../workspace/commands/paneCommands.ts | 2 +- .../workspace/commands/sessionCommands.ts | 2 +- .../commands => lib}/clipboardFailure.ts | 4 +++- .../src/workspace/hook/actions/picker.ts | 4 +++- .../src/workspace/tile-tree/useKeybinds.ts | 4 +++- 9 files changed, 62 insertions(+), 8 deletions(-) rename src/renderer/src/{features/workspace/commands => lib}/clipboardFailure.ts (66%) diff --git a/docs/plans/2026-09-27-copy-last-response-failure.md b/docs/plans/2026-09-27-copy-last-response-failure.md index 7d00be1d6..0219a9ce5 100644 --- a/docs/plans/2026-09-27-copy-last-response-failure.md +++ b/docs/plans/2026-09-27-copy-last-response-failure.md @@ -25,3 +25,12 @@ New `paneCommands.copy.renderer.test.ts`. The runtime entries are the recorded b ## Out of scope - #1250's other rows. - Debug-panel copy buttons (developer surfaces). + +## Review round 1 (a, b: FIX-BEFORE-MERGE; c: MERGE-READY) +- **a1 (Major): a refused copy reports `ran` to `commands.run` callers.** Declined, with reasons: + - Throwing would make `runGuarded` add its own "Command failed: Copy Last Response" toast, so every human path would get two messages for one failure. + - The `commands.run` contract already says `ran` means only that the dispatcher returned, and tells the caller to observe the app afterwards. +- **a2 (Minor): nothing pinned that the command stays pending until the write settles.** Test added with a deferred write: the command is not settled and silent before the write, then says "Copied". It fails with a fire-and-forget `.then`. +- **b1 (Major): Browser Pocket's pick (no composer) swallowed a refused write and said "Element copied".** It now says the refusal. Test in `pick.renderer.test.ts`, red on the old pick. +- **b2 / c1 (Minor): the wording was compared against the constant only.** It is now asserted literally. +- **c2 (Minor): the assistant-message picker and the code-block picker said "Clipboard write failed".** Both now use the shared sentence. The constant moved to `lib/clipboardFailure.ts`, since four features share it. diff --git a/src/renderer/src/features/browser-pocket/ui/pick.renderer.test.ts b/src/renderer/src/features/browser-pocket/ui/pick.renderer.test.ts index 84e80eb3f..7a72f8790 100644 --- a/src/renderer/src/features/browser-pocket/ui/pick.renderer.test.ts +++ b/src/renderer/src/features/browser-pocket/ui/pick.renderer.test.ts @@ -63,6 +63,17 @@ describe('pickIntoComposer', () => { expect(toast).toHaveBeenCalledWith(expect.stringMatching(/copied/i)) }) + // #1421 review b: a refused write was swallowed and "Element copied" shown + // anyway, so the user pasted whatever the clipboard held before. + it('without a composer, says a refused copy instead of claiming it', async () => { + const writeText = vi.fn(async () => { throw new DOMException('Document is not focused.', 'NotAllowedError') }) + Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true }) + const toast = vi.fn() + const { ws } = workspace('claude', '') + await pickIntoComposer('p1', 's1' as never, ws, vi.fn(), toast) + expect(toast.mock.calls).toEqual([["Couldn't copy to the clipboard. Click into the app and try again."]]) + }) + it('a cancelled pick changes nothing', async () => { window.api = { ...(window.api ?? {}), pickInPocket: vi.fn(async () => null) } as unknown as typeof window.api composer('s1', 'draft', 5) diff --git a/src/renderer/src/features/browser-pocket/ui/pick.ts b/src/renderer/src/features/browser-pocket/ui/pick.ts index 8eb0e338a..b190e849c 100644 --- a/src/renderer/src/features/browser-pocket/ui/pick.ts +++ b/src/renderer/src/features/browser-pocket/ui/pick.ts @@ -1,4 +1,5 @@ import { getRendererProviderCapabilities } from '@providers/registry.renderer.capabilities' +import { CLIPBOARD_WRITE_FAILED } from '@renderer/lib/clipboardFailure' import { formatElementChip, insertAtCaret } from '@shared/browserPocket/elementChip' import { isAgentProviderKind } from '@shared/types/providerKind' import type { Workspace } from '@renderer/workspace/workspaceStore' @@ -31,7 +32,15 @@ export async function pickIntoComposer(pocketId: string, sessionId: SessionId, w const chip = formatElementChip(result) const composer = document.querySelector(`[data-composer-input="${CSS.escape(sessionId)}"]`) if (!composer) { - await navigator.clipboard.writeText(chip).catch(() => {}) + // WHY the write is checked (#1421 review b): a refused write was + // swallowed and "Element copied" shown anyway, so the user pasted + // whatever the clipboard held before. + try { + await navigator.clipboard.writeText(chip) + } catch { + showToast(CLIPBOARD_WRITE_FAILED) + return + } showToast('Element copied — paste it into the agent') return } diff --git a/src/renderer/src/features/workspace/commands/copyCommands.clipboard.renderer.test.ts b/src/renderer/src/features/workspace/commands/copyCommands.clipboard.renderer.test.ts index 031997b29..33048f360 100644 --- a/src/renderer/src/features/workspace/commands/copyCommands.clipboard.renderer.test.ts +++ b/src/renderer/src/features/workspace/commands/copyCommands.clipboard.renderer.test.ts @@ -5,7 +5,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest' import { emptyRuntime } from '@renderer/session-runtime/state' import type { CommandContext } from '@renderer/features/command-palette/types' import type { Workspace } from '@renderer/workspace/hook' -import { CLIPBOARD_WRITE_FAILED } from '@renderer/features/workspace/commands/clipboardFailure' +import { CLIPBOARD_WRITE_FAILED } from '@renderer/lib/clipboardFailure' import { paneCommands } from '@renderer/features/workspace/commands/paneCommands' import { sessionCommands } from '@renderer/features/workspace/commands/sessionCommands' import { oneLaneStage } from '@renderer/workspace/testing/stageFixtures' @@ -63,7 +63,26 @@ describe('copy commands and a refused clipboard', () => { stubClipboard(refused) const { ctx, toasts } = context(bundle.input.provider) await copyLast.run(ctx) - expect(toasts).toEqual([CLIPBOARD_WRITE_FAILED]) + // The literal words (#1421 review b, c): comparing against the constant + // alone would let the advice be reworded away unnoticed. + expect(toasts).toEqual(["Couldn't copy to the clipboard. Click into the app and try again."]) + expect(CLIPBOARD_WRITE_FAILED).toBe(toasts[0]) + }) + + // #1421 review a: the command's promise is the dispatcher's single-flight + // and outcome; it must not resolve (or say anything) before the write does. + it('stays pending, and silent, until the clipboard write settles', async () => { + let finish!: () => void + stubClipboard(() => new Promise(resolve => { finish = resolve })) + const { ctx, toasts } = context(bundle.input.provider) + let settled = false + const running = Promise.resolve(copyLast.run(ctx)).then(() => { settled = true }) + await Promise.resolve(); await Promise.resolve() + expect(settled).toBe(false) + expect(toasts).toEqual([]) + finish() + await running + expect(toasts).toEqual(['Copied to clipboard']) }) it('says Copied only after the clipboard took the recorded response', async () => { diff --git a/src/renderer/src/features/workspace/commands/paneCommands.ts b/src/renderer/src/features/workspace/commands/paneCommands.ts index faca0b74a..9cbd949d8 100644 --- a/src/renderer/src/features/workspace/commands/paneCommands.ts +++ b/src/renderer/src/features/workspace/commands/paneCommands.ts @@ -15,7 +15,7 @@ import { commandTargetSessionId } from '@renderer/workspace/hook/selectors/comma import { submitActiveComposer } from '@renderer/workspace/tile-tree/TileLeaf/composerEnterRegistry' import { sessionHasTranscript } from '@renderer/workspace/transcriptAvailability' import { isWorkingAgent } from '@renderer/workspace/agentFollow' -import { CLIPBOARD_WRITE_FAILED } from '@renderer/features/workspace/commands/clipboardFailure' +import { CLIPBOARD_WRITE_FAILED } from '@renderer/lib/clipboardFailure' // DELETED with the unified layout (#992) — see RETIRED_COMMAND_IDS in // catalog.test.ts for the ledger: diff --git a/src/renderer/src/features/workspace/commands/sessionCommands.ts b/src/renderer/src/features/workspace/commands/sessionCommands.ts index 80ddcf0d5..b8e8281c0 100644 --- a/src/renderer/src/features/workspace/commands/sessionCommands.ts +++ b/src/renderer/src/features/workspace/commands/sessionCommands.ts @@ -1,5 +1,5 @@ import { commandTarget } from '@renderer/features/command-palette/commandTarget' -import { CLIPBOARD_WRITE_FAILED } from '@renderer/features/workspace/commands/clipboardFailure' +import { CLIPBOARD_WRITE_FAILED } from '@renderer/lib/clipboardFailure' import { clonedMcpOverrides } from '@renderer/workspace/mcpDomains' import { DEFAULT_PROVIDER, effectiveProviderRuntime, isAgentProviderKind } from '@shared/types/providerKind' import { getRendererProviderCapabilities } from '@providers/registry.renderer.capabilities' diff --git a/src/renderer/src/features/workspace/commands/clipboardFailure.ts b/src/renderer/src/lib/clipboardFailure.ts similarity index 66% rename from src/renderer/src/features/workspace/commands/clipboardFailure.ts rename to src/renderer/src/lib/clipboardFailure.ts index 3c9914dcf..bd145d97f 100644 --- a/src/renderer/src/features/workspace/commands/clipboardFailure.ts +++ b/src/renderer/src/lib/clipboardFailure.ts @@ -1,4 +1,6 @@ -// What a copy command says when the clipboard refused the write (#1250 row 9). +// What a copy action says when the clipboard refused the write (#1250 row 9): +// the copy commands, the assistant-message picker and Browser Pocket's pick, +// so one failure mode has one sentence (#1421 review c). // // WHY fixed words: the rejection is a DOMException whose message is browser // text ("Document is not focused."), and user-visible text is curated (q22). diff --git a/src/renderer/src/workspace/hook/actions/picker.ts b/src/renderer/src/workspace/hook/actions/picker.ts index 1e080a56d..2b8781b15 100644 --- a/src/renderer/src/workspace/hook/actions/picker.ts +++ b/src/renderer/src/workspace/hook/actions/picker.ts @@ -1,5 +1,6 @@ import { useCallback } from 'react' +import { CLIPBOARD_WRITE_FAILED } from '@renderer/lib/clipboardFailure' import { emptyRuntime } from '@renderer/session-runtime/state' import type { SessionId } from '@renderer/workspace/types' import { @@ -150,7 +151,8 @@ export function usePickerActions( await navigator.clipboard.writeText(text) showPaneToast(sessionId, 'Copied assistant message') } catch { - showPaneToast(sessionId, 'Clipboard write failed') + // The shared sentence (#1421 review c), with its advice. + showPaneToast(sessionId, CLIPBOARD_WRITE_FAILED) } }, [refs.latestRuntimesRef, setRuntimes, showPaneToast], diff --git a/src/renderer/src/workspace/tile-tree/useKeybinds.ts b/src/renderer/src/workspace/tile-tree/useKeybinds.ts index 763dea463..1f506173b 100644 --- a/src/renderer/src/workspace/tile-tree/useKeybinds.ts +++ b/src/renderer/src/workspace/tile-tree/useKeybinds.ts @@ -1,4 +1,5 @@ import { createTldrHoldController, dismissTldr, observeTldrHoldRelease, useTldrView } from '@renderer/features/tldr/viewState' +import { CLIPBOARD_WRITE_FAILED } from '@renderer/lib/clipboardFailure' import { useGlobalToast } from '@renderer/ui/GlobalToastContext' import { dismissGoalLoop, useGoalLoopView } from '@renderer/features/goal-loop/viewState' import { useEffect, useMemo, useRef } from 'react' @@ -827,7 +828,8 @@ export function useKeybinds( } else { void navigator.clipboard.writeText(code).then( () => workspace.showPaneToast(focusedSessionId, 'Copied code block'), - () => workspace.showPaneToast(focusedSessionId, 'Clipboard write failed'), + // The shared sentence (#1421 review c). + () => workspace.showPaneToast(focusedSessionId, CLIPBOARD_WRITE_FAILED), ) } return From bb183091b25b13c0f9bfcded9ea4dabdd890807d Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 05:50:13 -0700 Subject: [PATCH 30/40] fix(conversations): backward chunked scan for newest prompt, pair carriers only when adjacent (verification a) Co-Authored-By: Claude Opus 5.5 --- ...6-09-27-codex-conversations-usermessage.md | 6 ++ src/main/conversations/sources/codex.ts | 92 ++++++++++++------- .../sources/codex.userMessage0157.test.ts | 44 ++++++++- .../codex-0157/typed-prompt-head.json | 4 +- 4 files changed, 111 insertions(+), 35 deletions(-) diff --git a/docs/plans/2026-09-27-codex-conversations-usermessage.md b/docs/plans/2026-09-27-codex-conversations-usermessage.md index 830ce2ccf..52abef1b2 100644 --- a/docs/plans/2026-09-27-codex-conversations-usermessage.md +++ b/docs/plans/2026-09-27-codex-conversations-usermessage.md @@ -22,3 +22,9 @@ The fixture `testing/fixtures/conversations/codex-0157/typed-prompt-head.json` i - **Comment narrowed.** Older CLIs' UserMessage items can hold injected context or command wrappers. The index lists those too, and `firstUnwrappedPrompt` and classify decide what labels a row. - **Fixture rebuilt as a CONTIGUOUS real head.** It holds all 10 records from `session_meta` through the first UserMessage of the one local 0.157 file whose first prompt is typed. The expected length and timestamp are recorded independently in the fixture. Composed cases say they are composed. - **Filed, not fixed here (pre-existing):** #1418 (0.149–0.151 rollouts with no prompt event) and #1419 (search matches injected context). + +## Verification a (round 2) +- **The tail pass missed prompts far back.** In 10 of 46 local 0.157 files with a prompt past the head, that prompt lay wholly before the last 512 KiB, and a record straddling the window's start was dropped. The reader now scans BACKWARD in 512 KiB chunks, carrying each cut line into the next (earlier) chunk, until it finds a user record. It is bounded at 32 MiB, runs only for truncated heads, and is cached by mtime. +- **De-duplication collapsed a prompt repeated in a later turn.** A cross-carrier pair is now matched only within 4 records, since Codex writes the two carriers of one prompt back to back. No local file has both carriers, so there was no recorded distance to calibrate against. +- **Fixture label.** The fixture's `session_meta.cli_version` is 0.157.0; the label is corrected. +- **Tests (red on the previous commit):** a prompt followed by 4 MiB of output; a prompt whose line straddles the last chunk boundary, laid out deterministically; a prompt repeated in a later turn. Dropping the carried partial line fails the straddle test. diff --git a/src/main/conversations/sources/codex.ts b/src/main/conversations/sources/codex.ts index e933beee1..c89d86b14 100644 --- a/src/main/conversations/sources/codex.ts +++ b/src/main/conversations/sources/codex.ts @@ -105,15 +105,19 @@ async function readRolloutHead(file: string): Promise { // What older CLIs put in UserMessage items (sometimes injected context or a // command wrapper) is what the index lists too; firstUnwrappedPrompt and // classify decide what is a label, as for every other source. - const pending = { legacy: new Map(), item: new Map() } - const noteUser = (carrier: 'legacy' | 'item', text: string, timestamp: unknown) => { + // WHY a pair is matched only within a few records (#1407 verification a): + // matching identical text anywhere in the head collapsed a prompt the user + // really repeated in a later turn. Codex writes the two carriers of ONE + // prompt back to back, so the other carrier's record must be close. + const PAIR_WINDOW_RECORDS = 4 + const pending = { legacy: [] as Array<{ text: string; at: number }>, item: [] as Array<{ text: string; at: number }> } + const noteUser = (carrier: 'legacy' | 'item', text: string, timestamp: unknown, recordIndex: number) => { const other = carrier === 'legacy' ? pending.item : pending.legacy - const matched = other.get(text) ?? 0 - if (matched > 0) { - other.set(text, matched - 1) + const match = other.findIndex(candidate => candidate.text === text && recordIndex - candidate.at <= PAIR_WINDOW_RECORDS) + if (match >= 0) { + other.splice(match, 1) } else { - const own = pending[carrier] - own.set(text, (own.get(text) ?? 0) + 1) + pending[carrier].push({ text, at: recordIndex }) if (out.userTexts.length < 6) out.userTexts.push(text) } const ts = typeof timestamp === 'string' ? Date.parse(timestamp) : NaN @@ -134,7 +138,7 @@ async function readRolloutHead(file: string): Promise { out.source = typeof payload.source === 'string' ? payload.source : payload.source ? JSON.stringify(payload.source) : null } else { const user = userPromptOf(record, payload) - if (user !== null) noteUser(user.carrier, user.text, record.timestamp) + if (user !== null) noteUser(user.carrier, user.text, record.timestamp, records) } // WHY the limit is unconditional: a rollout whose first two hundred // records hold no user event (exec runs, synthesized transcripts) has @@ -159,37 +163,44 @@ async function readRolloutHead(file: string): Promise { return out } -// Bytes read from the end of a rollout for the newest user timestamp. A -// Codex turn's own records (reasoning, tool calls, outputs) fill this many -// bytes long before the next prompt in the usual case; a prompt further back -// than this keeps the head's time, which is at worst the old behaviour. -const TAIL_ACTIVITY_BYTES = 512 * 1024 +// The newest user timestamp is found by reading the rollout BACKWARD in +// chunks until a user record appears (#1407 verification a). A fixed 512 KiB +// tail missed it in 10 of 46 local 0.157 files whose latest prompt was past +// the head (a long agent turn can write megabytes after one prompt), and it +// dropped a record straddling the window's start. Reading back in chunks, +// carrying the partial line across each boundary, finds the newest one wherever +// it is. The scan is bounded: a file with no user record in its last +// TAIL_ACTIVITY_MAX_BYTES keeps the head's time, which is at worst the old +// behaviour. It runs only for heads that hit their record bound, and the +// result is cached by mtime with the head. +const TAIL_ACTIVITY_CHUNK_BYTES = 512 * 1024 +const TAIL_ACTIVITY_MAX_BYTES = 32 * 1024 * 1024 async function newestUserTimestampInTail(file: string): Promise { let handle try { handle = await open(file, 'r') const { size } = await handle.stat() - const start = Math.max(0, size - TAIL_ACTIVITY_BYTES) - const buffer = Buffer.alloc(size - start) - await handle.read(buffer, 0, buffer.length, start) - const lines = buffer.toString('utf8').split('\n') - // The first line of a mid-file window is partial; the last may be too. - if (start > 0) lines.shift() - let newest: number | null = null - for (const line of lines) { - if (!line.includes('"user_message"') && !line.includes('"UserMessage"')) continue - let record: Record - try { - record = JSON.parse(line) as Record - } catch { - continue - } - if (userPromptOf(record, asRecord(record.payload)) === null) continue - const ts = typeof record.timestamp === 'string' ? Date.parse(record.timestamp) : NaN - if (Number.isFinite(ts)) newest = Math.max(newest ?? ts, ts) + let end = size + // Bytes of the line that starts before the current chunk and was cut off. + let carry = Buffer.alloc(0) + while (end > 0 && size - end < TAIL_ACTIVITY_MAX_BYTES) { + const start = Math.max(0, end - TAIL_ACTIVITY_CHUNK_BYTES) + const chunk = Buffer.alloc(end - start) + await handle.read(chunk, 0, chunk.length, start) + const window = Buffer.concat([chunk, carry]) + const text = window.toString('utf8') + // Unless this chunk starts the file, its first line is incomplete: keep + // its bytes for the next (earlier) chunk rather than dropping it. + const firstBreak = start > 0 ? window.indexOf(0x0a) : -1 + const complete = firstBreak >= 0 ? window.subarray(firstBreak + 1).toString('utf8') : text + carry = firstBreak >= 0 ? window.subarray(0, firstBreak) : Buffer.alloc(0) + const newest = newestUserTimestampIn(complete.split('\n')) + if (newest !== null) return newest + if (start === 0) break + end = start } - return newest + return null } catch { return null } finally { @@ -197,6 +208,23 @@ async function newestUserTimestampInTail(file: string): Promise { } } +function newestUserTimestampIn(lines: string[]): number | null { + let newest: number | null = null + for (const line of lines) { + if (!line.includes('"user_message"') && !line.includes('"UserMessage"')) continue + let record: Record + try { + record = JSON.parse(line) as Record + } catch { + continue + } + if (userPromptOf(record, asRecord(record.payload)) === null) continue + const ts = typeof record.timestamp === 'string' ? Date.parse(record.timestamp) : NaN + if (Number.isFinite(ts)) newest = Math.max(newest ?? ts, ts) + } + return newest +} + /** The user prompt a rollout record carries, and through which carrier. */ function userPromptOf(record: Record, payload: Record | null): { carrier: 'legacy' | 'item'; text: string } | null { if (record.type !== 'event_msg' || !payload) return null diff --git a/src/main/conversations/sources/codex.userMessage0157.test.ts b/src/main/conversations/sources/codex.userMessage0157.test.ts index b293fc116..dc0bdedb9 100644 --- a/src/main/conversations/sources/codex.userMessage0157.test.ts +++ b/src/main/conversations/sources/codex.userMessage0157.test.ts @@ -15,7 +15,7 @@ import { CodexConversationSource } from './codex.js' // `item.type: 'UserMessage'`. Every 0.157 row came back with no prompt, was // classified `empty`, and was hidden from the default listing. // -// The fixture is a REAL, CONTIGUOUS 0.157.1 rollout head (see its evidence), +// The fixture is a REAL, CONTIGUOUS 0.157.0 rollout head (see its evidence), // with its expected first prompt recorded independently of the parser under // test. The later cases compose synthetic records AROUND that real head, and // say so. @@ -88,3 +88,45 @@ it('takes user activity from the tail when the head bound hides a later prompt', expect(row.userTexts).toEqual(['x'.repeat(expected.firstPromptLength)]) expect(row.lastUserActivityAt).toBe(Date.parse(later)) }) + +it('finds the newest prompt far behind a long agent turn', async () => { + // #1407 verification a: in 10 local 0.157 files the latest prompt lay + // wholly before a fixed 512 KiB tail. Here 4 MiB of agent output follow it. + const later = at(46.6 * 3600 * 1000) + const bulk = 'y'.repeat(64 * 1024) + const filler = (n: number, from: number) => Array.from({ length: n }, (_, i) => ({ timestamp: at(from + i), type: 'response_item', payload: { type: 'reasoning', summary: [], content: bulk } })) + const row = await discoverRow([...records, ...filler(250, 10), userMessage(later, [text('much later prompt')]), ...filler(64, 46.6 * 3600 * 1000 + 1)]) + expect(row.lastUserActivityAt).toBe(Date.parse(later)) +}) + +it('finds the newest prompt when its line straddles a read-chunk boundary', async () => { + // #1407 verification a: the tail reader dropped a record that started + // before its window. Lay the file out so the prompt's line ends exactly half + // inside the last 512 KiB chunk: bytes after the line = 512 KiB - half. + const later = at(46.6 * 3600 * 1000) + const bulk = 'y'.repeat(64 * 1024) + const head = [...records, ...Array.from({ length: 250 }, (_, i) => ({ timestamp: at(10 + i), type: 'response_item', payload: { type: 'reasoning', summary: [], content: bulk } }))] + const prompt = userMessage(later, [text('much later prompt')]) + const promptLine = JSON.stringify(prompt) + const bytesAfter = 512 * 1024 - Math.floor(promptLine.length / 2) + // After the prompt line: '\n' + tailLine + '\n' (discoverRow's join and final newline). + const base = { timestamp: at(46.6 * 3600 * 1000 + 1), type: 'response_item', payload: { type: 'reasoning', summary: [], content: '' } } + const pad = bytesAfter - 2 - JSON.stringify(base).length + const tail = { ...base, payload: { ...base.payload, content: 'y'.repeat(pad) } } + expect(Buffer.byteLength(JSON.stringify(tail)) + 2).toBe(bytesAfter) + const row = await discoverRow([...head, prompt, tail]) + expect(row.lastUserActivityAt).toBe(Date.parse(later)) +}) + +it('keeps a prompt the user really repeated in a later turn', async () => { + // #1407 verification a: identical text in a LATER turn is a new prompt, not + // the other carrier of an earlier one. Only a nearby pair is one prompt. + const row = await discoverRow([ + ...records, + legacyMessage(at(1000), 'repeat'), + legacyMessage(at(2000), 'different'), + ...Array.from({ length: 10 }, (_, i) => ({ timestamp: at(3000 + i), type: 'event_msg', payload: { type: 'token_count', info: null } })), + userMessage(at(48 * 3600 * 1000), [text('repeat')]), + ]) + expect(row.userTexts.slice(1)).toEqual(['repeat', 'different', 'repeat']) +}) diff --git a/testing/fixtures/conversations/codex-0157/typed-prompt-head.json b/testing/fixtures/conversations/codex-0157/typed-prompt-head.json index 99879f375..c822447dc 100644 --- a/testing/fixtures/conversations/codex-0157/typed-prompt-head.json +++ b/testing/fixtures/conversations/codex-0157/typed-prompt-head.json @@ -1,6 +1,6 @@ { - "evidence": "A real, CONTIGUOUS Codex 0.157.1 rollout head (#1363, rebuilt for #1407 reviews a and b): all 10 records from session_meta through the first event_msg item_completed whose item.type is UserMessage, in file order, nothing removed or reordered. It is the one local 0.157 file whose first UserMessage is a typed prompt; the other 421 open with an orchestration hand-off. Codex 0.157 writes no event_msg user_message. Keys, types, roles, CLI version, originator, model provider, timestamps and uuid ids are verbatim; every other string is replaced by the same number of x characters (newlines kept).", - "cliVersion": "0.157.1", + "evidence": "A real, CONTIGUOUS Codex 0.157.0 rollout head (its session_meta.cli_version; an earlier label said 0.157.1) (#1363, rebuilt for #1407 reviews a and b): all 10 records from session_meta through the first event_msg item_completed whose item.type is UserMessage, in file order, nothing removed or reordered. It is the one local 0.157 file whose first UserMessage is a typed prompt; the other 421 open with an orchestration hand-off. Codex 0.157 writes no event_msg user_message. Keys, types, roles, CLI version, originator, model provider, timestamps and uuid ids are verbatim; every other string is replaced by the same number of x characters (newlines kept).", + "cliVersion": "0.157.0", "expected": { "firstPromptLength": 464, "firstPromptTimestamp": "2026-09-25T05:44:03.249Z", From 456e6e1b0e3952b083108ff04cd9badeddff4700 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 05:56:20 -0700 Subject: [PATCH 31/40] fix(conversations): pair carriers by records and time; carry a chunk-spanning line whole (verification a, round 3) Co-Authored-By: Claude Opus 5.5 --- ...6-09-27-codex-conversations-usermessage.md | 5 +++ src/main/conversations/sources/codex.ts | 37 ++++++++++++++----- .../sources/codex.userMessage0157.test.ts | 22 +++++++++++ 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/docs/plans/2026-09-27-codex-conversations-usermessage.md b/docs/plans/2026-09-27-codex-conversations-usermessage.md index 52abef1b2..8a85cbf68 100644 --- a/docs/plans/2026-09-27-codex-conversations-usermessage.md +++ b/docs/plans/2026-09-27-codex-conversations-usermessage.md @@ -28,3 +28,8 @@ The fixture `testing/fixtures/conversations/codex-0157/typed-prompt-head.json` i - **De-duplication collapsed a prompt repeated in a later turn.** A cross-carrier pair is now matched only within 4 records, since Codex writes the two carriers of one prompt back to back. No local file has both carriers, so there was no recorded distance to calibrate against. - **Fixture label.** The fixture's `session_meta.cli_version` is 0.157.0; the label is corrected. - **Tests (red on the previous commit):** a prompt followed by 4 MiB of output; a prompt whose line straddles the last chunk boundary, laid out deterministically; a prompt repeated in a later turn. Dropping the carried partial line fails the straddle test. + +## Verification a (round 3) +- **The exact reported repeat (two records on, 48 h later) still paired.** The pair window is now records AND time: at most 4 records apart and at most 5 s apart. One prompt's two carriers share its instant. +- **A user line longer than two read chunks was lost.** A window with no newline is all one line, so all of it is carried to the next, earlier chunk, and nothing is parsed or dropped. +- **One of 452 files has its newest prompt 55.8 MB from the end, past the 32 MiB bound. Kept by design.** This is the degraded no-index path, rollouts reach gigabytes, and an unbounded scan per discovery is exactly the store-sized cost the head limit prevents. The WHY comment says so. diff --git a/src/main/conversations/sources/codex.ts b/src/main/conversations/sources/codex.ts index c89d86b14..ba26981b4 100644 --- a/src/main/conversations/sources/codex.ts +++ b/src/main/conversations/sources/codex.ts @@ -109,18 +109,25 @@ async function readRolloutHead(file: string): Promise { // matching identical text anywhere in the head collapsed a prompt the user // really repeated in a later turn. Codex writes the two carriers of ONE // prompt back to back, so the other carrier's record must be close. + // Both a record window AND a time window (#1407 verification a, round 2): + // records alone let the same text typed two days later, two records on, + // pass for the other carrier. One prompt's carriers share its instant. const PAIR_WINDOW_RECORDS = 4 - const pending = { legacy: [] as Array<{ text: string; at: number }>, item: [] as Array<{ text: string; at: number }> } + const PAIR_WINDOW_MS = 5_000 + const pending = { legacy: [] as Array<{ text: string; at: number; ts: number }>, item: [] as Array<{ text: string; at: number; ts: number }> } const noteUser = (carrier: 'legacy' | 'item', text: string, timestamp: unknown, recordIndex: number) => { + const ts = typeof timestamp === 'string' ? Date.parse(timestamp) : NaN const other = carrier === 'legacy' ? pending.item : pending.legacy - const match = other.findIndex(candidate => candidate.text === text && recordIndex - candidate.at <= PAIR_WINDOW_RECORDS) + const match = other.findIndex(candidate => + candidate.text === text && + recordIndex - candidate.at <= PAIR_WINDOW_RECORDS && + Number.isFinite(ts) && Number.isFinite(candidate.ts) && Math.abs(ts - candidate.ts) <= PAIR_WINDOW_MS) if (match >= 0) { other.splice(match, 1) } else { - pending[carrier].push({ text, at: recordIndex }) + pending[carrier].push({ text, at: recordIndex, ts }) if (out.userTexts.length < 6) out.userTexts.push(text) } - const ts = typeof timestamp === 'string' ? Date.parse(timestamp) : NaN if (Number.isFinite(ts)) out.lastUserAt = Math.max(out.lastUserAt ?? ts, ts) } let records = 0 @@ -172,7 +179,11 @@ async function readRolloutHead(file: string): Promise { // it is. The scan is bounded: a file with no user record in its last // TAIL_ACTIVITY_MAX_BYTES keeps the head's time, which is at worst the old // behaviour. It runs only for heads that hit their record bound, and the -// result is cached by mtime with the head. +// result is cached by mtime with the head. WHY a bound at all, knowing it +// misses (1 of 452 local 0.157 files had its newest prompt 55.8 MB from the +// end, #1407 verification a): this is the degraded no-index path, rollouts +// reach gigabytes, and an unbounded scan per discovery is the store-sized +// cost the head limit above exists to prevent. const TAIL_ACTIVITY_CHUNK_BYTES = 512 * 1024 const TAIL_ACTIVITY_MAX_BYTES = 32 * 1024 * 1024 @@ -189,12 +200,18 @@ async function newestUserTimestampInTail(file: string): Promise { const chunk = Buffer.alloc(end - start) await handle.read(chunk, 0, chunk.length, start) const window = Buffer.concat([chunk, carry]) - const text = window.toString('utf8') // Unless this chunk starts the file, its first line is incomplete: keep - // its bytes for the next (earlier) chunk rather than dropping it. - const firstBreak = start > 0 ? window.indexOf(0x0a) : -1 - const complete = firstBreak >= 0 ? window.subarray(firstBreak + 1).toString('utf8') : text - carry = firstBreak >= 0 ? window.subarray(0, firstBreak) : Buffer.alloc(0) + // its bytes for the next (earlier) chunk rather than dropping it. A + // window with NO newline is all one line longer than a chunk: carry the + // whole of it (#1407 verification a, round 2), never parse or drop it. + const firstBreak = window.indexOf(0x0a) + if (start > 0 && firstBreak < 0) { + carry = window + end = start + continue + } + const complete = start > 0 ? window.subarray(firstBreak + 1).toString('utf8') : window.toString('utf8') + carry = start > 0 ? window.subarray(0, firstBreak) : Buffer.alloc(0) const newest = newestUserTimestampIn(complete.split('\n')) if (newest !== null) return newest if (start === 0) break diff --git a/src/main/conversations/sources/codex.userMessage0157.test.ts b/src/main/conversations/sources/codex.userMessage0157.test.ts index dc0bdedb9..c44655975 100644 --- a/src/main/conversations/sources/codex.userMessage0157.test.ts +++ b/src/main/conversations/sources/codex.userMessage0157.test.ts @@ -130,3 +130,25 @@ it('keeps a prompt the user really repeated in a later turn', async () => { ]) expect(row.userTexts.slice(1)).toEqual(['repeat', 'different', 'repeat']) }) + +it('keeps a later repeat even when it is only two records on', async () => { + // #1407 verification a, round 2: the exact reported sequence, with no + // records between. The pair window is records AND time. + const row = await discoverRow([ + ...records, + legacyMessage(at(1000), 'repeat'), + legacyMessage(at(2000), 'different'), + userMessage(at(48 * 3600 * 1000), [text('repeat')]), + ]) + expect(row.userTexts.slice(1)).toEqual(['repeat', 'different', 'repeat']) +}) + +it('finds a newest prompt whose single line is longer than two read chunks', async () => { + // #1407 verification a, round 2: a window with no newline is all one line. + const later = at(46.6 * 3600 * 1000) + const bulk = 'y'.repeat(64 * 1024) + const head = [...records, ...Array.from({ length: 250 }, (_, i) => ({ timestamp: at(10 + i), type: 'response_item', payload: { type: 'reasoning', summary: [], content: bulk } }))] + const huge = userMessage(later, [text('z'.repeat(1_200_000))]) + const row = await discoverRow([...head, huge]) + expect(row.lastUserActivityAt).toBe(Date.parse(later)) +}) From b781ed57b530e0c1b26dc39024507949306a1ccd Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 05:58:29 -0700 Subject: [PATCH 32/40] docs(composer): plan saying an image paste the agent cannot take (#1250 row 7) Co-Authored-By: Claude Opus 5.5 --- ...-09-27-image-paste-unsupported-provider.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 docs/plans/2026-09-27-image-paste-unsupported-provider.md diff --git a/docs/plans/2026-09-27-image-paste-unsupported-provider.md b/docs/plans/2026-09-27-image-paste-unsupported-provider.md new file mode 100644 index 000000000..6cd4b1658 --- /dev/null +++ b/docs/plans/2026-09-27-image-paste-unsupported-provider.md @@ -0,0 +1,25 @@ +# Pasting an image into an agent that cannot take one says so (#1250 row 7) + +Short plan: a bug with a known root cause. The row comes from `temp/quality-loop/hunt-c3.md` (row 7, P3). #1250 is a batch issue, so this PR is `Refs #1250`. + +## Outcome +Only Claude takes pasted images today (`supportsImageAttachments`). In a Codex, OpenCode, Grok or Pi composer, pasting a screenshot does nothing at all. The user now sees " can't take pasted images." when the clipboard holds an image file and no text. + +## Root cause (verified in source, origin/main) +- `useClaudeImagePaste.handlePaste` returns `{ handledImages: false }` at once for a provider without image support. The textarea's default paste of an image-only clipboard inserts nothing, and `usePasteToFocus` appends only text. Nothing is said. + +## Design (contract) +- In that early return, read `clipboardData` synchronously. If it has an `image/*` ITEM and no `text/plain`, show a toast (through the hook's `showToast`, the pane toast): " can't take pasted images." +- **Only an image FILE item with no text counts.** Copying from a web page often carries `` in `text/html` alongside text, and that text paste must stay silent. A mixed image+text paste pastes the text as before, with no toast. +- It still returns `handledImages: false`, so the text routing is unchanged. + +## Tests +New `useClaudeImagePaste.renderer.test.tsx` renders the real hook, with a real PNG from `testing/fixtures/image-reads` placed in a `DataTransfer`. +- Codex, image only: the toast shows. Red on main. +- Codex, image plus text: no toast (the text pastes). +- Codex, text only: no toast. +- Claude, image only: no such toast (the image is taken). + +## Out of scope +- #1250's other rows. +- Image support for other providers. From d584eb6a92b7a1c14b40e3973fe68034672eb8e3 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 05:58:31 -0700 Subject: [PATCH 33/40] fix(conversations): pair carriers only with the immediately previous user record (verification b) Co-Authored-By: Claude Opus 5.5 --- ...6-09-27-codex-conversations-usermessage.md | 4 ++++ src/main/conversations/sources/codex.ts | 24 +++++++++++-------- .../sources/codex.userMessage0157.test.ts | 14 +++++++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/docs/plans/2026-09-27-codex-conversations-usermessage.md b/docs/plans/2026-09-27-codex-conversations-usermessage.md index 8a85cbf68..42c8b9b6c 100644 --- a/docs/plans/2026-09-27-codex-conversations-usermessage.md +++ b/docs/plans/2026-09-27-codex-conversations-usermessage.md @@ -33,3 +33,7 @@ The fixture `testing/fixtures/conversations/codex-0157/typed-prompt-head.json` i - **The exact reported repeat (two records on, 48 h later) still paired.** The pair window is now records AND time: at most 4 records apart and at most 5 s apart. One prompt's two carriers share its instant. - **A user line longer than two read chunks was lost.** A window with no newline is all one line, so all of it is carried to the next, earlier chunk, and nothing is parsed or dropped. - **One of 452 files has its newest prompt 55.8 MB from the end, past the 32 MiB bound. Kept by design.** This is the degraded no-index path, rollouts reach gigabytes, and an unbounded scan per discovery is exactly the store-sized cost the head limit prevents. The WHY comment says so. + +## Verification b (at bb183091) +- **A pair crossed an intervening prompt** (`repeat`, `different`, `repeat`, seconds apart). Fixed: a carrier pairs only with the IMMEDIATELY previous user record, which must be the other carrier, within 4 records and 5 s. Test: `start, repeat, different, repeat` keeps all four. It is red on `456e6e1b`. +- **The 32 MiB residual** (the same one file) is the deliberate bound documented at `456e6e1b`. diff --git a/src/main/conversations/sources/codex.ts b/src/main/conversations/sources/codex.ts index ba26981b4..2a65096aa 100644 --- a/src/main/conversations/sources/codex.ts +++ b/src/main/conversations/sources/codex.ts @@ -101,7 +101,8 @@ async function readRolloutHead(file: string): Promise { // read and merged, not "legacy wins" (#1407 reviews a and b): a file with // both carriers (a session resumed across writer versions) could then lose // a prompt only the items hold. The same prompt written by both carriers is - // counted once: each carrier consumes a pending match from the other. + // counted once: see the pairing rule below (the immediately previous user + // record, the other carrier, within 4 records and 5 s). // What older CLIs put in UserMessage items (sometimes injected context or a // command wrapper) is what the index lists too; firstUnwrappedPrompt and // classify decide what is a label, as for every other source. @@ -114,18 +115,21 @@ async function readRolloutHead(file: string): Promise { // pass for the other carrier. One prompt's carriers share its instant. const PAIR_WINDOW_RECORDS = 4 const PAIR_WINDOW_MS = 5_000 - const pending = { legacy: [] as Array<{ text: string; at: number; ts: number }>, item: [] as Array<{ text: string; at: number; ts: number }> } + let lastUser: { carrier: 'legacy' | 'item'; text: string; at: number; ts: number; paired: boolean } | null = null const noteUser = (carrier: 'legacy' | 'item', text: string, timestamp: unknown, recordIndex: number) => { const ts = typeof timestamp === 'string' ? Date.parse(timestamp) : NaN - const other = carrier === 'legacy' ? pending.item : pending.legacy - const match = other.findIndex(candidate => - candidate.text === text && - recordIndex - candidate.at <= PAIR_WINDOW_RECORDS && - Number.isFinite(ts) && Number.isFinite(candidate.ts) && Math.abs(ts - candidate.ts) <= PAIR_WINDOW_MS) - if (match >= 0) { - other.splice(match, 1) + // ...and never across another user prompt (#1407 verification b): the + // other carrier must be the IMMEDIATELY previous user record, so + // `repeat, different, repeat` inside a few seconds keeps both repeats. + const previous = lastUser + const pairs = previous !== null && previous.carrier !== carrier && !previous.paired && + previous.text === text && + recordIndex - previous.at <= PAIR_WINDOW_RECORDS && + Number.isFinite(ts) && Number.isFinite(previous.ts) && Math.abs(ts - previous.ts) <= PAIR_WINDOW_MS + if (pairs) { + previous.paired = true } else { - pending[carrier].push({ text, at: recordIndex, ts }) + lastUser = { carrier, text, at: recordIndex, ts, paired: false } if (out.userTexts.length < 6) out.userTexts.push(text) } if (Number.isFinite(ts)) out.lastUserAt = Math.max(out.lastUserAt ?? ts, ts) diff --git a/src/main/conversations/sources/codex.userMessage0157.test.ts b/src/main/conversations/sources/codex.userMessage0157.test.ts index c44655975..9128a17ee 100644 --- a/src/main/conversations/sources/codex.userMessage0157.test.ts +++ b/src/main/conversations/sources/codex.userMessage0157.test.ts @@ -152,3 +152,17 @@ it('finds a newest prompt whose single line is longer than two read chunks', asy const row = await discoverRow([...head, huge]) expect(row.lastUserActivityAt).toBe(Date.parse(later)) }) + +it('never pairs carriers across another prompt', async () => { + // #1407 verification b: `repeat` (legacy), `different` (item), `repeat` + // (item) within a few seconds. The second repeat's previous user record is + // `different`, so it is a new prompt, not the other carrier of the first. + const row = await discoverRow([ + ...records, + legacyMessage(at(1000), 'start'), + legacyMessage(at(1100), 'repeat'), + userMessage(at(1200), [text('different')]), + userMessage(at(1300), [text('repeat')]), + ]) + expect(row.userTexts.slice(1)).toEqual(['start', 'repeat', 'different', 'repeat']) +}) From 2bb9d19c51a6ea896a2af706bb6a3de35af1d43a Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 06:01:14 -0700 Subject: [PATCH 34/40] docs/test: quote the refusal as the code writes it; clearer test title (review c nits) Co-Authored-By: Claude Opus 5.5 --- .../plans/2026-09-27-ai-workspace-write-status-warning.md | 8 +++++++- src/main/aiWorkspace/AiWorkspaceRegistry.test.ts | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/plans/2026-09-27-ai-workspace-write-status-warning.md b/docs/plans/2026-09-27-ai-workspace-write-status-warning.md index 57c2111bc..9cff77bad 100644 --- a/docs/plans/2026-09-27-ai-workspace-write-status-warning.md +++ b/docs/plans/2026-09-27-ai-workspace-write-status-warning.md @@ -13,7 +13,7 @@ ## Decisions (defaults) 1. **A failed status refresh after a successful write does not fail the write.** It returns `ok: true` with an optional `warning` on the success branch of `AiWorkspaceWriteFileResult`, documented as "the file IS written; do not retry". It logs the error, and still emits `file-written` to every workspace holding the file. 2. **The owed-copy invariant is unchanged.** The state file is still never saved while a copy is owed. -3. **A refused save explains itself.** `preserveOwedCopy` rewrites a copy failure: "AI Workspace storage needs attention: N unreadable row(s) must be copied aside before saving, and the copy next to could not be written (). Clear whatever occupies that copy path to continue." Only the errno code is kept, not the raw text. +3. **A refused save explains itself.** `preserveOwedCopy` rewrites a copy failure: "AI Workspace storage needs attention: N unreadable row(s) must be copied aside before saving, and the copy could not be written (). " (the advice names the state file's folder) Only the errno code is kept, not the raw text. ## Tests (fail-first, `AiWorkspaceRegistry.test.ts`) The input is the real recorded workspace state. One real entry is pointed at a temp file (the recorded paths are redacted), and one real workspace is made malformed so a copy is owed. The copy path is blocked with a directory. @@ -36,3 +36,9 @@ The input is the real recorded workspace state. One real entry is pointed at a t - appending the raw error text to the refusal (asserted absent); - stopping the fan-out after the first workspace (two-workspace test); - dropping `get`'s notice. + +## Review c (at 589d42a9; MERGE-READY) +Test-strength notes, not defects: +- The emit on the warning path and the fan-out are now pinned. The two-workspace listener test landed in `d8f1eae6`. +- Four of the six advice branches (EACCES/EPERM, EROFS, ENOSPC, generic) have no test. They are not reachable portably from a unit test without mocking the filesystem module. +- The quoted refusal sentence in this plan and the body is corrected to the code's wording, and a test title is fixed. diff --git a/src/main/aiWorkspace/AiWorkspaceRegistry.test.ts b/src/main/aiWorkspace/AiWorkspaceRegistry.test.ts index 30bca1771..a267cb6f0 100644 --- a/src/main/aiWorkspace/AiWorkspaceRegistry.test.ts +++ b/src/main/aiWorkspace/AiWorkspaceRegistry.test.ts @@ -351,7 +351,7 @@ describe('a write whose status refresh cannot be saved (#1285)', () => { expect(await readFile(statePath, 'utf8')).not.toContain('storageWarning') }) - it('warns on no ordinary write, and tells every workspace even when a listener throws', async () => { + it('gives no warning on an ordinary write, and a throwing listener does not fail it', async () => { // #1416 review a: a throwing `changed` listener (the production one // broadcasts to every window) turned a landed write into `ok: false`, // and stopped the second workspace hearing about it. From a64baf97a42d22395675167107384596ac8e615c Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 06:02:31 -0700 Subject: [PATCH 35/40] fix(composer): say when a pasted image cannot go to this agent (#1250 row 7) Co-Authored-By: Claude Opus 5.5 --- .../useClaudeImagePaste.renderer.test.tsx | 61 +++++++++++++++++++ .../tile-tree/TileLeaf/useClaudeImagePaste.ts | 20 +++++- 2 files changed, 78 insertions(+), 3 deletions(-) create mode 100644 src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.renderer.test.tsx diff --git a/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.renderer.test.tsx b/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.renderer.test.tsx new file mode 100644 index 000000000..68b6dbc6f --- /dev/null +++ b/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.renderer.test.tsx @@ -0,0 +1,61 @@ +import { readFileSync } from 'node:fs' + +import { act, renderHook } from '@testing-library/react' +import { describe, expect, it, vi } from 'vitest' + +import { useClaudeImagePaste } from './useClaudeImagePaste' + +// #1250 row 7: only Claude takes pasted images. A screenshot pasted into a +// Codex, OpenCode, Grok or Pi composer inserted nothing and said nothing. +// +// The REAL hook with the real provider capabilities. The image bytes are a +// RECORDED user attachment (testing/fixtures/image-reads/claude-user-attachment.json); +// the paste event's clipboardData is the one stubbed edge, shaped as the +// browser gives it (items with kind/type/getAsFile, getData by type). + +const recorded = JSON.parse(readFileSync('testing/fixtures/image-reads/claude-user-attachment.json', 'utf8')) as { + entry: { message: { content: Array<{ source?: { data: string; media_type: string } }> } } +} +const source = recorded.entry.message.content[1]!.source! +const png = new File([Buffer.from(source.data, 'base64')], 'screenshot.png', { type: source.media_type }) + +function paste(options: { image: boolean; text?: string }) { + const items = options.image ? [{ kind: 'file', type: png.type, getAsFile: () => png }] : [] + return { + clipboardData: { + items, + getData: (type: string) => (type === 'text/plain' ? options.text ?? '' : ''), + } as unknown as DataTransfer, + preventDefault: vi.fn(), + } +} + +function hook(provider: 'codex' | 'claude') { + const showToast = vi.fn() + const { result } = renderHook(() => useClaudeImagePaste({ provider, sessionId: 's1' as never, setDraftImages: vi.fn(), showToast })) + return { handlePaste: result.current.handlePaste, showToast } +} + +describe('pasting an image into an agent that cannot take one', () => { + it('says so for an image-only paste', async () => { + const { handlePaste, showToast } = hook('codex') + let answer: unknown + await act(async () => { answer = await handlePaste(paste({ image: true })) }) + expect(showToast).toHaveBeenCalledWith("Codex can't take pasted images.") + // The text routing is unchanged: the caller still owns the text. + expect(answer).toEqual({ handledImages: false }) + }) + + it('stays silent when the paste also carries text, and for plain text', async () => { + const { handlePaste, showToast } = hook('codex') + await act(async () => { await handlePaste(paste({ image: true, text: 'see attached' })) }) + await act(async () => { await handlePaste(paste({ image: false, text: 'hello' })) }) + expect(showToast).not.toHaveBeenCalled() + }) + + it('does not say it for Claude, which takes the image', async () => { + const { handlePaste, showToast } = hook('claude') + await act(async () => { await handlePaste(paste({ image: true })) }) + expect(showToast).not.toHaveBeenCalledWith(expect.stringContaining("can't take pasted images")) + }) +}) diff --git a/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.ts b/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.ts index d40e76de2..a94ae04e9 100644 --- a/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.ts +++ b/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.ts @@ -95,9 +95,23 @@ export function useClaudeImagePaste({ const handlePaste = useCallback( async (e: ClipboardLike): Promise => { - // Codex has no inline-image content — fall through so the - // caller routes the clipboard's text instead. - if (!getRendererProviderCapabilities(provider).supportsImageAttachments) return { handledImages: false } + // Providers without inline-image content fall through, so the caller + // routes the clipboard's text instead. + const capabilities = getRendererProviderCapabilities(provider) + if (!capabilities.supportsImageAttachments) { + // WHY say so (#1250 row 7): an image-only paste (a screenshot) into + // a Codex/OpenCode/Grok/Pi composer inserted nothing and said + // nothing. Only an image FILE with no text counts: a web-page copy + // carries in text/html beside its text, and that text paste + // must stay silent. Read synchronously; the event's data is only + // reliable during dispatch. + const data = e.clipboardData + const imageOnly = Boolean(data) + && Array.from(data!.items).some(item => item.kind === 'file' && item.type.startsWith('image/')) + && !data!.getData('text/plain') + if (imageOnly) showToast(`${capabilities.shortLabel} can't take pasted images.`) + return { handledImages: false } + } const clipboardData = e.clipboardData if (!clipboardData) return { handledImages: false } From 3d5b768fc1a87a5dbbd32bcb030cb72390769d90 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 06:27:41 -0700 Subject: [PATCH 36/40] fix(composer): say a dropped image for file+text, HTML-only and async-only pastes; composer wording (#1426 review) Co-Authored-By: Claude Opus 5.5 --- ...-09-27-image-paste-unsupported-provider.md | 9 +++ .../tile-tree/TileLeaf/claudeImages.ts | 4 +- .../useClaudeImagePaste.renderer.test.tsx | 71 ++++++++++++++----- .../tile-tree/TileLeaf/useClaudeImagePaste.ts | 38 +++++++--- 4 files changed, 96 insertions(+), 26 deletions(-) diff --git a/docs/plans/2026-09-27-image-paste-unsupported-provider.md b/docs/plans/2026-09-27-image-paste-unsupported-provider.md index 6cd4b1658..93e9b5615 100644 --- a/docs/plans/2026-09-27-image-paste-unsupported-provider.md +++ b/docs/plans/2026-09-27-image-paste-unsupported-provider.md @@ -23,3 +23,12 @@ New `useClaudeImagePaste.renderer.test.tsx` renders the real hook, with a real P ## Out of scope - #1250's other rows. - Image support for other providers. + +## Review round 1 (a, b: FIX-BEFORE-MERGE) +- **b1: an image FILE plus text dropped the image silently** ("see attached" with no attachment). The text still pastes, and the toast says "…only the text was pasted." A file item is strong evidence; only an HTML `` beside text (a web-page copy) stays silent. +- **a2 / b2: an image arriving only as a data-URL `` in text/html, with no text, was silent.** It now counts. +- **a3: an image only the async clipboard API shows was silent.** With nothing else in the event (no text, no HTML, no items), `readImagesFromClipboard` is probed. Paste-to-focus's documented miss of this shape is unchanged (it never calls the hook for it). +- **b3: the wording blamed the provider.** Grok's own TUI attaches clipboard images. The sentence is now about this composer: "Pasted images can't be sent to from this composer." +- **a1 (terminal view): declined.** There the paste goes to the provider's own TUI, which owns image handling (Grok's attaches images); the app's capability flag is about its composer. +- **a4: every provider's wording is tested** (Codex, OpenCode, Grok, Pi). +- `parseImagesFromHtml` uses `querySelectorAll('img')` instead of `doc.images`. It is identical in a browser, and the happy-dom test DOM lacks `images` on a parsed document. diff --git a/src/renderer/src/workspace/tile-tree/TileLeaf/claudeImages.ts b/src/renderer/src/workspace/tile-tree/TileLeaf/claudeImages.ts index af4d98bbb..abcfa94c0 100644 --- a/src/renderer/src/workspace/tile-tree/TileLeaf/claudeImages.ts +++ b/src/renderer/src/workspace/tile-tree/TileLeaf/claudeImages.ts @@ -86,7 +86,9 @@ export function parseImagesFromHtml(html: string): ClaudeDraftImage[] { // the HTML is never injected into the live DOM. const doc = new DOMParser().parseFromString(html, 'text/html') const images: ClaudeDraftImage[] = [] - for (const img of Array.from(doc.images)) { + // querySelectorAll, not `doc.images`: identical in a browser, and the + // happy-dom test DOM has no `images` collection on a parsed document. + for (const img of Array.from(doc.querySelectorAll('img'))) { const src = img.getAttribute('src')?.trim() ?? '' if (!src.startsWith('data:image/')) continue try { diff --git a/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.renderer.test.tsx b/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.renderer.test.tsx index 68b6dbc6f..09a28aa1d 100644 --- a/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.renderer.test.tsx +++ b/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.renderer.test.tsx @@ -1,61 +1,100 @@ import { readFileSync } from 'node:fs' import { act, renderHook } from '@testing-library/react' -import { describe, expect, it, vi } from 'vitest' +import { afterEach, describe, expect, it, vi } from 'vitest' import { useClaudeImagePaste } from './useClaudeImagePaste' -// #1250 row 7: only Claude takes pasted images. A screenshot pasted into a -// Codex, OpenCode, Grok or Pi composer inserted nothing and said nothing. +// #1250 row 7: only Claude's composer takes pasted images. A screenshot +// pasted into a Codex, OpenCode, Grok or Pi composer was dropped with nothing +// said. // // The REAL hook with the real provider capabilities. The image bytes are a // RECORDED user attachment (testing/fixtures/image-reads/claude-user-attachment.json); -// the paste event's clipboardData is the one stubbed edge, shaped as the -// browser gives it (items with kind/type/getAsFile, getData by type). +// the paste event's clipboardData, and navigator.clipboard.read for the async +// case, are the stubbed edges, shaped as the browser gives them. const recorded = JSON.parse(readFileSync('testing/fixtures/image-reads/claude-user-attachment.json', 'utf8')) as { entry: { message: { content: Array<{ source?: { data: string; media_type: string } }> } } } const source = recorded.entry.message.content[1]!.source! const png = new File([Buffer.from(source.data, 'base64')], 'screenshot.png', { type: source.media_type }) +const dataUrlImg = `` -function paste(options: { image: boolean; text?: string }) { +const originalClipboard = Object.getOwnPropertyDescriptor(navigator, 'clipboard') +afterEach(() => { + if (originalClipboard) Object.defineProperty(navigator, 'clipboard', originalClipboard) + else Reflect.deleteProperty(navigator, 'clipboard') +}) + +function paste(options: { image?: boolean; text?: string; html?: string }) { const items = options.image ? [{ kind: 'file', type: png.type, getAsFile: () => png }] : [] return { clipboardData: { items, - getData: (type: string) => (type === 'text/plain' ? options.text ?? '' : ''), + getData: (type: string) => (type === 'text/plain' ? options.text ?? '' : type === 'text/html' ? options.html ?? '' : ''), } as unknown as DataTransfer, preventDefault: vi.fn(), } } -function hook(provider: 'codex' | 'claude') { +function hook(provider: 'codex' | 'opencode' | 'grok' | 'pi' | 'claude') { const showToast = vi.fn() const { result } = renderHook(() => useClaudeImagePaste({ provider, sessionId: 's1' as never, setDraftImages: vi.fn(), showToast })) return { handlePaste: result.current.handlePaste, showToast } } -describe('pasting an image into an agent that cannot take one', () => { - it('says so for an image-only paste', async () => { - const { handlePaste, showToast } = hook('codex') +describe('pasting an image into a composer that cannot take one', () => { + // Each provider is named: the sentence is built from its label (#1426 review a). + it.each([ + ['codex', 'Codex'], + ['opencode', 'OpenCode'], + ['grok', 'Grok'], + ['pi', 'Pi'], + ] as const)('says so for an image-only paste into %s', async (provider, label) => { + const { handlePaste, showToast } = hook(provider) let answer: unknown await act(async () => { answer = await handlePaste(paste({ image: true })) }) - expect(showToast).toHaveBeenCalledWith("Codex can't take pasted images.") - // The text routing is unchanged: the caller still owns the text. + expect(showToast).toHaveBeenCalledWith(`Pasted images can't be sent to ${label} from this composer.`) expect(answer).toEqual({ handledImages: false }) }) - it('stays silent when the paste also carries text, and for plain text', async () => { + // #1426 review b: "see attached" with the attachment silently dropped. + it('says the image was left out of an image-plus-text paste', async () => { const { handlePaste, showToast } = hook('codex') await act(async () => { await handlePaste(paste({ image: true, text: 'see attached' })) }) - await act(async () => { await handlePaste(paste({ image: false, text: 'hello' })) }) + expect(showToast).toHaveBeenCalledWith("Pasted images can't be sent to Codex from this composer; only the text was pasted.") + }) + + // #1426 review a, b: a browser image copy that arrives only as a data-URL + // in text/html. + it('says so for an image that arrives only as HTML', async () => { + const { handlePaste, showToast } = hook('codex') + await act(async () => { await handlePaste(paste({ html: dataUrlImg })) }) + expect(showToast).toHaveBeenCalledWith("Pasted images can't be sent to Codex from this composer.") + }) + + // #1426 review a: an image only the async clipboard API shows. + it('says so for an image only the async clipboard shows', async () => { + Object.defineProperty(navigator, 'clipboard', { + configurable: true, + value: { read: vi.fn(async () => [{ types: [png.type], getType: async () => png }]) }, + }) + const { handlePaste, showToast } = hook('codex') + await act(async () => { await handlePaste(paste({})) }) + expect(showToast).toHaveBeenCalledWith("Pasted images can't be sent to Codex from this composer.") + }) + + it('stays silent for plain text, and for a web-page copy (an beside its text)', async () => { + const { handlePaste, showToast } = hook('codex') + await act(async () => { await handlePaste(paste({ text: 'hello' })) }) + await act(async () => { await handlePaste(paste({ text: 'an article', html: `

an article

${dataUrlImg}` })) }) expect(showToast).not.toHaveBeenCalled() }) it('does not say it for Claude, which takes the image', async () => { const { handlePaste, showToast } = hook('claude') await act(async () => { await handlePaste(paste({ image: true })) }) - expect(showToast).not.toHaveBeenCalledWith(expect.stringContaining("can't take pasted images")) + expect(showToast).not.toHaveBeenCalledWith(expect.stringContaining("can't be sent")) }) }) diff --git a/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.ts b/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.ts index a94ae04e9..cdd8a61aa 100644 --- a/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.ts +++ b/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.ts @@ -99,17 +99,37 @@ export function useClaudeImagePaste({ // routes the clipboard's text instead. const capabilities = getRendererProviderCapabilities(provider) if (!capabilities.supportsImageAttachments) { - // WHY say so (#1250 row 7): an image-only paste (a screenshot) into - // a Codex/OpenCode/Grok/Pi composer inserted nothing and said - // nothing. Only an image FILE with no text counts: a web-page copy - // carries in text/html beside its text, and that text paste - // must stay silent. Read synchronously; the event's data is only + // WHY say so (#1250 row 7): an image pasted into a Codex, OpenCode, + // Grok or Pi composer was dropped with nothing said. The wording is + // about THIS composer, not the provider (#1426 review b): Grok's own + // TUI attaches clipboard images in Terminal view, where a paste goes + // to the TUI and this hook never runs. + // + // What counts as an image (#1426 review a, b): + // - an image FILE item, with or without text. A mixed paste pastes + // its text and says the image was left out ("see attached" with + // no attachment is the silent loss); + // - a data-URL in text/html with NO text. A web-page copy + // carries beside its text, and that text paste stays silent; + // - with nothing else at all, an image only the async clipboard API + // shows (an Electron/macOS shape claudeImages.ts documents). + // Everything is read synchronously first; the event's data is only // reliable during dispatch. const data = e.clipboardData - const imageOnly = Boolean(data) - && Array.from(data!.items).some(item => item.kind === 'file' && item.type.startsWith('image/')) - && !data!.getData('text/plain') - if (imageOnly) showToast(`${capabilities.shortLabel} can't take pasted images.`) + if (!data) return { handledImages: false } + const text = data.getData('text/plain') + const hasImageFile = Array.from(data.items).some(item => item.kind === 'file' && item.type.startsWith('image/')) + const html = data.getData('text/html') + const hasHtmlImage = parseImagesFromHtml(html).length > 0 + const where = `${capabilities.shortLabel} from this composer` + if (hasImageFile && text) { + showToast(`Pasted images can't be sent to ${where}; only the text was pasted.`) + } else if (hasImageFile || (hasHtmlImage && !text)) { + showToast(`Pasted images can't be sent to ${where}.`) + } else if (!text && !html && data.items.length === 0) { + const asyncImages = await readImagesFromClipboard().catch(() => []) + if (asyncImages.length > 0) showToast(`Pasted images can't be sent to ${where}.`) + } return { handledImages: false } } const clipboardData = e.clipboardData From a4a0f191ef2b3099318db8080b2228bf421c7471 Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 06:28:00 -0700 Subject: [PATCH 37/40] fix(feed-debug): a release sent while persistence is off writes no drop marker (#1392 review c round 2) Co-Authored-By: Claude Opus 5.5 --- src/main/ipc/debug.test.ts | 12 +++++++++--- src/main/ipc/debug.ts | 6 ++++-- src/main/storage/feedDebugLog.test.ts | 13 +++++++++++++ src/main/storage/feedDebugLog.ts | 12 ++++++++++-- src/preload/api/debug.ts | 2 +- .../useFeedDebugPersist.renderer.test.tsx | 8 +++++--- .../hook/persistence/useFeedDebugPersist.ts | 11 +++++++---- 7 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/main/ipc/debug.test.ts b/src/main/ipc/debug.test.ts index b67e8db22..e01878daf 100644 --- a/src/main/ipc/debug.test.ts +++ b/src/main/ipc/debug.test.ts @@ -4,7 +4,7 @@ const harness = vi.hoisted(() => ({ handlers: new Map unknown>(), order: [] as string[], queueFeedDebugAppend: vi.fn<(sessionId: string, entries: unknown[], epochMs?: number) => Promise>(async () => {}), - forgetFeedDebugSession: vi.fn<(sessionId: string) => void>(), + forgetFeedDebugSession: vi.fn<(sessionId: string, options?: { persistUnmarkedDrops?: boolean }) => void>(), saveDebugBundle: vi.fn(async () => { harness.order.push('save') return { bundlePath: '/tmp/test-bundle' } @@ -184,10 +184,16 @@ describe('debug:forget-feed-log', () => { return handler } - it('forgets the named session in main', () => { + it('forgets the named session in main, persisting unmarked drops by default', () => { harness.forgetFeedDebugSession.mockClear() forgetHandler()({}, { sessionId: 'closed-pane' }) - expect(harness.forgetFeedDebugSession).toHaveBeenCalledExactlyOnceWith('closed-pane') + expect(harness.forgetFeedDebugSession).toHaveBeenCalledExactlyOnceWith('closed-pane', { persistUnmarkedDrops: true }) + }) + + it('passes persistUnmarkedDrops: false through (persistence off)', () => { + harness.forgetFeedDebugSession.mockClear() + forgetHandler()({}, { sessionId: 'closed-pane', persistUnmarkedDrops: false }) + expect(harness.forgetFeedDebugSession).toHaveBeenCalledExactlyOnceWith('closed-pane', { persistUnmarkedDrops: false }) }) it.each([undefined, null, {}, { sessionId: '' }, { sessionId: 7 }, { sessionId: ['a'] }])( diff --git a/src/main/ipc/debug.ts b/src/main/ipc/debug.ts index c662b10d7..dd0c0f96b 100644 --- a/src/main/ipc/debug.ts +++ b/src/main/ipc/debug.ts @@ -56,9 +56,11 @@ export function registerDebugIpc( // Any append it queued earlier is already in the per-session queue (IPC // order is preserved and the append handler queues synchronously), and its // token makes it drop what it writes. - ipcMain.handle('debug:forget-feed-log', (_evt, params: { sessionId?: unknown }) => { + ipcMain.handle('debug:forget-feed-log', (_evt, params: { sessionId?: unknown; persistUnmarkedDrops?: unknown }) => { if (typeof params?.sessionId !== 'string' || params.sessionId.length === 0) return - forgetFeedDebugSession(params.sessionId) + // Only an explicit false skips the final marker; an older renderer that + // sends no flag keeps the previous (persisting) behaviour. + forgetFeedDebugSession(params.sessionId, { persistUnmarkedDrops: params.persistUnmarkedDrops !== false }) }) ipcMain.handle( diff --git a/src/main/storage/feedDebugLog.test.ts b/src/main/storage/feedDebugLog.test.ts index 515e1d4bc..aba10fe24 100644 --- a/src/main/storage/feedDebugLog.test.ts +++ b/src/main/storage/feedDebugLog.test.ts @@ -328,6 +328,19 @@ describe('a rebuilt cap state keeps the file\'s drop count', () => { expect(await lastMarkerDrops('rows-after-marker')).toBeGreaterThanOrEqual(1_001) }) + // #1392 review c, round 2: a release sent while persistence is OFF must not + // write the final drop marker either. Persistence off means no disk writes. + it('a forget told not to persist drops writes nothing', async () => { + await cappedFileWithMarker('no-write-forget', 1_000) + await queueFeedDebugAppend('no-write-forget', [entry(1)], 1_000) + await queueFeedDebugAppend('no-write-forget', [entry(2)], 1_000) + const before = await lastMarkerDrops('no-write-forget') + ;(forgetFeedDebugSession as (id: string, options?: { persistUnmarkedDrops?: boolean }) => void)('no-write-forget', { persistUnmarkedDrops: false }) + await queueFeedDebugAppend('no-write-forget', [], 1_000) + await new Promise(resolve => setTimeout(resolve, 20)) + expect(await lastMarkerDrops('no-write-forget')).toBe(before) + }) + it('after a forget during the first size check', async () => { await cappedFileWithMarker('capped-during-stat', 1_000) let release!: () => void diff --git a/src/main/storage/feedDebugLog.ts b/src/main/storage/feedDebugLog.ts index dd978bb9a..1160eed26 100644 --- a/src/main/storage/feedDebugLog.ts +++ b/src/main/storage/feedDebugLog.ts @@ -564,7 +564,15 @@ function flushUnmarkedDrops(sessionId: string, capState: FeedDebugCapState | und }) } -export function forgetFeedDebugSession(sessionId: string): void { +export function forgetFeedDebugSession( + sessionId: string, + /** `persistUnmarkedDrops: false` when the caller's user has persistence + * switched OFF (#1392 review c, round 2): the final drop marker is a disk + * write, and "off" means none. Those unmarked drop counts are then lost, + * which is what switching persistence off asks for. Defaults to true, the + * process-exit forget's behaviour. */ + options: { persistUnmarkedDrops?: boolean } = {}, +): void { // We never delete `feedDebugWriteQueues` synchronously here — // there might be an in-flight write that still owns the chain. // The settle-time reaper in queueFeedDebugAppend handles the queue @@ -579,6 +587,6 @@ export function forgetFeedDebugSession(sessionId: string): void { // in this process, we'll re-stat the on-disk file and prime a fresh counter; // never carrying stale cap state across "session forgotten" boundaries keeps // the map from growing unbounded across long-lived main processes. - flushUnmarkedDrops(sessionId, feedDebugCapState.get(sessionId)) + if (options.persistUnmarkedDrops !== false) flushUnmarkedDrops(sessionId, feedDebugCapState.get(sessionId)) feedDebugCapState.delete(sessionId) } diff --git a/src/preload/api/debug.ts b/src/preload/api/debug.ts index ced81ef05..db9cb07d1 100644 --- a/src/preload/api/debug.ts +++ b/src/preload/api/debug.ts @@ -31,7 +31,7 @@ export const debugApi = { /** Release main's per-session feed-debug state for a pane that is gone * (#1392). Sent once, after the renderer's last possible append. */ - forgetFeedDebugLog: (params: { sessionId: string }): Promise => + forgetFeedDebugLog: (params: { sessionId: string; persistUnmarkedDrops: boolean }): Promise => ipcRenderer.invoke('debug:forget-feed-log', params), saveDebugBundle: (params: SaveDebugBundleParams): Promise => diff --git a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx index 64443b901..98fedd953 100644 --- a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx +++ b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.renderer.test.tsx @@ -296,7 +296,7 @@ describe('releasing a session whose runtime is gone (#1392)', () => { // Pane `a` closes: its runtime is removed. refs.latestRuntimesRef.current = { b: refs.latestRuntimesRef.current.b! } await advance(1_000) - expect(forget).toHaveBeenCalledExactlyOnceWith({ sessionId: 'a' }) + expect(forget).toHaveBeenCalledExactlyOnceWith({ sessionId: 'a', persistUnmarkedDrops: true }) expect(refs.persistedFeedDebugIdRef.current).not.toHaveProperty('a') expect(refs.persistedFeedDebugIdRef.current.b).toBe(1) @@ -388,7 +388,9 @@ describe('releasing a session whose runtime is gone (#1392)', () => { act(() => { useDevDebugConfig.setState({ enabled: false, sessionRecordingEnabled: false }) }) refs.latestRuntimesRef.current = {} await advance(2_000) - expect(forget).toHaveBeenCalledExactlyOnceWith({ sessionId: 'a' }) + // Review c, round 2: an off-state release must not make main write the + // final drop marker. + expect(forget).toHaveBeenCalledExactlyOnceWith({ sessionId: 'a', persistUnmarkedDrops: false }) expect(append).toHaveBeenCalledTimes(1) }) @@ -403,7 +405,7 @@ describe('releasing a session whose runtime is gone (#1392)', () => { forget.mockResolvedValue(undefined) act(() => { useDevDebugConfig.setState({ enabled: true, sessionRecordingEnabled: false }) }) await advance(2_000) - expect(forget.mock.calls.at(-1)).toEqual([{ sessionId: 'a' }]) + expect(forget.mock.calls.at(-1)).toEqual([{ sessionId: 'a', persistUnmarkedDrops: true }]) }) it('does not forget a session that never had a runtime while mounted', async () => { diff --git a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts index 61c7b057b..14e56b016 100644 --- a/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts +++ b/src/renderer/src/workspace/hook/persistence/useFeedDebugPersist.ts @@ -188,10 +188,11 @@ export function useFeedDebugPersist(refs: WorkspaceRefs): void { // the ACK then leaves the id in `known`, and the next absence sends a new // release. // - // Releasing keeps running while persistence is OFF (#767): it writes - // nothing to disk, it only tells main to forget, and a session that + // Releasing keeps running while persistence is OFF (#767): a session that // appended while persistence was on still has state in main after the - // user switches persistence off (#1392 review c). + // user switches persistence off (#1392 review c). The release then tells + // main not to persist unmarked drops, so it causes no disk write either + // (review c, round 2). // // Known residual: a release that fails during the hook's own teardown // (workspace unmount) has no later tick to retry it. Main keeps that one @@ -209,7 +210,9 @@ export function useFeedDebugPersist(refs: WorkspaceRefs): void { // the method) becomes a rejection, retried like any failed release, // instead of escaping the interval with `releasing` held. void Promise.resolve() - .then(() => window.api.forgetFeedDebugLog({ sessionId })) + // Off means no disk writes, including main's final drop marker + // (#1392 review c, round 2); read at send time, not effect time. + .then(() => window.api.forgetFeedDebugLog({ sessionId, persistUnmarkedDrops: enabledRef.current })) .then(() => { if (!seenSinceRelease.has(sessionId)) known.delete(sessionId) }, () => {}) .finally(() => releasing.delete(sessionId)) } From 5b030704f52d4e965891b4b8c76d8e8d955c99aa Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 06:31:38 -0700 Subject: [PATCH 38/40] test(composer): pin non-image items, null clipboard and the Claude take (#1426 review c) Co-Authored-By: Claude Opus 5.5 --- ...-09-27-image-paste-unsupported-provider.md | 3 +- .../useClaudeImagePaste.renderer.test.tsx | 29 +++++++++++++++---- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/docs/plans/2026-09-27-image-paste-unsupported-provider.md b/docs/plans/2026-09-27-image-paste-unsupported-provider.md index 93e9b5615..64a9b5364 100644 --- a/docs/plans/2026-09-27-image-paste-unsupported-provider.md +++ b/docs/plans/2026-09-27-image-paste-unsupported-provider.md @@ -18,7 +18,7 @@ New `useClaudeImagePaste.renderer.test.tsx` renders the real hook, with a real P - Codex, image only: the toast shows. Red on main. - Codex, image plus text: no toast (the text pastes). - Codex, text only: no toast. -- Claude, image only: no such toast (the image is taken). +- Claude, image only: no such toast, and the image is taken (`handledImages: true`, draft images set). ## Out of scope - #1250's other rows. @@ -32,3 +32,4 @@ New `useClaudeImagePaste.renderer.test.tsx` renders the real hook, with a real P - **a1 (terminal view): declined.** There the paste goes to the provider's own TUI, which owns image handling (Grok's attaches images); the app's capability flag is about its composer. - **a4: every provider's wording is tested** (Codex, OpenCode, Grok, Pi). - `parseImagesFromHtml` uses `querySelectorAll('img')` instead of `doc.images`. It is identical in a browser, and the happy-dom test DOM lacks `images` on a parsed document. +- **c (MERGE-READY, reviewing the round-0 head; test gaps pinned):** a non-image file, a type-less file, a string item typed `image/*`, and a null `clipboardData` stay silent. The Claude case asserts the image is taken. The provider label is covered by the per-provider cases. diff --git a/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.renderer.test.tsx b/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.renderer.test.tsx index 09a28aa1d..47507da93 100644 --- a/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.renderer.test.tsx +++ b/src/renderer/src/workspace/tile-tree/TileLeaf/useClaudeImagePaste.renderer.test.tsx @@ -27,8 +27,8 @@ afterEach(() => { else Reflect.deleteProperty(navigator, 'clipboard') }) -function paste(options: { image?: boolean; text?: string; html?: string }) { - const items = options.image ? [{ kind: 'file', type: png.type, getAsFile: () => png }] : [] +function paste(options: { image?: boolean; text?: string; html?: string; items?: Array<{ kind: string; type: string }> }) { + const items = options.items ?? (options.image ? [{ kind: 'file', type: png.type, getAsFile: () => png }] : []) return { clipboardData: { items, @@ -40,8 +40,9 @@ function paste(options: { image?: boolean; text?: string; html?: string }) { function hook(provider: 'codex' | 'opencode' | 'grok' | 'pi' | 'claude') { const showToast = vi.fn() - const { result } = renderHook(() => useClaudeImagePaste({ provider, sessionId: 's1' as never, setDraftImages: vi.fn(), showToast })) - return { handlePaste: result.current.handlePaste, showToast } + const setDraftImages = vi.fn() + const { result } = renderHook(() => useClaudeImagePaste({ provider, sessionId: 's1' as never, setDraftImages, showToast })) + return { handlePaste: result.current.handlePaste, showToast, setDraftImages } } describe('pasting an image into a composer that cannot take one', () => { @@ -93,8 +94,24 @@ describe('pasting an image into a composer that cannot take one', () => { }) it('does not say it for Claude, which takes the image', async () => { - const { handlePaste, showToast } = hook('claude') - await act(async () => { await handlePaste(paste({ image: true })) }) + const { handlePaste, showToast, setDraftImages } = hook('claude') + let answer: unknown + await act(async () => { answer = await handlePaste(paste({ image: true })) }) expect(showToast).not.toHaveBeenCalledWith(expect.stringContaining("can't be sent")) + // Taken, not just unmentioned (#1426 review c). + expect(answer).toEqual({ handledImages: true }) + expect(setDraftImages).toHaveBeenCalled() + }) + + // #1426 review c: only an IMAGE FILE counts. A PDF, a type-less Finder file, + // or a string item that happens to say image/* is not an image paste, and a + // missing clipboardData says nothing. + it('stays silent for a non-image file, a string item, and no clipboard data', async () => { + const { handlePaste, showToast } = hook('codex') + await act(async () => { await handlePaste(paste({ items: [{ kind: 'file', type: 'application/pdf' }] })) }) + await act(async () => { await handlePaste(paste({ items: [{ kind: 'file', type: '' }] })) }) + await act(async () => { await handlePaste(paste({ items: [{ kind: 'string', type: 'image/png' }] })) }) + await act(async () => { await handlePaste({ clipboardData: null, preventDefault: vi.fn() }) }) + expect(showToast).not.toHaveBeenCalled() }) }) From c32d4baefc10f21bafadf2f9c821015e43239b5f Mon Sep 17 00:00:00 2001 From: Julius Olsson Date: Sun, 27 Sep 2026 06:34:19 -0700 Subject: [PATCH 39/40] fix(composer): paste-to-focus hands an empty paste to the image handler (#1426 verification a) Co-Authored-By: Claude Opus 5.5 --- ...-09-27-image-paste-unsupported-provider.md | 1 + ...ePasteToFocus.asyncImage.renderer.test.tsx | 37 +++++++++++++++++++ .../tile-tree/TileLeaf/usePasteToFocus.ts | 10 +++++ 3 files changed, 48 insertions(+) create mode 100644 src/renderer/src/workspace/tile-tree/TileLeaf/usePasteToFocus.asyncImage.renderer.test.tsx diff --git a/docs/plans/2026-09-27-image-paste-unsupported-provider.md b/docs/plans/2026-09-27-image-paste-unsupported-provider.md index 64a9b5364..d00945770 100644 --- a/docs/plans/2026-09-27-image-paste-unsupported-provider.md +++ b/docs/plans/2026-09-27-image-paste-unsupported-provider.md @@ -33,3 +33,4 @@ New `useClaudeImagePaste.renderer.test.tsx` renders the real hook, with a real P - **a4: every provider's wording is tested** (Codex, OpenCode, Grok, Pi). - `parseImagesFromHtml` uses `querySelectorAll('img')` instead of `doc.images`. It is identical in a browser, and the happy-dom test DOM lacks `images` on a parsed document. - **c (MERGE-READY, reviewing the round-0 head; test gaps pinned):** a non-image file, a type-less file, a string item typed `image/*`, and a null `clipboardData` stay silent. The Claude case asserts the image is taken. The provider label is covered by the per-provider cases. +- **Verification a (Major): an async-only image via paste-to-focus stayed silent.** That path decided "no image" synchronously and appended empty text. An EMPTY event (no text, no HTML, no items) now goes to the shared handler, which probes it; this also lets Claude attach such an image. Ordinary text never takes the branch, so it is never delayed. Test red on the previous head. diff --git a/src/renderer/src/workspace/tile-tree/TileLeaf/usePasteToFocus.asyncImage.renderer.test.tsx b/src/renderer/src/workspace/tile-tree/TileLeaf/usePasteToFocus.asyncImage.renderer.test.tsx new file mode 100644 index 000000000..0b9c73a62 --- /dev/null +++ b/src/renderer/src/workspace/tile-tree/TileLeaf/usePasteToFocus.asyncImage.renderer.test.tsx @@ -0,0 +1,37 @@ +import { fireEvent, render } from '@testing-library/react' +import { useRef } from 'react' +import { afterEach, describe, expect, it, vi } from 'vitest' + +import { usePasteToFocus } from './usePasteToFocus' + +// #1426 verification a: a paste landing outside the composer (paste-to-focus) +// whose image only the async clipboard API shows arrives as an EMPTY event: +// no text, no HTML, no items. It never reached the shared image handler, so +// nothing was said (and Claude never attached it). It now does; ordinary text +// still appends synchronously and never calls the handler. + +function Harness({ handlePaste }: { handlePaste: Parameters[0]['handlePaste'] }) { + const inputRef = useRef(null) + usePasteToFocus({ focused: true, sessionId: 's1' as never, inputRef, setDraftInput: vi.fn(), handlePaste }) + return