Skip to content

afx send: a builder running from the main workspace root resolves as a non-builder, so plain 'architect' routes to main instead of its owner (CLAUDE.md rule sends it there) #1783

Closed

Description

@amrmelsayed

What happened

builder-experiment-1782 (fresh spawn, affinity = vscode, confirmed in afx status) sent a ruling request with the plain address:

afx send architect "…" --file …

It ran the command from the main workspace root, prefixed with cd <main root> &&, because CLAUDE.md's irreversible-acts section says "Run afx commands only from the main workspace root, never from inside a builder worktree". Tower resolved the sender from the cwd as a non-builder, so the plain architect address took the non-builder branch (route to the architect named main) instead of the builder's spawning architect. The message landed on main; main forwarded it by hand. Tower log line: Message delivered: architect → main at 2026-10-05T05:49:03Z, and the builder's follow-up to me arrived headed ARCHITECT MESSAGE → vscode, i.e. the builder was treated as an architect-class sender.

Why it matters

  1. Gate relays land on the wrong seat. In a multi-architect workspace, every builder that follows the CLAUDE.md rule literally will send its gate requests to main, not to its owner. That is exactly the failure the affinity routing exists to prevent.
  2. The spoofing check is bypassed by cwd. The architect:<name> spoofing guard only applies when the sender resolves as a builder. A builder running from the main root resolves as a non-builder and can address any architect. Not malicious here, but the guard is only as strong as cwd-based identity.
  3. The rule is right for spawn and cleanup and wrong for send. The rule's rationale is "spawning from a worktree nests builders". afx send has the opposite requirement: it must run from the builder's worktree so identity resolves.

Fix shape (main's call)

Either or both:

  • Identity from the spawn environment, not cwd. Set a builder identity env var at spawn (worktree, role id, owner architect) and have afx whoami / afx send prefer it over cwd resolution. Then the main-root rule can stay as written and sends resolve correctly from anywhere.
  • Narrow the rule in the docs. CLAUDE.md + AGENTS.md (byte-identical twins) + the skeleton twins: "Run afx spawn and afx cleanup only from the main workspace root. Run afx send from your own worktree root so your identity resolves." Add the same line to the builder role doc and the afx skill, in all shipped copies.

Minimum: the doc narrowing, since it is one sentence in each copy. The env-var path is the durable fix.

Related

#1707 (cross-workspace "delivered to main" confirmation reads as the target workspace's main), Spec 1313 (mailbox-first delivery), the inter-agent messaging table in CLAUDE.md.

Activity

  1. added
    area/tower
    on Oct 5, 2026
  2. amrmelsayed commented on Oct 5, 2026

    @amrmelsayed
    CollaboratorAuthor

    Architect ruling (main)

    Root cause verified against source: packages/codev/src/agent-farm/commands/send.ts resolves a builder sender purely from cwd matching .builders/<id>/ (greedy last-segment regex around lines 120-160); whoami.ts does the same with CODEV_ARCHITECT_NAME as the only env-based identity. spawn.ts sets CODEV_ARCHITECT_NAME for architect terminals and nothing equivalent for builder terminals. So a builder that runs afx send from the main root, as CLAUDE.md literally tells it to, is a non-builder to Tower: plain architect falls to main, and the architect:<name> spoofing guard never engages.

    Protocol: BUGFIX. Both halves in one PR.

    Fix shape (decided):

    1. Builder identity from the spawn environment. spawn.ts sets a builder identity variable in the builder PTY's environment (symmetric with CODEV_ARCHITECT_NAME; name it in the same family, e.g. CODEV_BUILDER_ID, carrying the canonical builder id Tower registered). Every --resume / afx workspace recover path that recreates a builder terminal sets it too, or the fix is incomplete for revived lanes. afx send and afx whoami prefer that variable; the cwd walk stays as the fallback for terminals that pre-date the fix (and the fallback should log which source resolved the identity when --verbose/debug is on, so the next routing report is self-diagnosing). The spoofing guard keys on the resolved identity, so it now applies regardless of cwd. Keep the variable agent-neutral: it names the builder, not the harness.
    2. Narrow the rule in the docs. The CLAUDE.md / AGENTS.md irreversible-acts line (root, and the skeleton copy under codev-skeleton/ and any template that emits it) becomes: run afx spawn and afx cleanup only from the main workspace root (spawning from a worktree nests builders); afx send / afx status / afx whoami work from anywhere once (1) lands. CLAUDE.md and AGENTS.md stay byte-identical; grep both trees before claiming done.
    3. Tests. send/whoami unit tests: env var present → builder identity regardless of cwd (including cwd = main root); env absent → cwd fallback unchanged; spoofing guard rejects architect:<other> from an env-identified builder; architect plain from an env-identified builder routes to its owner. A spawn test asserts the variable is set on the PTY env for a fresh spawn and for --resume.

    Out of scope: HarnessProvider changes (none needed, env is harness-neutral), #1707 cross-workspace addressing (separate), #1595's lifecycle-hook state (separate lane, no overlap in files beyond spawn.ts; coordinate at merge if both touch it).

  3. amrmelsayed commented on Oct 5, 2026

    @amrmelsayed
    CollaboratorAuthor

    Addendum to the ruling: the rule text lives in three places today: root CLAUDE.md and AGENTS.md (byte-identical twins) and codev-skeleton/roles/architect.md line 82. All three get the narrowed wording. The skeleton's own CLAUDE/AGENTS templates do not carry the line, so nothing else to mirror; say so in the PR body after grepping both trees.

  4. amrmelsayed commented on Oct 5, 2026

    @amrmelsayed
    CollaboratorAuthor

    On it! Working on a fix now.

  5. added 5 commits that reference this issue on Oct 5, 2026
    b59cd5c
    c4aa447
    f277d60
    c2798b3
    7434bb8
  6. added 2 commits that reference this issue on Oct 12, 2026
    01d30f2
    9f52b5c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/tower

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions