@devries-cameron20 / t3code-1 / commits / 125b61954d
Fork 0

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

fix(server): release completed pull request sweep data (#25177)

Julius Marminge committed Oct 28, 2026 at 09:27 UTC 125b61954dbba5822a8108c8ca47a4846b4b4328
2 files changed +44 -7
apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts
+38
@@ -1,3 +1,5 @@
1 +import * as NodeV8 from "node:v8";
2 +
3 import { SourceControlProviderKind } from "@t3tools/contracts";
4 import * as Stream from "effect/Stream";
5 import {
@@ -21,10 +23,12 @@ import {
23 type ThreadPullRequestSnapshot,
24 } from "@t3tools/contracts";
25 import { assert, describe, it } from "@effect/vitest";
26 +import * as Cache from "effect/Cache";
27 import * as Clock from "effect/Clock";
28 import * as Crypto from "effect/Crypto";
29 import * as DateTime from "effect/DateTime";
30 import * as Deferred from "effect/Deferred";
31 +import * as Duration from "effect/Duration";
32 import * as Effect from "effect/Effect";
33 import * as Layer from "effect/Layer";
34 import * as Queue from "effect/Queue";
@@ -496,6 +500,40 @@ const mergingSnapshot = () =>
500 makeSnapshot([makeThread(MERGING_THREAD, { pullRequests: [makeLink(7, { state: "open" })] })]);
501
502 describe("PullRequestSyncReactor", () => {
503 + it.effect("lets a finished sweep's links go while a cache keeps the fiber that read them", () =>
504 + Effect.gen(function* () {
505 + class SweptLink {
506 + readonly swept = true;
507 + }
508 + // Like PullRequestReadCache's revisions: a lookup fiber, kept for good, forked from the reader.
509 + const kept = yield* Cache.makeWith(() => Effect.void, {
510 + capacity: 1,
511 + timeToLive: () => Duration.infinity,
512 + });
513 + const fixture = yield* makeHarness({
514 + snapshot: makeSnapshot([]),
515 + summary: (input) => Cache.get(kept, undefined).pipe(Effect.as(makeSummary(input))),
516 + });
517 + yield* Ref.set(
518 + fixture.snapshots,
519 + makeSnapshot(
520 + Array.from({ length: 30 }, (_, index) =>
521 + makeThread(`thread-${index}`, {
522 + pullRequests: [Object.assign(new SweptLink(), makeLink(7))],
523 + }),
524 + ),
525 + ),
526 + );
527 + yield* Effect.gen(function* () {
528 + yield* startAndSweep(fixture);
529 + assert.strictEqual((yield* Ref.get(fixture.syncCommands)).length, 30);
530 + yield* Ref.set(fixture.snapshots, makeSnapshot([]));
531 +
532 + assert.strictEqual(NodeV8.queryObjects(SweptLink, { format: "count" }), 0);
533 + }).pipe(Effect.provide(fixture.layer));
534 + }),
535 + );
536 +
537 it.effect("retries a failed stack read after the summary becomes terminal", () =>
538 Effect.scoped(
539 Effect.gen(function* () {
apps/server/src/orchestration-v2/PullRequestSyncReactor.ts
+6 -7
@@ -392,7 +392,9 @@ export const make = Effect.gen(function* () {
392 const stacksReadThisSweep = new Map<string, ThreadPullRequestStack | null>();
393 const persistence = yield* Semaphore.make(1);
394
395 - const syncEntry = Effect.fn("PullRequestSyncReactor.syncEntry")(function* (
395 + // Effect.fn's stack frames close over these sweep-scoped bodies and their arguments, and a
396 + // cache lookup forked inside keeps those frames, so a plain span leaves the sweep collectable.
397 + const syncEntry = Effect.fnUntraced(function* (
398 entry: LinkEntry,
399 fields: SnapshotFields,
400 fetchedStack: { readonly stack: ThreadPullRequestStack | null } | null,
@@ -446,12 +448,9 @@ export const make = Effect.gen(function* () {
448 stack: nextStack,
449 });
450 }
449 - });
451 + }, Effect.withSpan("PullRequestSyncReactor.syncEntry"));
452
451 - const syncGroup = Effect.fn("PullRequestSyncReactor.syncGroup")(function* (
452 - key: string,
453 - entries: ReadonlyArray<LinkEntry>,
454 - ) {
453 + const syncGroup = Effect.fnUntraced(function* (key: string, entries: ReadonlyArray<LinkEntry>) {
454 const first = entries[0]!;
455 const ref = {
456 projectId: first.thread.projectId,
@@ -554,7 +553,7 @@ export const make = Effect.gen(function* () {
553 ),
554 { discard: true },
555 );
557 - });
556 + }, Effect.withSpan("PullRequestSyncReactor.syncGroup"));
557
558 const skips = new Map<string, { count: number; readonly key: string }>();
559 const readGroup = (key: string, entries: ReadonlyArray<LinkEntry>, pauseKey: string) =>