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.

Reduce concurrent terminal polling and reject stale question captures (#540)

Deebb0cf693a829
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 876f16648..72087c24c 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -144,6 +144,9 @@ jobs:
sudo apt-get update
sudo apt-get install -y tmux musl-tools
npm ci --prefix cli --no-audit --no-fund
+ - name: Real tmux question polling and answer routing
+ working-directory: cli
+ run: node --import tsx scripts/question-poll-native.ts "$RUNNER_TEMP/question-poll.json"
- name: Release unit tests
run: cargo test --locked --release
- name: Build static Linux binary
diff --git a/cli/scripts/question-poll-native.ts b/cli/scripts/question-poll-native.ts
new file mode 100644
index 000000000..3c109700e
--- /dev/null
+++ b/cli/scripts/question-poll-native.ts
@@ -0,0 +1,199 @@
+/** Real, private tmux reads and question/answer flow using recorded dialog paint.
+ * No provider, user profile, or existing tmux server is used. Also compares the
+ * old per-pane capture with batching; CPU is this Node process, not tmux or the
+ * whole app. Run from cli/: node --import tsx scripts/question-poll-native.ts /tmp/result.json
+ */
+import assert from 'node:assert/strict'
+import { execFile } from 'node:child_process'
+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join, resolve } from 'node:path'
+import { promisify } from 'node:util'
+import { AskQuestionController, QuestionWatcher, type ShapedQuestion } from '../src/lib/askQuestion.js'
+import { TmuxCaptureBatcher, tmuxCaptureArgs } from '../src/lib/tmuxCapture.js'
+import type { RegisteredSession } from '../src/lib/registry.js'
+
+const exec = promisify(execFile)
+const root = mkdtempSync(join(tmpdir(), 'harness-question-poll-'))
+const socket = join(root, 'tmux.sock')
+const env = { ...process.env }
+delete env.TMUX; delete env.TMUX_PANE
+const tmux = async (...args: string[]) => (await exec('tmux', ['-S', socket, ...args], { env, timeout: 5_000 })).stdout
+const wait = (ms: number) => new Promise<void>(resolve => setTimeout(resolve, ms))
+async function eventually(check: () => boolean | Promise<boolean>, label: string, timeout = 6_000): Promise<void> {
+ const deadline = Date.now() + timeout
+ while (Date.now() < deadline) { if (await check()) return; await wait(25) }
+ throw new Error(`Timed out: ${label}`)
+}
+
+let captureProcesses = 0
+const batcher = new TmuxCaptureBatcher((args, options, done) => {
+ captureProcesses++
+ execFile('tmux', ['-S', socket, ...args], { ...options, env }, done)
+})
+const directCapture = (pane: string, history = 60): Promise<string | null> => new Promise(resolve => {
+ captureProcesses++
+ execFile('tmux', ['-S', socket, ...tmuxCaptureArgs(pane, history)], { env, timeout: 2_000 },
+ (error, text) => resolve(error ? null : text))
+})
+const panes: string[] = []
+const sessions = new Map<string, RegisteredSession>()
+let watcher: QuestionWatcher | undefined
+const result: Record<string, unknown> = { recordedAt: new Date().toISOString(), node: process.version, platform: `${process.platform}-${process.arch}`,
+ scope: 'Private real tmux with recorded dialog paint. Node CPU excludes tmux clients/server; not whole-app energy.' }
+
+try {
+ result.tmux = (await exec('tmux', ['-V'])).stdout.trim()
+ const question = readFileSync(resolve('src/lib/__fixtures__/question-single.txt'), 'utf8')
+ const helper = join(root, 'dialog.py')
+ writeFileSync(helper, String.raw`import os, signal, sys, termios
+from pathlib import Path
+signal.alarm(180)
+attrs = termios.tcgetattr(0)
+attrs[3] &= ~(termios.ECHO | termios.ICANON)
+attrs[6][termios.VMIN] = 1
+attrs[6][termios.VTIME] = 0
+termios.tcsetattr(0, termios.TCSANOW, attrs)
+text = Path(sys.argv[1]).read_text()
+def paint(value):
+ sys.stdout.write('\x1b[2J\x1b[3J\x1b[H' + value); sys.stdout.flush()
+paint(text)
+while True:
+ char = os.read(0, 1)
+ if not char: break
+ if char in (b'1', b'2'): paint('Answered ' + char.decode() + '\n')
+ if char == b'q': paint(text)
+`)
+ for (let i = 0; i < 32; i++) {
+ const fixture = join(root, `question-${i}.txt`)
+ writeFileSync(fixture, question.replace('Which drink would you like?', `Which drink for pane ${i}?`))
+ const command = i < 2 ? ['python3', '-u', helper, fixture]
+ : ['/bin/sh', '-c', 'cat "$1"; exec /bin/sleep 180', 'fixture', fixture]
+ const pane = (await tmux('-f', '/dev/null', 'new-session', '-d', '-P', '-F', '#{pane_id}',
+ '-s', `question-${i}`, '-x', '100', '-y', '35', ...command)).trim()
+ assert.match(pane, /^%\d+$/)
+ panes.push(pane)
+ sessions.set(`s${i}`, { agentId: `s${i}`, sessionId: `s${i}`, engine: 'claude', active: true,
+ tmuxPane: pane, runtimes: [{ backend: 'tmux', paneId: pane }] } as RegisteredSession)
+ }
+ await eventually(async () => {
+ const captures = await Promise.all(panes.map(pane => batcher.capture(pane, 60)))
+ return captures.every((text, i) => text?.includes(`Which drink for pane ${i}?`))
+ }, 'all fixture panes are painted')
+ const capture = (target: string, lines?: number) => {
+ const pane = sessions.get(target)?.tmuxPane
+ return pane ? batcher.capture(pane, lines) : Promise.resolve(null)
+ }
+ const sendKey = async (target: string, key: string) => {
+ const pane = sessions.get(target)?.tmuxPane
+ if (!pane) return false
+ try { await tmux('send-keys', '-t', pane, key); return true } catch { return false }
+ }
+ const controller = new AskQuestionController({ getSession: id => sessions.get(id), capture,
+ sendKey, sendText: async () => { throw new Error('This fixture must not type free text') } })
+ const open = new Map<string, { requestId: string; questions: ShapedQuestion[] }>()
+ let announcements = 0
+ const gone: string[] = []
+ watcher = new QuestionWatcher({ getSession: id => sessions.get(id), capture, hasDevice: () => true,
+ isDriving: id => controller.isDriving(id),
+ onQuestion: (id, requestId, questions) => { announcements++; controller.remember(requestId, id); open.set(id, { requestId, questions }) },
+ onQuestionGone: id => { gone.push(id); open.delete(id) } })
+ captureProcesses = 0
+ const started = performance.now()
+ for (const id of sessions.keys()) watcher.start(id)
+ await eventually(() => open.size === 32, 'all questions announce on the first shared tick')
+ const firstTickMs = performance.now() - started
+ assert.equal(captureProcesses, 1, '32 first-tick question reads use one tmux process')
+ for (let i = 0; i < 32; i++) assert.equal(open.get(`s${i}`)?.questions[0].q, `Which drink for pane ${i}?`)
+ await wait(1_600)
+ assert.equal(announcements, 32, 'an unchanged question announces once')
+
+ const beforeAnswer = open.get('s0')!
+ const answered = await controller.answer({ sessionId: 's0', requestId: beforeAnswer.requestId,
+ answers: { [beforeAnswer.questions[0].key]: 'Coffee' } })
+ if (!answered.ok) console.error('Fixture screen after failed answer:', JSON.stringify(await directCapture(panes[0])))
+ assert.deepEqual(answered, { ok: true })
+ await eventually(() => gone.includes('s0'), 'answered question closes after two valid empty reads')
+ assert.equal(gone.filter(id => id === 's0').length, 1)
+ assert.equal(open.size, 31, 'neighboring questions remain open')
+ assert.match((await directCapture(panes[0]))!, /Answered 2/)
+ assert.match((await directCapture(panes[1]))!, /Which drink for pane 1/)
+ assert.equal((await controller.answer({ sessionId: 's0', requestId: beforeAnswer.requestId,
+ answers: { [beforeAnswer.questions[0].key]: 'Coffee' } })).ok, false, 'an answered request is stale')
+
+ await tmux('send-keys', '-t', panes[0], 'q')
+ await eventually(() => open.has('s0'), 'question reopens after a screen change')
+ const beforeMissing = open.size
+ await tmux('kill-pane', '-t', panes[16])
+ await wait(3_100)
+ assert.equal(open.size, beforeMissing, 'failed reads are not a confirmed question close')
+ const missingBatch = await Promise.all([panes[0], panes[16], panes[31]].map(pane => batcher.capture(pane, 60)))
+ assert.match(missingBatch[0]!, /Which drink for pane 0/)
+ assert.equal(missingBatch[1], null)
+ assert.match(missingBatch[2]!, /Which drink for pane 31/)
+ sessions.delete('s16'); watcher.stop('s16')
+ assert.equal(open.size, 31)
+ watcher.stopAll()
+ const capturesAtStop = captureProcesses
+ await wait(1_600)
+ assert.equal(captureProcesses, capturesAtStop, 'no tmux polling after stopAll')
+ result.endToEnd = { result: 'passed', sessions: 32, firstTickProcesses: 1, firstTickMs,
+ checks: ['question identity', 'deduplication', 'answer routing', 'two-read close', 'stale answer refusal',
+ 'question reopens', 'missing-pane isolation', 'unknown capture preservation', 'poll teardown'] }
+
+ // The killed pane is replaced by another live pane in the benchmark's input.
+ // The old and new captures still receive identical ordered targets.
+ const targets = panes.map((pane, i) => i === 16 ? panes[31] : pane)
+ const reference = await Promise.all(targets.map(pane => directCapture(pane)))
+ const samples: Array<Record<string, unknown>> = []
+ for (const count of [1, 8, 32]) {
+ const selected = targets.slice(0, count)
+ for (let warm = 0; warm < 5; warm++) {
+ await Promise.all(selected.map(pane => directCapture(pane)))
+ await Promise.all(selected.map(pane => batcher.capture(pane, 60)))
+ }
+ for (let iteration = 0; iteration < 30; iteration++) {
+ for (const mode of iteration % 2 ? ['batched', 'direct'] : ['direct', 'batched']) {
+ captureProcesses = 0
+ const cpu = process.cpuUsage()
+ const start = performance.now()
+ const screens = await Promise.all(selected.map(pane => mode === 'direct' ? directCapture(pane) : batcher.capture(pane, 60)))
+ const elapsedMs = performance.now() - start
+ const used = process.cpuUsage(cpu)
+ assert.deepEqual(screens, reference.slice(0, count), 'capture bytes and target order stay identical')
+ samples.push({ count, mode, iteration, elapsedMs, nodeCpuMs: (used.user + used.system) / 1000, processes: captureProcesses })
+ }
+ }
+ }
+ result.benchmark = { warmups: 5, iterations: 30, samples }
+ const summary = [1, 8, 32].map(count => Object.fromEntries(['count', 'direct', 'batched'].map(mode => {
+ if (mode === 'count') return [mode, count]
+ const rows = samples.filter(row => row.count === count && row.mode === mode)
+ const elapsed = rows.map(row => row.elapsedMs as number).sort((a, b) => a - b)
+ return [mode, { medianMs: (elapsed[14] + elapsed[15]) / 2,
+ nodeCpuMs: rows.reduce((sum, row) => sum + (row.nodeCpuMs as number), 0),
+ processes: rows.reduce((sum, row) => sum + (row.processes as number), 0) }]
+ })))
+ result.summary = summary
+ const output = process.argv[2]
+ if (output) writeFileSync(resolve(output), JSON.stringify(result, null, 2) + '\n')
+ console.log(JSON.stringify({ endToEnd: result.endToEnd, summary }, null, 2))
+} finally {
+ watcher?.stopAll()
+ const missingServer = (error: unknown) => /no server running|error connecting.*(?:No such file|Connection refused)/i
+ .test(String((error as { stderr?: string }).stderr ?? error))
+ const fixturePids = (await tmux('list-panes', '-a', '-F', '#{pane_pid}').catch(error => {
+ if (!missingServer(error)) throw error
+ return ''
+ })).trim().split('\n').filter(Boolean).map(Number)
+ await tmux('kill-server').catch(error => { if (!missingServer(error)) throw error })
+ await eventually(() => fixturePids.every(pid => {
+ try { process.kill(pid, 0); return false } catch (error) {
+ if ((error as NodeJS.ErrnoException).code !== 'ESRCH') throw error
+ return true
+ }
+ }), 'all private fixture processes exit')
+ // Explicit socket on every command: cleanup can never address a user's server.
+ rmSync(root, { recursive: true, force: true })
+ console.log(`[question-native] cleaned ${fixturePids.length} private pane processes`)
+}
diff --git a/cli/src/lib/askQuestion.more.spec.ts b/cli/src/lib/askQuestion.more.spec.ts
index 45966f1a4..249abe1c3 100644
--- a/cli/src/lib/askQuestion.more.spec.ts
+++ b/cli/src/lib/askQuestion.more.spec.ts
@@ -696,7 +696,7 @@ describe('QuestionWatcher — polling', () => {
})
describe('QuestionWatcher — what it announces', () => {
- it('reads a session with no engine as Claude, a failed capture as an empty pane, and a dialog with no body as its question', async () => {
+ it('reads a session with no engine as Claude, ignores a failed capture, and uses a dialog with no body as its question', async () => {
const captures: Array<string | null> = [null, fixture('grok')]
let i = 0
const seen: Array<{ id: string; detail?: { permission: boolean; dialog: string } }> = []
diff --git a/cli/src/lib/askQuestion.polling.spec.ts b/cli/src/lib/askQuestion.polling.spec.ts
new file mode 100644
index 000000000..81801b9bb
--- /dev/null
+++ b/cli/src/lib/askQuestion.polling.spec.ts
@@ -0,0 +1,174 @@
+import { readFileSync } from 'node:fs'
+import { join } from 'node:path'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { QuestionWatcher } from './askQuestion.js'
+import type { RegisteredSession } from './registry.js'
+
+const QUESTION = readFileSync(join(__dirname, '__fixtures__/question-single.txt'), 'utf8')
+const NEXT = readFileSync(join(__dirname, '__fixtures__/question-multi.txt'), 'utf8')
+const watchers: QuestionWatcher[] = []
+
+function deferred<T>() {
+ let resolve!: (value: T) => void
+ let reject!: (error: Error) => void
+ const promise = new Promise<T>((yes, no) => { resolve = yes; reject = no })
+ return { promise, resolve, reject }
+}
+
+function harness(capture = vi.fn(async (_target: string): Promise<string | null> => QUESTION)) {
+ const sessions = new Map<string, RegisteredSession>()
+ const add = (id: string) => {
+ const session = { sessionId: id, agentId: `agent-${id}`, engine: 'claude', active: true,
+ tmuxPane: `%${sessions.size}`, processIdentity: { pid: 100 + sessions.size, startMarker: 'original', executable: '/bin/claude' } } as RegisteredSession
+ sessions.set(id, session)
+ return session
+ }
+ add('s1')
+ const state = { audience: true, driving: false }
+ const onQuestion = vi.fn()
+ const onQuestionGone = vi.fn()
+ const watcher = new QuestionWatcher({ getSession: id => sessions.get(id), capture,
+ hasDevice: () => state.audience, isDriving: () => state.driving, onQuestion, onQuestionGone })
+ watchers.push(watcher)
+ return { watcher, sessions, add, state, capture, onQuestion, onQuestionGone }
+}
+
+beforeEach(() => { vi.useFakeTimers(); vi.spyOn(console, 'log').mockImplementation(() => {}) })
+afterEach(() => { for (const watcher of watchers.splice(0)) watcher.stopAll(); vi.restoreAllMocks(); vi.useRealTimers() })
+
+describe('question polling resources and capture lifetime', () => {
+ it('uses one clock for staggered sessions and releases it when the last watcher stops', async () => {
+ const h = harness()
+ h.watcher.start('s1')
+ await vi.advanceTimersByTimeAsync(100)
+ h.add('s2'); h.watcher.start('s2')
+ await vi.advanceTimersByTimeAsync(100)
+ h.add('s3'); h.watcher.start('s3')
+ expect(vi.getTimerCount()).toBe(1)
+ await vi.advanceTimersByTimeAsync(1_300)
+ expect(h.capture.mock.calls.map(([target]) => target)).toEqual(['agent-s1', 'agent-s2', 'agent-s3'])
+ h.watcher.stop('s1'); h.watcher.stop('s2')
+ expect(vi.getTimerCount()).toBe(1)
+ h.watcher.stop('s3')
+ expect(vi.getTimerCount()).toBe(0)
+ })
+
+ it('does not overlap a slow poll or delay other sessions behind it', async () => {
+ const slow = deferred<string | null>()
+ const h = harness(vi.fn(async target => target === 'agent-s1' ? slow.promise : QUESTION))
+ h.add('s2'); h.watcher.start('s1'); h.watcher.start('s2')
+ await vi.advanceTimersByTimeAsync(4_500)
+ expect(h.capture.mock.calls.filter(([target]) => target === 'agent-s1')).toHaveLength(1)
+ expect(h.capture.mock.calls.filter(([target]) => target === 'agent-s2')).toHaveLength(3)
+ expect(h.onQuestion.mock.calls.map(([id]) => id)).toEqual(['s2'])
+ slow.resolve(QUESTION)
+ await vi.advanceTimersByTimeAsync(0)
+ expect(h.onQuestion.mock.calls.map(([id]) => id)).toEqual(['s2', 's1'])
+ })
+
+ it.each(['stop', 'stopAll'] as const)('discards a poll that completes after %s', async method => {
+ const slow = deferred<string | null>()
+ const h = harness(vi.fn(async () => slow.promise))
+ h.watcher.start('s1')
+ await vi.advanceTimersByTimeAsync(1_500)
+ if (method === 'stop') h.watcher.stop('s1'); else h.watcher.stopAll()
+ slow.resolve(QUESTION)
+ await vi.advanceTimersByTimeAsync(0)
+ expect(h.onQuestion).not.toHaveBeenCalled()
+ expect(h.onQuestionGone).not.toHaveBeenCalled()
+ expect(vi.getTimerCount()).toBe(0)
+ })
+
+ it('a stop/restart discards the old poll without starting a second concurrent capture', async () => {
+ const slow = deferred<string | null>()
+ const h = harness(vi.fn(async (): Promise<string | null> => QUESTION).mockImplementationOnce(() => slow.promise))
+ h.watcher.start('s1')
+ await vi.advanceTimersByTimeAsync(1_500)
+ h.watcher.stop('s1'); h.watcher.start('s1')
+ await vi.advanceTimersByTimeAsync(1_500)
+ expect(h.capture).toHaveBeenCalledTimes(1)
+ slow.resolve(NEXT)
+ await vi.advanceTimersByTimeAsync(0)
+ expect(h.onQuestion).not.toHaveBeenCalled()
+ await vi.advanceTimersByTimeAsync(1_500)
+ expect(h.onQuestion).toHaveBeenCalledOnce()
+ expect(h.onQuestion.mock.calls[0][2][0].q).toBe('Which drink would you like?')
+ })
+
+ it.each(['audience', 'driving'] as const)('rechecks %s after awaiting capture', async changed => {
+ const slow = deferred<string | null>()
+ const h = harness(vi.fn(async () => slow.promise))
+ h.watcher.start('s1')
+ await vi.advanceTimersByTimeAsync(1_500)
+ if (changed === 'audience') h.state.audience = false; else h.state.driving = true
+ slow.resolve(QUESTION)
+ await vi.advanceTimersByTimeAsync(0)
+ expect(h.onQuestion).not.toHaveBeenCalled()
+ })
+
+ it.each(['process', 'reused pid', 'pane', 'runtime', 'engine', 'inactive', 'removed'] as const)('rejects a capture when the session is %s before it returns', async changed => {
+ const slow = deferred<string | null>()
+ const h = harness(vi.fn(async (): Promise<string | null> => QUESTION).mockImplementationOnce(() => slow.promise))
+ h.watcher.start('s1')
+ await vi.advanceTimersByTimeAsync(1_500)
+ const session = h.sessions.get('s1')!
+ if (changed === 'process') session.processIdentity = { pid: 500, startMarker: 'replacement', executable: '/bin/claude' }
+ if (changed === 'reused pid') session.processIdentity!.startMarker = 'replacement'
+ if (changed === 'pane') session.tmuxPane = '%50'
+ if (changed === 'runtime') session.runtimes = [{ backend: 'tmux', paneId: '%50' }]
+ if (changed === 'engine') session.engine = 'codex'
+ if (changed === 'inactive') session.active = false
+ if (changed === 'removed') h.sessions.delete('s1')
+ slow.resolve(QUESTION)
+ await vi.advanceTimersByTimeAsync(0)
+ expect(h.onQuestion).not.toHaveBeenCalled()
+ if (changed === 'inactive' || changed === 'removed') {
+ await vi.advanceTimersByTimeAsync(1_500)
+ expect(h.capture).toHaveBeenCalledTimes(1)
+ expect(vi.getTimerCount()).toBe(0)
+ }
+ })
+
+ it('a failed read is not evidence a question closed, and breaks consecutive empty reads', async () => {
+ const capture = vi.fn(async (): Promise<string | null> => '')
+ .mockResolvedValueOnce(QUESTION).mockResolvedValueOnce('')
+ .mockResolvedValueOnce(null).mockResolvedValueOnce('')
+ const h = harness(capture)
+ h.watcher.start('s1')
+ await vi.advanceTimersByTimeAsync(6_000)
+ expect(h.onQuestion).toHaveBeenCalledOnce()
+ expect(h.onQuestionGone).not.toHaveBeenCalled()
+ await vi.advanceTimersByTimeAsync(1_500)
+ expect(h.onQuestionGone).toHaveBeenCalledOnce()
+ })
+
+ it('releases the pending poll after a rejected capture and retries on the next tick', async () => {
+ const h = harness(vi.fn(async (): Promise<string | null> => QUESTION).mockRejectedValueOnce(new Error('capture failed')))
+ h.watcher.start('s1')
+ await vi.advanceTimersByTimeAsync(3_000)
+ expect(h.capture).toHaveBeenCalledTimes(2)
+ expect(h.onQuestion).toHaveBeenCalledOnce()
+ })
+
+ it('a rejected turn-start read does not suppress a question or escape as an unhandled rejection', async () => {
+ const h = harness(vi.fn(async (): Promise<string | null> => QUESTION).mockRejectedValueOnce(new Error('baseline failed')))
+ h.watcher.start('s1'); h.watcher.noteTurnStart('s1')
+ await vi.advanceTimersByTimeAsync(1_500)
+ expect(h.capture).toHaveBeenCalledTimes(2)
+ expect(h.onQuestion).toHaveBeenCalledOnce()
+ })
+
+ it.each(['stop', 'stopAll', 'next turn'] as const)('a late turn-start read cannot suppress a later question after %s', async changed => {
+ const slow = deferred<string | null>()
+ const h = harness(vi.fn(async (): Promise<string | null> => QUESTION)
+ .mockImplementationOnce(() => slow.promise).mockResolvedValueOnce(''))
+ h.watcher.start('s1'); h.watcher.noteTurnStart('s1')
+ if (changed === 'stop') h.watcher.stop('s1')
+ if (changed === 'stopAll') h.watcher.stopAll()
+ h.watcher.start('s1'); h.watcher.noteTurnStart('s1')
+ await vi.advanceTimersByTimeAsync(0)
+ slow.resolve(QUESTION)
+ await vi.advanceTimersByTimeAsync(1_500)
+ expect(h.onQuestion).toHaveBeenCalledOnce()
+ })
+})
diff --git a/cli/src/lib/askQuestion.ts b/cli/src/lib/askQuestion.ts
index d3c52e9df..338689102 100644
--- a/cli/src/lib/askQuestion.ts
+++ b/cli/src/lib/askQuestion.ts
@@ -1069,7 +1069,10 @@ export function pollsQuestions(engine: AgentEngine): boolean {
* re-announces to a device that attaches mid-question — neither of which a one-shot event could do.
*/
export class QuestionWatcher {
- private timers = new Map<string, NodeJS.Timeout>()
+ private readonly watching = new Set<string>()
+ private timer: NodeJS.Timeout | undefined
+ private readonly pendingPolls = new Map<string, { cancelled: boolean }>()
+ private readonly pendingBaselines = new Map<string, { cancelled: boolean }>()
private last = new Map<string, string>() // sessionId → fingerprint of the announced question
private lastId = new Map<string, string>() // sessionId → requestId of the announced question
private misses = new Map<string, number>() // sessionId → consecutive polls with no dialog
@@ -1101,27 +1104,44 @@ export class QuestionWatcher {
*/
noteTurnStart(sessionId: string): void {
this.preTurn.delete(sessionId)
+ this.cancelPending(sessionId)
+ const pending = { cancelled: false }
+ this.pendingBaselines.set(sessionId, pending)
void (async () => {
- const session = this.deps.getSession(sessionId)
- const target = session?.agentId || session?.sessionId
- if (!target) return
- const view = parseEngineQuestionPane(session?.engine ?? 'claude', await this.deps.capture(target, CAPTURE_LINES) ?? '')
- if (!view || view.kind !== 'question' || !view.question || view.rows.length === 0) return
- // Only if nothing has been announced for this turn yet: the capture takes
- // a moment, and a dialog that opened inside that window is this turn's.
- if (this.lastId.has(sessionId)) return
- this.preTurn.set(sessionId, fingerprintOf(view))
+ try {
+ const session = this.deps.getSession(sessionId)
+ const target = session?.agentId || session?.sessionId
+ if (!target || session?.active === false || (session?.engine && !pollsQuestions(session.engine))) return
+ const generation = questionCaptureGeneration(session)
+ const capture = await this.deps.capture(target, CAPTURE_LINES)
+ if (pending.cancelled || generation !== questionCaptureGeneration(this.deps.getSession(sessionId))) return
+ const view = parseEngineQuestionPane(session?.engine ?? 'claude', capture ?? '')
+ if (!view || view.kind !== 'question' || !view.question || view.rows.length === 0) return
+ // Only if nothing has been announced for this turn yet: the capture takes
+ // a moment, and a dialog that opened inside that window is this turn's.
+ if (this.lastId.has(sessionId)) return
+ this.preTurn.set(sessionId, fingerprintOf(view))
+ } catch {
+ // A failed read supplies no baseline. Keep watching for a fresh dialog.
+ } finally {
+ if (this.pendingBaselines.get(sessionId) === pending) this.pendingBaselines.delete(sessionId)
+ }
})()
}
/** Poll this session's pane while its turn is open (called on turn_started). */
start(sessionId: string): void {
- if (this.timers.has(sessionId)) return
+ if (this.watching.has(sessionId)) return
const session = this.deps.getSession(sessionId)
// Only the engines that actually paint a question dialog: Claude and Command Code share one shape,
// devin has its own (parseDevinQuestionPane). Polling any other pane would be pure waste.
if (!session || session.active === false || !(session.agentId || session.sessionId) || !QUESTION_ENGINES.has(session.engine)) return
- this.timers.set(sessionId, setInterval(() => { void this.tick(sessionId) }, POLL_MS))
+ this.watching.add(sessionId)
+ // One clock also starts the reads in one event-loop turn, allowing the tmux
+ // backend to batch them without delaying polls or caching terminal content.
+ this.timer ??= setInterval(() => {
+ for (const id of this.watching) void this.tick(id)
+ }, POLL_MS)
}
/**
@@ -1138,9 +1158,11 @@ export class QuestionWatcher {
* was removed cannot answer either.
*/
stop(sessionId: string): void {
+ this.cancelPending(sessionId)
this.preTurn.delete(sessionId)
- const timer = this.timers.get(sessionId)
- if (timer) { clearInterval(timer); this.timers.delete(sessionId) }
+ this.blocked.delete(sessionId)
+ this.watching.delete(sessionId)
+ if (!this.watching.size && this.timer) { clearInterval(this.timer); this.timer = undefined }
const requestId = this.lastId.get(sessionId)
this.forget(sessionId)
if (requestId) this.deps.onQuestionGone?.(sessionId, requestId)
@@ -1148,8 +1170,13 @@ export class QuestionWatcher {
stopAll(): void {
- for (const timer of this.timers.values()) clearInterval(timer)
- this.timers.clear()
+ if (this.timer) clearInterval(this.timer)
+ this.timer = undefined
+ this.watching.clear()
+ for (const pending of this.pendingPolls.values()) pending.cancelled = true
+ for (const pending of this.pendingBaselines.values()) pending.cancelled = true
+ this.preTurn.clear()
+ this.blocked.clear()
this.last.clear()
this.lastId.clear()
this.misses.clear()
@@ -1168,6 +1195,13 @@ export class QuestionWatcher {
this.misses.delete(sessionId)
}
+ private cancelPending(sessionId: string): void {
+ const poll = this.pendingPolls.get(sessionId)
+ if (poll) poll.cancelled = true
+ const baseline = this.pendingBaselines.get(sessionId)
+ if (baseline) baseline.cancelled = true
+ }
+
/**
* A poll found no dialog. Announce the close once the miss is CONFIRMED, and only if we announced the
* question in the first place — a session nobody was told about has nothing to take back.
@@ -1186,9 +1220,12 @@ export class QuestionWatcher {
private async tick(sessionId: string): Promise<void> {
+ // A capture can take longer than POLL_MS. Keep one outstanding poll per
+ // session, including a cancelled capture that has not returned yet.
+ if (this.pendingPolls.has(sessionId)) return
const session = this.deps.getSession(sessionId)
const terminalTarget = session?.agentId || session?.sessionId
- if (!terminalTarget) { this.stop(sessionId); return }
+ if (!terminalTarget || session?.active === false || (session?.engine && !pollsQuestions(session.engine))) { this.stop(sessionId); return }
// Both of these silently do nothing, which is how a live dialog can sit on the terminal with no trace
// in the log. Say it once per transition rather than every 1.5s tick.
const blocked = !this.deps.hasDevice() ? 'no device' : this.deps.isDriving?.(sessionId) ? 'driving an answer' : ''
@@ -1197,8 +1234,25 @@ export class QuestionWatcher {
console.log(`[question] ${sessionId.slice(0, 8)} watcher ${blocked ? `paused · ${blocked}` : 'polling'}`)
}
if (blocked) return
- const engine = this.deps.getSession(sessionId)?.engine ?? 'claude'
- const view = parseEngineQuestionPane(engine, await this.deps.capture(terminalTarget, CAPTURE_LINES) ?? '')
+ const pending = { cancelled: false }
+ this.pendingPolls.set(sessionId, pending)
+ const generation = questionCaptureGeneration(session)
+ let capture: string | null
+ try {
+ capture = await this.deps.capture(terminalTarget, CAPTURE_LINES)
+ } catch {
+ capture = null
+ } finally {
+ if (this.pendingPolls.get(sessionId) === pending) this.pendingPolls.delete(sessionId)
+ }
+ if (pending.cancelled || generation !== questionCaptureGeneration(this.deps.getSession(sessionId))
+ || !this.deps.hasDevice() || this.deps.isDriving?.(sessionId)) return
+ if (capture === null) {
+ // Unavailable is not an empty pane, and breaks a run of confirmed misses.
+ this.misses.delete(sessionId)
+ return
+ }
+ const view = parseEngineQuestionPane(session?.engine ?? 'claude', capture)
if (view?.kind === 'question' && view.partial) {
// Scrolled so its top is out of the pane: still open, so the client showing it keeps showing it —
// but there is no question text to announce, and the rows in view are whichever the scroll left.
@@ -1227,6 +1281,8 @@ export class QuestionWatcher {
// means a different dialog, and the answer is refused (STALE_QUESTION) instead of keyed into it.
const requestId = questionRequestId(sessionId, view)
this.lastId.set(sessionId, requestId)
+ const baseline = this.pendingBaselines.get(sessionId)
+ if (baseline) baseline.cancelled = true
this.deps.onQuestion(sessionId, requestId, [{
key: view.question,
q: view.question,
@@ -1238,6 +1294,13 @@ export class QuestionWatcher {
}
}
+/** Snapshot scalar values before awaiting I/O: registry records can change in
+ * place when an engine exits, moves, or is replaced in the same pane. */
+function questionCaptureGeneration(session: RegisteredSession | undefined): string {
+ return session ? JSON.stringify([session.agentId, session.sessionId, session.engine, session.active,
+ session.tmuxPane, session.primaryRuntimeKey, session.runtimes, session.processIdentity]) : ''
+}
+
/**
* What makes two captures the SAME dialog: its words, its options, its arity — and, when the parser kept
* the whole dialog, what it says below its first line (a command that differs only on its second line is
diff --git a/cli/src/lib/tmux.ts b/cli/src/lib/tmux.ts
index 707454d8b..1ba34e30f 100644
--- a/cli/src/lib/tmux.ts
+++ b/cli/src/lib/tmux.ts
@@ -16,6 +16,7 @@ import {
} from './engineBin.js'
import { BYPASS_PERMISSION_FLAGS, PERMISSION_MODES, permissionModeApproves } from './engineLaunch.js'
import { psEnv } from './childLocale.js'
+export { captureTmuxPane, tmuxCaptureArgs } from './tmuxCapture.js'
function cleanPaneTitle(title: string): string | null {
const cleaned = title
@@ -1106,30 +1107,3 @@ export function sendKeyToTmux(pane: string, key: string): Promise<boolean> {
execFile('tmux', ['send-keys', '-t', pane, key], { timeout: 2000 }, (err) => resolve(!err))
})
}
-
-export function tmuxCaptureArgs(
- pane: string,
- historyLines = 100,
- options: { visible?: boolean; ansi?: boolean } = {},
-): string[] {
- const bounded = Math.max(20, Math.min(300, Math.floor(historyLines)))
- const args = ['capture-pane', '-p']
- if (options.ansi !== false) args.push('-e')
- args.push('-J', '-t', pane)
- if (!options.visible) args.push('-S', `-${bounded}`)
- return args
-}
-
-/** Capture terminal text; SGR and bounded history are independently selectable by backend consumers. */
-export function captureTmuxPane(
- pane: string,
- historyLines = 100,
- options: { visible?: boolean; ansi?: boolean } = {},
-): Promise<string | null> {
- return new Promise((resolve) => {
- execFile('tmux', tmuxCaptureArgs(pane, historyLines, options), { timeout: 2000 }, (err, stdout) => {
- if (err) { resolve(null); return }
- resolve(stdout)
- })
- })
-}
diff --git a/cli/src/lib/tmuxCapture.spec.ts b/cli/src/lib/tmuxCapture.spec.ts
new file mode 100644
index 000000000..3eb38aa61
--- /dev/null
+++ b/cli/src/lib/tmuxCapture.spec.ts
@@ -0,0 +1,142 @@
+import { describe, expect, it, vi } from 'vitest'
+import { captureTmuxPane, TmuxCaptureBatcher, tmuxCaptureArgs } from './tmuxCapture.js'
+
+const childProcess = vi.hoisted(() => ({ execFile: vi.fn() }))
+vi.mock('node:child_process', () => childProcess)
+
+type Execute = NonNullable<ConstructorParameters<typeof TmuxCaptureBatcher>[0]>
+
+function commands(args: string[]): string[][] {
+ const result: string[][] = [[]]
+ for (const arg of args) {
+ if (arg === ';') result.push([])
+ else result[result.length - 1].push(arg)
+ }
+ return result
+}
+
+function server(panes: Record<string, string>) {
+ const run: Execute = (args, _options, done) => {
+ let stdout = ''
+ for (const command of commands(args)) {
+ if (command[0] === 'display-message') stdout += `${command[2]}\n`
+ else {
+ const pane = command[command.indexOf('-t') + 1]
+ if (!(pane in panes)) { done(new Error('missing pane'), stdout); return }
+ stdout += panes[pane]
+ }
+ }
+ done(null, stdout)
+ }
+ const execute = vi.fn(run)
+ return { panes, execute, capture: new TmuxCaptureBatcher(execute) }
+}
+
+describe('fresh tmux capture batching', () => {
+ it('the public capture helper uses the default tmux process executor', async () => {
+ childProcess.execFile.mockImplementation((_file, _args, _options, done) => done(null, 'default screen\n'))
+ expect(await captureTmuxPane('%7', 40, { ansi: false })).toBe('default screen\n')
+ expect(childProcess.execFile).toHaveBeenCalledOnce()
+ expect(childProcess.execFile.mock.calls[0].slice(0, 3)).toEqual([
+ 'tmux', tmuxCaptureArgs('%7', 40, { ansi: false }), { timeout: 2_000, maxBuffer: 1024 * 1024 },
+ ])
+ })
+
+ it('reads concurrent panes in one process without mixing ANSI, empty, or multiline captures', async () => {
+ const h = server({ '%1': '\u001b[31mhello\u001b[0m\nnext\n', '%2': '\n', '%3': 'third\n\n' })
+ expect(await Promise.all(['%1', '%2', '%3'].map(id => h.capture.capture(id)))).toEqual(Object.values(h.panes))
+ expect(h.execute).toHaveBeenCalledOnce()
+ expect(h.execute.mock.calls[0][1]).toEqual({ timeout: 2_000, maxBuffer: 4 * 1024 * 1024 })
+ })
+
+ it('keeps solitary and subsequent captures fresh, with no framing or terminal cache', async () => {
+ const h = server({ '%1': 'before\n' })
+ expect(await h.capture.capture('%1', 60, { ansi: false, visible: true })).toBe('before\n')
+ expect(h.execute.mock.calls[0][0]).toEqual(['capture-pane', '-p', '-J', '-t', '%1'])
+ expect(h.execute.mock.calls[0][1]).toEqual({ timeout: 2_000, maxBuffer: 1024 * 1024 })
+ h.panes['%1'] = 'after\n'
+ expect(await h.capture.capture('%1')).toBe('after\n')
+ expect(h.execute).toHaveBeenCalledTimes(2)
+ })
+
+ it('a completely empty framed capture stays distinct from an unavailable pane', async () => {
+ const h = server({ '%1': '', '%2': 'visible\n' })
+ expect(await Promise.all([h.capture.capture('%1'), h.capture.capture('%2')])).toEqual(['', 'visible\n'])
+ expect(h.execute).toHaveBeenCalledOnce()
+ })
+
+ it('preserves each requested ANSI, visible-screen, and history option', async () => {
+ const h = server({ '%1': 'one\n', '%2': 'two\n' })
+ await Promise.all([h.capture.capture('%1', 60), h.capture.capture('%2', 300, { ansi: false, visible: true })])
+ expect(commands(h.execute.mock.calls[0][0]).filter(command => command[0] === 'capture-pane')).toEqual([
+ tmuxCaptureArgs('%1', 60), tmuxCaptureArgs('%2', 300, { ansi: false, visible: true }),
+ ])
+ })
+
+ it.each([0, 1, 2])('one missing pane at position %i cannot hide another pane or return a partial frame', async missing => {
+ const h = server({ '%0': 'zero\n', '%1': 'one\n', '%2': 'two\n' })
+ delete h.panes[`%${missing}`]
+ expect(await Promise.all(['%0', '%1', '%2'].map(id => h.capture.capture(id))))
+ .toEqual([h.panes['%0'] ?? null, h.panes['%1'] ?? null, h.panes['%2'] ?? null])
+ // The successfully framed prefix is not read twice. The failed pane and
+ // the commands tmux never reached get independent reads.
+ expect(h.execute).toHaveBeenCalledTimes(1 + 3 - missing)
+ })
+
+ it('retries a truncated batch frame instead of interpreting it as a complete screen', async () => {
+ const h = server({ '%1': 'whole first screen\n', '%2': 'whole second screen\n' })
+ h.execute.mockImplementationOnce((args, _options, done) => {
+ const start = commands(args)[0][2]
+ done(new Error('maxBuffer exceeded'), `${start}\npartial screen\n`)
+ })
+ expect(await Promise.all([h.capture.capture('%1'), h.capture.capture('%2')]))
+ .toEqual(['whole first screen\n', 'whole second screen\n'])
+ expect(h.execute).toHaveBeenCalledTimes(3)
+ })
+
+ it('does not accept an end-marker fragment inside a terminal line', async () => {
+ const h = server({ '%1': 'full first\n', '%2': 'full second\n' })
+ h.execute.mockImplementationOnce((args, _options, done) => {
+ const batch = commands(args)
+ done(new Error('truncated'), `${batch[0][2]}\npartial${batch[2][2]}\n`)
+ })
+ expect(await Promise.all([h.capture.capture('%1'), h.capture.capture('%2')])).toEqual(['full first\n', 'full second\n'])
+ })
+
+ it('bounds both command batches and output per pane', async () => {
+ const panes = Object.fromEntries(Array.from({ length: 65 }, (_, i) => [`%${i}`, `pane-${i}\n`]))
+ const h = server(panes)
+ expect(await Promise.all(Object.keys(panes).map(id => h.capture.capture(id)))).toEqual(Object.values(panes))
+ expect(h.execute).toHaveBeenCalledTimes(3)
+ expect(h.execute.mock.calls.map(([args]) => commands(args).filter(command => command[0] === 'capture-pane').length))
+ .toEqual([32, 32, 1])
+ h.panes['%0'] = `${'界'.repeat(350_000)}\n`
+ expect(await Promise.all([h.capture.capture('%0'), h.capture.capture('%1')])).toEqual([null, 'pane-1\n'])
+ })
+
+ it('rejects malformed targets before constructing a compound command', async () => {
+ const h = server({ '%1': 'safe\n' })
+ for (const target of [';', '%1;', '%1\n', '-t', '', 'named-session', '%-2', '#{pane_id}']) {
+ expect(await h.capture.capture(target)).toBeNull()
+ }
+ expect(h.execute).not.toHaveBeenCalled()
+ })
+
+ it('resolves unavailable when tmux cannot be spawned, including the fallback', async () => {
+ const execute = vi.fn<Execute>(() => { throw new Error('spawn failed') })
+ const h = new TmuxCaptureBatcher(execute)
+ expect(await Promise.all([h.capture('%1'), h.capture('%2')])).toEqual([null, null])
+ expect(await h.capture('%3')).toBeNull()
+ })
+
+ it('never returns a failed single capture\'s partial stdout as a screen', async () => {
+ const capture = new TmuxCaptureBatcher((_args, _options, done) => done(new Error('timed out'), 'partial question\n'))
+ expect(await capture.capture('%1')).toBeNull()
+ })
+
+ it('does not deduplicate reads of a pane that may change between commands', async () => {
+ let count = 0
+ const h = server({ get '%1'() { return `screen ${++count}\n` } })
+ expect(await Promise.all([h.capture.capture('%1'), h.capture.capture('%1')])).toEqual(['screen 1\n', 'screen 2\n'])
+ })
+})
diff --git a/cli/src/lib/tmuxCapture.ts b/cli/src/lib/tmuxCapture.ts
new file mode 100644
index 000000000..1e272faec
--- /dev/null
+++ b/cli/src/lib/tmuxCapture.ts
@@ -0,0 +1,100 @@
+import { execFile } from 'node:child_process'
+import { randomUUID } from 'node:crypto'
+
+type CaptureOptions = { visible?: boolean; ansi?: boolean }
+type CaptureExecutor = (args: string[], options: { timeout: number; maxBuffer: number },
+ done: (error: Error | null, stdout: string) => void) => void
+type PendingCapture = { args: string[]; resolve: (value: string | null) => void }
+
+const MAX_BATCH = 32
+const SINGLE_BYTES = 1024 * 1024
+const BATCH_BYTES = 4 * SINGLE_BYTES
+
+export function tmuxCaptureArgs(pane: string, historyLines = 100, options: CaptureOptions = {}): string[] {
+ const bounded = Math.max(20, Math.min(300, Math.floor(historyLines)))
+ const args = ['capture-pane', '-p']
+ if (options.ansi !== false) args.push('-e')
+ args.push('-J', '-t', pane)
+ if (!options.visible) args.push('-S', `-${bounded}`)
+ return args
+}
+
+/** Concurrent reads share a tmux client, never a cached screen. A microtask
+ * collects only this event-loop turn; a solitary read keeps the direct path. */
+export class TmuxCaptureBatcher {
+ private pending: PendingCapture[] = []
+
+ constructor(private readonly execute: CaptureExecutor = (args, options, done) => {
+ execFile('tmux', args, options, done)
+ }) {}
+
+ capture(pane: string, historyLines = 100, options: CaptureOptions = {}): Promise<string | null> {
+ // Captures address exact pane IDs. In particular, an argv command separator
+ // must never be accepted as a target in a compound tmux command.
+ if (!/^%\d+$/.test(pane)) return Promise.resolve(null)
+ return new Promise(resolve => {
+ this.pending.push({ args: tmuxCaptureArgs(pane, historyLines, options), resolve })
+ if (this.pending.length === 1) queueMicrotask(() => this.flush())
+ })
+ }
+
+ private flush(): void {
+ const pending = this.pending
+ this.pending = []
+ for (let i = 0; i < pending.length; i += MAX_BATCH) this.batch(pending.slice(i, i + MAX_BATCH))
+ }
+
+ private single(read: PendingCapture): void {
+ try {
+ this.execute(read.args, { timeout: 2_000, maxBuffer: SINGLE_BYTES }, (error, stdout) => {
+ read.resolve(error ? null : stdout)
+ })
+ } catch {
+ read.resolve(null)
+ }
+ }
+
+ private batch(reads: PendingCapture[]): void {
+ if (reads.length === 1) { this.single(reads[0]); return }
+ const nonce = `harness-capture-${randomUUID()}`
+ const frames = reads.map((_, i) => ({ start: `${nonce}-${i}-start\n`, end: `${nonce}-${i}-end\n` }))
+ const args: string[] = []
+ for (const [i, read] of reads.entries()) {
+ if (i) args.push(';')
+ args.push('display-message', '-p', frames[i].start.trimEnd(), ';', ...read.args,
+ ';', 'display-message', '-p', frames[i].end.trimEnd())
+ }
+ const finish = (_error: Error | null, stdout: string): void => {
+ let cursor = 0
+ for (const [i, read] of reads.entries()) {
+ const { start, end } = frames[i]
+ const begin = stdout.startsWith(start, cursor) ? cursor + start.length : -1
+ const finish = begin < 0 ? -1 : stdout.indexOf(end, begin)
+ if (finish >= begin && begin >= 0 && (finish === begin || stdout[finish - 1] === '\n')) {
+ const text = stdout.slice(begin, finish)
+ // A retained question must not retain the backing string for every
+ // other pane in this batch. Return independent UTF-8 string storage.
+ read.resolve(Buffer.byteLength(text) <= SINGLE_BYTES ? Buffer.from(text).toString('utf8') : null)
+ cursor = finish + end.length
+ } else {
+ // tmux stops a command list at the first missing pane. Retain only
+ // complete frames; retry every unfinished read on its own so one dead
+ // pane or an output-size limit cannot hide neighboring questions.
+ this.single(read)
+ }
+ }
+ }
+ try {
+ this.execute(args, { timeout: 2_000, maxBuffer: BATCH_BYTES }, finish)
+ } catch {
+ for (const read of reads) this.single(read)
+ }
+ }
+}
+
+const captures = new TmuxCaptureBatcher()
+
+/** Capture fresh terminal text with independently selectable ANSI and history. */
+export function captureTmuxPane(pane: string, historyLines = 100, options: CaptureOptions = {}): Promise<string | null> {
+ return captures.capture(pane, historyLines, options)
+}
diff --git a/docs/performance/2026-10-01-question-poll-data/native-macos.json b/docs/performance/2026-10-01-question-poll-data/native-macos.json
new file mode 100644
index 000000000..4dbd4564a
--- /dev/null
+++ b/docs/performance/2026-10-01-question-poll-data/native-macos.json
@@ -0,0 +1,1511 @@
+{
+ "recordedAt": "2026-10-01T11:51:57.495Z",
+ "node": "v22.23.2",
+ "platform": "darwin-arm64",
+ "scope": "Private real tmux with recorded dialog paint. Node CPU excludes tmux clients/server; not whole-app energy.",
+ "tmux": "tmux 3.5a",
+ "endToEnd": {
+ "result": "passed",
+ "sessions": 32,
+ "firstTickProcesses": 1,
+ "firstTickMs": 1553.500625,
+ "checks": [
+ "question identity",
+ "deduplication",
+ "answer routing",
+ "two-read close",
+ "stale answer refusal",
+ "question reopens",
+ "missing-pane isolation",
+ "unknown capture preservation",
+ "poll teardown"
+ ]
+ },
+ "benchmark": {
+ "warmups": 5,
+ "iterations": 30,
+ "samples": [
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 0,
+ "elapsedMs": 3.3780839999999444,
+ "nodeCpuMs": 0.366,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 0,
+ "elapsedMs": 3.8534579999995913,
+ "nodeCpuMs": 0.355,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 1,
+ "elapsedMs": 3.576042000000598,
+ "nodeCpuMs": 0.394,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 1,
+ "elapsedMs": 3.472334000000046,
+ "nodeCpuMs": 0.362,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 2,
+ "elapsedMs": 3.4621660000011616,
+ "nodeCpuMs": 0.415,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 2,
+ "elapsedMs": 3.6232919999984006,
+ "nodeCpuMs": 0.491,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 3,
+ "elapsedMs": 3.43841699999939,
+ "nodeCpuMs": 1.09,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 3,
+ "elapsedMs": 3.7765419999996084,
+ "nodeCpuMs": 0.352,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 4,
+ "elapsedMs": 3.7990420000005543,
+ "nodeCpuMs": 0.445,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 4,
+ "elapsedMs": 3.638375000000451,
+ "nodeCpuMs": 0.358,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 5,
+ "elapsedMs": 3.6424580000002607,
+ "nodeCpuMs": 0.341,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 5,
+ "elapsedMs": 3.595833000001221,
+ "nodeCpuMs": 0.351,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 6,
+ "elapsedMs": 3.8239159999993717,
+ "nodeCpuMs": 0.736,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 6,
+ "elapsedMs": 3.7034999999996217,
+ "nodeCpuMs": 2.51,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 7,
+ "elapsedMs": 3.5328339999996388,
+ "nodeCpuMs": 0.349,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 7,
+ "elapsedMs": 3.517083000000639,
+ "nodeCpuMs": 0.308,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 8,
+ "elapsedMs": 3.889999999999418,
+ "nodeCpuMs": 0.391,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 8,
+ "elapsedMs": 3.5351670000000013,
+ "nodeCpuMs": 0.351,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 9,
+ "elapsedMs": 3.516250000000582,
+ "nodeCpuMs": 0.348,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 9,
+ "elapsedMs": 3.353541000000405,
+ "nodeCpuMs": 0.315,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 10,
+ "elapsedMs": 3.510041999999885,
+ "nodeCpuMs": 0.321,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 10,
+ "elapsedMs": 3.512917000000016,
+ "nodeCpuMs": 0.357,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 11,
+ "elapsedMs": 3.474207999999635,
+ "nodeCpuMs": 0.351,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 11,
+ "elapsedMs": 3.318375000000742,
+ "nodeCpuMs": 0.353,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 12,
+ "elapsedMs": 3.47400000000016,
+ "nodeCpuMs": 0.901,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 12,
+ "elapsedMs": 3.504624999999578,
+ "nodeCpuMs": 0.343,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 13,
+ "elapsedMs": 3.837792000000263,
+ "nodeCpuMs": 0.333,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 13,
+ "elapsedMs": 3.6857920000002196,
+ "nodeCpuMs": 0.366,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 14,
+ "elapsedMs": 3.646999999999025,
+ "nodeCpuMs": 0.33,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 14,
+ "elapsedMs": 3.9822079999994457,
+ "nodeCpuMs": 0.371,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 15,
+ "elapsedMs": 3.9746670000004087,
+ "nodeCpuMs": 0.453,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 15,
+ "elapsedMs": 4.070832999999766,
+ "nodeCpuMs": 0.446,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 16,
+ "elapsedMs": 3.945791999998619,
+ "nodeCpuMs": 0.413,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 16,
+ "elapsedMs": 4.424999999999272,
+ "nodeCpuMs": 0.453,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 17,
+ "elapsedMs": 3.99029100000007,
+ "nodeCpuMs": 0.488,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 17,
+ "elapsedMs": 3.5762500000000728,
+ "nodeCpuMs": 0.451,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 18,
+ "elapsedMs": 3.4724159999987023,
+ "nodeCpuMs": 1.089,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 18,
+ "elapsedMs": 3.4254999999993743,
+ "nodeCpuMs": 0.353,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 19,
+ "elapsedMs": 3.5590830000001006,
+ "nodeCpuMs": 0.351,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 19,
+ "elapsedMs": 3.699000000000524,
+ "nodeCpuMs": 0.376,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 20,
+ "elapsedMs": 3.5359580000003916,
+ "nodeCpuMs": 0.645,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 20,
+ "elapsedMs": 3.455792000000656,
+ "nodeCpuMs": 0.34,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 21,
+ "elapsedMs": 3.5152500000003783,
+ "nodeCpuMs": 0.349,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 21,
+ "elapsedMs": 3.4523750000007567,
+ "nodeCpuMs": 0.306,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 22,
+ "elapsedMs": 3.5402910000011616,
+ "nodeCpuMs": 0.318,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 22,
+ "elapsedMs": 3.9985409999990225,
+ "nodeCpuMs": 0.312,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 23,
+ "elapsedMs": 3.422207999999955,
+ "nodeCpuMs": 0.313,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 23,
+ "elapsedMs": 3.4164999999993597,
+ "nodeCpuMs": 0.314,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 24,
+ "elapsedMs": 3.4122500000012224,
+ "nodeCpuMs": 0.314,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 24,
+ "elapsedMs": 3.6193750000002183,
+ "nodeCpuMs": 0.353,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 25,
+ "elapsedMs": 3.4626250000001164,
+ "nodeCpuMs": 0.334,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 25,
+ "elapsedMs": 3.4549580000002607,
+ "nodeCpuMs": 0.312,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 26,
+ "elapsedMs": 3.3878329999988637,
+ "nodeCpuMs": 0.333,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 26,
+ "elapsedMs": 3.477708000000348,
+ "nodeCpuMs": 0.756,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 27,
+ "elapsedMs": 3.4933750000000146,
+ "nodeCpuMs": 0.329,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 27,
+ "elapsedMs": 3.435749999998734,
+ "nodeCpuMs": 0.34,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 28,
+ "elapsedMs": 3.3415839999997843,
+ "nodeCpuMs": 0.312,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 28,
+ "elapsedMs": 3.595584000000599,
+ "nodeCpuMs": 0.331,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "batched",
+ "iteration": 29,
+ "elapsedMs": 3.432875000000422,
+ "nodeCpuMs": 0.331,
+ "processes": 1
+ },
+ {
+ "count": 1,
+ "mode": "direct",
+ "iteration": 29,
+ "elapsedMs": 3.563709000000017,
+ "nodeCpuMs": 0.34,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 0,
+ "elapsedMs": 6.066791999999623,
+ "nodeCpuMs": 2.508,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 0,
+ "elapsedMs": 4.803458000000319,
+ "nodeCpuMs": 0.522,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 1,
+ "elapsedMs": 4.979917000000569,
+ "nodeCpuMs": 0.547,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 1,
+ "elapsedMs": 5.8272500000002765,
+ "nodeCpuMs": 2.519,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 2,
+ "elapsedMs": 5.8890420000007,
+ "nodeCpuMs": 2.601,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 2,
+ "elapsedMs": 4.956292000000758,
+ "nodeCpuMs": 0.57,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 3,
+ "elapsedMs": 4.868000000000393,
+ "nodeCpuMs": 0.552,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 3,
+ "elapsedMs": 5.72954099999879,
+ "nodeCpuMs": 2.384,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 4,
+ "elapsedMs": 5.936000000001513,
+ "nodeCpuMs": 2.224,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 4,
+ "elapsedMs": 5.007916999998997,
+ "nodeCpuMs": 0.588,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 5,
+ "elapsedMs": 4.915416000001642,
+ "nodeCpuMs": 0.535,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 5,
+ "elapsedMs": 5.7152920000007725,
+ "nodeCpuMs": 2.414,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 6,
+ "elapsedMs": 6.9167080000006536,
+ "nodeCpuMs": 5.171,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 6,
+ "elapsedMs": 4.895790999999008,
+ "nodeCpuMs": 0.564,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 7,
+ "elapsedMs": 4.891417000000729,
+ "nodeCpuMs": 0.518,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 7,
+ "elapsedMs": 5.931291000000783,
+ "nodeCpuMs": 2.374,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 8,
+ "elapsedMs": 6.361417000000074,
+ "nodeCpuMs": 2.591,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 8,
+ "elapsedMs": 4.88958300000013,
+ "nodeCpuMs": 0.542,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 9,
+ "elapsedMs": 5.209500000000844,
+ "nodeCpuMs": 0.526,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 9,
+ "elapsedMs": 6.05225000000064,
+ "nodeCpuMs": 2.906,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 10,
+ "elapsedMs": 5.757707999999184,
+ "nodeCpuMs": 2.317,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 10,
+ "elapsedMs": 5.035916999999245,
+ "nodeCpuMs": 0.751,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 11,
+ "elapsedMs": 5.036167000000205,
+ "nodeCpuMs": 1.163,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 11,
+ "elapsedMs": 6.083792000001267,
+ "nodeCpuMs": 4.566,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 12,
+ "elapsedMs": 6.387165999998615,
+ "nodeCpuMs": 2.606,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 12,
+ "elapsedMs": 5.17987500000163,
+ "nodeCpuMs": 0.588,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 13,
+ "elapsedMs": 5.210875000000669,
+ "nodeCpuMs": 0.554,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 13,
+ "elapsedMs": 6.619625000001179,
+ "nodeCpuMs": 4.894,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 14,
+ "elapsedMs": 6.5945839999985765,
+ "nodeCpuMs": 12.827,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 14,
+ "elapsedMs": 4.967667000000802,
+ "nodeCpuMs": 0.624,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 15,
+ "elapsedMs": 5.25066599999991,
+ "nodeCpuMs": 0.539,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 15,
+ "elapsedMs": 6.820332999999664,
+ "nodeCpuMs": 2.451,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 16,
+ "elapsedMs": 5.843249999999898,
+ "nodeCpuMs": 2.68,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 16,
+ "elapsedMs": 5.032999999999447,
+ "nodeCpuMs": 0.628,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 17,
+ "elapsedMs": 4.971708000000945,
+ "nodeCpuMs": 0.534,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 17,
+ "elapsedMs": 5.819541999999274,
+ "nodeCpuMs": 2.553,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 18,
+ "elapsedMs": 5.903207999999722,
+ "nodeCpuMs": 2.457,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 18,
+ "elapsedMs": 5.0144580000014685,
+ "nodeCpuMs": 0.6,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 19,
+ "elapsedMs": 5.007666999999856,
+ "nodeCpuMs": 0.514,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 19,
+ "elapsedMs": 5.763165999998819,
+ "nodeCpuMs": 2.45,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 20,
+ "elapsedMs": 5.887750000001688,
+ "nodeCpuMs": 2.57,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 20,
+ "elapsedMs": 4.957790999998906,
+ "nodeCpuMs": 0.589,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 21,
+ "elapsedMs": 4.994333000000552,
+ "nodeCpuMs": 0.53,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 21,
+ "elapsedMs": 6.3229169999995065,
+ "nodeCpuMs": 4.815,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 22,
+ "elapsedMs": 5.973415999998906,
+ "nodeCpuMs": 2.497,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 22,
+ "elapsedMs": 4.877666999998837,
+ "nodeCpuMs": 0.576,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 23,
+ "elapsedMs": 4.977708000000348,
+ "nodeCpuMs": 0.505,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 23,
+ "elapsedMs": 7.323792000001049,
+ "nodeCpuMs": 2.85,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 24,
+ "elapsedMs": 7.551166000001103,
+ "nodeCpuMs": 8.428,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 24,
+ "elapsedMs": 5.615750000000844,
+ "nodeCpuMs": 0.662,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 25,
+ "elapsedMs": 5.677207999999155,
+ "nodeCpuMs": 0.689,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 25,
+ "elapsedMs": 6.778374999999869,
+ "nodeCpuMs": 5.73,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 26,
+ "elapsedMs": 6.242708000001585,
+ "nodeCpuMs": 2.581,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 26,
+ "elapsedMs": 5.241500000000087,
+ "nodeCpuMs": 1.909,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 27,
+ "elapsedMs": 5.262333000000581,
+ "nodeCpuMs": 0.589,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 27,
+ "elapsedMs": 5.9756670000006125,
+ "nodeCpuMs": 4.02,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 28,
+ "elapsedMs": 5.888457999999446,
+ "nodeCpuMs": 2.908,
+ "processes": 8
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 28,
+ "elapsedMs": 4.971665999999459,
+ "nodeCpuMs": 0.567,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "batched",
+ "iteration": 29,
+ "elapsedMs": 5.053125000000364,
+ "nodeCpuMs": 0.52,
+ "processes": 1
+ },
+ {
+ "count": 8,
+ "mode": "direct",
+ "iteration": 29,
+ "elapsedMs": 5.996957999999722,
+ "nodeCpuMs": 4.295,
+ "processes": 8
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 0,
+ "elapsedMs": 19.887500000000728,
+ "nodeCpuMs": 16.538,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 0,
+ "elapsedMs": 10.046125000000757,
+ "nodeCpuMs": 1.227,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 1,
+ "elapsedMs": 10.065957999999227,
+ "nodeCpuMs": 1.275,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 1,
+ "elapsedMs": 18.206082999999126,
+ "nodeCpuMs": 11.946,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 2,
+ "elapsedMs": 18.734167000000525,
+ "nodeCpuMs": 18.272,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 2,
+ "elapsedMs": 10.167583000000377,
+ "nodeCpuMs": 1.285,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 3,
+ "elapsedMs": 9.91295799999898,
+ "nodeCpuMs": 1.199,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 3,
+ "elapsedMs": 18.191208000000188,
+ "nodeCpuMs": 10.781,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 4,
+ "elapsedMs": 18.92870800000128,
+ "nodeCpuMs": 13.277,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 4,
+ "elapsedMs": 9.729041999999026,
+ "nodeCpuMs": 1.162,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 5,
+ "elapsedMs": 9.720833000001221,
+ "nodeCpuMs": 1.132,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 5,
+ "elapsedMs": 20.176375000000917,
+ "nodeCpuMs": 26.749,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 6,
+ "elapsedMs": 18.485249999999724,
+ "nodeCpuMs": 17.354,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 6,
+ "elapsedMs": 10.065833000000566,
+ "nodeCpuMs": 2.423,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 7,
+ "elapsedMs": 9.744124999999258,
+ "nodeCpuMs": 1.196,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 7,
+ "elapsedMs": 19.69183300000077,
+ "nodeCpuMs": 10.288,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 8,
+ "elapsedMs": 22.020375000000058,
+ "nodeCpuMs": 13.11,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 8,
+ "elapsedMs": 10.392499999999927,
+ "nodeCpuMs": 3.198,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 9,
+ "elapsedMs": 10.038415999999415,
+ "nodeCpuMs": 1.195,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 9,
+ "elapsedMs": 18.73225000000093,
+ "nodeCpuMs": 15.315,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 10,
+ "elapsedMs": 19.898165999999037,
+ "nodeCpuMs": 28.374,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 10,
+ "elapsedMs": 9.879291999999623,
+ "nodeCpuMs": 1.188,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 11,
+ "elapsedMs": 9.827499999999418,
+ "nodeCpuMs": 1.146,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 11,
+ "elapsedMs": 18.700208000000202,
+ "nodeCpuMs": 13.545,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 12,
+ "elapsedMs": 18.840833000000202,
+ "nodeCpuMs": 14.648,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 12,
+ "elapsedMs": 9.808500000001004,
+ "nodeCpuMs": 1.265,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 13,
+ "elapsedMs": 9.849500000000262,
+ "nodeCpuMs": 1.18,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 13,
+ "elapsedMs": 17.91966599999978,
+ "nodeCpuMs": 12.583,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 14,
+ "elapsedMs": 19.350500000000466,
+ "nodeCpuMs": 13.604,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 14,
+ "elapsedMs": 9.841291000000638,
+ "nodeCpuMs": 1.207,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 15,
+ "elapsedMs": 9.846459000000323,
+ "nodeCpuMs": 1.157,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 15,
+ "elapsedMs": 17.839874999999665,
+ "nodeCpuMs": 10.797,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 16,
+ "elapsedMs": 18.467583999999988,
+ "nodeCpuMs": 18.189,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 16,
+ "elapsedMs": 10.060166000001118,
+ "nodeCpuMs": 1.271,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 17,
+ "elapsedMs": 9.662292000000889,
+ "nodeCpuMs": 1.164,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 17,
+ "elapsedMs": 19.58820900000137,
+ "nodeCpuMs": 9.55,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 18,
+ "elapsedMs": 18.596707999999126,
+ "nodeCpuMs": 12.115,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 18,
+ "elapsedMs": 9.906208000000333,
+ "nodeCpuMs": 1.197,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 19,
+ "elapsedMs": 9.829458000000159,
+ "nodeCpuMs": 1.137,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 19,
+ "elapsedMs": 19.275374999999258,
+ "nodeCpuMs": 11.232,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 20,
+ "elapsedMs": 18.13195900000028,
+ "nodeCpuMs": 10.246,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 20,
+ "elapsedMs": 9.807957999999417,
+ "nodeCpuMs": 1.231,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 21,
+ "elapsedMs": 9.718333000000712,
+ "nodeCpuMs": 1.149,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 21,
+ "elapsedMs": 18.861332999998922,
+ "nodeCpuMs": 21.859,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 22,
+ "elapsedMs": 17.926041999999143,
+ "nodeCpuMs": 12.592,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 22,
+ "elapsedMs": 10.091291000000638,
+ "nodeCpuMs": 1.229,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 23,
+ "elapsedMs": 9.716667000000598,
+ "nodeCpuMs": 1.164,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 23,
+ "elapsedMs": 17.310833000001367,
+ "nodeCpuMs": 10.584,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 24,
+ "elapsedMs": 19.17304199999853,
+ "nodeCpuMs": 9.284,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 24,
+ "elapsedMs": 10.013625000001412,
+ "nodeCpuMs": 1.241,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 25,
+ "elapsedMs": 9.783666999999696,
+ "nodeCpuMs": 1.173,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 25,
+ "elapsedMs": 19.634541999999783,
+ "nodeCpuMs": 25.876,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 26,
+ "elapsedMs": 18.92683399999987,
+ "nodeCpuMs": 12.465,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 26,
+ "elapsedMs": 10.104374999998981,
+ "nodeCpuMs": 1.492,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 27,
+ "elapsedMs": 10.33008300000074,
+ "nodeCpuMs": 1.147,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 27,
+ "elapsedMs": 19.879916999998386,
+ "nodeCpuMs": 10.897,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 28,
+ "elapsedMs": 19.654209000000264,
+ "nodeCpuMs": 12.004,
+ "processes": 32
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 28,
+ "elapsedMs": 10.326750000000175,
+ "nodeCpuMs": 3.003,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "batched",
+ "iteration": 29,
+ "elapsedMs": 10.35687499999949,
+ "nodeCpuMs": 1.154,
+ "processes": 1
+ },
+ {
+ "count": 32,
+ "mode": "direct",
+ "iteration": 29,
+ "elapsedMs": 22.764458999999988,
+ "nodeCpuMs": 17.324,
+ "processes": 32
+ }
+ ]
+ },
+ "summary": [
+ {
+ "count": 1,
+ "direct": {
+ "medianMs": 3.513562500000262,
+ "nodeCpuMs": 12.620999999999995,
+ "processes": 30
+ },
+ "batched": {
+ "medianMs": 3.547125000000051,
+ "nodeCpuMs": 14.187999999999997,
+ "processes": 30
+ }
+ },
+ {
+ "count": 8,
+ "direct": {
+ "medianMs": 5.986312500000167,
+ "nodeCpuMs": 108.18699999999998,
+ "processes": 240
+ },
+ "batched": {
+ "medianMs": 5.001000000000204,
+ "nodeCpuMs": 19.095,
+ "processes": 30
+ }
+ },
+ {
+ "count": 32,
+ "direct": {
+ "medianMs": 18.894083499999397,
+ "nodeCpuMs": 441.39799999999985,
+ "processes": 960
+ },
+ "batched": {
+ "medianMs": 9.892749999999978,
+ "nodeCpuMs": 41.18700000000001,
+ "processes": 30
+ }
+ }
+ ]
+}
diff --git a/docs/performance/2026-10-01-question-polling.md b/docs/performance/2026-10-01-question-polling.md
new file mode 100644
index 000000000..537b152a8
--- /dev/null
+++ b/docs/performance/2026-10-01-question-polling.md
@@ -0,0 +1,73 @@
+# Question polling: fewer tmux processes, fresh terminal reads
+
+The daemon profile identified repeated `QuestionWatcher` → `captureTerminal` →
+`captureTmuxPane` calls as its largest application call path. Each watched session
+had a separate 1.5-second timer and spawned a tmux client for every read. A slow
+read could overlap the next tick; a late result could announce a question after
+the watcher stopped. Failed reads also counted as an empty screen.
+
+The watcher now shares one 1.5-second clock. Concurrent captures share a tmux
+invocation, in groups of at most 32. The capture queue lasts one microtask and
+does not cache screen contents. A single read uses the direct capture command.
+Input-driving and Resume reads still obtain a fresh screen.
+
+Each capture has independent framing. When tmux stops a compound command at a
+missing pane, complete results are retained and unfinished reads retry separately.
+Batch output is capped at 4 MiB and individual results at 1 MiB. Each returned
+string owns its storage so a retained question cannot retain the other panes'
+output. There is no background timer in the capture queue.
+
+The watcher allows one pending poll per session. Stops, new turns, changed
+processes, changed terminal routes, and loss of an audience invalidate late
+results. It rechecks whether an answer is being entered before announcing a
+capture. A failed read breaks the consecutive-empty-read count; only two valid
+empty reads close a question. Shutdown clears the polling clock and saved
+baseline/diagnostic state.
+
+## Local measurements
+
+The committed [raw samples](2026-10-01-question-poll-data/native-macos.json) come
+from a private macOS ARM64 tmux server with recorded dialog paint, Node 22.23.2,
+five warmups, and 30 measured rounds per mode. Direct and batched modes alternate
+order. Every result is checked byte-for-byte against direct capture output.
+
+| Concurrent pane reads | tmux processes per round, direct → batched | Median wall time, direct → batched | Node CPU over 30 rounds, direct → batched |
+| --- | --- | --- | --- |
+| 1 | 1 → 1 | 3.514 → 3.547 ms | 12.621 → 14.188 ms |
+| 8 | 8 → 1 | 5.986 → 5.001 ms | 108.187 → 19.095 ms |
+| 32 | 32 → 1 | 18.894 → 9.893 ms | 441.398 → 41.187 ms |
+
+Node CPU for these reads fell about 82% with eight panes and 91% with 32 panes.
+The single-pane case has small queue overhead and essentially unchanged latency.
+The fixture measures reads that reach tmux together. In the daemon, reads that
+first await control-lease validation may reach tmux in different event-loop turns
+and therefore may not batch. Those input-safety checks are unchanged.
+These measurements exclude tmux client/server CPU, GPU work, and the desktop UI.
+Other development processes were running on the host. They do not establish a
+whole-app energy reduction or the requested 100-fold resource target.
+
+## Validation and reproduction
+
+From `cli/`:
+
+```sh
+node --import tsx scripts/question-poll-native.ts /tmp/question-poll.json
+```
+
+The native fixture creates a private tmux socket and 32 synthetic panes. It
+verifies question identity, deduplication, answer routing through the real
+controller, two-read close confirmation, stale-answer refusal, reopening,
+missing-pane isolation, failed-read preservation, and timer teardown. Its first
+shared tick used one capture process and announced all 32 questions in 1.554 s.
+It kills only its private server, verifies its remaining 31 pane processes exit
+(one was deliberately removed earlier), and removes its temporary files.
+The dialog fixture clears both screen and history when dismissing a question;
+it uses recorded terminal paint, not a live model or an authenticated engine.
+
+The manual CI workflow runs this native fixture on Linux x64 and ARM64 as well.
+Unit regressions cover slow and overlapping reads, stop/restart races, stale
+turn-start baselines, process/PID replacement, changed routes, audience changes,
+answer-in-flight changes, unavailable captures, bounded output, and malformed
+targets. Actual Claude/Codex lifecycle checks run separately through
+`scripts/resume-native-e2e.ts`; no installed app or user session is replaced by
+these fixtures.