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 21, 19:45 UTC
fix(server): a finished turn refreshes only its own project's PR listings (#35070)
Julius Marminge committed
Nov 12, 2026 at 02:40 UTC
40526f96f6ae3dfe74ae60ca279e748d7838a691
4 files changed
+54
-12
apps/server/src/git/linkCreatedPullRequest.test.ts
+8
-4
@@ -169,7 +169,7 @@ it.effect(
169
"refreshes PR readers after a push from a thread or project, but not a local commit",
170
() =>
171
Effect.gen(function* () {
172
- const refreshed: string[] = [];
172
+ const refreshed: Array<[string, boolean | undefined]> = [];
173
const layerDependencies = Layer.mergeAll(
174
Layer.mock(Orchestrator.OrchestratorV2)({
175
getThreadShell: () => Effect.succeed(v2PullRequestThread(thread)),
@@ -178,9 +178,9 @@ it.effect(
178
listShells: () => Effect.succeed([project]),
179
}),
180
Layer.mock(PullRequestService.PullRequestService)({
181
- refreshAfterTurn: (id) =>
181
+ refreshAfterTurn: (id, options) =>
182
Effect.sync(() => {
183
- refreshed.push(id);
183
+ refreshed.push([id, options?.pushed]);
184
}),
185
}),
186
);
@@ -203,6 +203,10 @@ it.effect(
203
{ cwd: "/draft-worktree", projectId: PROJECT_ID },
204
{ push: { status: "pushed" } },
205
).pipe(Effect.provide(layerDependencies));
206
- expect(refreshed).toEqual([PROJECT_ID, PROJECT_ID, PROJECT_ID]);
206
+ expect(refreshed).toEqual([
207
+ [PROJECT_ID, true],
208
+ [PROJECT_ID, true],
209
+ [PROJECT_ID, true],
210
+ ]);
211
}),
212
);
apps/server/src/git/refreshPushedPullRequests.ts
+3
-3
@@ -16,18 +16,18 @@ export const refreshPushedPullRequests = Effect.fn("refreshPushedPullRequests")(
16
const engine = yield* OrchestratorV2.OrchestratorV2;
17
const thread = yield* engine.getThreadShell(input.threadId);
18
if (thread !== null) {
19
- yield* pullRequests.refreshAfterTurn(thread.projectId);
19
+ yield* pullRequests.refreshAfterTurn(thread.projectId, { pushed: true });
20
return;
21
}
22
}
23
if (input.projectId !== undefined) {
24
- yield* pullRequests.refreshAfterTurn(input.projectId);
24
+ yield* pullRequests.refreshAfterTurn(input.projectId, { pushed: true });
25
return;
26
}
27
const projects = yield* (yield* ProjectStore.ProjectStoreV2).listShells();
28
yield* Effect.forEach(
29
projects.filter((project) => project.workspaceRoot === input.cwd),
30
- (project) => pullRequests.refreshAfterTurn(project.id),
30
+ (project) => pullRequests.refreshAfterTurn(project.id, { pushed: true }),
31
{ discard: true },
32
);
33
},
apps/server/src/pullRequest/PullRequestService.test.ts
+34
@@ -2671,6 +2671,40 @@ it.effect("does not revive old summaries when project epochs are evicted", () =>
2671
}),
2672
);
2673
2674
+it.effect("a finished turn leaves another project's cached listing in place", () =>
2675
+ Effect.gen(function* () {
2676
+ const reads: string[] = [];
2677
+ const service = yield* makeService({
2678
+ projects: [
2679
+ project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" }),
2680
+ project({ id: "p2", title: "api", workspaceRoot: "/b", repository: "acme/api" }),
2681
+ ],
2682
+ providers: [
2683
+ fakePullRequestProvider(SourceControlProviderKind.make("github"), {
2684
+ listChangeRequests: ({ repository }) => {
2685
+ reads.push(repository);
2686
+ return Effect.succeed({ items: [], truncated: false, continues: false });
2687
+ },
2688
+ }),
2689
+ ],
2690
+ });
2691
+ const webListing = { state: "open" as const, projectId: "p1" as ProjectId };
2692
+ const everyListing = { state: "open" as const };
2693
+
2694
+ yield* service.list(webListing);
2695
+ yield* service.list(everyListing);
2696
+ reads.length = 0;
2697
+ yield* service.refreshAfterTurn("p2" as ProjectId);
2698
+ yield* service.list(webListing);
2699
+ yield* service.list(everyListing);
2700
+ assert.deepStrictEqual(reads, []);
2701
+
2702
+ yield* service.refreshAfterTurn("p2" as ProjectId, { pushed: true });
2703
+ yield* service.list(everyListing);
2704
+ assert.deepStrictEqual(reads.toSorted(), ["acme/api", "acme/web"]);
2705
+ }),
2706
+);
2707
+
2708
it.effect("a refresh or a finished turn drops the provider's own change request reads", () =>
2709
Effect.gen(function* () {
2710
const forgotten: Array<{ readonly repository: string; readonly number?: number } | undefined> =
apps/server/src/pullRequest/PullRequestService.ts
+9
-5
@@ -218,7 +218,10 @@ export class PullRequestService extends Context.Service<
218
input: PullRequestReportStateInput,
219
) => Effect.Effect<void, PullRequestError>;
220
readonly subscribeRefreshes: Stream.Stream<number>;
221
- readonly refreshAfterTurn: (projectId: ProjectId) => Effect.Effect<void>;
221
+ readonly refreshAfterTurn: (
222
+ projectId: ProjectId,
223
+ options?: { readonly pushed?: boolean },
224
+ ) => Effect.Effect<void>;
225
/** Project and remote lookups inside `effect` read once per filter, e.g. across one sync sweep. */
226
readonly withSharedProjectReads: <A, E, R>(
227
effect: Effect.Effect<A, E, R>,
@@ -3639,12 +3642,14 @@ export const make = Effect.gen(function* () {
3642
3643
const refreshAfterTurn: PullRequestService["Service"]["refreshAfterTurn"] = Effect.fn(
3644
"PullRequestService.refreshAfterTurn",
3642
- )(function* (projectId) {
3645
+ )(function* (projectId, options) {
3646
// Everything the provider holds, not just the project's repository: a turn can touch a
3647
// change request reached through another repository, and no epoch may move until those
3648
// reads are gone, or a reader in between keeps the old one under the new epoch.
3649
yield* forgetProviderReads();
3647
- listingsEpoch = ++epochCounter;
3650
+ const epoch = ++epochCounter;
3651
+ // A push can open or move a PR; a plain turn waits for the listing TTL to spare the API quota.
3652
+ if (options?.pushed === true) listingsEpoch = epoch;
3653
projectEpochs.delete(projectId);
3654
if (projectEpochs.size >= REF_EPOCH_CAPACITY) {
3655
const oldest = projectEpochs.keys().next().value;
@@ -3653,8 +3658,7 @@ export const make = Effect.gen(function* () {
3658
projectEpochs.delete(oldest);
3659
}
3660
}
3656
- projectEpochs.set(projectId, listingsEpoch);
3657
- const epoch = listingsEpoch;
3661
+ projectEpochs.set(projectId, epoch);
3662
yield* readCache.invalidate(`project:${projectId}`);
3663
yield* SubscriptionRef.set(pullRequestRefreshes, epoch);
3664
});