Skip to content

Fix #2083: deliver mail to agents started through a wrapper script (configured harness) - #2087

Merged
waleedkadous merged 14 commits into
mainfrom
builder/bugfix-2083
Dec 5, 2026
Merged

waleedkadous merged 14 commits into
mainfrom
builder/bugfix-2083

Conversation

@waleedkadous

@waleedkadous waleedkadous commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An agent started through a wrapper script (shell.architect: "./start-agent.sh claude") had every message held no-profile, forever and silently: the mailbox identified the agent's app from its running command only, and never read the harness the owner named in config. The mailbox now falls back to shell.architectHarness / shell.builderHarness / shell.siteManagerHarness when the command and the launch script identify no harness, says so once at start when mail will be held, and codev doctor reports it.

Fixes #2083

Root Cause

Tower splits shell.architect on whitespace and launches the first word, so the architect's running command is ./start-agent.sh. resolveProfileForSession (mailbox-wiring.ts) matched that command's basename against the known harnesses, then read a builder's .builder-start.sh (an exact harness name in command position), and otherwise returned null, so deliverAgentMail held no-profile on every pass. The launch side already resolves the harness from config first (getArchitectHarness: explicit architectHarness → detection → claude); the mailbox never consulted it. Builders behind a wrapper (the launch script names start-agent.sh, not a harness) and the Site Manager behind one were affected the same way.

Fix

  • Resolution (gate-profiles.ts resolveAgentProfile): running command → launch script → configured harness, the last tier only when the first two name no harness. A command that names a harness always wins over config (PIR Architect identity: hydrate from the WELCOME frame (fully-authoritative) instead of fail-closed self-heal #1475), including one with no profile (e.g. opencode), which config never overrides. A wrong declaration stays safe: another family's profile fails the composer-marker test, so mail holds rather than misdelivers.
  • Which setting: the delivery port now receives (scope, toAgent); the kind comes from Tower's routing registry (architect / builder), machine scope is the Site Manager (siteManagerHarness, then architectHarness, as its launch does). A plain shell has no setting. Config is read at each resolution, so mail already held delivers on the next pass once the setting is added, with no restart.
  • Said once, at start (servers/agent-profile.ts warnIfMailWillBeHeld): a Tower WARN and one line for the person starting the agent, naming what could not be identified, that mail will be held, and the setting that fixes it. When the command or launch script identifies a harness the mailbox has no profile for (e.g. opencode), the line says so and that no setting changes it (CMAP, codex). It is returned by activate (mailNotices, main + re-spawned siblings), add-architect and builder terminal-create (mailNotice), and printed by afx workspace start / setup / add-architect, afx spawn, and afx manager start (via the Site Manager's state reason, also shown by afx status).
  • codev doctor reports each configured architect / builder / Site Manager command it cannot identify (configuredMailNotices), reading each as the launch side runs it (environment variables expanded) and a builder command as its launch script will (exact harness name only).
  • The new module is registry-free on purpose: tower-instances (imported by tower-terminals) and site-manager warn without importing the mailbox wiring.
  • Docs: the no-profile entry in agent-farm.md (both codev/ and codev-skeleton/) names the settings.

Adjacent fix, in place: the 180 s owner notice for a no-profile builder fell into the "CANNOT VERIFY" arm: it blamed a drifted TUI / torn frame and offered afx interrupt, which only sends ESC (ends the builder's turn) and cannot clear a hold caused by the gate not recognising the app. It now names no terminal command and gives both causes of a no-profile hold: a wrapper script, which shell.builderHarness fixes with no restart, or a harness with no screen profile, which no setting changes. #1482's test that pinned the old remedy for no-profile is updated accordingly. The Site Manager's sender notice offered afx manager attach for the same hold and now gives the same two causes with shell.siteManagerHarness (CMAP, claude). The liveness warning for no-profile gives the same two causes, with the agent's own setting, instead of only "check for a TUI update".

Adjacent fix, found by this PR's Windows run: bugfix-1751-protocol-reference.test.ts checked the heading-then-placeholder layout with a regex expecting a bare \n; a Windows checkout gives the builder-prompt templates CRLF line endings, so all 18 template cases failed there. The test landed on main after the last green Windows run, so it had never run on Windows. Now \r?\n.

Size: about 450 production lines, a good part of them comments: above the ~300 guideline because the start notice and the doctor check reach every start path (architect main/sibling, builder, Site Manager, four CLI commands). The resolution change itself is small.

The issue's two "Not checked" points

  1. Does the 180 s stuck notice fire for a no-profile hold and name the reason? For an architect (the reported case): no. escalateHeldToOwner deliberately skips architect-addressed rows (the notice would starve in the same mailbox); the only traces were the sender's held (no-profile) answer and the liveness log/notification after 10 consecutive checks with recent output, which blamed "a TUI update". For a builder: yes, to its owner architect at 3 × the escalation age, naming no-profile, but with the wrong remedy (fixed above). For the Site Manager: its senders get the notice. With this PR the person starting any of the three is told at start, and the liveness warning names the setting.
  2. What happens to mail already held no-profile? The drainer retries held rows every 1.5 s backstop pass and re-resolves the profile each time; the config tier reads the config file at each resolution. So once the setting is added, held mail delivers on the next pass, with no restart of Tower or the agent. Pinned in both the unit test and the e2e below.

Test Plan

  • Regression tests added; both fail with the config tier disabled (11 of 35 unit cases; both e2e cases) and pass with it
    • bugfix-2083-configured-harness.test.ts (unit, real createSessionRaw sessions, real config files, isolated HOME): precedence (command / launch script / config), each kind (architect, builder, Site Manager incl. its architectHarness fallback), known command wins over config, a builder ignores architectHarness, delivery through the production resolveProfile port, held mail delivers after the setting is added, the start notice + exactly one WARN, a builder's notice names its launch script (never /bin/bash), doctor's report, owner/liveness wording
    • bugfix-2083-wrapper-architect.e2e.test.ts: a scratch Tower (dist, own port 14830, isolated HOME/state/sockets; not the machine's Tower) whose workspace's shell.architect is a real wrapper script on disk. With architectHarness: "claude": POST /api/send to architect answers delivered and the bytes reach the terminal. Without it: activate returns the notice, the send answers held / no-profile, and writing the setting (no restart) delivers the held message. Run with vitest run --config vitest.e2e.config.ts src/agent-farm/__tests__/bugfix-2083-wrapper-architect.e2e.test.ts
  • Build passes (porch check)
  • All tests pass (porch check: full suite, run once with 1-minute load under 10)
  • Windows (suites=true): first run failed in two pre-existing tests, neither in code this PR changes (see below); rerun after the CRLF fix passed on 7261d22f8, peer-pipeline included

CMAP

  • codex: REQUEST_CHANGES (round 1): a recognised harness with no profile (opencode) got no start notice, and the stuck/liveness notices promised the setting for every no-profile. Both fixed in 26aea5ac2.
  • codex: REQUEST_CHANGES (round 2): a running command naming a profile-less harness (opencode) fell through to the launch script, so a script naming claude would read its screen with Claude's profile. Pre-existing precedence, but it contradicts PIR Architect identity: hydrate from the WELCOME frame (fully-authoritative) instead of fail-closed self-heal #1475 (the running command is authoritative); fixed in 79ea594e5: the command's harness is checked before the script.
  • codex: REQUEST_CHANGES (round 3): the on-demand Windows workflow had not been run, though the PR touches Tower launch and terminal paths. Dispatched: Windows run.
  • codex: APPROVE (round 4), no key issues, on 7261d22f8.
  • claude: APPROVE (round 1), with six comments. Fixed in b11cbc30b: Site Manager sender notice, doctor env-var expansion, launch script read once, docstring note on the substring matcher (a wrapper named run-gemini-agent.sh reads as gemini; since 26aea5ac2 it gets the profile-less notice instead of silence), manager.ts comment. Not changed: "(claude or codex)" in the remedy omits agy on purpose: agy is not a launch harness (resolveHarness rejects it unless a custom harness is defined), so naming it in architectHarness would break the launch.

Flaky Tests

  • This PR's own bugfix-2083-wrapper-architect.e2e.test.ts timed out once on CI (912277fe6, Tower Integration): its first case waited 10 s for the wrapper's ready line on a cold scratch Tower; the second case passed. Fixed in 245bbb740: 30 s wait, the architect's terminal id re-read each check, and a timeout reports the terminal output and Tower's log tail. Green on CI since.

  • peer-pipeline.test.ts › "a backlog of held mail" › "drains in order against C's per-pair limit…" and "…against R's own limit with C's raised…" (Windows only): expected [] to have a length of 29 / 30 but got +0 after a 5 s clock advance (26 s and 22 s wall time). Its own header notes the file runs ~75× slower on the Windows runner. It imports only peer/* and db/mailbox, none of which this PR touches; it passes on macOS/Linux CI and locally. Left running.

… configured harness

The mailbox read an agent's app from its running command, then a builder's
launch script, and never from shell.architectHarness / builderHarness /
siteManagerHarness, so an agent started through a wrapper script had every
message held no-profile. The configured harness is now the last tier, read
only when the command and the launch script identify no harness, and read at
each pass, so mail already held delivers once the setting is added.

An agent whose mail will be held is said so once at start: a Tower WARN and a
line for afx workspace start / add-architect / setup / spawn and afx manager
start. codev doctor reports configured commands it cannot identify. The
no-profile owner notice and liveness warning name the setting instead of
afx interrupt / a TUI update.
Unit: the precedence (command, launch script, config), each agent kind, the
start notice and its single log line, doctor's report, and held mail
delivering once the setting is added. E2E in a scratch Tower: an architect
whose command is a real wrapper script answers delivered with
architectHarness set; without it activation says so, the send holds
no-profile, and adding the setting delivers the held mail with no restart.
Both fail with the config tier disabled.
…-profile causes

Codex review: an agent whose command or launch script names a harness the
mailbox has no profile for (opencode) also has all its mail held, and the
issue asks for a notice whenever no profile resolves. It now gets one at
start and from codev doctor, saying no setting changes it. The owner and
liveness notices cannot tell the two causes apart, so they name both and
promise the setting only for the wrapper case.
…nv vars

Claude review: the Site Manager's sender notice still offered
afx manager attach for a no-profile hold; it now names the two causes and
shell.siteManagerHarness. codev doctor reads a configured command with its
environment variables expanded, as the launch side runs it, so $AGENT
naming claude is not reported. heldMailNotice reads the launch script once,
and notes that a wrapper whose name contains a harness name reads as that
harness.
…the launch script

Codex review round 2: a running command naming a harness with no profile
(opencode) fell through to the launch script, so a script naming claude
read its screen with Claude's profile. The precedence predates this PR; it
contradicts PIR #1475 (the running command is authoritative), so the
command's harness is now checked before the script.
Found by this PR's Windows run: a Windows checkout gives the builder-prompt
templates CRLF line endings, and the heading-then-placeholder regex expected
a bare \n, so all 18 template cases failed there. The test landed on main
after the last green Windows run, so it had never run on Windows.
… and says what it saw

Tower Integration on CI: the first case timed out after 10 s waiting for the
wrapper's ready line on a cold scratch Tower; the second case passed. The
wait is now 30 s, re-reads the architect's terminal id on every check (a
terminal replaced while Tower starts is followed), and on timeout fails
with the terminal's output and the tail of Tower's log.
@waleedkadous
waleedkadous merged commit 8105c3a into main Dec 5, 2026
10 checks passed
waleedkadous added a commit that referenced this pull request Dec 5, 2026
waleedkadous added a commit that referenced this pull request Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mailbox holds all mail to an agent started through a wrapper script: the harness is read from the command only, never from the configured harness

1 participant