From 5c7271bc2cfe6424fbe54a37a65a08a1c846b5f8 Mon Sep 17 00:00:00 2001 From: kumar-karan <93268009+kumar-karan@users.noreply.github.com> Date: Mon, 16 Nov 2026 10:33:36 +0530 Subject: [PATCH 1/5] fix(server): a watch without a live feed hears pending checks before the sweep A watched pull request whose host has no event feed only noticed concluded checks on the next 2-minute sweep. Between sweeps, the reactor now probes the watches whose last read saw checks pending with one fingerprint query each, and the targeted read that already exists for host events runs when the fingerprint moved. Fixes #37477 --- .../PullRequestWatchReactor.ts | 22 ++++ .../src/orchestration-v2/runtimeLayer.test.ts | 111 ++++++++++++++++++ 2 files changed, 133 insertions(+) diff --git a/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts b/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts index 5b69a7efa3377..ad9d483d8c3a5 100644 --- a/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts +++ b/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts @@ -46,6 +46,8 @@ import { /** Checks take minutes; faster sweeps waste the account's shared host quota. */ const SWEEP_MINUTES = 2; +/** Between sweeps, pending checks get a fingerprint probe this often; a full read only follows a change. */ +const PENDING_PROBE_MS = 30_000; const READ_FAILURE_LIMIT = 8; /** Group reads in flight at once, inside the host's own request limit. */ const GROUP_READS = 4; @@ -839,6 +841,17 @@ export const make = Effect.gen(function* () { Effect.withSpan("PullRequestWatchReactor.readOnChange"), ); + /** Targeted reads for the watches whose last read saw checks or mergeability still pending. */ + const probePending = Effect.suspend(() => + Effect.forEach( + currentGroups + .filter((group) => lastReads.get(group.key)?.inFlight === true) + .map(pullRequestOf), + readOnChange, + { concurrency: "unbounded", discard: true }, + ), + ); + const start: PullRequestWatchReactor["Service"]["start"] = Effect.fn( "PullRequestWatchReactor.start", )(function* () { @@ -870,6 +883,15 @@ export const make = Effect.gen(function* () { Effect.asVoid, ), ); + // A host without a live feed leaves the sweep as the only reader, so a pending watch + // would wait the whole sweep for its checks; the probes catch the conclusion sooner. + yield* forkParked( + Effect.sleep(PENDING_PROBE_MS).pipe( + Effect.andThen(probePending), + Effect.repeat(Schedule.spaced(PENDING_PROBE_MS)), + Effect.asVoid, + ), + ); }); return { start, sweep } satisfies PullRequestWatchReactor["Service"]; diff --git a/apps/server/src/orchestration-v2/runtimeLayer.test.ts b/apps/server/src/orchestration-v2/runtimeLayer.test.ts index 0614a14861abd..b0f86b8907a34 100644 --- a/apps/server/src/orchestration-v2/runtimeLayer.test.ts +++ b/apps/server/src/orchestration-v2/runtimeLayer.test.ts @@ -5779,6 +5779,117 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { }), ); + it.effect("wakes pending checks from the interim probe when the host has no live feed", () => + Effect.gen(function* () { + const orchestrator = yield* Orchestrator.OrchestratorV2; + const threadId = ThreadId.make("runtime-pull-request-watch-probe"); + const projectId = ProjectId.make("pr-watch-probe-project"); + yield* seedProject({ + projectId, + title: "Watch probe", + workspaceRoot: "/workspace/watch-probe", + defaultModelSelection: null, + createdAt: "2026-10-01T00:00:00.000Z", + }); + yield* orchestrator.dispatch({ + type: "thread.create", + createdBy: "user", + creationSource: "web", + commandId: CommandId.make("pr-watch-probe-create"), + threadId, + projectId, + title: "Watch probe", + modelSelection, + runtimeMode: "full-access", + interactionMode: "default", + branch: null, + worktreePath: null, + }); + const key = { host: "github.com", repository: "pingdotgg/t3code", number: 14 }; + yield* orchestrator.dispatch({ + type: "thread.pull-request.watch", + commandId: CommandId.make("pr-watch-probe-start"), + threadId, + ...key, + watching: true, + link: { url: "https://github.com/pingdotgg/t3code/pull/14", source: "agent" }, + }); + + let checks: PullRequestDetail["checks"] = [ + { name: "lint", status: "pending", description: null, url: null, required: true }, + ]; + let status = "pending"; + const detailReads = yield* Queue.unbounded(); + const host = Layer.mergeAll( + NodeServices.layer, + NodeCrypto.layer, + Layer.mock(PullRequestService.PullRequestService)({ + detail: () => + Queue.offer(detailReads, undefined).pipe( + Effect.as({ + ...watchedPullRequestDetail({ + projectId, + number: 14, + at: "2026-10-02T12:00:00.000Z", + }), + headSha: "6074dd48ff", + checks, + }), + ), + activity: () => + Effect.succeed({ + comments: [], + commentCount: 0, + commentsTruncated: false, + reviewThreads: [], + commits: [], + }), + watchFingerprint: () => Effect.sync(() => ({ status, remarks: "none" })), + invalidate: () => Effect.void, + // Without the GitHub app sign-in no feed is on, so only the sweep hears checks. + changes: () => Stream.empty, + }), + ); + const wakes = Effect.map( + orchestrator.getThreadRecords(threadId, ["messages"]), + ({ messages }) => + messages.filter( + (message) => message.notification !== undefined && message.notification !== null, + ), + ); + const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host)); + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; + yield* reactor.start(); + yield* Queue.take(detailReads); + yield* worker.drain(); + assert.lengthOf(yield* wakes, 0); + + status = "passed"; + checks = [{ name: "lint", status: "success", description: null, url: null, required: true }]; + // The probe must hear the concluded checks long before the 2-minute sweep could. + yield* TestClock.adjust("30 seconds"); + yield* Queue.take(detailReads); + yield* worker.drain(); + const woken = yield* wakes; + assert.lengthOf(woken, 1); + assert.equal(woken[0]!.notification?.summary, "#14: checks passed"); + + // The settled pull request stays quiet until the sweep. + yield* TestClock.adjust("30 seconds"); + yield* worker.drain(); + assert.lengthOf(yield* wakes, 1); + + yield* orchestrator.dispatch({ + type: "thread.pull-request.watch", + commandId: CommandId.make("pr-watch-probe-end"), + threadId, + ...key, + watching: false, + }); + yield* worker.drain(); + }), + ); + // regression: #21155 watching a pull request again repeated news the thread already got it.effect("watching a dismissed stack layer again keeps what its last watch told", () => Effect.gen(function* () { From a2db84a49a0326a0ad709f39157bf97859fb7735 Mon Sep 17 00:00:00 2001 From: kumar-karan <93268009+kumar-karan@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:04:37 +0530 Subject: [PATCH 2/5] fix(orchestration): fix probe cadence and dedupe probe passes across projects --- .../PullRequestWatchReactor.ts | 16 +- .../src/orchestration-v2/runtimeLayer.test.ts | 140 +++++++++++++++++- 2 files changed, 148 insertions(+), 8 deletions(-) diff --git a/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts b/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts index ad9d483d8c3a5..bc1cc5f968b96 100644 --- a/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts +++ b/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts @@ -841,12 +841,17 @@ export const make = Effect.gen(function* () { Effect.withSpan("PullRequestWatchReactor.readOnChange"), ); - /** Targeted reads for the watches whose last read saw checks or mergeability still pending. */ + /** Targeted reads for the watches whose last read saw checks or mergeability still pending. One + * pass per pull request covers every project watching it. */ const probePending = Effect.suspend(() => Effect.forEach( - currentGroups - .filter((group) => lastReads.get(group.key)?.inFlight === true) - .map(pullRequestOf), + [ + ...new Set( + currentGroups + .filter((group) => lastReads.get(group.key)?.inFlight === true) + .map(pullRequestOf), + ), + ], readOnChange, { concurrency: "unbounded", discard: true }, ), @@ -887,8 +892,7 @@ export const make = Effect.gen(function* () { // would wait the whole sweep for its checks; the probes catch the conclusion sooner. yield* forkParked( Effect.sleep(PENDING_PROBE_MS).pipe( - Effect.andThen(probePending), - Effect.repeat(Schedule.spaced(PENDING_PROBE_MS)), + Effect.andThen(probePending.pipe(Effect.repeat(Schedule.spaced(PENDING_PROBE_MS)))), Effect.asVoid, ), ); diff --git a/apps/server/src/orchestration-v2/runtimeLayer.test.ts b/apps/server/src/orchestration-v2/runtimeLayer.test.ts index b0f86b8907a34..f9bf08ea2681c 100644 --- a/apps/server/src/orchestration-v2/runtimeLayer.test.ts +++ b/apps/server/src/orchestration-v2/runtimeLayer.test.ts @@ -5824,8 +5824,12 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { NodeServices.layer, NodeCrypto.layer, Layer.mock(PullRequestService.PullRequestService)({ - detail: () => - Queue.offer(detailReads, undefined).pipe( + detail: (input) => + // Watches left by earlier cases in this layer are swept too. + (input.projectId === projectId + ? Queue.offer(detailReads, undefined) + : Effect.void + ).pipe( Effect.as({ ...watchedPullRequestDetail({ projectId, @@ -5864,6 +5868,13 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { yield* worker.drain(); assert.lengthOf(yield* wakes, 0); + // The probes keep coming every 30 seconds while the checks stay pending. + yield* TestClock.adjust("30 seconds"); + yield* Queue.take(detailReads); + yield* TestClock.adjust("30 seconds"); + yield* Queue.take(detailReads); + assert.lengthOf(yield* wakes, 0); + status = "passed"; checks = [{ name: "lint", status: "success", description: null, url: null, required: true }]; // The probe must hear the concluded checks long before the 2-minute sweep could. @@ -5890,6 +5901,131 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { }), ); + it.effect("probes a pull request watched from two projects once", () => + Effect.gen(function* () { + const orchestrator = yield* Orchestrator.OrchestratorV2; + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; + const projects = [ + { + threadId: ThreadId.make("runtime-pull-request-watch-probe-dedupe-a"), + projectId: ProjectId.make("pr-watch-probe-dedupe-project-a"), + }, + { + threadId: ThreadId.make("runtime-pull-request-watch-probe-dedupe-b"), + projectId: ProjectId.make("pr-watch-probe-dedupe-project-b"), + }, + ]; + for (const [index, { projectId, threadId }] of projects.entries()) { + yield* seedProject({ + projectId, + title: `Watch probe ${index}`, + workspaceRoot: `/workspace/watch-probe-${index}`, + defaultModelSelection: null, + createdAt: "2026-10-01T00:00:00.000Z", + }); + yield* orchestrator.dispatch({ + type: "thread.create", + createdBy: "user", + creationSource: "web", + commandId: CommandId.make(`pr-watch-probe-dedupe-create-${index}`), + threadId, + projectId, + title: `Watch probe ${index}`, + modelSelection, + runtimeMode: "full-access", + interactionMode: "default", + branch: null, + worktreePath: null, + }); + yield* orchestrator.dispatch({ + type: "thread.pull-request.watch", + commandId: CommandId.make(`pr-watch-probe-dedupe-start-${index}`), + threadId, + host: "github.com", + repository: "pingdotgg/t3code", + number: 14, + watching: true, + link: { url: "https://github.com/pingdotgg/t3code/pull/14", source: "agent" }, + }); + } + + const checks = [ + { name: "lint", status: "pending", description: null, url: null, required: true }, + ] as const; + const detailReads = yield* Queue.unbounded(); + const fingerprintReads = yield* Queue.unbounded(); + let fingerprints = 0; + const mine = (projectId: ProjectId) => + projects.some((project) => project.projectId === projectId); + const host = Layer.mergeAll( + NodeServices.layer, + NodeCrypto.layer, + Layer.mock(PullRequestService.PullRequestService)({ + detail: (input) => + // Watches left by earlier cases in this layer are swept too. + (mine(input.projectId) ? Queue.offer(detailReads, undefined) : Effect.void).pipe( + Effect.as({ + ...watchedPullRequestDetail({ + projectId: input.projectId, + number: 14, + at: "2026-10-02T12:00:00.000Z", + }), + headSha: "6074dd48ff", + checks, + }), + ), + activity: () => + Effect.succeed({ + comments: [], + commentCount: 0, + commentsTruncated: false, + reviewThreads: [], + commits: [], + }), + watchFingerprint: (input) => + Effect.sync(() => ({ status: "pending", remarks: "none" })).pipe( + Effect.tap(() => + mine(input.projectId) + ? Effect.sync(() => void fingerprints++).pipe( + Effect.andThen(Queue.offer(fingerprintReads, undefined)), + ) + : Effect.void, + ), + ), + invalidate: () => Effect.void, + changes: () => Stream.empty, + }), + ); + const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host)); + yield* reactor.start(); + // The first sweep reads both project groups. + yield* Queue.take(detailReads); + yield* Queue.take(detailReads); + yield* worker.drain(); + // One probe pass fingerprints each group once; a repeat pass per tick would double it. + yield* TestClock.adjust("30 seconds"); + yield* Queue.take(fingerprintReads); + yield* Queue.take(fingerprintReads); + yield* TestClock.adjust("30 seconds"); + yield* Queue.take(fingerprintReads); + yield* Queue.take(fingerprintReads); + assert.equal(fingerprints, 6); + + for (const [index, { threadId }] of projects.entries()) { + yield* orchestrator.dispatch({ + type: "thread.pull-request.watch", + commandId: CommandId.make(`pr-watch-probe-dedupe-end-${index}`), + threadId, + host: "github.com", + repository: "pingdotgg/t3code", + number: 14, + watching: false, + }); + } + yield* worker.drain(); + }), + ); + // regression: #21155 watching a pull request again repeated news the thread already got it.effect("watching a dismissed stack layer again keeps what its last watch told", () => Effect.gen(function* () { From 998973a7ee5c92a6caf71bf6ce806c0b2d887e1e Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 16 Nov 2026 05:57:27 +0000 Subject: [PATCH 3/5] fix(server): pending probes read only after the fingerprint moves, every 30s The probe ran a full pass for each pending watch, and planRead treats a pending last read as reason enough for a detail read whenever the fingerprint does not cover detail (GitHub) or is absent (no-fingerprint hosts, which also reread activity). Every probe was a full read. It now asks only for the fingerprint, reads on a status or remarks move, and skips hosts without fingerprints. The repeat also reran the initial sleep on top of Schedule.spaced, so probes came every 60s, not 30s. Co-Authored-By: Claude Opus 5.5 --- .../PullRequestWatchReactor.ts | 30 +++++++++++-------- .../src/orchestration-v2/runtimeLayer.test.ts | 20 +++++++++++-- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts b/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts index ad9d483d8c3a5..b94a934dab788 100644 --- a/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts +++ b/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts @@ -841,13 +841,25 @@ export const make = Effect.gen(function* () { Effect.withSpan("PullRequestWatchReactor.readOnChange"), ); - /** Targeted reads for the watches whose last read saw checks or mergeability still pending. */ + // Hosts without fingerprints are left to the sweep, since every probe there would be a full read. const probePending = Effect.suspend(() => Effect.forEach( - currentGroups - .filter((group) => lastReads.get(group.key)?.inFlight === true) - .map(pullRequestOf), - readOnChange, + currentGroups.filter((group) => { + const last = lastReads.get(group.key); + return last?.inFlight === true && last.status !== null; + }), + (group) => + fingerprintOf(group).pipe( + Effect.flatMap((fingerprint) => { + const last = lastReads.get(group.key); + return fingerprint !== null && + fingerprint !== "paused" && + last !== undefined && + (last.status !== fingerprint.status || last.remarks !== fingerprint.remarks) + ? readOnChange(pullRequestOf(group)) + : Effect.void; + }), + ), { concurrency: "unbounded", discard: true }, ), ); @@ -885,13 +897,7 @@ export const make = Effect.gen(function* () { ); // A host without a live feed leaves the sweep as the only reader, so a pending watch // would wait the whole sweep for its checks; the probes catch the conclusion sooner. - yield* forkParked( - Effect.sleep(PENDING_PROBE_MS).pipe( - Effect.andThen(probePending), - Effect.repeat(Schedule.spaced(PENDING_PROBE_MS)), - Effect.asVoid, - ), - ); + yield* forkParked(probePending.pipe(Effect.delay(PENDING_PROBE_MS), Effect.forever)); }); return { start, sweep } satisfies PullRequestWatchReactor["Service"]; diff --git a/apps/server/src/orchestration-v2/runtimeLayer.test.ts b/apps/server/src/orchestration-v2/runtimeLayer.test.ts index b0f86b8907a34..b134c2664d87d 100644 --- a/apps/server/src/orchestration-v2/runtimeLayer.test.ts +++ b/apps/server/src/orchestration-v2/runtimeLayer.test.ts @@ -5820,12 +5820,17 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { ]; let status = "pending"; const detailReads = yield* Queue.unbounded(); + const fingerprintReads = yield* Queue.unbounded(); const host = Layer.mergeAll( NodeServices.layer, NodeCrypto.layer, Layer.mock(PullRequestService.PullRequestService)({ - detail: () => - Queue.offer(detailReads, undefined).pipe( + // Earlier cases' watches share this host, so only this project's reads count. + detail: (input) => + (input.projectId === projectId + ? Queue.offer(detailReads, undefined) + : Effect.void + ).pipe( Effect.as({ ...watchedPullRequestDetail({ projectId, @@ -5844,7 +5849,11 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { reviewThreads: [], commits: [], }), - watchFingerprint: () => Effect.sync(() => ({ status, remarks: "none" })), + watchFingerprint: (input) => + (input.projectId === projectId + ? Queue.offer(fingerprintReads, undefined) + : Effect.void + ).pipe(Effect.andThen(Effect.sync(() => ({ status, remarks: "none" })))), invalidate: () => Effect.void, // Without the GitHub app sign-in no feed is on, so only the sweep hears checks. changes: () => Stream.empty, @@ -5860,10 +5869,14 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host)); const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; yield* reactor.start(); + yield* Queue.take(fingerprintReads); yield* Queue.take(detailReads); yield* worker.drain(); assert.lengthOf(yield* wakes, 0); + // A probe whose fingerprint has not moved reads nothing more. + yield* TestClock.adjust("30 seconds"); + yield* Queue.take(fingerprintReads); status = "passed"; checks = [{ name: "lint", status: "success", description: null, url: null, required: true }]; // The probe must hear the concluded checks long before the 2-minute sweep could. @@ -5873,6 +5886,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { const woken = yield* wakes; assert.lengthOf(woken, 1); assert.equal(woken[0]!.notification?.summary, "#14: checks passed"); + assert.equal(yield* Queue.size(detailReads), 0); // The settled pull request stays quiet until the sweep. yield* TestClock.adjust("30 seconds"); From 5a4242bd9566bd1f94551c640f34f1bcabb3ff3a Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 16 Nov 2026 15:55:45 +0000 Subject: [PATCH 4/5] test(server): keep the probe regression case, drop the exact-count dedupe case Co-Authored-By: Claude Opus 5.5 --- .../src/orchestration-v2/runtimeLayer.test.ts | 134 ------------------ 1 file changed, 134 deletions(-) diff --git a/apps/server/src/orchestration-v2/runtimeLayer.test.ts b/apps/server/src/orchestration-v2/runtimeLayer.test.ts index cc2fe0bff5847..82bf9d4816a80 100644 --- a/apps/server/src/orchestration-v2/runtimeLayer.test.ts +++ b/apps/server/src/orchestration-v2/runtimeLayer.test.ts @@ -5904,140 +5904,6 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { }), ); - it.effect("probes a pull request watched from two projects once", () => - Effect.gen(function* () { - const orchestrator = yield* Orchestrator.OrchestratorV2; - const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; - const projects = [ - { - threadId: ThreadId.make("runtime-pull-request-watch-probe-dedupe-a"), - projectId: ProjectId.make("pr-watch-probe-dedupe-project-a"), - }, - { - threadId: ThreadId.make("runtime-pull-request-watch-probe-dedupe-b"), - projectId: ProjectId.make("pr-watch-probe-dedupe-project-b"), - }, - ]; - for (const [index, { projectId, threadId }] of projects.entries()) { - yield* seedProject({ - projectId, - title: `Watch probe ${index}`, - workspaceRoot: `/workspace/watch-probe-${index}`, - defaultModelSelection: null, - createdAt: "2026-10-01T00:00:00.000Z", - }); - yield* orchestrator.dispatch({ - type: "thread.create", - createdBy: "user", - creationSource: "web", - commandId: CommandId.make(`pr-watch-probe-dedupe-create-${index}`), - threadId, - projectId, - title: `Watch probe ${index}`, - modelSelection, - runtimeMode: "full-access", - interactionMode: "default", - branch: null, - worktreePath: null, - }); - yield* orchestrator.dispatch({ - type: "thread.pull-request.watch", - commandId: CommandId.make(`pr-watch-probe-dedupe-start-${index}`), - threadId, - host: "github.com", - repository: "pingdotgg/t3code", - number: 14, - watching: true, - link: { url: "https://github.com/pingdotgg/t3code/pull/14", source: "agent" }, - }); - } - - const checks = [ - { name: "lint", status: "pending", description: null, url: null, required: true }, - ] as const; - let status = "pending"; - const detailReads = yield* Queue.unbounded(); - const fingerprintReads = yield* Queue.unbounded(); - let details = 0; - let fingerprints = 0; - const mine = (projectId: ProjectId) => - projects.some((project) => project.projectId === projectId); - const host = Layer.mergeAll( - NodeServices.layer, - NodeCrypto.layer, - Layer.mock(PullRequestService.PullRequestService)({ - detail: (input) => - // Watches left by earlier cases in this layer are swept too. - (mine(input.projectId) - ? Effect.sync(() => void details++).pipe( - Effect.andThen(Queue.offer(detailReads, undefined)), - ) - : Effect.void - ).pipe( - Effect.as({ - ...watchedPullRequestDetail({ - projectId: input.projectId, - number: 14, - at: "2026-10-02T12:00:00.000Z", - }), - headSha: "6074dd48ff", - checks, - }), - ), - activity: () => - Effect.succeed({ - comments: [], - commentCount: 0, - commentsTruncated: false, - reviewThreads: [], - commits: [], - }), - watchFingerprint: (input) => - Effect.sync(() => ({ status, remarks: "none" })).pipe( - Effect.tap(() => - mine(input.projectId) - ? Effect.sync(() => void fingerprints++).pipe( - Effect.andThen(Queue.offer(fingerprintReads, undefined)), - ) - : Effect.void, - ), - ), - invalidate: () => Effect.void, - changes: () => Stream.empty, - }), - ); - const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host)); - yield* reactor.start(); - // The first sweep reads both project groups. - yield* Queue.take(detailReads); - yield* Queue.take(detailReads); - yield* worker.drain(); - // The host moves but the checks stay pending, so a second pass would read both again. - status = "running"; - yield* TestClock.adjust("30 seconds"); - yield* Queue.take(detailReads); - yield* Queue.take(detailReads); - yield* TestClock.adjust("30 seconds"); - // Sweep, probe, the one pass and the next quiet probe each fingerprint both groups. - for (let read = 0; read < 8; read++) yield* Queue.take(fingerprintReads); - assert.equal(fingerprints, 8); - assert.equal(details, 4); - - for (const [index, { threadId }] of projects.entries()) { - yield* orchestrator.dispatch({ - type: "thread.pull-request.watch", - commandId: CommandId.make(`pr-watch-probe-dedupe-end-${index}`), - threadId, - host: "github.com", - repository: "pingdotgg/t3code", - number: 14, - watching: false, - }); - } - yield* worker.drain(); - }), - ); - // regression: #21155 watching a pull request again repeated news the thread already got it.effect("watching a dismissed stack layer again keeps what its last watch told", () => Effect.gen(function* () { From ecb5d5aea7e894bb22b78ba306a766d5c066d811 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 16 Nov 2026 17:53:16 +0000 Subject: [PATCH 5/5] fix(server): probe watches whose head has no checks registered yet A freshly pushed head reads with no checks, so the last read was not in flight and the probe skipped it: checks that registered and finished inside one sweep still waited for the sweep. The probe now also covers any watch the evaluator still counts as waiting on checks. Co-Authored-By: Claude Opus 5.5 --- .../PullRequestWatchReactor.ts | 13 +- .../src/orchestration-v2/runtimeLayer.test.ts | 238 +++++++++--------- 2 files changed, 133 insertions(+), 118 deletions(-) diff --git a/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts b/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts index 8c5f192d13309..27eb6c73f7814 100644 --- a/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts +++ b/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts @@ -90,6 +90,8 @@ interface LastRead { readonly at: number; readonly fingerprint: string; readonly inFlight: boolean; + /** Some watch still waits on checks, including a head whose checks have not registered yet. */ + readonly checksPending: boolean; readonly remarksComplete: boolean; readonly watches: ReadonlySet; readonly status: string | null; @@ -683,6 +685,12 @@ export const make = Effect.gen(function* () { fingerprint === null ? QUIET_REREAD_MS : FINGERPRINT_REREAD_MS, ) : null; + const reports = new Map( + group.targets.map((target) => [ + target, + evaluatePullRequestWatch(target.watch, detail, remarks, now), + ]), + ); lastReads.set(group.key, { at: plan.activity || last === undefined @@ -692,13 +700,14 @@ export const make = Effect.gen(function* () { inFlight: detail.mergeability === "unknown" || detail.checks.some((check) => check.status === "pending"), + checksPending: [...reports.values()].some((report) => report.next.checksPending === true), remarksComplete: plan.activity ? remarks !== null : (last?.remarksComplete ?? false), watches: new Set(group.targets.map(watchKey)), status: fingerprint?.status ?? null, remarks: fingerprint?.remarks ?? null, }); yield* eachTarget(group, (target) => { - const report = evaluatePullRequestWatch(target.watch, detail, remarks, now); + const report = reports.get(target)!; if (report.changes.length > 0) { const wake = { ...pullRequestWatchMessage({ @@ -848,7 +857,7 @@ export const make = Effect.gen(function* () { yield* Effect.forEach( currentGroups.filter((group) => { const last = lastReads.get(group.key); - return last?.inFlight === true && last.status !== null; + return last !== undefined && (last.inFlight || last.checksPending) && last.status !== null; }), (group) => fingerprintOf(group).pipe( diff --git a/apps/server/src/orchestration-v2/runtimeLayer.test.ts b/apps/server/src/orchestration-v2/runtimeLayer.test.ts index 82bf9d4816a80..2562cafd7b19f 100644 --- a/apps/server/src/orchestration-v2/runtimeLayer.test.ts +++ b/apps/server/src/orchestration-v2/runtimeLayer.test.ts @@ -5779,129 +5779,135 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { }), ); - it.effect("wakes pending checks from the interim probe when the host has no live feed", () => - Effect.gen(function* () { - const orchestrator = yield* Orchestrator.OrchestratorV2; - const threadId = ThreadId.make("runtime-pull-request-watch-probe"); - const projectId = ProjectId.make("pr-watch-probe-project"); - yield* seedProject({ - projectId, - title: "Watch probe", - workspaceRoot: "/workspace/watch-probe", - defaultModelSelection: null, - createdAt: "2026-10-01T00:00:00.000Z", - }); - yield* orchestrator.dispatch({ - type: "thread.create", - createdBy: "user", - creationSource: "web", - commandId: CommandId.make("pr-watch-probe-create"), - threadId, - projectId, - title: "Watch probe", - modelSelection, - runtimeMode: "full-access", - interactionMode: "default", - branch: null, - worktreePath: null, - }); - const key = { host: "github.com", repository: "pingdotgg/t3code", number: 14 }; - yield* orchestrator.dispatch({ - type: "thread.pull-request.watch", - commandId: CommandId.make("pr-watch-probe-start"), - threadId, - ...key, - watching: true, - link: { url: "https://github.com/pingdotgg/t3code/pull/14", source: "agent" }, - }); + // A fresh head has no checks yet; the watch waits for them all the same. + it.effect.each(["pending", "not yet registered"] as const)( + "wakes %s checks from the interim probe when the host has no live feed", + (start) => + Effect.gen(function* () { + const orchestrator = yield* Orchestrator.OrchestratorV2; + const threadId = ThreadId.make(`runtime-pull-request-watch-probe-${start}`); + const projectId = ProjectId.make(`pr-watch-probe-project-${start}`); + yield* seedProject({ + projectId, + title: "Watch probe", + workspaceRoot: "/workspace/watch-probe", + defaultModelSelection: null, + createdAt: "2026-10-01T00:00:00.000Z", + }); + yield* orchestrator.dispatch({ + type: "thread.create", + createdBy: "user", + creationSource: "web", + commandId: CommandId.make(`pr-watch-probe-create-${start}`), + threadId, + projectId, + title: "Watch probe", + modelSelection, + runtimeMode: "full-access", + interactionMode: "default", + branch: null, + worktreePath: null, + }); + const key = { host: "github.com", repository: "pingdotgg/t3code", number: 14 }; + yield* orchestrator.dispatch({ + type: "thread.pull-request.watch", + commandId: CommandId.make(`pr-watch-probe-start-${start}`), + threadId, + ...key, + watching: true, + link: { url: "https://github.com/pingdotgg/t3code/pull/14", source: "agent" }, + }); - let checks: PullRequestDetail["checks"] = [ - { name: "lint", status: "pending", description: null, url: null, required: true }, - ]; - let status = "pending"; - const detailReads = yield* Queue.unbounded(); - const fingerprintReads = yield* Queue.unbounded(); - const host = Layer.mergeAll( - NodeServices.layer, - NodeCrypto.layer, - Layer.mock(PullRequestService.PullRequestService)({ - detail: (input) => - // Watches left by earlier cases in this layer are swept too. - (input.projectId === projectId - ? Queue.offer(detailReads, undefined) - : Effect.void - ).pipe( - Effect.as({ - ...watchedPullRequestDetail({ - projectId, - number: 14, - at: "2026-10-02T12:00:00.000Z", + let checks: PullRequestDetail["checks"] = + start === "pending" + ? [{ name: "lint", status: "pending", description: null, url: null, required: true }] + : []; + let status: string = start; + const detailReads = yield* Queue.unbounded(); + const fingerprintReads = yield* Queue.unbounded(); + const host = Layer.mergeAll( + NodeServices.layer, + NodeCrypto.layer, + Layer.mock(PullRequestService.PullRequestService)({ + detail: (input) => + // Watches left by earlier cases in this layer are swept too. + (input.projectId === projectId + ? Queue.offer(detailReads, undefined) + : Effect.void + ).pipe( + Effect.as({ + ...watchedPullRequestDetail({ + projectId, + number: 14, + at: "2026-10-02T12:00:00.000Z", + }), + headSha: "6074dd48ff", + checks, }), - headSha: "6074dd48ff", - checks, + ), + activity: () => + Effect.succeed({ + comments: [], + commentCount: 0, + commentsTruncated: false, + reviewThreads: [], + commits: [], }), + watchFingerprint: (input) => + (input.projectId === projectId + ? Queue.offer(fingerprintReads, undefined) + : Effect.void + ).pipe(Effect.andThen(Effect.sync(() => ({ status, remarks: "none" })))), + invalidate: () => Effect.void, + // Without the GitHub app sign-in no feed is on, so only the sweep hears checks. + changes: () => Stream.empty, + }), + ); + const wakes = Effect.map( + orchestrator.getThreadRecords(threadId, ["messages"]), + ({ messages }) => + messages.filter( + (message) => message.notification !== undefined && message.notification !== null, ), - activity: () => - Effect.succeed({ - comments: [], - commentCount: 0, - commentsTruncated: false, - reviewThreads: [], - commits: [], - }), - watchFingerprint: (input) => - (input.projectId === projectId - ? Queue.offer(fingerprintReads, undefined) - : Effect.void - ).pipe(Effect.andThen(Effect.sync(() => ({ status, remarks: "none" })))), - invalidate: () => Effect.void, - // Without the GitHub app sign-in no feed is on, so only the sweep hears checks. - changes: () => Stream.empty, - }), - ); - const wakes = Effect.map( - orchestrator.getThreadRecords(threadId, ["messages"]), - ({ messages }) => - messages.filter( - (message) => message.notification !== undefined && message.notification !== null, - ), - ); - const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host)); - const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; - yield* reactor.start(); - yield* Queue.take(fingerprintReads); - yield* Queue.take(detailReads); - yield* worker.drain(); - assert.lengthOf(yield* wakes, 0); + ); + const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host)); + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2; + yield* reactor.start(); + yield* Queue.take(fingerprintReads); + yield* Queue.take(detailReads); + yield* worker.drain(); + assert.lengthOf(yield* wakes, 0); - // A probe whose fingerprint has not moved reads nothing more. - yield* TestClock.adjust("30 seconds"); - yield* Queue.take(fingerprintReads); - status = "passed"; - checks = [{ name: "lint", status: "success", description: null, url: null, required: true }]; - // The probe must hear the concluded checks long before the 2-minute sweep could. - yield* TestClock.adjust("30 seconds"); - yield* Queue.take(detailReads); - yield* worker.drain(); - const woken = yield* wakes; - assert.lengthOf(woken, 1); - assert.equal(woken[0]!.notification?.summary, "#14: checks passed"); - assert.equal(yield* Queue.size(detailReads), 0); + // A probe whose fingerprint has not moved reads nothing more. + yield* TestClock.adjust("30 seconds"); + yield* Queue.take(fingerprintReads); + status = "passed"; + checks = [ + { name: "lint", status: "success", description: null, url: null, required: true }, + ]; + // The probe must hear the concluded checks long before the 2-minute sweep could. + yield* TestClock.adjust("30 seconds"); + yield* Queue.take(detailReads); + yield* worker.drain(); + const woken = yield* wakes; + assert.lengthOf(woken, 1); + assert.equal(woken[0]!.notification?.summary, "#14: checks passed"); + assert.equal(yield* Queue.size(detailReads), 0); - // The settled pull request stays quiet until the sweep. - yield* TestClock.adjust("30 seconds"); - yield* worker.drain(); - assert.lengthOf(yield* wakes, 1); + // The settled pull request stays quiet until the sweep. + yield* TestClock.adjust("30 seconds"); + yield* worker.drain(); + assert.lengthOf(yield* wakes, 1); - yield* orchestrator.dispatch({ - type: "thread.pull-request.watch", - commandId: CommandId.make("pr-watch-probe-end"), - threadId, - ...key, - watching: false, - }); - yield* worker.drain(); - }), + yield* orchestrator.dispatch({ + type: "thread.pull-request.watch", + commandId: CommandId.make(`pr-watch-probe-end-${start}`), + threadId, + ...key, + watching: false, + }); + yield* worker.drain(); + }), ); // regression: #21155 watching a pull request again repeated news the thread already got