Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Master test runs reuse the landed pull request's passed full run again after a no-change master merge (GST-2927) (#9618)

Garry Tan0f5b0d51cb02
diff --git a/changelog.d/capy-squash-landing-reuse-same-tree-head.md b/changelog.d/capy-squash-landing-reuse-same-tree-head.md
new file mode 100644
index 0000000000..caedd60d46
--- /dev/null
+++ b/changelog.d/capy-squash-landing-reuse-same-tree-head.md
@@ -0,0 +1,4 @@
+**A pull request landed as one squashed commit now reuses its passed full test run on master again, even when master was merged into it with no file change just before landing.**
+
+### Fixed
+- `scripts/ci-reuse.ts`: a one-parent push to master looked for a passed full run only on the head GitHub names for the landed pull request. Landing first merges master into the branch, and when that merge changes no file the new head has the tested tree but only a pull-request run, so every landing ran Test and E2E in full again (about 18 minutes instead of about 4). The push's tree now decides, as in the remote gate. The newest full run on any head with that tree wins, and those heads are the pull request head, its first parents with the same tree and the heads of recent dispatch and push runs. A newer failed or in-progress full run on the tree still runs in full, and what counts as a complete full run is unchanged. A hand revert or direct push whose tree matches a passed full run now reuses it too. docs/ci-event-parity.md, "Master-push reuse", says so.
diff --git a/docs/ci-event-parity.md b/docs/ci-event-parity.md
index 3b881ad968..cadb19181b 100644
--- a/docs/ci-event-parity.md
+++ b/docs/ci-event-parity.md
@@ -135,14 +135,15 @@ complete full-suite run of the same workflow (`scripts/ci-reuse.ts`, in Test
The push must be a merge commit or a one-parent commit. A merge commit tries the
runs on its merged head first, newest first, then other heads with the same
-tree. A one-parent commit (a squashed landing) has no merged head, so only the
-landed pull request's own run counts: the heads GitHub names for the commit,
-with the push's tree. Every run on those heads is read, and the newest one
-decides, as in the
+tree. A one-parent commit (a squashed landing, a hand revert, a direct push) has
+no merged head, so its tree alone decides. The heads with that tree are the
+heads GitHub names for the commit, each with its first parents that still have
+the tree (a merge of master that changed no file leaves the full run on the
+commit before it), and the heads of recent dispatch and push runs. Every run on
+those heads is read, and the newest one decides, as in the
[remote gate](#remote-gate-reuse): if that run failed or is still running, the
push runs in full; a cancelled run, or one that skipped its full job, is passed
-over for the next older one. A one-parent commit no pull request names (a hand
-revert, a direct push) runs in full. Anything else, an API error or a
+over for the next older one. Anything else, an API error or a
partial, cancelled or diagnostic run included, leaves reuse unset, so the push
runs in full. A reusing push skips every full lane and both aggregates, records the
reused run in its summary, and runs the `reused-full-suite` job with the
diff --git a/scripts/ci-reuse.ts b/scripts/ci-reuse.ts
index b56862dbb7..a8230007a8 100644
--- a/scripts/ci-reuse.ts
+++ b/scripts/ci-reuse.ts
@@ -25,12 +25,13 @@
* full_corpus, order_hunt) skips the full-suite job, so (c) rejects it.
* Candidates on head M^2 (the merged PR head) come first, newest first; then
* recent successful dispatch and push runs whose head tree equals M's tree. S
- * has no merged head, so only the landed pull request's own run counts: a head
- * GitHub names for S (commits/<sha>/pulls) with S's tree, whose newest dispatch
- * or push run decides, as in the remote gate: a newer failed or in-progress
- * full run gives no reuse, a cancelled run or one that skipped the full job
- * looks further back. S with no pull request behind it, or whose lookup fails,
- * runs in full. Any API error, cancelled, failed or in-progress attempt,
+ * has no merged head, so its tree alone decides: the heads with S's tree are
+ * the heads GitHub names for S (commits/<sha>/pulls), each with the first
+ * parents that still have that tree (a merge of master that changed no file),
+ * and the heads of recent dispatch and push runs with that tree. Their newest
+ * dispatch or push run decides, as in the remote gate: a newer failed or
+ * in-progress full run gives no reuse, a cancelled run or one that skipped the
+ * full job looks further back. Any API error, cancelled, failed or in-progress attempt,
* missing or cheap artifact, tree mismatch or root commit gives reuse=false
* with a reason.
*
@@ -73,6 +74,8 @@ export interface ReuseDeps {
recentSuccessfulRuns(file: string): Promise<FullRun[]>;
/** Head commits of the pull requests GitHub associates with commit `sha` (a squashed landing names its pull request); a fork head's runs are refused like any fork run. */
pullHeads(sha: string): Promise<string[]>;
+ /** The newest workflow_dispatch and push runs of `file`, whatever their status (a failed run counts against its tree too). */
+ recentRuns(file: string): Promise<FullRun[]>;
jobs(runId: number, attempt: number): Promise<JobRow[]>;
artifact(runId: number, name: string): Promise<{ value?: unknown; reason?: string }>;
}
@@ -145,16 +148,50 @@ export async function decide(deps: ReuseDeps, p: Profile, sha: string, repo: str
}
/**
- * A one-parent push (a squashed landing) has no merged head, so only the landed pull request's own run can stand in:
- * the heads GitHub names for the commit, with the push's tree. Every run on those heads is read by head, and the
- * newest one decides. A push no pull request names (a hand revert, a direct push) always runs in full.
+ * A one-parent push (a squashed landing, a hand revert, a direct push) has no merged head, so its tree alone decides:
+ * the newest full run on any head with that tree, as in the remote gate. The landed pull request's head counts, and
+ * so do its first parents with the same tree, since a merge of master that changed no file leaves the full run on the
+ * commit before it.
*/
async function decideOneParent(deps: ReuseDeps, p: Profile, sha: string, tree: string, repo: string, rejected: Rejection[]): Promise<Decision> {
- const heads: string[] = [];
+ const seeds: string[] = [];
for (const head of new Set(await deps.pullHeads(sha))) {
- if (head !== sha && (await deps.commit(head)).tree === tree) heads.push(head);
+ let at = head;
+ for (let i = 0; i < MAX_FALLBACK_HEADS && at !== sha && !seeds.includes(at); i++) {
+ const c = await deps.commit(at);
+ if (c.tree !== tree) break;
+ seeds.push(at);
+ if (!c.parents[0]) break;
+ at = c.parents[0];
+ }
+ }
+ const found = await newestFullRun(deps, p, await sameTreeHeads(deps, p, tree, repo, seeds, sha), tree, repo, rejected);
+ if (found && !found.why) return accept(found.run, tree, rejected, `head ${found.run.head_sha.slice(0, 12)} (same tree as the one-parent push)`);
+ if (found?.why) return { reuse: false, reason: found.why.reason, detail: `the newest full run on tree ${tree} decides: ${found.why.detail}`, tree, rejected };
+ if (!rejected.length) return { reuse: false, reason: 'no_candidate', detail: `no ${p.workflow} workflow_dispatch or push run exists on a head with tree ${tree} (the pull request heads GitHub names for one-parent push ${sha} or recent runs)`, tree, rejected };
+ return { reuse: false, reason: rejected[0]!.reason, detail: rejected.map(r => r.detail).join('; '), tree, rejected };
+}
+
+/** `seeds` plus the heads of recent dispatch and push runs whose commit has `tree`, never `skip` (the push itself). */
+async function sameTreeHeads(deps: ReuseDeps, p: Profile, tree: string, repo: string, seeds: string[], skip?: string): Promise<string[]> {
+ const shas = [...seeds];
+ const trees = new Map<string, string>();
+ for (const run of (await deps.recentRuns(p.file)).sort((a, b) => b.id - a.id)) {
+ if (!isCandidate(run) || run.head_sha === skip || shas.includes(run.head_sha) || run.head_repository?.full_name !== repo || trees.has(run.head_sha)) continue;
+ if (trees.size >= MAX_FALLBACK_HEADS) break;
+ trees.set(run.head_sha, (await deps.commit(run.head_sha)).tree);
+ if (trees.get(run.head_sha) === tree) shas.push(run.head_sha);
}
- const runs = (await Promise.all(heads.map(async head => (await deps.runsForHead(p.file, head)).filter(r => r.head_sha === head && isCandidate(r) && r.head_repository?.full_name === repo)))).flat().sort((a, b) => b.id - a.id);
+ return shas;
+}
+
+/**
+ * The newest full run across `shas` that decides: a passed complete one (no `why`), or one in progress, failed or with
+ * a failed full job (`why` says which). A run that skipped its full job or lacks it (a diagnostic dispatch, a push
+ * that reused) and any other rejected run is recorded in `rejected` and passed over. Undefined when none decides.
+ */
+async function newestFullRun(deps: ReuseDeps, p: Profile, shas: string[], tree: string, repo: string, rejected: Rejection[]): Promise<{ run: FullRun; why?: Omit<Rejection, 'run_id'> } | undefined> {
+ const runs = (await Promise.all(shas.map(async sha => (await deps.runsForHead(p.file, sha)).filter(r => r.head_sha === sha && isCandidate(r) && r.head_repository?.full_name === repo)))).flat().sort((a, b) => b.id - a.id);
for (const run of runs) {
const full = (await deps.jobs(run.id, run.run_attempt)).filter(j => j.name === p.job);
if (full.some(j => j.conclusion === 'skipped') || (run.status === 'completed' && full.length === 0)) {
@@ -162,14 +199,10 @@ async function decideOneParent(deps: ReuseDeps, p: Profile, sha: string, tree: s
continue;
}
const why = await reject(deps, p, run, repo, tree, tree);
- if (!why) return accept(run, tree, rejected, `head ${run.head_sha.slice(0, 12)} (same tree as the one-parent push)`);
+ if (!why || why.reason === 'run_in_progress' || why.reason === 'run_failed' || why.reason === 'full_suite_not_success') return { run, why };
rejected.push({ run_id: run.id, ...why });
- if (why.reason === 'run_in_progress' || why.reason === 'run_failed' || why.reason === 'full_suite_not_success') {
- return { reuse: false, reason: why.reason, detail: `the newest full run on tree ${tree} decides: ${why.detail}`, tree, rejected };
- }
}
- if (!rejected.length) return { reuse: false, reason: 'no_candidate', detail: `no pull request GitHub names for one-parent push ${sha} has a head with tree ${tree} and a ${p.workflow} workflow_dispatch or push run`, tree, rejected };
- return { reuse: false, reason: rejected[0]!.reason, detail: rejected.map(r => r.detail).join('; '), tree, rejected };
+ return undefined;
}
function accept(run: FullRun, tree: string, rejected: Rejection[], where: string): Decision {
@@ -198,8 +231,6 @@ export interface ExecutedCounts { tests: number; failed: number; partial?: numbe
export const LEDGER_JOB = 'executed-receipts';
export interface GateDecision { state: GateState; detail: string; tests?: number; failed?: number; partial?: number; url?: string }
export interface GateDeps extends ReuseDeps {
- /** The newest workflow_dispatch and push runs of `file`, whatever their status (a failed run counts against its tree too). */
- recentRuns(file: string): Promise<FullRun[]>;
/** Executed (pass, fail) test identities in the run's executed-identities artifact, each job at its newest attempt (`ledgerAttempt` when an earlier attempt wrote it), or why they cannot be read. */
executed(run: FullRun): Promise<ExecutedCounts | { reason: string; transient?: boolean }>;
}
@@ -209,30 +240,13 @@ export async function decideGate(deps: GateDeps, p: Profile, head: string, tree:
try {
const headTree = (await deps.commit(head)).tree;
if (headTree !== tree) return { state: 'none', detail: `${p.workflow}: commit ${head} has tree ${headTree} on GitHub, not the working tree ${tree}` };
- const shas = [head];
- const trees = new Map<string, string>();
- for (const run of (await deps.recentRuns(p.file)).sort((a, b) => b.id - a.id)) {
- if (!isCandidate(run) || run.head_sha === head || run.head_repository?.full_name !== repo || trees.has(run.head_sha)) continue;
- if (trees.size >= MAX_FALLBACK_HEADS) break;
- trees.set(run.head_sha, (await deps.commit(run.head_sha)).tree);
- if (trees.get(run.head_sha) === tree) shas.push(run.head_sha);
- }
- const runs = (await Promise.all(shas.map(async sha => (await deps.runsForHead(p.file, sha)).filter(r => r.head_sha === sha && isCandidate(r))))).flat().sort((a, b) => b.id - a.id);
- for (const run of runs) {
- const full = (await deps.jobs(run.id, run.run_attempt)).filter(j => j.name === p.job);
- if (full.some(j => j.conclusion === 'skipped') || (run.status === 'completed' && full.length === 0)) {
- rejected.push({ run_id: run.id, reason: 'full_suite_missing', detail: `run ${run.id} attempt ${run.run_attempt} did not run ${p.job} (not a full-profile run)` });
- continue;
- }
- const why = await reject(deps, p, run, repo, tree, tree);
- if (!why) {
- const d = await gateAccept(deps, p, run, tree, repo);
- return d.state === 'rejected' && run.head_sha !== head ? { ...d, state: 'none' } : d;
- }
- if (why.reason === 'run_in_progress') return { state: 'pending', detail: `${p.workflow} ${why.detail}` };
- if (why.reason === 'run_failed' || why.reason === 'full_suite_not_success') return { state: 'failed', detail: `${p.workflow} ${why.detail}`, url: runUrl(repo, run) };
- rejected.push({ run_id: run.id, ...why });
+ const found = await newestFullRun(deps, p, await sameTreeHeads(deps, p, tree, repo, [head]), tree, repo, rejected);
+ if (found && !found.why) {
+ const d = await gateAccept(deps, p, found.run, tree, repo);
+ return d.state === 'rejected' && found.run.head_sha !== head ? { ...d, state: 'none' } : d;
}
+ if (found?.why?.reason === 'run_in_progress') return { state: 'pending', detail: `${p.workflow} ${found.why.detail}` };
+ if (found?.why) return { state: 'failed', detail: `${p.workflow} ${found.why.detail}`, url: runUrl(repo, found.run) };
} catch (e) {
return { state: 'none', detail: `${p.workflow}: reading commits, runs, jobs or artifacts failed: ${e instanceof Error ? e.message : String(e)}` };
}
@@ -334,6 +348,10 @@ export function apiDeps(client: GitHubClient): ReuseDeps {
async pullHeads(sha) {
return (await client.request<Array<{ head: { sha: string } }>>('GET', `repos/{repo}/commits/${sha}/pulls`)).map(pr => pr.head.sha);
},
+ async recentRuns(file) {
+ const pages = await Promise.all(CANDIDATE_EVENTS.map(event => client.request<{ workflow_runs: FullRun[] }>('GET', `repos/{repo}/actions/workflows/${file}/runs?event=${event}&per_page=100`)));
+ return pages.flatMap(p => p.workflow_runs);
+ },
jobs: (runId, attempt) => attemptJobs(client, runId, attempt),
artifact: (runId, name) => fetchArtifactJson(client, runId, name, TREE_FILE),
};
@@ -342,10 +360,6 @@ export function apiDeps(client: GitHubClient): ReuseDeps {
export function gateDeps(client: GitHubClient): GateDeps {
return {
...apiDeps(client),
- async recentRuns(file) {
- const pages = await Promise.all(CANDIDATE_EVENTS.map(event => client.request<{ workflow_runs: FullRun[] }>('GET', `repos/{repo}/actions/workflows/${file}/runs?event=${event}&per_page=100`)));
- return pages.flatMap(p => p.workflow_runs);
- },
async executed(run) {
const got = await fetchArtifactJson(client, run.id, 'executed-identities', 'executed-identities.json');
if (got.reason) return got.transient ? { reason: got.reason, transient: true } : { reason: got.reason };
diff --git a/test/scripts/ci-reuse.test.ts b/test/scripts/ci-reuse.test.ts
index 6091b92c04..fc0a958700 100644
--- a/test/scripts/ci-reuse.test.ts
+++ b/test/scripts/ci-reuse.test.ts
@@ -58,6 +58,7 @@ function fixture(f: Fixture): ReuseDeps & { jobCalls: string[] } {
return runs.filter(r => r.head_sha === sha);
},
async recentSuccessfulRuns() { return runs.filter(r => r.conclusion === 'success'); },
+ async recentRuns() { return runs; },
async pullHeads(sha) {
if (f.fail === 'pulls') throw new Error(`GitHub API GET commits/${sha}/pulls -> 502: bad gateway`);
return f.pulls?.[sha] ?? [];
@@ -279,14 +280,31 @@ describe('ci-reuse decision', () => {
expect(await decide(squash([prRun(), failedFork]), PROFILES.test, M, REPO)).toMatchObject({ reuse: true, source: { run_id: 500 } });
});
- test('a passed run on a same-tree head GitHub does not name for the commit runs in full', async () => {
+ test('#9577: a no-content merge of master made just before landing leaves the passed full run on the head before it, and that run is reused', async () => {
+ // The landed pull request's head H is a merge of master that changed no file, so it carries the tree the full
+ // run tested on H2 (its first parent) but only a cheap pull_request run of its own.
+ const MASTER = '5'.repeat(40);
+ const commits = { [M]: { tree: T, parents: [MASTER] }, [H]: { tree: T, parents: [H2, MASTER] }, [H2]: { tree: T, parents: [BASE, MASTER] }, [BASE]: { tree: OTHER, parents: [] }, [MASTER]: { tree: OTHER, parents: [] } };
+ const cheap = prRun({ id: 610, head_sha: H, event: 'pull_request' });
+ const full = prRun({ id: 500, head_sha: H2 });
+ const d = await decide(squash([cheap, full], { commits }), PROFILES.test, M, REPO);
+ expect(d).toMatchObject({ reuse: true, reason: 'identical_tree_full_run', tree: T, source: { run_id: 500, run_attempt: 1, sha: H2 } });
+ // The newest full run on the tree still decides: a newer failure on H2 refuses.
+ const failed = prRun({ id: 620, head_sha: H2, conclusion: 'failure' });
+ expect(await decide(squash([cheap, full, failed], { commits }), PROFILES.test, M, REPO)).toMatchObject({ reuse: false, reason: 'run_failed' });
+ });
+
+ test('a passed run on a same-tree head GitHub does not name for the commit (a hand-dispatched branch) is reused; a newer failure there refuses', async () => {
const elsewhere = prRun({ head_sha: H2 });
- expect(await decide(squash([elsewhere]), PROFILES.test, M, REPO)).toMatchObject({ reuse: false, reason: 'no_candidate' });
+ expect(await decide(squash([elsewhere]), PROFILES.test, M, REPO)).toMatchObject({ reuse: true, source: { run_id: 500, sha: H2 } });
expect(await decide(squash([elsewhere], { pulls: { [M]: [H2] } }), PROFILES.test, M, REPO)).toMatchObject({ reuse: true, source: { run_id: 500, sha: H2 } });
+ const failedElsewhere = prRun({ id: 600, head_sha: H2, conclusion: 'failure' });
+ expect(await decide(squash([prRun(), failedElsewhere]), PROFILES.test, M, REPO)).toMatchObject({ reuse: false, reason: 'run_failed' });
});
- test('a one-parent push with no pull request behind it (a hand revert, a direct push) runs in full', async () => {
- expect(await decide(squash([prRun()], { pulls: {} }), PROFILES.test, M, REPO)).toMatchObject({ reuse: false, reason: 'no_candidate' });
+ test('a one-parent push with no pull request behind it (a hand revert, a direct push) reuses a passed full run of its exact tree, and runs in full without one', async () => {
+ expect(await decide(squash([prRun()], { pulls: {} }), PROFILES.test, M, REPO)).toMatchObject({ reuse: true, source: { run_id: 500, sha: H } });
+ expect(await decide(squash([prRun({ head_sha: BASE })], { pulls: {} }), PROFILES.test, M, REPO)).toMatchObject({ reuse: false, reason: 'no_candidate' });
});
test('a named head with another tree never counts', async () => {
@@ -781,3 +799,9 @@ describe('ci-reuse remote-gate decision', () => {
expect(await decideGate(deps, PROFILES.test, M2, T, REPO)).toMatchObject({ state: 'reuse', tests: 600 });
});
});
+describe('docs/ci-event-parity.md', () => {
+ test('carries no paragraph cut short by a line-truncation marker', () => {
+ const doc = readFileSync(resolve(import.meta.dir, '../../docs/ci-event-parity.md'), 'utf8');
+ expect(doc).not.toMatch(/\(line truncated to \d+ chars\)/);
+ });
+});