Fleet-spawned Devin blocks on interactive directory trust prompt

Merged
AG
2mo ago
+707-35

Fail closed on Devin directory-trust prompts during fleet spawn

A Devin process could remain live on its directory-trust menu without executing
its task. The broker now detects the menu during startup, blocks readiness, and
reports directory_trust_required once it remains unresolved for 30 seconds
from first detection. Verification ticks enforce the deadline even on a frozen
screen. Verified fleet spawns return spawn_directory_trust_required and release
the worker through existing cleanup. Error messages contain fixed remediation,
not terminal output. Already-trusted workers still become ready and begin work.

This implements Part 1 of reviewed-plan.md. Automatic trust acceptance
(Part 2) is deferred as required by its capture gate: this environment has no
Devin executable or raw trust-screen captures, and no reporting-node access was
available. devin --help / devin trust --help inspection and real normal-width
and 40-column captures remain prerequisites. No speculative keystrokes, trust
file modifications, or broad trust settings are introduced. Fresh-home automatic
acceptance and task execution are therefore not implemented or proven.

For unverified (confirm: false) spawns the worker error is emitted, but existing
behavior leaves the harness alive; verified-spawn cleanup is what releases
capacity. Validation below ran on Linux with a synthetic Python PTY fixture;
it does not constitute real Devin or macOS validation of the reported incident.

Changes

  • Recognize recorded directory/authors/workspace questions and corroborating
    choices, including wrapped text; scope the startup gate to Devin.
  • Anchor the failure deadline to detection, report once, and avoid retroactively
    failing workers already released through readiness or fallback.
  • Route the specific failure through generation-checked fleet cleanup and CLI
    failure pass-through; preserve Muse behavior and Claude trust parsing.
  • Add isolated-home PTY regressions for frozen, wrapped and scope-widening menus
    (no input sent), plus already-trusted readiness and task submission. Add unit
    coverage for deadline semantics, cleared prompts, CLI scoping, and capacity
    cleanup after a stale-generation error followed by the current generation.
  • Update the Devin documentation and patch changelog. No workflow changes.

Validation

  • env -u GIT_CONFIG_COUNT ~/.cargo/bin/cargo test -p agent-relay-broker:
    1,378 unit tests and 23 integration tests passed; 5 existing tests ignored.
    The initial default-environment run passed 1,374 unit tests and failed four
    existing hook-chain tests because the runner injects core.hooksPath.
    Removing the inherited Git config injection only for the test process made
    all four pass; no repository or global Git configuration was changed.
  • ~/.cargo/bin/cargo test -p relay-pty: 260 unit tests and 3 unchanged
    Claude raw-capture regressions passed; 1 existing doc test ignored
    .
  • npx vitest run packages/cli/src/cli/lib/fleet-spawn-confirmation.test.ts:
    26 passed.
  • cargo fmt --all --check and git diff --check: passed.

New PTY integration output (cargo test -p agent-relay-broker --test devin_trust_cli -- --nocapture):

    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.21s
     Running tests/devin_trust_cli.rs (target/debug/deps/devin_trust_cli-e4581ac805f4e550)

running 4 tests
test already_trusted_directory_becomes_ready_and_begins_task ... ok
test fresh_home_frozen_trust_prompt_fails_without_readiness ... ok
test wrapped_workspace_trust_prompt_fails_without_readiness ... ok
test widening_only_trust_menu_is_never_accepted ... ok

test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 30.21s

Full broker suite result lines:

test result: ok. 1378 passed; 0 failed; 5 ignored; 0 measured; 0 filtered out; finished in 40.13s
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 30.21s
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Full relay-pty suite result lines:

test result: ok. 260 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.56s
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
test result: ok. 0 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.00s

Diff statistics (excluding this summary):

 .../compacted/compact_d6sq3rpl6inr_2026-10-06.json |  48 ++++++
 .../compacted/compact_d6sq3rpl6inr_2026-10-06.md   |  21 +++
 CHANGELOG.md                                       |   6 +-
 crates/broker/src/pty_worker.rs                    | 181 ++++++++++++++++++++-
 crates/broker/src/runtime/fleet.rs                 |   8 +
 crates/broker/src/runtime/tests.rs                 |  65 ++++++++
 crates/broker/src/runtime/worker_events.rs         |   7 +
 crates/broker/tests/devin_trust_cli.rs             | 179 ++++++++++++++++++++
 crates/relay-pty/src/terminal.rs                   |  41 +++++
 docs/harnesses/devin.md                            |  11 ++
 .../src/cli/lib/fleet-spawn-confirmation.test.ts   |   6 +-
 11 files changed, 564 insertions(+), 9 deletions(-)

Checks

Relayflow ran this repository's checks (.relayflow/check.sh) and they passed.

What ran (.relayflow/check.sh)
#!/bin/sh
# Fresh-machine CI check for this repo.
#
# Mirrors the `test` job of .github/workflows/test.yml (install -> build ->
# guard tests -> vitest) plus the codegen sync check from
# .github/workflows/codegen-models.yml and the Rust tests from
# .github/workflows/rust-ci.yml.
set -e

cd "$(dirname "$0")/.."

# CI sets this for every workflow so no run emits telemetry.
export AGENT_RELAY_TELEMETRY_DISABLED=1

# A CI runner has no ambient Relay configuration, but this machine may: the
# harness that invokes this script exports RELAY_BASE_URL, and the CLI reads
# RELAY_*/AGENT_RELAY_* straight off process.env, so tests that assert a bare
# client inherits no gateway would fail on the host's value instead of the
# change under test. Drop the whole family (minus the telemetry switch above)
# so the suite sees the same empty environment CI gives it.
for relay_var in $(env | sed -n 's/^\(RELAY_[A-Z0-9_]*\|RELAYCAST_[A-Z0-9_]*\|AGENT_RELAY_[A-Z0-9_]*\)=.*/\1/p'); do
  if [ "$relay_var" != "AGENT_RELAY_TELEMETRY_DISABLED" ]; then
    unset "$relay_var"
  fi
done

# Same story for git: the invoking harness pins core.hooksPath=/dev/null through
# the GIT_CONFIG_* override family, which disables every git hook process-wide.
# The broker's spawner tests commit through real pre-commit/prepare-commit-msg
# hooks to prove its attestation hook chains instead of replacing them, so they
# only pass against the unmanaged git a CI runner has.
for git_var in $(env | sed -n 's/^\(GIT_CONFIG_[A-Z0-9_]*\)=.*/\1/p'); do
  unset "$git_var"
done

# --- Dependencies -----------------------------------------------------------
npm ci

# CI installs rollup separately to work around npm's optional-dependency
# resolution bug; it is allowed to fail there too.
npm install --no-save rollup || true

# --- Code generation --------------------------------------------------------
# codegen-models.yml regenerates these from packages/utils/cli-registry.yaml
# and fails the PR when the committed output is stale.
npm run codegen:models
git diff --quiet packages/config/src/cli-registry.generated.ts packages/sdk-py/src/agent_relay/models.py || {
  echo "Generated models are out of sync with cli-registry.yaml. Run 'npm run codegen:models' and commit the changes." >&2
  exit 1
}

# --- Build ------------------------------------------------------------------
# `npm test` would run this itself via `pretest`; doing it explicitly here and
# calling vitest directly below keeps the build to a single pass.
# `build:rust` inside this skips the broker build when cargo is absent
# (published installs take the broker from platform optional dependencies).
npm run build

# --- Tests ------------------------------------------------------------------
# Guard suites the test job runs ahead of vitest.
node --test scripts/pr-proof/broker-transfer.test.mjs scripts/pr-proof/run-cloud.test.mjs scripts/flows/deploy-listeners.test.mjs scripts/pr-proof/event-from-input.test.mjs
npm run test:subscriptions:proof

# Equivalent to `npm test` (its pretest build already ran above).
npx vitest run

# Rust crates (crates/broker, crates/relay-pty). rust-ci.yml also runs
# `cargo test --release`, clippy, fmt and cross-compile checks; the debug test
# run is the coverage that matters here. Skipped entirely when no toolchain is
# installed.
# rust-ci.yml installs the toolchain with dtolnay/rust-toolchain, which leaves
# cargo on PATH. A rustup install on this machine puts it in ~/.cargo/bin, which
# is not on the invoking shell's PATH -- without this the whole Rust suite takes
# the "no toolchain" branch below and silently reports nothing.
if [ -x "$HOME/.cargo/bin/cargo" ]; then
  PATH="$HOME/.cargo/bin:$PATH"
  export PATH
fi

# This machine has a 10G disk and target/ already holds ~6G of artifacts. The
# debug profile's incremental caches add ~2.6G on top, which is what filled the
# volume and made the whole vitest run collapse into ENOSPC. The compiled test
# binaries are identical either way.
export CARGO_INCREMENTAL=0

if command -v cargo >/dev/null 2>&1; then
  cargo test
else
  echo "Skipping cargo test: no Rust toolchain on this machine."
fi

# Not run here, and why:
# - Coverage upload (test.yml `coverage`): needs a Codecov token.
# - `npm run lint` / `npm run format:check`: separate CI jobs, not tests.
# - E2E / fleet / stress / eval suites (e2e-tests.yml, fleet-e2e.yml,
#   stress-tests.yml, relay-evals.yml) and `smoke:prod`: need real agent CLIs,
#   provider API keys, a live broker, cloud credentials or a Daytona account.
# - Swift SDK tests (test.yml `swift-test`): macOS runner with a Swift
#   toolchain.
# - Windows credential ACL tests (test.yml `windows-credential-acl`): require
#   a Windows runner.
# - Publish/package-qualification workflows: npm registry credentials.

What the repair agent found

Repair notes

All failures on this branch came from the check environment, not from the
Devin directory-trust change in b9162ce. No source or test file was modified;
every fix landed in .relayflow/check.sh (uncommitted, git-excluded).

Fixed as missing setup

  1. Disk exhaustion (the original cascade). The volume was 100% full (22M
    free), so 71 vitest files failed with ENOSPC — bun build --compile
    could not copy its executable and vite could not write its SSR cache.
    These were not test failures at all. Freed by dropping
    target/debug/incremental (2.6G), and CARGO_INCREMENTAL=0 now keeps it
    from coming back: target/ already holds ~6G on a 10G disk.

  2. RELAY_BASE_URL leaking from the harness. The invoking harness exports
    RELAY_BASE_URL=https://cast.agentrelay.com. The CLI reads RELAY_* off
    process.env, so two tests that assert a bare client inherits no gateway
    read the host's value instead:

    • packages/cli/src/cli/lib/sdk-client.test.ts — "does not inherit a
      persisted gateway when an explicit agent token is supplied"
    • packages/cli/src/cli/commands/fleet-lifecycle-integration.test.ts —
      "reuses the persisted Cloud target across spawn, attach, message, list,
      and release without --base-url"

    check.sh now unsets the whole RELAY_*/RELAYCAST_*/AGENT_RELAY_*
    family (keeping only AGENT_RELAY_TELEMETRY_DISABLED, which CI sets),
    matching the empty environment a CI runner provides.

  3. GIT_CONFIG_* pinning core.hooksPath=/dev/null. The harness disables
    every git hook process-wide through the GIT_CONFIG_KEY_*/VALUE_*
    override family. Four broker tests commit through real
    pre-commit/prepare-commit-msg hooks to prove the attestation hook
    chains to them rather than replacing them, so all four failed:
    spawner::tests::broker_hook_chain_execs_{a_home_relative_configured_hooks_path, a_repository_configured_hooks_path, the_repository_prepare_commit_msg_hook, the_repositorys_pre_commit_hook}. check.sh now unsets GIT_CONFIG_*.

  4. Rust suite silently skipped. cargo is installed at ~/.cargo/bin but
    is absent from the invoking shell's PATH, so command -v cargo failed and
    the script took its "no Rust toolchain" branch — reporting nothing for the
    crates that carry the bulk of this branch's change. check.sh now prepends
    ~/.cargo/bin when present, matching CI, where dtolnay/rust-toolchain
    leaves cargo on PATH. With it on, this branch's own regression tests run
    and pass (crates/broker/tests/devin_trust_cli.rs, 4 tests).

Observed once, not reproducible, left alone

relay-pty's codex_session::tests::create_resumable_codex_thread_scrubs_explicit_node_identity
failed once with Text file busy (os error 26) while exec'ing the fake codex
shell script it writes to a temp dir. This is the standard ETXTBSY fork/exec
race: a sibling test in the same binary forks while this test's write fd is
still open, the child inherits the fd, and the exec then sees the file as open
for writing. It is unrelated to this branch (nothing here touches
codex_session.rs) and it appeared only on the disk-pressure run. It did not
recur in 6 isolated runs, 2 full cargo test runs, or the final green
check.sh, so I left the test as-is rather than reworking an unrelated
harness.

Final state

./.relayflow/check.sh exits 0: vitest 3660 passed / 24 skipped, guard suites
67 + 99 passed, Rust 1378 + 260 + 26 passed across all crates.

Fixes #1824


[!NOTE]
Medium Risk
Changes PTY startup gating and fleet spawn failure paths for Devin; incorrect trust detection could block legitimate spawns or miss stuck workers, but scope is CLI-specific with extensive tests and no auto-approval of security prompts.

Overview
Fleet-spawned Devin workers no longer sit live on the directory-trust menu without running tasks. The broker now treats Devin’s trust interstitial as a blocking startup gate, blocks readiness and injection, and after 30 seconds from first detection emits a terminal worker_error with code directory_trust_required (fixed remediation text, no terminal leakage).

Detection is Devin-scoped: new screen heuristics in relay-pty require question + choice (including wrapped variants), and devin_trust_prompt_active ignores stale trust text when the idle composer holds the cursor. Verified spawns map the error to spawn_directory_trust_required, expire the pending spawn, and release capacity via existing fleet cleanup; CLI spawn confirmation tests cover the new reason string.

Automatic trust acceptance is explicitly not added (Part 1 only). New PTY integration tests use a synthetic Python “Devin” fixture to prove frozen/widening/wrapped prompts fail without keystrokes, while already-trusted cwd still reaches worker_ready and accepts the task. Devin harness docs and the patch changelog document the behavior.

Reviewed by Cursor Bugbot for commit efafa4de377c089265af1bade9e6f3add6b9c179. Bugbot is set up for automated code reviews on this repo. Configure here.