From 0c1de35f5a9e09698f13ae3fd238addbf7a51955 Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Sun, 26 Jul 2026 19:39:37 -0700 Subject: [PATCH] Harden PR monitoring after adversarial review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Findings from a multi-agent review panel (23 confirmed after two-lens adversarial verification), grouped by root cause: Lifecycle identity - Thread a monitor generation through monitor commands, events, and the projected monitor state; reject updates/ends whose generation is not the active one, and make every registry removal generation-conditional so a delayed lifecycle event cannot delete a newer monitor - Re-validate registration, projected monitor status, archive state, generation, and claim at the wake send boundary (after the fresh fetch, not before it) Event loss - Diff before the readiness exit: actionable activity now wins over ending as ready, so a bot comment landing in the same poll as green CI is never discarded - Persist non-actionable cursor transitions so resolved→reopened is still detectable - Acknowledge the cursor only if the wake claim still exists, so a user-turn release is not overwritten Readiness - Collapse reviews to each reviewer's latest opinionated review, so an approval supersedes that reviewer's earlier changes-requested - Re-include pre-monitor review threads once they are edited or reopened Snapshot integrity - Final terminal/head revalidation after pagination, with one bounded refetch on head change - Fetch the last 10 comments per review thread and track per-thread updatedAt so edits to non-final comments are visible - Reopened threads wake regardless of self-authorship - Include the changes-requested review body in the wake prompt Lifecycle events - Archive atomically emits thread.monitor-ended before thread.archived, mirroring settle - Treat a queued-but-unadopted user turn as busy at the send boundary - Boot reconciliation isolates per-thread failures (Bugbot) UI - Gate ready-state PR actions on the checkout PR matching the monitored PR number - Wake snoozed threads on monitor ready/needs-attention/session-ended - Legacy sidebar renders the ready payoff and a needs-attention state; session failure outranks Monitoring - Reset merge confirmation when PR or monitor status changes - endThreadMonitor honors a caller-provided endedAt Co-Authored-By: Claude Fable 5 --- .../src/mcp/toolkits/monitor/handlers.ts | 1 + apps/server/src/monitor/MonitorRegistry.ts | 1 + .../src/monitor/PullRequestMonitor.test.ts | 265 ++++++++++++++---- apps/server/src/monitor/PullRequestMonitor.ts | 153 +++++++--- apps/server/src/monitor/monitorDiff.ts | 19 +- apps/server/src/monitor/readiness.test.ts | 29 ++ apps/server/src/monitor/readiness.ts | 21 +- apps/server/src/monitor/wakePrompt.ts | 3 +- .../Layers/ProjectionPipeline.ts | 13 +- .../src/orchestration/decider.monitor.test.ts | 23 ++ apps/server/src/orchestration/decider.ts | 41 ++- .../orchestration/projector.monitor.test.ts | 4 + apps/server/src/orchestration/projector.ts | 5 +- .../sourceControl/gitHubPullRequestMonitor.ts | 74 ++++- apps/web/src/components/ChatView.tsx | 15 +- apps/web/src/components/MonitorStrip.tsx | 29 +- apps/web/src/components/Sidebar.logic.test.ts | 65 ++++- apps/web/src/components/Sidebar.logic.ts | 67 ++++- apps/web/src/components/SidebarV2.tsx | 50 ++-- .../src/operations/commands.test.ts | 26 ++ .../client-runtime/src/operations/commands.ts | 2 +- .../src/state/threadSettled.test.ts | 1 + .../client-runtime/src/state/threadSettled.ts | 35 ++- .../src/state/threadSnoozed.test.ts | 89 ++++++ packages/contracts/src/orchestration.ts | 8 + 25 files changed, 873 insertions(+), 166 deletions(-) diff --git a/apps/server/src/mcp/toolkits/monitor/handlers.ts b/apps/server/src/mcp/toolkits/monitor/handlers.ts index 6d48bd0f2d..7cfcac31b7 100644 --- a/apps/server/src/mcp/toolkits/monitor/handlers.ts +++ b/apps/server/src/mcp/toolkits/monitor/handlers.ts @@ -86,6 +86,7 @@ const monitorStart = Effect.fn("MonitorToolkit.monitorStart")(function* ({ type: "thread.monitor.start", commandId, threadId: invocation.threadId, + generation, prNumber, blockersSummary: warning ?? "", headSha: snapshot.headSha, diff --git a/apps/server/src/monitor/MonitorRegistry.ts b/apps/server/src/monitor/MonitorRegistry.ts index cb52c095cf..98851824ee 100644 --- a/apps/server/src/monitor/MonitorRegistry.ts +++ b/apps/server/src/monitor/MonitorRegistry.ts @@ -156,6 +156,7 @@ export const endActiveMonitorForSession = (threadId: ThreadId): Effect.Effect ({ archivedAt: null, settledOverride: null, settledAt: null, - monitor: null, + monitor: { + generation: 1, + prNumber: 42, + status: "monitoring", + blockersSummary: "", + headSha: "head-1", + wakeCount: 0, + startedAt: now, + endedAt: null, + endedReason: null, + }, deletedAt: null, messages: [], proposedPlans: [], @@ -110,7 +122,11 @@ const harness = Effect.fn("PullRequestMonitor.testHarness")(function* (input: { readonly failFreshFetch?: boolean; readonly reconcileFailures?: number; readonly reconcileThreadId?: ThreadId; + readonly reconcileThreadIds?: ReadonlyArray; + readonly failReconcileThreadId?: ThreadId; + readonly releaseWakeOnDispatch?: boolean; readonly busy?: { value: boolean }; + readonly queuedUserTurn?: boolean; readonly afterUpdate?: () => void; readonly changeGenerationAfterUpdate?: boolean; }) { @@ -125,6 +141,7 @@ const harness = Effect.fn("PullRequestMonitor.testHarness")(function* (input: { }; const commands: OrchestrationCommand[] = []; const ordering: string[] = []; + let monitorService: PullRequestMonitor["Service"] | undefined; const registry = MonitorRegistry.MonitorRegistry.of({ registerIfAbsent: (next) => Effect.sync(() => { @@ -202,6 +219,29 @@ const harness = Effect.fn("PullRequestMonitor.testHarness")(function* (input: { } if (command.type === "thread.turn.start") { ordering.push("dispatch"); + if (input.releaseWakeOnDispatch && monitorService) { + return monitorService + .handleDomainEvent({ + sequence: 1, + eventId: EventId.make("user-turn"), + aggregateKind: "thread", + aggregateId: threadId, + occurredAt: now, + commandId: CommandId.make("user-turn"), + causationEventId: null, + correlationId: null, + metadata: {}, + type: "thread.turn-start-requested", + payload: { + threadId, + messageId: MessageId.make("user-message"), + runtimeMode: "full-access", + interactionMode: "default", + createdAt: now, + }, + }) + .pipe(Effect.as({ sequence: commands.length })); + } if (input.failWake) { return Effect.fail( new OrchestrationCommandInvariantError({ @@ -219,6 +259,17 @@ const harness = Effect.fn("PullRequestMonitor.testHarness")(function* (input: { }), ); } + if ( + command.type === "thread.monitor.end" && + command.threadId === input.failReconcileThreadId + ) { + return Effect.fail( + new OrchestrationCommandInvariantError({ + commandType: command.type, + detail: "reconcile rejected", + }), + ); + } return Effect.succeed({ sequence: commands.length }); }, }); @@ -258,40 +309,71 @@ const harness = Effect.fn("PullRequestMonitor.testHarness")(function* (input: { return Effect.succeed({ snapshotSequence: 0, projects: [], - threads: input.reconcileThreadId - ? [ - { - ...thread(), - id: input.reconcileThreadId, - monitor: { - status: "monitoring" as const, - prNumber: 42, - startedAt: now, - blockersSummary: "", - headSha: "head-1", - wakeCount: 0, - updatedAt: now, - endedAt: null, - endedReason: null, - }, - latestUserMessageAt: null, - hasPendingApprovals: false, - hasPendingUserInput: false, - hasActionableProposedPlan: false, - }, - ] - : [], + threads: ( + input.reconcileThreadIds ?? + (input.reconcileThreadId ? [input.reconcileThreadId] : []) + ).map((id) => ({ + ...thread(), + id, + monitor: { + generation: 1, + status: "monitoring" as const, + prNumber: 42, + startedAt: now, + blockersSummary: "", + headSha: "head-1", + wakeCount: 0, + updatedAt: now, + endedAt: null, + endedReason: null, + }, + latestUserMessageAt: null, + hasPendingApprovals: false, + hasPendingUserInput: false, + hasActionableProposedPlan: false, + })), updatedAt: now, }); }, getThreadDetailById: () => - Effect.succeed(Option.some(thread(input.busy?.value ?? false))), + Effect.map(DateTime.now, (currentDateTime) => { + const detail = thread(input.busy?.value ?? false); + const currentTime = DateTime.formatIso(currentDateTime); + return Option.some( + input.queuedUserTurn + ? { + ...detail, + messages: [ + { + id: MessageId.make("queued-message"), + role: "user" as const, + text: "user work", + attachments: [], + turnId: null, + streaming: false, + createdAt: currentTime, + updatedAt: currentTime, + }, + ], + } + : detail, + ); + }), }), NodeServices.layer, ), ), ); - return { monitor, commands, ordering, getRegistration: () => registration }; + monitorService = monitor; + return { + monitor, + commands, + ordering, + getRegistration: () => registration, + replaceGeneration: (generation: number) => { + if (registration) registration = { ...registration, generation }; + }, + }; }); const endReason = (commands: ReadonlyArray) => @@ -319,7 +401,10 @@ describe("PullRequestMonitor dispatch protocol", () => { const ready = snapshot({ checkRuns: [{ ...snapshot().checkRuns[0]!, status: "completed", conclusion: "success" }], }); - const h = yield* harness({ initial: snapshot(), current: { value: ready } }); + const h = yield* harness({ + initial: snapshot(), + current: { value: ready }, + }); yield* h.monitor.pollOnce; assert.deepStrictEqual( h.commands.map((command) => command.type), @@ -333,12 +418,16 @@ describe("PullRequestMonitor dispatch protocol", () => { const oldComment = { ...comment("old"), createdAt: "2026-07-22T00:00:00.000Z", + updatedAt: "2026-07-22T00:00:00.000Z", }; const ready = snapshot({ reviewThreads: [oldComment], checkRuns: [{ ...snapshot().checkRuns[0]!, status: "completed", conclusion: "success" }], }); - const h = yield* harness({ initial: snapshot(), current: { value: ready } }); + const h = yield* harness({ + initial: snapshot({ reviewThreads: [oldComment] }), + current: { value: ready }, + }); yield* h.monitor.pollOnce; assert.strictEqual(endReason(h.commands)?.type, "thread.monitor.end"); }), @@ -356,6 +445,31 @@ describe("PullRequestMonitor dispatch protocol", () => { }), ); + it.effect("ready defers to an actionable diff", () => + Effect.gen(function* () { + const h = yield* harness({ + initial: snapshot(), + current: { + value: snapshot({ + reviewThreads: [comment("one")], + checkRuns: [ + { ...snapshot().checkRuns[0]!, status: "completed", conclusion: "success" }, + ], + }), + }, + }); + yield* h.monitor.pollOnce; + assert.strictEqual( + h.commands.some((command) => command.type === "thread.turn.start"), + true, + ); + assert.strictEqual( + h.commands.some((command) => command.type === "thread.monitor.end"), + false, + ); + }), + ); + it.effect("failed-dispatch-preserves-cursor", () => Effect.gen(function* () { const initial = snapshot(); @@ -370,6 +484,19 @@ describe("PullRequestMonitor dispatch protocol", () => { }), ); + it.effect("conditional ack preserves a user-turn release", () => + Effect.gen(function* () { + const initial = snapshot(); + const h = yield* harness({ + initial, + current: { value: snapshot({ reviewThreads: [comment("one")] }) }, + releaseWakeOnDispatch: true, + }); + yield* h.monitor.pollOnce; + assert.deepStrictEqual(h.getRegistration()?.cursor, cursorFromSnapshot(initial)); + }), + ); + it.effect("failed-send-boundary-fetch-discards-wake-without-acking", () => Effect.gen(function* () { const initial = snapshot(); @@ -463,6 +590,21 @@ describe("PullRequestMonitor dispatch protocol", () => { }), ); + it.effect("queued user turn blocks a monitor wake", () => + Effect.gen(function* () { + const h = yield* harness({ + initial: snapshot(), + current: { value: snapshot({ reviewThreads: [comment("one")] }) }, + queuedUserTurn: true, + }); + yield* h.monitor.pollOnce; + assert.strictEqual( + h.commands.some((command) => command.type === "thread.turn.start"), + false, + ); + }), + ); + it.effect("coalesces events while a wake is in flight", () => Effect.gen(function* () { const current = { value: snapshot({ reviewThreads: [comment("one")] }) }; @@ -521,49 +663,30 @@ describe("PullRequestMonitor dispatch protocol", () => { }), ); - it.effect("archives by projecting stopped before removing the registration", () => + it.effect("delayed ended event preserves a newer generation", () => Effect.gen(function* () { const h = yield* harness({ initial: snapshot(), current: { value: snapshot() } }); + h.replaceGeneration(2); yield* h.monitor.handleDomainEvent({ sequence: 1, - eventId: EventId.make("archived"), + eventId: EventId.make("ended"), aggregateKind: "thread", aggregateId: threadId, occurredAt: now, - commandId: CommandId.make("archived"), + commandId: CommandId.make("ended"), causationEventId: null, correlationId: null, metadata: {}, - type: "thread.archived", - payload: { threadId, archivedAt: now, updatedAt: now }, + type: "thread.monitor-ended", + payload: { + threadId, + generation: 1, + reason: "stopped", + blockersSummary: "", + endedAt: now, + }, }); - const ended = endReason(h.commands); - assert.strictEqual(ended?.type === "thread.monitor.end" && ended.reason, "stopped"); - assert.strictEqual(h.getRegistration(), undefined); - }), - ); - - it.effect("removes an archived registration when projecting monitor end fails", () => - Effect.gen(function* () { - const h = yield* harness({ - initial: snapshot(), - current: { value: snapshot() }, - failEnd: true, - }); - yield* h.monitor.handleDomainEvent({ - sequence: 1, - eventId: EventId.make("archived"), - aggregateKind: "thread", - aggregateId: threadId, - occurredAt: now, - commandId: CommandId.make("archived"), - causationEventId: null, - correlationId: null, - metadata: {}, - type: "thread.archived", - payload: { threadId, archivedAt: now, updatedAt: now }, - }); - assert.strictEqual(h.getRegistration(), undefined); + assert.strictEqual(h.getRegistration()?.generation, 2); }), ); @@ -594,4 +717,24 @@ describe("PullRequestMonitor dispatch protocol", () => { ); }), ); + + it.effect("boot reconcile continues past a per-thread failure", () => + Effect.gen(function* () { + const failing = ThreadId.make("failing-orphan"); + const succeeding = ThreadId.make("succeeding-orphan"); + const h = yield* harness({ + initial: snapshot(), + current: { value: snapshot() }, + reconcileThreadIds: [failing, succeeding], + failReconcileThreadId: failing, + }); + yield* h.monitor.pollOnce; + assert.strictEqual( + h.commands.some( + (command) => command.type === "thread.monitor.end" && command.threadId === succeeding, + ), + true, + ); + }), + ); }); diff --git a/apps/server/src/monitor/PullRequestMonitor.ts b/apps/server/src/monitor/PullRequestMonitor.ts index 291673c2cb..5733e6aec1 100644 --- a/apps/server/src/monitor/PullRequestMonitor.ts +++ b/apps/server/src/monitor/PullRequestMonitor.ts @@ -24,6 +24,7 @@ import { buildWakePrompt, formatBlockersSummary } from "./wakePrompt.ts"; const POLL_INTERVAL = Duration.seconds(30); const MAX_BACKOFF = Duration.minutes(5); +const QUEUED_TURN_START_GRACE_MS = 2 * 60 * 1_000; interface WakeClaim { readonly generation: number; @@ -123,6 +124,7 @@ export const make = Effect.gen(function* () { const dispatchUpdate = Effect.fn("PullRequestMonitor.dispatchUpdate")(function* ( threadId: ThreadId, + generation: number, blockersSummary: string, headSha: string, wakeCount: number, @@ -132,6 +134,7 @@ export const make = Effect.gen(function* () { type: "thread.monitor.update", commandId: CommandId.make(yield* crypto.randomUUIDv4), threadId, + generation, blockersSummary, headSha, wakeCount, @@ -156,6 +159,7 @@ export const make = Effect.gen(function* () { type: "thread.monitor.end", commandId: CommandId.make(yield* crypto.randomUUIDv4), threadId, + generation: expectedGeneration, reason, blockersSummary, endedAt, @@ -185,7 +189,6 @@ export const make = Effect.gen(function* () { }); if (!claimed) return; - const current = yield* registry.get(registration.threadId); // Fresh terminal read at the send boundary (I1): the poll's snapshot is // seconds stale by now, and a merge in that window must veto the wake — // the cached `latestStates` alone cannot see it. @@ -202,11 +205,42 @@ export const make = Effect.gen(function* () { return; } const state = freshState.value; + const current = yield* registry.get(registration.threadId); const thread = yield* snapshots.getThreadDetailById(registration.threadId); const validRegistration = - Option.isSome(current) && current.value.generation === registration.generation; + Option.isSome(current) && + current.value.generation === registration.generation && + Option.isSome(thread) && + thread.value.archivedAt === null && + thread.value.monitor?.status === "monitoring" && + thread.value.monitor.generation === registration.generation; + const latestUserMessageAt = Option.isSome(thread) + ? thread.value.messages.reduce( + (latest, message) => + message.role === "user" ? Math.max(latest, Date.parse(message.createdAt)) : latest, + Number.NEGATIVE_INFINITY, + ) + : Number.NEGATIVE_INFINITY; + const latestTurnAt = + Option.isSome(thread) && thread.value.latestTurn !== null + ? Math.max( + ...[ + thread.value.latestTurn.requestedAt, + thread.value.latestTurn.startedAt, + thread.value.latestTurn.completedAt, + ].map((value) => (value === null ? Number.NEGATIVE_INFINITY : Date.parse(value))), + ) + : Number.NEGATIVE_INFINITY; + const createdAt = DateTime.formatIso(yield* DateTime.now); + const queuedUserTurn = + Option.isSome(thread) && + thread.value.session?.status !== "error" && + Number.isFinite(latestUserMessageAt) && + latestUserMessageAt > latestTurnAt && + Math.abs(Date.parse(createdAt) - latestUserMessageAt) <= QUEUED_TURN_START_GRACE_MS; const busy = Option.isNone(thread) || + queuedUserTurn || thread.value.latestTurn?.state === "running" || (thread.value.session?.activeTurnId !== null && thread.value.session?.activeTurnId !== undefined) || @@ -221,7 +255,6 @@ export const make = Effect.gen(function* () { return; } - const createdAt = DateTime.formatIso(yield* DateTime.now); yield* engine .dispatch({ type: "thread.turn.start", @@ -253,7 +286,13 @@ export const make = Effect.gen(function* () { ), ), Effect.tap(() => - registry.updateCursor(registration.threadId, nextCursor, registration.generation), + Ref.get(claims).pipe( + Effect.flatMap((currentClaims) => + currentClaims.get(registration.threadId)?.commandId === commandId + ? registry.updateCursor(registration.threadId, nextCursor, registration.generation) + : Effect.void, + ), + ), ), Effect.tapError(() => mutateClaim(registration.threadId, (claim) => @@ -264,6 +303,7 @@ export const make = Effect.gen(function* () { const wakeCount = yield* registry.incrementWake(registration.threadId, registration.generation); yield* dispatchUpdate( registration.threadId, + registration.generation, formatBlockersSummary(computeReadiness(snapshot)), snapshot.headSha, wakeCount, @@ -281,16 +321,18 @@ export const make = Effect.gen(function* () { ...fetchedSnapshot, monitoringStartedAt: registration.startedAt, }; - const readiness = computeReadiness(snapshot); + const readiness = computeReadiness(snapshot, registration.cursor.threadVersions); const summary = formatBlockersSummary(readiness); + const diff = diffPullRequestMonitorSnapshot(registration.cursor, snapshot); if (snapshot.state !== "open") { yield* end(registration.threadId, "terminal", summary, registration.generation); return; } - if (readiness.ready) { + if (readiness.ready && diff.actionableEvents.length === 0) { yield* dispatchUpdate( registration.threadId, + registration.generation, summary, snapshot.headSha, registration.wakeCount, @@ -299,9 +341,17 @@ export const make = Effect.gen(function* () { return; } - const diff = diffPullRequestMonitorSnapshot(registration.cursor, snapshot); - yield* dispatchUpdate(registration.threadId, summary, snapshot.headSha, registration.wakeCount); - if (diff.actionableEvents.length === 0) return; + yield* dispatchUpdate( + registration.threadId, + registration.generation, + summary, + snapshot.headSha, + registration.wakeCount, + ); + if (diff.actionableEvents.length === 0) { + yield* registry.updateCursor(registration.threadId, diff.nextCursor, registration.generation); + return; + } if (registration.wakeCount >= 10) { yield* end(registration.threadId, "needs-attention", summary, registration.generation); return; @@ -335,12 +385,19 @@ export const make = Effect.gen(function* () { type: "thread.monitor.end", commandId: CommandId.make(`monitor-boot-reconcile:${thread.id}:${endedAt}`), threadId: thread.id, + generation: thread.monitor!.generation, reason: "session-ended", blockersSummary: "", endedAt, }); }); }), + Effect.catchCause((cause) => + Effect.logWarning("pull request monitor orphan reconcile failed", { + threadId: thread.id, + cause, + }), + ), ), { discard: true }, ); @@ -378,41 +435,61 @@ export const make = Effect.gen(function* () { const onEvent = (event: OrchestrationEvent) => { const threadId = threadIdOf(event); if (threadId === undefined) return Effect.void; - if (event.type === "thread.archived") { - return registry.get(threadId).pipe( - Effect.flatMap((registration) => - Option.isNone(registration) - ? Effect.void - : end(threadId, "stopped", "", registration.value.generation).pipe( - Effect.catch((error) => - Effect.logWarning( - "pull request monitor archive projection stuck; removing registration", - { - threadId, - error, - }, - ).pipe( - Effect.andThen(registry.remove(threadId, registration.value.generation)), + if (event.type === "thread.monitor-ended") { + return registry + .remove(threadId, event.payload.generation) + .pipe( + Effect.andThen( + mutateClaim(threadId, (claim) => + claim?.generation === event.payload.generation ? undefined : claim, + ), + ), + Effect.asVoid, + ); + } + if (event.type === "thread.settled") { + return Effect.all([registry.get(threadId), snapshots.getThreadDetailById(threadId)]).pipe( + Effect.flatMap(([registration, thread]) => { + if ( + Option.isNone(registration) || + Option.isNone(thread) || + thread.value.monitor?.generation !== registration.value.generation + ) + return Effect.void; + return registry + .remove(threadId, registration.value.generation) + .pipe( + Effect.andThen( + mutateClaim(threadId, (claim) => + claim?.generation === registration.value.generation ? undefined : claim, + ), + ), + ); + }), + Effect.catchCause((cause) => + Effect.logWarning("pull request monitor settled cleanup failed", { threadId, cause }), + ), + Effect.asVoid, + ); + } + if (event.type === "thread.deleted") { + return registry + .get(threadId) + .pipe( + Effect.flatMap((registration) => + Option.isNone(registration) + ? Effect.void + : registry + .remove(threadId, registration.value.generation) + .pipe( Effect.andThen( mutateClaim(threadId, (claim) => claim?.generation === registration.value.generation ? undefined : claim, ), ), - Effect.asVoid, ), - ), - ), - ), - ); - } - if ( - event.type === "thread.deleted" || - event.type === "thread.settled" || - event.type === "thread.monitor-ended" - ) { - return registry - .remove(threadId) - .pipe(Effect.andThen(mutateClaim(threadId, () => undefined)), Effect.asVoid); + ), + ); } if (event.type === "thread.turn-start-requested") { // A turn we didn't start won the thread. Drop our claim — and if our diff --git a/apps/server/src/monitor/monitorDiff.ts b/apps/server/src/monitor/monitorDiff.ts index 7aaeda8186..adab7ce6b7 100644 --- a/apps/server/src/monitor/monitorDiff.ts +++ b/apps/server/src/monitor/monitorDiff.ts @@ -18,7 +18,11 @@ export interface PullRequestMonitorCursor { export type PullRequestMonitorActionableEvent = | { readonly kind: "new-review-comment"; readonly threadId: string; readonly edited: boolean } - | { readonly kind: "changes-requested-review"; readonly reviewId: string } + | { + readonly kind: "changes-requested-review"; + readonly reviewId: string; + readonly body: string; + } | { readonly kind: "check-failed"; readonly checkRunId: string; readonly checkName: string } | { readonly kind: "behind-base" }; @@ -69,11 +73,12 @@ export function diffPullRequestMonitorSnapshot( const actionableEvents: PullRequestMonitorActionableEvent[] = []; for (const thread of snapshot.reviewThreads) { const previous = previousCursor.threadVersions[thread.id]; - if ( + const reopened = previous?.resolved === true && !thread.resolved; + const changedComment = !thread.latestCommentByViewer && !thread.resolved && - (!previous || previous.resolved || previous.updatedAt !== thread.updatedAt) - ) { + (!previous || previous.updatedAt !== thread.updatedAt); + if (reopened || changedComment) { actionableEvents.push({ kind: "new-review-comment", threadId: thread.id, @@ -97,7 +102,11 @@ export function diffPullRequestMonitorSnapshot( review.state === "changes-requested" && previousCursor.reviewStates[review.id] !== "changes-requested" ) { - actionableEvents.push({ kind: "changes-requested-review", reviewId: review.id }); + actionableEvents.push({ + kind: "changes-requested-review", + reviewId: review.id, + body: review.body.slice(0, 500), + }); } } for (const check of snapshot.checkRuns.filter((item) => item.headSha === snapshot.headSha)) { diff --git a/apps/server/src/monitor/readiness.test.ts b/apps/server/src/monitor/readiness.test.ts index 0c25491a5b..9d3e8cbb88 100644 --- a/apps/server/src/monitor/readiness.test.ts +++ b/apps/server/src/monitor/readiness.test.ts @@ -42,6 +42,7 @@ describe("pull request monitor readiness", () => { state: "changes-requested", submittedAt: "2026-01-01T00:00:00Z", commitSha: "head-1", + body: "", }, ], }), @@ -62,6 +63,7 @@ describe("pull request monitor readiness", () => { state: "changes-requested", submittedAt: "2026-01-01T00:00:00Z", commitSha: "head-2", + body: "", }, ], }), @@ -81,6 +83,7 @@ describe("pull request monitor readiness", () => { state: "approved", submittedAt: "2026-01-01T00:00:00Z", commitSha: "head-1", + body: "", }, ], }), @@ -89,6 +92,32 @@ describe("pull request monitor readiness", () => { assert.strictEqual(result.ready, true); }); + it("unblocks a changes request superseded by the same reviewer's approval", () => { + const result = computeReadiness( + snapshot({ + reviews: [ + { + id: "changes", + author: { login: "reviewer", type: "user" }, + state: "changes-requested", + submittedAt: "2026-01-01T00:00:00Z", + commitSha: "head-1", + body: "Please fix this", + }, + { + id: "approval", + author: { login: "reviewer", type: "user" }, + state: "approved", + submittedAt: "2026-01-02T00:00:00Z", + commitSha: "head-2", + body: "", + }, + ], + }), + ); + assert.strictEqual(result.ready, true); + }); + it("does not report ready when no check runs exist", () => { const result = computeReadiness(snapshot({ checkRuns: [] })); assert.strictEqual(result.ready, false); diff --git a/apps/server/src/monitor/readiness.ts b/apps/server/src/monitor/readiness.ts index 3daafe89e2..1d52a95052 100644 --- a/apps/server/src/monitor/readiness.ts +++ b/apps/server/src/monitor/readiness.ts @@ -18,6 +18,9 @@ export interface PullRequestMonitorReadiness { export function computeReadiness( snapshot: PullRequestMonitorSnapshot, + previousThreadVersions: Readonly< + Record + > = {}, ): PullRequestMonitorReadiness { const blockers: PullRequestMonitorBlocker[] = []; if (snapshot.state !== "open") blockers.push({ kind: "terminal", state: snapshot.state }); @@ -38,7 +41,15 @@ export function computeReadiness( blockers.push({ kind: "check-failed", checkName: check.name }); } } + const latestOpinionatedReviews = new Map(); for (const review of snapshot.reviews) { + if (review.state !== "changes-requested" && review.state !== "approved") continue; + const previous = latestOpinionatedReviews.get(review.author.login); + if (previous === undefined || (review.submittedAt ?? "") > (previous.submittedAt ?? "")) { + latestOpinionatedReviews.set(review.author.login, review); + } + } + for (const review of latestOpinionatedReviews.values()) { // Stale approvals must not count toward green, but a changes-requested // review blocks regardless of which commit it reviewed — GitHub keeps it // active until dismissed or superseded by a re-review. @@ -47,10 +58,12 @@ export function computeReadiness( } } for (const thread of snapshot.reviewThreads) { - if ( - !thread.resolved && - (!snapshot.monitoringStartedAt || thread.createdAt >= snapshot.monitoringStartedAt) - ) { + const previous = previousThreadVersions[thread.id]; + const changedSinceStart = + snapshot.monitoringStartedAt === undefined || + thread.updatedAt > snapshot.monitoringStartedAt || + (previous?.resolved === true && !thread.resolved); + if (!thread.resolved && changedSinceStart) { blockers.push({ kind: "unresolved-thread", threadId: thread.id }); } } diff --git a/apps/server/src/monitor/wakePrompt.ts b/apps/server/src/monitor/wakePrompt.ts index 5d72fca76e..939288fe94 100644 --- a/apps/server/src/monitor/wakePrompt.ts +++ b/apps/server/src/monitor/wakePrompt.ts @@ -52,7 +52,8 @@ function formatEvent( } case "changes-requested-review": { const review = snapshot.reviews.find((item) => item.id === event.reviewId); - return `- ${review?.author.login ?? "Reviewer"} requested changes`; + const detail = excerpt(event.body); + return `- ${review?.author.login ?? "Reviewer"} requested changes${detail ? `: ${detail}` : ""}`; } case "check-failed": { const check = snapshot.checkRuns.find((item) => item.id === event.checkRunId); diff --git a/apps/server/src/orchestration/Layers/ProjectionPipeline.ts b/apps/server/src/orchestration/Layers/ProjectionPipeline.ts index c6eccc6590..c185bd1bc9 100644 --- a/apps/server/src/orchestration/Layers/ProjectionPipeline.ts +++ b/apps/server/src/orchestration/Layers/ProjectionPipeline.ts @@ -722,6 +722,7 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti yield* projectionThreadRepository.upsert({ ...existingRow.value, monitor: { + generation: event.payload.generation, prNumber: event.payload.prNumber, status: "monitoring", blockersSummary: event.payload.blockersSummary, @@ -740,7 +741,11 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti const existingRow = yield* projectionThreadRepository.getById({ threadId: event.payload.threadId, }); - if (Option.isNone(existingRow) || existingRow.value.monitor === null) return; + if ( + Option.isNone(existingRow) || + existingRow.value.monitor?.generation !== event.payload.generation + ) + return; yield* projectionThreadRepository.upsert({ ...existingRow.value, monitor: { @@ -758,7 +763,11 @@ const makeOrchestrationProjectionPipeline = Effect.fn("makeOrchestrationProjecti const existingRow = yield* projectionThreadRepository.getById({ threadId: event.payload.threadId, }); - if (Option.isNone(existingRow) || existingRow.value.monitor === null) return; + if ( + Option.isNone(existingRow) || + existingRow.value.monitor?.generation !== event.payload.generation + ) + return; yield* projectionThreadRepository.upsert({ ...existingRow.value, monitor: { diff --git a/apps/server/src/orchestration/decider.monitor.test.ts b/apps/server/src/orchestration/decider.monitor.test.ts index a95a9d3ca3..f2a0471acd 100644 --- a/apps/server/src/orchestration/decider.monitor.test.ts +++ b/apps/server/src/orchestration/decider.monitor.test.ts @@ -46,6 +46,7 @@ const makeReadModel = (monitor: OrchestrationThread["monitor"] = null): Orchestr }); const activeMonitor: NonNullable = { + generation: 1, prNumber: 42, status: "monitoring", blockersSummary: "waiting", @@ -66,6 +67,7 @@ it.layer(NodeServices.layer)("monitor decider", (it) => { type: "thread.monitor.start" as const, commandId: commandId("start"), threadId, + generation: 1, prNumber: 42, blockersSummary: "", headSha: "abc", @@ -100,6 +102,7 @@ it.layer(NodeServices.layer)("monitor decider", (it) => { type: "thread.monitor.start", commandId: commandId("different"), threadId, + generation: 2, prNumber: 43, blockersSummary: "", headSha: "def", @@ -114,6 +117,7 @@ it.layer(NodeServices.layer)("monitor decider", (it) => { type: "thread.monitor.update", commandId: commandId("update"), threadId, + generation: 1, blockersSummary: "CI", headSha: "def", wakeCount: 1, @@ -129,6 +133,7 @@ it.layer(NodeServices.layer)("monitor decider", (it) => { type: "thread.monitor.end", commandId: commandId("end"), threadId, + generation: 1, reason: "ready", blockersSummary: "", endedAt: NOW, @@ -146,6 +151,7 @@ it.layer(NodeServices.layer)("monitor decider", (it) => { type: "thread.monitor.update" as const, commandId: commandId("bad-update"), threadId, + generation: 1, blockersSummary: "", headSha: "abc", wakeCount: 0, @@ -155,6 +161,7 @@ it.layer(NodeServices.layer)("monitor decider", (it) => { type: "thread.monitor.end" as const, commandId: commandId("bad-end"), threadId, + generation: 1, reason: "stopped" as const, blockersSummary: "", endedAt: NOW, @@ -176,4 +183,20 @@ it.layer(NodeServices.layer)("monitor decider", (it) => { ]); }), ); + + it.effect("archive emits monitor-ended before archived", () => + Effect.gen(function* () { + const archived = yield* decideOrchestrationCommand({ + command: { type: "thread.archive", commandId: commandId("archive"), threadId }, + readModel: makeReadModel(activeMonitor), + }); + expect(Array.isArray(archived) ? archived.map((event) => event.type) : []).toEqual([ + "thread.monitor-ended", + "thread.archived", + ]); + if (Array.isArray(archived) && archived[0]?.type === "thread.monitor-ended") { + expect(archived[0].payload.generation).toBe(1); + } + }), + ); }); diff --git a/apps/server/src/orchestration/decider.ts b/apps/server/src/orchestration/decider.ts index 41eb852cc5..cc1f008f6b 100644 --- a/apps/server/src/orchestration/decider.ts +++ b/apps/server/src/orchestration/decider.ts @@ -401,13 +401,13 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand" } case "thread.archive": { - yield* requireThreadNotArchived({ + const thread = yield* requireThreadNotArchived({ readModel, command, threadId: command.threadId, }); const occurredAt = yield* nowIso; - return { + const archivedEvent: PlannedOrchestrationEvent = { ...(yield* withEventBase({ aggregateKind: "thread", aggregateId: command.threadId, @@ -421,6 +421,26 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand" updatedAt: occurredAt, }, }; + if (thread.monitor?.status !== "monitoring") return archivedEvent; + return [ + { + ...(yield* withEventBase({ + aggregateKind: "thread", + aggregateId: command.threadId, + occurredAt, + commandId: command.commandId, + })), + type: "thread.monitor-ended", + payload: { + threadId: command.threadId, + generation: thread.monitor.generation, + reason: "stopped", + blockersSummary: thread.monitor.blockersSummary, + endedAt: occurredAt, + }, + }, + archivedEvent, + ]; } case "thread.unarchive": { @@ -516,6 +536,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand" type: "thread.monitor-ended", payload: { threadId: command.threadId, + generation: thread.monitor.generation, reason: "stopped", blockersSummary: thread.monitor.blockersSummary, endedAt: occurredAt, @@ -547,6 +568,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand" type: "thread.monitor-started", payload: { threadId: command.threadId, + generation: command.generation, prNumber: command.prNumber, blockersSummary: thread.monitor?.status === "monitoring" @@ -596,6 +618,12 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand" detail: `thread ${command.threadId} has no active monitor`, }); } + if (command.generation !== undefined && command.generation !== thread.monitor.generation) { + return yield* new OrchestrationCommandInvariantError({ + commandType: command.type, + detail: `thread ${command.threadId} monitor generation does not match`, + }); + } return { ...(yield* withEventBase({ aggregateKind: "thread", @@ -606,6 +634,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand" type: "thread.monitor-snapshot-updated", payload: { threadId: command.threadId, + generation: thread.monitor.generation, blockersSummary: command.blockersSummary, headSha: command.headSha, wakeCount: command.wakeCount, @@ -626,6 +655,13 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand" detail: `thread ${command.threadId} has no active monitor`, }); } + const generation = command.generation ?? thread.monitor.generation; + if (generation !== thread.monitor.generation) { + return yield* new OrchestrationCommandInvariantError({ + commandType: command.type, + detail: `thread ${command.threadId} monitor generation does not match`, + }); + } return { ...(yield* withEventBase({ aggregateKind: "thread", @@ -636,6 +672,7 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand" type: "thread.monitor-ended", payload: { threadId: command.threadId, + generation, reason: command.reason, blockersSummary: command.blockersSummary, endedAt: command.endedAt, diff --git a/apps/server/src/orchestration/projector.monitor.test.ts b/apps/server/src/orchestration/projector.monitor.test.ts index 038a74bfc3..28bcf48391 100644 --- a/apps/server/src/orchestration/projector.monitor.test.ts +++ b/apps/server/src/orchestration/projector.monitor.test.ts @@ -32,6 +32,7 @@ it.effect("projects the monitor lifecycle without changing settledOverride", () createEmptyReadModel(NOW), event(1, "thread.created", { threadId: ThreadId.make("thread-1"), + generation: 1, projectId: ProjectId.make("project-1"), title: "Thread", modelSelection: { provider: "codex", model: "gpt-5.4" }, @@ -47,6 +48,7 @@ it.effect("projects the monitor lifecycle without changing settledOverride", () model, event(2, "thread.monitor-started", { threadId: ThreadId.make("thread-1"), + generation: 1, prNumber: 42, blockersSummary: "draft", headSha: "abc", @@ -60,6 +62,7 @@ it.effect("projects the monitor lifecycle without changing settledOverride", () model, event(3, "thread.monitor-snapshot-updated", { threadId: ThreadId.make("thread-1"), + generation: 1, blockersSummary: "CI", headSha: "def", wakeCount: 2, @@ -71,6 +74,7 @@ it.effect("projects the monitor lifecycle without changing settledOverride", () model, event(4, "thread.monitor-ended", { threadId: ThreadId.make("thread-1"), + generation: 1, reason: "ready", blockersSummary: "", endedAt: NOW, diff --git a/apps/server/src/orchestration/projector.ts b/apps/server/src/orchestration/projector.ts index 9e2f8148c3..80d003f80c 100644 --- a/apps/server/src/orchestration/projector.ts +++ b/apps/server/src/orchestration/projector.ts @@ -403,6 +403,7 @@ export function projectEvent( ...nextBase, threads: updateThread(nextBase.threads, payload.threadId, { monitor: { + generation: payload.generation, prNumber: payload.prNumber, status: "monitoring", blockersSummary: payload.blockersSummary, @@ -427,7 +428,7 @@ export function projectEvent( Effect.map((payload) => ({ ...nextBase, threads: nextBase.threads.map((thread) => - thread.id === payload.threadId && thread.monitor != null + thread.id === payload.threadId && thread.monitor?.generation === payload.generation ? { ...thread, monitor: { @@ -448,7 +449,7 @@ export function projectEvent( Effect.map((payload) => ({ ...nextBase, threads: nextBase.threads.map((thread) => - thread.id === payload.threadId && thread.monitor != null + thread.id === payload.threadId && thread.monitor?.generation === payload.generation ? { ...thread, monitor: { diff --git a/apps/server/src/sourceControl/gitHubPullRequestMonitor.ts b/apps/server/src/sourceControl/gitHubPullRequestMonitor.ts index ef17444f62..95da0c8611 100644 --- a/apps/server/src/sourceControl/gitHubPullRequestMonitor.ts +++ b/apps/server/src/sourceControl/gitHubPullRequestMonitor.ts @@ -17,6 +17,7 @@ export interface PullRequestMonitorReview { readonly state: "approved" | "changes-requested" | "commented" | "dismissed" | "pending"; readonly submittedAt: string | null; readonly commitSha: string | null; + readonly body: string; } export interface PullRequestMonitorReviewThread { @@ -82,6 +83,7 @@ const ReviewSchema = Schema.Struct({ state: Schema.String, submittedAt: Schema.NullOr(Schema.String), commit: Schema.NullOr(Schema.Struct({ oid: Schema.String })), + body: Schema.String, }); const ThreadSchema = Schema.Struct({ id: Schema.String, @@ -153,6 +155,19 @@ const CheckRunsSchema = Schema.Struct({ }), ), }); +const FinalPullRequestStateSchema = Schema.Struct({ + data: Schema.Struct({ + repository: Schema.Struct({ + pullRequest: Schema.NullOr( + Schema.Struct({ + state: Schema.String, + merged: Schema.Boolean, + headRefOid: Schema.String, + }), + ), + }), + }), +}); export class GitHubPullRequestMonitorDecodeError extends Schema.TaggedErrorClass()( "GitHubPullRequestMonitorDecodeError", @@ -230,6 +245,7 @@ export const getPullRequestMonitorSnapshot = Effect.fn("getPullRequestMonitorSna function* (input: { readonly cwd: string; readonly pullRequestNumber: number; + readonly refetchAttempt?: number; }): Effect.fn.Return< PullRequestMonitorSnapshot, GitHubPullRequestMonitorError, @@ -270,7 +286,7 @@ export const getPullRequestMonitorSnapshot = Effect.fn("getPullRequestMonitorSna > | undefined; do { - const query = `query($owner:String!,$name:String!,$number:Int!,$reviews:String,$threads:String){viewer{login} repository(owner:$owner,name:$name){pullRequest(number:$number){state isDraft merged mergeable headRefOid baseRefName reviews(first:100,after:$reviews){nodes{id author{login __typename} state submittedAt commit{oid}} pageInfo{hasNextPage endCursor}} reviewThreads(first:100,after:$threads){nodes{id isResolved comments(last:1){nodes{author{login __typename} body path line createdAt updatedAt}}} pageInfo{hasNextPage endCursor}}}}}`; + const query = `query($owner:String!,$name:String!,$number:Int!,$reviews:String,$threads:String){viewer{login} repository(owner:$owner,name:$name){pullRequest(number:$number){state isDraft merged mergeable headRefOid baseRefName reviews(first:100,after:$reviews){nodes{id author{login __typename} state submittedAt commit{oid} body} pageInfo{hasNextPage endCursor}} reviewThreads(first:100,after:$threads){nodes{id isResolved comments(last:10){nodes{author{login __typename} body path line createdAt updatedAt}}} pageInfo{hasNextPage endCursor}}}}}`; const result: VcsProcess.VcsProcessOutput = yield* github.execute({ cwd: input.cwd, args: [ @@ -326,6 +342,7 @@ export const getPullRequestMonitorSnapshot = Effect.fn("getPullRequestMonitorSna state: normalizeReviewState(review.state), submittedAt: review.submittedAt, commitSha: review.commit?.oid ?? null, + body: review.body, }); } reviewsComplete = !pr.reviews.pageInfo.hasNextPage; @@ -333,7 +350,13 @@ export const getPullRequestMonitorSnapshot = Effect.fn("getPullRequestMonitorSna } if (!threadsComplete) { for (const thread of pr.reviewThreads.nodes) { - const comment = thread.comments.nodes[0]; + const comment = thread.comments.nodes.reduce< + (typeof thread.comments.nodes)[number] | undefined + >( + (latest, candidate) => + latest === undefined || candidate.updatedAt > latest.updatedAt ? candidate : latest, + undefined, + ); if (comment) { reviewThreads.set(thread.id, { id: thread.id, @@ -427,6 +450,53 @@ export const getPullRequestMonitorSnapshot = Effect.fn("getPullRequestMonitorSna if (response.check_runs.length < 100) break; } + const finalQuery = `query($owner:String!,$name:String!,$number:Int!){repository(owner:$owner,name:$name){pullRequest(number:$number){state merged headRefOid}}}`; + const finalResult = yield* github.execute({ + cwd: input.cwd, + args: [ + "api", + "graphql", + "-f", + `query=${finalQuery}`, + "-F", + `owner=${owner}`, + "-F", + `name=${name}`, + "-F", + `number=${input.pullRequestNumber}`, + ], + }); + const finalPage = yield* decode( + FinalPullRequestStateSchema, + finalResult.stdout, + input.cwd, + "GitHub GraphQL returned invalid final pull request state JSON.", + ); + const finalPr = finalPage.data.repository.pullRequest; + if (finalPr === null) { + return yield* new GitHubPullRequestMonitorDecodeError({ + command: "gh", + cwd: input.cwd, + detail: "GitHub pull request disappeared during monitor fetch.", + cause: input.pullRequestNumber, + }); + } + const finalState: PullRequestMonitorSnapshot["state"] = finalPr.merged + ? "merged" + : finalPr.state === "CLOSED" + ? "closed" + : "open"; + if (finalState !== "open") metadata = { ...metadata, state: finalState }; + if (finalState === "open" && finalPr.headRefOid !== metadata.headSha) { + if ((input.refetchAttempt ?? 0) === 0) { + return yield* getPullRequestMonitorSnapshot({ + ...input, + refetchAttempt: 1, + }); + } + metadata = { ...metadata, headSha: finalPr.headRefOid }; + } + return { ...metadata, behindBaseBy: null, diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 83fc0c1e35..f774c77c7b 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -2337,12 +2337,17 @@ function ChatViewContent(props: ChatViewProps) { // ready-state "View PR"/"Merge…" affordances, and a stop handler that ends // the monitor via the same command path the server drives. const openPrLink = useOpenPrLink(); + const checkoutPr = resolveThreadPr({ + threadBranch: activeThread?.branch ?? null, + gitStatus: gitStatusQuery.data ?? null, + hasDedicatedWorktree: activeThread?.worktreePath != null, + }); + // Monitoring can target a PR other than the checkout's current PR, so never + // let the ready actions open a differently numbered pull request. const monitorPrUrl = - resolveThreadPr({ - threadBranch: activeThread?.branch ?? null, - gitStatus: gitStatusQuery.data ?? null, - hasDedicatedWorktree: activeThread?.worktreePath != null, - })?.url ?? null; + checkoutPr !== null && checkoutPr.number === activeThread?.monitor?.prNumber + ? checkoutPr.url + : null; const handleStopMonitoring = useCallback(() => { if (activeThread == null || activeThread.monitor == null) return; void endThreadMonitor({ diff --git a/apps/web/src/components/MonitorStrip.tsx b/apps/web/src/components/MonitorStrip.tsx index 23e6cba66c..c5e56d132c 100644 --- a/apps/web/src/components/MonitorStrip.tsx +++ b/apps/web/src/components/MonitorStrip.tsx @@ -1,6 +1,6 @@ import type { OrchestrationThreadMonitor } from "@t3tools/contracts"; import { ExternalLinkIcon, GitMergeIcon } from "lucide-react"; -import { type MouseEvent, useState } from "react"; +import { type MouseEvent, useEffect, useState } from "react"; import { cn } from "~/lib/utils"; import { resolveMonitorReadyLabel, resolveMonitorSidebarState } from "./Sidebar.logic"; @@ -42,9 +42,13 @@ export function MonitorStrip({ }) { const [mergeConfirmOpen, setMergeConfirmOpen] = useState(false); const state = resolveMonitorSidebarState(monitor); + useEffect(() => { + setMergeConfirmOpen(false); + }, [monitor.prNumber, monitor.status]); // Only the meaningful, live-ish states get a strip: an actively monitoring - // PR, the ready payoff, or a dead-session floor marker. Terminal/user-stop/ - // needs-attention monitors hand off to the normal settled/status treatment. + // PR, the ready payoff, the needs-attention escalation, or a dead-session + // floor marker. Other terminal/user-stop monitors hand off to the normal + // settled/status treatment. if (state === null) return null; const blockers = monitor.blockersSummary.trim(); @@ -65,6 +69,22 @@ export function MonitorStrip({ ); } + if (state === "needs-attention") { + return ( +
+
+ + + Monitoring paused — needs your attention + + {blockers !== "" ? ( + {blockers} + ) : null} +
+
+ ); + } + const isReady = state === "ready"; const handleOpenPr = (event: MouseEvent) => { if (prUrl) onOpenPr(event, prUrl); @@ -145,8 +165,9 @@ export function MonitorStrip({ rather than inventing a new server mutation (out of P3 scope). */}