Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

e2e: a step is typed once when the tool wraps its prompt (#1442)

lingrd3b6e42ba86c1
diff --git a/cli/src/e2e/e2e.spec.ts b/cli/src/e2e/e2e.spec.ts
index c670046db..c62a5ff31 100644
--- a/cli/src/e2e/e2e.spec.ts
+++ b/cli/src/e2e/e2e.spec.ts
@@ -10,7 +10,7 @@ import { pickGridModel } from './gridSwitchDriver.js'
import { prepareWorkspace, readLog, logPath, readWorkspaceFile, preAcceptClaudeBypassMode, CALC_MCP_MJS } from './workspace.js'
import { toolResult, useByRef } from './sessionTools.js'
import { execFileSync } from 'node:child_process'
-import { probeLeg, runCheck, dismissStartupDialogs, STARTUP_DIALOGS, type Tmux } from './paneProbe.js'
+import { findRef, probeLeg, runCheck, dismissStartupDialogs, STARTUP_DIALOGS, type Tmux } from './paneProbe.js'
import { mkdtempSync, mkdirSync, readFileSync, writeFileSync, chmodSync, existsSync, rmSync } from 'node:fs'
import { join } from 'node:path'
import { tmpdir } from 'node:os'
@@ -326,6 +326,35 @@ describe('pane probe (live steps on a tmux pane)', () => {
expect([...own.checks, ...grid.checks].every((c) => /^ref-[0-9a-z]{6}$/.test(c.ref ?? ''))).toBe(true)
})
+ // grid-dev, 2026-10-20: codex's TUI wraps a long prompt, so its `(ref-…)` tag reached the screen in two
+ // pieces; the probe took it for dropped and typed every write step three times, and the third ran into
+ // the next step's prompt on the grid leg (edit=stuck).
+ it('types a step once when the tool wraps its prompt across lines', async () => {
+ const { pane, probe, files } = fakeAgent()
+ // At 72 columns the tag of this step's prompt (from column 69) is cut in two, as on grid-dev's screen.
+ const wrap = (text: string) => text.split('\n').map((line) => line.match(/.{1,72}/g)?.join('\n ') ?? line).join('\n')
+ const wrapped: Tmux = { ...pane, capture: async (p, lines) => wrap(await pane.capture(p, lines)) }
+ const write = SCENARIO.subscription[1]
+ const out = await runCheck(wrapped, '%1', write, probe)
+ expect(out.status).toBe('ok')
+ expect(pane.typed.filter((t) => t.startsWith(write.prompt))).toHaveLength(1)
+ expect(files['out/hello-1.txt']).toBe('hello from step 1\n')
+ })
+
+ it('finds a tag cut by a wrap inside a bordered box, and only its own', () => {
+ const ref = 'ref-2uj4gc'
+ // A plain indent (codex), a side border before and after the break, and a quote/prompt lead.
+ for (const screen of [`… (ref-2u\n j4gc)`, `… (ref-2u │\n│ j4gc)`, `… (ref-2u│\n│j4gc)`, `… (ref-2u\n› j4gc)`]) {
+ expect(findRef(screen, ref), JSON.stringify(screen)).not.toBeNull()
+ }
+ // Text between the pieces is not a wrap; nor is another tag.
+ expect(findRef('… (ref-2u x\nj4gc)', ref)).toBeNull()
+ expect(findRef('(ref-2uj4gd)', ref)).toBeNull()
+ // The last echo is the one an answer is read after.
+ const screen = `(ref-2uj4gc) first\n(ref-2u\n j4gc) second`
+ expect(screen.slice(findRef(screen, ref)![1])).toBe(') second')
+ })
+
it('saying is not doing: each step fails when the tool only claims it, with what was missing', async () => {
const notes: Record<CheckId, RegExp> = {
read: /notes\/info-1\.txt's token never appeared/,
diff --git a/cli/src/e2e/paneProbe.ts b/cli/src/e2e/paneProbe.ts
index e68f70322..2f1bc4ff1 100644
--- a/cli/src/e2e/paneProbe.ts
+++ b/cli/src/e2e/paneProbe.ts
@@ -196,6 +196,22 @@ export async function waitForPaneSettle(tmux: Tmux, pane: string, opts: ProbeOpt
return false
}
+/**
+ * Where [ref] last is on [screen], as `[start, end)`, or null. A tool's TUI wraps a long prompt itself,
+ * indenting what follows, so the tag can reach the screen cut in two (`(ref-2u` / ` j4gc)`): it is
+ * matched with a line break allowed between any two of its characters, with a box's side border and
+ * padding on either side of the break and a prompt lead after it. Searched as one string, a wrapped tag
+ * looked dropped, and every write step was typed three times (grid-dev, 2026-10-20).
+ */
+export function findRef(screen: string, ref: string): [number, number] | null {
+ // The tag is [a-z0-9-]: only `-` needs escaping, and only outside a character class.
+ const wrap = '(?:[ \\t│┃|]*\\r?\\n[ \\t│┃|>›]*)?'
+ const pattern = new RegExp(ref.split('').map((c) => (c === '-' ? '\\-' : c)).join(wrap), 'g')
+ let last: [number, number] | null = null
+ for (const m of screen.matchAll(pattern)) last = [m.index, m.index + m[0].length]
+ return last
+}
+
/** A short tag typed after the prompt so THIS check's echo can be told from earlier ones. */
export function checkRef(now: number): string {
return `ref-${now.toString(36).slice(-4).padStart(4, '0')}${Math.floor(Math.random() * 1296).toString(36).padStart(2, '0')}`
@@ -208,7 +224,7 @@ export function checkRef(now: number): string {
* wrong: a resume redraws the whole transcript, so the previous leg's answer is on screen again,
* and as the new turn scrolls the old one out the count stays flat — a real `ANSWER_42` on the
* back-home leg was recorded as stuck (measured, codex 0.155.1). The tag pins the search to the
- * new turn instead; a wrapped tag (never echoed in one piece) falls back to "one more hit than before".
+ * new turn instead, found even when the tool wrapped it across lines (findRef).
*/
export async function runCheck(tmux: Tmux, pane: string, check: SmokeCheck, opts: ProbeOptions = {}): Promise<CheckOutcome> {
const o = { ...DEFAULTS, ...opts }
@@ -230,7 +246,7 @@ export async function runCheck(tmux: Tmux, pane: string, check: SmokeCheck, opts
let landed = false
for (let waited = 0; waited < 5_000 && !landed; waited += o.pollMs) {
await tmux.sleep(o.pollMs)
- landed = (await tmux.capture(pane, o.tailLines)).includes(ref)
+ landed = findRef(await tmux.capture(pane, o.tailLines), ref) !== null
}
if (landed) break
await tmux.type(pane, `${check.prompt} (${ref})`)
@@ -263,8 +279,8 @@ export async function runCheck(tmux: Tmux, pane: string, check: SmokeCheck, opts
while (tmux.now() - start < o.checkTimeoutMs) {
await tmux.sleep(o.pollMs)
tail = await tmux.capture(pane, o.tailLines)
- const echo = tail.lastIndexOf(ref)
- const afterEcho = echo >= 0 ? tail.slice(echo + ref.length) : null
+ const echo = findRef(tail, ref)
+ const afterEcho = echo ? tail.slice(echo[1]) : null
// A modal can land in the middle of a turn (claude's gateway notice); answer it and keep waiting.
// Only one that appeared after THIS prompt: startup screens answered before it stay in the
// scrollback, and answering them again would send their keys into the running turn.