Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: judge merge-gate checks by suite creation, not start (#12549)

[._.]/ Adam Eivyc4802d4d7178
diff --git a/server/lib/mergeGateAudit.js b/server/lib/mergeGateAudit.js
index 7ec92ff37b..342e09bffa 100644
--- a/server/lib/mergeGateAudit.js
+++ b/server/lib/mergeGateAudit.js
@@ -36,7 +36,7 @@ const time = (value) => {
* read, and no verdict is possible. An empty list is a repository with no CI on
* that head, which has nothing to wait for.
*
- * @param {Array<{name?: string, status?: string, conclusion?: string|null, started_at?: string|null, completed_at?: string|null}>|null} checks
+ * @param {Array<{name?: string, status?: string, conclusion?: string|null, created_at?: string|null, completed_at?: string|null}>|null} checks
* @param {string} mergedAt
* @returns {{ readable: boolean, notGreenAtMerge: string[], failing: string[], settled: boolean }}
*/
@@ -47,15 +47,17 @@ export function classifyHeadChecks(checks, mergedAt) {
const failing = [];
let settled = true;
for (const check of checks) {
+ // A run whose suite was created after the merge (a manual rerun, a scheduled
+ // workflow) was never something the merge could have waited for, so it can
+ // neither flag the merge nor drive a recovery. Judged by creation, not start:
+ // a check queued before the merge may not begin until well after it.
+ const createdMs = time(check?.created_at);
+ if (createdMs !== null && mergedMs !== null && createdMs > mergedMs + LEASE_CLOCK_SKEW_MS) continue;
const name = String(check?.name || 'unnamed check');
const completed = check?.status === 'completed';
const conclusion = String(check?.conclusion || '').toLowerCase();
if (!completed) settled = false;
if (completed && RED_CONCLUSIONS.has(conclusion)) failing.push(name);
- // A run created after the merge (a push workflow on the merge commit, a manual
- // rerun) was never something the merge could have waited for.
- const startedMs = time(check?.started_at);
- if (startedMs !== null && mergedMs !== null && startedMs > mergedMs + LEASE_CLOCK_SKEW_MS) continue;
const completedMs = time(check?.completed_at);
const greenBeforeMerge = completed && GREEN_CONCLUSIONS.has(conclusion)
&& mergedMs !== null && completedMs !== null && completedMs <= mergedMs;
diff --git a/server/services/mergeGateAudit.js b/server/services/mergeGateAudit.js
index b5a7d128ef..1c4b84394f 100644
--- a/server/services/mergeGateAudit.js
+++ b/server/services/mergeGateAudit.js
@@ -44,9 +44,9 @@ const watchKey = (repository, headSha) => `${repository}#${String(headSha).toLow
const readWatches = (app) => readList(app?.mergeGateWatches).filter((watch) => isPlainObject(watch) && watch.key);
// Commit statuses (CI that reports through the status API rather than check
-// runs) are mapped onto the check-run shape. A status has no start time worth
-// trusting: its `created_at` moves when the context flips pending to success.
-const CHECK_RUN_JQ = '.check_runs[] | {name, status, conclusion, started_at, completed_at}';
+// runs) are mapped onto the check-run shape.
+const CHECK_RUN_JQ = '.check_runs[] | {name, status, conclusion, suite: .check_suite.id, completed_at}';
+const CHECK_SUITE_JQ = '.check_suites[] | {id, created_at}';
const STATUS_JQ = '.statuses[] | {name: .context, status: (if .state == "pending" then "in_progress" else "completed" end), conclusion: (if .state == "error" then "failure" else .state end), completed_at: .updated_at}';
async function readGhLines({ origin, repoSpec, forgeExec, path, jq }) {
@@ -58,14 +58,21 @@ async function readGhLines({ origin, repoSpec, forgeExec, path, jq }) {
return rows.every(isPlainObject) ? rows : null;
}
-/** The check runs and commit statuses of `headSha`, or null when either could not be read. */
+/**
+ * The check runs and commit statuses of `headSha`, or null when any read failed.
+ * Each run carries its suite's `created_at`; a status has no creation time worth
+ * trusting (its context flips pending to success in place) and carries none.
+ */
async function readHeadCheckRuns({ origin, repoSpec, forgeExec, headSha }) {
const base = `repos/${origin.fullName}/commits/${headSha}`;
- const [runs, statuses] = await Promise.all([
+ const [runs, suites, statuses] = await Promise.all([
readGhLines({ origin, repoSpec, forgeExec, path: `${base}/check-runs?per_page=100`, jq: CHECK_RUN_JQ }),
+ readGhLines({ origin, repoSpec, forgeExec, path: `${base}/check-suites?per_page=100`, jq: CHECK_SUITE_JQ }),
readGhLines({ origin, repoSpec, forgeExec, path: `${base}/status?per_page=100`, jq: STATUS_JQ }),
]);
- return runs && statuses ? [...runs, ...statuses] : null;
+ if (!runs || !suites || !statuses) return null;
+ const created = new Map(suites.map((suite) => [suite.id, suite.created_at]));
+ return [...runs.map(({ suite, ...run }) => ({ ...run, created_at: created.get(suite) ?? null })), ...statuses];
}
async function readMergedPrs({ repoSpec, forgeExec, branch, since }) {
diff --git a/server/services/mergeGateAudit.test.js b/server/services/mergeGateAudit.test.js
index 73d93d4e23..a3b524678f 100644
--- a/server/services/mergeGateAudit.test.js
+++ b/server/services/mergeGateAudit.test.js
@@ -4,7 +4,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
// run's recorded lease history and the task queue are injected; the audit,
// the watch sweep and the pure assessment run for real.
const f = vi.hoisted(() => ({
- agent: null, apps: new Map(), tasks: [], prs: [], checks: [], statuses: [], held: null, addTaskFailures: 0,
+ agent: null, apps: new Map(), tasks: [], prs: [], checks: [], statuses: [], suites: [], held: null, addTaskFailures: 0,
}));
const execGhMock = vi.fn();
@@ -53,7 +53,7 @@ const MERGED_AT = '2026-10-20T02:16:47Z';
const task = { id: 'task-agent-1', metadata: { app: 'app1' } };
const run = (agentId = 'agent-1') => auditClaimMergeGate({ agentId, task, agentState: { ...f.agent, id: agentId } });
-const check = (overrides) => ({ name: 'build', status: 'completed', conclusion: 'success', completed_at: '2026-10-20T02:10:00Z', ...overrides });
+const check = (overrides) => ({ name: 'build', status: 'completed', conclusion: 'success', suite: 1, completed_at: '2026-10-20T02:10:00Z', ...overrides });
const lease = (overrides) => ({ repository: 'github.com/example/repo', outcome: 'merged',
acquiredAt: '2026-10-20T02:16:30Z', releasedAt: '2026-10-20T02:16:55Z', ...overrides });
@@ -68,6 +68,7 @@ beforeEach(() => {
f.prs = [{ number: 7, url: PR_URL, headRefOid: HEAD, mergedAt: MERGED_AT, baseRefName: 'main' }];
f.checks = [check()];
f.statuses = [];
+ f.suites = [{ id: 1, created_at: '2026-10-20T02:09:00Z' }, { id: 2, created_at: '2026-10-20T02:30:00Z' }];
f.addTaskFailures = 0;
addTaskMock.mockClear();
notifyMock.mockClear();
@@ -75,7 +76,8 @@ beforeEach(() => {
execGhMock.mockReset().mockImplementation(async (args) => {
if (args[0] === 'pr' && args[1] === 'list') return JSON.stringify(f.prs);
if (args[0] === 'api') {
- const rows = args.some((arg) => String(arg).includes('/status')) ? f.statuses : f.checks;
+ const path = args.find((arg) => String(arg).startsWith('repos/'));
+ const rows = path.includes('/check-suites') ? f.suites : path.includes('/status') ? f.statuses : f.checks;
if (rows === null) throw new Error('forge down');
return rows.map((c) => JSON.stringify(c)).join('\n');
}
@@ -172,7 +174,7 @@ describe('post-merge gate audit', () => {
f.checks = [
check(),
// A push workflow on the merge commit was never something the merge could wait for.
- check({ name: 'post-merge deploy', started_at: '2026-10-20T02:30:00Z', status: 'in_progress', conclusion: null, completed_at: null }),
+ check({ name: 'post-merge deploy', suite: 2, conclusion: 'failure', completed_at: '2026-10-20T02:31:00Z' }),
];
f.statuses = [{ name: 'ci/legacy', status: 'completed', conclusion: 'failure', completed_at: '2026-10-20T02:20:00Z' }];
await run();
@@ -180,6 +182,8 @@ describe('post-merge gate audit', () => {
codes: ['no-admission-lease', 'checks-not-green-at-merge'], notGreenAtMerge: ['ci/legacy'],
})]);
expect(f.tasks).toHaveLength(1);
+ expect(f.tasks[0].context).toContain('ci/legacy');
+ expect(f.tasks[0].context).not.toContain('post-merge deploy');
});
it('keeps an audit the forge could not answer and completes it from the durable sweep', async () => {