Skip to content

Commit 4faca05

Browse files
committed
fix(release): verify original dispatch on parent recovery
1 parent d48f259 commit 4faca05

2 files changed

Lines changed: 108 additions & 16 deletions

File tree

‎scripts/release-ci-summary.mjs‎

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -996,11 +996,7 @@ function selectedAttemptParentJob(parentJobs, child, parentManifest) {
996996
if (currentJobs.length !== 1) {
997997
throw new Error(`manifest parent job is not unique at the selected attempt: ${child.name}`);
998998
}
999-
const currentJob = currentJobs[0];
1000-
if (currentJob.status !== "completed" || currentJob.conclusion !== "success") {
1001-
throw new Error(`manifest parent job is not completed/success: ${child.name}`);
1002-
}
1003-
return { currentJob, slotJobs };
999+
return { currentJob: currentJobs[0], slotJobs };
10041000
}
10051001

10061002
export function resolveManifestChildOriginAttempt(run, child, parentManifest, parentJobs) {
@@ -1018,6 +1014,9 @@ export function resolveManifestChildOriginAttempt(run, child, parentManifest, pa
10181014
}
10191015

10201016
const { currentJob, slotJobs } = selectedAttemptParentJob(parentJobs, child, parentManifest);
1017+
if (currentJob.status !== "completed" || currentJob.conclusion !== "success") {
1018+
throw new Error(`manifest parent job is not completed/success: ${child.name}`);
1019+
}
10211020
const currentFingerprint = JSON.stringify(parentJobExecutionFingerprint(currentJob));
10221021
const carriedOriginAttempts = slotJobs
10231022
.filter(
@@ -1033,12 +1032,14 @@ export function resolveManifestChildOriginAttempt(run, child, parentManifest, pa
10331032
: parentManifest.runAttempt;
10341033
}
10351034

1036-
export function selectManifestParentJob(parentJobs, child, parentManifest, originAttempt) {
1035+
export function selectManifestParentJob(
1036+
parentJobs,
1037+
child,
1038+
parentManifest,
1039+
originAttempt,
1040+
options = {},
1041+
) {
10371042
const { currentJob, slotJobs } = selectedAttemptParentJob(parentJobs, child, parentManifest);
1038-
if (originAttempt === parentManifest.runAttempt) {
1039-
return currentJob;
1040-
}
1041-
10421043
const originJobs = slotJobs.filter((job) => Number(job.run_attempt) === originAttempt);
10431044
if (originJobs.length !== 1) {
10441045
throw new Error(`manifest parent job origin is not unique: ${child.name}`);
@@ -1047,6 +1048,28 @@ export function selectManifestParentJob(parentJobs, child, parentManifest, origi
10471048
if (originJob.status !== "completed" || originJob.conclusion !== "success") {
10481049
throw new Error(`manifest parent job origin is not completed/success: ${child.name}`);
10491050
}
1051+
if (originAttempt === parentManifest.runAttempt) {
1052+
return originJob;
1053+
}
1054+
if (originAttempt > parentManifest.runAttempt) {
1055+
throw new Error(`manifest parent job origin attempt is invalid: ${child.name}`);
1056+
}
1057+
if (options.requireSkippedCarryForward === true) {
1058+
for (let attempt = originAttempt + 1; attempt <= parentManifest.runAttempt; attempt += 1) {
1059+
const carriedJobs = slotJobs.filter((job) => Number(job.run_attempt) === attempt);
1060+
if (carriedJobs.length !== 1) {
1061+
throw new Error(`manifest parent job carry-forward is not unique: ${child.name}`);
1062+
}
1063+
const carriedJob = carriedJobs[0];
1064+
if (carriedJob.status !== "completed" || carriedJob.conclusion !== "skipped") {
1065+
throw new Error(`manifest parent job was redispatched during recovery: ${child.name}`);
1066+
}
1067+
}
1068+
return originJob;
1069+
}
1070+
if (currentJob.status !== "completed" || currentJob.conclusion !== "success") {
1071+
throw new Error(`manifest parent job is not completed/success: ${child.name}`);
1072+
}
10501073
if (
10511074
JSON.stringify(parentJobExecutionFingerprint(currentJob)) !==
10521075
JSON.stringify(parentJobExecutionFingerprint(originJob))
@@ -1065,6 +1088,7 @@ export function validateManifestChildRun(
10651088
selectedParentJobLog,
10661089
repository,
10671090
plannedRunAttempt,
1091+
requireSkippedCarryForward = false,
10681092
) {
10691093
const targetRepository = repository ?? DEFAULT_REPO;
10701094
if (String(run.id) !== String(runId)) {
@@ -1101,7 +1125,9 @@ export function validateManifestChildRun(
11011125
if (childWorkflowPath !== `.github/workflows/${child.workflow}`) {
11021126
throw new Error(`manifest child workflow mismatch: ${child.name}`);
11031127
}
1104-
selectManifestParentJob(parentJobs, child, parentManifest, originAttempt);
1128+
selectManifestParentJob(parentJobs, child, parentManifest, originAttempt, {
1129+
requireSkippedCarryForward,
1130+
});
11051131
validateReleaseChildDispatchBinding({
11061132
child: {
11071133
key: child.manifestKey,
@@ -1697,6 +1723,7 @@ function validateStrictChildRun({
16971723
child,
16981724
parentEvidence.manifest,
16991725
originAttempt,
1726+
{ requireSkippedCarryForward: plannedChild !== undefined },
17001727
);
17011728
validateManifestChildRun(
17021729
run,
@@ -1707,6 +1734,7 @@ function validateStrictChildRun({
17071734
client.getJobLog(parentJob.id),
17081735
repository,
17091736
plannedChild?.runAttempt,
1737+
plannedChild !== undefined,
17101738
);
17111739
let jobs;
17121740
let composite;

‎test/scripts/release-ci-summary.test.ts‎

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { tmpdir } from "node:os";
55
import { dirname, join, resolve } from "node:path";
66
import { pathToFileURL } from "node:url";
77
import { expectDefined } from "@openclaw/normalization-core";
8-
import { describe, expect, it, vi } from "vitest";
8+
import { afterEach, describe, expect, it, vi } from "vitest";
99
import {
1010
buildReleaseExecutionPlanArtifact,
1111
releaseCompositeJobsSha256,
@@ -39,10 +39,12 @@ import {
3939
validateRequestedEvidenceReuse,
4040
validateTrustedProducerIdentity,
4141
} from "../../scripts/release-ci-summary.mjs";
42+
import { useAutoCleanupTempDirTracker } from "../helpers/temp-dir.js";
4243

4344
const SCRIPT = "scripts/release-ci-summary.mjs";
4445
const MANIFEST_ARTIFACT_ENTRY = "full-release-validation-manifest.json";
4546
const hasUnzip = spawnSync("unzip", ["-v"], { stdio: "ignore" }).status === 0;
47+
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
4648

4749
describe("GitHub API commands", () => {
4850
it("delegates authentication to gh for REST and artifact requests", () => {
@@ -340,7 +342,7 @@ describe("runReleaseCiGh", () => {
340342

341343
describe("Release execution plan artifact reads", () => {
342344
it("treats GitHub CLI 2.93 missing named artifacts as unavailable", () => {
343-
const root = mkdtempSync(join(tmpdir(), "release-plan-missing-artifact-"));
345+
const root = tempDirs.make("release-plan-missing-artifact-");
344346
const ghPath = join(root, "gh");
345347
writeFileSync(
346348
ghPath,
@@ -362,7 +364,6 @@ process.exit(1);
362364
} else {
363365
process.env.PATH = previousPath;
364366
}
365-
rmSync(root, { force: true, recursive: true });
366367
}
367368
});
368369
});
@@ -1302,17 +1303,42 @@ describe("release CI summary child correlation", () => {
13021303
};
13031304
manifest.executionPlanSha256 = String(executionPlan.sha256);
13041305
manifest.sourceParentRunAttempt = 1;
1306+
manifest.runAttempt = "2";
13051307
manifest.childEvidence = {
13061308
releaseChecks: releaseChecksEvidence,
13071309
};
1310+
fixture.parentRun.run_attempt = 2;
1311+
fixture.parentView.attempt = 2;
1312+
fixture.artifact.name = `full-release-validation-${fixture.runId}-2`;
1313+
const skippedParentJob = {
1314+
completed_at: "2026-08-22T00:02:00Z",
1315+
conclusion: "skipped",
1316+
id: fixture.parentJob.id + 1,
1317+
name: fixture.parentJob.name,
1318+
run_attempt: 2,
1319+
started_at: "2026-08-22T00:02:00Z",
1320+
status: "completed",
1321+
steps: [],
1322+
};
13081323
client.loadExecutionPlan = () => executionPlan;
1324+
client.loadManifest = (requestedRunId: string, requestedRunAttempt: number) => {
1325+
expect(requestedRunId).toBe(fixture.runId);
1326+
expect(requestedRunAttempt).toBe(2);
1327+
return { artifact: fixture.artifact, manifest };
1328+
};
1329+
client.getParentJobs = (requestedRunId: string) => {
1330+
expect(requestedRunId).toBe(fixture.runId);
1331+
return [fixture.parentJob, skippedParentJob];
1332+
};
13091333
client.getRunAttemptJobs = (_runId: string, attempt: number) =>
13101334
attempt === 1 ? [firstAttemptJob] : [secondAttemptJob];
1311-
fixture.client.getJobLog = () =>
1312-
[
1335+
fixture.client.getJobLog = (jobId: number) => {
1336+
expect(jobId).toBe(fixture.parentJob.id);
1337+
return [
13131338
`TARGET_SHA: ${fixture.targetSha}`,
13141339
`Dispatched openclaw-release-checks.yml: ${fixture.childRun.html_url} (attempt 1)`,
13151340
].join("\n");
1341+
};
13161342

13171343
const evidence = validateReleaseRunEvidence(
13181344
{
@@ -1359,6 +1385,44 @@ describe("release CI summary child correlation", () => {
13591385
).toThrow("execution plan child dispatch tuple mismatch");
13601386
});
13611387

1388+
it("rejects a parent recovery that reruns a sealed child dispatch slot", () => {
1389+
const child = expectedChildDispatches("28717729503", 2, "main").find(
1390+
(entry) => entry.manifestKey === "releaseChecks",
1391+
);
1392+
if (!child) {
1393+
throw new Error("missing release checks fixture");
1394+
}
1395+
const parentManifest = { runAttempt: 2, runId: "28717729503" };
1396+
const parentJobs = [
1397+
{
1398+
completed_at: "2026-08-22T00:01:00Z",
1399+
conclusion: "success",
1400+
id: 900,
1401+
name: child.parentJobName,
1402+
run_attempt: 1,
1403+
started_at: "2026-08-22T00:00:00Z",
1404+
status: "completed",
1405+
steps: [],
1406+
},
1407+
{
1408+
completed_at: "2026-08-22T00:02:00Z",
1409+
conclusion: "success",
1410+
id: 901,
1411+
name: child.parentJobName,
1412+
run_attempt: 2,
1413+
started_at: "2026-08-22T00:01:00Z",
1414+
status: "completed",
1415+
steps: [],
1416+
},
1417+
];
1418+
1419+
expect(() =>
1420+
selectManifestParentJob(parentJobs, child, parentManifest, 1, {
1421+
requireSkippedCarryForward: true,
1422+
}),
1423+
).toThrow("manifest parent job was redispatched during recovery");
1424+
});
1425+
13621426
it("accepts beta advisory release-check failures through canonical policy", () => {
13631427
const fixture = trustedMainPackageFixture();
13641428
fixture.manifest.releaseProfile = "beta";

0 commit comments

Comments
 (0)