Skip to content

Commit e095a6c

Browse files
committed
fix(server): preserve permanent PR failures during concurrent reads
1 parent c083167 commit e095a6c

2 files changed

Lines changed: 73 additions & 48 deletions

File tree

‎apps/server/src/orchestration-v2/PullRequestWatchReactor.ts‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -472,17 +472,23 @@ export const make = Effect.gen(function* () {
472472
const reference = referenceOf(group);
473473
// Invalidate cached reads before using the newer fingerprint; clients receive no notification.
474474
if (fingerprint !== null) yield* pullRequests.invalidate({ reference });
475-
const read = yield* Effect.exit(
476-
Effect.all(
477-
[
478-
pullRequests.detail({ ...reference, allowStale: false }),
475+
const [detailRead, activityRead] = yield* Effect.all(
476+
[
477+
Effect.exit(pullRequests.detail({ ...reference, allowStale: false })),
478+
Effect.exit(
479479
plan.activity
480480
? pullRequests.activity(reference).pipe(Effect.asSome)
481481
: Effect.succeed(Option.none<PullRequestActivity>()),
482-
],
483-
{ concurrency: 2 },
484-
),
482+
),
483+
],
484+
{ concurrency: 2 },
485485
);
486+
// Activity failures must not cancel or hide a permanent detail failure.
487+
const read = Exit.isFailure(detailRead)
488+
? Exit.failCause(detailRead.cause)
489+
: Exit.isFailure(activityRead)
490+
? Exit.failCause(activityRead.cause)
491+
: Exit.succeed([detailRead.value, activityRead.value] as const);
486492
if (Exit.isFailure(read)) {
487493
if (Cause.hasInterruptsOnly(read.cause)) return yield* Effect.failCause(read.cause);
488494
lastReads.delete(group.key);

‎apps/server/src/orchestration-v2/runtimeLayer.test.ts‎

Lines changed: 60 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3173,13 +3173,20 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
31733173
}),
31743174
);
31753175

3176-
it.effect.each(["failed", "not-found"] as const)(
3177-
"handles repeated host read failures: %s",
3178-
(reason) =>
3176+
it.effect.each([
3177+
{ reason: "failed", activityFails: false },
3178+
{ reason: "not-found", activityFails: false },
3179+
{ reason: "failed", activityFails: true },
3180+
{ reason: "not-found", activityFails: true },
3181+
] as const)(
3182+
"handles repeated host read failures: $reason (activity fails: $activityFails)",
3183+
({ reason, activityFails }) =>
31793184
Effect.gen(function* () {
31803185
const orchestrator = yield* Orchestrator.OrchestratorV2;
3181-
const threadId = ThreadId.make(`runtime-pull-request-watch-unreadable-${reason}`);
3182-
const projectId = ProjectId.make(`pr-watch-unreadable-project-${reason}`);
3186+
const threadId = ThreadId.make(
3187+
`runtime-pull-request-watch-unreadable-${reason}-${activityFails}`,
3188+
);
3189+
const projectId = ProjectId.make(`pr-watch-unreadable-project-${reason}-${activityFails}`);
31833190
yield* seedProject({
31843191
projectId,
31853192
title: "Watch unreadable",
@@ -3191,7 +3198,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
31913198
type: "thread.create",
31923199
createdBy: "user",
31933200
creationSource: "web",
3194-
commandId: CommandId.make(`pr-watch-unreadable-create-${reason}`),
3201+
commandId: CommandId.make(`pr-watch-unreadable-create-${reason}-${activityFails}`),
31953202
threadId,
31963203
projectId,
31973204
title: "Watch unreadable",
@@ -3203,7 +3210,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
32033210
});
32043211
yield* orchestrator.dispatch({
32053212
type: "thread.pull-request.watch",
3206-
commandId: CommandId.make(`pr-watch-unreadable-start-${reason}`),
3213+
commandId: CommandId.make(`pr-watch-unreadable-start-${reason}-${activityFails}`),
32073214
threadId,
32083215
host: "github.com",
32093216
repository: "pingdotgg/t3code",
@@ -3213,51 +3220,61 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
32133220
});
32143221
let disconnected = false;
32153222
let passed = false;
3223+
let genericFailure = false;
3224+
const activityFailures = yield* Queue.unbounded<void>();
3225+
const readFailure = (operation: string, failure: "failed" | "not-found") =>
3226+
new PullRequestOperationError({
3227+
operation,
3228+
detail: "host read failed",
3229+
cause: new PullRequestProviderError({
3230+
provider: SourceControlProviderKind.make("github"),
3231+
operation,
3232+
reason: failure,
3233+
detail: "host read failed",
3234+
}),
3235+
});
32163236
const reactor = yield* PullRequestWatchReactor.make.pipe(
32173237
Effect.provide(
32183238
Layer.mergeAll(
32193239
NodeServices.layer,
32203240
Layer.mock(PullRequestService.PullRequestService)({
32213241
watchFingerprint: () => Effect.succeed(null),
32223242
detail: () =>
3223-
disconnected
3224-
? Effect.fail(
3225-
new PullRequestOperationError({
3226-
operation: "detail",
3227-
detail: "host read failed",
3228-
cause: new PullRequestProviderError({
3229-
provider: SourceControlProviderKind.make("github"),
3230-
operation: "detail",
3231-
reason,
3232-
detail: "host read failed",
3243+
genericFailure
3244+
? Effect.die("host read failed")
3245+
: disconnected
3246+
? (activityFails ? Queue.take(activityFailures) : Effect.void).pipe(
3247+
Effect.andThen(Effect.fail(readFailure("detail", reason))),
3248+
)
3249+
: Effect.succeed({
3250+
...watchedPullRequestDetail({
3251+
projectId,
3252+
number: 8,
3253+
at: "2026-10-02T12:00:00.000Z",
32333254
}),
3255+
headSha: "abc1234def",
3256+
checks: [
3257+
{
3258+
name: "test",
3259+
status: passed ? ("success" as const) : ("pending" as const),
3260+
description: null,
3261+
url: null,
3262+
required: true,
3263+
},
3264+
],
32343265
}),
3266+
activity: () =>
3267+
disconnected && activityFails
3268+
? Queue.offer(activityFailures, undefined).pipe(
3269+
Effect.andThen(Effect.fail(readFailure("activity", "failed"))),
32353270
)
32363271
: Effect.succeed({
3237-
...watchedPullRequestDetail({
3238-
projectId,
3239-
number: 8,
3240-
at: "2026-10-02T12:00:00.000Z",
3241-
}),
3242-
headSha: "abc1234def",
3243-
checks: [
3244-
{
3245-
name: "test",
3246-
status: passed ? ("success" as const) : ("pending" as const),
3247-
description: null,
3248-
url: null,
3249-
required: true,
3250-
},
3251-
],
3272+
comments: [],
3273+
commentCount: 0,
3274+
commentsTruncated: false,
3275+
reviewThreads: [],
3276+
commits: [],
32523277
}),
3253-
activity: () =>
3254-
Effect.succeed({
3255-
comments: [],
3256-
commentCount: 0,
3257-
commentsTruncated: false,
3258-
reviewThreads: [],
3259-
commits: [],
3260-
}),
32613278
}),
32623279
),
32633280
),
@@ -3272,6 +3289,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
32723289
assert.deepEqual(yield* summaries, []);
32733290
disconnected = true;
32743291
for (let pass = 0; pass < 15; pass += 1) {
3292+
genericFailure = reason === "failed" && (pass === 0 || (pass >= 2 && pass <= 8));
32753293
yield* TestClock.adjust("2 minutes");
32763294
yield* sweep;
32773295
}
@@ -3285,6 +3303,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
32853303
assert.isDefined(thread?.pullRequests?.[0]?.watch);
32863304
assert.deepEqual(yield* summaries, []);
32873305
disconnected = false;
3306+
genericFailure = false;
32883307
passed = true;
32893308
yield* sweep;
32903309
assert.deepEqual(yield* summaries, ["#8: checks passed"]);
@@ -3293,7 +3312,7 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
32933312
assert.deepEqual(yield* summaries, ["#8: checks passed"]);
32943313
yield* orchestrator.dispatch({
32953314
type: "thread.pull-request.watch",
3296-
commandId: CommandId.make(`pr-watch-unreadable-stop-${reason}`),
3315+
commandId: CommandId.make(`pr-watch-unreadable-stop-${reason}-${activityFails}`),
32973316
threadId,
32983317
host: "github.com",
32993318
repository: "pingdotgg/t3code",

0 commit comments

Comments
 (0)