Skip to content

feat(orchestration): detect a wedged supervised worker and surface it as a signal - #15273

Open
artile wants to merge 6 commits into
stablyai:mainfrom
artile:artile/wedged-worker-signal
Open

artile wants to merge 6 commits into
stablyai:mainfrom
artile:artile/wedged-worker-signal

Conversation

@artile

@artile artile commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

A supervised worker that hangs is indistinguishable from one that is thinking hard until the coordinator's own check --wait window expires — routinely 15 to 60 minutes of nothing. The runtime already receives turn-boundary events from each worker's harness and already owns its PTY, so it can notice the silence far sooner.

This adds that detection and nothing else.

What it does

  • Collects progress evidence per ready dispatch: harness turn boundaries, harness hook events, PTY output, accepted heartbeats, messages the worker itself sent, and recorded ask threads.
  • Classifies each dispatch as working, blocked, unknown or wedged. Absence of evidence classifies as unknown, never as wedged, and unknown is never promoted to working.
  • Synthesizes one escalation into the owning Run's mailbox when a dispatch stays quiet past the threshold, describing what was and was not observed, then repeats only on a long cadence with a rising count.
  • Ships thresholds with documented defaults (15 min wedge, 30 min re-escalation, 60 s scan), each overridable through an environment variable and clamped so a bad value cannot cause spam.

What it deliberately does not do

  • It never stops, kills, restarts, interrupts, closes, focuses or writes to a worker. No process, terminal or filesystem action of any kind.
  • It never fails a dispatch, never marks a task failed, never touches the circuit breaker. The escalation's taskId stays nested under payload.wedgedWorker precisely because the retired coordinator loop fails a dispatch on a top-level payload.taskId.
  • It never escalates a worker blocked on an external wait. An unanswered ask, a live ask or check --wait on the dispatch mailbox, and a harness reporting waiting or blocked all classify as blocked. The dispatch preamble already tells workers those calls are themselves liveness signals; this honours that.
  • It never escalates a federated dispatch. A worker on another Orca server classifies as unknown, because local evidence says nothing about it.
  • It does not change the rules coordinators follow. A check --wait timeout is still a checkpoint, not a failure, and heartbeats plus visible terminal activity still mean alive, not done. The escalation body says so, and the orchestration guide now says a rising count is the same wedge reported again.

Delivery

The escalation reaches the coordinator through the same notifyMessageArrived path that worker_done, question and setup-status messages already use, including push-on-idle into the coordinator's own pane. No such delivery is ever aimed at the worker.

Cost

The scan runs on its own unref'd timer, short-circuits on the DB's cached dispatch-emptiness probe, and stops itself as soon as a pass finds no supervised worker. It adds no per-message work. The detector is armed when a supervised worker becomes ready and when workers are adopted after a restart.

Compatibility

No RPC shape and no stream opcode changes. It publishes new content of an existing message type on an existing path, which is a Rule 3 concern in docs/reference/remote-wire-compatibility.md: an older paired client receives an ordinary escalation it can read, print and acknowledge, and it ignores the payload key it does not know. Federated dispatches never produce this signal, so a mixed-version pair cannot see one attributed to a worker its own server does not own.

Tests

src/main/runtime/orchestration/wedged-worker-detector.test.ts, wedged-worker-runtime-monitor.test.ts and worker-progress-thresholds.test.ts cover wedged, working, blocked on ask, blocked in check --wait, harness waiting, settled, missing pane, disconnected pane, replaced process, federated, deduplication at the scan interval, the long re-escalation cadence, count reset after resumed progress, count resumption after a restart, and detection disabled.

The monitor test drives the real runtime adapter behind a proxy that fails on any runtime call outside the four read-only ones this path is allowed to make, so "it touches no terminal" is machine-checked rather than asserted.

npx vitest run --config config/vitest.config.ts \
  src/main/runtime/orchestration/wedged-worker-detector.test.ts \
  src/main/runtime/orchestration/wedged-worker-runtime-monitor.test.ts \
  src/main/runtime/orchestration/worker-progress-thresholds.test.ts
# 24 passed

npx tsc --noEmit -p config/tsconfig.node.json
# No errors found

npx vitest run --config config/vitest.config.ts src/main/runtime
# 3897 passed, 6 skipped

oxlint, the native and type-aware code-quality audits, the max-lines ratchet and the bundled-skill-guide check all pass. No max-lines suppression was added; the detector is split across four modules instead.

Documentation

docs/reference/wedged-worker-detection.md records what counts as progress, what classifies as unknown, why a blocked worker is never a wedge, the cadence and its defaults, and the message shape. It is linked from AGENTS.md, which is what the .gitignore allow-list for tracked reference docs requires.


Moved from #13762, same commits, same head SHA. That pull request was opened from an organisation-owned fork, and GitHub refuses maintainer pushes on org-owned forks even when maintainer_can_modify reports true — so a maintainer could not push a fixup to it, only ask or rewrite. This one is on a personal fork, where a maintainer push works.

The review history stays readable on #13762: #13762

artile added 6 commits August 11, 2026 09:31
Add the evidence model behind a wedged-worker signal: a DB query for "ready"
supervised dispatches with their heartbeat, worker-message and question
timestamps, plus a pure classifier that turns those and a pane liveness sample
into working, blocked, unknown or wedged.

Absence of evidence classifies as unknown and never as wedged, and unknown is
never promoted to working. Federated dispatches, unobservable panes and panes
whose process was replaced all classify as unknown.

Thresholds come from the environment with documented defaults and are clamped so
a bad value cannot turn the detector into a spammer.
Synthesize one high-priority escalation into the owning Run's mailbox when a
supervised worker shows no progress evidence past the threshold, then repeat only
on the long cadence with a rising count. Resumed progress or a settled dispatch
clears the cadence, and the count is read back from the last escalation so a
runtime restart cannot restart it at one.

Detection only. The path performs no process, terminal or filesystem action: it
never stops, kills, restarts, interrupts, closes, focuses or writes to a worker.
The escalation says so in its own body, and its taskId stays nested under
payload.wedgedWorker so the retired coordinator loop cannot read it as a dispatch
failure.
Arm the wedged-worker detector when a supervised worker becomes ready and when
workers are adopted after a restart. The runtime supplies the two things the
detector cannot see for itself: the worker pane's PTY output and harness turn
boundaries, and whether a blocking ask or check --wait is parked on the
dispatch's mailbox.

The scan is off the hot path. It runs on its own unref'd timer, short-circuits
on the DB's cached dispatch-emptiness probe, and stops itself as soon as a pass
finds no supervised worker, so a runtime that never orchestrates pays nothing.
Record what counts as progress evidence, what classifies as unknown rather than
wedged, why a blocked worker is never a wedge, the configurable cadence and its
defaults, and the message shape.

Tell coordinators in the orchestration guide how to read the signal: it is
advisory, Orca took no action on the worker, and a rising escalationCount is the
same wedge reported again. The existing rules stand — a check --wait timeout is
still a checkpoint, and a slow worker is still not a failed one.
Five fixes from review on stablyai#13762, four of them correctness:

- createStartingWorkerDispatch now marks the dispatch-context emptiness cache
  true. The agent-status publish path probes that cache on every frame, so a
  cached false was the normal state when a session's first worker started; the
  scan then reported zero candidates and the monitor disarmed itself.
- A persisted escalation is discarded when the worker made progress after it, so
  a recovered-then-wedged dispatch escalates at once with the count back at 1
  instead of inheriting a stale count and a stale cadence. The comparison allows
  a one-second margin because SQLite stamps whole seconds while pane evidence is
  millisecond-precise, and a truncated stamp would otherwise double-escalate an
  unchanged wedge.
- A failed scan no longer disarms detection for every supervised worker. The
  timer keeps running and the next tick retries; five consecutive failures
  disarm it.
- An exact process-incarnation match is now required whenever the dispatch
  recorded one, and both identity checks run before the harness-state check. A
  pane that reports no identity is unverified, so it stays unknown rather than
  lending its output to a working, blocked or wedged verdict.
- Both guidance documents now name the wedged classification rather than
  "no progress evidence", because missing evidence is unknown and a worker on
  ask or check --wait is blocked.

The escalation cadence tests now write to the Run mailbox instead of a memory-only
stub, which is what hid the persisted-record defect.
…-worker signal

The escalation record was read back off the message row stamp, which SQLite
truncates to whole seconds. A one-second tolerance hid that loss, and the same
tolerance rejected real progress made inside the second after an escalation: a
worker that resumed was read as the same unchanged wedge, so its next wedge was
suppressed by the old cadence or reported with an inflated repeat count.

The signal payload now carries escalatedAtEpochMs, the instant the detector
escalated, and the reader prefers it. The row stamp stays as the fallback for
records written before the field existed, and a record read that way is marked
truncated so the tolerance applies to it alone. An exact instant needs no margin.

The reset test mixed a fake clock with the real row stamp: it set the worker's
output to exactly the escalation instant, and that only read as later progress
because the stamp came from real wall-clock time, minutes behind the fake clock.
It now moves the clock first, so the output lands strictly after the escalation
and the test asserts what it says it asserts.

Also states the unknown-classification rule directly in the reference doc.
@coderabbitai

coderabbitai Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@artile, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 23 minutes

Limit details: You’ve used all 10 included reviews currently available under your plan.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8bc10eea-3e56-4666-8040-8658ad4ce6bd

📥 Commits

Reviewing files that changed from the base of the PR and between 545b3fb and 677d6b6.

📒 Files selected for processing (18)
  • .gitignore
  • AGENTS.md
  • docs/reference/wedged-worker-detection.md
  • skill-guides/orchestration.md
  • src/cli/bundled-skill-guides.ts
  • src/main/runtime/orca-runtime.ts
  • src/main/runtime/orchestration/db.ts
  • src/main/runtime/orchestration/types.ts
  • src/main/runtime/orchestration/wedged-worker-detector.test.ts
  • src/main/runtime/orchestration/wedged-worker-detector.ts
  • src/main/runtime/orchestration/wedged-worker-escalation.test.ts
  • src/main/runtime/orchestration/wedged-worker-escalation.ts
  • src/main/runtime/orchestration/wedged-worker-runtime-monitor.test.ts
  • src/main/runtime/orchestration/wedged-worker-runtime-monitor.ts
  • src/main/runtime/orchestration/worker-progress-evidence.ts
  • src/main/runtime/orchestration/worker-progress-thresholds.test.ts
  • src/main/runtime/orchestration/worker-progress-thresholds.ts
  • src/main/runtime/rpc/methods/orchestration-workers.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Tauri-EPO

Tauri-EPO commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Carrying this over from #13762 as you asked, and thanks for the straight answer on the boundary.

On the boundary. Understood, and I will keep #14897 open as a follow-up built on this classification rather than beside it. Your first reason is the one I had not thought through: a detector that writes ends up reading its own bytes back as evidence, so the nudge has to sit above the classifier or the classifier stops being trustworthy. That is a stronger argument for the split than the one I made, and I will state it that way on #14897 so the ordering is on the record and nobody has to reconstruct it from two threads.

On the cadence. Agreed, and no second threshold — one cadence, wedged as strike 1, strike history additive to the existing payload. I will keep the classification split intact: unknown skips the ladder entirely, blocked is never struck. Those two are the reason the ladder can be safe at all, and they are yours, not mine.

On the db/ re-homing. Here is what the port looked like, so you do not have to do the archaeology.

The split is 81d7f9b24e — refactor: split db.ts under 400 lines (#14979). After it, src/main/runtime/orchestration/db.ts is a barrel of re-exports and nothing else; the class lives in db/orchestration-db.ts and its methods are attached from db/ subdirectories.

Your db.ts diff on this branch is three hunks, and they land in three different places:

  1. The SupervisedWorkerProgressRow type import — no move. src/main/runtime/orchestration/types.ts is untouched by the split, and you already edit it here.

  2. this.hasAnyDispatchContextsCache = true after the starting-worker-dispatch insert — goes to db/worker-dispatch/worker-dispatch-start.ts, which is where createStartingWorkerDispatch now lives.

    Worth knowing: the plain dispatch-context path already does exactly this on main, at db/dispatch-context/dispatch-context-store.ts:110, added by 30b76e6edb (fix(orchestration): enforce task dispatch state invariant #14961). So the pattern is established and your comment matches the one already there — but that call site is a different insert, and the worker-dispatch path still has no such write. Your hunk is still needed; it just has a sibling now.

  3. listSupervisedWorkerProgressRows() — goes to db/dispatch-context/dispatch-lookup.ts, which is where hasAnyDispatchContexts ended up and where the read-side dispatch queries now live.

    The shape there is a free function taking this, then two registrations at the bottom of the same file:

    export function listSupervisedWorkerProgressRows(
      this: OrchestrationDb
    ): SupervisedWorkerProgressRow[] { … }
    
    export type DispatchLookupMethods = {
      …
      listSupervisedWorkerProgressRows: typeof listSupervisedWorkerProgressRows
    }
    
    export function attachDispatchLookup(ctor: { prototype: object }): void {
      Object.assign(ctor.prototype, { …, listSupervisedWorkerProgressRows })
    }

    Nothing above that needs touching: db/orchestration-db-methods.ts already composes DispatchLookupMethods into the class type, and db/attach-orchestration-db-methods.ts already calls attachDispatchLookup(ctor), so a method added in those two spots propagates on its own.

    On size, since the split was a max-lines exercise: dispatch-lookup.ts is 187 lines today and your query is around 60, which stays under the tightest tier in .oxlintrc.json.

One correction to something you wrote, in your favour. You mentioned the db.ts hunk needing re-homing on #15274 as well. That branch does not touch db.ts at all — its files are src/cli/handlers/orchestration.ts, src/main/runtime/rpc/methods/orchestration.ts and its tests, plus skill-guides/orchestration.md. rpc/methods/orchestration.ts was not split and is still one 2056-line file, so whatever is dirty there should be an ordinary rebase rather than a move.

On the fork. Thanks for writing that up — I would not have guessed it, and it is worth knowing before anyone else sets one up under an organisation.

@AmethystLiang

Copy link
Copy Markdown
Contributor

thanks for reporting. looking into it

@AmethystLiang AmethystLiang self-assigned this Aug 18, 2026
@artile

artile commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Thank you — the port map is exactly what was needed, and your correction about #15274 is right: that branch does not touch db.ts at all. I said it did from the mergeable_state alone rather than from the file list. Corrected.

What I did with the map. I ran the rebase to see how far it reaches, and it stops one commit in, on the whole-file conflict you would expect: db.ts on main is now the barrel, and my branch still carries the monolith. Resolving means taking the barrel and re-homing by hand — which is what your three destinations answer.

One addition to your map, found while looking: my db.ts diff is four hunks, not three. Alongside the type import, the cache write and listSupervisedWorkerProgressRows, there is getLatestDispatchEscalation(dispatchId) — a read of the newest escalation message attributed to a Dispatch, used to resume a signal's repeat count across a restart. It is a message read rather than a dispatch lookup, so db/messages/ looks like its home rather than db/dispatch-context/. If you ported anything near that, I would rather match you than guess.

Also useful, and thank you for flagging it: db/dispatch-context/dispatch-context-store.ts:110 already sets the cache after the plain dispatch-context insert (30b76e6edb, #14961). That makes hunk 2 a sibling of an established pattern rather than a novelty — and it confirms the underlying bug was real enough that someone else hit the other half of it.

What I am not doing today, and why. The port is six commits deep with the conflict recurring past the first, so I am not landing it inside a daily review pass where I would be half-finishing it. It is going on our side as its own piece of work, with your map as the specification. When it lands, this PR should read as an ordinary diff against current main rather than an archaeology exercise.

On the boundary and the cadence — agreed on all of it, and thank you for saying you will put the ordering argument on #14897. That is the right place for it: a reader of the ladder needs to know why the detector cannot own the nudge, and reconstructing it from two PR threads is exactly the kind of thing that gets lost.

This branch has not been deployed

No deployments
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.

3 participants