Harden agent transport recovery and diagnostics
Root cause
Direct agent CLIs were always spawned with a piped stdin. The worker opened the
sidechannel around startup and closed the unused pipe after a delay, but Codex
had already detected non-TTY stdin and entered its additional-input lifecycle.
When that process exited, the SDK retained only a generic nonzero code and
stderr. The kernel then conflated semantic iteration with infrastructure
recovery: crashes consumed no semantic iteration and therefore had no separate
bound, while f.agent() exposed no recovery controls.
Change
- Open the sidechannel before spawn and decide the child stdin contract during a
bounded pre-spawn enrollment window. An unattended CLI starts with stdin
ignored/EOF; only an already-connecteddrivepeer gets a pipe. - Journal bounded, redacted direct-transport evidence: phase, cause, exit code,
signal, safe OS error code, retryability, and stderr tail. - Classify only a closed set of transport failures as
crashed: signal close,
close without status, selected transient spawn errors, and the exact historical
Codex stdin-lifecycle signature. Ordinary nonzero exits stay terminal
worker_error; timeout staystimeout. - Add
maxIterations,transportRetries, andrecoveryModetof.agent(),
authored lowering, YAML/kernel compilation, reverse compilation, diagnostics,
docs, and examples. - Split semantic and transport retry budgets in the kernel. The transport budget
is deterministic and bounded across both reported crashes and abandoned
leases; replacement attempts preserve the idempotency key and pinned revisions. - Add the direct Codex lifecycle fixture plus SDK, authored-flow, compiler,
diagnostic, kernel, pin/idempotency, exhaustion, and crash/resume tests.
Compatibility and safety
maxIterationsremains 1 by default.transportRetriesdefaults to one additional classified infrastructure
attempt, preserving the existing one-crash resume contract while removing the
former unbounded loop. Explicit0disables transport recovery.- The SDK omits an undeclared transport budget, preserving legacy canonical
authored specs and hashes; an explicitly authored zero round-trips. reset,inspect, andmanualretain the RFC Appendix A recovery meanings.- The authored root now has one semantic iteration plus seven transport retries,
so a returned bodyworker_errorcannot replay semantic side effects while a
genuinely lost process remains resumable.
Verification evidence
Rust workspace
Command:
export PATH="$HOME/.rustup/toolchains/stable-aarch64-apple-darwin/bin:$PATH" CARGO_INCREMENTAL=0 CARGO_PROFILE_TEST_DEBUG=0
../ops/cargo.sh test --workspace --quiet
Captured result lines, in test-binary execution order (exit 0):
test result: ok. 51 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 40 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 67 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 32 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
The toolchain also emitted non-fatal rust-objcopy warnings because its
libLLVM.dylib is absent; the command exited 0 and every test binary above
completed.
SDK supported runtime suite
Command:
export RELAYFLOWD_BIN="$HOME/.relayflows-toolchain/target/1166253295/debug/relayflowd"
npx vitest run --exclude tests/authored-node-runtime.test.ts
Captured output:
Test Files 145 passed | 1 skipped (146)
Tests 2357 passed | 3 skipped (2360)
Duration 100.20s
SDK typecheck and build
Command:
npm run typecheck && npm run typecheck:tests && npm run build
Captured output (exit 0):
> @relayflows/sdk@2.0.22 typecheck
> tsc --noEmit && tsc -p tsconfig.type-tests.json
> @relayflows/sdk@2.0.22 typecheck:tests
> tsc -p tsconfig.tests.json
> @relayflows/sdk@2.0.22 build
> tsc && node scripts/make-cli-executable.mjs
Surface and packed-consumer gates
Commands:
cd packages/surface && npm test
bash scripts/surface-package-gate.sh
Captured output:
Test Files 9 passed (9)
Tests 46 passed (46)
PACKED_RUNTIME_OK name=packed-runtime-consumer completionReason=success
PACKED_RUNTIME_REFUSAL_OK invalidHeaders=9 forgedHandle=refused
PACKED_TYPESCRIPT_OK
Test Files 1 passed (1)
Tests 26 passed (26)
packages/surface build, main typecheck, and regression typecheck also exited 0.
Review follow-up at exact head 139690f7
The review delta closes the manual-recovery gap: worker-reported crashed or lease_expired completions now park under recoveryMode: manual before consulting the retry budget, including a zero budget. The wait.human append uses the journaled start pin, and resume repairs a process death between the park placeholder and wait append idempotently. The general timer test again requires a retryable crash, max_transport_retries is always journaled, and older journals still read through the serde default. Internal helpers remain crate-private.
Committed literal evidence is under kernel/evidence/501/, including mutation-transcript.txt (red mutations, checksummed restore, green rerun), green-kernel.txt, green-sdk-authored-node-runtime.txt, and codex-live-probe.txt.
Exact-head local commands and captured result excerpts:
$ ../ops/cargo.sh test --workspace --quiet
...
test result: ok. 53 passed; 0 failed
test result: ok. 41 passed; 0 failed
test result: ok. 72 passed; 0 failed
exit_code=0
$ ../ops/cargo.sh test -p relayflowd-core --lib -- machine::recovery_tests
test result: ok. 3 passed; 0 failed
$ ../ops/cargo.sh test -p relayflowd --test manual_recovery
test result: ok. 2 passed; 0 failed
$ ../ops/cargo.sh test -p relayflowd --test crash_resume manual_recovery
test result: ok. 1 passed; 0 failed; 40 filtered out
$ npm ci --ignore-scripts
$ npm install --no-save --package-lock=false --ignore-scripts ../../dist/publish/relayflows-surface-2.0.22.tgz
$ npm run typecheck && npm run typecheck:tests && npm run build
exit_code=0
$ RELAYFLOWD_BIN=... npx vitest run tests/pty-sidechannel.test.ts tests/worker-cli.test.ts tests/authored-flow.test.ts tests/step-failure-diagnostic.test.ts
Test Files 4 passed (4)
Tests 82 passed (82)
$ RELAYFLOWD_BIN=... npx vitest run tests/authored-root.test.ts tests/authored-agent-permissions.test.ts tests/authored-run-failure-evidence.test.ts tests/deterministic-llm.test.ts tests/spec-parity.test.ts tests/verb-field-lint.test.ts tests/agent-transcript-live.test.ts
Test Files 7 passed (7)
Tests 185 passed (185)
$ cd packages/schema && npm test -- --run tests/parity.test.ts
80 pass
0 fail
Repository-wide gate blockers (reported, not hidden)
../ops/cargo.sh fmt --all -- --checkexits 1 on existing formatting drift
across files includingrelayflowd/src/engine/remote.rs,relayflowd/src/lib.rs,
crash fixtures, schema, memory, and state. First captured hunk:
Diff in /Users/khaliqgant/Projects/AgentWorkforce/flows/kernel/relayflowd/src/engine/remote.rs:434:
- answer.insert(
- "attribution".to_owned(),
- Value::from("client_asserted"),
- );
+ answer.insert("attribution".to_owned(), Value::from("client_asserted"));
../ops/cargo.sh clippy --workspace -- -D warningsexits 101 on three existing
collapsible_iffindings:
relayflowd-core/src/schema.rs:125
relayflowd-core/src/spec.rs:77
relayflowd-core/src/memoization.rs:102
- The excluded standalone authored-node-runtime suite cannot launch under the
installed Node 26.7.0:
/opt/homebrew/Cellar/node/26.7.0/bin/node: bad option: --experimental-transform-types
packages/surface npm run typecheck:exampleshas existing URL-global errors:
../../workflows/stuck-run-triage.flow.ts(77,12): error TS2304: Cannot find name 'URL'.
../../workflows/stuck-run-triage.flow.ts(79,15): error TS2552: Cannot find name 'URL'. Did you mean 'url'?
No merge is requested; this PR is ready for independent review at commit
139690f754805ee961bb7f12e2c5d0f4f8b72f46.
[!NOTE]
High Risk
Changes core kernel retry, journaling, and agent recovery semantics (including manual park and dispatch refusal), which directly affect run durability and idempotency across crashes and worker attachment.
Overview
Introduces a bounded transport retry budget (transportRetries / retry.max_transport_retries, default one) separate from maxIterations, so classified infrastructure loss (crashed, lease_expired) can redispatch without consuming semantic iterations while ordinary worker_error and verification failures stay terminal. step.attempt.started now always journals max_transport_retries (including explicit zero).
recoveryMode: manual is honored consistently when the worker reports transport loss: the step parks with wait.human anchored on journaled start pins, matching the abandoned-lease path. Resume repairs a torn park (completion without the wait append). Pin-mismatch refusals before dispatch use refused_dispatch_actions to re-elect under max_iterations without treating them like a worker failure.
Docs and examples document f.agent controls, richer failure diagnostics (transport phase/cause/signal), and PTY drive enrollment before spawn (stdin ignored unless drive connects in the window). Adds PR #501 evidence (kernel tests, mutation checks, SDK gates) and registers transportRetries in authored step fields.
Reviewed by Cursor Bugbot for commit e55317cf27e92c2990d14b0cbd844eea521dbadf. Bugbot is set up for automated code reviews on this repo. Configure here.
Agent Relay sessions