Skip to content

feat(server): wake the watcher when an unsettled top-level thread fails - #205

Open
nullStack65 wants to merge 4 commits into
release/native-0.1.10from
feat/clo-1066-thread-failed
Open

nullStack65 wants to merge 4 commits into
release/native-0.1.10from
feat/clo-1066-thread-failed

Conversation

@nullStack65

@nullStack65 nullStack65 commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

A failed top-level thread with no launching thread, such as one a person created, tells nobody. Today only the 15-minute fleet watchdog finds it. This PR wakes the configured watcher thread (modelAlertWatcher) when that happens. The watchdog stays as it is.

Stacked on #204 (the release-branch hook baseline fix). The first two commits here are #204's. Merge #204 first. This PR's own changes are the top two commits.

Change

  1. ThreadEventAlerts adds a thread-failed event, judged when a run ends. It fires only for a thread that:
    • has status failed, a latest run, and no live run;
    • has no recorded launcher (inbox.origin / inbox.requestedBy agent). A lane with a launcher keeps the existing lane-ended route to that launcher, so a founder-facing watcher still never hears about a lane it did not launch;
    • did not stop at a usage limit. That failure goes only into the limit's one grouped usage-limit alert, or the auto-resume path;
    • is top-level (no parent lineage) and listed, not delegated (delegatedFrom) or a side chat;
    • is not archived and not settled.
      The finding keys on the failed run's id, so replaying the same run is not a second wake. It stops holding once the thread's latest run changes.
  2. ModelAlertReactor delivers thread-failed to the watcher through the existing model-alert outbox, as next_turn, so an idle watcher starts a turn.
    • After a delivered wake it holds further failure wakes for that thread for five minutes.
    • A failure wake waits while the watcher itself is stopped at its own usage limit. This is the existing usage-limit hold, moved to the exported watcherLimitHold.
    • It drops the wake when no watcher is configured, or when the failed thread is the watcher itself. It checks this both when queueing and when delivering.
  3. docs/operations/watcher-thread.md and the modelAlertWatcher setting description cover the new event.

An earlier revision also bundled a provider-readiness check for launch, delegation and placement. It is removed: it was unrelated, and it failed the remote delegation tests.

Checks

  • Pre-commit hook and pre-push check:changed with hooks on, with no --no-verify.
  • Under Node 26: format and lint on the changed files, server typecheck, and the full apps/server suite.
  • Tests cover:
    • lane routing: the launcher hears its own lane, and the watcher hears no lane it did not launch;
    • one usage limit failing three threads gives one grouped alert and no per-thread wake. With the usage-limit gate removed, this test fails;
    • the watcher's own failure gives no wake, while another person-created thread's failure gives exactly one;
    • the watcher usage-limit hold;
    • exclusion of settled, archived, delegated, child-lineage, side-chat, interrupted, still-running and launcher-owned threads;
    • the per-thread rate limit, per-run dedupe, and next_turn delivery both local and remote.

Deploy: fleet

Model: claude-opus-5-5
Task: CLO-1066

🤖 Generated with Claude Code

On release/native-0.1.10 the pre-commit hook fails on eight unused exports
and the pre-push check fails on a scenario typecheck error and a stale agent
context budget, so no code change can land without bypassing the hooks.

Seven unused exports are used only inside their own module and lose their
export. The client setThreadDelegationNudge wrapper has no caller and goes;
the server command and its MCP tool stay. The upstream ACP refresh scenario
imports rpcClient from scenarios/t3.ts, so the fork's identical helper moves
there as upstream has it. The MCP tool list budget takes the measured size
after the event subscription and delegation nudge tools landed.

Model: claude-opus-5-5
Task: CLO-1066
Agent: claude-code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Git exports GIT_DIR to hooks. Under pre-push, the replay workspace
fixture inherited it, so its git init, config, add and commit ran
against the pushing worktree: it committed "initial" onto the branch
being pushed and wrote the test identity into the shared repository
config. Unset the inherited repository selectors, as the server's
VcsProcess already does for its own git calls.

Model: claude-opus-5-5
Task: CLO-1066
Agent: claude-code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A failed top-level thread with no launching thread, including one a person
created, told nobody, so a 15-minute fleet watchdog had to find it.

A new thread-failed event starts a watcher turn through the existing model
alert delivery path. It fires once per failed run, only for an unsettled,
unarchived, top-level thread that is not a delegated or side-chat thread and
has no live run. Delivery uses next_turn so an idle watcher wakes, keys on
the run so a replay is not a second wake, waits five minutes per thread
after a delivered wake, and never wakes the watcher about itself. Lane
events keep going to the launching thread.

Launch and delegation also refuse a provider that is not ready, has
discovered no models or is signed out, before any thread or run is created,
using one readiness check shared with placement and capabilities.

Model: claude-opus-5-5
Task: CLO-1066
Agent: claude-code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@nullStack65

Copy link
Copy Markdown
Owner Author

RESULT

Reviewer notes only, no verdict (t3code #205, CLO-1066 watcher wake on thread failure)

CTO took this PR out of the review queue because of known CI regressions. These are notes from a review that was already running and was asked to stop. This is not a gate record and not a merge verdict. It is a bot result (Claude Opus 5.5, read-only, isolated clone), not human approval. Head 016b15eaaf9c9cbd68fede1ac3bdf30eabe15b4d, on top of #204's head 7941765bfe77.

  1. Breaks an existing test that CI doesn't run. apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts:5208, "a lane's thread events reach the thread that launched it and never Lead", now fails with expected 5 to equal 1. It passes at 7941765bfe77. The PR's checks don't include a full server test job. The new behaviour matches CLO-1066's intent, so the assertion is probably the stale part.

  2. Usage-limit outages can flood the watcher. Failure wakes skip the usage-limit and auto-resume holds (ThreadEventAlerts.ts:227-243, ModelAlertReactor.ts:1250). If 20 threads fail on one usage limit, the watcher gets 20 separate next_turn wakes on top of the single grouped item. A thread waiting to auto-resume also wakes the watcher before the reset arrives. The default watcher is the CoS thread on the laptop, so each wake starts an agent turn there.

  3. Unrelated provider-readiness change bundled in. It touches servedModel.ts, placementEvidence.ts, handlers.ts and OrchestratorMcpService.ts:409,1662:

    • A provider with an empty model list now fails launch, delegation and placement with provider_unavailable.
    • The model check now also applies to inherited models.

    None of this is in CLO-1066. Suggest splitting it into its own PR.

  4. Two mutations went uncaught: adding occurredAt back to the alert id (ThreadEventAlerts.ts:390), and dropping the delivery-time runId re-check (:455).

  5. Uneven lane-ended routes. When the launcher isn't the watcher, both a lane-ended digest and a watcher wake go out (ModelAlertReactor.ts:1738-1749). This should be documented if it's intended.

The watcher can't wake itself. It is guarded twice: once when the wake is queued (:1695) and again when it is delivered (:1305-1312). Children, subagents, side-chats and delegated threads don't qualify. A scratch test confirmed this, and it catches removing both guards. The 15-minute watchdog is external and unchanged; the diff touches no timers.

Tests at the head: the four touched test files passed 209/209. DelegatedCompletionDelivery had 1 failure out of 67 (item 1). The shared checkout's .git/config and git status were confirmed unchanged afterwards.

Not verified: a watcher setting that points at a deleted thread; the usage-limit flood as a live run; whether older peers accept next_turn; the full server suite.

The failure wake fired for every failed top-level lane, so the watcher
also heard about lanes another thread launched, and the "never Lead"
lane-routing test saw five wakes instead of one. A failure wake now
needs a thread with no recorded launcher, such as one a person created.
Lanes with a launcher keep the lane-ended route to that launcher.

A failure the model alert already reports as a usage limit gets no
failure wake; it goes only into that limit's one grouped alert or the
auto-resume path. A failure wake also waits while the watcher itself is
stopped at its own usage limit, through the existing hold, now the
exported watcherLimitHold.

Drop the bundled provider-readiness change (servedModel, placement
evidence, project launch and the orchestrator capabilities report). It
was unrelated to the wake and rejected launches on an unregistered
provider, which failed the remote delegation tests.

Tests cover one usage limit failing several threads (one grouped alert,
no per-thread wake), the watcher's own failure (no wake), launcher
exclusions and the watcher usage-limit hold.

Model: claude-opus-5-5
Task: CLO-1066
Agent: claude-code
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nullStack65

Copy link
Copy Markdown
Owner Author
{
  "reviewed_head": "7c1cfb7201c413256dcaa4e98c437ac613394a47",
  "reviewer": "Gemini 4 Neon, T3 Code",
  "findings": [
    {
      "id": "R205-1",
      "severity": "nit",
      "summary": "Idle local watcher with a queued digest is reported as queued by readWatcher, so busyWatcherHold delays a thread-failed next_turn wake up to 10 minutes even though a digest will not start a turn on its own.",
      "outcome": "open"
    },
    {
      "id": "R205-2",
      "severity": "nit",
      "summary": "watcherLimitHold fails open for a remote watcher because t3_thread_read does not expose usageLimited or resetAt (documented and covered by unit test).",
      "outcome": "open"
    },
    {
      "id": "R205-3",
      "severity": "nit",
      "summary": "judgeThread does not apply RECENT_RUN_END_MS to thread-failed (unlike lane-ended); id keys on latestRunId so replays after delivery still dedupe.",
      "outcome": "open"
    }
  ]
}

Independent bot review — nullStack65/t3code#205 (CLO-1066)

Bot review only, not human approval. Full independent review pass at head 7c1cfb7201c413256dcaa4e98c437ac613394a47 (base release/native-0.1.10 dfc50380a558, stacked on #204 7941765bfe77).

Verdict: merge (once #204 merges first; 0 critical, 0 important, 3 nits)

Scope & Obligation

  • Matches CLO-1066: Adds thread-failed to ThreadEventAlerts and delivers it via ModelAlertReactor as next_turn to modelAlertWatcher for failed, unsettled, unarchived top-level threads with no recorded launcher (inbox.origin / inbox.requestedBy), excluding usage-limit failures, delegated/side-chat/child threads, and the watcher itself.
  • Note on provider-readiness guard: Commit 7c1cfb72 cleanly dropped the unrelated provider-readiness guard from the earlier revision; the net diff over fix(ci): restore the release commit and push hook baseline #204 (7941765b..7c1cfb72) touches only the 7 alert/test/doc/settings files.
  • Prior cancelled-review notes (016b15ea) resolved:
    • DelegatedCompletionDelivery.test.ts:5208 ("a lane's thread events reach the thread that launched it and never Lead") passes.
    • Usage-limit storm protection is enforced (usageLimitReported !== true in judgeThread, plus watcherLimitHold when the watcher itself is usage-limited).
    • Launcher-owned lanes stay on lane-ended to their launcher and never double-wake the watcher.
  • Stack note: Still stacked on open PR fix(ci): restore the release commit and push hook baseline #204 (fix/release-hook-baseline, commits 417b3c47 and 7941765b); merge fix(ci): restore the release commit and push hook baseline #204 first.

Verification

  • CI: All 6 checks green on 7c1cfb7201c413256dcaa4e98c437ac613394a47 (Deploy line declared, Voice + inbox core, Voice + inbox web, Voice + inbox mobile, Voice + founder inbox, CodeRabbit).
  • Local tests (detached worktree at 7c1cfb72): vp test run src/orchestration-v2/ThreadEventAlerts.test.ts src/orchestration-v2/ModelAlertReactor.test.ts src/orchestration-v2/DelegatedCompletionDelivery.test.ts — 170/170 passed (56 + 45 + 69).
  • Compatibility & contracts: ModelAlertState.failureWakeSentAt defaults to {} via Schema.withDecodingDefault; OrchestratorMcpService.sendToThread accepts deliveryClass: "next_turn" with coalesceKey, expiresAt, and digestCategory.

Findings (non-blocking nits)

  1. R205-1 (nit): readWatcher (apps/server/src/orchestration-v2/ModelAlertReactor.ts:1240-1246) reports an idle local watcher with a queued digest run as status: "queued". Since deliver() runs busyWatcherHold on thread-failed wakes too, a next_turn failure wake can wait up to 10 minutes (BUSY_WATCHER_MAX_HOLD_MS) behind an idle watcher's queued digest even though the digest won't start a turn on its own.
  2. R205-2 (nit): watcherLimitHold (ModelAlertReactor.ts:714-734) fails open for a remote watcher because t3_thread_read does not expose usageLimited or resetAt. Documented and covered by unit test (ModelAlertReactor.test.ts:204).
  3. R205-3 (nit): thread-failed in judgeThread (ThreadEventAlerts.ts:227-245) omits the RECENT_RUN_END_MS window used by lane-ended. Because id keys on latestRunId, post-delivery replays still dedupe via reported and clientRequestId.

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.

2 participants