Skip to content

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

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

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

Conversation

@artile

@artile artile commented Aug 11, 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.

artile added 4 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.
@coderabbitai

coderabbitai Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f46651f5-12d2-4e16-a18b-4ab406d17bb5

📥 Commits

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

📒 Files selected for processing (5)
  • docs/reference/wedged-worker-detection.md
  • 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
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/main/runtime/orchestration/wedged-worker-detector.test.ts
  • docs/reference/wedged-worker-detection.md
  • src/main/runtime/orchestration/wedged-worker-detector.ts
  • src/main/runtime/orchestration/wedged-worker-escalation.ts

📝 Walkthrough

Walkthrough

Adds detection-only wedged-worker monitoring for supervised local workers. The change collects progress evidence, classifies worker states, resolves configurable thresholds, and queries eligible dispatches. It plans immediate and repeated escalation messages with restart-persistent counts. Runtime monitors start after workers become ready, re-arm after restart reconciliation, stop when no candidates remain, and suppress duplicate monitors. Tests cover classification, cadence, persistence, runtime lifecycle, and disabled detection. Documentation defines the behavior and operational handling.

Merge Risk: ⚪ Minimal · up to 677d6

This localized change adds wedged-worker detection and notification without changing worker control behavior; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it omits the required linked issue, visual proof or N/A statement, checklist, and author sections. Add the required Linked Issue, Visual Proof, Checklist, and Author sections, and include the issue reference and N/A visual-proof statement if applicable.
Docstring Coverage ⚠️ Warning Docstring coverage is 31.25% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: detecting wedged supervised workers and surfacing signals.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch artile/wedged-worker-signal

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (2)
src/main/runtime/orchestration/wedged-worker-runtime-monitor.test.ts (1)

126-137: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the re-arm path after the monitor stops itself.

The suite proves the monitor stops when no candidate exists. It does not prove that a later worker start arms it again. That transition is the whole reason the stop is considered safe. Add a test that stops the monitor through a zero-candidate scan, starts a ready worker, calls ensureWedgedWorkerMonitor again, and asserts runWedgedWorkerScan returns a summary instead of null.

Also add a test for the scan-failure path once runWedgedWorkerScan keeps the timer alive. See the comment on wedged-worker-runtime-monitor.ts lines 90-102.

src/main/runtime/orchestration/worker-progress-thresholds.test.ts (1)

40-72: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for the re-escalation floor.

When reEscalateAfterMs is below wedgedAfterMs, resolveWorkerProgressThresholds clamps it to wedgedAfterMs. Add a case with 900000 and 120000 that expects both values to resolve to 900_000.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a82cf7d9-abf7-42dd-8de3-9c2349d793f5

📥 Commits

Reviewing files that changed from the base of the PR and between c578f4e and 6e9a0f6.

📒 Files selected for processing (17)
  • .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.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

Comment thread AGENTS.md Resolved
Comment thread src/main/runtime/orchestration/db.ts Resolved
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: adb57ad6-6d38-42e9-8d6d-bf5ba6c13b6a

📥 Commits

Reviewing files that changed from the base of the PR and between 6e9a0f6 and b2166fa.

📒 Files selected for processing (11)
  • AGENTS.md
  • docs/reference/wedged-worker-detection.md
  • skill-guides/orchestration.md
  • src/cli/bundled-skill-guides.ts
  • src/main/runtime/orchestration/db.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.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
🚧 Files skipped from review as they are similar to previous changes (5)
  • skill-guides/orchestration.md
  • AGENTS.md
  • src/main/runtime/orchestration/wedged-worker-detector.ts
  • src/main/runtime/orchestration/worker-progress-evidence.ts
  • src/main/runtime/orchestration/db.ts

…-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.
@Tauri-EPO

Copy link
Copy Markdown
Contributor

I filed #14897 on 16 Aug proposing a nudge ladder for the same silence, before I had read this. Having now read docs/reference/wedged-worker-detection.md properly: this is the layer underneath what I proposed, and the boundary you drew looks right to me. I would rather build on it than beside it, so here is the shape and one question about your scope.

Where the two meet. #14897's ladder is:

healthy → quiet → nudged(1) → nudged(2) → unresponsive
          └─────┘  └──────────────────┘   └───────────┘
        your detector      the gap        your escalation

Your evidence collector and classifier are exactly the input that ladder needs, and your escalation is exactly its ceiling. What neither of us has is the middle: a fixed, typed prod at the worker — you hold active dispatch X; if you finished, send worker_done; if you are stuck, send escalation — before the coordinator is told anything.

That middle matters because the most common failure I hit is not a hung worker. It is a worker that finished and never sent worker_done. Detection reports that correctly and the coordinator still has to go handle it by hand. A prod turns it into self-recovery.

The proposal, using your thresholds rather than new ones. I do not want a second cadence competing with yours. Instead, wedged becomes strike 1: at your 15 minutes, the runtime nudges instead of escalating immediately; if the nudge is confirmed consumed and silence continues, strike 2; only then unresponsive, which escalates through your existing wedged_worker_signal with the strike history added to the payload. One message, one format, one mailbox — the coordinator gets "wedged, and two prods were already tried" rather than two reports of the same lane.

The honest cost is that your signal arrives later than it does today, by one nudge-confirmation window. I think that trade is worth it precisely because the escalation that survives it is the one a human actually needs to see, but it is your call before mine — it is your cadence.

Three rules I would keep, and two of them you already have.

  1. An undelivered nudge is not a disobeyed nudge. After nudging, consumption must be confirmed before recording a strike, or the runtime punishes workers for its own delivery bugs and stacks drafts in the composer. Your agent_turn_boundary and terminal_output evidence is already the right way to answer that — it is the same signal, read after a write instead of before one.
  2. A dead process skips the ladder. Nudging a ghost terminal injects into nothing. Your unknown classification already covers this: missing pane, disconnected PTY, replaced process identity.
  3. A lane waiting on a human is never nudged or struck. Your blocked — pending ask, live ask or check --wait, harness reporting waiting — already is this rule, and it is stricter than what I had written.

My question. Is "never writes to a worker" a permanent boundary for this feature, or the scope you set for this PR and intend to extend later? Both are reasonable and they lead to opposite things on my side:

I am not asking anyone to prioritise one over the other — this is your area and your PR, and I would rather ask than assume, which I have already got wrong once in this repo.

One practical note, in case the notification did not reach you: this branch currently conflicts with main. mergeable_state is dirty, and the orchestration db.ts you touch was split into a barrel plus a db/ directory upstream, so that hunk will need re-homing rather than a plain rebase. I hit the same split rebasing my own branches yesterday, and the method moved into db/dispatch-context/. Happy to share what the port looked like if it saves you time.

@artile

artile commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for reading the doc before proposing on top of it — the ladder you drew is the right shape, and the boundary question deserves a straight answer.

"Never writes to a worker" is the scope of this PR, and I do not intend to extend it. Take #14897 as a follow-up built on this classification; I will stay out of the nudge. Do not close it.

Two reasons the boundary is where it is, in case they are useful when you build the middle:

  1. A detector that writes cannot be trusted as evidence of itself. Once the runtime injects, the next terminal_output sample carries the runtime's own bytes, and agent_turn_boundary may fire for a turn the nudge started rather than the work. The classifier would then be reading its own tail. Keeping the writer out means every sample the detector reads was produced by the worker. Your rule 1 — confirm consumption before recording a strike — is the same insight, and it is exactly why the nudge belongs above the classifier and not inside it.
  2. The doc states it as a property, and it is load-bearing for adoption: "It never stops, kills, restarts, interrupts, closes, focuses or writes to a worker. Its only effect is one escalation message", and later, "a signal must never cause an effect." A user who has to trust the thing enough to leave it armed for hours is trusting that sentence. If the nudge lands, it should be its own opt-in above the detector rather than a change to what this feature promises.

On your cadence proposal — the trade is yours to make, and I think you are right about it. Making wedged strike 1 rather than an immediate escalation, and keeping one message, one format, one mailbox, does not require anything from me: wedged_worker_signal already carries the repeat count and the escalation cadence recovers across restarts, so adding a strike history to that payload is additive. The one thing I would keep is the classification split you already named — unknown skips the ladder, blocked is never struck. They exist precisely so that "no evidence" and "waiting on a human" are not treated as silence.

The one thing I would not fold in is a second threshold. If the nudge uses the same 15 minutes, a wedge costs the coordinator one nudge-confirmation window of extra latency, which is small next to the 15 that preceded it. If it gets its own, the two cadences drift the first time somebody tunes one.

On the conflict: you are right, and your note is the first I knew of the db/ split. mergeable_state is dirty on this branch and on #13763. The orchestration db.ts hunk needs re-homing, not a rebase, and yes — please share what the port looked like on your branches. That saves me the archaeology on two branches, and I would rather match where you put things than invent a second placement.

One thing worth knowing before you spend time on it, since it is the reason these PRs have sat: our fork is owned by an organisation, and GitHub does not grant maintainer push on org-owned forks even though maintainer_can_modify reports true. So a maintainer cannot push a fixup here; they have to ask, or rewrite and close. #13639 was closed for exactly that. It is being sorted out on our side.

@artile

artile commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Moved to #15273 and closing this one — same branch, same commits, same head SHA, opened from a personal fork instead of an organisation-owned one.

The reason is the one Jinwoo-H hit on #13639: GitHub does not grant maintainer push access on a fork owned by an organisation, even though the API reports maintainer_can_modify: true. A maintainer who wanted to push a fixup here could not, and had to either ask and wait or rewrite the change on main and close ours. That is a poor trade for a reviewer, and it is very likely why these sat.

Nothing about the change moved. This thread keeps the review history, and #15273 carries the code.

@Tauri-EPO — your question and my answer are above and stay readable here; the code moved to #15273. Please carry the #14897 discussion there. The db/ re-homing you offered notes on still applies to that branch unchanged.

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.

4 participants