@devries-cameron20 / t3code Mirror · read-only / commits / f5ca0f9427
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 21, 13:30 UTC

fix(server): wake GitLab MR watches when a rebase is required (#30312)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

tcrapts committed Nov 15, 2026 at 01:51 UTC f5ca0f9427e9b71b90bd9ad0ace130287739ff10
13 files changed +166 -4
apps/server/src/orchestration-v2/Orchestrator.ts
+1
@@ -5065,6 +5065,7 @@ const makeOrchestrator = Effect.fn("orchestrationV2.Orchestrator.layer")(functio
5065 passed: existing.endedWatch.passed,
5066 passedChecks: existing.endedWatch.passedChecks,
5067 conflicting: existing.endedWatch.conflicting,
5068 + rebaseRequired: existing.endedWatch.rebaseRequired,
5069 }),
5070 awaitingBaseline: existing.endedWatch
5071 ? existing.endedWatch.awaitingBaseline
apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts
+33
@@ -613,6 +613,39 @@ describe("PullRequestSyncReactor", () => {
613 }).pipe(Effect.provide(fixture.layer));
614 }),
615 );
616 + it.effect("syncs a rebase blocker even when the PR timestamp is unchanged", () =>
617 + Effect.scoped(
618 + Effect.gen(function* () {
619 + yield* TestClock.setTime(Date.parse(NOW));
620 + const required = yield* Ref.make(false);
621 + const fixture = yield* makeHarness({
622 + snapshot: makeSnapshot([makeThread("rebase", { pullRequests: [makeLink(7)] })]),
623 + summary: (input) =>
624 + Ref.get(required).pipe(
625 + Effect.map((rebaseRequired) => makeSummary(input, { rebaseRequired })),
626 + ),
627 + });
628 + yield* Effect.gen(function* () {
629 + const reactor = yield* startAndSweep(fixture);
630 + yield* applyRecordedSyncs(fixture);
631 + yield* Ref.set(required, true);
632 + yield* reactor.requestSync({
633 + host: "github.com",
634 + repository: "owner/repository",
635 + number: 7,
636 + });
637 + yield* Queue.take(fixture.snapshotReads);
638 + yield* reactor.drain;
639 + const commands = yield* Ref.get(fixture.syncCommands);
640 + assert.equal(commands.length, 2);
641 + assert.equal(commands[0]?.snapshot?.rebaseRequired, false);
642 + assert.equal(commands[1]?.snapshot?.rebaseRequired, true);
643 + assert.equal(commands[0]?.snapshot?.updatedAt, commands[1]?.snapshot?.updatedAt);
644 + }).pipe(Effect.provide(fixture.layer));
645 + }),
646 + ),
647 + );
648 +
649 it.effect("snapshots an unsynced link once and writes it to the thread", () =>
650 Effect.gen(function* () {
651 yield* TestClock.setTime(Date.parse(NOW));
apps/server/src/orchestration-v2/PullRequestSyncReactor.ts
+3 -1
@@ -234,6 +234,7 @@ function snapshotFieldsOf(summary: PullRequestSummary): SnapshotFields {
234 ...(summary.reviewDecision === undefined ? {} : { reviewDecision: summary.reviewDecision }),
235 ...(summary.checksState === undefined ? {} : { checksState: summary.checksState }),
236 ...(summary.mergeability === undefined ? {} : { mergeability: summary.mergeability }),
237 + ...(summary.rebaseRequired === undefined ? {} : { rebaseRequired: summary.rebaseRequired }),
238 };
239 }
240
@@ -282,7 +283,8 @@ function snapshotFieldsEqual(left: SnapshotFields, right: SnapshotFields): boole
283 left.changedFiles === right.changedFiles &&
284 (left.reviewDecision ?? null) === (right.reviewDecision ?? null) &&
285 (left.checksState ?? null) === (right.checksState ?? null) &&
285 - left.mergeability === right.mergeability
286 + left.mergeability === right.mergeability &&
287 + left.rebaseRequired === right.rebaseRequired
288 );
289 }
290
apps/server/src/orchestration-v2/PullRequestWatchReactor.ts
+2
@@ -151,6 +151,7 @@ const snapshotFingerprint = ({ link }: WatchTarget) => {
151 snapshot.updatedAt,
152 snapshot.checksState,
153 snapshot.mergeability,
154 + snapshot.rebaseRequired,
155 snapshot.reviewDecision,
156 snapshot.isDraft,
157 ].join(" ");
@@ -212,6 +213,7 @@ function watchesEqual(left: ThreadPullRequestWatch, right: ThreadPullRequestWatc
213 left.remarksThrough === right.remarksThrough &&
214 left.remarkIds.join("\n") === right.remarkIds.join("\n") &&
215 left.conflicting === right.conflicting &&
216 + left.rebaseRequired === right.rebaseRequired &&
217 left.mergeQueueRemovalId === right.mergeQueueRemovalId &&
218 left.wakes === right.wakes &&
219 left.awaitingBaseline === right.awaitingBaseline &&
apps/server/src/orchestration-v2/pullRequestWatch.test.ts
+47 -1
@@ -81,6 +81,45 @@ const remark = (
81 const noRemarks: ReadonlyArray<PullRequestComment> = [];
82
83 describe("evaluatePullRequestWatch", () => {
84 + it.each(["pending", "success"] as const)(
85 + "reports a required rebase once with %s CI",
86 + (status) => {
87 + const blocked = detail({
88 + mergeability: "unknown",
89 + rebaseRequired: true,
90 + checks: [check("test", status)],
91 + });
92 + const first = evaluatePullRequestWatch(watch(), blocked, noRemarks);
93 + assert.include(
94 + first.changes.map((change) => change.kind),
95 + "needs-rebase",
96 + );
97 + assert.deepEqual(evaluatePullRequestWatch(first.next, blocked, noRemarks).changes, []);
98 + const unknown = evaluatePullRequestWatch(
99 + first.next,
100 + { ...blocked, rebaseRequired: undefined },
101 + noRemarks,
102 + );
103 + assert.deepEqual(evaluatePullRequestWatch(unknown.next, blocked, noRemarks).changes, []);
104 + const clean = evaluatePullRequestWatch(
105 + first.next,
106 + { ...blocked, rebaseRequired: false },
107 + noRemarks,
108 + );
109 + assert.deepEqual(evaluatePullRequestWatch(clean.next, blocked, noRemarks).changes, [
110 + { kind: "needs-rebase" },
111 + ]);
112 + assert.include(
113 + evaluatePullRequestWatch(
114 + first.next,
115 + { ...blocked, headSha: "bbbbbbbbbb" },
116 + noRemarks,
117 + ).changes.map((change) => change.kind),
118 + "needs-rebase",
119 + );
120 + },
121 + );
122 +
123 it.each([false, true])("baselines already-passed checks (required: %s)", (required) => {
124 const green = detail({ checks: [{ ...check("test", "success"), required }] });
125 const baseline = evaluatePullRequestWatch(watch({ awaitingBaseline: "all" }), green, noRemarks);
@@ -115,6 +154,7 @@ describe("evaluatePullRequestWatch", () => {
154 const broken = detail({
155 checks: [check("lint", "failure"), check("test", "pending")],
156 mergeability: "conflicting",
157 + rebaseRequired: true,
158 });
159 const baseline = evaluatePullRequestWatch(
160 watch({ awaitingBaseline: "all" }),
@@ -125,6 +165,7 @@ describe("evaluatePullRequestWatch", () => {
165 assert.deepEqual(baseline.next.failedChecks, ["lint"]);
166 assert.isFalse(baseline.next.passed);
167 assert.isTrue(baseline.next.conflicting);
168 + assert.isTrue(baseline.next.rebaseRequired);
169 assert.deepEqual(evaluatePullRequestWatch(baseline.next, broken, noRemarks).changes, []);
170
171 const failed = evaluatePullRequestWatch(
@@ -135,11 +176,16 @@ describe("evaluatePullRequestWatch", () => {
176 assert.deepEqual(failed.changes, [
177 { kind: "checks-failed", failed: [check("test", "failure")] },
178 ]);
138 - const clean = evaluatePullRequestWatch(failed.next, detail(), noRemarks);
179 + const clean = evaluatePullRequestWatch(
180 + failed.next,
181 + detail({ rebaseRequired: false }),
182 + noRemarks,
183 + );
184 assert.deepEqual(clean.changes, []);
185 assert.deepEqual(evaluatePullRequestWatch(clean.next, broken, noRemarks).changes, [
186 { kind: "checks-failed", failed: [check("lint", "failure")] },
187 { kind: "conflicting" },
188 + { kind: "needs-rebase" },
189 ]);
190 });
191
apps/server/src/orchestration-v2/pullRequestWatch.ts
+13 -1
@@ -21,6 +21,7 @@ export type PullRequestWatchChange =
21 | { readonly kind: "remarks"; readonly remarks: ReadonlyArray<PullRequestComment> }
22 | { readonly kind: "no-checks"; readonly minutes: number }
23 | { readonly kind: "conflicting" }
24 + | { readonly kind: "needs-rebase" }
25 | { readonly kind: "merge-queue-removed"; readonly reason: string | null };
26
27 export interface PullRequestWatchReport {
@@ -46,6 +47,7 @@ export function evaluatePullRequestWatch(
47 | "mergeability"
48 | "viewer"
49 | "author"
50 + | "rebaseRequired"
51 | "mergeQueueRemoval"
52 >,
53 remarks: ReadonlyArray<PullRequestComment> | null,
@@ -196,11 +198,16 @@ export function evaluatePullRequestWatch(
198 ...atLatest.map((remark) => remark.id),
199 ];
200
199 - // Like a failed check, a conflict a push did not resolve is news for the new head.
201 + // Like a failed check, a conflict or rebase a push did not resolve is news for the new head.
202 const toldConflict = !headMoved && watch.conflicting;
203 if (watch.awaitingBaseline !== "all" && detail.mergeability === "conflicting" && !toldConflict) {
204 changes.push({ kind: "conflicting" });
205 }
206 + const toldRebase = !headMoved && watch.rebaseRequired === true;
207 + if (watch.awaitingBaseline !== "all" && detail.rebaseRequired === true && !toldRebase) {
208 + changes.push({ kind: "needs-rebase" });
209 + }
210 + const rebaseRequired = detail.rebaseRequired ?? watch.rebaseRequired;
211 // "unknown" is a host still computing after a push; only a clean answer clears a conflict.
212 const conflicting =
213 detail.mergeability === "unknown" ? toldConflict : detail.mergeability === "conflicting";
@@ -239,6 +246,7 @@ export function evaluatePullRequestWatch(
246 remarksThrough,
247 remarkIds,
248 conflicting,
249 + rebaseRequired,
250 mergeQueueRemovalId,
251 wakes,
252 // Only a read that cannot be trusted to show the checks leaves the baseline to the next one.
@@ -308,6 +316,8 @@ function changeLines(
316 return [
317 `- No checks have reported${context.commit} after ${change.minutes} minutes. None may be configured to run on this change.`,
318 ];
319 + case "needs-rebase":
320 + return [`- The branch requires a rebase onto ${context.baseBranch}.`];
321 case "conflicting":
322 return [`- The branch now conflicts with ${context.baseBranch}.`];
323 case "merge-queue-removed":
@@ -324,6 +334,7 @@ const SUMMARY: Record<PullRequestWatchChange["kind"], string> = {
334 remarks: "new comments",
335 "no-checks": "no checks reported",
336 conflicting: "merge conflict",
337 + "needs-rebase": "rebase required",
338 "merge-queue-removed": "removed from merge queue",
339 };
340
@@ -388,6 +399,7 @@ export function pullRequestWatchMessage(input: {
399 (change) =>
400 change.kind === "checks-failed" ||
401 change.kind === "conflicting" ||
402 + change.kind === "needs-rebase" ||
403 change.kind === "merge-queue-removed",
404 );
405 const summary = changes.map((change) => SUMMARY[change.kind]);
apps/server/src/pullRequest/PullRequestService.test.ts
+4
@@ -3458,6 +3458,7 @@ it.effect(
3458 Effect.succeed({
3459 ...changeRequest(1, "2026-07-02T00:00:00Z"),
3460 isDraft: true,
3461 + rebaseRequired: false,
3462 reviewDecision: "approved",
3463 checksState: "passing",
3464 }),
@@ -3467,6 +3468,7 @@ it.effect(
3468 deletions: 3,
3469 changedFiles: 5,
3470 mergeability: "conflicting",
3471 + rebaseRequired: true,
3472 }),
3473 }),
3474 ],
@@ -3474,6 +3476,8 @@ it.effect(
3476 yield* service.summary(reference);
3477 const detail = yield* service.detail(reference);
3478 const summary = yield* service.summary(reference);
3479 + assert.strictEqual(detail.rebaseRequired, true);
3480 + assert.strictEqual(summary.rebaseRequired, true);
3481 assert.strictEqual(summary.isDraft, false);
3482 assert.deepStrictEqual(summary.author, detail.author);
3483 assert.strictEqual(summary.additions, 14);
apps/server/src/pullRequest/PullRequestService.ts
+10
@@ -1309,6 +1309,9 @@ export const make = Effect.gen(function* () {
1309 state: input.item.state,
1310 isDraft: input.item.isDraft,
1311 mergeability: input.item.mergeability,
1312 + ...(input.item.rebaseRequired === undefined
1313 + ? {}
1314 + : { rebaseRequired: input.item.rebaseRequired }),
1315 additions: input.item.additions,
1316 deletions: input.item.deletions,
1317 createdAt: input.item.createdAt,
@@ -1792,6 +1795,9 @@ export const make = Effect.gen(function* () {
1795 ...(changeRequest.mergeability === undefined
1796 ? {}
1797 : { mergeability: changeRequest.mergeability }),
1798 + ...(changeRequest.rebaseRequired === undefined
1799 + ? {}
1800 + : { rebaseRequired: changeRequest.rebaseRequired }),
1801 ...(changeRequest.stack === undefined ? {} : { stack: changeRequest.stack }),
1802 ...(changeRequest.headSha?.trim() ? { headSha: changeRequest.headSha.trim() } : {}),
1803 ...(changeRequest.autoMergeEnabled === undefined
@@ -1891,6 +1897,9 @@ export const make = Effect.gen(function* () {
1897 state: changeRequest.state,
1898 isDraft: changeRequest.isDraft,
1899 mergeability: changeRequest.mergeability,
1900 + ...(changeRequest.rebaseRequired === undefined
1901 + ? {}
1902 + : { rebaseRequired: changeRequest.rebaseRequired }),
1903 additions: changeRequest.additions,
1904 deletions: changeRequest.deletions,
1905 changedFiles: changeRequest.changedFiles,
@@ -3330,6 +3339,7 @@ export const make = Effect.gen(function* () {
3339 deletions: detail.deletions,
3340 changedFiles: detail.changedFiles,
3341 mergeability: detail.mergeability,
3342 + ...(detail.rebaseRequired === undefined ? {} : { rebaseRequired: detail.rebaseRequired }),
3343 headBranch: detail.headBranch,
3344 baseBranch: detail.baseBranch,
3345 closedAt: detail.closedAt,
packages/contracts/src/pullRequest.ts
+3
@@ -370,6 +370,7 @@ export const PullRequestListEntry = Schema.Struct({
370 state: PullRequestState,
371 isDraft: Schema.Boolean,
372 mergeability: PullRequestMergeability,
373 + rebaseRequired: Schema.optional(Schema.Boolean),
374 /** Zero until fetched through `PullRequestListStatsInput`; GitHub listings omit counts. */
375 additions: NonNegativeInt,
376 deletions: NonNegativeInt,
@@ -528,6 +529,7 @@ export const PullRequestSummary = Schema.Struct({
529 reviewDecision: Schema.optional(Schema.NullOr(PullRequestReviewDecision)),
530 checksState: Schema.optional(Schema.NullOr(PullRequestChecksState)),
531 mergeability: Schema.optional(PullRequestMergeability),
532 + rebaseRequired: Schema.optional(Schema.Boolean),
533 /** Null when the host says the pull request is in no stack; absent when the read did not ask. */
534 stack: Schema.optional(Schema.NullOr(PullRequestStackMembership)),
535 headSha: Schema.optional(TrimmedNonEmptyString),
@@ -651,6 +653,7 @@ export const PullRequestDetail = Schema.Struct({
653 state: PullRequestState,
654 isDraft: Schema.Boolean,
655 mergeability: PullRequestMergeability,
656 + rebaseRequired: Schema.optional(Schema.Boolean),
657 additions: NonNegativeInt,
658 deletions: NonNegativeInt,
659 changedFiles: NonNegativeInt,
packages/contracts/src/threadPullRequest.ts
+2
@@ -51,6 +51,7 @@ export const ThreadPullRequestSnapshot = Schema.Struct({
51 reviewDecision: Schema.optional(Schema.NullOr(PullRequestReviewDecision)),
52 checksState: Schema.optional(Schema.NullOr(PullRequestChecksState)),
53 mergeability: Schema.optional(PullRequestMergeability),
54 + rebaseRequired: Schema.optional(Schema.Boolean),
55 });
56 export type ThreadPullRequestSnapshot = typeof ThreadPullRequestSnapshot.Type;
57
@@ -97,6 +98,7 @@ export const ThreadPullRequestWatch = Schema.Struct({
98 /** Reported remarks at remarksThrough, so late arrivals at that timestamp still count. */
99 remarkIds: Schema.Array(TrimmedNonEmptyString),
100 conflicting: Schema.Boolean,
101 + rebaseRequired: Schema.optional(Schema.Boolean),
102 /** Last removal seen; null after an empty read, absent before the first read. */
103 mergeQueueRemovalId: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
104 /** Consecutive comment-only wakes; limited to prevent bot loops. */
packages/source-control-core/src/server/PullRequestProvider.ts
+2
@@ -97,6 +97,7 @@ export interface ProviderChangeRequest {
97 readonly state: PullRequestState;
98 readonly isDraft: boolean;
99 readonly mergeability: PullRequestMergeability;
100 + readonly rebaseRequired?: boolean | undefined;
101 readonly additions: number;
102 readonly deletions: number;
103 readonly createdAt: string;
@@ -127,6 +128,7 @@ export interface ProviderChangeRequestSummary {
128 readonly reviewDecision?: PullRequestReviewDecision | null | undefined;
129 readonly checksState?: PullRequestChecksState | null | undefined;
130 readonly mergeability?: PullRequestMergeability | undefined;
131 + readonly rebaseRequired?: boolean | undefined;
132 /** Null means no stack; absent means not requested. */
133 readonly stack?: PullRequestStackMembership | null | undefined;
134 readonly headSha?: string | undefined;
packages/source-control-gitlab/src/server/gitLabMergeRequestJson.test.ts
+34
@@ -126,6 +126,37 @@ describe("decodeMergeRequestListJson", () => {
126 });
127
128 describe("decodeMergeRequestDetailJson", () => {
129 + it("preserves a required rebase while CI is running or successful", () => {
130 + for (const status of ["running", "success"]) {
131 + const detail = expectSuccess(
132 + decodeMergeRequestDetailJson(
133 + detailJson({
134 + merge_status: "can_be_merged",
135 + detailed_merge_status: "need_rebase",
136 + has_conflicts: false,
137 + head_pipeline: { status },
138 + }),
139 + ),
140 + );
141 + expect(detail.rebaseRequired).toBe(true);
142 + expect(detail.mergeability).toBe("mergeable");
143 + }
144 + });
145 +
146 + it("distinguishes a cleared rebase blocker from an inconclusive merge check", () => {
147 + expect(
148 + expectSuccess(
149 + decodeMergeRequestDetailJson(detailJson({ detailed_merge_status: "mergeable" })),
150 + ).rebaseRequired,
151 + ).toBe(false);
152 + for (const detailed_merge_status of [undefined, "checking", "ci_still_running"]) {
153 + expect(
154 + expectSuccess(decodeMergeRequestDetailJson(detailJson({ detailed_merge_status })))
155 + .rebaseRequired,
156 + ).toBeUndefined();
157 + }
158 + });
159 +
160 it("reads the description, file count and pipeline", () => {
161 const detail = expectSuccess(
162 decodeMergeRequestDetailJson(
@@ -1266,6 +1297,7 @@ describe("decodeMergeRequestWatchFingerprintJson", () => {
1297 mergeRequest: {
1298 state: "opened",
1299 mergeStatusEnum: "CAN_BE_MERGED",
1300 + detailedMergeStatus: "MERGEABLE",
1301 conflicts: false,
1302 diffHeadSha: "a".repeat(40),
1303 userPermissions: { updateMergeRequest: true },
@@ -1307,6 +1339,8 @@ describe("decodeMergeRequestWatchFingerprintJson", () => {
1339 expect(edited?.remarks).not.toBe(base?.remarks);
1340 expect(resolved?.remarks).toBe(base?.remarks);
1341 expect(read({ userNotesCount: 3 })?.remarks).not.toBe(base?.remarks);
1342 + // A target branch moving on leaves merge_status at can_be_merged on fast-forward projects.
1343 + expect(read({ detailedMergeStatus: "NEED_REBASE" })?.status).not.toBe(base?.status);
1344 });
1345
1346 // Only the REST read asks GitLab to recheck mergeability, and only for viewers who can update.
packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts
+12 -1
@@ -73,6 +73,7 @@ const RawMergeRequestSchema = Schema.Struct({
73 state: Schema.optional(Schema.NullOr(Schema.String)),
74 draft: Schema.optional(Schema.Boolean),
75 work_in_progress: Schema.optional(Schema.Boolean),
76 + detailed_merge_status: Schema.optional(Schema.NullOr(Schema.String)),
77 merge_status: Schema.optional(Schema.NullOr(Schema.String)),
78 has_conflicts: Schema.optional(Schema.NullOr(Schema.Boolean)),
79 created_at: Schema.String,
@@ -208,6 +209,7 @@ export interface GitLabMergeRequestListItem {
209 readonly state: PullRequestState;
210 readonly isDraft: boolean;
211 readonly mergeability: PullRequestMergeability;
212 + readonly rebaseRequired?: boolean | undefined;
213 readonly additions: number;
214 readonly deletions: number;
215 readonly createdAt: string;
@@ -484,6 +486,7 @@ export function decodePipelineStageChecksJson(
486 function toListItem(
487 raw: Schema.Schema.Type<typeof RawMergeRequestSchema>,
488 ): GitLabMergeRequestListItem {
489 + const detailedMergeStatus = raw.detailed_merge_status?.trim().toLowerCase();
490 return {
491 number: raw.iid,
492 title: raw.title,
@@ -494,6 +497,12 @@ function toListItem(
497 state: toState(raw),
498 isDraft: raw.draft ?? raw.work_in_progress ?? false,
499 mergeability: toMergeability(raw),
500 + rebaseRequired:
501 + detailedMergeStatus === "need_rebase"
502 + ? true
503 + : detailedMergeStatus === "mergeable"
504 + ? false
505 + : undefined,
506 additions: 0,
507 deletions: 0,
508 createdAt: raw.created_at,
@@ -2063,7 +2072,7 @@ export function decodeMergeRequestFileStatsJson(raw: string): Result.Result<
2072 export const MERGE_REQUEST_WATCH_FINGERPRINT_GRAPHQL_QUERY = `query($fullPath: ID!, $iid: String!) {
2073 project(fullPath: $fullPath) {
2074 mergeRequest(iid: $iid) {
2066 - state mergeStatusEnum conflicts diffHeadSha
2075 + state mergeStatusEnum detailedMergeStatus conflicts diffHeadSha
2076 userPermissions { updateMergeRequest }
2077 headPipeline {
2078 id status
@@ -2097,6 +2106,7 @@ const decodeMergeRequestWatchFingerprint = decodeJsonResult(
2106 Schema.Struct({
2107 state: Schema.String,
2108 mergeStatusEnum: Schema.NullOr(Schema.String),
2109 + detailedMergeStatus: Schema.optional(Schema.NullOr(Schema.String)),
2110 conflicts: Schema.Boolean,
2111 diffHeadSha: Schema.NullOr(Schema.String),
2112 userPermissions: Schema.Struct({ updateMergeRequest: Schema.Boolean }),
@@ -2182,6 +2192,7 @@ export function decodeMergeRequestWatchFingerprintJson(
2192 status: [
2193 mr.state,
2194 mr.mergeStatusEnum ?? "",
2195 + mr.detailedMergeStatus ?? "",
2196 mr.conflicts,
2197 mr.diffHeadSha ?? "",
2198 pipeline?.id ?? "",