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.

harnessd: hn's terminal_info is answered; a full desk end to end (#762)

Dee718337837d50
diff --git a/cli/e2e/compat.e2e.ts b/cli/e2e/compat.e2e.ts
index c43747723..c41671664 100644
--- a/cli/e2e/compat.e2e.ts
+++ b/cli/e2e/compat.e2e.ts
@@ -30,7 +30,14 @@ const FROM = process.env.COMPAT_FROM
* Differences on purpose, by the path that differs (a prefix covers everything under it), each with
* why. Keep this honest: a difference nobody can explain is a regression until shown otherwise.
*/
-const CHANGED: Record<string, string> = {}
+const CHANGED: Record<string, string> = {
+ // The terminal streams passed `terminal_info` over and nothing answered it, so hn waited out its
+ // three seconds each time. It is answered now: what the pane runs and where, or why not.
+ 'terminal_info claude': 'answered now; the released build left it unanswered',
+ 'terminal_info codex': 'answered now; the released build left it unanswered',
+ 'terminal_info with nothing': 'answered now; the released build left it unanswered',
+ 'terminal_info for no such agent': 'answered now; the released build left it unanswered',
+}
type Engine = 'claude' | 'codex'
type Answers = Record<string, unknown>
@@ -152,12 +159,12 @@ async function scenario(d: IsolatedDaemon): Promise<Answers> {
const from = client.frames.length
const asked = client.next((frame) => frame.type === 'commander_question' && frame.agentId === agent[engine], 30_000, `${step} (${engine})`)
client.send('message', { agentId: agent[engine], content })
- const question = await asked
- const shaped = question.payload?.questions?.[0]
- answers[`${step} on ${engine}`] = walk(question.payload)
+ const question = (await asked).payload ?? {}
+ const shaped = question.questions?.[0]
+ answers[`${step} on ${engine}`] = walk(question)
const ended = client.next((frame) => frame.type === 'turn_ended' && frame.agentId === agent[engine], 60_000, `turn_ended after ${step}`)
- const replied = client.next((frame) => frame.type === 'question_response_result' && frame.payload?.requestId === question.payload.requestId, 45_000, `${step} answered`)
- client.send('question_response', { requestId: question.payload.requestId, agentId: agent[engine], answers: { [shaped.q]: typeof pick === 'number' ? shaped.options[pick] : pick } })
+ const replied = client.next((frame) => frame.type === 'question_response_result' && frame.payload?.requestId === question.requestId, 45_000, `${step} answered`)
+ client.send('question_response', { requestId: question.requestId, agentId: agent[engine], answers: { [shaped.q]: typeof pick === 'number' ? shaped.options[pick] : pick } })
answers[`${step} answered on ${engine}`] = walk((await replied).payload)
await ended
await new Promise((done) => setTimeout(done, 1_000))
@@ -284,7 +291,11 @@ describe.skipIf(!FROM)('what the apps see, compared with the released build', ()
const released = sides.released!
const current = sides.this!
const found = differences(released.answers, current.answers)
- const explained = (path: string) => Object.keys(CHANGED).find((prefix) => path === prefix || path.startsWith(`${prefix}.`) || path.startsWith(`${prefix}[`))
+ // Paths read `.<step>.<field>…`; a CHANGED entry names a step, or a path under one.
+ const explained = (path: string) => Object.keys(CHANGED).find((prefix) => {
+ const step = `.${prefix}`
+ return path === step || path.startsWith(`${step}.`) || path.startsWith(`${step}[`)
+ })
const added = found.filter((difference) => difference.from === undefined)
const unexplained = found.filter((difference) => difference.from !== undefined && !explained(difference.path))
if (process.env.COMPAT_REPORT) {
diff --git a/cli/e2e/scale.e2e.ts b/cli/e2e/scale.e2e.ts
new file mode 100644
index 000000000..187f0cb8e
--- /dev/null
+++ b/cli/e2e/scale.e2e.ts
@@ -0,0 +1,101 @@
+/**
+ * A full desk, for Claude Code and Codex together, on the real daemon: many agents created at once, a
+ * turn each in parallel, then a daemon restart that brings every one of them back with its
+ * conversation, and a turn each again. What it checks is what a crowded machine notices first: the
+ * core holds, every turn reaches the window, the restart's attaches finish in bounded time, and the
+ * core's memory stays bounded by the work rather than growing with the desk.
+ *
+ * `SCALE_AGENTS` sets the size, 24 by default. The design's own bar is 50 panes:
+ * `SCALE_AGENTS=50 npm run test:e2e -- scale`. Each agent is a fake engine process and a tmux pane, so
+ * 50 needs a few GB of memory free.
+ */
+import { mkdirSync, writeFileSync } from 'node:fs'
+import { join } from 'node:path'
+import { afterEach, describe, expect, it, onTestFailed } from 'vitest'
+import { LocalClient, type Frame } from './harness/client.js'
+import { IsolatedDaemon, until } from './harness/daemon.js'
+
+const AGENTS = Number(process.env.SCALE_AGENTS ?? 24)
+
+type Row = Record<string, any>
+const rows = async (client: LocalClient): Promise<Row[]> =>
+ (await client.request<{ agents: Row[] }>('agents_list', { includeStopped: true }, 60_000)).agents
+const isTurn = (type: string, agentId: string) => (frame: Frame) => frame.type === type && frame.agentId === agentId
+async function turn(client: LocalClient, agentId: string, content: string): Promise<void> {
+ const started = client.next(isTurn('turn_started', agentId), 120_000, `turn_started (${content})`)
+ const ended = client.next(isTurn('turn_ended', agentId), 120_000, `turn_ended (${content})`)
+ client.send('message', { agentId, content })
+ expect((await started).payload?.userMessage).toBe(content)
+ await ended
+}
+/** The lowest of a few samples: what the process holds, not a moment's garbage before a collection. */
+async function settledRss(daemon: IsolatedDaemon): Promise<number> {
+ const samples: number[] = []
+ for (let i = 0; i < 5; i++) { samples.push(await daemon.rssMiB()); await new Promise((resolve) => setTimeout(resolve, 1_000)) }
+ return Math.min(...samples)
+}
+
+describe('a full desk', () => {
+ let daemon: IsolatedDaemon | undefined
+ afterEach(async () => { await daemon?.close(); daemon = undefined })
+
+ it(`${AGENTS} agents, half Claude Code and half Codex: created together, a turn each, through a restart, and back`, async () => {
+ const d = await IsolatedDaemon.create()
+ daemon = d
+ onTestFailed(() => { console.log(`---- daemon log\n${d.log().split('\n').slice(-150).join('\n')}`) })
+ await d.start()
+ let client = await LocalClient.connect(d)
+ const rssEmpty = await settledRss(d)
+
+ // Created together, as a restored desk or a script making a team does.
+ const engines = Array.from({ length: AGENTS }, (_, i) => (i % 2 ? 'codex' : 'claude') as 'claude' | 'codex')
+ const created = await Promise.all(engines.map(async (engine, i) => {
+ const cwd = join(d.projectsDir, `desk-${i}`)
+ mkdirSync(cwd, { recursive: true })
+ const answer = await client.request('agent_create', { engine, cwd, bypassPermission: true }, 180_000)
+ expect(answer.error, `agent ${i}: ${JSON.stringify(answer)}`).toBeUndefined()
+ return answer.agent.id as string
+ }))
+ const bound = await until(`all ${AGENTS} agents to bind`, async () => {
+ const now = await rows(client)
+ const ready = created.map((id) => now.find((row) => row.id === id)).filter((row): row is Row => !!row?.sessionId && row.status === 'active')
+ return ready.length === AGENTS ? ready : null
+ }, 240_000, 1_000)
+ const sessions = new Map(bound.map((row) => [row.id as string, row.sessionId as string]))
+
+ // A turn each, all at once: every one reaches the window as itself.
+ await Promise.all(created.map((id, i) => turn(client, id, `desk turn ${i}`)))
+ client.frames.splice(0, client.frames.length)
+ const rssWorking = await settledRss(d)
+
+ // A restart: every agent comes back with its conversation, in bounded time.
+ client.close()
+ const restartedAt = Date.now()
+ await d.restart()
+ client = await LocalClient.connect(d)
+ await until(`all ${AGENTS} agents back after the restart`, async () => {
+ const now = await rows(client)
+ const back = created.filter((id) => {
+ const row = now.find((one) => one.id === id)
+ return row?.status === 'active' && row.sessionId === sessions.get(id)
+ })
+ return back.length === AGENTS || null
+ }, 240_000, 1_000)
+ const backInMs = Date.now() - restartedAt
+
+ // And they work: a turn each again, all at once.
+ await Promise.all(created.map((id, i) => turn(client, id, `after the restart ${i}`)))
+ client.frames.splice(0, client.frames.length)
+ const rssAfter = await settledRss(d)
+
+ const report = `${AGENTS} agents · rss empty ${rssEmpty.toFixed(0)} → working ${rssWorking.toFixed(0)} → after the restart ${rssAfter.toFixed(0)} MiB · back in ${(backInMs / 1000).toFixed(1)} s`
+ if (process.env.SCALE_REPORT) writeFileSync(process.env.SCALE_REPORT, `${report}\n`)
+ // Bounded by the work, not the desk: a few MiB an agent at most, measured from an empty core.
+ expect(rssWorking - rssEmpty, report).toBeLessThan(64 + AGENTS * 6)
+ expect(rssAfter - rssEmpty, report).toBeLessThan(64 + AGENTS * 6)
+ // Every attach after the restart is bounded: back well inside the master's start-up deadline.
+ expect(backInMs, report).toBeLessThan(120_000)
+ expect(d.coresStarted()).toBe(2)
+ client.close()
+ }, 900_000)
+})
diff --git a/cli/e2e/soak.e2e.ts b/cli/e2e/soak.e2e.ts
index 75945c80f..11fd9bfdc 100644
--- a/cli/e2e/soak.e2e.ts
+++ b/cli/e2e/soak.e2e.ts
@@ -72,5 +72,6 @@ describe('a desk of agents working', () => {
expect(filesAfter - filesBefore, report).toBeLessThan(16)
expect(d.coresStarted()).toBe(1)
client.close()
- })
+ // A round takes a second or two; the suite's own limit fits only the default 40.
+ }, 120_000 + ROUNDS * 3_000)
})
diff --git a/cli/e2e/terminal.e2e.ts b/cli/e2e/terminal.e2e.ts
index 7c8739f55..5466c96a6 100644
--- a/cli/e2e/terminal.e2e.ts
+++ b/cli/e2e/terminal.e2e.ts
@@ -4,7 +4,7 @@
* reflows it; one window takes a terminal from another, or watches it without taking it; a window that
* goes, closes, freezes or floods its terminal costs only that stream, never the agent or the daemon.
*/
-import { mkdirSync } from 'node:fs'
+import { mkdirSync, realpathSync } from 'node:fs'
import { join } from 'node:path'
import { afterEach, describe, expect, it, onTestFailed } from 'vitest'
import { TerminalBinaryKind, type TerminalBinaryClear } from '../src/lib/terminalBinary.js'
@@ -160,6 +160,20 @@ describe('the terminal', () => {
client.close()
})
+ it.each(engines)('%s: asked what its pane runs and where (terminal_info, as hn asks), it says, from tmux', async (engine) => {
+ const d = await fresh()
+ const client = await LocalClient.connect(d)
+ const agent = await create(d, client, engine, `info-${engine}`)
+ const info = await client.request('terminal_info', { agentId: agent.id }, 10_000)
+ expect(info.error, JSON.stringify(info)).toBeUndefined()
+ expect(realpathSync(info.path)).toBe(realpathSync(join(d.projectsDir, `info-${engine}`)))
+ expect(Number.isSafeInteger(info.pid)).toBe(true)
+ expect(info.tty).toMatch(/^\/dev\//)
+ expect(typeof info.command).toBe('string')
+ expect(await client.request('terminal_info', { agentId: 'no-such-agent' }, 10_000)).toMatchObject({ error: 'AGENT_NOT_FOUND' })
+ client.close()
+ })
+
it.each(engines)('%s: keystrokes out of order type nothing and say which one was expected; JSON keystrokes are refused', async (engine) => {
const d = await fresh()
const client = await LocalClient.connect(d)
diff --git a/cli/src/backendSocket.spec.ts b/cli/src/backendSocket.spec.ts
index 3861584fe..8135cfe3e 100644
--- a/cli/src/backendSocket.spec.ts
+++ b/cli/src/backendSocket.spec.ts
@@ -872,6 +872,25 @@ describe('BackendSocket outbound queue', () => {
await socket.stop()
})
+ it('answers terminal_info, which the terminal streams pass over, and leaves every other terminal frame to them', async () => {
+ const socket = new BackendSocket('token')
+ // As in the daemon: a stream manager that takes its own frames and passes over the rest.
+ const handleFrame = vi.fn(async (_connId: string, type: string) => type !== 'terminal_info' && type !== 'terminal_unknown')
+ socket.setTerminalStreamManager({ handleFrame, closeConnection: vi.fn(async () => {}), stop: vi.fn(async () => {}) } as unknown as TerminalStreamManager)
+ const frames: Array<Record<string, unknown>> = []
+ socket.registerLocalClient('local:hn', { sendFrame: (frame) => { frames.push(frame as Record<string, unknown>); return true }, sendBinary: () => true })
+ socket.handleLocalFrame('local:hn', { type: 'terminal_info', payload: { requestId: 'i-1', agentId: 'no-such-agent' } })
+ await vi.waitFor(() => expect(frames).toContainEqual({ type: 'terminal_info_result', payload: { requestId: 'i-1', error: 'AGENT_NOT_FOUND' } }))
+ expect(handleFrame).toHaveBeenCalledWith('local:hn', 'terminal_info', expect.objectContaining({ agentId: 'no-such-agent' }))
+ // A terminal frame the streams take, or one nobody knows, is not answered here.
+ socket.handleLocalFrame('local:hn', { type: 'terminal_resize', payload: { requestId: 'r-1', streamId: 's' } })
+ socket.handleLocalFrame('local:hn', { type: 'terminal_unknown', payload: { requestId: 'u-1' } })
+ await vi.waitFor(() => expect(handleFrame).toHaveBeenCalledTimes(3))
+ await new Promise((resolve) => setTimeout(resolve, 50))
+ expect(frames.filter((frame) => frame.type !== 'terminal_info_result')).toEqual([])
+ await socket.stop()
+ })
+
it('hands theme_set to the host-theme sink and acknowledges it to the requester', async () => {
const socket = new BackendSocket('token')
const received: unknown[] = []
diff --git a/cli/src/backendSocket.ts b/cli/src/backendSocket.ts
index 50f7d816b..9156072ea 100644
--- a/cli/src/backendSocket.ts
+++ b/cli/src/backendSocket.ts
@@ -2045,8 +2045,11 @@ export class BackendSocket {
if (type.startsWith('terminal_')) {
this.noteTerminalInputRoute(connId, type, payload, transport)
- if (this.terminalStreams) await this.terminalStreams.handleFrame(connId, type, payload)
- return
+ const taken = this.terminalStreams ? await this.terminalStreams.handleFrame(connId, type, payload) : false
+ // `terminal_info` (what a pane runs and where, which hn asks) is not a stream's: the streams pass
+ // it over, and it is answered below. From hn's first release it stopped here unanswered
+ // (e2e/compat.e2e.ts found it), and hn waited out its three seconds each time.
+ if (taken || type !== 'terminal_info') return
}
// A request a service answers, in its own process or in this one: routed to it, or answered
diff --git a/docs/design/2026-10-03-harnessd.md b/docs/design/2026-10-03-harnessd.md
index 1eccb344a..8b0bd561c 100644
--- a/docs/design/2026-10-03-harnessd.md
+++ b/docs/design/2026-10-03-harnessd.md
@@ -722,8 +722,11 @@ Found while mapping, and fixed on their own rather than inside a move:
- where an agent worked is read at most every 15 s;
- how far a launch has got when `agent_create` replies is a race with the engine starting.
- One finding: the switch's `terminal_info` case can never run, because every `terminal_*` frame
- goes to the terminal streams first. Neither build answers it.
+ One finding, fixed since: hn asks `terminal_info` (what a pane runs and where), and no build
+ has ever answered it. Every `terminal_*` frame went to the terminal streams, which pass
+ this one over, and the socket dropped it there instead of answering it, so hn waited out three
+ seconds each time. It is answered now (`e2e/terminal.e2e.ts`), and the comparison lists it as
+ changed on purpose.
- The sixteenth round (`e2e/ends.e2e.ts`), how an agent's life ends, for both engines:
- closed now, then opened again with its conversation;
- closed only when idle, which leaves a working agent working;