The best way to control Claude Code, Codex and more from any computer or phone
fix(server): Forgejo checks keep the final status when it shares a second with a pending one (#24871)
Co-authored-by: maria-rcks <maria@kuuro.net>
fixfon committed
Oct 31, 2026 at 11:43 UTC
f7e55652dfdf39d03d885decf8183da2e5235fb8
4 files changed
+86
-2
packages/source-control-core/src/server/pullRequestChecks.test.ts
+40
-1
@@ -6,16 +6,22 @@ import { dedupeChecks } from "./pullRequestChecks.ts";
6
function entry(
7
name: string,
8
status: PullRequestCheckStatus,
9
- extra: { readonly workflowName?: string | null; readonly at?: string | null } = {},
9
+ extra: {
10
+ readonly workflowName?: string | null;
11
+ readonly at?: string | null;
12
+ readonly sequence?: number;
13
+ } = {},
14
): {
15
readonly check: PullRequestCheck;
16
readonly workflowName: string | null;
17
readonly at: string | null;
18
+ readonly sequence?: number;
19
} {
20
return {
21
check: { name, status, description: null, url: null },
22
workflowName: extra.workflowName ?? null,
23
at: extra.at ?? null,
24
+ ...(extra.sequence === undefined ? {} : { sequence: extra.sequence }),
25
};
26
}
27
@@ -53,6 +59,39 @@ describe("dedupeChecks", () => {
59
expect([forward[0]?.status, reversed[0]?.status]).toEqual(["failure", "failure"]);
60
});
61
62
+ it("takes the higher sequence when instants tie, whichever is listed first", () => {
63
+ const final = entry("build", "success", { at: "2026-10-12T10:14:29Z", sequence: 15 });
64
+ const pending = entry("build", "pending", { at: "2026-10-12T10:14:29Z", sequence: 14 });
65
+
66
+ expect(
67
+ [
68
+ [final, pending],
69
+ [pending, final],
70
+ ].map((runs) => dedupeChecks(runs)[0]?.status),
71
+ ).toEqual(["success", "success"]);
72
+ });
73
+
74
+ it("lets a newer instant win over a higher sequence", () => {
75
+ const stale = entry("build", "success", { at: "2026-10-12T10:14:29Z", sequence: 15 });
76
+ const fresh = entry("build", "failure", { at: "2026-10-12T10:14:30Z", sequence: 14 });
77
+
78
+ expect(
79
+ [
80
+ [stale, fresh],
81
+ [fresh, stale],
82
+ ].map((runs) => dedupeChecks(runs)[0]?.status),
83
+ ).toEqual(["failure", "failure"]);
84
+ });
85
+
86
+ it("takes the last copy for equal instants when only one run has a sequence", () => {
87
+ const checks = dedupeChecks([
88
+ entry("build", "success", { at: "2026-10-12T10:14:29Z", sequence: 15 }),
89
+ entry("build", "failure", { at: "2026-10-12T10:14:29Z" }),
90
+ ]);
91
+
92
+ expect(checks.map((check) => check.status)).toEqual(["failure"]);
93
+ });
94
+
95
it.each([
96
["2026-10-16", "2026-10-15T23:00:00-02:00", "success"],
97
["2026-10-16T00:00:00", "2026-10-15T23:00:00-02:00", "success"],
packages/source-control-core/src/server/pullRequestChecks.ts
+13
-1
@@ -55,13 +55,25 @@ export function dedupeChecks(
55
readonly check: PullRequestCheck;
56
readonly workflowName: string | null;
57
readonly at: string | null;
58
+ // Hosts with one-second timestamps can date a final and an earlier status alike.
59
+ readonly sequence?: number;
60
}>,
61
): ReadonlyArray<PullRequestCheck> {
62
const newestByCheck = new Map<string, (typeof entries)[number]>();
63
for (const entry of entries) {
64
const key = JSON.stringify([entry.workflowName ?? "", entry.check.name]);
65
const kept = newestByCheck.get(key);
64
- if (kept === undefined || isAtLeastAsNew(entry.at, kept.at)) newestByCheck.set(key, entry);
66
+ if (kept !== undefined) {
67
+ if (!isAtLeastAsNew(entry.at, kept.at)) continue;
68
+ if (
69
+ entry.sequence !== undefined &&
70
+ kept.sequence !== undefined &&
71
+ entry.sequence < kept.sequence &&
72
+ isAtLeastAsNew(kept.at, entry.at)
73
+ )
74
+ continue;
75
+ }
76
+ newestByCheck.set(key, entry);
77
}
78
const survivors = [...newestByCheck.values()];
79
const countsByName = new Map<string, number>();
packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts
+31
@@ -183,6 +183,37 @@ it("treats a required pattern's `*` as a wildcard even when the check name has o
183
);
184
});
185
186
+const tiedStatuses = [
187
+ { id: 15, status: "success" },
188
+ { id: 14, status: "pending" },
189
+].map(({ id, status }) => ({
190
+ id,
191
+ context: "ci/required-build",
192
+ status,
193
+ description: null,
194
+ target_url: null,
195
+ updated_at: "2026-10-12T10:14:29Z",
196
+}));
197
+
198
+it.effect.each([
199
+ ["newest first", tiedStatuses],
200
+ ["oldest first", tiedStatuses.toReversed()],
201
+] as const)("reads the status created last when two share a second, listed %s", ([, statuses]) =>
202
+ Effect.gen(function* () {
203
+ const provider = yield* ForgejoPullRequestProvider.make;
204
+ const readChecks = provider.getChangeRequestChecks;
205
+ if (readChecks === undefined) return yield* Effect.die("checks read missing");
206
+ const summary = yield* readChecks(requiredChecksInput);
207
+ const detail = yield* provider.getChangeRequest(requiredChecksInput);
208
+ for (const checks of [summary.checks, detail.checks]) {
209
+ assert.deepStrictEqual(
210
+ checks.map((check) => [check.name, check.status]),
211
+ [["ci/required-build", "success"]],
212
+ );
213
+ }
214
+ }).pipe(Effect.provide(requiredChecksLayer(Effect.succeed({}), statuses))),
215
+);
216
+
217
const forgejoMergeProvider = (repository: Effect.Effect<string, ForgejoCli.ForgejoCliError>) => {
218
const writes: Array<ForgejoCli.ForgejoApiInput> = [];
219
const provider = ForgejoPullRequestProvider.make.pipe(
packages/source-control-forgejo/src/server/forgejoPullRequestJson.ts
+2
@@ -103,6 +103,7 @@ export const ForgejoCommit = Schema.Struct({
103
),
104
});
105
export const ForgejoStatus = Schema.Struct({
106
+ id: Schema.optional(Schema.Int),
107
context: Schema.String,
108
status: Schema.String,
109
description: Schema.NullOr(Schema.String),
@@ -236,6 +237,7 @@ export function forgejoChecks(
237
statuses.map((status) => ({
238
workflowName: null,
239
at: status.updated_at,
240
+ ...(status.id === undefined ? {} : { sequence: status.id }),
241
check: {
242
name: status.context || "check",
243
description: status.description || null,