Skip to content

Commit 2359cc9

Browse files
t3dotggclaude
andcommitted
fix(server): a new watch on a quiet PR reads on the next pass
Track which watches the last read evaluated instead of comparing start times, which missed a watch started in the same millisecond. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 4c23b62 commit 2359cc9

2 files changed

Lines changed: 45 additions & 28 deletions

File tree

‎apps/server/src/orchestration-v2/PullRequestWatchReactor.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@ interface LastRead {
8585
readonly fingerprint: string;
8686
/** Nothing is in flight or unread, so only a moved snapshot or the reread brings news. */
8787
readonly quiet: boolean;
88+
/** The watches this read evaluated; a watch started since takes its first look next pass. */
89+
readonly watches: ReadonlySet<string>;
8890
}
8991

92+
const watchKey = ({ thread, watch }: WatchTarget) => `${thread.id} ${watch.startedAt}`;
93+
9094
const snapshotFingerprint = ({ link }: WatchTarget) => {
9195
const snapshot = link.snapshot;
9296
return snapshot === null
@@ -107,8 +111,7 @@ function needsRead(group: WatchGroup, last: LastRead | undefined, now: number):
107111
!last.quiet ||
108112
last.fingerprint !== group.fingerprint ||
109113
now - last.at >= QUIET_REREAD_MS ||
110-
// A new watch takes its first look right away.
111-
group.targets.some((target) => Date.parse(target.watch.startedAt) > last.at)
114+
group.targets.some((target) => !last.watches.has(watchKey(target)))
112115
);
113116
}
114117

@@ -342,6 +345,7 @@ export const make = Effect.gen(function* () {
342345
remarks !== null &&
343346
detail.mergeability !== "unknown" &&
344347
detail.checks.every((check) => check.status !== "pending"),
348+
watches: new Set(group.targets.map(watchKey)),
345349
});
346350
yield* eachTarget(group, (target) => {
347351
const report = evaluatePullRequestWatch(target.watch, detail, remarks);

‎apps/server/src/orchestration-v2/runtimeLayer.test.ts‎

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,32 +2537,34 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
25372537
const threadIds = ["one", "two"].map((name) =>
25382538
ThreadId.make(`runtime-pull-request-watch-shared-${name}`),
25392539
);
2540-
for (const threadId of threadIds) {
2541-
yield* orchestrator.dispatch({
2542-
type: "thread.create",
2543-
createdBy: "user",
2544-
creationSource: "web",
2545-
commandId: CommandId.make(`create:${threadId}`),
2546-
threadId,
2547-
projectId,
2548-
title: "Watch shared",
2549-
modelSelection,
2550-
runtimeMode: "full-access",
2551-
interactionMode: "default",
2552-
branch: null,
2553-
worktreePath: null,
2554-
});
2555-
yield* orchestrator.dispatch({
2556-
type: "thread.pull-request.watch",
2557-
commandId: CommandId.make(`watch:${threadId}`),
2558-
threadId,
2559-
host: "github.com",
2560-
repository: "pingdotgg/t3code",
2561-
number: 9,
2562-
watching: true,
2563-
link: { url: "https://github.com/pingdotgg/t3code/pull/9", source: "agent" },
2540+
const watchFrom = (threadId: ThreadId) =>
2541+
Effect.gen(function* () {
2542+
yield* orchestrator.dispatch({
2543+
type: "thread.create",
2544+
createdBy: "user",
2545+
creationSource: "web",
2546+
commandId: CommandId.make(`create:${threadId}`),
2547+
threadId,
2548+
projectId,
2549+
title: "Watch shared",
2550+
modelSelection,
2551+
runtimeMode: "full-access",
2552+
interactionMode: "default",
2553+
branch: null,
2554+
worktreePath: null,
2555+
});
2556+
yield* orchestrator.dispatch({
2557+
type: "thread.pull-request.watch",
2558+
commandId: CommandId.make(`watch:${threadId}`),
2559+
threadId,
2560+
host: "github.com",
2561+
repository: "pingdotgg/t3code",
2562+
number: 9,
2563+
watching: true,
2564+
link: { url: "https://github.com/pingdotgg/t3code/pull/9", source: "agent" },
2565+
});
25642566
});
2565-
}
2567+
for (const threadId of threadIds) yield* watchFrom(threadId);
25662568
const rateLimited = new PullRequestOperationError({
25672569
operation: "getChangeRequest",
25682570
detail: "github requests are paused until the rate limit resets",
@@ -2641,11 +2643,22 @@ it.layer(TestLayer)("OrchestrationV2LayerLive lifecycle", (it) => {
26412643
yield* reactor.sweep;
26422644
assert.equal(reads, 21);
26432645

2646+
// A new watch on the quiet pull request takes its first look on the next pass.
2647+
const late = ThreadId.make("runtime-pull-request-watch-shared-late");
2648+
yield* watchFrom(late);
2649+
yield* reactor.sweep;
2650+
assert.equal(reads, 22);
2651+
assert.deepEqual(yield* summaries(late), ["#9: checks passed"]);
2652+
for (const threadId of threadIds) {
2653+
assert.deepEqual(yield* summaries(threadId), ["#9: checks passed"]);
2654+
}
2655+
threadIds.push(late);
2656+
26442657
// The quiet reread finds the pull request closed, ends both watches, and says so.
26452658
host = "closed";
26462659
yield* TestClock.adjust("10 minutes");
26472660
yield* reactor.sweep;
2648-
assert.equal(reads, 22);
2661+
assert.equal(reads, 23);
26492662
for (const threadId of threadIds) {
26502663
assert.isFalse(yield* watching(threadId));
26512664
assert.deepEqual(yield* summaries(threadId), [

0 commit comments

Comments
 (0)