Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/gstack-doctor-components.sh
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ gstack_result_anchor() {
RECEIPT_CARRY_REFUSED) printf '%s' 'receipt-carry-refused' ;;
PROSE_LINT_FOUND) printf '%s' 'prose-lint-found' ;;
REVIEW_LOOP_EXCEPTION_INVALID) printf '%s' 'review-loop-exception-invalid' ;;
CI_CARRY_RERUN_MALFORMED) printf '%s' 'ci-carry-rerun-malformed' ;;
RECEIPT_CARRY_TREE_MISMATCH) printf '%s' 'receipt-carry-tree-mismatch' ;;
RECEIPT_CARRY_PRODUCT_CHANGED) printf '%s' 'receipt-carry-product-changed' ;;
RECEIPT_CARRY_SCOPED_REVIEW) printf '%s' 'receipt-carry-scoped-review' ;;
Expand Down
21 changes: 15 additions & 6 deletions bin/gstack-evidence
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ import { isUnavailable, loadPolicyFromBase, resolveBaseBranch } from "../lib/shi
import { versionAtRef } from "../lib/restamp";
import { bashCommandInvocation, runScriptSync, wtreeFingerprint } from "../lib/script-invocation";
import { carriedFromLine, findCarry, laneMapping, mappingCoverage, perFileCommand } from "../lib/ci-carry";
import { DEFAULT_MAX_AGE_HOURS, runChanged } from "../lib/run-evidence";
import { DEFAULT_MAX_AGE_HOURS, rerunByRun, rerunMarker, runChanged } from "../lib/run-evidence";
import { isConfigUnavailable, loadConfigFromBase } from "../lib/pregate/config";
import { buildRunCheck } from "../lib/pregate/run-check";
import { readTestLaneExceptions, testLaneExceptionText, type BoundLaneException } from "../lib/test-lane-exception";
Expand Down Expand Up @@ -149,6 +149,8 @@ interface EvidenceRecord {
skipped_here?: { label: string; files: string[]; tests_ran: number | "unknown"; not_owed?: string[] };
/** The owner's test-lane exception that let a lane carry with uncovered inventory files, and the preflight of exactly them here (GST-1595). */
exception?: BoundLaneException;
/** Per carried run (`<id>/<attempt>`) whose tree.json lists files that passed only on a re-run: how many, and the run's attempts (record-ci, GST-3054). */
rerun?: Record<string, { files: number; attempts: number[] }>;
}

/** Bytes of streamed output kept for the tests_ran parse (the 2MB log would truncate the summary). */
Expand Down Expand Up @@ -714,7 +716,7 @@ function reused(file: string, label: string, cmdSha: string, maxAgeHours: number

/** record-ci's record line, the one lib/ci-carry.ts recordCiResult reads. */
const recordedCiLine = (r: EvidenceRecord): string =>
`gstack-evidence: recorded label=${r.label} exit=0 tests_ran=${r.tests_ran}${r.tests_unit ? ` unit=${r.tests_unit}` : ""} log=- source=ci runs=${r.runs!.join(",")} policy=${r.policy}${r.skipped_here ? ` skipped_here=${r.skipped_here.files.length} tests_ran_here=${r.skipped_here.tests_ran}${r.skipped_here.not_owed ? ` not_owed_here=${r.skipped_here.not_owed.length}` : ""}` : ""}`;
`gstack-evidence: recorded label=${r.label} exit=0 tests_ran=${r.tests_ran}${r.tests_unit ? ` unit=${r.tests_unit}` : ""} log=- source=ci runs=${r.runs!.join(",")}${rerunMarker(Object.values(r.rerun ?? {}))} policy=${r.policy}${r.skipped_here ? ` skipped_here=${r.skipped_here.files.length} tests_ran_here=${r.skipped_here.tests_ran}${r.skipped_here.not_owed ? ` not_owed_here=${r.skipped_here.not_owed.length}` : ""}` : ""}`;

/**
* record-ci's reuse (GST-1795): the label's newest ledger row stands only when it is the CI row this record-ci would write again
Expand Down Expand Up @@ -802,7 +804,9 @@ async function cmdRecordCi(argv: string[]): Promise<number> {
}
if (!v.ok) return none(v.reason, `${v.detail}${v.reason === "inventory_uncovered" && !atHead.length && elsewhere.length ? `; test-lane exception ${elsewhere.join(", ")} binds another head, not HEAD ${head.slice(0, 12)}` : ""}`, v.diagnosis);
const runs = v.runs.map((r) => `${r.run_id}/${r.run_attempt}`);
const prior = v.excepted?.length ? null : reusableCiRow(label, { commit: head, wtree: tree, cmd_sha256: sha256(command), runs, profiles: m.profiles, policy: loaded.label, jobs: m.jobs, tests_ran: v.tests, tests_unit: v.unit, not_owed: v.notOwed }, v.remainder ?? [], m.per_file);
const reran = rerunByRun(v.runs);
const rerun = reran.size ? Object.fromEntries(reran) : undefined;
const prior = v.excepted?.length ? null : reusableCiRow(label, { commit: head, wtree: tree, cmd_sha256: sha256(command), runs, profiles: m.profiles, policy: loaded.label, jobs: m.jobs, tests_ran: v.tests, tests_unit: v.unit, not_owed: v.notOwed, rerun }, v.remainder ?? [], m.per_file);
if (prior) {
console.error(recordedCiLine(prior));
if (prior.not_owed) console.error(`gstack-evidence: not owed: ${prior.not_owed}`);
Expand Down Expand Up @@ -867,7 +871,7 @@ async function cmdRecordCi(argv: string[]): Promise<number> {
}
const rec: EvidenceRecord = {
ts: new Date(v.runs.map((r) => r.finished_at).sort()[0]!).toISOString(), label, command, cmd_sha256: sha256(command), exit: 0, duration_s: 0,
commit: head, tree, dirty: false, wtree: tree, tests_ran: testsRan, source: "ci", runs, profiles: m.profiles, policy: loaded.label, ...(m.jobs ? { jobs: m.jobs } : {}), ...(v.unit ? { tests_unit: v.unit } : {}), ...(v.notOwed ? { not_owed: v.notOwed } : {}), ...(here ? { skipped_here: here } : {}), ...(exception ? { exception } : {}),
commit: head, tree, dirty: false, wtree: tree, tests_ran: testsRan, source: "ci", runs, profiles: m.profiles, policy: loaded.label, ...(m.jobs ? { jobs: m.jobs } : {}), ...(v.unit ? { tests_unit: v.unit } : {}), ...(v.notOwed ? { not_owed: v.notOwed } : {}), ...(here ? { skipped_here: here } : {}), ...(exception ? { exception } : {}), ...(rerun ? { rerun } : {}),
};
appendJsonl(paths.file, rec, { mode: 0o600 });
console.error(recordedCiLine(rec));
Expand Down Expand Up @@ -897,9 +901,14 @@ function cmdCarried(argv: string[]): number {
for (const r of records) latest.set(r.label, r);
const carried = [...latest.values()].filter((r) => r.source === "ci" && !!wtree && r.wtree === wtree && Array.isArray(r.runs) && typeof r.policy === "string" && r.policy.startsWith(policyRef)
&& gradeRecord(r, { maxAgeHours: DEFAULT_MAX_AGE_HOURS, allowPaths: [], wtreeNow: wtree }).verdict === "FRESH")
.flatMap((r) => r.runs!.map((ref) => { const [run, attempt] = ref.split("/").map(Number); return { lane: r.label, run, attempt, tree: r.wtree!, ...(r.exception ? { exception: r.exception } : {}) }; }));
.flatMap((r) => r.runs!.map((ref) => {
const [run, attempt] = ref.split("/").map(Number);
const re = r.rerun?.[ref];
const reran = re && Number.isInteger(re.files) && re.files > 0 && Array.isArray(re.attempts) && re.attempts.every((n) => Number.isInteger(n) && n > 0) ? { rerun: re.files, attempts: re.attempts } : {};
return { lane: r.label, run, attempt, tree: r.wtree!, ...reran, ...(r.exception ? { exception: r.exception } : {}) };
}));
if (argv.includes("--json")) console.log(JSON.stringify(carried));
else for (const c of carried) console.log(`CI_CARRIED: ${c.lane} run=${c.run}/${c.attempt} tree=${c.tree.slice(0, 12)}`);
else for (const c of carried) console.log(`CI_CARRIED: ${c.lane} run=${c.run}/${c.attempt} tree=${c.tree.slice(0, 12)}${"rerun" in c ? rerunMarker([{ files: c.rerun!, attempts: c.attempts! }]) : ""}`);
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions changelog.d/ci-carry-marks-rerun-passes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- **A CI run that passed only after its failed jobs were re-run is now marked wherever gstack reuses it.** When a run's `tree.json` lists `rerun_files` and `attempts` (gbrain writes these since gbrain#9690), the `CI_CARRY:` line, the `SHIP_RECEIPT:` line's `ci_carried=` field, and the receipt line `gstack-ship-queue ready` and `land` print now add `rerun=<files> attempts=<list>`, so a pass on a re-run reads as flaky instead of as a clean first-attempt pass. The run is still accepted. A `tree.json` without those fields prints exactly as before, and a malformed `rerun_files` or `attempts` refuses that run with `CI_CARRY_RERUN_MALFORMED`.
5 changes: 4 additions & 1 deletion docs/pregate.md
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,10 @@ each mapped lane from the green run at that exact tree, reuses or runs the rest,
checks every lane FRESH and reruns the pregate there, whose tests stage carries
the same run. `gstack-ship-receipt write` records the carried runs as
`ci_carried: [{ lane, run, attempt, tree }]`, and the `SHIP_RECEIPT:` line names
them (`ci_carried=<lane>:<run>/<attempt>`). Each `record-ci` gets the base
them (`ci_carried=<lane>:<run>/<attempt>`). A run whose `tree.json` lists
`rerun_files` adds `rerun` and `attempts` to its entries and
`rerun=<files> attempts=<list>` after `ci_carried=`, as its `CI_CARRY:` line does
([ship-policy.md](ship-policy.md#ci-carry-rerun)). Each `record-ci` gets the base
policy's [`ci_record_timeout_s`](ship-policy.md#ci-record-timeout) (600 s by
default, 3600 s at most), and accept prints it as `CI_RECORD_TIMEOUT:`.

Expand Down
11 changes: 11 additions & 0 deletions docs/ship-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -2730,6 +2730,17 @@ body plain: they become main's history.
A `pull_request` CI run tests GitHub's merge commit rather than your branch,
so on a branch behind main `gstack-ci-carry` reports `tree_mismatch`:
dispatch the workflow on the branch (`gh workflow run <workflow> --ref <branch>`).
- <a id="ci-carry-rerun"></a>**A carried run that passed only after a re-run is marked, not refused.**
When only a run's failed jobs were re-run, its `tree.json` may list
`rerun_files` (the files whose newest result came from a re-run attempt) and
`attempts` (for example `[1, 2]`). The carry still accepts the run, but the
`CI_CARRY:` line, the `SHIP_RECEIPT:` line's `ci_carried=` field, and the
receipt line `ready` and `land` print all add `rerun=<files> attempts=<list>`,
so a pass on a re-run reads as flaky, never as a clean first-attempt pass. A
`tree.json` without `rerun_files`, or with an empty list, prints exactly as
before. A `rerun_files` that is not a list of paths, or `attempts` that is not
a list of attempt numbers, refuses that run
([`CI_CARRY_RERUN_MALFORMED`](troubleshooting.md#ci-carry-rerun-malformed)).

<a id="land-direct-contract"></a>
#### Every check land makes
Expand Down
17 changes: 17 additions & 0 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -7251,6 +7251,23 @@ pass the `gstack-review-scope summary` file as `--review-loop`, put the printed
line in the PR body, and write again
([ship-policy.md](ship-policy.md#ship-receipt)).

<a id="ci-carry-rerun-malformed"></a>
### `CI_CARRY_RERUN_MALFORMED`

**Meaning.** A CI run's `tree.json` names `rerun_files` or `attempts`, the
fields that say some test files passed only on a re-run attempt, but in a shape
gstack cannot read: `rerun_files` is not a list of file paths, or `attempts` is
not a list of attempt numbers of 1 or more. gstack fails closed: that run is not
evidence, the carry refuses it (`rerun_malformed` in the `CI_CARRY: none` or
`no_verified_run` detail), and the lane runs here instead. A well-formed record
is accepted and marked `rerun=<files> attempts=<list>`
([ship-policy.md](ship-policy.md#ci-carry-rerun)).

**Fix.** Fix the workflow step that writes `tree.json` so it writes
`"rerun_files": ["test/a.test.ts", …]` and `"attempts": [1, 2]`, or leaves both
out. Then dispatch a fresh run at the same head and rerun
`gstack-ci-carry wait`.

<a id="receipt-carry-tree-mismatch"></a>
### `RECEIPT_CARRY_TREE_MISMATCH`

Expand Down
2 changes: 1 addition & 1 deletion lib/ci-carry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function newestVerified(src: RunSource, name: string, profile: RunProfile, heads
for (const run of listed) {
const v = verifyRun(src.deps, { repo: src.repo, runRef: String(run.id), profileName: name, profile, vetoHeads: heads, now: src.now, unchanged: src.unchanged, docsOnly });
if (v.ok) return v;
refusals.push(`run ${run.id}: ${v.reason}${v.fix ? ` (the pull request's base moved after the run; fix: ${v.fix})` : ''}`);
refusals.push(`run ${run.id}: ${v.reason}${v.reason === 'rerun_malformed' ? ` (${v.detail})` : ''}${v.fix ? ` (the pull request's base moved after the run; fix: ${v.fix})` : ''}`);
}
return no('no_verified_run', `${name}: ${refusals.join('; ')}`);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/headless-artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ export interface ShipReceipt {
gate?: Record<string, unknown>; ci?: Record<string, unknown>; spend_usd?: number | string; predecessor?: string;
/** The run's calls from the call log (lib/ship-clock.ts callsSince: gstack-command calls plus keep-alives), so a 200-call run shows at the receipt; absent on older receipts. */
calls?: number;
/** GSTA-258: the lanes CI carried at this head's tree, one entry per run (gstack-evidence carried). */
ci_carried?: Array<{ lane: string; run: number; attempt: number; tree: string; exception?: BoundLaneException }>;
/** GSTA-258: the lanes CI carried at this head's tree, one entry per run (gstack-evidence carried); `rerun` and `attempts` when files passed only on a re-run (GST-3054). */
ci_carried?: Array<{ lane: string; run: number; attempt: number; tree: string; rerun?: number; attempts?: number[]; exception?: BoundLaneException }>;
session_kind?: string; artifacts_consumed?: string; run?: string;
// C-stamp (C3/C5/C7): the tree receipt's verdicts and the policy provenance, all optional.
thread?: string; tree?: string; gate_reuse?: string; policy?: string; queue_mode?: string; preregistration?: string; history?: string;
Expand Down Expand Up @@ -267,6 +267,7 @@ export const ARTIFACT_SCHEMAS = {
schema_version: { const: 1 }, pr: { type: 'integer' }, head: str, version: str, base: str, gated_tree: str,
gate: { type: 'object' }, ci: { type: 'object' }, spend_usd: { type: ['number', 'string'] }, calls: { type: 'integer', minimum: 0 }, predecessor: str,
ci_carried: { type: 'array', items: { type: 'object', required: ['lane', 'run', 'attempt', 'tree'], properties: { lane: str, run: { type: 'integer', minimum: 1 }, attempt: { type: 'integer', minimum: 1 }, tree: str,
rerun: { type: 'integer', minimum: 1 }, attempts: { type: 'array', items: { type: 'integer', minimum: 1 } },
exception: { type: 'object', required: ['head', 'files', 'by', 'reason', 'at', 'approval', 'preflight'], properties: { head: str, files: strList, by: str, reason: str, at: str, approval: str,
preflight: { type: 'object', required: ['label', 'tests_ran'], properties: { label: str, tests_ran: { type: 'integer', minimum: 1 } } } } } } } },
session_kind: str, artifacts_consumed: { ...str, description: '<n>/<m>' }, run: str,
Expand Down
5 changes: 5 additions & 0 deletions lib/result-codes-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,11 @@ export const RELEASE_RESULT_CODES = {
summary: 'write --review-loop-exception got an exception that is malformed, accepts a stop the review loop does not show (a fix_check with review_loop.fix_checks 0 or missing, or a second_pass with fewer than two passes or no deferred finding), names a head that is not the receipt head or its ancestor, or is missing from the PR body',
fix: 'pass { accepted_by, date, via, reason } plus fix_check: { head, findings } or second_pass: { head, deferred: [<finding id>] } with the owner’s words, the --review-loop summary that shows that stop, and the printed "Review-loop exception: …" line in the body',
},
CI_CARRY_RERUN_MALFORMED: {
anchor: 'ci-carry-rerun-malformed',
summary: 'a CI run\'s tree.json carries rerun_files or attempts in a shape gstack cannot read (rerun_files not a list of paths, attempts not a list of attempt numbers), so the run is not evidence and no lane carries from it',
fix: 'fix the workflow step that writes tree.json (rerun_files: ["test/a.test.ts", …], attempts: [1, 2]), dispatch a fresh run at the same head, then rerun gstack-ci-carry wait',
},
RECEIPT_CARRY_TREE_MISMATCH: {
anchor: 'receipt-carry-tree-mismatch',
summary: 'the branch was rebased or force-pushed since its /ship receipt, and HEAD\'s tree is not a tree the receipt covers, so no review saw this code',
Expand Down
Loading
Loading