Skip to content

Add a typed supervision event contract for pull-only backends #682

Open

Description

@e-jung

Summary

FirstMate describes supervision as event-driven and zero-token, but its reference tmux backend and experimental Orca backend still use a 15-second polling loop plus terminal-tail regexes as their default lifecycle signal. Herdr can replace the blind sleep with pane.agent_status_changed events, but the watcher still performs periodic reconciliation and most backends have no typed lifecycle source.

Add a backend-neutral typed supervision event contract so supported harness/backends can report durable task transitions without terminal scraping, while retaining the existing watcher as a compatibility and reconciliation fallback.

Verified current behavior

Current main documents and implements:

  • FM_POLL defaults to 15 seconds in bin/fm-watch.sh.
  • tmux, Orca, zellij, and cmux report no native busy primitive and fall back to terminal-tail regex detection.
  • Herdr protocol 16+ can block on pane.agent_status_changed, immediately surfacing blocked, but capability or runtime failures revert to polling.
  • Append-only status files are wake-event history, not authoritative current state; fm-crew-state.sh combines no-mistakes state, backend busy detection, pane content, and status-log fallback.
  • Several additional guards, beacons, queues, daemon paths, and turn-end hooks compensate for missed or ambiguous supervision signals.

This architecture is careful and defensive, but the number of compensating mechanisms is also evidence that terminal state is carrying lifecycle semantics it cannot authoritatively represent.

Why it matters

For manager-of-managers workflows, silent delay or ambiguity at each layer compounds:

  • a finished worker can look idle, stale, or still working depending on pane text;
  • a steer can be accepted by the terminal transport but remain queued inside a busy harness;
  • restart recovery must infer current truth from several partially overlapping records;
  • the same work can be represented differently across tmux, Herdr, Orca, and harness-specific hooks.

Polling itself is not expensive in tokens, but terminal scraping and inferred state make unattended correctness hard to prove.

Proposed direction

Define a versioned backend-neutral event envelope such as:

task_id, attempt_id, sequence, event_type, state, timestamp, backend_identity, payload_digest

Minimum event types: started, heartbeat, blocked, needs_decision, completed, failed, interrupted, and endpoint_exited.

Requirements:

  1. Events are appended durably before the producer advances its local state.
  2. Consumers resume from a cursor/sequence after restart and deduplicate replay.
  3. A terminal or backend exit deterministically reconciles the task attempt.
  4. Harness hooks, Herdr events, and Orca orchestration messages normalize into the same envelope.
  5. Pane scraping remains an explicitly degraded fallback, never silently equivalent to typed state.
  6. The watcher periodically reconciles authoritative task/endpoint state even when push delivery appears healthy.

Acceptance criteria

  • A supported event-capable backend reports blocked, completed, and failed without reading terminal text.
  • Completion reaches the first mate within two seconds under normal operation.
  • Killing and restarting the first-mate session replays an unconsumed event exactly once.
  • Killing a worker endpoint cannot leave the task indefinitely working or ready without a recorded failure/retry state.
  • Duplicate events and reconnects are idempotent.
  • The UI/CLI exposes when a backend is using typed events versus polling/scraping fallback.
  • Existing tmux users keep working through the fallback path.

Related

This is intended as an incremental contract beneath the existing recovery policy, not a request to delete the watcher. Prepared with AI assistance after comparing FirstMate's current watcher and backend implementations. Reporter: @ericjung.

Activity

  1. str0203 commented on Aug 10, 2026

    @str0203

    Orca is now a good first concrete backend for this contract rather than only an example. The current CLI exposes supervised-worker state, while the broader versioned protocol discussion is active upstream:

    A bounded first slice could add an optional backend capability such as wait_events(cursor, timeout) while leaving the existing watcher polling path unchanged:

    1. capability-probe the Orca supervised-worker/event surface;
    2. persist a per-task attempt identity and event cursor;
    3. normalize only authoritative Orca transitions into the proposed envelope;
    4. append/durably acknowledge before advancing the cursor;
    5. fall back visibly to polling when the capability or event stream is unavailable;
    6. periodically reconcile authoritative worker/endpoint state even when push looks healthy.

    That would let the contract prove itself against one real consumer before generalizing every harness/backend. The minimum useful acceptance test is blocked + completed + failed delivery, restart replay exactly once, duplicate-event dedupe, and a visible diagnostic naming typed-events versus polling fallback.

  2. kunchenguid commented on Aug 24, 2026

    @kunchenguid
    Owner

    Speaking as Kun's firstmate: inspected on current main 8fa0505e48a1.

    VISION.md (each rule):

    • One captain, one interface: aligns if typed events replace scrape-only wakes the captain should never see.
    • Authority is explicit: aligns as opt-in per backend capability, with poll fallback.
    • Scripts own the mechanics: aligns. A typed contract is exact; regex tailing is not.
    • A restart is a non-event: aligns (durable transitions).
    • Delegation with a spine: aligns. Existing primitives still poll (FM_POLL default 15 in bin/fm-watch.sh).
    • The fleet outlives any vendor: aligns. Bind to semantics backends expose (Herdr pane.agent_status_changed; pull-only stay on reconcile).
    • Scope: aligns.

    Related open #1813 / #683. No covering PR. Labeling ready-for-pr.

  3. added
    ready-for-pr
    on Aug 24, 2026
  4. kunchenguid commented on Aug 24, 2026

    @kunchenguid
    Owner

    Speaking as Kun's firstmate:

    Scheduled 3:10am PT 8/24 pass (FM-FMOSS-CRON). VISION.md read in full from current main 8fa0505e48a155da78a9aeeb50911719dc558710 (#2939). Unstamped; one later comment from str0203 (2026-08-10) proposing Orca as first consumer. No covering implementation PR.

    Inspected bin/fm-watch.sh (POLL=${FM_POLL:-15}), bin/fm-backend.sh fm_backend_has_push / fm_backend_events_capable / fm_backend_wait_transition (herdr-only; others return incapable/2), bin/backends/herdr.sh fm_backend_herdr_events_capable (events.subscribe + pane.agent_status_changed), bin/fm-busy-event.sh / docs/architecture.md (harness turn busy/idle, not backend task lifecycle), bin/backends/orca.sh, docs/orca-backend.md (no native Orca busy/events; watcher has no Orca push path), and tests/fm-supervision-events.test.sh (Herdr splice only).

    Still present. Existing primitives do not cover the proposed envelope:

    • Herdr can replace the sleep with a bounded blocked-edge wait; tmux, Orca, zellij, and cmux stay on the 15s poll.
    • fm-busy-event.sh is adapter-owned turn busy/idle/unknown/dead. It is not started / blocked / completed / failed / interrupted / endpoint_exited with a cursor.
    • No versioned backend-neutral event envelope, no wait_events(cursor, timeout), no diagnostic that names typed-events versus polling fallback for pull-only backends.

    VISION (inspected those files):

    • One captain, one interface: aligns if typed states surface as outcomes (blocked / completed / failed), never as reconstructed terminal mechanics.
    • Authority is explicit: aligns. Capability-gated opt-in with polling as the explicit fallback; never assume a backend is event-capable.
    • Scripts own the mechanics: aligns. Bind to vendor-exposed transitions instead of terminal-tail regex.
    • A restart is a non-event: aligns. Cursor/sequence replay and deterministic endpoint-exit reconcile are the durable close.
    • Delegation with a spine: mixed. This is a contract under the existing watcher, not a new task shape. Resist a second event bus or a framework every backend must implement. Compose with fm_backend_wait_transition and the busy record; first real consumer is Orca supervised-worker state (Orca backend: adopt Orca's supervised-worker primitives instead of raw worktree + terminal #1813), as str0203 sketched.
    • The fleet outlives any vendor: aligns. Contracts bind to semantics a vendor actually exposes. Herdr remains one adapter; Orca/tmux keep the poll fallback when they have no events.
    • Scope: aligns as command-layer adapter contract. Do not grow firstmate into a general orchestrator protocol (upstream [Feature] Agent-Orchestrator Protocol: extract 3-layer protocol as universal standard stablyai/orca#9810 stays upstream).

    Constraints: incremental; keep the watcher as compatibility/reconcile; pane scrape is a named degraded mode; acceptance stays blocked + completed + failed without terminal text, restart replay exactly once, duplicate dedupe, and a visible typed-vs-poll diagnostic. Related open #1813 / #2084 / #683.

    Labeling ready-for-pr. ready-for-pr is a queue label, not a merge vote.

  5. devin-ai-integration commented on Sep 24, 2026

    @devin-ai-integration
    No description provided.
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

    enhancementready-for-pr

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions