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
6 changes: 5 additions & 1 deletion .agents/skills/work-issue/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ pinned browser/layout/offline/endurance/editorial and native runtime categories.
Missing tools, skipped runtimes, failures/cancellations and unexpected job skips
leave selected hosted proof incomplete. Never delete tests, weaken offline
harnesses or rerun a real failure to obtain green. Keep drafts cheap and batch
pushes. A ready PR synchronize event runs fast feedback with a deliberately
pushes. For heavy iteration on a draft (native, runtime, browser, layout,
endurance or complete unit categories), request hosted feedback with
`bun scripts/request-heavy-feedback.ts <pr>` instead of running long suites
locally. It needs no reservation, a newer push or request cancels it, and its
`draft heavy feedback` result is never `proof`. A ready PR synchronize event runs fast feedback with a deliberately
nonpassing final gate. Before `confirm`, run `bun scripts/collisions.ts --json --pr <pr>`
and record its collisions (or none) with the PR head in the PR. For ordinary candidates, acquire the exact-candidate integration reservation
with `bun scripts/integrate.ts confirm <pr> --issues owner/repo#N,...` before
Expand Down
8 changes: 8 additions & 0 deletions .agents/skills/work-issue/references/ci-and-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ runtimes, failures/cancellations and unexpected skips leave proof unfinished.
Keep drafts cheap and batch pushes. Ready synchronize runs fast feedback and
leaves `proof` nonpassing; convert to draft and mark ready after the final push
to request candidate confirmation. Open/reopen ready events also request it.
For heavy iteration on a draft, run `bun scripts/request-heavy-feedback.ts
<pr>` (`--json` prints the run identity). It dispatches the PR's affected heavy
categories at its live head without the reservation, and refuses a ready,
closed, foreign or moved head. A newer request or push cancels the earlier run,
and admission waits while a ready confirmation holds the reservation. Its
aggregate, `draft heavy feedback`, is feedback only: the merge gate never reads
it, and exact-head ready confirmation remains the only `proof`. Use long local
suites only to debug a specific failure.
Draft runs report `draft gates`, not `proof`. A ready PR without a passing
`proof` from its confirmation run is unconfirmed, even if `draft gates` passed
or failed because its live read found the PR ready; request confirmation again.
Expand Down
473 changes: 473 additions & 0 deletions .github/workflows/heavy-feedback.yml

Large diffs are not rendered by default.

41 changes: 40 additions & 1 deletion docs/decisions/ci-utility.md
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,46 @@ The dispatch workflow and request script are
[#3272](https://github.com/schlessera/brain-kit/issues/3272). The `check:pr` and
guidance changes are [#3273](https://github.com/schlessera/brain-kit/issues/3273).
Runner-slot wait is [#2952](https://github.com/schlessera/brain-kit/issues/2952).
Until #3272 lands, drafts keep running cheap gates only.

#### How the request runs

`bun scripts/request-heavy-feedback.ts <pr>` reads the live head and
dispatches `.github/workflows/heavy-feedback.yml` from the default branch with
the PR number and that SHA. It prints the run URL, or the run identity with
`--json`. A dispatch can only start a workflow file that exists on the default
branch, so the request always runs main's admission code.

- **Same jobs and pins.** `scripts/heavy-feedback-workflow.ts` generates the
workflow from `ci.yml`. It copies the category jobs and replaces only their
checkout ref, which becomes the requested head, and their planner
environment. `bun run lint` refuses a stale copy, so a change to a
category job in `ci.yml` regenerates this file in the same PR.
- **Exact head.** The admission job refuses unless the live PR is open, a
draft, from this repository and at exactly the requested SHA. It checks this
again on every wait poll. It then plans the PR's affected selection against
the live PR base with the `feedback-heavy` cadence, which selects what
confirmation would.
- **Never proof.** The aggregate is named `draft heavy feedback` and prints no
candidate receipt. The candidate gate refuses the `feedback-heavy` cadence.
The merge gate reads only `ci.yml`'s `pull_request` runs and their `proof`
job, so a feedback run cannot satisfy it.
- **One run per PR.** The concurrency group is
`heavy-feedback-<pr>` with `cancel-in-progress`. The same workflow also runs
a one-step job on the PR's `synchronize`, `ready_for_review` and `closed`
events. That job joins the group and so cancels the in-flight feedback run.
- **Ready confirmations first.** GitHub Actions has no job priority. The
chosen approximation is admission-time yielding. The admission job waits
while the exact-candidate integration reservation holds a live lease,
because every ordinary confirmation runs under one. It also waits while
another feedback run is queued or in progress, which caps feedback at two
runs repository-wide. Waiting polls every 30 seconds and refuses after 30
minutes. A confirmation requested after a feedback run was admitted still
competes with that run for runners. A ready transition cancels the PR's own
feedback run. The [#2952](https://github.com/schlessera/brain-kit/issues/2952)
runner-slot wait measures whether this is enough.
- **Red main.** The refusal while main is red is the red-main gate from
[#2942](https://github.com/schlessera/brain-kit/issues/2942). Whichever of
#2942 and #3272 lands second adds that gate to the admission job.

## Historical measurement and upstream guidance

Expand Down
2 changes: 2 additions & 0 deletions scripts/candidate-proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const CONFIRMATION_REQUIRED = "Candidate confirmation required: convert this PR
export async function validateCandidate(root: string, event: any, env: NodeJS.ProcessEnv,
api?: API, actual: Checkout = checkout(root)): Promise<void> {
const cadence = proofCadence(env, event);
// Draft heavy feedback is never proof; only an exact-head ready confirmation is (#3272).
if (cadence === "feedback-heavy") throw new Error(`Draft heavy feedback is never proof. ${CONFIRMATION_REQUIRED}`);
if (cadence === "feedback") throw new Error(CONFIRMATION_REQUIRED);
if (cadence === "draft") return requireLiveDraft(event, api);
if (cadence !== "confirmation") return;
Expand Down
43 changes: 43 additions & 0 deletions scripts/check-ci-workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import { existsSync, readFileSync, readdirSync } from "node:fs";
import { join, resolve } from "node:path";
import { PROOF_SHARDS, shardNumbers, type ShardedDomain } from "./proof-shards";
import { FEEDBACK_AGGREGATE } from "./heavy-feedback";
import { CATEGORY_JOBS, FEEDBACK_GROUP, renderHeavyFeedbackWorkflow, sameWorkflow } from "./heavy-feedback-workflow";

export const CI_WORKFLOWS = ["ci.yml", "contract.yml"] as const;
const RUN_EXPRESSIONS = new Set(["matrix.shard", "github.event_name", "github.base_ref", "github.event.before"]);
Expand Down Expand Up @@ -127,6 +129,7 @@ export function checkCIWorkflows(root: string): string[] {
const expected = ["ci.yml", "contract.yml", "project-sync.yml"];
if (files.includes("publish-pages.yml")) expected.push("publish-pages.yml");
if (files.includes("ci-timings.yml")) expected.push("ci-timings.yml");
if (files.includes("heavy-feedback.yml")) expected.push("heavy-feedback.yml");
if (JSON.stringify(files) !== JSON.stringify(expected.sort())) problems.push("GitHub must contain only authoritative CI, contract, project-sync and optional Pages/timing workflows");
const depot = join(root, ".depot/workflows");
if (existsSync(depot) && readdirSync(depot).some(file => /\.ya?ml$/.test(file))) problems.push("Active Depot CI workflow definitions must be removed");
Expand All @@ -137,11 +140,51 @@ export function checkCIWorkflows(root: string): string[] {
}
const pages = join(directory, "publish-pages.yml");
if (existsSync(pages)) problems.push(...publicationWorkflowProblems(readFileSync(pages, "utf8")));
const feedback = join(directory, "heavy-feedback.yml");
if (existsSync(feedback) && existsSync(join(directory, "ci.yml"))) problems.push(...heavyFeedbackWorkflowProblems(readFileSync(feedback, "utf8"), readFileSync(join(directory, "ci.yml"), "utf8")));
const timings = join(directory, "ci-timings.yml");
if (existsSync(timings)) problems.push(...timingWorkflowProblems(readFileSync(timings, "utf8")));
return problems;
}

/** Draft heavy feedback (#3272): ci.yml's own category jobs, per-PR cancellation, never `proof`. */
export function heavyFeedbackWorkflowProblems(text: string, ciText: string): string[] {
const errors: string[] = [], fail = (message: string) => errors.push(`heavy-feedback.yml: ${message}`);
let workflow: Workflow & { concurrency?: Record<string, unknown> };
try { workflow = Bun.YAML.parse(text) as typeof workflow; }
catch { return ["heavy-feedback.yml: invalid YAML"]; }
if (!workflow || typeof workflow !== "object") return ["heavy-feedback.yml: workflow must be a mapping"];
let rendered = "";
try { rendered = renderHeavyFeedbackWorkflow(ciText); } catch (error) { fail(`cannot derive from ci.yml: ${String(error)}`); }
if (rendered && !sameWorkflow(text, rendered)) fail("stale copy of ci.yml's category jobs and pins; run bun scripts/heavy-feedback-workflow.ts");
if (/\bsecrets\.|\bpull_request_target\b|\bworkflow_run\b/.test(text)) fail("feedback must not expose secrets or privileged triggers");
if (JSON.stringify(workflow.permissions) !== JSON.stringify({ contents: "read", actions: "read", checks: "read" })) fail("token must stay read-only");
if (JSON.stringify(Object.keys(workflow.on ?? {}).sort()) !== JSON.stringify(["pull_request", "workflow_dispatch"])) fail("only a dispatch requests feedback; pull_request only cancels it");
const inputs = (workflow.on?.workflow_dispatch as any)?.inputs;
if (inputs?.pr?.required !== true || inputs?.head_sha?.required !== true) fail("dispatch must name the PR and its exact head");
if (workflow.concurrency?.group !== FEEDBACK_GROUP || workflow.concurrency?.["cancel-in-progress"] !== true) fail("at most one draft heavy run per PR: per-PR group with cancel-in-progress");
const jobs = workflow.jobs ?? {};
// A job's check name is its `name`, or its id when unnamed.
if (Object.entries(jobs).some(([id, job]) => String(job.name ?? id).trim().toLowerCase() === "proof")) fail("feedback must never be named proof");
if (jobs.aggregate?.name !== FEEDBACK_AGGREGATE) fail(`aggregate must be named ${FEEDBACK_AGGREGATE}`);
if (JSON.stringify(jobs.aggregate?.needs) !== JSON.stringify(["changeset", ...CATEGORY_JOBS])) fail("aggregate must observe every selected category");
if (!jobs.aggregate?.steps?.some(step => step.run === "bun scripts/heavy-feedback.ts aggregate") ||
jobs.aggregate?.steps?.some(step => /ci-proof\.ts aggregate|candidate-proof/.test(step.run ?? ""))) fail("aggregate must report feedback without candidate receipts");
const admission = jobs.changeset?.steps ?? [];
const admit = admission.findIndex(step => step.run === "bun scripts/heavy-feedback.ts admit");
const headCheckout = admission.findIndex(step => step.uses?.startsWith("actions/checkout@") && step.with?.ref === "${{ inputs.head_sha }}");
if (admit < 0 || headCheckout <= admit) fail("admission must refuse a stale, ready, closed or foreign head before checking it out");
for (const [name, job] of Object.entries(jobs)) {
if (job["runs-on"] !== "ubuntu-24.04") fail(`${name}: unmapped GitHub-hosted runner`);
if (job.permissions !== undefined) fail(`${name}: job permissions must inherit the read-only workflow token`);
for (const step of job.steps ?? []) {
if (step.uses?.startsWith("actions/checkout@") && step.with?.["persist-credentials"] !== false) fail(`${name}: checkout credentials must not persist`);
for (const match of (step.run ?? "").matchAll(/\$\{\{\s*([^}]*?)\s*\}\}/g)) if (!RUN_EXPRESSIONS.has(match[1]!)) fail(`${name}: untrusted expression in run script: ${match[1]}`);
}
}
return errors;
}

/** Measurement is scheduled trusted code with no product-proof authority. */
export function timingWorkflowProblems(text: string): string[] {
const errors: string[] = [], fail = (message: string) => errors.push(`ci-timings.yml: ${message}`);
Expand Down
19 changes: 14 additions & 5 deletions scripts/ci-plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const FAST_TESTS: Readonly<Record<string, readonly string[]>> = {
"tests/candidate-proof.test.ts", "tests/proof-inventory.test.ts",
"tests/proof-reuse.test.ts", // 4.47s immutable source/input ownership controls (#1333).
"tests/measurement-fixture-lifetime.test.ts", // 0.13s owner/exit regression (#1330).
"tests/ci-workflows.test.ts", "tests/release-manifest.test.ts", "tests/ci-pack.test.ts",
"tests/ci-workflows.test.ts", "tests/heavy-feedback.test.ts", "tests/release-manifest.test.ts", "tests/ci-pack.test.ts",
"tests/lockfile.test.ts",
"tests/changeset-gate.test.ts", "tests/contract-gate.test.ts",
"tests/decision-citations.test.ts", "tests/dependency-edges.test.ts",
Expand Down Expand Up @@ -391,10 +391,17 @@ export function unitShards(plan: CheckPlan): number[] {
return Array.from({length: Math.min(4, count)}, (_, i) => i + 1);
}

export type ProofCadence = "draft" | "feedback" | "confirmation" | "integrated" | "exhaustive";
export type ProofCadence = "draft" | "feedback" | "feedback-heavy" | "confirmation" | "integrated" | "exhaustive";

/** A request is an event, never a sticky label that can approve a later head. */
/** A draft heavy feedback dispatch names its PR and head; ci.yml's bare dispatch declares no inputs. */
export function heavyFeedbackDispatch(env: NodeJS.ProcessEnv, event: any): boolean {
return env.GITHUB_EVENT_NAME === "workflow_dispatch" && event?.inputs?.pr !== undefined && event?.inputs?.head_sha !== undefined;
}

/** A request is an event, never a sticky label that can approve a later head.
* `feedback-heavy` selects like confirmation but is never proof (#3272). */
export function proofCadence(env: NodeJS.ProcessEnv, event: any): ProofCadence {
if (heavyFeedbackDispatch(env, event)) return "feedback-heavy";
if (env.GITHUB_EVENT_NAME === "pull_request") {
if (event.pull_request?.draft === true) return "draft";
if (["opened", "reopened", "ready_for_review"].includes(event.action)) return "confirmation";
Expand Down Expand Up @@ -437,8 +444,10 @@ export function changedFiles(root: string, base: string, head = "HEAD", mergeBas
}

export function planFromEnvironment(root: string, env: NodeJS.ProcessEnv): CheckPlan {
if (["api", "schedule", "workflow_dispatch"].includes(env.GITHUB_EVENT_NAME ?? "")) return planChecks(["package.json"], workspaces(root), root);
const pr = env.GITHUB_EVENT_NAME === "pull_request";
// Draft heavy feedback plans its PR's affected selection against the PR base (#3272).
const feedback = env.GITHUB_EVENT_NAME === "workflow_dispatch" && Boolean(env.FEEDBACK_PR);
if (!feedback && ["api", "schedule", "workflow_dispatch"].includes(env.GITHUB_EVENT_NAME ?? "")) return planChecks(["package.json"], workspaces(root), root);
const pr = feedback || env.GITHUB_EVENT_NAME === "pull_request";
const base = pr ? env.BASE_SHA : env.BEFORE_SHA;
if (!base || !env.HEAD_SHA) throw new Error("CI requires BASE_SHA/BEFORE_SHA and HEAD_SHA");
return planChecks(changedFiles(root, base, env.HEAD_SHA, pr), workspaces(root), root, pr);
Expand Down
Loading
Loading