From bc7bb4f023eb4656c7f3f0bfc7d8f0ddbcfa216b Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 16 Nov 2026 04:57:43 +0000 Subject: [PATCH] fix(server): PR watches without a host event feed notice check changes within seconds A watched pull request with checks running or mergeability unknown now gets a batched fingerprint probe every 20 seconds when no host event feed is live, and is read in full only when the fingerprint moved. Before, without the GitHub app sign-in and event-streams preview, a finished check waited for the next 2-minute sweep. Fixes pingdotgg/t3code#37477 Co-Authored-By: Claude Opus 5.5 --- .../PullRequestWatchReactor.ts | 32 +++++ .../src/orchestration-v2/runtimeLayer.test.ts | 118 ++++++++++++++++++ docs/user/source-control.md | 3 +- 3 files changed, 152 insertions(+), 1 deletion(-) diff --git a/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts b/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts index 5b69a7efa3377..096b3eb2a6882 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; +/** Without a host event feed, in-flight PRs poll their batched fingerprint and read only on change. */ +const PROBE_SECONDS = 20; const READ_FAILURE_LIMIT = 8; /** Group reads in flight at once, inside the host's own request limit. */ const GROUP_READS = 4; @@ -863,6 +865,33 @@ export const make = Effect.gen(function* () { ); } }); + const probe = Effect.gen(function* () { + const due = currentGroups.filter( + (group) => + lastReads.get(group.key)?.inFlight === true && + !FiberMap.hasUnsafe(feeds, pullRequestOf(group)), + ); + const moved = new Set(); + yield* Effect.forEach( + due, + (group) => + fingerprintOf(group).pipe( + Effect.map((fingerprint) => { + const last = lastReads.get(group.key); + if ( + fingerprint !== null && + fingerprint !== "paused" && + last !== undefined && + (last.status !== fingerprint.status || last.remarks !== fingerprint.remarks) + ) { + moved.add(pullRequestOf(group)); + } + }), + ), + { concurrency: "unbounded", discard: true }, + ); + yield* Effect.forEach(moved, readOnChange, { discard: true }); + }); yield* forkParked( sweep.pipe( Effect.andThen(follow), @@ -870,6 +899,9 @@ export const make = Effect.gen(function* () { Effect.asVoid, ), ); + yield* forkParked( + Effect.sleep(`${PROBE_SECONDS} seconds`).pipe(Effect.andThen(probe), 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 82ca01576deea..522ba29e56adf 100644 --- a/apps/server/src/orchestration-v2/runtimeLayer.test.ts +++ b/apps/server/src/orchestration-v2/runtimeLayer.test.ts @@ -5208,6 +5208,124 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => { }), ); + it.effect( + "without a host feed, reads a pull request with running checks once its fingerprint moves", + () => + 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: 16 }; + 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/16", source: "agent" }, + }); + + let checks: PullRequestDetail["checks"] = [ + { name: "lint", status: "pending", description: null, url: null, required: true }, + ]; + let status = "pending"; + const followed = yield* Deferred.make(); + const detailReads = yield* Queue.unbounded(); + const host = Layer.mergeAll( + NodeServices.layer, + NodeCrypto.layer, + Layer.mock(PullRequestService.PullRequestService)({ + // Watches other cases left on share this mock, so only this project's reads count. + detail: (input) => + (input.projectId === projectId + ? Queue.offer(detailReads, undefined) + : Effect.void + ).pipe( + Effect.as({ + ...watchedPullRequestDetail({ + projectId, + number: 16, + at: "2026-10-02T12:00:00.000Z", + }), + headSha: "bbbbbbbbbb", + checks, + }), + ), + activity: () => + Effect.succeed({ + comments: [], + commentCount: 0, + commentsTruncated: false, + reviewThreads: [], + commits: [], + }), + watchFingerprint: () => Effect.sync(() => ({ status, remarks: "" })), + invalidate: () => Effect.void, + // The host offers no event feed, as without the GitHub app sign-in. + changes: () => Stream.fromEffectDrain(Deferred.succeed(followed, undefined)), + }), + ); + 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* Deferred.await(followed); + yield* Queue.take(detailReads); + + // An unchanged fingerprint costs no detail read. + yield* TestClock.adjust("20 seconds"); + assert.isTrue(Option.isNone(yield* Queue.poll(detailReads))); + + checks = [ + { name: "lint", status: "failure", description: null, url: null, required: true }, + ]; + status = "failure"; + // Well inside the 2-minute sweep. + yield* TestClock.adjust("20 seconds"); + yield* Queue.take(detailReads); + yield* reactor.sweep; + yield* worker.drain(); + const woken = yield* wakes; + assert.lengthOf(woken, 1); + assert.include(woken[0]!.notification?.summary ?? "", "failed"); + + yield* orchestrator.dispatch({ + type: "thread.pull-request.watch", + commandId: CommandId.make("pr-watch-probe-end"), + threadId, + ...key, + watching: false, + }); + }), + ); + it.effect( "reads a watched pull request when the host reports a change, and wakes once per change", () => diff --git a/docs/user/source-control.md b/docs/user/source-control.md index 2f068d8827494..e1ed50b07c1f8 100644 --- a/docs/user/source-control.md +++ b/docs/user/source-control.md @@ -326,7 +326,8 @@ when requested. Settling a thread refreshes its open and closed reviews once; af review is terminal. An open or unsynced link keeps it active. Ask the agent to watch, monitor, or babysit a pull request and it calls `watch_pull_request`. While -the thread is active, the server checks the pull request every two minutes and wakes the agent when a +the thread is active, the server checks the pull request every two minutes, and every 20 seconds while its +checks are running, and wakes the agent when a check fails or waits for a maintainer's approval, the required checks pass, someone else comments or reviews, or the branch starts to conflict. On github.com it also wakes the agent, with GitHub's reason, when the merge queue drops the pull request without merging it. Threads in a project that watch the same pull request share one check. On GitHub, a check