From 6657a951ab23b88276e79f993ae03e0d2b750a42 Mon Sep 17 00:00:00 2001 From: Tibor Casteleijn Date: Thu, 19 Nov 2026 14:24:19 +0100 Subject: [PATCH 1/6] fix(server): wake when CI fails during the PR watch baseline read A watch's immediate start read can return failed if CI flips while that read is in flight. awaitingBaseline then records the red as old news and later sweeps never wake. Seed checksPending from the rollup at watch_pull_request and report those failures. Co-authored-by: Cursor --- .../src/orchestration-v2/Orchestrator.ts | 10 +++- .../orchestration-v2/pullRequestWatch.test.ts | 52 +++++++++++++++++++ .../src/orchestration-v2/pullRequestWatch.ts | 6 ++- .../pullRequest/PullRequestWatchService.ts | 15 ++++-- packages/contracts/src/orchestrationV2.ts | 6 +++ 5 files changed, 84 insertions(+), 5 deletions(-) diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index c71addfa57c0..15d810a6d383 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -5255,7 +5255,15 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio approvalAnnounced: existing.endedWatch.approvalAnnounced, }), // A finished-checks answer may be an older head's; a fresh read decides. - ...(existing.endedWatch?.checksPending === true && { checksPending: true }), + // Prefer the host rollup from watch_pull_request so a pending→failed race + // during the immediate baseline read still wakes; endedWatch only fills + // when that is absent. + ...(command.type === "thread.pull-request.watch" && + command.checksPending !== undefined + ? { checksPending: command.checksPending } + : existing.endedWatch?.checksPending === true + ? { checksPending: true } + : {}), ...(existing.endedWatch?.checksAwaitedSince !== undefined && { checksAwaitedSince: existing.endedWatch.checksAwaitedSince, }), diff --git a/apps/server/src/orchestration-v2/pullRequestWatch.test.ts b/apps/server/src/orchestration-v2/pullRequestWatch.test.ts index c0ab327d41af..b24765f64496 100644 --- a/apps/server/src/orchestration-v2/pullRequestWatch.test.ts +++ b/apps/server/src/orchestration-v2/pullRequestWatch.test.ts @@ -190,6 +190,58 @@ describe("evaluatePullRequestWatch", () => { ]); }); + // Pending-at-start watches must report failures the baseline read returns; otherwise a + // host that flips to red during that read is baselined and never wakes. + it("reports failures when the baseline read returns red after a pending-at-start watch", () => { + const red = detail({ + checks: [check("lint", "failure"), check("test", "failure")], + }); + const reported = evaluatePullRequestWatch( + watch({ awaitingBaseline: "all", checksPending: true }), + red, + noRemarks, + ); + assert.deepEqual(reported.changes, [ + { + kind: "checks-failed", + failed: [check("lint", "failure"), check("test", "failure")], + }, + ]); + assert.isFalse(reported.next.checksPending); + + // Already terminal when the watch started: still baselined (no wake). + assert.deepEqual( + evaluatePullRequestWatch( + watch({ awaitingBaseline: "all", checksPending: false }), + red, + noRemarks, + ).changes, + [], + ); + + // Partial settle on the first read: keep quiet until the rest finish, but do not lose the + // pending-start debt — a later all-green must still surface the earlier failure. + const partial = detail({ + checks: [check("lint", "failure"), check("test", "pending")], + }); + const waiting = evaluatePullRequestWatch( + watch({ awaitingBaseline: "all", checksPending: true }), + partial, + noRemarks, + ); + assert.deepEqual(waiting.changes, [ + { kind: "checks-failed", failed: [check("lint", "failure")] }, + ]); + assert.deepEqual(waiting.next.failedChecks, ["lint"]); + assert.isTrue(waiting.next.checksPending); + const laterGreen = evaluatePullRequestWatch( + waiting.next, + detail({ checks: [check("lint", "failure"), check("test", "success")] }), + noRemarks, + ); + assert.deepEqual(laterGreen.changes, []); + }); + it("baselines checks already awaiting approval", () => { const gated = detail({ checks: [{ ...check("CI", "action-required"), url: run(1) }] }); const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: "all" }), gated, noRemarks); diff --git a/apps/server/src/orchestration-v2/pullRequestWatch.ts b/apps/server/src/orchestration-v2/pullRequestWatch.ts index eedbe47d1a01..8ddfdf444c67 100644 --- a/apps/server/src/orchestration-v2/pullRequestWatch.ts +++ b/apps/server/src/orchestration-v2/pullRequestWatch.ts @@ -78,7 +78,11 @@ export function evaluatePullRequestWatch( // A run awaiting approval waits on a person, like a review, so only running checks count. checksPending = checks.some((check) => check.status === "pending"); const newlyFailed = failed.filter((check) => !failedChecks.includes(check.name)); - if (!checksBaseline && newlyFailed.length > 0) { + // Baseline suppresses failures that were already terminal when the watch started. A watch + // seeded with checksPending (CI still running at watch_pull_request) must still report + // failures the baseline read returns — including when another check is still pending — + // otherwise a host that flips to red during the immediate start read never wakes. + if (newlyFailed.length > 0 && (!checksBaseline || watch.checksPending === true)) { changes.push({ kind: "checks-failed", failed: newlyFailed }); } if (!approvalAnnounced && awaiting.length > 0) { diff --git a/apps/server/src/pullRequest/PullRequestWatchService.ts b/apps/server/src/pullRequest/PullRequestWatchService.ts index c50de1a847f9..f3f42ebf27bd 100644 --- a/apps/server/src/pullRequest/PullRequestWatchService.ts +++ b/apps/server/src/pullRequest/PullRequestWatchService.ts @@ -126,8 +126,11 @@ const make = Effect.gen(function* () { if (watching && before?.snapshot?.state === "merged") { return yield* new PullRequestNotOpenError({ state: "merged" }); } + // When CI was still running (or the rollup was unread) at watch start, seed checksPending so + // a failure the immediate baseline read returns is reported instead of baselined away. + let checksPendingAtStart: boolean | undefined; if (watching && before?.watch === undefined) { - yield* pullRequests + checksPendingAtStart = yield* pullRequests .summary( { projectId: thread.projectId, @@ -142,11 +145,14 @@ const make = Effect.gen(function* () { Effect.flatMap((summary) => summary.state === "merged" ? Effect.fail(new PullRequestNotOpenError({ state: "merged" })) - : Effect.void, + : Effect.succeed( + // Unknown rollup: prefer pending so a fast fail during the baseline read still wakes. + summary.checksState === "pending" || summary.checksState == null, + ), ), Effect.catchTags({ // Host and transport errors can recover while the watch is active. - PullRequestOperationError: () => Effect.void, + PullRequestOperationError: () => Effect.succeed(true as const), }), ); } @@ -162,6 +168,9 @@ const make = Effect.gen(function* () { watching, ...(watching ? { link: { url: target.url, source: "agent" as const } } : {}), ...(watching && input.until !== undefined && { until: input.until }), + ...(watching && checksPendingAtStart !== undefined + ? { checksPending: checksPendingAtStart } + : {}), }) .pipe( Effect.catchCause((cause) => diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts index c5286116655d..75c8388750a2 100644 --- a/packages/contracts/src/orchestrationV2.ts +++ b/packages/contracts/src/orchestrationV2.ts @@ -3323,6 +3323,12 @@ export const OrchestrationV2Command = Schema.Union([ watching: Schema.Boolean, /** With `watching`, sets how long the watch holds its thread; absent keeps the current one. */ until: Schema.optional(PullRequestWatchUntil), + /** + * Host check rollup when the watch starts. `true` when CI was still running (or unknown); + * `false` when it had already passed or failed. Seeds `checksPending` so a failure the + * immediate baseline read returns is still news, not a silent baseline. + */ + checksPending: Schema.optional(Schema.Boolean), link: Schema.optional( Schema.Struct({ url: TrimmedNonEmptyString, From 9ea58a3b3370d48d1c4f2da7f4b558d236ec52a4 Mon Sep 17 00:00:00 2001 From: Tibor Casteleijn Date: Thu, 19 Nov 2026 14:39:25 +0100 Subject: [PATCH 2/6] fix(server): keep PR watch pending seed across incomplete baselines A placeholder-bearing baseline read was clearing checksPending from visible checks, so the first complete read suppressed failures that never appeared as pending. Preserve the pending-at-start seed while awaitingBaseline remains. Co-authored-by: Cursor --- .../orchestration-v2/pullRequestWatch.test.ts | 23 +++++++++++++++++++ .../src/orchestration-v2/pullRequestWatch.ts | 5 ++++ 2 files changed, 28 insertions(+) diff --git a/apps/server/src/orchestration-v2/pullRequestWatch.test.ts b/apps/server/src/orchestration-v2/pullRequestWatch.test.ts index b24765f64496..705cdd91131c 100644 --- a/apps/server/src/orchestration-v2/pullRequestWatch.test.ts +++ b/apps/server/src/orchestration-v2/pullRequestWatch.test.ts @@ -240,6 +240,29 @@ describe("evaluatePullRequestWatch", () => { noRemarks, ); assert.deepEqual(laterGreen.changes, []); + + // Incomplete baseline (placeholder): keep the pending seed so the first complete read + // can still report a check that never appeared as pending. + const placeholder = { + ...check("Workflow approval status", "pending"), + placeholder: true as const, + }; + const incomplete = evaluatePullRequestWatch( + watch({ awaitingBaseline: "all", checksPending: true }), + detail({ checks: [check("lint", "success"), placeholder] }), + noRemarks, + ); + assert.deepEqual(incomplete.changes, []); + assert.equal(incomplete.next.awaitingBaseline, "checks"); + assert.isTrue(incomplete.next.checksPending); + const afterPlaceholder = evaluatePullRequestWatch( + incomplete.next, + detail({ checks: [check("lint", "success"), check("gated", "failure")] }), + noRemarks, + ); + assert.deepEqual(afterPlaceholder.changes, [ + { kind: "checks-failed", failed: [check("gated", "failure")] }, + ]); }); it("baselines checks already awaiting approval", () => { diff --git a/apps/server/src/orchestration-v2/pullRequestWatch.ts b/apps/server/src/orchestration-v2/pullRequestWatch.ts index 8ddfdf444c67..ec612d53c5bc 100644 --- a/apps/server/src/orchestration-v2/pullRequestWatch.ts +++ b/apps/server/src/orchestration-v2/pullRequestWatch.ts @@ -77,6 +77,11 @@ export function evaluatePullRequestWatch( if (checks.length > 0) { // A run awaiting approval waits on a person, like a review, so only running checks count. checksPending = checks.some((check) => check.status === "pending"); + // An incomplete baseline (placeholder) must keep the pending-at-start seed; otherwise the + // next complete read treats failures as already known and stays quiet. + if (checksBaseline && unread && watch.checksPending === true) { + checksPending = true; + } const newlyFailed = failed.filter((check) => !failedChecks.includes(check.name)); // Baseline suppresses failures that were already terminal when the watch started. A watch // seeded with checksPending (CI still running at watch_pull_request) must still report From 19d45d4e5319af8970d301b1109d312ae6a13020 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Nov 2026 13:45:13 +0000 Subject: [PATCH 3/6] fix(server): tighten PR watch baseline fix comments and tests Co-Authored-By: Claude Opus 5.5 --- .../src/orchestration-v2/Orchestrator.ts | 6 +-- .../orchestration-v2/pullRequestWatch.test.ts | 50 +++++-------------- .../src/orchestration-v2/pullRequestWatch.ts | 6 +-- .../PullRequestWatchService.test.ts | 28 +++++++---- .../pullRequest/PullRequestWatchService.ts | 10 ++-- packages/contracts/src/orchestrationV2.ts | 6 +-- 6 files changed, 40 insertions(+), 66 deletions(-) diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index 15d810a6d383..26e458939065 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -5254,10 +5254,8 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio ...(existing.endedWatch?.approvalAnnounced !== undefined && { approvalAnnounced: existing.endedWatch.approvalAnnounced, }), - // A finished-checks answer may be an older head's; a fresh read decides. - // Prefer the host rollup from watch_pull_request so a pending→failed race - // during the immediate baseline read still wakes; endedWatch only fills - // when that is absent. + // The rollup read at the start wins; a finished-checks answer kept from + // the last watch may be an older head's. ...(command.type === "thread.pull-request.watch" && command.checksPending !== undefined ? { checksPending: command.checksPending } diff --git a/apps/server/src/orchestration-v2/pullRequestWatch.test.ts b/apps/server/src/orchestration-v2/pullRequestWatch.test.ts index b24765f64496..b85e26fc25c6 100644 --- a/apps/server/src/orchestration-v2/pullRequestWatch.test.ts +++ b/apps/server/src/orchestration-v2/pullRequestWatch.test.ts @@ -190,26 +190,24 @@ describe("evaluatePullRequestWatch", () => { ]); }); - // Pending-at-start watches must report failures the baseline read returns; otherwise a - // host that flips to red during that read is baselined and never wakes. - it("reports failures when the baseline read returns red after a pending-at-start watch", () => { - const red = detail({ - checks: [check("lint", "failure"), check("test", "failure")], - }); - const reported = evaluatePullRequestWatch( + it("reports failures on the first read only when checks were running at the start", () => { + const red = detail({ checks: [check("lint", "failure"), check("test", "pending")] }); + const pending = evaluatePullRequestWatch( watch({ awaitingBaseline: "all", checksPending: true }), red, noRemarks, ); - assert.deepEqual(reported.changes, [ - { - kind: "checks-failed", - failed: [check("lint", "failure"), check("test", "failure")], - }, + assert.deepEqual(pending.changes, [ + { kind: "checks-failed", failed: [check("lint", "failure")] }, ]); - assert.isFalse(reported.next.checksPending); - - // Already terminal when the watch started: still baselined (no wake). + assert.deepEqual( + evaluatePullRequestWatch( + pending.next, + detail({ checks: [check("lint", "failure"), check("test", "success")] }), + noRemarks, + ).changes, + [], + ); assert.deepEqual( evaluatePullRequestWatch( watch({ awaitingBaseline: "all", checksPending: false }), @@ -218,28 +216,6 @@ describe("evaluatePullRequestWatch", () => { ).changes, [], ); - - // Partial settle on the first read: keep quiet until the rest finish, but do not lose the - // pending-start debt — a later all-green must still surface the earlier failure. - const partial = detail({ - checks: [check("lint", "failure"), check("test", "pending")], - }); - const waiting = evaluatePullRequestWatch( - watch({ awaitingBaseline: "all", checksPending: true }), - partial, - noRemarks, - ); - assert.deepEqual(waiting.changes, [ - { kind: "checks-failed", failed: [check("lint", "failure")] }, - ]); - assert.deepEqual(waiting.next.failedChecks, ["lint"]); - assert.isTrue(waiting.next.checksPending); - const laterGreen = evaluatePullRequestWatch( - waiting.next, - detail({ checks: [check("lint", "failure"), check("test", "success")] }), - noRemarks, - ); - assert.deepEqual(laterGreen.changes, []); }); it("baselines checks already awaiting approval", () => { diff --git a/apps/server/src/orchestration-v2/pullRequestWatch.ts b/apps/server/src/orchestration-v2/pullRequestWatch.ts index 8ddfdf444c67..729ae608cb04 100644 --- a/apps/server/src/orchestration-v2/pullRequestWatch.ts +++ b/apps/server/src/orchestration-v2/pullRequestWatch.ts @@ -78,10 +78,8 @@ export function evaluatePullRequestWatch( // A run awaiting approval waits on a person, like a review, so only running checks count. checksPending = checks.some((check) => check.status === "pending"); const newlyFailed = failed.filter((check) => !failedChecks.includes(check.name)); - // Baseline suppresses failures that were already terminal when the watch started. A watch - // seeded with checksPending (CI still running at watch_pull_request) must still report - // failures the baseline read returns — including when another check is still pending — - // otherwise a host that flips to red during the immediate start read never wakes. + // The baseline hides failures from before the watch, but CI running at the start can fail + // before the first read. if (newlyFailed.length > 0 && (!checksBaseline || watch.checksPending === true)) { changes.push({ kind: "checks-failed", failed: newlyFailed }); } diff --git a/apps/server/src/pullRequest/PullRequestWatchService.test.ts b/apps/server/src/pullRequest/PullRequestWatchService.test.ts index 2c4f4d92e469..5da99a43e8be 100644 --- a/apps/server/src/pullRequest/PullRequestWatchService.test.ts +++ b/apps/server/src/pullRequest/PullRequestWatchService.test.ts @@ -114,6 +114,7 @@ interface HarnessOptions { readonly project?: OrchestrationProjectShell | null; readonly readFailure?: PullRequestService.PullRequestError; readonly readState?: PullRequestSummary["state"]; + readonly readChecksState?: PullRequestSummary["checksState"]; } const makeHarness = Effect.fn("makePullRequestWatchHarness")(function* ( @@ -144,6 +145,9 @@ const makeHarness = Effect.fn("makePullRequestWatchHarness")(function* ( title: "Pull request", url: `https://github.com/${input.repository}/pull/${input.number}`, state: options.readState ?? "open", + ...(options.readChecksState !== undefined && { + checksState: options.readChecksState, + }), headBranch: "feature", baseBranch: "main", updatedAt: "2026-08-20T00:00:00.000Z", @@ -164,15 +168,20 @@ const makeHarness = Effect.fn("makePullRequestWatchHarness")(function* ( describe("PullRequestWatchService", () => { it.effect("links an unlinked watch even while the host has a transient read failure", () => Effect.gen(function* () { - for (const options of [ - {}, - { - readFailure: new PullRequestOperationError({ - operation: "summary", - detail: "The host is temporarily unavailable.", - }), - }, - ]) { + const cases: ReadonlyArray = [ + [{}, true], + [{ readChecksState: "failing" }, false], + [ + { + readFailure: new PullRequestOperationError({ + operation: "summary", + detail: "The host is temporarily unavailable.", + }), + }, + true, + ], + ]; + for (const [options, checksPending] of cases) { const harness = yield* makeHarness(options); const result = yield* harness.setWatching(true, { url: "https://github.com/t3tools/t3code/pull/9", @@ -183,6 +192,7 @@ describe("PullRequestWatchService", () => { type: "thread.pull-request.watch", number: 9, watching: true, + checksPending, link: { url: "https://github.com/t3tools/t3code/pull/9", source: "agent" }, }, ]); diff --git a/apps/server/src/pullRequest/PullRequestWatchService.ts b/apps/server/src/pullRequest/PullRequestWatchService.ts index f3f42ebf27bd..1829cf7ef0e0 100644 --- a/apps/server/src/pullRequest/PullRequestWatchService.ts +++ b/apps/server/src/pullRequest/PullRequestWatchService.ts @@ -126,8 +126,7 @@ const make = Effect.gen(function* () { if (watching && before?.snapshot?.state === "merged") { return yield* new PullRequestNotOpenError({ state: "merged" }); } - // When CI was still running (or the rollup was unread) at watch start, seed checksPending so - // a failure the immediate baseline read returns is reported instead of baselined away. + // CI running (or unknown) now may fail before the first read, which must still report it. let checksPendingAtStart: boolean | undefined; if (watching && before?.watch === undefined) { checksPendingAtStart = yield* pullRequests @@ -145,14 +144,11 @@ const make = Effect.gen(function* () { Effect.flatMap((summary) => summary.state === "merged" ? Effect.fail(new PullRequestNotOpenError({ state: "merged" })) - : Effect.succeed( - // Unknown rollup: prefer pending so a fast fail during the baseline read still wakes. - summary.checksState === "pending" || summary.checksState == null, - ), + : Effect.succeed(summary.checksState === "pending" || summary.checksState == null), ), Effect.catchTags({ // Host and transport errors can recover while the watch is active. - PullRequestOperationError: () => Effect.succeed(true as const), + PullRequestOperationError: () => Effect.succeed(true), }), ); } diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts index 75c8388750a2..415101ce32e3 100644 --- a/packages/contracts/src/orchestrationV2.ts +++ b/packages/contracts/src/orchestrationV2.ts @@ -3323,11 +3323,7 @@ export const OrchestrationV2Command = Schema.Union([ watching: Schema.Boolean, /** With `watching`, sets how long the watch holds its thread; absent keeps the current one. */ until: Schema.optional(PullRequestWatchUntil), - /** - * Host check rollup when the watch starts. `true` when CI was still running (or unknown); - * `false` when it had already passed or failed. Seeds `checksPending` so a failure the - * immediate baseline read returns is still news, not a silent baseline. - */ + /** Whether CI was running (or unknown) when the watch started, so its failures are news. */ checksPending: Schema.optional(Schema.Boolean), link: Schema.optional( Schema.Struct({ From 939f38917b7c960857b3e0d9f3dcdfab37417136 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Nov 2026 14:09:15 +0000 Subject: [PATCH 4/6] fix(server): seed client PR watch starts from the link's CI state Web, desktop and mobile dispatch thread.pull-request.watch without a fresh check read, so the orchestrator now falls back to the link's last synced checksState when the command carries none. Co-Authored-By: Claude Opus 5.5 --- .../src/orchestration-v2/Orchestrator.ts | 14 +++++----- .../src/orchestration-v2/runtimeLayer.test.ts | 27 +++++++++++++++++++ 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index 26e458939065..ba8454208abf 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -5254,14 +5254,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio ...(existing.endedWatch?.approvalAnnounced !== undefined && { approvalAnnounced: existing.endedWatch.approvalAnnounced, }), - // The rollup read at the start wins; a finished-checks answer kept from - // the last watch may be an older head's. - ...(command.type === "thread.pull-request.watch" && + // CI running at the start may fail before the first read, which must still + // report it. A caller's fresh read beats the link's last sync; a + // finished-checks answer kept from the last watch may be an older head's. + ...((command.type === "thread.pull-request.watch" && command.checksPending !== undefined - ? { checksPending: command.checksPending } - : existing.endedWatch?.checksPending === true - ? { checksPending: true } - : {}), + ? command.checksPending + : existing.snapshot?.checksState === "pending" || + existing.endedWatch?.checksPending === true) && { checksPending: true }), ...(existing.endedWatch?.checksAwaitedSince !== undefined && { checksAwaitedSince: existing.endedWatch.checksAwaitedSince, }), diff --git a/apps/server/src/orchestration-v2/runtimeLayer.test.ts b/apps/server/src/orchestration-v2/runtimeLayer.test.ts index 0fedb489f451..d61eb8315b88 100644 --- a/apps/server/src/orchestration-v2/runtimeLayer.test.ts +++ b/apps/server/src/orchestration-v2/runtimeLayer.test.ts @@ -4278,6 +4278,33 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { assert.isUndefined(yield* watchOf); const { messages } = yield* orchestrator.getThreadRecords(threadId, ["messages"]); assert.deepEqual(messages, []); + + // A client start sends no CI state, so the link's last sync seeds it. + yield* orchestrator.dispatch({ + type: "thread.pull-request-link.sync", + commandId: CommandId.make("pr-watch-ci-running"), + threadId, + ...key, + snapshot: { + state: "open", + title: "Watched pull request", + headBranch: "feature", + baseBranch: "main", + isDraft: false, + updatedAt: null, + syncedAt: "2026-10-02T12:30:00.000Z", + checksState: "pending", + }, + stack: null, + }); + yield* orchestrator.dispatch({ + type: "thread.pull-request.watch", + commandId: CommandId.make("pr-watch-client-start"), + threadId, + ...key, + watching: true, + }); + assert.isTrue((yield* watchOf)?.checksPending); }), ); From 02ddb454de62b3f712323be8c90316faa4ab31d1 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Nov 2026 14:15:57 +0000 Subject: [PATCH 5/6] fix(server): seed PR watches when a failing rollup may still be running A failing rollup is reported while other checks are pending, so only a passing one means CI finished before the watch started. Co-Authored-By: Claude Opus 5.5 --- apps/server/src/orchestration-v2/Orchestrator.ts | 7 ++++--- .../server/src/pullRequest/PullRequestWatchService.test.ts | 3 ++- apps/server/src/pullRequest/PullRequestWatchService.ts | 4 ++-- packages/contracts/src/orchestrationV2.ts | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index ba8454208abf..bd65abcafc43 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -5254,13 +5254,14 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio ...(existing.endedWatch?.approvalAnnounced !== undefined && { approvalAnnounced: existing.endedWatch.approvalAnnounced, }), - // CI running at the start may fail before the first read, which must still - // report it. A caller's fresh read beats the link's last sync; a - // finished-checks answer kept from the last watch may be an older head's. + // CI running at the start, which a failing rollup can still be, may fail + // before the first read. A caller's fresh read beats the link's last sync; + // a finished-checks answer kept from the last watch may be an older head's. ...((command.type === "thread.pull-request.watch" && command.checksPending !== undefined ? command.checksPending : existing.snapshot?.checksState === "pending" || + existing.snapshot?.checksState === "failing" || existing.endedWatch?.checksPending === true) && { checksPending: true }), ...(existing.endedWatch?.checksAwaitedSince !== undefined && { checksAwaitedSince: existing.endedWatch.checksAwaitedSince, diff --git a/apps/server/src/pullRequest/PullRequestWatchService.test.ts b/apps/server/src/pullRequest/PullRequestWatchService.test.ts index 5da99a43e8be..bca69d7cf1ef 100644 --- a/apps/server/src/pullRequest/PullRequestWatchService.test.ts +++ b/apps/server/src/pullRequest/PullRequestWatchService.test.ts @@ -170,7 +170,8 @@ describe("PullRequestWatchService", () => { Effect.gen(function* () { const cases: ReadonlyArray = [ [{}, true], - [{ readChecksState: "failing" }, false], + [{ readChecksState: "failing" }, true], + [{ readChecksState: "passing" }, false], [ { readFailure: new PullRequestOperationError({ diff --git a/apps/server/src/pullRequest/PullRequestWatchService.ts b/apps/server/src/pullRequest/PullRequestWatchService.ts index 1829cf7ef0e0..3473013a82c7 100644 --- a/apps/server/src/pullRequest/PullRequestWatchService.ts +++ b/apps/server/src/pullRequest/PullRequestWatchService.ts @@ -126,7 +126,7 @@ const make = Effect.gen(function* () { if (watching && before?.snapshot?.state === "merged") { return yield* new PullRequestNotOpenError({ state: "merged" }); } - // CI running (or unknown) now may fail before the first read, which must still report it. + // Only a passing rollup means CI finished; a failing one can still have checks running. let checksPendingAtStart: boolean | undefined; if (watching && before?.watch === undefined) { checksPendingAtStart = yield* pullRequests @@ -144,7 +144,7 @@ const make = Effect.gen(function* () { Effect.flatMap((summary) => summary.state === "merged" ? Effect.fail(new PullRequestNotOpenError({ state: "merged" })) - : Effect.succeed(summary.checksState === "pending" || summary.checksState == null), + : Effect.succeed(summary.checksState !== "passing"), ), Effect.catchTags({ // Host and transport errors can recover while the watch is active. diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts index 415101ce32e3..15bffeb1a09c 100644 --- a/packages/contracts/src/orchestrationV2.ts +++ b/packages/contracts/src/orchestrationV2.ts @@ -3323,7 +3323,7 @@ export const OrchestrationV2Command = Schema.Union([ watching: Schema.Boolean, /** With `watching`, sets how long the watch holds its thread; absent keeps the current one. */ until: Schema.optional(PullRequestWatchUntil), - /** Whether CI was running (or unknown) when the watch started, so its failures are news. */ + /** Whether CI may have been running when the watch started, so its failures are news. */ checksPending: Schema.optional(Schema.Boolean), link: Schema.optional( Schema.Struct({ From f78dad5bfa7ec71d13a629e6f64c0672c4a25208 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 19 Nov 2026 14:34:39 +0000 Subject: [PATCH 6/6] fix(server): seed PR watches only from a pending check rollup A failing rollup cannot tell failures from before the watch from ones that land before its first read, so seeding on it reported old failures as news. Only a pending rollup, which has no failure yet, seeds the watch; anything else keeps the quiet baseline. Co-Authored-By: Claude Opus 5.5 --- .../src/orchestration-v2/Orchestrator.ts | 7 +- .../orchestration-v2/pullRequestWatch.test.ts | 2 +- .../src/orchestration-v2/runtimeLayer.test.ts | 148 ++++++++++++++++++ .../PullRequestWatchService.test.ts | 18 ++- .../pullRequest/PullRequestWatchService.ts | 7 +- packages/contracts/src/orchestrationV2.ts | 2 +- 6 files changed, 168 insertions(+), 16 deletions(-) diff --git a/apps/server/src/orchestration-v2/Orchestrator.ts b/apps/server/src/orchestration-v2/Orchestrator.ts index bd65abcafc43..c1cd138c10a1 100644 --- a/apps/server/src/orchestration-v2/Orchestrator.ts +++ b/apps/server/src/orchestration-v2/Orchestrator.ts @@ -5254,14 +5254,13 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio ...(existing.endedWatch?.approvalAnnounced !== undefined && { approvalAnnounced: existing.endedWatch.approvalAnnounced, }), - // CI running at the start, which a failing rollup can still be, may fail - // before the first read. A caller's fresh read beats the link's last sync; - // a finished-checks answer kept from the last watch may be an older head's. + // CI pending with no failure yet at the start may fail before the first + // read. A caller's fresh read beats the link's last sync; a finished-checks + // answer kept from the last watch may be an older head's. ...((command.type === "thread.pull-request.watch" && command.checksPending !== undefined ? command.checksPending : existing.snapshot?.checksState === "pending" || - existing.snapshot?.checksState === "failing" || existing.endedWatch?.checksPending === true) && { checksPending: true }), ...(existing.endedWatch?.checksAwaitedSince !== undefined && { checksAwaitedSince: existing.endedWatch.checksAwaitedSince, diff --git a/apps/server/src/orchestration-v2/pullRequestWatch.test.ts b/apps/server/src/orchestration-v2/pullRequestWatch.test.ts index 8004121b7a30..78d5c42e9a6d 100644 --- a/apps/server/src/orchestration-v2/pullRequestWatch.test.ts +++ b/apps/server/src/orchestration-v2/pullRequestWatch.test.ts @@ -190,7 +190,7 @@ describe("evaluatePullRequestWatch", () => { ]); }); - it("reports failures on the first read only when checks were running at the start", () => { + it("reports failures on the first read only when CI was pending at the start", () => { const red = detail({ checks: [check("lint", "failure"), check("test", "pending")] }); const pending = evaluatePullRequestWatch( watch({ awaitingBaseline: "all", checksPending: true }), diff --git a/apps/server/src/orchestration-v2/runtimeLayer.test.ts b/apps/server/src/orchestration-v2/runtimeLayer.test.ts index d61eb8315b88..f7e6e03bb460 100644 --- a/apps/server/src/orchestration-v2/runtimeLayer.test.ts +++ b/apps/server/src/orchestration-v2/runtimeLayer.test.ts @@ -5246,6 +5246,154 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { }), ); + it.effect.each([ + // Failures from before the watch stay baseline, even with checks still running. + { + label: "finished failing", + atStart: "failing", + reads: [ + { lint: "failure", test: "success" }, + { lint: "failure", test: "success" }, + ], + told: [[], []], + }, + { + label: "failing and still running", + atStart: "failing", + reads: [ + { lint: "failure", test: "pending" }, + { lint: "failure", test: "failure" }, + ], + told: [[], ["test"]], + }, + // Pending CI had no failure, so one the first read finds landed after the start. + { + label: "pending", + atStart: "pending", + reads: [ + { lint: "failure", test: "pending" }, + { lint: "failure", test: "failure" }, + ], + told: [["lint"], ["test"]], + }, + ] as const)( + "reports only failures after a watch that starts on $label CI", + ({ label, atStart, reads, told }) => + Effect.gen(function* () { + const orchestrator = yield* Orchestrator.OrchestratorV2; + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; + const threadId = ThreadId.make(`runtime-pull-request-watch-start-${label}`); + const projectId = ProjectId.make("pr-watch-start-project"); + yield* seedProject({ + projectId, + title: "Watch start", + workspaceRoot: "/workspace/watch-start", + defaultModelSelection: null, + createdAt: "2026-10-01T00:00:00.000Z", + }); + yield* orchestrator.dispatch({ + type: "thread.create", + createdBy: "user", + creationSource: "web", + commandId: CommandId.make(`pr-watch-start-create-${label}`), + threadId, + projectId, + title: "Watch start", + modelSelection, + runtimeMode: "full-access", + interactionMode: "default", + branch: null, + worktreePath: null, + }); + const key = { host: "github.com", repository: "pingdotgg/t3code", number: 13 }; + yield* orchestrator.dispatch({ + type: "thread.pull-request.link", + commandId: CommandId.make(`pr-watch-start-link-${label}`), + threadId, + ...key, + url: "https://github.com/pingdotgg/t3code/pull/13", + source: "manual", + }); + yield* orchestrator.dispatch({ + type: "thread.pull-request-link.sync", + commandId: CommandId.make(`pr-watch-start-sync-${label}`), + threadId, + ...key, + snapshot: { + state: "open", + title: "Watched pull request", + headBranch: "feature", + baseBranch: "main", + isDraft: false, + updatedAt: null, + syncedAt: "2026-10-02T12:00:00.000Z", + checksState: atStart, + }, + stack: null, + }); + // A client start, which carries no CI state of its own. + yield* orchestrator.dispatch({ + type: "thread.pull-request.watch", + commandId: CommandId.make(`pr-watch-start-watch-${label}`), + threadId, + ...key, + watching: true, + }); + + let read = 0; + const host = Layer.mergeAll( + NodeServices.layer, + NodeCrypto.layer, + Layer.mock(PullRequestService.PullRequestService)({ + detail: () => + Effect.sync(() => ({ + ...watchedPullRequestDetail({ + projectId, + number: 13, + at: "2026-10-02T12:00:00.000Z", + }), + headSha: "ad70160aaa", + checks: Object.entries(reads[read]!).map(([name, status]) => ({ + name, + status, + description: null, + url: null, + })), + })), + activity: () => + Effect.succeed({ + comments: [], + commentCount: 0, + commentsTruncated: false, + reviewThreads: [], + commits: [], + }), + }), + ); + const texts = Effect.map( + orchestrator.getThreadRecords(threadId, ["messages"]), + ({ messages }) => messages.map((message) => message.text), + ); + const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host)); + for (const [index, names] of told.entries()) { + read = index; + const before = (yield* texts).length; + if (index > 0) yield* TestClock.adjust("10 minutes"); + yield* reactor.sweep; + yield* worker.drain(); + const wakes = (yield* texts).slice(before); + assert.equal(wakes.length, names.length === 0 ? 0 : 1); + for (const name of ["lint", "test"]) { + assert.equal( + wakes.some((text) => text.includes(` - ${name}`)), + names.includes(name as never), + `read ${index} told ${name}`, + ); + } + } + }), + ); + it.effect("baselines a new watch across restarts and reports later changes", () => Effect.gen(function* () { const orchestrator = yield* Orchestrator.OrchestratorV2; diff --git a/apps/server/src/pullRequest/PullRequestWatchService.test.ts b/apps/server/src/pullRequest/PullRequestWatchService.test.ts index bca69d7cf1ef..3aa614ed8f29 100644 --- a/apps/server/src/pullRequest/PullRequestWatchService.test.ts +++ b/apps/server/src/pullRequest/PullRequestWatchService.test.ts @@ -168,10 +168,10 @@ const makeHarness = Effect.fn("makePullRequestWatchHarness")(function* ( describe("PullRequestWatchService", () => { it.effect("links an unlinked watch even while the host has a transient read failure", () => Effect.gen(function* () { - const cases: ReadonlyArray = [ - [{}, true], - [{ readChecksState: "failing" }, true], - [{ readChecksState: "passing" }, false], + const cases: ReadonlyArray = [ + [{ readChecksState: "pending" }, true], + [{ readChecksState: "failing" }, false], + [{}, false], [ { readFailure: new PullRequestOperationError({ @@ -179,7 +179,7 @@ describe("PullRequestWatchService", () => { detail: "The host is temporarily unavailable.", }), }, - true, + undefined, ], ]; for (const [options, checksPending] of cases) { @@ -188,15 +188,19 @@ describe("PullRequestWatchService", () => { url: "https://github.com/t3tools/t3code/pull/9", }); expect(result).toMatchObject({ number: 9, wasWatching: false }); - expect(yield* Ref.get(harness.commands)).toMatchObject([ + const commands = yield* Ref.get(harness.commands); + expect(commands).toMatchObject([ { type: "thread.pull-request.watch", number: 9, watching: true, - checksPending, link: { url: "https://github.com/t3tools/t3code/pull/9", source: "agent" }, }, ]); + const [command] = commands; + expect(command?.type === "thread.pull-request.watch" ? command.checksPending : null).toBe( + checksPending, + ); } }), ); diff --git a/apps/server/src/pullRequest/PullRequestWatchService.ts b/apps/server/src/pullRequest/PullRequestWatchService.ts index 3473013a82c7..b38075baeb7b 100644 --- a/apps/server/src/pullRequest/PullRequestWatchService.ts +++ b/apps/server/src/pullRequest/PullRequestWatchService.ts @@ -126,7 +126,7 @@ const make = Effect.gen(function* () { if (watching && before?.snapshot?.state === "merged") { return yield* new PullRequestNotOpenError({ state: "merged" }); } - // Only a passing rollup means CI finished; a failing one can still have checks running. + // A pending rollup has no failure yet, so any failure the first read finds is news. let checksPendingAtStart: boolean | undefined; if (watching && before?.watch === undefined) { checksPendingAtStart = yield* pullRequests @@ -144,11 +144,12 @@ const make = Effect.gen(function* () { Effect.flatMap((summary) => summary.state === "merged" ? Effect.fail(new PullRequestNotOpenError({ state: "merged" })) - : Effect.succeed(summary.checksState !== "passing"), + : Effect.succeed(summary.checksState === "pending"), ), Effect.catchTags({ // Host and transport errors can recover while the watch is active. - PullRequestOperationError: () => Effect.succeed(true), + // A failed read leaves the seed to the link's last sync. + PullRequestOperationError: () => Effect.undefined, }), ); } diff --git a/packages/contracts/src/orchestrationV2.ts b/packages/contracts/src/orchestrationV2.ts index 15bffeb1a09c..f914656a202b 100644 --- a/packages/contracts/src/orchestrationV2.ts +++ b/packages/contracts/src/orchestrationV2.ts @@ -3323,7 +3323,7 @@ export const OrchestrationV2Command = Schema.Union([ watching: Schema.Boolean, /** With `watching`, sets how long the watch holds its thread; absent keeps the current one. */ until: Schema.optional(PullRequestWatchUntil), - /** Whether CI may have been running when the watch started, so its failures are news. */ + /** Whether CI was pending with no failure yet when the watch started, so any failure is news. */ checksPending: Schema.optional(Schema.Boolean), link: Schema.optional( Schema.Struct({