Skip to content

Daemon-mode watcher (or durable wake queue) — supervisor misses crewmate wakes between turns in chat mode #27

Closed

Description

@e-jung

Summary

In interactive (chat) mode the supervisor only handles crewmate wakes when it is already active — i.e. on the captain's next message. A crewmate that finishes, blocks, or needs a decision during a quiet stretch sits unhandled until something pokes the supervisor. Finished work goes unrelayed, queued tasks don't dispatch, blocked crewmates wait.

Root cause

bin/fm-watch.sh has been a one-shot since the initial commit (6 commits, all refinements — coalesce signals, liveness guard, silence idle, prevent starvation — never a daemon or foreground loop). It runs as a background task, exits on every wake, and relies on the supervisor to restart it ("restart it after handling every wake"). The liveness guard (bin/fm-guard.sh) is pull-based: it surfaces a stale-watcher warning only on the supervisor's next fleet action (AGENTS.md:409 — "the protocol no longer relies on remembering"). There is no shipped mechanism that proactively routes a watcher wake into a supervisor turn.

So in chat-mode (supervisor turns paced by captain messages), wakes that land between messages are not handled promptly: the supervisor goes idle after each reply, the watcher exits on the next wake and stays exited, and the guard fires only on the next fleet action.

This is distinct from #26 (the watcher crashing on Linux stat). #26 is a crash; this is the design's wake-routing gap in interactive use.

Impact (observed in this session)

  • Three finished scout tasks sat unrelayed for ~2h until the captain noticed.
  • The watcher repeatedly goes stale (observed 679s and 222s stale across consecutive turns) and must be manually restarted each supervisor turn while crewmates are active.
  • The captain cannot walk away and trust that in-flight crewmates will be advanced (unblocked, dispatched, relayed) — the fleet effectively stalls between captain messages.

Proposed fix

A daemon-mode watcher (or equivalent durable wake queue):

  • The watcher runs continuously (does not exit on wake), detects signal/stale/check/heartbeat events internally, and appends each wake to a durable file (e.g. state/.wake-queue).
  • The supervisor drains the wake-queue at the start of every turn; fm-guard.sh still covers the "supervisor totally idle" case as a backstop.
  • This preserves the design's stated goals (zero-token idle, responsive to the captain, no foreground-blocking per AGENTS.md:415-416) while removing both the "watcher exits and isn't restarted" failure mode and the laggy-wake symptom.

Open question (broader scope): whether to also support an autonomous supervisor loop mode (supervisor self-paces through wakes without captain messages) for true unattended operation. The daemon-mode watcher is the minimal fix that makes the current chat-mode reliable; the autonomous loop is the larger follow-up.

Repro

  1. Spawn a crewmate on any task.
  2. Stop sending the supervisor messages; let the crewmate write a done: status.
  3. Observe: the watcher exits on the status signal and is not restarted; the supervisor does not relay the completion until the next captain message triggers a state check. fm-guard.sh warns only on the supervisor's next fleet action.

Activity

  1. e-jung commented on Jun 20, 2026

    @e-jung
    ContributorAuthor

    Refined fix after reproducing this live: the root issue isn't only the watcher exiting — it's that even a durable wake queue goes unhandled when the supervisor (an interactive opencode/claude/codex session) only takes turns on captain messages. Wakes between messages sit forever.

    Proposed fix: a supervisor wake-injection daemon (bin/fm-supervise-daemon.sh, new — separable from fm-watch.sh so it doesn't conflict with #26):

    • A long-lived background loop that runs the watcher and, on each wake, injects the wake reason as a message into the firstmate supervisor's tmux pane (tmux send-keys), which triggers a fresh supervisor turn.
    • Each wake → one supervisor turn → handle (unblock / dispatch queued / queue captain-decisions) → idle → next wake repeats. Supervision becomes self-triggering and independent of captain messages — the actual mechanism for "supervise while away."
    • Pair with the daemon-mode watcher (Daemon-mode watcher (or durable wake queue) — supervisor misses crewmate wakes between turns in chat mode #27 itself) so the underlying detector never silently dies; the injection daemon is what turns detection into action without a human prompt.

    Honest scope limit (separate follow-up): this keeps supervision alive within a harness session. Surviving the harness itself crashing (e.g. opencode auto-update exits) needs a system-level supervisor (systemd/launchd relaunch + reattach) — a distinct layer worth its own issue.

    Net: daemon-mode watcher (detect reliably) + wake-injection daemon (act without the captain) = deterministic supervision. Filing this here so the fix approach is captured; can implement as a crewmate-built PR on the fork.

  2. e-jung commented on Jun 20, 2026

    @e-jung
    ContributorAuthor

    Refinement deployed locally: fm-supervise-daemon.sh now filters routine heartbeat wakes (logs + skips injection) so autonomous supervision doesn't churn the supervisor's context with no-op fleet reviews. Actionable wakes (signal/stale/check) still inject. One-line case before the injection block; worth including when this daemon lands upstream.

  3. kunchenguid commented on Jun 20, 2026

    @kunchenguid
    Owner

    thanks @e-jung - curious what agent harness are you running firstmate from?

  4. kunchenguid commented on Jun 20, 2026

    @kunchenguid
    Owner

    Thanks again @e-jung - this and the stat fix are both excellent.

    Landed: a durable wake-queue (state/.wake-queue) + singleton enforcement on the watcher, with wakes enqueued before any suppression marker advances. That kills the two concrete bugs - duplicate watchers (now physically impossible) and silently-consumed wake edges (wakes are now durable and lossless). Universal and harness-agnostic.

    On the remaining problem - and why a daemon won't fully solve it. We dug in and concluded the deeper gap isn't fixable in firstmate's shell layer. A shell process can detect events and queue them, but it cannot start a new agent inference turn - only the harness can. So "the supervisor wakes itself between user messages" is fundamentally a harness capability, not something a watcher daemon can manufacture. A persistent detector would faithfully fill the queue, but the queue still only gets drained when something injects a supervisor turn.

    Turn-injection has exactly three flavors, per harness:

    1. fires a turn on background-process completion (e.g. Claude Code - this is what already gives walk-away there: the exiting watcher + heartbeat re-invoke the supervisor with no user message);
    2. a scheduler that injects turns (Claude Code cron; Codex thread automations);
    3. neither → the only path is an external driver outside the agent (OS cron/launchd, or a shell loop) running the harness non-interactively (claude -p / codex exec / opencode run) to drain + act.

    So our plan: ship the universal durable-queue (done), model turn-injection as a per-harness adapter fact, and scope true unattended/walk-away operation as harness-specific - free where the harness offers (1) or (2), and requiring an external exec-loop where it offers neither. A persistent-detector/blocking-waiter refactor is still on the table for ergonomics, but we don't think it's the thing that unlocks walk-away.

    Does that match your experience - and do you see a universal in-agent mechanism we're missing?

  5. e-jung commented on Jun 20, 2026

    @e-jung
    ContributorAuthor

    Thanks Kun! Running firstmate from opencode (glm-5.2) — the chat-mode wake gap is exactly what bit us, since opencode only turns on a user message.

    Your framing matches our experience precisely. The daemon we deployed locally is the opencode-specific turn-injection: it runs the watcher, and on each wake does tmux send-keys of the wake into the supervisor's opencode pane, which opencode treats as a user message and turns on. So walk-away works for opencode via that shim — but only because opencode accepts injected pane input as a turn-trigger, which is exactly the harness capability you're describing, not a universal one. On Claude Code we wouldn't need it (your flavor 1).

    So: agree there's no universal in-agent mechanism — your three-flavors model covers it cleanly. The durable queue you landed is the right universal layer; turn-injection stays per-harness. For opencode (flavor 3 — neither native completion-turns nor a scheduler), it's either the pane-injection shim (what we run) or a non-interactive opencode run loop draining the queue — the latter is probably the cleaner long-term. Happy to help validate the per-harness adapter framing as it takes shape.

  6. added a commit that references this issue on Jun 22, 2026
    b7c933e
  7. added a commit that references this issue on Jun 22, 2026
    5810a3b
  8. armchairo commented on Aug 22, 2026

    @armchairo

    New churn case (2026-08-23): a secondmate agent parked in a FOREGROUND fm-watch-arm.sh wait (aa home) trips the parent home's stale escalation every cycle - escalations 1-6 in one night, each demanding deep inspection, while every inspection finds the same healthy state: agent revision static by design, child home's own watcher beacon fresh. The #11 idle-by-design backoff does not cover this shape because the pane reads working (blocked on the foreground tool) rather than done/paused. Suggested fix: treat a static-revision pane whose recorded home has a fresh .last-watcher-beat as idle-by-design for backoff purposes.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions