Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

ci(spec-owner): stop undecided at a per-run request budget (#9268)

Cindy Zhanga1b7c6b579e9
diff --git a/.github/scripts/review-signal-decision.cjs b/.github/scripts/review-signal-decision.cjs
index a326e45bd9..ba60b5fe99 100644
--- a/.github/scripts/review-signal-decision.cjs
+++ b/.github/scripts/review-signal-decision.cjs
@@ -138,6 +138,10 @@ const SPEC_WAITING_TEXT = {
};
const SPEC_MIRROR_PREFIX = 'Mirrors review-required · spec ';
const SPEC_CHECKING_TEXT = '⏳ Checking for spec changes…';
+// A run over the spec-owner job's request budget decides nothing; a
+// maintainer's dispatch decides (spec:AST-030 FR15).
+const SPEC_TOO_LARGE_TEXT =
+ '⏳ Too large to reconcile automatically: a maintainer can run the Review signal workflow for this PR';
const CODE_WAITING_PREFIX = 'Waiting on code review';
const REVIEW_COMPLETE = 'Review complete.';
@@ -175,6 +179,9 @@ function readSpecStatus(status) {
text: SPEC_WAITING_TEXT.held(holder),
};
}
+ if (rest.startsWith('too large')) {
+ return {known: true, satisfied: false, text: SPEC_TOO_LARGE_TEXT};
+ }
if (rest.startsWith('waiting (design)')) {
return {known: true, satisfied: false, text: SPEC_WAITING_TEXT.design};
}
@@ -274,6 +281,7 @@ module.exports = {
REVIEW_GATE_CONTEXT,
SPEC_GATE_CONTEXT,
SPEC_MIRROR_PREFIX,
+ SPEC_TOO_LARGE_TEXT,
SPEC_WAITING_TEXT,
classifyReviewSignalPaths,
composeReviewGate,
diff --git a/.github/scripts/spec-owner-decision.test.mjs b/.github/scripts/spec-owner-decision.test.mjs
index 18f3df9466..410fe2805a 100644
--- a/.github/scripts/spec-owner-decision.test.mjs
+++ b/.github/scripts/spec-owner-decision.test.mjs
@@ -747,4 +747,25 @@ describe('one review gate', () => {
compose({known: true, satisfied: false, text: '⏳ wait', url}),
).toEqual({state: 'pending', description: '⏳ wait', target_url: url});
});
+ it('reads a too-large run as a pending spec half that names the dispatch', () => {
+ const url = 'https://github.com/meta/astryx/actions/runs/8/attempts/1';
+ const spec = readSpecGate([
+ {
+ context: 'spec-owner-approval',
+ state: 'pending',
+ description:
+ 'Mirrors review-required · spec too large to reconcile automatically',
+ target_url: url,
+ creator: {login: 'github-actions[bot]'},
+ },
+ ]);
+ expect(
+ composeReviewGate({codeGated: false, codeDescription: noCode, spec}),
+ ).toEqual({
+ state: 'pending',
+ description:
+ '⏳ Too large to reconcile automatically: a maintainer can run the Review signal workflow for this PR',
+ target_url: url,
+ });
+ });
});
diff --git a/.github/scripts/spec-owner-reconcile.cjs b/.github/scripts/spec-owner-reconcile.cjs
index 90bd938443..bf2fcf7edf 100644
--- a/.github/scripts/spec-owner-reconcile.cjs
+++ b/.github/scripts/spec-owner-reconcile.cjs
@@ -25,6 +25,8 @@ const {
} = require('./spec-owner-decision.cjs');
const {
REVIEW_GATE_CONTEXT,
+ SPEC_MIRROR_PREFIX,
+ SPEC_TOO_LARGE_TEXT,
SPEC_WAITING_TEXT,
composeReviewGate,
readCodeGate,
@@ -32,6 +34,30 @@ const {
} = require('./review-signal-decision.cjs');
/* eslint-enable @typescript-eslint/no-require-imports */
+// One run's GitHub API requests before it stops undecided. Reading a spec
+// change hundreds of files wide would otherwise spend the repository's shared
+// hourly budget that every workflow needs (spec:AST-030 FR15).
+const REQUEST_BUDGET = 300;
+
+class RequestBudgetExceeded extends Error {}
+
+/**
+ * Reconcile one pull request's spec gate. A run that reaches the request
+ * budget leaves the gate pending as too large to reconcile automatically; a
+ * maintainer's dispatch of the Review signal workflow is exempt and decides.
+ */
+async function reconcileSpecOwnerGate(options) {
+ const budget = {onExceeded: null};
+ try {
+ await reconcileWithinBudget({...options, budget});
+ } catch (error) {
+ if (!(error instanceof RequestBudgetExceeded) || !budget.onExceeded) {
+ throw error;
+ }
+ await budget.onExceeded();
+ }
+}
+
function isCommandComment(eventName, payload) {
if (eventName !== 'issue_comment') return true;
return parseOwnerCommandIntent(payload.comment?.body) !== null;
@@ -64,14 +90,38 @@ function isSettled(pr) {
return Boolean(pr.merged_at) || pr.state === 'closed';
}
-async function reconcileSpecOwnerGate({
+async function reconcileWithinBudget({
github,
context,
core,
workspace = process.env.GITHUB_WORKSPACE,
env = process.env,
now = () => new Date(),
+ budget,
+ // The job's request count (lib/rate-limit-backoff.cjs); no budget without it.
+ requestCounter,
+ requestBudget = REQUEST_BUDGET,
}) {
+ // Read when the first budgeted call is made, never before the event checks.
+ const requestCount = () =>
+ (requestCounter ?? github.__rateLimitBackoff)?.requests ?? null;
+ // Checked before each file read and comparison, the calls that grow with
+ // the pull request. Reads start in parallel batches before the job's count
+ // sees them, so each checked call is also counted here as it starts.
+ let countAtFirstCheck = null;
+ let checkedCalls = 0;
+ function spendRequest() {
+ const observed = requestCount();
+ if (observed == null || context.eventName === 'workflow_dispatch') return;
+ countAtFirstCheck ??= observed;
+ const spent = Math.max(observed, countAtFirstCheck + checkedCalls);
+ if (spent >= requestBudget) {
+ throw new RequestBudgetExceeded(
+ `Stopped after ${spent} GitHub API requests (budget ${requestBudget}).`,
+ );
+ }
+ checkedCalls += 1;
+ }
const {owner, repo} = context.repo;
const repository = `${owner}/${repo}`;
if (
@@ -288,6 +338,7 @@ async function reconcileSpecOwnerGate({
}
async function readText(fullName, ref, filePath) {
+ spendRequest();
const [repoOwner, repoName] = fullName.split('/');
try {
const {data} = await github.rest.repos.getContent({
@@ -335,6 +386,7 @@ async function reconcileSpecOwnerGate({
/** A spec path's text at `ref`, or null when the path is absent there. */
async function readSpecContent(fullName, ref, filePath) {
+ spendRequest();
const [repoOwner, repoName] = fullName.split('/');
try {
const {data} = await github.rest.repos.getContent({
@@ -722,6 +774,26 @@ async function reconcileSpecOwnerGate({
// check, like the mirror, so a newer run's decision is restored over it.
await publishReviewGate(initialHead, readSpecGate([]));
if (await restoreNewerStatus(initialHead)) return;
+ // From here a run can reach the request budget. It then says so on both
+ // statuses, so an owner's command never reads as taken, and leaves the
+ // decision to a maintainer's dispatch.
+ budget.onExceeded = async () => {
+ core.warning(
+ `Stopped after ${requestCount()} GitHub API requests: this pull request is too large to reconcile automatically. Run the Review signal workflow with pr=${pullNumber} to decide it.`,
+ );
+ if (!(await isPublishable(initialHead))) return;
+ await createStatus({
+ sha: initialHead,
+ context: GATE_STATUS_CONTEXT,
+ state: 'pending',
+ description: `${SPEC_MIRROR_PREFIX}too large to reconcile automatically`,
+ });
+ if (await restoreNewerStatus(initialHead)) return;
+ await publishReviewGate(initialHead, {
+ satisfied: false,
+ text: SPEC_TOO_LARGE_TEXT,
+ });
+ };
const commentAuthor = context.payload.comment?.user?.login?.toLowerCase();
const snapshot = await fetchSnapshot();
@@ -867,6 +939,7 @@ async function reconcileSpecOwnerGate({
// An approved commit's spec paths join the head's, so dropping an approved
// change no longer matches. A failed comparison matches nothing.
async function specChangesAt(sha) {
+ spendRequest();
const {data} = await github.rest.repos.compareCommitsWithBasehead({
owner,
repo,
@@ -899,6 +972,7 @@ async function reconcileSpecOwnerGate({
]);
return atHead.fingerprint === atShaContent.fingerprint;
} catch (error) {
+ if (error instanceof RequestBudgetExceeded) throw error;
core.warning(`Could not compare ${sha.slice(0, 7)}: ${error.message}`);
return false;
}
diff --git a/.github/scripts/spec-owner-reconcile.test.mjs b/.github/scripts/spec-owner-reconcile.test.mjs
index 9da4f65777..8b8a9dd3db 100644
--- a/.github/scripts/spec-owner-reconcile.test.mjs
+++ b/.github/scripts/spec-owner-reconcile.test.mjs
@@ -1672,6 +1672,120 @@ describe('spec owner workflow reconciliation', () => {
});
});
+ describe('a spec change too large for one run', () => {
+ const moved = Array.from({length: 300}, (_, i) => ({
+ filename: `docs/specs/components/C${i}/C${i}.spec.md`,
+ previous_filename: `packages/core/src/C${i}/C${i}.spec.md`,
+ status: 'renamed',
+ changes: 0,
+ }));
+ const tooLarge =
+ '⏳ Too large to reconcile automatically: a maintainer can run the Review signal workflow for this PR';
+
+ // The job's request count, as lib/rate-limit-backoff.cjs keeps it: a
+ // request counts once it reaches the client, a tick after the call.
+ function countRequests(harness) {
+ const counter = {requests: 0, waits: 0};
+ const repos = harness.github.rest.repos;
+ for (const name of ['getContent', 'compareCommitsWithBasehead']) {
+ const method = repos[name];
+ repos[name] = async input => {
+ await Promise.resolve();
+ counter.requests += 1;
+ return method(input);
+ };
+ }
+ harness.github.__rateLimitBackoff = counter;
+ return counter;
+ }
+
+ it('stops at the budget and leaves the gate pending, even after an owner command', async () => {
+ const harness = createHarness({
+ changedFiles: moved,
+ headContent: currentRecord,
+ baseContent: currentRecord,
+ });
+ const counter = countRequests(harness);
+
+ await commentRun(harness, ownerComment(`/approve-spec ${head}`));
+
+ // Parallel reads stop at the budget too, not one batch past it.
+ expect(counter.requests).toBe(300);
+ expect(latestReviewGate(harness.state)).toMatchObject({
+ state: 'pending',
+ description: tooLarge,
+ });
+ expect(latestGateStatus(harness.state)).toMatchObject({
+ state: 'pending',
+ description:
+ 'Mirrors review-required · spec too large to reconcile automatically',
+ });
+ });
+
+ it('stops parallel reads at the budget, not a batch past it', async () => {
+ const harness = createHarness({
+ changedFiles: moved,
+ headContent: currentRecord,
+ baseContent: currentRecord,
+ });
+ const counter = countRequests(harness);
+
+ await reconcileSpecOwnerGate({
+ github: harness.github,
+ context: context({runId: 100n}),
+ core: harness.core,
+ workspace,
+ env,
+ requestBudget: 100,
+ });
+
+ expect(counter.requests).toBe(100);
+ expect(latestReviewGate(harness.state).description).toBe(tooLarge);
+ });
+
+ it('stops, rather than decides, when the budget runs out comparing an approval', async () => {
+ // One record fits the budget; the approved commit's comparison does not.
+ const harness = createHarness({
+ headContent: currentRecord,
+ contentAt: {[oldHead]: currentRecord},
+ comments: [ownerComment(`/approve-spec ${oldHead}`)],
+ });
+ countRequests(harness);
+
+ await reconcileSpecOwnerGate({
+ github: harness.github,
+ context: context({runId: 100n}),
+ core: harness.core,
+ workspace,
+ env,
+ requestBudget: 2,
+ });
+
+ expect(latestReviewGate(harness.state)).toMatchObject({
+ state: 'pending',
+ description: tooLarge,
+ });
+ });
+
+ it("lets a maintainer's dispatch decide past the budget", async () => {
+ const harness = createHarness({
+ changedFiles: moved,
+ headContent: currentRecord,
+ baseContent: currentRecord,
+ comments: [ownerComment(`/approve-spec ${head}`)],
+ });
+ const counter = countRequests(harness);
+
+ await run(
+ harness,
+ context({runId: 100n, eventName: 'workflow_dispatch'}),
+ );
+
+ expect(counter.requests).toBeGreaterThan(300);
+ expect(latestReviewGate(harness.state).state).toBe('success');
+ });
+ });
+
it('reads a spec wait as satisfied code review, not an older code wait', async () => {
const harness = createHarness({
headContent: currentRecord,
diff --git a/docs/architecture/knowledge-contracts.md b/docs/architecture/knowledge-contracts.md
index 5071d4f441..638ac54b5e 100644
--- a/docs/architecture/knowledge-contracts.md
+++ b/docs/architecture/knowledge-contracts.md
@@ -1101,7 +1101,10 @@ requested changes and can reply /approve-spec <sha>`. An approved spec change
owner command re-evaluates the gate, and each evaluation publishes a terminal
state for the head it read. A fork review carries a read-only token and is
skipped, so owners approve a fork pull request with the command. Comments that
- are not owner commands start no runner.
+ are not owner commands start no runner. A run that would exceed the
+ spec-owner job's request budget leaves the gate pending as too large to
+ reconcile automatically, and a maintainer-dispatched run decides it
+ (`spec:AST-030` FR15).
Rejected: exact-head binding (recording the approval and every base merge
forced re-approval of unchanged text); per-record or per-section approval
diff --git a/docs/specs/AST-030/spec.md b/docs/specs/AST-030/spec.md
index 0691c15cca..7b211d62d2 100644
--- a/docs/specs/AST-030/spec.md
+++ b/docs/specs/AST-030/spec.md
@@ -306,7 +306,10 @@ they are separately named.
check. The spec-owner job
evaluates pull-request, review, and owner-command comment events, runs
without cancel-in-progress, and publishes a terminal state for the head it
- read. It skips fork review events, whose tokens are read-only; fork approvals
+ read. A run that would exceed the job's request budget leaves the gate
+ pending, saying the pull request is too large to reconcile automatically; a
+ maintainer-dispatched run is exempt from the budget and decides normally. It
+ skips fork review events, whose tokens are read-only; fork approvals
use the owner command. Only the review-signal job keeps a per-pull-request
cancel group. Each writer of `review-required` composes both halves and links
a spec wait to the spec decision's details. Comments that are not owner
@@ -429,7 +432,7 @@ read change (FR14).
| FR12 | Storybook visual-plan, canonical workflow, and repository-owner guard tests | PR scope; full-plan maintenance; report-only publication; deployment/a11y/RTL/vibe artifacts | another workflow captures or compares pixels, a renamed or aliased owner escapes the guard, or legitimate non-visual artifacts are rejected |
| FR13 | classifier, workflow contract, component-analysis and RTL-scope tests | component change; shared module; Changeset beside code; infrastructure path; incomplete list; no build | an infrastructure path is scoped, a file-system guard test is skipped, a reverse dependent leaves visual/RTL or enters PR accessibility, or a full-suite event is narrowed |
| FR14 | `workflow-paths.test.mjs` over every workflow | path allowlist; required-context workflow | a `paths-ignore`, a match-all or exclusion glob, or a path filter on a workflow that reports a required context fails |
-| FR15 | workflow contract and reconciler tests | ENGOWNER spec PR; owner command; other comment; fork review; non-spec PR | `review-required` succeeds while spec approval is missing, another workflow publishes a review context, a fork review starts the spec checks, or a non-command comment starts a runner |
+| FR15 | workflow contract and reconciler tests | ENGOWNER spec PR; owner command; other comment; fork review; non-spec PR; run over the request budget; maintainer dispatch | `review-required` succeeds while spec approval is missing, another workflow publishes a review context, a fork review starts the spec checks, a non-command comment starts a runner, or an over-budget run decides |
| FR16 | `heavy-caps-action.test.mjs` cap cases and heavy-job contract; `ci-admission.test.mjs` | sixteenth-oldest PR; 101st heavy run of the day, beside cancelled, light and other-branch runs; agent lane and its five-PR and forty-run backstops; an engineering owner, including the shared login past those backstops, a commented-out or trailing-comment handle and an unreadable roster; bot; the deciding run; re-run; failed lookup; a run with room, without room, past its longest wait, beside a waiting `main` check, as a draft or unlabelled fork, with opt-in labels, beside small workflows past their measured most, and with the API unreadable; each workflow's most jobs; every required context's rule | a heavy suite that runs ahead of the author's fifteen oldest PRs, or past the daily cap, a capped job that passes, an engineering owner or a re-run that is held, or a roster read from the pull request's head, a run that starts without room before its longest wait, a pull-request run that starts while `main` waits, a job admission could skip, or a peak below the jobs its run holds fails |
| FR17 | `ci-pr-gate.test.mjs` over every `pull_request` workflow and the shared conditions | branch here, fork with and without `ci:run`, another label, draft with the label, ready, push, merge group, dispatch | a job that can start on a pull request without the condition, a label trigger, a required job that skips for a pull request that may not run CI, or a draft or unlabelled fork that runs fails |
| FR19 | `ci-impact.test.mjs`, `pr-preview.test.mjs` and the maintenance template | CI change and non-CI change; standard, non-standard and expression runners; added, removed and changed jobs; trigger change | a CI change reports no impact, a move onto a non-standard runner or a pool or time-to-green rise past its threshold goes unflagged, or the section names a price |