Skip to content

Commit fc66aab

Browse files
committed
fix(pull-requests): close review edge cases
1 parent 1b2312f commit fc66aab

7 files changed

Lines changed: 69 additions & 60 deletions

File tree

‎apps/server/src/orchestration/ThreadSettlementReactor.test.ts‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options:
154154
readonly number: number;
155155
}>
156156
>([]);
157+
const summaryRecovery = yield* Ref.make<ReadonlyArray<boolean | undefined>>([]);
157158

158159
const updateSettings = (patch: ServerSettingsPatch) =>
159160
Effect.gen(function* () {
@@ -168,18 +169,23 @@ const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options:
168169
Effect.andThen(options.branchPullRequest?.(input) ?? Effect.succeed(null)),
169170
);
170171

171-
const pullRequestSummary: PullRequestService["Service"]["summary"] = (input) =>
172-
Ref.update(summaryCalls, (calls) => [...calls, input]).pipe(
173-
Effect.andThen(
174-
options.pullRequestSummary?.(input) ??
172+
const pullRequestSummary: PullRequestService["Service"]["summary"] = (input, readOptions) =>
173+
Effect.gen(function* () {
174+
yield* Ref.update(summaryCalls, (calls) => [...calls, input]);
175+
yield* Ref.update(summaryRecovery, (values) => [
176+
...values,
177+
readOptions?.recoverTransientFailure,
178+
]);
179+
return yield* (
180+
options.pullRequestSummary?.(input, readOptions) ??
175181
Effect.succeed(
176182
makePullRequestSummary({
177183
...input,
178184
state: "open",
179185
}),
180-
),
181-
),
182-
);
186+
)
187+
);
188+
});
183189

184190
const dispatch: OrchestrationEngineShape["dispatch"] = (command) => {
185191
if (command.type !== "thread.auto-settle") {
@@ -231,6 +237,7 @@ const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options:
231237
commands,
232238
branchCalls,
233239
summaryCalls,
240+
summaryRecovery,
234241
updateSettings,
235242
layer: ThreadSettlementReactor.layer.pipe(Layer.provide(dependencies)),
236243
};
@@ -313,6 +320,7 @@ describe("ThreadSettlementReactor", () => {
313320
assert.deepStrictEqual(yield* Ref.get(fixture.summaryCalls), [
314321
{ projectId: LINKED_PROJECT_ID, repository: "owner/repository", number: 42 },
315322
]);
323+
assert.deepStrictEqual(yield* Ref.get(fixture.summaryRecovery), [false]);
316324
}).pipe(Effect.provide(fixture.layer));
317325
}),
318326
),

‎apps/server/src/orchestration/ThreadSettlementReactor.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,14 @@ export const make = Effect.gen(function* () {
6969
if (!projects.has(thread.linkedPullRequest.projectId)) {
7070
return yield* Effect.die(new Error("linked pull request project not found"));
7171
}
72-
const summary = yield* pullRequests.summary({
73-
projectId: thread.linkedPullRequest.projectId,
74-
repository: thread.linkedPullRequest.repository,
75-
number: thread.linkedPullRequest.number,
76-
});
72+
const summary = yield* pullRequests.summary(
73+
{
74+
projectId: thread.linkedPullRequest.projectId,
75+
repository: thread.linkedPullRequest.repository,
76+
number: thread.linkedPullRequest.number,
77+
},
78+
{ recoverTransientFailure: false },
79+
);
7780
return {
7881
state: summary.state,
7982
updatedAt: summary.updatedAt,

‎apps/server/src/pullRequest/PullRequestService.test.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2934,7 +2934,7 @@ it.effect(
29342934
}),
29352935
);
29362936

2937-
it.effect("shares linked summaries and keeps the last good value through a transient failure", () =>
2937+
it.effect("shares linked summaries and only recovers transient failures for display reads", () =>
29382938
Effect.gen(function* () {
29392939
let calls = 0;
29402940
let failing = false;
@@ -2973,9 +2973,14 @@ it.effect("shares linked summaries and keeps the last good value through a trans
29732973

29742974
yield* TestClock.adjust("61 seconds");
29752975
failing = true;
2976+
const strict = yield* Effect.flip(
2977+
service.summary(reference, { recoverTransientFailure: false }),
2978+
);
2979+
assert.strictEqual(strict._tag, "PullRequestOperationError");
2980+
29762981
const stale = yield* service.summary(reference);
29772982
assert.strictEqual(stale.updatedAt, "2026-07-02T00:00:00Z");
2978-
assert.strictEqual(calls, 2);
2983+
assert.strictEqual(calls, 3);
29792984

29802985
yield* service.invalidate({ reference });
29812986
const invalidated = yield* Effect.flip(service.summary(reference));

‎apps/server/src/pullRequest/PullRequestService.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export class PullRequestService extends Context.Service<
131131
) => Effect.Effect<PullRequestListStatsResult, PullRequestError>;
132132
readonly summary: (
133133
input: PullRequestRef,
134+
options?: { readonly recoverTransientFailure?: boolean },
134135
) => Effect.Effect<PullRequestSummary, PullRequestError>;
135136
readonly detail: (input: PullRequestRef) => Effect.Effect<PullRequestDetail, PullRequestError>;
136137
readonly activity: (
@@ -1073,6 +1074,11 @@ export const make = Effect.gen(function* () {
10731074
Effect.flatMap((page) =>
10741075
Effect.flatMap(Clock.currentTimeMillis, (now) => {
10751076
const rows = new Map<string, Array<ProviderChangeRequest>>();
1077+
for (const [key, visibleAt] of searchVisibleAt) {
1078+
if (now - visibleAt > Duration.toMillis(SEARCH_VISIBILITY_TTL)) {
1079+
searchVisibleAt.delete(key);
1080+
}
1081+
}
10761082
for (const item of page.items) {
10771083
const key = item.repository.trim().toLowerCase();
10781084
const held = rows.get(key);
@@ -2039,9 +2045,10 @@ export const make = Effect.gen(function* () {
20392045
timeToLive: (exit) => (Exit.isSuccess(exit) ? SUMMARY_CACHE_TTL : Duration.zero),
20402046
},
20412047
);
2042-
const summary: PullRequestService["Service"]["summary"] = (input) => {
2048+
const summary: PullRequestService["Service"]["summary"] = (input, options) => {
20432049
const key = refCacheKey(input);
2044-
return lastGoodSummary.read(key, Cache.get(summaryCache, key));
2050+
const cached = Cache.get(summaryCache, key);
2051+
return options?.recoverTransientFailure === false ? cached : lastGoodSummary.read(key, cached);
20452052
};
20462053

20472054
// Keys serialize positionally and parse back in the lookup, so the cache is the only holder

‎apps/server/src/vcs/VcsProcess.test.ts‎

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,42 +49,40 @@ const captureProcessResult = (
4949
);
5050

5151
describe("VcsProcess.run", () => {
52-
it.effect("bounds a synthetic burst of GitHub API processes", () =>
52+
it.effect("bounds a synthetic burst of GitHub API processes across service instances", () =>
5353
Effect.gen(function* () {
5454
const gate = yield* Deferred.make<void>();
5555
const starts = yield* Queue.unbounded<number>();
5656
const active = yield* Ref.make(0);
5757
const peak = yield* Ref.make(0);
5858
const total = yield* Ref.make(0);
59-
const service = yield* VcsProcess.make.pipe(
60-
Effect.provideService(
61-
ProcessRunner.ProcessRunner,
62-
ProcessRunner.ProcessRunner.of({
63-
run: () =>
64-
Effect.gen(function* () {
65-
const count = yield* Ref.updateAndGet(active, (held) => held + 1);
66-
yield* Ref.update(peak, (held) => Math.max(held, count));
67-
yield* Ref.update(total, (held) => held + 1);
68-
yield* Queue.offer(starts, count);
69-
yield* Deferred.await(gate);
70-
return {
71-
stdout: "",
72-
stderr: "",
73-
code: ChildProcessSpawner.ExitCode(0),
74-
timedOut: false,
75-
stdoutTruncated: false,
76-
stderrTruncated: false,
77-
stdoutInvalidUtf8: false,
78-
stderrInvalidUtf8: false,
79-
};
80-
}).pipe(Effect.ensuring(Ref.update(active, (count) => count - 1))),
81-
}),
82-
),
83-
);
59+
const processRunner = ProcessRunner.ProcessRunner.of({
60+
run: () =>
61+
Effect.gen(function* () {
62+
const count = yield* Ref.updateAndGet(active, (held) => held + 1);
63+
yield* Ref.update(peak, (held) => Math.max(held, count));
64+
yield* Ref.update(total, (held) => held + 1);
65+
yield* Queue.offer(starts, count);
66+
yield* Deferred.await(gate);
67+
return {
68+
stdout: "",
69+
stderr: "",
70+
code: ChildProcessSpawner.ExitCode(0),
71+
timedOut: false,
72+
stdoutTruncated: false,
73+
stderrTruncated: false,
74+
stdoutInvalidUtf8: false,
75+
stderrInvalidUtf8: false,
76+
};
77+
}).pipe(Effect.ensuring(Ref.update(active, (count) => count - 1))),
78+
});
79+
const services = yield* Effect.all([VcsProcess.make, VcsProcess.make], {
80+
concurrency: "unbounded",
81+
}).pipe(Effect.provideService(ProcessRunner.ProcessRunner, processRunner));
8482

8583
const burst = yield* Effect.all(
8684
Array.from({ length: 32 }, (_, index) =>
87-
service.run({
85+
services[index % services.length]!.run({
8886
operation: `synthetic.github.${index}`,
8987
command: "gh",
9088
args: ["api", "user"],

‎apps/server/src/vcs/VcsProcess.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const DEFAULT_MAX_OUTPUT_BYTES = 1_000_000;
5555
const OUTPUT_TRUNCATED_MARKER = "\n\n[truncated]";
5656
const VCS_PROCESS_CONCURRENCY = 8;
5757
const GITHUB_PROCESS_CONCURRENCY = 4;
58+
// These limits protect the Node process, including independently built server layer branches.
59+
const vcsProcesses = Semaphore.makeUnsafe(VCS_PROCESS_CONCURRENCY);
60+
const githubProcesses = Semaphore.makeUnsafe(GITHUB_PROCESS_CONCURRENCY);
5861

5962
const classifyNonZeroExit = (command: string, stderr: string): VcsProcessExitFailureKind => {
6063
const normalized = stderr.toLowerCase();
@@ -104,8 +107,6 @@ const classifyNonZeroExit = (command: string, stderr: string): VcsProcessExitFai
104107

105108
export const make = Effect.gen(function* () {
106109
const processRunner = yield* ProcessRunner.ProcessRunner;
107-
const vcsProcesses = yield* Semaphore.make(VCS_PROCESS_CONCURRENCY);
108-
const githubProcesses = yield* Semaphore.make(GITHUB_PROCESS_CONCURRENCY);
109110

110111
const runUnbounded = Effect.fn("VcsProcess.runUnbounded")(function* (input: VcsProcessInput) {
111112
const baseError = {

‎packages/client-runtime/src/state/pullRequests.ts‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,7 @@ export class EnvironmentHttpConnectionNotReadyError extends Data.TaggedError(
2727
"EnvironmentHttpConnectionNotReadyError",
2828
)<{ readonly message: string }> {}
2929

30-
export const LINKED_PULL_REQUEST_DETAIL_IDLE_TTL_MS = 5_000;
31-
32-
/** Refresh a linked PR while its thread is visible so merges update the sidebar. */
33-
export function createLinkedPullRequestDetailAtomFamily<R, E>(
34-
runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,
35-
) {
36-
return createEnvironmentRpcQueryAtomFamily(runtime, {
37-
label: "environment-data:pull-requests:linked-detail",
38-
tag: WS_METHODS.pullRequestsDetail,
39-
staleTimeMs: 15_000,
40-
refreshIntervalMs: 30_000,
41-
idleTtlMs: LINKED_PULL_REQUEST_DETAIL_IDLE_TTL_MS,
42-
});
43-
}
30+
export const LINKED_PULL_REQUEST_IDLE_TTL_MS = 5_000;
4431

4532
/** Refresh only the live fields a linked thread renders. */
4633
export function createLinkedPullRequestSummaryAtomFamily<R, E>(
@@ -51,7 +38,7 @@ export function createLinkedPullRequestSummaryAtomFamily<R, E>(
5138
tag: WS_METHODS.pullRequestsSummary,
5239
staleTimeMs: 60_000,
5340
refreshIntervalMs: 60_000,
54-
idleTtlMs: LINKED_PULL_REQUEST_DETAIL_IDLE_TTL_MS,
41+
idleTtlMs: LINKED_PULL_REQUEST_IDLE_TTL_MS,
5542
});
5643
}
5744

0 commit comments

Comments
 (0)