@devries-cameron20 / t3code Mirror · read-only / commits / aaba9de94f
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 13:15 UTC

fix(server): PR discovery sweeps skip hidden subagent threads (#26983)

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

Julius Marminge committed Oct 29, 2026 at 10:51 UTC aaba9de94f6e3f8b57ef9b605621afde791e625e
2 files changed +132 -3
apps/server/src/orchestration-v2/ThreadPullRequestService.test.ts
+122
@@ -179,6 +179,128 @@ describe("ThreadPullRequestServiceV2 reads", () => {
179 ),
180 );
181
182 + it.effect("leaves delegated child threads to their own refresh instead of the sweep", () =>
183 + Effect.scoped(
184 + Effect.gen(function* () {
185 + const parent = {
186 + ...threadShell("parent-thread"),
187 + branch: "feature/parent",
188 + worktreePath: "/workspace/parent",
189 + };
190 + const child: OrchestrationV2ThreadShell = {
191 + ...threadShell("child-thread"),
192 + branch: "t3/reply-ok",
193 + worktreePath: "/workspace/child",
194 + lineage: {
195 + rootThreadId: parent.id,
196 + parentThreadId: parent.id,
197 + relationshipToParent: "subagent",
198 + },
199 + };
200 + const project: OrchestrationProjectShell = {
201 + id: parent.projectId,
202 + title: "Project",
203 + workspaceRoot: "/workspace/project",
204 + defaultModelSelection: null,
205 + scripts: [],
206 + createdAt: "2026-08-01T00:00:00.000Z",
207 + updatedAt: "2026-08-01T00:00:00.000Z",
208 + };
209 + const activation = yield* Deferred.make<void>();
210 + const domainEvents = yield* Queue.unbounded<OrchestrationV2DomainEvent>();
211 + const sweeps = yield* Queue.unbounded<void>();
212 + const childLookup = yield* Deferred.make<void>();
213 + const lookups: Array<{ readonly branch: string; readonly refresh: boolean }> = [];
214 + const dependencies = Layer.mergeAll(
215 + Layer.mock(Orchestrator.OrchestratorV2)({
216 + streamDomainEvents: Stream.fromQueue(domainEvents),
217 + getShellSnapshot: () =>
218 + Queue.offer(sweeps, undefined).pipe(
219 + Effect.as({
220 + schemaVersion: 2,
221 + snapshotSequence: 1,
222 + threads: [parent, child],
223 + archivedThreads: [],
224 + }),
225 + ),
226 + getThreadEventSequence: () => Effect.succeed(1),
227 + getThreadShell: (threadId) =>
228 + Effect.succeed([parent, child].find((thread) => thread.id === threadId) ?? null),
229 + }),
230 + Layer.mock(ProjectStore.ProjectStoreV2)({
231 + listShells: () => Effect.succeed([project]),
232 + getShell: () => Effect.succeedSome(project),
233 + }),
234 + Layer.mock(GitManager.GitManager)({
235 + branchPullRequest: (input, options) =>
236 + Effect.gen(function* () {
237 + const refresh = options?.refresh ?? false;
238 + lookups.push({ branch: input.branch, refresh });
239 + if (input.branch === child.branch && refresh) {
240 + yield* Deferred.succeed(childLookup, undefined);
241 + }
242 + return null;
243 + }),
244 + }),
245 + Layer.mock(PullRequestService.PullRequestService)({}),
246 + Layer.mock(RepositoryIdentityResolver.RepositoryIdentityResolver)({
247 + resolve: () =>
248 + Effect.succeed({
249 + canonicalKey: "github.com/acme/project",
250 + locator: {
251 + source: "git-remote" as const,
252 + remoteName: "origin",
253 + remoteUrl: "git@github.com:acme/project.git",
254 + },
255 + provider: SourceControlProviderKind.make("github"),
256 + owner: "acme",
257 + name: "project",
258 + }),
259 + }),
260 + Layer.mock(BackgroundPolicy.BackgroundPolicy)({
261 + shouldRunScopeWork: () => Effect.succeed(true),
262 + shouldRunOpportunisticWork: Effect.succeed(true),
263 + }),
264 + Layer.succeed(ServerActivation.ServerActivation, Deferred.await(activation)),
265 + Layer.succeed(
266 + Crypto.Crypto,
267 + Crypto.make({
268 + randomBytes: (size) => new Uint8Array(size).fill(1),
269 + digest: (_algorithm, data) => Effect.succeed(data),
270 + }),
271 + ),
272 + FileSystem.layerNoop({}),
273 + );
274 + yield* Effect.gen(function* () {
275 + const service = yield* ThreadPullRequestService.make;
276 + yield* service.start();
277 + yield* Deferred.succeed(activation, undefined);
278 +
279 + // Startup backfill sweep, then one periodic sweep.
280 + yield* Queue.take(sweeps);
281 + yield* service.drain;
282 + yield* TestClock.adjust("1 minute");
283 + yield* Queue.take(sweeps);
284 + yield* service.drain;
285 + const sweepLookups = lookups.map((lookup) => lookup.branch).toSorted();
286 +
287 + // The child's own turn still discovers its pull request.
288 + yield* Queue.offer(domainEvents, {
289 + type: "checkpoint.captured",
290 + threadId: child.id,
291 + } as OrchestrationV2DomainEvent);
292 + yield* Deferred.await(childLookup);
293 + yield* service.drain;
294 +
295 + expect(sweepLookups).toEqual([parent.branch, parent.branch]);
296 + expect(lookups.slice(sweepLookups.length)).toEqual([
297 + { branch: child.branch, refresh: true },
298 + ]);
299 + }).pipe(Effect.provide(dependencies));
300 + }),
301 + ),
302 + );
303 +
304 it.effect.each([
305 { state: "closed", sameBranch: false },
306 { state: "merged", sameBranch: false },
apps/server/src/orchestration-v2/ThreadPullRequestService.ts
+10 -3
@@ -139,9 +139,16 @@ export const make = Effect.gen(function* () {
139 readThreadSnapshot(request),
140 projectStore.listShells(),
141 ]);
142 + // Subagent children refresh after their own runs; sweeping them costs a lookup each per minute.
143 + const snapshotThreads =
144 + request.threadId === null
145 + ? threadSnapshot.threads.filter(
146 + (thread) => thread.lineage.relationshipToParent !== "subagent",
147 + )
148 + : threadSnapshot.threads;
149 const projects = new Map(projectShells.map((project) => [project.id, project]));
150 if (request.backfill) {
144 - for (const thread of threadSnapshot.threads) {
151 + for (const thread of snapshotThreads) {
152 if (
153 (thread.settledOverride === "settled" || thread.settledAt !== null) &&
154 thread.branchPullRequest == null
@@ -151,13 +158,13 @@ export const make = Effect.gen(function* () {
158 }
159 }
160 const visibleThreadIds = new Set(
154 - threadSnapshot.threads.filter((thread) => thread.branch !== null).map((thread) => thread.id),
161 + snapshotThreads.filter((thread) => thread.branch !== null).map((thread) => thread.id),
162 );
163 const checkedIds = request.threadId === null ? [...pendingBackfill.keys()] : [request.threadId];
164 for (const threadId of checkedIds) {
165 if (!visibleThreadIds.has(threadId)) pendingBackfill.delete(threadId);
166 }
160 - const threads = threadSnapshot.threads.filter(
167 + const threads = snapshotThreads.filter(
168 (thread) =>
169 thread.archivedAt === null &&
170 ((thread.settledOverride !== "settled" && thread.settledAt === null) ||