Skip to content
Source
Sign inSign up
pingdotgg/t3code

Add PR monitoring: server-driven babysit mode for agent threads #4428

Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 7 commits intomain fromt3code/add-pr-monitoring-flowopened View on GitHub

Threads can now formally monitor a PR after creating it. The agent calls a new monitor_start MCP tool; a dedicated PullRequestMonitor service polls GitHub every 30s, diffs review comments / reviews / check runs against a per-thread cursor, and wakes the thread with a self-contained prompt when there is something to address. The server — never the agent — declares the PR ready from head-SHA-anchored GitHub state.

What's included

  • GitHub monitor snapshot (gitHubPullRequestMonitor.ts): reviews, review threads + resolution, check runs, head SHA, mergeability; pure cursor-diff and readiness modules with false-green guards (stale approvals don't count, zero checks ≠ green, changes-requested blocks until re-review)
  • Domain events thread.monitor-started/-snapshot-updated/-ended through decider/projector; monitor state on the thread shell; migration 035 (monitor_json)
  • Wake dispatch protocol: claim → fresh terminal revalidation at the send boundary → dispatch → cursor ack only after accepted start. User turns always win and rewind in-flight wake cursors so events re-diff instead of being lost. 10-wake circuit breaker ends as needs-attention
  • Lifecycle: monitoring holds the thread unsettled; user settle ends the monitor; session teardown ends it as session-ended; merged/closed PRs end it as terminal with the whole poll cycle discarded (no post-merge resurrection)
  • UI: steady cyan Monitoring pill (never masks approval/input/failed), blockers sub-line, header MonitorStrip with Stop, emerald Ready-to-merge state behind a confirm dialog. Clients can only end a monitor with reason "stopped" — the other reasons are server verdicts
  • Rebased over thread snoozing (#4311); snooze + monitor coexist on the lifecycle files

Design docs: UX plan https://lmrxu2kpvpm0.postplan.dev · implementation plan https://nr9llb5mku4z.postplan.dev

Testing

  • New unit tests: cursor diff, readiness, dispatch-protocol (terminal-discards, ack ordering, failed-dispatch-preserves-cursor, busy veto, generation change, breaker), decider/projector monitor events, threadSettled monitor blocker, sidebar pill priority
  • Full suites green post-rebase: apps/server 1640, apps/web 1513, client-runtime 473

🤖 Generated with Claude Code


Note

High Risk Large new orchestration + in-process polling path that auto-starts at boot, dispatches agent turns from GitHub state, and uses module-global monitor registrations that are lost on restart until boot reconcile.

Overview Agents can start PR babysit mode via a new MCP monitor_start tool (with monitor capability on MCP sessions). The server registers the thread in a shared MonitorRegistry, emits thread.monitor.* commands/events, and runs PullRequestMonitor on a ~30s poll loop that fetches GitHub PR state, diffs review/CI changes, evaluates merge readiness, and dispatches thread.turn.start wake prompts when needed—with claim/ack/rewind logic for races, user turns, and provider failures, plus a 10-wake needs-attention stop.

Orchestration & persistence: New monitor lifecycle in the decider/projector (start clears settled override; settle/archive end monitoring), monitor_json on projected threads (migration 035), and session teardown that ends monitors before revoking MCP.

UI: MonitorStrip in chat (stop / ready / merge confirm) and sidebar status pills (Monitoring, Ready to merge, Needs attention) that do not override approval/input/failed states.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit d1faaa16ff7f89e1c364b2df5e30e02e129ef1b4. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add server-driven PR monitoring with agent babysit mode for orchestration threads

  • Introduces a full PR monitoring pipeline: a PullRequestMonitor actor starts at server boot, polls GitHub for PR state changes (reviews, check runs, behind-base, thread updates), diffs against a cursor, and wakes the agent thread with a structured prompt when actionable events are detected.
  • Adds MonitorRegistry to track per-thread monitor state (generation, cursor, wake count) module-globally so both the runtime core and MCP routes share the same instance.
  • Extends the orchestration contracts with thread.monitor.start/update/end commands and corresponding events; the decider and projector handle the full monitor lifecycle and persist state in a new monitor_json column (migration 035).
  • Exposes a new MCP tool monitor_start that agents can call to begin monitoring a PR; MCP credentials now include the monitor capability by default.
  • Adds MonitorStrip to the chat header and updates sidebar rows with monitoring-aware pills (Monitoring, Needs attention, Ready to merge) and blockers summary; threads with an active monitor are always considered unsettled.
  • Risk: the monitor actor starts automatically as part of reactor initialization and polls GitHub CLI on an interval — environments without GitHub CLI access or valid credentials will see monitor start failures at boot.
Macroscope summarized d1faaa1.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: c625b82c-8650-4902-9e98-6215d8881819

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `t3code/add-pr-monitoring-flow`

      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.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      This PR introduces a substantial new feature (PR monitoring/babysit mode) with new server-side services, MCP toolkit, orchestration events, database migration, and UI components spanning ~3000+ lines of new code. New features of this scope warrant human review to validate the design and runtime behavior.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Effect Service Conventions: 2 findings. Two standalone *Shape service interfaces were introduced; the conventions require the service interface to be declared inline in the Context.Service tag and referenced as Service["Service"].

      Posted via Macroscope — Effect Service Conventions
      @@ -0,0 +22,21 @@
      22+import { diffPullRequestMonitorSnapshot, type PullRequestMonitorCursor } from "./monitorDiff.ts";
      23+import { computeReadiness } from "./readiness.ts";
      24+import { buildWakePrompt, formatBlockersSummary } from "./wakePrompt.ts";
      25+
      26+const POLL_INTERVAL = Duration.seconds(30);
      27+const MAX_BACKOFF = Duration.minutes(5);
      28+const QUEUED_TURN_START_GRACE_MS = 2 * 60 * 1_000;
      29+
      30+interface WakeClaim {
      31+ readonly generation: number;
      32+ readonly commandId: CommandId;
      33+ readonly phase: "pending" | "in-flight";
      34+ readonly dispatchedAt?: string;
      35+ readonly previousWakeCount: number;
      36+ // Cursor as it was before this wake acked, so a wake that dies after the
      37+ // ack — provider start failure, superseded by a user turn — can rewind and
      38+ // let the next poll re-diff the same events instead of losing them (I5).
      39+ readonly previousCursor: PullRequestMonitorCursor;
      40+}
      41+
      42+export interface PullRequestSnapshotFetcherShape {

      Standalone PullRequestSnapshotFetcherShape interface. Same convention as MonitorRegistryShape: declare the interface inline in the Context.Service tag and reference it as PullRequestSnapshotFetcher["Service"] rather than keeping a separate FooShape type.

      export class PullRequestSnapshotFetcher extends Context.Service<PullRequestSnapshotFetcher>()(
        "t3/monitor/PullRequestMonitor/PullRequestSnapshotFetcher",
        {
          fetch: (input: { readonly cwd: string; readonly pullRequestNumber: number }) =>
            Effect.Effect<PullRequestMonitorSnapshot, GitHubPullRequestMonitorError>,
        },
      ) {}
      Posted via Macroscope — Effect Service Conventions

      Same as the sibling comment: FooShape + Context.Service<Foo, FooShape> is the prevailing pattern in apps/server (43 occurrences, zero using the inline-members overload), so PullRequestSnapshotFetcherShape stays consistent with its neighbors. A codebase-wide migration would be a separate PR.

    5. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 355a2893d4845a3c251295f1cdf693c87b8d3177. Configure [here](https://www.cursor.com/dashboard/bugbot).
    6. Closing in favor of #2829 (orchestration V2).

      #2829 deletes the V1 orchestration layer this PR builds on — apps/server/src/orchestration/**, provider/Layers/*Adapter.ts and provider/Services/** are removed and replaced by apps/server/src/orchestration-v2/**, with the IPC surface renamed to ORCHESTRATION_V2_WS_METHODS. The files this PR touches either no longer exist or are rewritten, so it can't be rebased — it would need reimplementing against the V2 adapters.

      This is not a judgement on the change itself. Several of these are real gaps we still want fixed; the base just moved out from under them.

      Once #2829 merges, please rebase onto main, port the change to the V2 equivalent, and reopen (or open a fresh PR). Ping me and I'll prioritise the review.

    7. juliusmarminge closed this

Sign in to join this conversation.