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, 22:15 UTC
fix(server): opening a pull request loads while its host is rate-limited (#27595)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 11, 2026 at 12:00 UTC
173374c4a7cd4f3020785df316ca1238cef4e8d6
3 files changed
+102
-29
apps/server/src/pullRequest/PullRequestService.test.ts
+65
@@ -1891,6 +1891,71 @@ it.effect("stops new reads after a rate limit while leaving manual actions avail
1891
}),
1892
);
1893
1894
+it.effect(
1895
+ "opening a pull request during a rate-limit pause still reads its detail and activity",
1896
+ () =>
1897
+ Effect.gen(function* () {
1898
+ let detailReads = 0;
1899
+ let activityReads = 0;
1900
+ const service = yield* makeService({
1901
+ projects: [
1902
+ project({ id: "p1", title: "cloud", workspaceRoot: "/cloud", repository: "acme/web" }),
1903
+ ],
1904
+ providers: [
1905
+ fakePullRequestProvider(SourceControlProviderKind.make("github"), {
1906
+ getChangeRequest: ({ number }) =>
1907
+ Effect.suspend(() => {
1908
+ detailReads += 1;
1909
+ return number === 1
1910
+ ? Effect.fail(
1911
+ new PullRequestProviderError({
1912
+ provider: SourceControlProviderKind.make("github"),
1913
+ operation: "getChangeRequest",
1914
+ reason: "rate-limited",
1915
+ detail: "GitHub API rate limit exceeded.",
1916
+ }),
1917
+ )
1918
+ : Effect.succeed({ ...hostedChangeRequest("Body"), number });
1919
+ }),
1920
+ getChangeRequestActivity: () =>
1921
+ Effect.sync(() => {
1922
+ activityReads += 1;
1923
+ return {
1924
+ comments: [],
1925
+ commentCount: 0,
1926
+ commentsTruncated: false,
1927
+ reviewThreads: [],
1928
+ commits: [],
1929
+ };
1930
+ }),
1931
+ }),
1932
+ ],
1933
+ });
1934
+ const reference = { projectId: "p1" as ProjectId, repository: "acme/web", number: 2 };
1935
+
1936
+ yield* Effect.result(service.detail({ ...reference, number: 1 }));
1937
+ const background = yield* Effect.result(service.detail(reference));
1938
+ const opened = yield* Effect.result(
1939
+ service
1940
+ .detail(reference)
1941
+ .pipe(Effect.provideService(SourceControlRateLimit.Interactive, true)),
1942
+ );
1943
+ const timeline = yield* Effect.result(
1944
+ service
1945
+ .activity(reference)
1946
+ .pipe(Effect.provideService(SourceControlRateLimit.Interactive, true)),
1947
+ );
1948
+
1949
+ expect(background).toMatchObject({ _tag: "Failure" });
1950
+ expect({ opened, timeline }).toMatchObject({
1951
+ opened: { _tag: "Success", success: { number: 2 } },
1952
+ timeline: { _tag: "Success", success: { commentCount: 0 } },
1953
+ });
1954
+ assert.strictEqual(detailReads, 2);
1955
+ assert.strictEqual(activityReads, 1);
1956
+ }),
1957
+);
1958
+
1959
it.effect("refuses a repository that does not belong to the requested project", () =>
1960
Effect.gen(function* () {
1961
const service = yield* makeService({
apps/server/src/pullRequest/PullRequestService.ts
+32
-27
@@ -471,32 +471,37 @@ function withRateLimitBackoff(
471
const protect = <A>(
472
operation: string,
473
effect: Effect.Effect<A, PullRequestProviderError>,
474
- allowPaused: boolean,
474
+ alwaysInteractive: boolean,
475
) =>
476
- limits.check(key, allowPaused ? { allowPaused: true } : undefined).pipe(
477
- Effect.mapError(
478
- (error) =>
479
- new PullRequestProviderError({
480
- provider: api.kind,
481
- operation,
482
- reason: "rate-limited",
483
- detail: error.detail,
484
- retryAt: error.retryAt,
485
- cause: error,
486
- }),
487
- ),
488
- Effect.flatMap((lease) =>
489
- effect.pipe(
490
- Effect.provideService(SourceControlRateLimit.Interactive, allowPaused),
491
- Effect.tap(() => limits.recordSuccess({ ...key, lease })),
492
- Effect.tapError((error) =>
493
- error.reason === "rate-limited"
494
- ? limits.recordRateLimit({
495
- ...key,
496
- lease,
497
- ...(error.retryAt === undefined ? {} : { retryAt: error.retryAt }),
498
- })
499
- : Effect.void,
476
+ SourceControlRateLimit.Interactive.pipe(
477
+ Effect.map((callerInteractive) => alwaysInteractive || callerInteractive),
478
+ Effect.flatMap((allowPaused) =>
479
+ limits.check(key, allowPaused ? { allowPaused: true } : undefined).pipe(
480
+ Effect.mapError(
481
+ (error) =>
482
+ new PullRequestProviderError({
483
+ provider: api.kind,
484
+ operation,
485
+ reason: "rate-limited",
486
+ detail: error.detail,
487
+ retryAt: error.retryAt,
488
+ cause: error,
489
+ }),
490
+ ),
491
+ Effect.flatMap((lease) =>
492
+ effect.pipe(
493
+ Effect.provideService(SourceControlRateLimit.Interactive, allowPaused),
494
+ Effect.tap(() => limits.recordSuccess({ ...key, lease })),
495
+ Effect.tapError((error) =>
496
+ error.reason === "rate-limited"
497
+ ? limits.recordRateLimit({
498
+ ...key,
499
+ lease,
500
+ ...(error.retryAt === undefined ? {} : { retryAt: error.retryAt }),
501
+ })
502
+ : Effect.void,
503
+ ),
504
+ ),
505
),
506
),
507
),
@@ -505,10 +510,10 @@ function withRateLimitBackoff(
510
<Args extends ReadonlyArray<unknown>, A>(
511
operation: string,
512
call: (...args: Args) => Effect.Effect<A, PullRequestProviderError>,
508
- allowPaused = false,
513
+ alwaysInteractive = false,
514
) =>
515
(...args: Args) =>
511
- protect(operation, call(...args), allowPaused);
516
+ protect(operation, call(...args), alwaysInteractive);
517
const interactive = <Args extends ReadonlyArray<unknown>, A>(
518
operation: string,
519
call: (...args: Args) => Effect.Effect<A, PullRequestProviderError>,
apps/server/src/ws.ts
+5
-2
@@ -258,6 +258,7 @@ import * as VcsProjectConfig from "./vcs/VcsProjectConfig.ts";
258
import * as PairingGrantStore from "./auth/PairingGrantStore.ts";
259
import * as SessionStore from "./auth/SessionStore.ts";
260
import { failEnvironmentAuthInvalid, failEnvironmentInternal } from "./auth/http.ts";
261
+import * as SourceControlRateLimit from "@t3tools/source-control-core/server/SourceControlRateLimit";
262
import { isNetworkPath } from "@t3tools/shared/path";
263
import * as RelayClient from "@t3tools/shared/relayClient";
264
import {
@@ -1540,6 +1541,8 @@ export const layerWsRpc = (
1541
yield* SourceControlRepositoryService.SourceControlRepositoryService;
1542
const sourceControlSignIn = yield* SourceControlSignIn.SourceControlSignIn;
1543
const withPullRequestViewer = pullRequests.withRoutingCredential;
1544
+ // The panel's reads for a pull request the user opened go out during a rate-limit pause.
1545
+ const openedPullRequestRead = Effect.provideService(SourceControlRateLimit.Interactive, true);
1546
const bootstrapCredentials = yield* PairingGrantStore.PairingGrantStore;
1547
const sessions = yield* SessionStore.SessionStore;
1548
const processDiagnostics = yield* ProcessDiagnostics.ProcessDiagnostics;
@@ -2666,13 +2669,13 @@ export const layerWsRpc = (
2669
),
2670
),
2671
[WS_METHODS.pullRequestsDetail]: (input) =>
2669
- withPullRequestViewer(input, pullRequests.detail(input)),
2672
+ withPullRequestViewer(input, openedPullRequestRead(pullRequests.detail(input))),
2673
[WS_METHODS.pullRequestsPreview]: (input) =>
2674
withPullRequestViewer(input, pullRequests.preview(input)),
2675
[WS_METHODS.pullRequestsChecks]: (input) =>
2676
withPullRequestViewer(input, pullRequests.checks(input)),
2677
[WS_METHODS.pullRequestsActivity]: (input) =>
2675
- withPullRequestViewer(input, pullRequests.activity(input)),
2678
+ withPullRequestViewer(input, openedPullRequestRead(pullRequests.activity(input))),
2679
[WS_METHODS.pullRequestsReviewGuide]: (input) =>
2680
withPullRequestViewer(input, reviewGuides.get(input)),
2681
[WS_METHODS.pullRequestsGenerateReviewGuide]: (input) =>