Skip to content

afx attach can't find builders registered only in Tower's terminal registry #717

@timeleft--

Description

@timeleft--

Summary

afx attach fails to find a builder that afx status shows as active. The builder is visible in the Tower web UI and responds to afx send, but afx attach -p <id> says "Builder not found."

Root Cause

afx status (when Tower is running) queries the Tower API, which reads from global.db terminal_sessions. But afx attach only queries the local .agent-farm/state.db builders table via getBuilder() / getBuilders() in state.ts.

These are two separate databases with no synchronization. If the local builders row was never written (e.g., spawned by a different session, race condition during spawn, or state.db was cleared), the builder exists in Tower but is invisible to attach.

Reproduction

  1. Have a Tower running with an active builder (visible in afx status and Tower web UI)
  2. Verify .agent-farm/state.db builders table is empty: sqlite3 .agent-farm/state.db "SELECT * FROM builders;"
  3. Run afx attach -p <builder-id> → "Builder not found"
  4. Run afx send <builder-id> "hello" → works (routes through Tower API)

Expected Behavior

afx attach should fall back to querying Tower's terminal registry when the local builders table has no match, similar to how afx status already does.

Relevant Code

  • commands/attach.ts:41-63findBuilderById() only queries local state
  • commands/status.ts:26-62 — queries Tower API when Tower is running
  • servers/tower-terminals.ts:819-828 — Tower tracks builders by role_id
  • state.ts:75-111upsertBuilder() writes only to local state.db

Workaround

Use afx send <builder-id> "<message>" (routes through Tower) or interact via the Tower web UI at http://localhost:4100.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions