Skip to content

feat(bin): domain-first routing with Claude→OpenAI fallback and read-only tmux dashboard - #737

Closed
Pawel-Podemski wants to merge 7 commits into
kunchenguid:mainfrom
Pawel-Podemski:codex/primary-fallback-dashboard
Closed

Pawel-Podemski wants to merge 7 commits into
kunchenguid:mainfrom
Pawel-Podemski:codex/primary-fallback-dashboard

Conversation

@Pawel-Podemski

@Pawel-Podemski Pawel-Podemski commented Jul 19, 2026 •

Copy link
Copy Markdown

Intent

Implement domain-first FirstMate and SecondMate model routing with direct Claude-to-OpenAI hard-unavailability fallback, ban Ultra, preserve work-order state across fallback, and add a read-only three-pane tmux operator dashboard with tests and documentation.

What Changed

  • Added a primary-available dispatch strategy to fm-dispatch-select.sh that walks declared profiles in order and picks the first whose adapter command exists and whose provider is not proven exhausted; missing/stale/auth-failed telemetry is treated as UNKNOWN so it keeps the primary instead of speculatively downgrading, with a fresh-quota gate on the exact-zero exhaustion signal. Wired every "using first profile" fallback path (missing/unreadable quota, absent quota-axi, unparseable JSON) to honor this strategy.
  • Introduced per-secondmate dispatch in fm-spawn.sh: an optional config/secondmate-dispatch.json resolves a per-ID (or default) profile through the same use/select contract, threading harness/model/effort while letting explicit per-spawn axes win and falling through to the legacy secondmate-harness chain on a miss (set-e-safe so an uncovered ID no longer aborts the spawn); the local dispatch config is gitignored.
  • Added a read-only three-pane tmux operator dashboard (fm-dashboard.sh, fm-dashboard-loop.sh, fm-dashboard-view.sh) that renders coordinator capture, roster, and worker details from fleet snapshots and current-state without keying or waking the observed session, backed by new dispatch/dashboard/bootstrap/secondmate-harness tests and updated architecture, configuration, scripts, and tmux-backend docs.

Risk Assessment

✅ Low: The only changes since the prior review are the two correct, well-bounded fixes for the previously reported findings (set-e-safe dispatch resolution and a deduplicated age_label guard), leaving the branch clean.

Testing

The configured tmux e2e suite already passed as baseline; I re-ran the changed/related tests (dispatch-select, dashboard, secondmate-harness, bootstrap, spawn-batch, session-start, backend-orca) and all passed with no regressions. Beyond tests, I demonstrated the intent end-to-end: a CLI transcript proves the domain-first Claude→OpenAI fallback fires only on hard unavailability (missing adapter, exact quota exhaustion) and preserves the primary on unknown telemetry; a real tmux launch produced captures of the read-only three-pane observer dashboard (coordinator/roster/details) confirming it creates a separate observer session and never sends keys to the target; and a populated-snapshot render plus composited layout show the panes with live worker telemetry. No "Ultra" model/tier appears anywhere in the tree. Worktree left clean; all evidence written under the evidence directory.

Evidence: Domain-first Claude→OpenAI fallback routing transcript (4 scenarios)

Scenario A: Claude adapter HARD-MISSING → {"harness":"codex","model":"gpt-5.6-sol","effort":"high"} Scenario B: Claude quota EXACTLY exhausted (0%) → codex Scenario C: Claude telemetry UNKNOWN → claude PRESERVED (no speculative downgrade) Scenario D (control): healthy quota → claude PRESERVED

=== primary-available: domain-first Claude→OpenAI hard-unavailability fallback ===

--- Scenario A: Claude adapter HARD-MISSING (command not on PATH) ---
profiles: claude(opus) -> codex(gpt-5.6-sol);  expect: codex (Claude skipped)
result:  {"harness":"codex","model":"gpt-5.6-sol","effort":"high"}
stderr:  fm-dispatch-select: quota-axi missing; using first profile
fm-dispatch-select: profile 0 harness 'claude' is unavailable; trying next profile

--- Scenario B: both adapters present, Claude general quota EXACTLY exhausted (0%) ---
expect: codex (hard-unavailable Claude), work profile preserved as declared
result:  {"harness":"codex","model":"gpt-5.6-sol","effort":"high"}

--- Scenario C: Claude telemetry UNKNOWN (provider absent from quota) ---
expect: claude PRESERVED — unknown never triggers speculative downgrade
result:  {"harness":"claude","model":"opus","effort":"high"}

--- Scenario D (control): fresh quota, Claude healthy → primary stays Claude ---
result:  {"harness":"claude","model":"opus","effort":"high"}
Evidence: Live three-pane read-only tmux dashboard — composited layout
READ-ONLY THREE-PANE OPERATOR DASHBOARD  (observer session: fm-dashboard-demo — never sends keys to fm-demo)
=======================================================================================================================
┌─ PANE 0 · coordinator (target capture) ───────────────┐  ┌─ PANE 1 · roster ─────────────────────────────────────────┐
│ FIRSTMATE · fm-demo · read-only capture              │  │ ROSTER · workers=3 · snapshot=2026-07-19T12:00:00Z       │
│ Detach: Ctrl-b d                                     │  │ ID                     ROLE          MODEL               │
│                                                      │  │ ──────────────────────────────────────────────────────── │
│ > dispatched sm-auth-refactor [claude/opus] -> worki │  │ sm-auth-refactor       secondmate    claude/opus/high    │
│ > dispatched cm-docs-sweep [codex/gpt-5.6-sol] -> wa │  │ cm-docs-sweep          crewmate      codex/gpt-5.6-sol/h │
│ > Claude quota healthy; primary routing active       │  │ cm-flaky-hunt          crewmate      claude/sonnet/mediu │
└──────────────────────────────────────────────────────┘  │                                                          │
                                                          │ Sources: state/meta + current-state; no model polling.   │
                                                          └──────────────────────────────────────────────────────────┘
                                                          ┌─ PANE 2 · details ────────────────────────────────────────┐
                                                          │ DETAILS · active/waiting=2                               │
                                                          │ Session/work order: fm-demo                              │
                                                          │ ID: sm-auth-refactor                                     │
                                                          │ Role: secondmate                                         │
                                                          │ Profile: claude/opus/high                                │
                                                          │ State: working · source=current-state                    │
                                                          │ Repo: firstmate                                          │
                                                          │ Branch: codex/auth-refactor                              │
                                                          │ Worktree: /home/agent/firstmate/wt/auth                  │
                                                          │ Heartbeat/change: 47 s · source=heartbeat                │
                                                          │ Gate: none                                               │
                                                          │ Last event: ran tests: 42 passed                         │
                                                          │                                                          │
                                                          │ Work-order scope: unavailable in current telemetry       │
                                                          │                                                          │
                                                          │ Phase/wave: unavailable in current telemetry             │
                                                          │ Tools/safe events: unavailable in current telemetry      │
                                                          │ Source state: snapshot=fm-fleet-snapshot.v1              │
                                                          └──────────────────────────────────────────────────────────┘
Evidence: Live dashboard launch status (mutation: false, observer session)

status: ready observer: fm-dashboard-demo target: fm-demo attach: "tmux attach -t fm-dashboard-demo" detach: "Ctrl-b d" mutation: false

status: ready
observer: fm-dashboard-demo
target: fm-demo
attach: "tmux attach -t fm-dashboard-demo"
detach: "Ctrl-b d"
mutation: false
Evidence: Live captured coordinator pane (read-only target capture)
> dispatched sm-auth-refactor [claude/opus] -> working
> dispatched cm-docs-sweep [codex/gpt-5.6-sol] -> waiting (decision)
> Claude quota healthy; primary routing active
Evidence: Populated roster + details panes render
############ PANE: ROSTER ############
ROSTER · workers=3 · snapshot=2026-07-19T12:00:00Z
ID                     ROLE          MODEL                     STATE        AGE
────────────────────────────────────────────────────────────────────────────
sm-auth-refactor       secondmate    claude/opus/high          working      47s
cm-docs-sweep          crewmate      codex/gpt-5.6-sol/high    waiting      5m
cm-flaky-hunt          crewmate      claude/sonnet/medium      done         1h

Sources: state/meta + current-state; no model polling.

############ PANE: DETAILS ############
DETAILS · active/waiting=2
Session/work order: fm-demo
ID: sm-auth-refactor
Role: secondmate
Profile: claude/opus/high
State: working · source=current-state
Repo: firstmate
Branch: codex/auth-refactor
Worktree: /home/agent/firstmate/wt/auth
Heartbeat/change: 47 s · source=heartbeat
Gate: none
Last event: ran tests: 42 passed

Work-order scope: unavailable in current telemetry

Phase/wave: unavailable in current telemetry
Tools/safe events: unavailable in current telemetry
Source state: snapshot=fm-fleet-snapshot.v1

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed ✅
  • 🚨 bin/fm-spawn.sh:321 - fm-spawn.sh runs under set -eu (line 82), but the secondmate-dispatch resolution assigns SM_DISPATCH_SPEC=$(jq -ec '.profiles[$id] // .default // empty' ...) as a bare assignment and only reads sm_dispatch_status=$? on the next line. When the spawned ID is not in the dispatch file and no default exists, jq -e produces no output and exits 4; under set -e the assignment itself aborts the script with status 4 before line 322/the exit-4 fall-through branch (323-329) can run. I confirmed this empirically: set -eu; X=$(jq -ec '.profiles["nope"] // .default // empty' ...) exits the shell with code 4. Result: whenever config/secondmate-dispatch.json is present but does not cover a given secondmate ID (and has no default), the secondmate spawn dies instead of falling through to the documented legacy config/secondmate-harness chain (docs/configuration.md: 'A missing ID falls through to the optional default profile set, then to the backward-compatible config/secondmate-harness chain'). Fix by making the assignment set-e-safe, e.g. if SM_DISPATCH_SPEC=$(jq ...); then sm_dispatch_status=0; else sm_dispatch_status=$?; fi. The passing test only exercises a matching ID, so the exit-4 path is uncovered.
  • ℹ️ bin/fm-dashboard-view.sh:33 - age_label() runs two identical case "$seconds" in ''|null|*[!0-9]*) blocks back to back (one to print 'n/a', one to return). This can collapse to a single guard, e.g. case ... ) printf 'n/a'; return ;; esac. Purely a readability simplification; behavior is already correct.

🔧 Fix: fix set -e abort in secondmate dispatch, dedup age_label guard
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
  • bash tests/fm-dispatch-select.test.sh (11 cases incl. primary-available fallback, exact-exhaustion, unknown-telemetry-preserves-primary, hard-missing-adapter)
  • bash tests/fm-dashboard.test.sh (read-only observer-only tmux ops, no-active-worker render)
  • bash tests/fm-secondmate-harness.test.sh (per-ID secondmate dispatch B3a, harness/model/effort threading)
  • bash tests/fm-bootstrap.test.sh (validates crew-dispatch + per-ID secondmate-dispatch profiles)
  • bash tests/fm-spawn-batch.test.sh, bash tests/fm-session-start.test.sh, bash tests/fm-backend-orca.test.sh (no regressions)
  • Manual E2E: fm-dispatch-select.sh --select primary-available across 4 quota/adapter scenarios → routing-fallback-transcript.txt
  • Manual E2E: launched live fm-dashboard.sh fm-demo on isolated tmux socket, captured all three panes; verified observer session created and target never keyed
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@Pawel-Podemski Pawel-Podemski changed the title feat: add domain-first routing with Claude→OpenAI fallback and tmux observer dashboard feat(bin): domain-first routing with Claude→OpenAI fallback and read-only tmux dashboard Jul 19, 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.

1 participant