Repository navigation
feat(bin): add Rex attention marks, event-driven watcher wakes, and short sidebar tab labels - #3
Merged
Merged
Conversation
…bels Phase 3 of the Rex backend: the captain sees which worker needs them from Rex itself, and the watcher wakes on Rex events instead of only polling. - fm-rex-marks.sh maps each Rex task's latest status to one OSC 7501 id=fm program-status record on its pane plus an OSC 777 notification on each new attention state; the watcher syncs it each poll and cleanup clears it. config/rex-status-marks selects on (default), off, or labels. - The Rex adapter follows `rex events` per session, reconciles after every subscribe, escalates a blocked root status or an exited agent or closed pane at once, ignores Firstmate's own records, and treats exit 4 as unusable, never dead. - busy_state and submit confirmation read the root program status only for harnesses a live guard proves (Claude Code today). - The away-mode wedge alarm gains a rex channel, added by auto when Firstmate runs in a Rex pane. - Worker tab labels are sidebar-sized: kind marker plus a few words from fm-spawn --title, the backlog title, or the task id, at most 24 visible characters; the block label stays the identity check. - New opt-in per-harness program-status live guard, docs, and dated verification evidence.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
I want to add Rex support /rex to firstmate, with full support for first and second mates, at the same level as the herdr support. It should use the Rex capabilties to the maximum, using its multiplexing and pane management and all other things to the maximum for an optimal development experience
Context: a planning investigation split this into phases. Phase 1 (workers and scouts in Rex tabs, #1) and Phase 2 (second mates in their own fm- sessions, local workers in fm-local, remote second mates, away mode inside Rex, #2) have merged. This task is Phase 3, the Rex-native experience: the captain sees which worker needs them from Rex itself (tab badges, session-picker indicators, Activity sidebar, Dock badge, notifications), and the watcher wakes on Rex events instead of only polling. A later Phase 4 covers features beyond Herdr parity (command-palette actions, web view, side panes, progress and tinting) and is out of scope here.
the terminal titles can be better right, can we make them relevant and sidebar sized?
Context: today a worker's Rex tab label is
<project>·<task-id>(for examplefirstmate-rex·rex-backend-p3) and its block label is the identity stringfm-<hometag>-<task-id>; both are long and say nothing about the work, and the Rex sidebar truncates them.What Changed
bin/fm-rex-marks.shmaps each Rex task's latest status (needs-decision or hold, blocked, failed, done) to a Firstmate program-status record on that worker's pane. Rex then badges the tab, the session picker, the Activity sidebar and the Dock. When the mark changes to a new state that needs the captain, it also sends one OSC 777 desktop notification.fm-watch.shsyncs the marks on every poll cycle, andfm-teardown.shclears a task's mark before closing its pane.config/rex-status-marksturns the marksonoroff. They are on when the file is absent.config/wedge-alarmgets a newrexchannel, whichautoadds when Firstmate's own pane is a Rex pane.bin/backends/rex.shfollowsrex eventsfor the watched session, andfm-backend.shwires that into the shared transition dispatchers.blockedescalates right away. So does a child exiting or a block closing.fm_backend_busy_stateand steer-submit confirmation now read the root program status for the harnesses that publish one: Claude Code by default, configurable withFM_BACKEND_REX_STATUS_APPS. All other harnesses keep capture and hash polling.fm-spawn.sh --title, or a kind marker (Ship,ScoutorMate) plus the backlog title's first clause, falling back to the task id.rex_tab_label=and kept across relaunches unless a new--titleis given.fm-<home>-<id>is still the identity check.docs/rex-backend.md, configuration, wedge-alarm, and runtime-backends verification.tests/fm-rex-program-status-live-e2e.test.sh, which checks that Claude Code's root program status is published on Rex.🤖 Generated with Claude Code
Risk Assessment
deadedge that sends a false wake on routine Rex teardowns, and its native busy trust depends on unproven turn-end behaviour of Claude Code's status record; both can be fixed in follow-ups, but both affect supervision.Testing
Following the operator's budget-cut guidance, I ran only the listed deterministic suites with REX_* unset. The Rex smoke ran the real Rex binary against a disposable lab server, which its own teardown removed. It showed: unfocused, labeled sidebar tabs in one fm-local session; a tab rename taking effect; a Firstmate attention mark (an invisible id=fm program-status record plus a desktop notification) clearing on its own; the real
rex eventswait reporting blocked and dead edges; kill proving exit 3; and an unreachable server being exit 4 and never autostarting. The adapter suite covered the remaining Phase 3 behavior: sidebar-sized tab labels (explicit title, else a condensed backlog title, else the id), kill pre-committing its dead edge, event-wait escalation and subscribe reconcile, and the marks producer honoring on/off. Transition-lib, backend, daemon and endpoint-safety all passed. fm-teardown passed 118 assertions with 0 failures before my tool's 20-minute background limit stopped it. Not run, per the operator's 'run only' list: tests/fm-supervision-events.test.sh, which holds the retired-pane dead-wake guard test, and the opt-in, token-spending Claude live e2e. No UI screenshot was captured: the operator scoped this round to the deterministic suites and forbade new lifecycle drivers, so the Rex sidebar was shown through the smoke's real tab-label and mark output. The teardown false-wake scenario and the no-regression scenario were checked only by deterministic suites, not driven live, so they are recorded as untested.Evidence: Rex real-binary smoke transcript (private lab server)
Source: Rex real-binary smoke transcript (private lab server)
Evidence: Rex adapter suite
Source: Rex adapter suite
Evidence: Transition lib suite
Source: Transition lib suite
Evidence: Daemon suite
Source: Daemon suite
Evidence: Backend suite
Source: Backend suite
Evidence: Teardown suites (main partial, endpoint-safety complete)
Source: Teardown suites (main partial, endpoint-safety complete)
Evidence: Smoke highlights
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-teardown.sh:3890- Tearing down a Rex worker now sends Firstmate a false 'pane closed' wake. The change makesdeadactionable (bin/fm-transition-lib.sh:102) and mapsblock_closed/child_exitedtodead(bin/backends/rex.sh:1202-1204). Teardown closes the worker's pane throughfm_backend_kill, but it does not pause the watcher or pre-mark the edge, and it only removes the dedupe markers afterwards (fm_backend_clear_transitionat bin/fm-teardown.sh:3951). Concrete sequence: the armed watcher sits infm_backend_rex_wait_transitionwith the task's window in its watched list, which is snapshotted at cycle start. Firstmate runs fm-teardown.sh.block_closedstreams in and becomes adeadrecord. No.rex-escalated-…deadmarker exists yet, sohandle_push_transition(bin/fm-push-transition-lib.sh:167-170) appends a stale wake and callswake "stale: <window> (rex: agent exited or pane closed …)"for a task Firstmate is deliberately removing. If the meta is already gone,window_to_taskfalls back to the block uuid. This happens on essentially every Rex teardown while the watcher is armed. Herdr never produced this because it has nodeadstatus. The same unguarded edge also reaches the subscribe-time reconcile (bin/backends/rex.sh:1301-1311, exit 3 means dead) when a cycle starts between the kill and the meta removal. Smallest fix, at the shared boundary both paths dedupe on: for rex, have teardown create the dead dedupe marker (fm_backend_rex_escalation_marker "$STATE" "$T" dead, or an equivalent commit helper) beforefm_backend_kill. The existingfm_backend_clear_transitioncall later removes it.bin/backends/rex.sh:1134-fm_backend_rex_busy_statetreats a claude-code root record ofworkingas busy whenever the agent process is alive. Nothing proves that Claude Code changes or drops that record when a turn ends. The live guard (tests/fm-rex-program-status-live-e2e.test.sh:145-148) only checks thatworkingappears at some point. It stops sampling as soon as the status file says done, so it never checks the record after the turn ends. The recorded evidence for Claude Code 2.1.308 (docs/verification/runtime-backends.md) shows onlyworking, with nodone/idle, even though the probe finished. If 2.1.308 leavesworkingin place while idle, every new consumer of this verdict reads an idle pane as busy indefinitely:pane_is_busy(bin/fm-supervise-daemon.sh:734) keeps deferring away-mode injects until the wedge alarm fires;fm_pending_reply_backend_observation(bin/fm-pending-reply-lib.sh:815) never sees busy turn to idle;fm_task_inbox_ring(bin/fm-task-inbox-lib.sh:368) refuses the doorbell Enter; andfm_busy_classify(bin/fm-busy-lib.sh:1093) reportsbusy rex-native. Fix: extend the guard to keep sampling after the worker reports done and fail unless claude-code's root record leavesworking(moves to idle/done or is removed) once the turn ends. Until that is shown, do not trustworkingas busy.bin/fm-spawn.sh:965- Simplification: the newfm-spawn.sh --title <text>option and its relaunch rename path (bin/fm-spawn.sh:4228-4239, 1013) are not needed for the intent ('make [titles] relevant and sidebar sized'). That intent is already met by the automatic label: a kind marker plus the condensed backlog title, else the task id (fm_backend_rex_tab_label). Nothing in AGENTS.md, the skills, or any caller passes--title, so it only adds an unused override plus a relaunch-time rename branch. Recommended: remove the option and keep the automatic backlog-derived label.bin/fm-rex-marks.sh:207- Simplification: thelabelschannel of config/rex-status-marks goes beyond the intent. It is a third mode that prefixes '⚑ ' to the tab label throughwindow lsandwindow rename, and brings its own undo, a channel switch, and a cache mode (bin/fm-rex-marks.sh:205-209, 266-272; bin/backends/rex.sh:1079-1094fm_backend_rex_label_flag). The intent asks for Rex-native attention signals (tab badges, session picker, Activity sidebar, Dock badge, notifications), and theonprogram-status mark already provides them. No requirement asks for a label-rewriting fallback. Recommended: removelabelsand keepon/off. If it goes, the relaunch path'sfm_backend_rex_label_flagrename is needed only by the--titleoption flagged separately.bin/fm-spawn.sh:4239- On relaunch, a task that has no recordedrex_tab_label(any task spawned before this change) gets a new tab labeledfm_backend_rex_tab_label "$KIND" "$ID" "$DISPLAY_TITLE". That call omits the backlog title, so it readsShip · <id>instead of the relevant title a fresh spawn gets (line 4572 passes${FM_BACKLOG_ROW_TITLE:-}). The backlog probe at line 4173 has already filledFM_BACKLOG_ROW_TITLEwhen backlog transitions apply. Fix: pass"${FM_BACKLOG_ROW_TITLE:-}"here as well.🔧 Fix applied.
8 issues (7 warnings, 1 info) still open:
bin/fm-teardown.sh:3890- Tearing down a Rex worker now sends Firstmate a false 'pane closed' wake. The change makesdeadactionable (bin/fm-transition-lib.sh:102) and mapsblock_closed/child_exitedtodead(bin/backends/rex.sh:1202-1204). Teardown closes the worker's pane throughfm_backend_kill, but it does not pause the watcher or pre-mark the edge, and it only removes the dedupe markers afterwards (fm_backend_clear_transitionat bin/fm-teardown.sh:3951). Concrete sequence: the armed watcher sits infm_backend_rex_wait_transitionwith the task's window in its watched list, which is snapshotted at cycle start. Firstmate runs fm-teardown.sh.block_closedstreams in and becomes adeadrecord. No.rex-escalated-…deadmarker exists yet, sohandle_push_transition(bin/fm-push-transition-lib.sh:167-170) appends a stale wake and callswake "stale: <window> (rex: agent exited or pane closed …)"for a task Firstmate is deliberately removing. If the meta is already gone,window_to_taskfalls back to the block uuid. This happens on essentially every Rex teardown while the watcher is armed. Herdr never produced this because it has nodeadstatus. The same unguarded edge also reaches the subscribe-time reconcile (bin/backends/rex.sh:1301-1311, exit 3 means dead) when a cycle starts between the kill and the meta removal. Smallest fix, at the shared boundary both paths dedupe on: for rex, have teardown create the dead dedupe marker (fm_backend_rex_escalation_marker "$STATE" "$T" dead, or an equivalent commit helper) beforefm_backend_kill. The existingfm_backend_clear_transitioncall later removes it.bin/fm-spawn.sh:965- Simplification: the newfm-spawn.sh --title <text>option and its relaunch rename path (bin/fm-spawn.sh:4228-4239, 1013) are not needed for the intent ('make [titles] relevant and sidebar sized'). That intent is already met by the automatic label: a kind marker plus the condensed backlog title, else the task id (fm_backend_rex_tab_label). Nothing in AGENTS.md, the skills, or any caller passes--title, so it only adds an unused override plus a relaunch-time rename branch. Recommended: remove the option and keep the automatic backlog-derived label.bin/fm-rex-marks.sh:207- Simplification: thelabelschannel of config/rex-status-marks goes beyond the intent. It is a third mode that prefixes '⚑ ' to the tab label throughwindow lsandwindow rename, and brings its own undo, a channel switch, and a cache mode (bin/fm-rex-marks.sh:205-209, 266-272; bin/backends/rex.sh:1079-1094fm_backend_rex_label_flag). The intent asks for Rex-native attention signals (tab badges, session picker, Activity sidebar, Dock badge, notifications), and theonprogram-status mark already provides them. No requirement asks for a label-rewriting fallback. Recommended: removelabelsand keepon/off. If it goes, the relaunch path'sfm_backend_rex_label_flagrename is needed only by the--titleoption flagged separately.bin/fm-spawn.sh:4239- On relaunch, a task that has no recordedrex_tab_label(any task spawned before this change) gets a new tab labeledfm_backend_rex_tab_label "$KIND" "$ID" "$DISPLAY_TITLE". That call omits the backlog title, so it readsShip · <id>instead of the relevant title a fresh spawn gets (line 4572 passes${FM_BACKLOG_ROW_TITLE:-}). The backlog probe at line 4173 has already filledFM_BACKLOG_ROW_TITLEwhen backlog transitions apply. Fix: pass"${FM_BACKLOG_ROW_TITLE:-}"here as well.bin/fm-teardown.sh:4053- The round-1 fix (c5e179d) narrows the false teardown 'pane closed' wake but leaves one path open.fm_backend_rex_killnow writes the.deaddedupe marker before closing (bin/backends/rex.sh:869-870), and teardown movedfm_backend_clear_transitionto just after the meta removal (bin/fm-teardown.sh:4053). The watcher still snapshots its watched windows at cycle start (recorded_windows, bin/fm-watch.sh:842 → wait_transition at :3057), and the subscribe-time reconcile only runs after the poke loop (bin/backends/rex.sh:1362-1378). Concrete sequence: (1) teardown has already closed the block and is finishing up. (2) A watcher cycle starts and reads the task's meta, so the dead block is still inwatched. (3) Teardown removes the meta and immediately clears both markers. (4) The cycle's first poke is answered and the reconcile runsfm_backend_rex_reconcile_record; exit 3 givesdead, no marker exists any more, sofm_backend_rex_apply_transitionreturns the record. (5)handle_push_transition(bin/fm-push-transition-lib.sh:151-175) finds no meta, sowindow_to_taskfalls back to the block uuid, and it appends and firesstale: <sid>:<bid> (rex: agent exited or pane closed …)for a task Firstmate just retired. The window is the snapshot-to-reconcile latency (up to about a second, more under load), so it hits a minority of teardowns but does happen. docs/rex-backend.md:148 now promises such a close 'never escalates'. The same unguarded edge reaches the event loop (bin/backends/rex.sh:1385-1390) ifblock_closedis read after the clear. Earliest shared boundary that makes the invariant hold: inhandle_push_transition, whento=deadand the window maps to no current task meta, commit the record and return without waking. That covers the reconcile and event paths for every caller. The alternative is to stop deleting the.deadmarker infm_backend_rex_clear_transition(block uuids are never reused).docs/rex-backend.md:157- The round-1 fix changed this doc to say Claude Code's root record 'leavesworkingonce its turn ends, proven bytests/fm-rex-program-status-live-e2e.test.sh'. That round only added the assertion (tests/fm-rex-program-status-live-e2e.test.sh:153-166). No run of it is recorded: the dated table in docs/verification/runtime-backends.md still shows onlyworkingfor Claude Code 2.1.308 and has no 'root record leaves working after the turn' result. Sofm_backend_rex_busy_statestill trustsworkingas busy (bin/backends/rex.sh:1149) with the turn-end edge unproven for the version that was probed. If it never leavesworking, every busy consumer stays stuck on busy: away-mode inject deferral, pending-reply observation, the inbox doorbell, andbusy rex-native. Fix: run the opt-in guard (FM_REX_STATUS_LIVE=1) and record its turn-end line in docs/verification/runtime-backends.md, or reword the doc to say the guard checks this instead of claiming it is proven.bin/fm-spawn.sh:965- Simplification (re-reported because it was never decided in round 1): the newfm-spawn.sh --title <text>option and its relaunch rename branch (bin/fm-spawn.sh:4226-4231, 1013-1016) go beyond the intent ('make [titles] relevant and sidebar sized'). The automatic label already meets it: a kind marker plus the condensed backlog title, else the task id (fm_backend_rex_tab_label). No caller in AGENTS.md, the skills, or the scripts passes--title. Recommended remedy: remove the option and keep the automatic backlog-derived label.bin/fm-rex-marks.sh:207- Simplification (re-reported because it was never decided in round 1): thelabelschannel of config/rex-status-marks is a third mode the intent does not ask for. It prefixes '⚑ ' to tab labels throughwindow lsandwindow rename, and brings its own undo, channel switch, and cache mode (bin/fm-rex-marks.sh:205-209, 266-272; bin/backends/rex.shfm_backend_rex_label_flag). The intent asks for Rex-native signals (tab badges, session picker, Activity sidebar, Dock badge, notifications), which theonprogram-status mark already provides. Recommended remedy: removelabelsand keepon/off. If--titleis also removed,fm_backend_rex_label_flaghas no remaining caller.🔧 Fix applied.
3 warnings still open:
bin/fm-spawn.sh:965- Simplification: the newfm-spawn.sh --title <text>option and its relaunch rename path (bin/fm-spawn.sh:4228-4239, 1013) are not needed for the intent ('make [titles] relevant and sidebar sized'). That intent is already met by the automatic label: a kind marker plus the condensed backlog title, else the task id (fm_backend_rex_tab_label). Nothing in AGENTS.md, the skills, or any caller passes--title, so it only adds an unused override plus a relaunch-time rename branch. Recommended: remove the option and keep the automatic backlog-derived label.bin/fm-spawn.sh:965- Simplification (re-reported because it was never decided in round 1): the newfm-spawn.sh --title <text>option and its relaunch rename branch (bin/fm-spawn.sh:4226-4231, 1013-1016) go beyond the intent ('make [titles] relevant and sidebar sized'). The automatic label already meets it: a kind marker plus the condensed backlog title, else the task id (fm_backend_rex_tab_label). No caller in AGENTS.md, the skills, or the scripts passes--title. Recommended remedy: remove the option and keep the automatic backlog-derived label.docs/verification/runtime-backends.md:2331- Left behind by round 2's labels-channel removal (3e3fa93). That round deleted the labels fallback and rewrote the real smoke assertion (tests/fm-backend-rex-smoke.test.sh:142-145) into a plain tab-rename check with a new pass line ('...cleared alone; a tab rename takes'). The dated evidence block here still records the old output ('...cleared alone; the labels fallback flags the tab'). As a result, the verification doc presents a lab-run result for a feature that no longer exists, and the new rename assertion has no recorded run. No other stale reference remains:git grepfinds nolabel_flag,FLAG_PREFIX, or⚑anywhere else, and the configuration, rex-backend and skill docs were all updated. Fix: re-run the real smoke and replace the recorded line, or mark the line as recorded before the labels channel was removed.🔧 Fix applied.
2 warnings still open:
bin/fm-spawn.sh:965- Simplification: the newfm-spawn.sh --title <text>option and its relaunch rename path (bin/fm-spawn.sh:4228-4239, 1013) are not needed for the intent ('make [titles] relevant and sidebar sized'). That intent is already met by the automatic label: a kind marker plus the condensed backlog title, else the task id (fm_backend_rex_tab_label). Nothing in AGENTS.md, the skills, or any caller passes--title, so it only adds an unused override plus a relaunch-time rename branch. Recommended: remove the option and keep the automatic backlog-derived label.bin/fm-spawn.sh:965- Simplification (re-reported because it was never decided in round 1): the newfm-spawn.sh --title <text>option and its relaunch rename branch (bin/fm-spawn.sh:4226-4231, 1013-1016) go beyond the intent ('make [titles] relevant and sidebar sized'). The automatic label already meets it: a kind marker plus the condensed backlog title, else the task id (fm_backend_rex_tab_label). No caller in AGENTS.md, the skills, or the scripts passes--title. Recommended remedy: remove the option and keep the automatic backlog-derived label.🔧 **Test** - 1 issue found → no changes applied ✅
🔧 No changes applied.
✅ Re-checked - no issues remain.
env -u REX_SESSION -u REX_BLOCK -u REX_CLIENT -u REX_SERVER bash tests/fm-backend-rex.test.sh(34 ok)env -u REX_* PATH=$REX_BIN_DIR:$PATH FM_REX_SMOKE=1 bash tests/fm-backend-rex-smoke.test.shagainst a private fm-rex-lab server, using the bundled Rex CLI at the adapter's documented app-bundle path (12 ok, lab torn down)bash tests/fm-transition-lib.test.sh(all assertions passed)bash tests/fm-backend.test.sh(32 ok)bash tests/fm-daemon.test.sh(151 ok)bash tests/fm-teardown-endpoint-safety.test.sh(27 ok)bash tests/fm-teardown.test.sh(118 ok, 0 not ok before the 20-minute background limit stopped it)Post-run check: /tmp/fm-rex-lab-$UID is empty, no fm-rexlab processes remain, worktree clean✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.