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.

Core boundary, part 14: permissions end to end, and a soak that proves memory settles (#743)

Deea6e7b863b6ab
diff --git a/cli/e2e/harness/fakeEngine.mjs b/cli/e2e/harness/fakeEngine.mjs
index bf0af59ae..4c55727f9 100644
--- a/cli/e2e/harness/fakeEngine.mjs
+++ b/cli/e2e/harness/fakeEngine.mjs
@@ -12,8 +12,9 @@
// `!tool <command>` runs a tool call first, `!grow <MiB>` appends that much compaction history
// before answering (the transcripts that crashed the daemon on 2026-10-03), `!hold` leaves the turn
// open until the next prompt, `!ask` asks the person which drink they would like in the engine's own
-// dialog and answers with their choice, `!exit` ends the process. Everything else is echoed as the
-// answer.
+// dialog and answers with their choice, `!permit <command>` asks permission to run a command the way
+// the engine does and runs it only if allowed, `!exit` ends the process. Everything else is echoed as
+// the answer.
import { randomUUID } from 'node:crypto'
import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { dirname, join } from 'node:path'
@@ -101,7 +102,16 @@ export async function run(engine, config) {
const drawDialog = () => {
const rule = '─'.repeat(60)
const mark = (i, on) => (dialog.cursor === i ? on : ' ')
- const lines = engine === 'claude'
+ // A permission prompt, as the CLIs draw one (__fixtures__/permission-claude.txt, permission-codex.txt).
+ const command = dialog.command
+ const lines = dialog.kind === 'permit' ? (engine === 'claude'
+ ? [rule, ' Bash command', ` ${command}`, ' Run the command', ' This command requires approval', ' Do you want to proceed?',
+ ...['Yes', `Yes, and don’t ask again for: ${command} *`, 'No'].map((label, i) => `${dialog.cursor === i ? ' ❯ ' : ' '}${i + 1}. ${label}`),
+ ' Esc to cancel · Tab to amend · ctrl+e to explain']
+ : [` $ ${command}`, '',
+ `${mark(0, '›')} 1. Yes, proceed (y)`, `${mark(1, '›')} 2. Yes, and don't ask again for commands that start with \`${command}\` (p)`,
+ `${mark(2, '›')} 3. No, and tell Codex what to do differently (esc)`, '', ' Press enter to confirm or esc to cancel'])
+ : engine === 'claude'
? [rule, ' ☐ Drink', '', QUESTION, '',
...CHOICES.flatMap(([label, description], i) => [`${mark(i, '❯')} ${i + 1}. ${label}`, ` ${description}`]),
' 3. Type something.', rule, ' 4. Chat about this', '', 'Enter to select · ↑/↓ to navigate · Esc to cancel']
@@ -122,7 +132,15 @@ export async function run(engine, config) {
for (const key of chunk.match(/\x1b\[[AB]|\x1b|\r|\n|./gs) ?? []) {
if (!dialog) return
const settle = (choice) => { eraseDialog(); const asked = dialog; dialog = null; asked.resolve(choice) }
- const rows = engine === 'claude' ? CHOICES.length : CHOICES.length + 1
+ const rows = dialog.kind === 'permit' ? 3 : engine === 'claude' ? CHOICES.length : CHOICES.length + 1
+ if (dialog.kind === 'permit') {
+ // Both CLIs take a row's digit (and Codex its letter) as the decision; Esc declines.
+ if (key === '\x1b') settle(null)
+ else if (key === 'y' && engine === 'codex') settle(0)
+ else if (key === '\r' || key === '\n') settle(dialog.cursor)
+ else if (/^[1-3]$/.test(key)) settle(Number(key) - 1)
+ continue
+ }
if (key === '\x1b[B') { dialog.cursor = Math.min(dialog.cursor + 1, rows - 1); drawDialog() }
else if (key === '\x1b[A') { dialog.cursor = Math.max(dialog.cursor - 1, 0); drawDialog() }
else if (key === '\x1b') settle(null)
@@ -187,6 +205,24 @@ export async function run(engine, config) {
}
}
if (directive?.[1] === 'hold') return
+ if (directive?.[1] === 'permit') {
+ const command = directive[2] || 'printf hi'
+ await new Promise((resolve) => setTimeout(resolve, 2_000))
+ const row = await new Promise((resolve) => { dialog = { kind: 'permit', command, cursor: 0, drawn: 0, resolve }; drawDialog() })
+ const allowed = row === 0 || row === 1
+ const id = `call_${turn}_p`
+ if (allowed) {
+ if (engine === 'claude') {
+ claude({ type: 'assistant', message: { id: `msg_${turn}_p`, role: 'assistant', model: config.claudeModel ?? 'claude-opus-5-5', content: [{ type: 'tool_use', id, name: 'Bash', input: { command } }], stop_reason: 'tool_use' } })
+ claude({ type: 'user', message: { role: 'user', content: [{ type: 'tool_result', tool_use_id: id, content: `ran ${command}` }] } })
+ } else {
+ codex('response_item', { type: 'function_call', call_id: id, name: 'exec_command', arguments: JSON.stringify({ cmd: command }) })
+ codex('response_item', { type: 'function_call_output', call_id: id, output: `ran ${command}` })
+ }
+ }
+ finish(allowed ? `ran ${command}` : `did not run ${command}`)
+ return
+ }
if (directive?.[1] === 'ask') {
// A real engine thinks before it asks; a dialog already on screen when its turn began reads to the
// daemon as the previous turn's (askQuestion.ts `noteTurnStart`).
diff --git a/cli/e2e/questions.e2e.ts b/cli/e2e/questions.e2e.ts
index af4b3900a..b26439ed0 100644
--- a/cli/e2e/questions.e2e.ts
+++ b/cli/e2e/questions.e2e.ts
@@ -1,7 +1,8 @@
/**
* An agent's question, end to end, for Claude Code and Codex: the dialog the engine draws reaches the
* window as a question, the answer chosen there is typed into the dialog and is the one the agent gets,
- * and an answer to a question that is no longer the one on screen types nothing.
+ * and an answer to a question that is no longer the one on screen types nothing. A permission prompt
+ * is a question too: Yes in the window runs the command, No leaves it unrun.
*/
import { mkdirSync } from 'node:fs'
import { join } from 'node:path'
@@ -72,6 +73,26 @@ describe('an agent asks a question', () => {
client.close()
})
+ it.each(engines)('%s: a permission the agent asks for reaches the window, and Yes there runs the command, No does not', async (engine) => {
+ const d = await fresh()
+ const client = await LocalClient.connect(d)
+ const agent = await create(d, client, engine, `permit-${engine}`)
+ for (const [choice, outcome] of [[0, 'ran printf hi'], [2, 'did not run printf hi']] as const) {
+ const asked = client.next((frame) => frame.type === 'commander_question' && frame.agentId === agent.id, 30_000, 'commander_question')
+ client.send('message', { agentId: agent.id, content: '!permit printf hi' })
+ const question = await asked
+ const shaped = question.payload?.questions?.[0]
+ expect(shaped?.q).toContain('printf hi')
+ expect(shaped?.options).toHaveLength(3)
+ const ended = client.next(isTurn('turn_ended', agent.id), 45_000, 'turn_ended')
+ const result = await answer(client, agent.id, question.payload.requestId, { [shaped.q]: shaped.options[choice] })
+ expect(result.error, JSON.stringify(result)).toBeUndefined()
+ await ended
+ expect(await d.capture(agent.tmuxPane)).toContain(outcome)
+ }
+ client.close()
+ })
+
it.each(engines)('%s: an answer to a question that is not the one on screen types nothing', async (engine) => {
const d = await fresh()
const client = await LocalClient.connect(d)
diff --git a/cli/e2e/soak.e2e.ts b/cli/e2e/soak.e2e.ts
new file mode 100644
index 000000000..75945c80f
--- /dev/null
+++ b/cli/e2e/soak.e2e.ts
@@ -0,0 +1,76 @@
+/**
+ * A desk of agents working, for Claude Code and Codex, on the real daemon: two of each run turn after
+ * turn together, and the core's memory and open files settle instead of growing with them. A leak per
+ * turn shows here long before it shows on a machine that has been running for a week.
+ */
+import { execFile } from 'node:child_process'
+import { mkdirSync, writeFileSync } from 'node:fs'
+import { join } from 'node:path'
+import { promisify } from 'node:util'
+import { afterEach, describe, expect, it, onTestFailed } from 'vitest'
+import { LocalClient, type Frame } from './harness/client.js'
+import { IsolatedDaemon, until } from './harness/daemon.js'
+
+const exec = promisify(execFile)
+const ROUNDS = Number(process.env.SOAK_ROUNDS ?? 40)
+
+const row = async (client: LocalClient, agentId: string) =>
+ ((await client.request<{ agents: Array<Record<string, any>> }>('agents_list', {}, 30_000)).agents).find((agent) => agent.id === agentId)
+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 ended = client.next(isTurn('turn_ended', agentId), 60_000, `turn_ended (${content})`)
+ client.send('message', { agentId, content })
+ await ended
+}
+async function openFiles(pid: number | null): Promise<number> {
+ if (!pid) return 0
+ const { stdout } = await exec('lsof', ['-n', '-P', '-p', String(pid)]).catch(() => ({ stdout: '' }))
+ return stdout.trim().split('\n').length
+}
+/** 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 desk of agents working', () => {
+ let daemon: IsolatedDaemon | undefined
+ afterEach(async () => { await daemon?.close(); daemon = undefined })
+
+ it(`four agents, ${ROUNDS} rounds of turns together: memory and open files settle`, async () => {
+ const d = await IsolatedDaemon.create()
+ daemon = d
+ onTestFailed(() => { console.log(`---- daemon log\n${d.log().split('\n').slice(-80).join('\n')}`) })
+ await d.start()
+ const client = await LocalClient.connect(d)
+ const ids: string[] = []
+ for (const [i, engine] of (['claude', 'codex', 'claude', 'codex'] as const).entries()) {
+ const cwd = join(d.projectsDir, `desk-${i}`)
+ mkdirSync(cwd, { recursive: true })
+ const created = await client.request('agent_create', { engine, cwd, bypassPermission: true }, 90_000)
+ expect(created.error, JSON.stringify(created)).toBeUndefined()
+ ids.push(created.agent.id)
+ }
+ for (const id of ids) await until(`${id.slice(0, 8)} to bind`, async () => (await row(client, id))?.sessionId || null, 60_000, 500)
+
+ // Warm: pools, caches and the first transcripts reach their working size.
+ for (let round = 0; round < 5; round++) await Promise.all(ids.map((id) => turn(client, id, `warm ${round}`)))
+ const rssBefore = await settledRss(d)
+ const filesBefore = await openFiles(d.corePid())
+
+ for (let round = 0; round < ROUNDS; round++) {
+ await Promise.all(ids.map((id) => turn(client, id, `round ${round} — ${'some words '.repeat(20)}`)))
+ // The client keeps only what it still needs, so its own memory is not the one measured.
+ client.frames.splice(0, client.frames.length)
+ }
+ const rssAfter = await settledRss(d)
+ const filesAfter = await openFiles(d.corePid())
+ const report = `rss ${rssBefore.toFixed(1)} → ${rssAfter.toFixed(1)} MiB · open files ${filesBefore} → ${filesAfter} · ${ROUNDS * ids.length} turns`
+ if (process.env.SOAK_REPORT) writeFileSync(process.env.SOAK_REPORT, `${report}\n`)
+ expect(rssAfter - rssBefore, report).toBeLessThan(96)
+ expect(filesAfter - filesBefore, report).toBeLessThan(16)
+ expect(d.coresStarted()).toBe(1)
+ client.close()
+ })
+})
diff --git a/docs/design/2026-10-03-harnessd.md b/docs/design/2026-10-03-harnessd.md
index c3cd9a850..9f7dfc693 100644
--- a/docs/design/2026-10-03-harnessd.md
+++ b/docs/design/2026-10-03-harnessd.md
@@ -549,6 +549,9 @@ Found while mapping, and fixed on their own rather than inside a move:
with no `turn_ended` (which would recap a killed turn). The fifth round
(`e2e/questions.e2e.ts`) proves an agent's question end to end for both engines: the dialog reaches
the window, the answer chosen there is the one the agent gets, and a stale answer types nothing.
+ - Part 14: a permission prompt the same way (Yes in the window runs the command, No does not), and
+ a soak (`e2e/soak.e2e.ts`): 2,400 turns across two Claude Code and two Codex agents left the
+ core's memory flat (246.7 → 244.7 MiB) and its open files at 33.
## Testing