Skip to content

Commit 33cd213

Browse files
authored
fix(stream): a child's pipe must not kill the run that owns it (#42)
A killed child's stdout and stderr can emit `error` after the fact, and a stream with no error listener throws to the top of the process. Measured: a 42-cell study died at cell 3 on an unhandled EPIPE, after two cells had already cost twenty minutes each. `stdin` was handled and reported the policy that stopped reading; the other two pipes had `resume()` and a data listener and no error listener at all. The child's fate already reaches an operator through `health()`, so these listeners record into the same bounded buffer that explains a dead agent and do not rethrow. Both launchers get the same treatment, because a launcher's job is to outlive its agent long enough to publish the meter.
1 parent bd72038 commit 33cd213

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

‎drivers/stream-sandbox.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,17 @@ export function createStreamSandboxDriver(options: StreamSandboxDriverOptions):
285285
// The agent's own output is not an action channel: actions arrive through
286286
// the file. Its stderr is still kept, bounded, because it is the only thing
287287
// that can explain an agent which never wrote an action.
288+
// A killed child's pipes can emit `error` after the fact, and a stream with
289+
// no error listener throws to the top of the process. MEASURED: a 42-cell
290+
// study died at cell 3 on an unhandled `EPIPE` from one of these, after two
291+
// cells had already cost twenty minutes each. The child's fate is already
292+
// reported through `health()`, so these listeners record and do not rethrow.
293+
started.stdout?.on('error', (error: Error) => {
294+
if (agentStderr.length < 4096) agentStderr += `\n[stdout] ${error.message}`
295+
})
296+
started.stderr?.on('error', (error: Error) => {
297+
if (agentStderr.length < 4096) agentStderr += `\n[stderr] ${error.message}`
298+
})
288299
started.stdout?.resume()
289300
started.stderr?.setEncoding('utf8')
290301
started.stderr?.on('data', (chunk: string) => {

‎harnesses/author-policy‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ function account(event) {
214214
publish()
215215

216216
const child = spawn(command, args, { cwd: sandbox, stdio: ['ignore', 'pipe', 'inherit'] })
217+
// A pipe to a killed child emits `error`, and a stream with no listener throws
218+
// to the top of the process. This launcher's whole job is to outlive its agent
219+
// long enough to publish the meter, so it cannot die on the agent's pipe.
220+
child.stdout.on('error', (error) => console.error(`playproof: agent stdout: ${error.message}`))
217221
let carry = ''
218222
child.stdout.setEncoding('utf8')
219223
child.stdout.on('data', (chunk) => {

‎harnesses/claude-code‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ function account(event) {
223223
publish()
224224

225225
const child = spawn(command, args, { cwd: sandbox, stdio: ['ignore', 'pipe', 'inherit'] })
226+
// A pipe to a killed child emits `error`, and a stream with no listener throws
227+
// to the top of the process. This launcher's whole job is to outlive its agent
228+
// long enough to publish the meter, so it cannot die on the agent's pipe.
229+
child.stdout.on('error', (error) => console.error(`playproof: agent stdout: ${error.message}`))
226230
let carry = ''
227231
child.stdout.setEncoding('utf8')
228232
child.stdout.on('data', (chunk) => {

0 commit comments

Comments
 (0)