Skip to content

Latest commit

 

History

History
158 lines (111 loc) · 19.5 KB

worker-states.md

File metadata and controls

158 lines (111 loc) · 19.5 KB

Worker states

Each worker's workspace is labeled <emoji> <ticket> (under Rex its window, <emoji> <ticket> <title>), and the emoji says who the ticket is waiting on. This page is the one place that lists every state a worker can be in, the emoji it shows, and what dispatch does about it: whether it nudges the worker, notifies you or escalates the ticket. Read it when you use dispatch, and before you change a rule that nudges, notifies or escalates.

The emoji

Emoji Waiting on Meaning
🟢 The worker, or dispatch The worker is busy, dispatch just nudged it, or dispatch is about to relaunch it or close its workspace
🟡 CI In Review, the worker is idle, gone or unconfirmed, the PR isn't ready and its checks are still running
👀 You In Review, the PR is ready for your review (the notification also needs an idle worker)
⏳ The PR's approvers In Review in a repo with open_pr_as = "draft", the PR is ready, you have opened it and its head isn't approved. No notification
🔀 Whoever merges In Review in a repo with open_pr_as = "draft", the PR is ready, opened and its head is approved. Dispatch merges it when auto_merge is on. When it is off the label waits on you, and an idle worker sends one "approved and ready to merge" notification per head
🔍 A session reviewing the PR In Review, a session ran dispatch review start for the PR's current head under an hour ago, and the worker is idle or gone. Don't merge yet
💤 You The worker is idle with no background task running and nothing else pending. Open its window
🔴 You Needs Human, the worker is blocked on a question popup, or the worker ran dispatch ask and waits for your answer. Answer in its window
⏸️ Nobody A Todo child of an In Progress parent, which keeps its tree, with a workspace still open

💤 changes the label and tells the sessions following the ticket once each time it appears (the notify-idle rule, In Progress tickets only, design tickets included). It sends nothing to the worker and no reminder, and it goes back to 🟢 within seconds of you typing into the window. That depends on the multiplexer already reporting the worker as working when the hook fires. Otherwise 💤 stays until the next Notification or resync.

How the label is chosen

The first line that fits wins.

  1. The ticket is Needs Human: 🔴.
  2. The ticket is paused and its worker's Claude session is gone: ⏸️.
  3. The worker is blocked on a question popup, or is asking: 🔴. A worker is asking from the first read that sees it idle after it ran dispatch ask until its session takes a message, typed or sent by dispatch, or ends. A task notice, the message Claude Code hands the session when one of its own background tasks finishes, ends no ask. It sits above the ready-PR line, so an ask shows 🔴 over 👀.
  4. The worker is working, or dispatch sent it a nudge and no read has yet seen it working or blocked: 🟢.
  5. A session is reviewing the PR (a PR review, see Reviewing a PR) and the worker is idle or gone (a worker whose launch isn't confirmed counts as gone, as on line 7): 🟢 if the worker is idle and line 8 or line 10 holds for it, otherwise 🔍. 🔍 shows whatever the PR's state.
  6. The PR is ready and the worker is idle or gone: ⏳ if the repo opens drafts, the PR has left draft and its head isn't approved, 🔀 if the same PR is approved, otherwise 👀. "Approved" is what auto_merge counts, so a repo's approval_checks that haven't passed keep the PR at ⏳.
  7. The worker's Claude session is gone, or its launch isn't confirmed: 🟡 if the PR's checks are running, otherwise 🟢.
  8. The worker is idle and its last Stop (the Claude Code hook that records when a turn ended) lists a background task still running and is under 60 minutes old, or its session took a message after that Stop: 🟢. A message is anything typed to the worker or sent by dispatch, so 💤 clears when you type, before the multiplexer reads the worker as working.
  9. The PR's checks are running: 🟡.
  10. The worker has no Stop record, or its Stop didn't say what was running: 🟢. Nothing proves it is waiting.
  11. Otherwise: 💤.

A PR that dispatch could not read leaves a 🟢, 👀, ⏳, 🔀, 🟡 or 💤 label as it is until the next read. A 🔍 label is worked out again with the PR as dispatch last read it, so it stays while that review applies and line 5 gives 🔍, and done or the hour brings back the label that PR gives. When dispatch has read no PR for the ticket since it started, 🔍 stays while the PR review is under an hour old and line 5 still gives 🔍, and otherwise the label follows the lines above as for a ticket with no PR.

After the ask ends the label follows the lines above with no case of its own, so a worker you just answered shows 🟢 even before the multiplexer reads it working. Under Rex 🔴 shows moments after the turn ends; under herdr and the Herdr app it shows at Claude Code's idle_prompt Notification, about 60 seconds later, as 💤 does. While the session log can't be read, nothing is read as an ask and the label follows the other lines.

The Stop record comes from the plugin's Stop hook (dispatch record-stop), which also reports the turn's closing message and the path of the harness's transcript of the session. Dispatch keeps both in a file beside the session log. dispatch turn prints the message only while the worker is not in a turn, and it asks the harness whether the session took a message after the Stop, so a prompt report lost while dispatch run was down still counts. The plugin's Notification and UserPromptSubmit hooks run dispatch wake, which asks the running loop to read the multiplexer and the pools again and run a cycle. That is not a resync, so nothing that failed is retried and no PR is read again unless a worker just went idle. Every non-empty prompt the hook sees is written to the session log as a command or a plain message, and a worker whose session took one after its latest Stop is in a turn: its waiting fact is false, on a Needs Human ticket as well as an In Progress one. Claude Code raises an idle_prompt Notification about 60 seconds after a turn ends with nobody typing, so 💤 shows within about a minute of the worker going idle. Without a running loop the label moves at the next resync. A worker dispatch just nudged shows 🟢 until a read sees it working or blocked, or the next resync. A read that still sees it idle keeps the 🟢, so a second nudge cannot go out before Claude takes the first.

Under Rex the loop also listens to Rex's event stream. A worker's status change, its Claude exiting and its tab closing each make the loop read only that worker's pane, so 💤 and the idle and blocked notices show within moments, with no Notification and no full read. A stream that ends prints dispatch: the worker stream ended: <reason>; workers update at each resync until it reopens to stderr, after the time like the other stderr lines. The loop reopens it at the next resync, including one dispatch tick forces. The herdr TUI and the Herdr app have no stream and behave as before.

A worker can report no status, as Claude does while it shows a startup dialog. It reads working, and on every host dispatch sends nothing to it. A nudge to it fails with "status unknown, nothing sent" and the send record is withdrawn. If the launch that started it died before its kickoff was confirmed, the worker reads idle instead, so close-unconfirmed-worker closes it after its grace period.

Every combination

"Gone" means the workspace exists and the worker's Claude session is gone (the state none). "Unconfirmed" means the launch's first instruction hasn't run yet. A ticket with no workspace has nothing to label. The tests in labels_test.go cover each row, and ask_test.go and asking_alone_test.go the asking rows.

In Progress

Worker Stop record Emoji What dispatch does
Working any 🟢 Nothing
Idle none, or without the task list 🟢 Nothing
Idle a task still running, under 60 minutes old 🟢 Nothing. After 60 minutes it counts as stopped, so the next row applies
Idle stopped, nothing running 💤 Tells the sessions following the ticket once. No nudge, nothing sent to the worker
Idle, asking any 🔴 Tells the sessions following the ticket once per ask that the worker asked a question (notify-asked), and sends no "worker is idle" notification while it asks. No rule nudges it (an-asking-worker-is-left-alone). Never moves the ticket, and the worker keeps its place under max_in_progress
Idle, unconfirmed any 🟢 After 5 minutes, closes the workspace and relaunches the worker. The closes count toward launch_failure_limit
Blocked on a popup any 🔴 Notifies on the first cycle and every blocked_renotify_minutes. Never nudges, never moves the ticket
Gone n/a 🟢 Relaunches the worker. A launch a rule asked to stack on another ticket's PR starts a new branch at that PR's head and records it, and its receipt says stacked on <ticket> at <short head> (<branch>). A relaunch never changes the record

In Review

dispatch reads the PR only when the worker is idle or gone.

Worker Stop record PR Emoji What dispatch does
Working any not read 🟢 Nothing
Blocked on a popup any not read 🔴 Notifies as in In Progress
Idle, asking any any 🔴 Tells the sessions following the ticket once per ask, as in In Progress. No "PR is ready for review" or "approved and ready to merge" notification while it asks; it goes out once the ask ends and the worker is idle. No PR or restack nudge, no escalation for ignoring PR nudges, and no merge under auto_merge while it asks (an-asking-worker-is-left-alone)
Idle none ready 👀, ⏳ or 🔀 👀 notifies once per head commit. ⏳ says nothing. 🔀 notifies once per head commit that the PR is approved, unless auto_merge will merge it
Idle none checks running 🟡 Nothing about the label. Nudges for a failed check, changes requested or a merge conflict
Idle none none, or not ready with no check running 🟢 Nothing about the label. Nudges for a failed check, changes requested or a merge conflict
Idle stopped ready 👀, ⏳ or 🔀 As above
Idle stopped checks running 🟡 Nothing
Idle stopped none, unresolved thread or mergeability not computed on a read with no ready read just before it 💤 Nothing
Idle stopped failed check, changes requested or merge conflict 💤, then 🟢 once nudged PR nudge every 5 minutes. After nudge_limit nudges with no push, moves the ticket to Needs Human
Idle a task running ready 👀, ⏳ or 🔀 As above
Idle a task running anything else 🟢 Nudges for a PR that needs work, as above. The label stays 🟢
Idle without the task list checks running 🟡 Nothing
Idle without the task list anything else 🟢 Nudges for a PR that needs work, as above. The label stays 🟢
Idle, unconfirmed any ready 👀, ⏳ or 🔀 Closes the workspace after 5 minutes
Idle, unconfirmed any checks running 🟡 Closes the workspace after 5 minutes
Idle, unconfirmed any anything else 🟢 Closes the workspace after 5 minutes
Gone n/a ready 👀, ⏳ or 🔀 Nothing. The notification waits until the worker is idle
Gone n/a checks running 🟡 Nothing
Gone n/a anything else 🟢 Relaunches the worker for a PR that needs work or an unseen review thread

A ready PR keeps its 👀, ⏳ or 🔀 while GitHub is still computing whether it merges cleanly after the base branch moves. It holds when the PR's last read was ready (or held the same way) and the new read has the same head, draft and approval. The ready and waitingOn facts are Unknown, so a rule holds instead of seeing a PR that is not ready. Every read that still finds GitHub computing holds again, with no time cap, and the first read where GitHub answers decides. A read with no ready read of the PR just before it (the PR's first read, one after the worker was working, a failed read, or a dispatch restart) is not held and shows 💤, as in the table.

The Stop record column above is what the emoji label reads, for a worker in any status. The busy and lastStop facts rules read come from the Stop record only for an idle worker on an In Progress or Needs Human ticket, so for an In Review worker busy is false and lastStop is when dispatch first saw it idle.

While a session reviews the PR, an idle or gone worker shows 🔍 in place of the Emoji column in every row above that has a PR, except that a confirmed idle worker whose Stop lists a running task and is under 60 minutes old, or whose session took a message after its Stop, shows 🟢, as does an idle worker with no Stop record or whose Stop didn't say what was running, and a worker dispatch just nudged. Working, blocked and asking workers show what the table says. Dispatch nudges, notifies and merges exactly as the table says.

A PR that waits on its approvers still nudges its worker for a failed check, a merge conflict, changes requested or new activity.

An idle In Review worker whose PR gains a review or comment gets the activity nudge once per new item.

None of these nudges reaches a worker that is asking, or one still on a message it took, as Asking with dispatch ask describes.

Other statuses

Ticket Worker Emoji What dispatch does
Needs Human any 🔴 Notifies once on entering the status, a design ticket included. While the worker has not paused (it is working, has no Stop record, or took a message after its last Stop) the notice waits for it to pause or for 5 minutes after the status began, whichever comes first. A worker blocked on a popup is held too. With no worker it notifies at once
Paused (Backlog or Todo) gone none Returns the tree, discarding uncommitted changes. A Todo child of an In Progress parent keeps its tree and shows ⏸️
Paused live unchanged Closes the workspace, then ⏸️

A Needs Human worker is nudged about new reviews and comments on its PR even while it asks, since nobody else acts on them.

A design or design-review worker is never nudged, and its ticket notifies like any other for a blocked popup, for Needs Human and for going idle. Its label follows the same lines as a build worker's, and 💤 is how you see that a design is waiting on you.

What dispatch no longer does

Dispatch used to type a stall nudge into an idle In Progress worker, and to notify you on every 6th stall nudge and once when a nudge went unanswered for an hour. Both are gone. The stall nudge could land on top of a question the worker had just asked and read as the answer. Without it, nothing prompts a worker that stopped In Progress without moving its ticket, and 💤 is how you see it. Going 💤 sends one message to the sessions following the ticket, which only tells them and never sends the worker anything.

A build worker asks you its questions in chat, not through the question popup. A popup it still opens is handled as before: the multiplexer reports the worker blocked, the sessions following the ticket get the notification, and the label is 🔴.

Asking with dispatch ask

A worker that needs your answer runs dispatch ask, says why in chat and ends its turn. Dispatch keeps the ask in the session's log and moves no ticket. Once the worker is idle its window shows 🔴, and each session following the ticket gets one message:

dispatch event (worker asked a question): ENG-12's worker asked a question in its workspace: <title> Ticket: <url>

The ask ends when the session takes a message, typed in its window or sent by dispatch tell (a task notice doesn't count, see below), or when the session ends. A worker that asks again after your answer shows 🔴 again and sends a second message. Running dispatch ask twice before your answer records one ask and sends one message. A restart of dispatch run keeps the 🔴 and sends no second message, because the ask is in the session log and the message's once key is in the ledger. A worker whose session ends while it asks is gone, and the rules relaunch it into a new session with nothing asked.

dispatch ask run while dispatch run is down prints dispatch: not running, exits 3 and records nothing. The worker shows 💤 or its PR label as it would without the ask.

A ticket in Needs Human, whoever moved it there, shows 🔴 and notifies with notify-needs-human, whether or not its worker asked.

While a worker asks, the shipped rules leave it alone: no PR nudge, no restack nudge, no escalation for ignoring PR nudges, and no merge under auto_merge. The exemption an-asking-worker-is-left-alone in rules/asks.ts takes those actions away whichever rule queued them. In Needs Human the nudges still go out, as above. dispatch tell, with or without --turn, still delivers, since it is you answering.

A worker's own finished background task does not end its ask. Claude Code hands the session a task notice, a message that opens with <task-notification>, and the worker shows 🟢 while it handles it, then 🔴 again when it stops, with no second message to followers. That handling ends a turn of its own, so dispatch tell <ticket> --turn <at> for the turn that asked is refused as moved past. dispatch turn prints the new turn's time.

Any idle worker that took a message, an answer to its ask or anything else you typed or dispatch tell sent, is left alone the same way until it ends the turn that message started, or until 15 minutes after the message when that turn end never arrives. The exemption is a-worker-finishes-its-message-first in rules/nudges.ts, and the 15 minutes is MESSAGE_HOLD in rules/shared.ts. So nothing lands on top of your answer while the multiplexer still reads the pane idle, and a PR that still needs work is nudged again once that turn ends.

While the session log can't be read, neither exemption holds anything, and nudges and merges go on as for any idle worker. A nudge sent then is a message, so it ends the ask, and the worker shows 🔴 again only once it runs dispatch ask again and its session log can be read.

Reviewing a PR with dispatch review

A session about to review an In Review ticket's PR reads the PR's head and reports it:

$ gh api repos/kapetan-io/dispatch/pulls/311 --jq .head.sha
4f2a9c1d0b7e...
$ dispatch review start ENG-842 4f2a9c1
reviewing ENG-842 at 4f2a9c1
$ dispatch review done ENG-842
review of ENG-842 done

start takes the ticket and 7 to 40 hex digits of the head, in either case, and checks nothing else: a start on a ticket that isn't In Review, or at a head the PR has moved past, shows nothing. Any session's review counts, a later start replaces the earlier one, and done ends the ticket's review whoever started it. done with no review prints dispatch: <ticket> has no review and exits 1. Both commands exit 3 with dispatch: not running, recording nothing, while dispatch run is down.

The review ends at done, at a push (while the PR's head doesn't start with the reported one) or an hour after start, at the first cycle after the hour. Both commands wake dispatch, so 🔍 shows, and leaves at done, within moments. A restart of dispatch run doesn't end it, since dispatch keeps it in dispatch.db, and the hour still counts from the start. A ticket with no PR has no head to match and shows no 🔍.