Skip to content

Commit d73eb23

Browse files
authored
fix(release): report seeded changelog provenance truthfully (#119897)
* fix(release): report seeded changelog provenance truthfully * fix(release): reject legacy provenance formatting * fix(release): enforce complete provenance records
1 parent 8c64ca2 commit d73eb23

9 files changed

Lines changed: 410 additions & 56 deletions

‎.agents/skills/openclaw-changelog-update/SKILL.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,17 @@ every human `Thanks @...` attribution.
6969
audit; it contains every referenced PR, eligible contributor credit,
7070
inline issue context, every direct commit, and an editorial-eligibility
7171
classification for PRs and direct commits
72+
- schema version 3 is the required ephemeral manifest contract. Regenerate
73+
older manifests; version 2 is not a supported downstream-reader boundary
7274
- for a historical backfill, add `--seed-ref <pre-backfill-ref>` once so
7375
contribution records from the prior changelog are retained even when an
7476
older merged commit omitted its PR number; the verifier excludes records
7577
for work reverted after the base tag, including beta work reverted before
7678
the stable release
79+
- generated provenance reports in-range PRs separately from retained
80+
seed-only PRs, then states the unique row total. A PR present in both
81+
inventories counts as in-range; never describe the seed-inclusive total
82+
as work merged in the current release range
7783
- add repeatable `--shipped-ref <prior-shipped-tag>` when the reachable main
7884
closeout differs from the shipped tag or later forward-port commits
7985
re-associate PRs that were already released. Each tag is a cumulative
@@ -150,6 +156,8 @@ every human `Thanks @...` attribution.
150156
PR references explicitly present in active commit subjects/bodies. It
151157
preserves author/co-author credit and any issue references in the original
152158
title
159+
- the provenance arithmetic and unique total must match the rendered PR
160+
rows exactly; candidate validation rejects malformed or forged counts
153161
- direct commits remain in the manifest with GitHub-resolved author,
154162
co-author, issue, and editorial-eligibility data. They inform grouped
155163
prose but are never rendered as a public `#### Direct commits` dump. Add

‎.agents/skills/openclaw-changelog-update/scripts/verify-release-notes.mjs‎

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import path from "node:path";
1414
import { pathToFileURL } from "node:url";
1515
import {
1616
extractChangelogReleaseSections,
17+
formatContributionRecordProvenance,
1718
formatShippedBaselineExclusions,
19+
parseContributionRecordProvenance,
1820
parseShippedBaselineExclusions,
1921
releaseNotesVersionForTag,
2022
verifyGithubReleaseNotes,
@@ -671,10 +673,8 @@ export function contributionRecordTarget(section) {
671673
if (recordStart < 0) {
672674
return undefined;
673675
}
674-
return section.source
675-
.slice(recordStart)
676-
.match(/^This audited record covers the complete \S+\.\.(?<target>[0-9a-f]{40}) history:/mu)
677-
?.groups?.target;
676+
const target = parseContributionRecordProvenance(section.source.slice(recordStart))?.target;
677+
return target && /^[0-9a-f]{40}$/u.test(target) ? target : undefined;
678678
}
679679

680680
export function pullRequestTitleFromCommitSubject(subject, number) {
@@ -688,19 +688,12 @@ function completeContributionRecord(section, label) {
688688
fail(`${label} is missing ### Complete contribution record`);
689689
}
690690
const recordSource = section.source.slice(recordStart);
691-
const provenance = recordSource.match(
692-
/^This audited record covers the complete \S+\.\.[0-9a-f]{40} history: (?<count>[0-9]+) merged PRs?\./mu,
693-
);
694-
if (!provenance?.groups?.count) {
691+
const provenance = parseContributionRecordProvenance(recordSource);
692+
if (!provenance || !/^[0-9a-f]{40}$/u.test(provenance.target)) {
695693
fail(`${label} is missing exact complete contribution record provenance`);
696694
}
697695
const record = contributionRecordFor(section);
698-
const declaredCount = Number(provenance.groups.count);
699-
if (record.pullRequests.size !== declaredCount) {
700-
fail(
701-
`${label} contribution record declares ${declaredCount} PRs but contains ${record.pullRequests.size}`,
702-
);
703-
}
696+
const declaredCount = provenance.uniquePullRequests;
704697
return { record, declaredCount };
705698
}
706699

@@ -2069,6 +2062,10 @@ export function ledgerFor(
20692062
!revertedReferences.has(entry.number),
20702063
);
20712064
const issues = entries.filter((entry) => entry.type === "Issue");
2065+
const inRangePullRequestNumbers = new Set([
2066+
...sourcePullRequests,
2067+
...[...sourceReferences].filter((number) => nodes.get(number)?.__typename === "PullRequest"),
2068+
]);
20722069
const legacyIssues = legacyIssuesByPullRequest(priorRecord, nodes);
20732070
const records = pullRequests.map((entry) => {
20742071
const priorEntry = priorRecord.pullRequests.get(entry.number);
@@ -2097,11 +2094,20 @@ export function ledgerFor(
20972094
thanks,
20982095
});
20992096
});
2097+
const inRangePullRequests = records.filter((entry) =>
2098+
inRangePullRequestNumbers.has(entry.number),
2099+
).length;
2100+
const retainedSeedOnlyPullRequests = records.length - inRangePullRequests;
2101+
const provenance = {
2102+
inRangePullRequests,
2103+
retainedSeedOnlyPullRequests,
2104+
uniquePullRequests: records.length,
2105+
};
21002106
const shippedBaselineLine = formatShippedBaselineExclusions(shippedBaselines);
21012107
const ledger = [
21022108
"### Complete contribution record",
21032109
"",
2104-
`This audited record covers the complete ${base}..${target} history: ${records.length} merged PRs. The generation manifest also supplies direct commits as editorial input; the grouped notes above prioritize user impact.`,
2110+
`${formatContributionRecordProvenance({ base, target, ...provenance })} The generation manifest also supplies direct commits as editorial input; the grouped notes above prioritize user impact.`,
21052111
...(shippedBaselineLine ? ["", shippedBaselineLine] : []),
21062112
"",
21072113
"#### Pull requests",
@@ -2113,6 +2119,7 @@ export function ledgerFor(
21132119
issues,
21142120
ledger,
21152121
pullRequests: records,
2122+
provenance,
21162123
titleReferences: titleReferences(records),
21172124
};
21182125
}
@@ -2176,6 +2183,22 @@ export function ledgerChecks(section, pullRequests, nodes, directCommits, shippe
21762183
return errors;
21772184
}
21782185
const ledger = section.source.slice(ledgerStart);
2186+
try {
2187+
const provenance = parseContributionRecordProvenance(ledger);
2188+
if (!provenance) {
2189+
errors.push("missing exact complete contribution record provenance");
2190+
} else if (
2191+
section.expectedProvenance &&
2192+
provenance.inRangePullRequests !== undefined &&
2193+
(provenance.inRangePullRequests !== section.expectedProvenance.inRangePullRequests ||
2194+
provenance.retainedSeedOnlyPullRequests !==
2195+
section.expectedProvenance.retainedSeedOnlyPullRequests)
2196+
) {
2197+
errors.push("contribution record provenance partition does not match generated inventory");
2198+
}
2199+
} catch (error) {
2200+
errors.push(error instanceof Error ? error.message : String(error));
2201+
}
21792202
const expectedShippedBaselineLine = formatShippedBaselineExclusions(shippedBaselines);
21802203
try {
21812204
const sectionShippedBaselineLine = formatShippedBaselineExclusions(
@@ -2312,15 +2335,15 @@ function manifestFor(options, source, ledger, directCommitRecords) {
23122335
}));
23132336
const unlinkedCommits = directCommits.filter((commit) => commit.references.length === 0);
23142337
return {
2315-
schemaVersion: 2,
2338+
schemaVersion: 3,
23162339
base: options.base,
23172340
target: options.target,
23182341
mergeBase: source.mergeBase,
23192342
version: options.version,
23202343
shippedBaselines: source.shippedBaselines,
23212344
source: {
23222345
references: ledger.entries.length,
2323-
pullRequests: ledger.pullRequests.length,
2346+
...ledger.provenance,
23242347
issues: ledger.issues.length,
23252348
directCommits: directCommits.length,
23262349
unlinkedCommits: unlinkedCommits.length,
@@ -2589,7 +2612,7 @@ function main() {
25892612
}
25902613

25912614
const errors = ledgerChecks(
2592-
candidateSection,
2615+
{ ...candidateSection, expectedProvenance: ledger.provenance },
25932616
ledger.pullRequests,
25942617
nodes,
25952618
relationships.directCommits,
@@ -2619,7 +2642,7 @@ function main() {
26192642
shippedBaselines: source.shippedBaselines,
26202643
source: {
26212644
references: references.length,
2622-
pullRequests: ledger.pullRequests.length,
2645+
...ledger.provenance,
26232646
issues: ledger.issues.length,
26242647
directCommits: manifest.directCommits.length,
26252648
unlinkedCommits: manifest.unlinkedCommits.length,
@@ -2642,7 +2665,7 @@ function main() {
26422665
? `, GitHub snapshot ${githubSnapshotState.hits} hits/${githubSnapshotState.misses} misses`
26432666
: "";
26442667
process.stdout.write(
2645-
`${options.version}: ${ledger.pullRequests.length} PRs, ${ledger.issues.length} issues, ${errors.length === 0 ? "verified" : `${errors.length} errors`}${snapshotSummary}\n`,
2668+
`${options.version}: ${ledger.provenance.uniquePullRequests} unique PRs (${ledger.provenance.inRangePullRequests} in-range + ${ledger.provenance.retainedSeedOnlyPullRequests} retained seed-only), ${ledger.issues.length} issues, ${errors.length === 0 ? "verified" : `${errors.length} errors`}${snapshotSummary}\n`,
26462669
);
26472670
}
26482671
if (errors.length > 0) {

‎scripts/release-candidate-checklist.mjs‎

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
extractChangelogReleaseSections,
3131
extractChangelogSection,
3232
formatShippedBaselineExclusions,
33+
parseContributionRecordProvenance,
3334
parseShippedBaselineExclusions,
3435
releaseNotesSectionForTag,
3536
releaseNotesVersionForTag,
@@ -751,36 +752,13 @@ function candidateContributionRecordPullRequests(
751752
Number(match.groups.number),
752753
);
753754
const rows = new Set(rowNumbers);
754-
if (rows.size !== rowNumbers.length) {
755-
const seen = new Set();
756-
const duplicates = rowNumbers.filter((number) => {
757-
if (seen.has(number)) {
758-
return true;
759-
}
760-
seen.add(number);
761-
return false;
762-
});
763-
throw new Error(
764-
`${label} contains duplicate contribution record PR rows: ${[...new Set(duplicates)]
765-
.map((number) => `#${number}`)
766-
.join(", ")}`,
767-
);
768-
}
755+
const provenance = parseContributionRecordProvenance(record);
769756
if (!requireExactProvenance) {
770757
return rows;
771758
}
772-
const provenance = record.match(
773-
/^This audited record covers the complete \S+\.\.[0-9a-f]{40} history: (?<count>[0-9]+) merged PRs?\./mu,
774-
);
775-
if (!provenance?.groups?.count) {
759+
if (!provenance || !/^[0-9a-f]{40}$/u.test(provenance.target)) {
776760
throw new Error(`${label} is missing exact complete contribution record provenance`);
777761
}
778-
const declaredCount = Number(provenance.groups.count);
779-
if (rows.size !== declaredCount) {
780-
throw new Error(
781-
`${label} contribution record declares ${declaredCount} PRs but contains ${rows.size}`,
782-
);
783-
}
784762
return rows;
785763
}
786764

@@ -884,12 +862,10 @@ export function validateCandidateChangelogProvenance({
884862
section,
885863
`CHANGELOG.md ## ${sectionVersion}`,
886864
);
887-
const provenance = record.match(
888-
/^This audited record covers the complete (?<base>\S+)\.\.(?<target>[0-9a-f]{40}) history:/mu,
889-
);
890-
const base = provenance?.groups?.base;
891-
const recordedTarget = provenance?.groups?.target;
892-
if (!base || !recordedTarget) {
865+
const provenance = parseContributionRecordProvenance(record);
866+
const base = provenance?.base;
867+
const recordedTarget = provenance?.target;
868+
if (!base || !recordedTarget || !/^[0-9a-f]{40}$/u.test(recordedTarget)) {
893869
throw new Error(
894870
`CHANGELOG.md ## ${sectionVersion} is missing exact complete contribution record provenance`,
895871
);

‎scripts/render-github-release-notes.d.mts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ export function extractChangelogSection(changelog: unknown, version: unknown): u
77
export function releaseNotesVersionForTag(tag: unknown): unknown;
88
export function formatShippedBaselineExclusions(baselines: ShippedBaselineExclusion[]): string;
99
export function parseShippedBaselineExclusions(section: string): ShippedBaselineExclusion[];
10+
export function formatContributionRecordProvenance(
11+
provenance: ContributionRecordProvenance,
12+
): string;
13+
export function parseContributionRecordProvenance(
14+
section: string,
15+
): ContributionRecordProvenance | undefined;
1016
export function dedicatedSectionVersionForTag(tag: unknown): unknown;
1117
export function releaseNotesSectionForTag(
1218
changelog: unknown,
@@ -69,3 +75,10 @@ export type ShippedBaselineExclusion = {
6975
count: number;
7076
pullRequests: number[];
7177
};
78+
export type ContributionRecordProvenance = {
79+
base: string;
80+
target: string;
81+
inRangePullRequests?: number;
82+
retainedSeedOnlyPullRequests?: number;
83+
uniquePullRequests: number;
84+
};

‎scripts/render-github-release-notes.mjs‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,62 @@ function validateTag(tag) {
4040
}
4141
}
4242

43+
export function formatContributionRecordProvenance(provenance) {
44+
const { base, target, inRangePullRequests, retainedSeedOnlyPullRequests } = provenance;
45+
if (inRangePullRequests === undefined || retainedSeedOnlyPullRequests === undefined) {
46+
fail("canonical contribution record provenance requires split PR counts");
47+
}
48+
const uniquePullRequests = inRangePullRequests + retainedSeedOnlyPullRequests;
49+
const count = (value) => value.toLocaleString("en-US");
50+
const prs = (value) => `PR${value === 1 ? "" : "s"}`;
51+
return `This audited record covers the complete ${base}..${target} history: ${count(inRangePullRequests)} in-range ${prs(inRangePullRequests)} + ${count(retainedSeedOnlyPullRequests)} retained seed-only ${prs(retainedSeedOnlyPullRequests)} = ${count(uniquePullRequests)} unique ${prs(uniquePullRequests)}.`;
52+
}
53+
export function parseContributionRecordProvenance(section) {
54+
const rows = Array.from(section.matchAll(/^- \*\*PR #(\d+)\*\*/gmu), (match) => Number(match[1]));
55+
const duplicate = rows.find((value, index) => rows.indexOf(value) !== index);
56+
if (duplicate !== undefined) {
57+
fail(`duplicate contribution record PR #${duplicate}`);
58+
}
59+
const line = section.match(/^This audited record covers the complete .+$/mu)?.[0];
60+
if (!line) {
61+
return undefined;
62+
}
63+
const canonical = line.match(
64+
/^This audited record covers the complete (?<base>\S+)\.\.(?<target>[0-9a-f]{40}) history: (?<inRange>0|[1-9][0-9]{0,2}(?:,[0-9]{3})*) in-range PRs? \+ (?<seedOnly>0|[1-9][0-9]{0,2}(?:,[0-9]{3})*) retained seed-only PRs? = (?<unique>0|[1-9][0-9]{0,2}(?:,[0-9]{3})*) unique PRs?\./u,
65+
);
66+
const legacy =
67+
canonical ??
68+
line.match(
69+
/^This audited record covers the complete (?<base>\S+)\.\.(?<target>\S+) history: (?<unique>[0-9]+) merged PRs?\./u,
70+
);
71+
if (!legacy?.groups) {
72+
fail("release contribution record provenance is malformed");
73+
}
74+
const number = (value) => Number(value.replaceAll(",", ""));
75+
const provenance = {
76+
base: legacy.groups.base,
77+
target: legacy.groups.target,
78+
uniquePullRequests: number(legacy.groups.unique),
79+
};
80+
if (canonical?.groups) {
81+
provenance.inRangePullRequests = number(canonical.groups.inRange);
82+
provenance.retainedSeedOnlyPullRequests = number(canonical.groups.seedOnly);
83+
if (
84+
provenance.inRangePullRequests + provenance.retainedSeedOnlyPullRequests !==
85+
provenance.uniquePullRequests
86+
) {
87+
fail("release contribution record provenance arithmetic is invalid");
88+
}
89+
}
90+
if (provenance.uniquePullRequests > 0 && !/^#### Pull requests\r?$/mu.test(section)) {
91+
fail("positive contribution record requires a Pull requests section");
92+
}
93+
if (rows.length !== provenance.uniquePullRequests) {
94+
fail(`contribution record row count ${rows.length} != ${provenance.uniquePullRequests}`);
95+
}
96+
return provenance;
97+
}
98+
4399
function githubReleaseBodySize(body) {
44100
return {
45101
characters: [...body].length,

‎test/scripts/release-candidate-checklist.test.ts‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,38 @@ describe("release candidate checklist", () => {
358358
targetSha,
359359
isAncestor: () => true,
360360
}),
361-
).toThrow("duplicate contribution record PR rows: #123");
361+
).toThrow("duplicate contribution record PR #123");
362+
});
363+
364+
it("rejects canonical provenance whose unique total does not match the PR rows", () => {
365+
const targetSha = "b".repeat(40);
366+
const changelog = [
367+
"# Changelog",
368+
"",
369+
"## 2026.7.1",
370+
"",
371+
"### Highlights",
372+
"",
373+
"- User-facing notes.",
374+
"",
375+
"### Complete contribution record",
376+
"",
377+
`This audited record covers the complete base..${targetSha} history: 1 in-range PR + 1 retained seed-only PR = 2 unique PRs.`,
378+
"",
379+
"#### Pull requests",
380+
"",
381+
"- **PR #123** fix: example.",
382+
].join("\n");
383+
384+
expect(() =>
385+
validateCandidateChangelogProvenance({
386+
changelog,
387+
version: "2026.7.1",
388+
tag: "v2026.7.1-beta.3",
389+
targetSha,
390+
isAncestor: () => true,
391+
}),
392+
).toThrow("contribution record row count 1 != 2");
362393
});
363394

364395
it("uses numbered historical record rows and skips Unreleased baseline rows", () => {
@@ -379,7 +410,7 @@ describe("release candidate checklist", () => {
379410
"",
380411
"### Complete contribution record",
381412
"",
382-
"This audited record covers the complete base..HEAD history: 0 merged PRs.",
413+
"This audited record covers the complete base..HEAD history: 1 merged PR.",
383414
"",
384415
"#### Pull requests",
385416
"",

0 commit comments

Comments
 (0)