@devries-cameron20 / t3code-1 / commits / 56a85428d5
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

perf(server): a slow host no longer delays other watched PRs' wakes (935 ms → 65 ms median) (#30291)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Andrei committed Nov 6, 2026 at 12:24 UTC 56a85428d5b46b81e1706e5644ad0a459edf3318
2 files changed +98 -14
apps/server/src/orchestration-v2/PullRequestWatchReactor.ts
+21 -14
@@ -24,6 +24,7 @@ import * as Layer from "effect/Layer";
24 import * as Option from "effect/Option";
25 import * as Schedule from "effect/Schedule";
26 import * as Schema from "effect/Schema";
27 +import * as Semaphore from "effect/Semaphore";
28 import type * as Scope from "effect/Scope";
29
30 import {
@@ -43,6 +44,8 @@ import {
44 /** Checks take minutes; faster sweeps waste the account's shared host quota. */
45 const SWEEP_MINUTES = 2;
46 const READ_FAILURE_LIMIT = 8;
47 +/** Group reads in flight at once, inside the host's own request limit. */
48 +const GROUP_READS = 4;
49 /** Without fingerprints, reread quiet PRs on snapshot changes or this interval to catch edits. */
50 const QUIET_REREAD_MS = 10 * 60_000;
51 /** Reread despite unchanged fingerprints; they miss review-thread comment edits. */
@@ -626,22 +629,26 @@ export const make = Effect.gen(function* () {
629 ),
630 { discard: true },
631 );
629 - const fingerprints = yield* Effect.forEach(groups, fingerprintOf, {
630 - concurrency: "unbounded",
631 - });
632 + // Every fingerprint is asked for at once so the host can batch them, and each group reads
633 + // as soon as its own answer lands rather than waiting on the slowest host.
634 + const reads = yield* Semaphore.make(GROUP_READS);
635 yield* Effect.forEach(
636 groups,
634 - (group, index) => {
635 - const fingerprint = fingerprints[index]!;
636 - return fingerprint === "paused"
637 - ? Effect.void
638 - : readGroup(group, fingerprint).pipe(
639 - Effect.catchCause(
640 - logFailure("pull request watch check failed", { pullRequest: group.key }),
641 - ),
642 - );
643 - },
644 - { concurrency: 4, discard: true },
637 + (group) =>
638 + fingerprintOf(group).pipe(
639 + Effect.flatMap((fingerprint) =>
640 + fingerprint === "paused"
641 + ? Effect.void
642 + : reads.withPermit(
643 + readGroup(group, fingerprint).pipe(
644 + Effect.catchCause(
645 + logFailure("pull request watch check failed", { pullRequest: group.key }),
646 + ),
647 + ),
648 + ),
649 + ),
650 + ),
651 + { concurrency: "unbounded", discard: true },
652 );
653 }).pipe(
654 Effect.catchCause(logFailure("pull request watch sweep failed", {})),
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+77
@@ -4334,6 +4334,83 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
4334 }),
4335 );
4336
4337 + it.effect("reads each watched PR as soon as its own fingerprint lands", () =>
4338 + Effect.gen(function* () {
4339 + const orchestrator = yield* Orchestrator.OrchestratorV2;
4340 + const projectId = ProjectId.make("pr-watch-pipeline-project");
4341 + yield* seedProject({
4342 + projectId,
4343 + title: "Watch pipeline",
4344 + workspaceRoot: "/workspace/watch-pipeline",
4345 + defaultModelSelection: null,
4346 + createdAt: "2026-10-01T00:00:00.000Z",
4347 + });
4348 + for (const number of [21, 22]) {
4349 + const threadId = ThreadId.make(`runtime-pull-request-watch-pipeline-${number}`);
4350 + yield* orchestrator.dispatch({
4351 + type: "thread.create",
4352 + createdBy: "user",
4353 + creationSource: "web",
4354 + commandId: CommandId.make(`pr-watch-pipeline-create-${number}`),
4355 + threadId,
4356 + projectId,
4357 + title: "Watch pipeline",
4358 + modelSelection,
4359 + runtimeMode: "full-access",
4360 + interactionMode: "default",
4361 + branch: null,
4362 + worktreePath: null,
4363 + });
4364 + yield* orchestrator.dispatch({
4365 + type: "thread.pull-request.watch",
4366 + commandId: CommandId.make(`pr-watch-pipeline-start-${number}`),
4367 + threadId,
4368 + host: "github.com",
4369 + repository: "pingdotgg/t3code",
4370 + number,
4371 + watching: true,
4372 + link: { url: `https://github.com/pingdotgg/t3code/pull/${number}`, source: "agent" },
4373 + });
4374 + }
4375 + const at = "2026-10-02T12:00:00.000Z";
4376 + const texts = (number: number) =>
4377 + orchestrator
4378 + .getThreadRecords(ThreadId.make(`runtime-pull-request-watch-pipeline-${number}`), [
4379 + "messages",
4380 + ])
4381 + .pipe(Effect.map(({ messages }) => messages.map((message) => message.text).join("\n")));
4382 + // #21's host answers only after #22 has been read, so waiting on every fingerprint first
4383 + // never finishes.
4384 + const read22 = yield* Deferred.make<void>();
4385 + const host = Layer.mergeAll(
4386 + NodeServices.layer,
4387 + NodeCrypto.layer,
4388 + Layer.mock(PullRequestService.PullRequestService)({
4389 + watchFingerprint: (input) =>
4390 + input.number === 21
4391 + ? Deferred.await(read22).pipe(Effect.as(null))
4392 + : Effect.succeed(null),
4393 + detail: (input) =>
4394 + (input.number === 22 ? Deferred.succeed(read22, undefined) : Effect.void).pipe(
4395 + Effect.as(watchedPullRequestDetail({ projectId, number: input.number, at })),
4396 + ),
4397 + activity: () =>
4398 + Effect.succeed({
4399 + comments: [],
4400 + commentCount: 0,
4401 + commentsTruncated: false,
4402 + reviewThreads: [],
4403 + commits: [],
4404 + }),
4405 + }),
4406 + );
4407 + const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host));
4408 + yield* reactor.sweep;
4409 + assert.include(yield* texts(21), "#21");
4410 + assert.include(yield* texts(22), "#22");
4411 + }),
4412 + );
4413 +
4414 it.effect("persists rejected command receipts across retries", () =>
4415 Effect.gen(function* () {
4416 const orchestrator = yield* Orchestrator.OrchestratorV2;