Skip to content

Commit 4ba036d

Browse files
committed
fix(release): retry transient decision artifact reads
1 parent 9eca306 commit 4ba036d

14 files changed

Lines changed: 318 additions & 185 deletions

‎scripts/full-release-validation-at-sha.mts‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { pathToFileURL } from "node:url";
1212
import { parse as parseYaml } from "yaml";
1313
import { isRecord as isJsonRecord } from "../packages/normalization-core/src/record-coerce.ts";
1414
import {
15+
classifyReleaseGhTransportError,
1516
formatReleaseStateOutcome,
1617
validateReleaseStateArtifact,
1718
} from "./full-release-validation-policy.mjs";
@@ -74,6 +75,13 @@ type CommandOptions = {
7475
stdio?: "inherit" | ["ignore", "pipe" | "ignore", "pipe" | "inherit" | "ignore"];
7576
timeoutMs?: number;
7677
};
78+
type CommandStatus = {
79+
error?: Error;
80+
signal?: unknown;
81+
status: number | null;
82+
stderr: unknown;
83+
stdout: unknown;
84+
};
7785
type TemporaryRefParams = {
7886
keepBranch: boolean;
7987
dryRun: boolean;
@@ -588,15 +596,20 @@ export function releaseDecisionStopsForeground(state: unknown) {
588596
].includes(stringValue(state));
589597
}
590598

591-
function tryReadReleaseDecision(
599+
export function tryReadReleaseDecision(
592600
parentRunId: string,
593601
parentRunAttempt: number,
594602
workflowSha: string,
603+
runStatusImpl: (
604+
command: string,
605+
args: string[],
606+
options?: CommandOptions,
607+
) => CommandStatus = runStatus,
595608
) {
596609
const artifactName = `full-release-decision-${parentRunId}-${parentRunAttempt}`;
597610
const downloadDir = mkdtempSync(join(tmpdir(), "openclaw-release-decision-"));
598611
try {
599-
const result = runStatus(
612+
const result = runStatusImpl(
600613
"gh",
601614
[
602615
"run",
@@ -618,10 +631,31 @@ function tryReadReleaseDecision(
618631
) {
619632
return undefined;
620633
}
634+
const downloadError = Object.assign(
635+
result.error instanceof Error
636+
? result.error
637+
: new Error(
638+
`Release Decision artifact download failed${
639+
stderr.trim() ? `: ${stderr.trim().slice(0, 500)}` : ""
640+
}`,
641+
),
642+
{
643+
signal: result.signal,
644+
status: result.status,
645+
stderr,
646+
},
647+
);
648+
if (classifyReleaseGhTransportError(downloadError) === "transient") {
649+
console.warn(
650+
`Release Decision artifact unavailable this poll; retrying: ${downloadError.message}`,
651+
);
652+
return undefined;
653+
}
621654
throw new Error(
622655
`Release Decision artifact download failed${
623656
stderr.trim() ? `: ${stderr.trim().slice(0, 500)}` : ""
624657
}`,
658+
{ cause: downloadError },
625659
);
626660
}
627661
const decisionPath = join(downloadDir, RELEASE_DECISION_FILE);
Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,60 @@
1-
export const RELEASE_DECISION_STATES: readonly string[];
2-
export function buildReleaseExecutionPlan(input: Record<string, any>): {
3-
children: Array<Record<string, any>>;
4-
gates: Array<Record<string, any>>;
1+
export interface ReleaseRecord {
2+
[key: string]: unknown;
3+
}
4+
export interface ReleaseChild extends ReleaseRecord {
5+
key: string;
6+
runAttempt: number | null;
7+
runId: string;
8+
}
9+
export interface ReleaseExecutionPlan extends ReleaseRecord {
10+
children: ReleaseChild[];
11+
evidenceReuse: ReleaseRecord;
12+
gates: ReleaseRecord[];
13+
}
14+
export interface ReleaseStateArtifact extends ReleaseRecord {
15+
blockers: ReleaseRecord[];
16+
children: Record<string, ReleaseRecord>;
17+
errors: ReleaseRecord[];
18+
parentRunAttempt: number;
19+
sourceParentRunAttempt: number;
20+
state: string;
21+
}
22+
export type ReleaseGhTransportErrorClass = "hard" | "transient";
23+
export function classifyReleaseGhTransportError(error: unknown): ReleaseGhTransportErrorClass;
24+
export function buildReleaseExecutionPlan(input: ReleaseRecord): {
25+
children: ReleaseChild[];
26+
gates: ReleaseRecord[];
527
};
6-
export function buildReleaseExecutionPlanArtifact(input: Record<string, any>): Record<string, any>;
28+
export function buildReleaseExecutionPlanArtifact(input: ReleaseRecord): ReleaseExecutionPlan;
729
export function validateReleaseExecutionPlanArtifact(
830
payload: unknown,
931
expected?: Record<string, unknown>,
10-
): Record<string, any>;
11-
export function releaseExecutionPlanSha256(plan: Record<string, any>): string;
12-
13-
export function isReleaseCheckJobAdvisory(input: {
14-
jobName: string;
15-
releaseProfile: string;
16-
workflowRef: string;
17-
}): boolean;
18-
19-
export function failedJobsForPolicy(
20-
child: Record<string, any>,
21-
releaseProfile: string,
22-
workflowRef: string,
23-
): Array<Record<string, any>>;
32+
): ReleaseExecutionPlan;
33+
export function releaseExecutionPlanSha256(plan: ReleaseRecord): string;
2434

2535
export function terminalPolicyPass(
26-
child: Record<string, any>,
36+
child: ReleaseRecord,
2737
releaseProfile: string,
2838
workflowRef: string,
2939
): boolean;
3040

31-
export function classifyReleaseSnapshot(input: Record<string, any>): Record<string, any>;
32-
export function releasePlanGateFailures(
33-
gates: Array<Record<string, any>>,
34-
): Array<Record<string, any>>;
35-
export function buildReleaseStateArtifact(input: Record<string, any>): Record<string, any>;
41+
export function classifyReleaseSnapshot(input: ReleaseRecord): ReleaseStateArtifact;
42+
export function releasePlanGateFailures(gates: ReleaseRecord[]): ReleaseRecord[];
43+
export function buildReleaseStateArtifact(input: ReleaseRecord): ReleaseStateArtifact;
3644
export function validateReleaseStateArtifact(
3745
payload: unknown,
3846
expected?: Record<string, unknown>,
3947
expectedMode?: string,
40-
): Record<string, any>;
48+
): ReleaseStateArtifact;
4149
export function verifyReleaseStateArtifacts(
4250
executionPlanPayload: unknown,
4351
decisionPayload: unknown,
4452
drainPayload: unknown,
4553
expected?: Record<string, unknown>,
4654
): {
47-
decision: Record<string, any>;
48-
drain: Record<string, any>;
49-
executionPlan: Record<string, any>;
55+
decision: ReleaseStateArtifact;
56+
drain: ReleaseStateArtifact;
57+
executionPlan: ReleaseExecutionPlan;
5058
sourceAttempts: {
5159
decision: number;
5260
drain: number;
@@ -59,19 +67,18 @@ export function selectReleaseStateArtifacts(
5967
drainCandidates: Array<{ name: string; payload: unknown }>,
6068
expected?: Record<string, unknown>,
6169
): {
62-
decision: Record<string, any>;
63-
drain: Record<string, any>;
64-
executionPlan: Record<string, any>;
70+
decision: ReleaseStateArtifact;
71+
drain: ReleaseStateArtifact;
72+
executionPlan: ReleaseExecutionPlan;
6573
sourceAttempts: {
6674
decision: number;
6775
drain: number;
6876
executionPlan: number;
6977
};
7078
};
71-
export function releaseStateDetailLines(payload: Record<string, any>, maxItems?: number): string[];
72-
export function formatReleaseStateOutcome(payload: Record<string, any>): string;
79+
export function formatReleaseStateOutcome(payload: ReleaseRecord): string;
7380
export function affectedActiveRunIds(
74-
children: Array<Record<string, any>>,
75-
blockers: Array<Record<string, any>>,
81+
children: ReleaseRecord[],
82+
blockers: ReleaseRecord[],
7683
cancelledRunIds?: Set<string>,
7784
): string[];

‎scripts/full-release-validation-policy.mjs‎

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ const MAX_MESSAGE_LENGTH = 500;
88
const MAX_URL_LENGTH = 1024;
99
const EXACT_TARGET_EVIDENCE_REUSE_POLICY = "exact-target-full-validation-v1";
1010
const CHANGELOG_ONLY_EVIDENCE_REUSE_POLICY = "changelog-only-release-v1";
11+
const HARD_GH_TRANSPORT_PATTERN =
12+
/HTTP (?:401|403)\b|Bad credentials|authentication required|not authenticated|gh auth login|unknown (?:command|flag)|Usage: gh\b|ENOENT|EACCES/iu;
13+
const TRANSIENT_GH_TRANSPORT_PATTERN =
14+
/HTTP 429\b|HTTP 5[0-9][0-9]\b|Server Error|secondary rate limit|API rate limit|abuse detection|error connecting to|context deadline exceeded|connection reset by peer|connection refused|TLS handshake timeout|i\/o timeout|network is unreachable|unexpected EOF|ETIMEDOUT|ECONNRESET|EAI_AGAIN/iu;
1115

12-
export const RELEASE_DECISION_STATES = Object.freeze([
16+
const RELEASE_DECISION_STATES = Object.freeze([
1317
"qualifying",
1418
"blocked_diagnostics_running",
1519
"passed",
@@ -70,6 +74,42 @@ const CHILD_SPECS = Object.freeze([
7074
},
7175
]);
7276

77+
function releaseGhTransportErrorText(error) {
78+
const values = [error];
79+
const seen = new Set();
80+
const parts = [];
81+
while (values.length > 0) {
82+
const value = values.shift();
83+
if (value && typeof value === "object") {
84+
if (seen.has(value)) {
85+
continue;
86+
}
87+
seen.add(value);
88+
if (value instanceof Error) {
89+
parts.push(value.name, value.message);
90+
}
91+
for (const key of ["stderr", "stdout", "code", "signal", "cause"]) {
92+
if (key in value && value[key] !== undefined) {
93+
values.push(value[key]);
94+
}
95+
}
96+
continue;
97+
}
98+
if (value !== undefined && value !== null) {
99+
parts.push(String(value));
100+
}
101+
}
102+
return parts.join("\n");
103+
}
104+
105+
export function classifyReleaseGhTransportError(error) {
106+
const text = releaseGhTransportErrorText(error);
107+
if (HARD_GH_TRANSPORT_PATTERN.test(text)) {
108+
return "hard";
109+
}
110+
return TRANSIENT_GH_TRANSPORT_PATTERN.test(text) ? "transient" : "hard";
111+
}
112+
73113
function stringValue(value, fallback = "") {
74114
return typeof value === "string" ? value : fallback;
75115
}
@@ -193,7 +233,7 @@ function normalizedEvidenceReuse(evidenceReuse) {
193233
evidenceReuse.sourceManifest &&
194234
typeof evidenceReuse.sourceManifest === "object" &&
195235
!Array.isArray(evidenceReuse.sourceManifest)
196-
? JSON.parse(JSON.stringify(evidenceReuse.sourceManifest))
236+
? structuredClone(evidenceReuse.sourceManifest)
197237
: null,
198238
};
199239
}
@@ -356,7 +396,7 @@ function normalizeIssues(issues, fallbackKind) {
356396
.map((issue) => normalizeIssue(issue, fallbackKind));
357397
}
358398

359-
export function isReleaseCheckJobAdvisory({ jobName, releaseProfile, workflowRef }) {
399+
function isReleaseCheckJobAdvisory({ jobName, releaseProfile, workflowRef }) {
360400
if (
361401
jobName.startsWith("Run QA Lab parity lane (") ||
362402
jobName === "Run QA Lab parity report" ||
@@ -389,7 +429,7 @@ export function isReleaseCheckJobAdvisory({ jobName, releaseProfile, workflowRef
389429
);
390430
}
391431

392-
export function failedJobsForPolicy(child, releaseProfile, workflowRef) {
432+
function failedJobsForPolicy(child, releaseProfile, workflowRef) {
393433
return child.jobs.filter((job) => {
394434
if (
395435
job.status !== "completed" ||
@@ -671,7 +711,8 @@ function validatePlan(value) {
671711
});
672712
}
673713

674-
export function validateReleaseStateArtifact(payload, expected = {}, expectedMode) {
714+
export function validateReleaseStateArtifact(payload, expected, expectedMode) {
715+
const expectedValues = expected ?? {};
675716
if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
676717
throw new Error("release state artifact is invalid");
677718
}
@@ -688,17 +729,20 @@ export function validateReleaseStateArtifact(payload, expected = {}, expectedMod
688729
!/^[a-f0-9]{64}$/u.test(String(payload.executionPlanSha256 ?? "")) ||
689730
positiveInteger(payload.parentRunAttempt) === undefined ||
690731
positiveInteger(payload.sourceParentRunAttempt) === undefined ||
691-
(expected.parentRunId !== undefined &&
692-
String(payload.parentRunId) !== String(expected.parentRunId)) ||
693-
(expected.parentRunAttempt !== undefined &&
694-
Number(payload.parentRunAttempt) !== Number(expected.parentRunAttempt)) ||
695-
(expected.maxParentRunAttempt !== undefined &&
696-
Number(payload.parentRunAttempt) > Number(expected.maxParentRunAttempt)) ||
697-
(expected.workflowRef !== undefined && payload.workflowRef !== expected.workflowRef) ||
698-
(expected.workflowSha !== undefined && payload.workflowSha !== expected.workflowSha) ||
699-
(expected.targetSha !== undefined && payload.targetSha !== expected.targetSha) ||
700-
(expected.releaseProfile !== undefined && payload.releaseProfile !== expected.releaseProfile) ||
701-
(expected.rerunGroup !== undefined && payload.rerunGroup !== expected.rerunGroup)
732+
(expectedValues.parentRunId !== undefined &&
733+
String(payload.parentRunId) !== String(expectedValues.parentRunId)) ||
734+
(expectedValues.parentRunAttempt !== undefined &&
735+
Number(payload.parentRunAttempt) !== Number(expectedValues.parentRunAttempt)) ||
736+
(expectedValues.maxParentRunAttempt !== undefined &&
737+
Number(payload.parentRunAttempt) > Number(expectedValues.maxParentRunAttempt)) ||
738+
(expectedValues.workflowRef !== undefined &&
739+
payload.workflowRef !== expectedValues.workflowRef) ||
740+
(expectedValues.workflowSha !== undefined &&
741+
payload.workflowSha !== expectedValues.workflowSha) ||
742+
(expectedValues.targetSha !== undefined && payload.targetSha !== expectedValues.targetSha) ||
743+
(expectedValues.releaseProfile !== undefined &&
744+
payload.releaseProfile !== expectedValues.releaseProfile) ||
745+
(expectedValues.rerunGroup !== undefined && payload.rerunGroup !== expectedValues.rerunGroup)
702746
) {
703747
throw new Error("release state artifact binding is invalid");
704748
}
@@ -806,17 +850,15 @@ function verifyStateChildren(state, executionPlan, label) {
806850
if (snapshot.errors.length > 0) {
807851
throw new Error(`${label} child contains collector errors: ${child.key}`);
808852
}
809-
return {
810-
...child,
811-
...snapshot,
853+
return Object.assign({}, child, snapshot, {
812854
jobs: snapshot.timing.jobs.map((job) => ({
813855
conclusion: job.conclusion,
814856
html_url: job.url,
815857
name: job.name,
816858
status: job.status,
817859
url: job.url,
818860
})),
819-
};
861+
});
820862
});
821863
const recomputed = classifyReleaseSnapshot({
822864
children: snapshots,
@@ -929,8 +971,8 @@ function issueSummary(prefix, issue) {
929971
return `- ${prefix}: ${label}${result}${url}`;
930972
}
931973

932-
export function releaseStateDetailLines(payload, maxItems = MAX_SUMMARY_ISSUES) {
933-
const normalizedMax = Math.max(1, Math.min(Number(maxItems) || MAX_SUMMARY_ISSUES, 10));
974+
function releaseStateDetailLines(payload, maxItems = MAX_SUMMARY_ISSUES) {
975+
const normalizedMax = Math.max(1, Math.min(maxItems || MAX_SUMMARY_ISSUES, 10));
934976
const lines = [];
935977
for (const blocker of payload.blockers.slice(0, normalizedMax)) {
936978
lines.push(issueSummary("Blocker", blocker));

‎scripts/full-release-validation-state.d.mts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function validateChildBinding(
77
export function parsePlanInputs(value: string): Record<string, unknown>;
88
export function hydrateReusedPlan(
99
plan: Record<string, unknown>[],
10-
evidence: Record<string, any>,
10+
evidence: Record<string, unknown>,
1111
): Record<string, unknown>[];
1212
export function formatReleaseStateHeartbeat(
1313
mode: string,

0 commit comments

Comments
 (0)