Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

test: stop the CI fail-fast contract from silently losing a leaf job

[._.]/ Adam Eivyf6472bd5fed6
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 9c34521f9b..96a3ab4c0d 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -50,6 +50,14 @@ jobs:
full-ci:
needs: verify-ci
if: needs.verify-ci.outputs.verified != 'true'
+ # `actions: write` looks unused from here — the fail-fast cancellation step
+ # in ci.yml's leaf jobs is gated on `github.event_name == 'pull_request'`,
+ # and a called workflow inherits the caller's event, which is this push.
+ # It still has to be granted: a called workflow's jobs cannot hold a
+ # permission the calling job does not, so narrowing this to `contents: read`
+ # strips `actions: write` from leaf jobs that declare it. This block also
+ # scopes full-ci DOWN from the workflow-level `contents: write` the release
+ # job needs; ci.yml only ever checks out. ci-fail-fast.test.js pins it.
permissions:
contents: read
actions: write
diff --git a/docs/GITHUB_ACTIONS.md b/docs/GITHUB_ACTIONS.md
index 18ffd8b4c0..c0394f26fa 100644
--- a/docs/GITHUB_ACTIONS.md
+++ b/docs/GITHUB_ACTIONS.md
@@ -274,28 +274,54 @@ endpoint. The helper accepts no repository or run arguments: it validates and
uses only `GITHUB_REPOSITORY` and `GITHUB_RUN_ID` supplied by Actions, with the
step-scoped `GITHUB_TOKEN`.
-The leaf jobs request only `contents: read` and `actions: write`. The token is
-present in the environment only for the cancellation step, and no third-party
-action or long-lived secret is involved. The failing test/build step runs
-before cancellation, so its annotations and logs remain the evidence for the
-failure. A successful cancellation returns `202`; a `409` means the run is
-already terminal and is treated as a no-op.
+The leaf jobs request only `contents: read` and `actions: write`, and check
+out with `persist-credentials: false` so a token that can now cancel runs is
+not left in `.git/config` for the test suite's own subprocesses to read. The
+token is present in the environment only for the cancellation step, and no
+third-party action or long-lived secret is involved. The failing test/build
+step runs before cancellation, so its annotations and logs remain the evidence
+for the failure. A successful cancellation returns `202`; a `409` means the run
+is already terminal and is treated as a no-op.
+
+`release.yml`'s `full-ci` job must grant `actions: write` to the workflow it
+calls even though the cancellation step never fires there — a called workflow's
+jobs cannot hold a permission the calling job lacks. See the comment on that
+job; `scripts/ci-fail-fast.test.js` pins it.
Cancellation is deliberately best-effort. Fork pull requests and other
read-only-token runs may receive a permission failure, and transient API or
network failures are also possible. The helper logs the unavailable
cancellation and exits normally, preserving the original failed step and its
-failed job result when the API is unavailable. When cancellation succeeds, the
-run-wide cancellation can mark the requesting job and `CI Gate` as canceled;
-the failed step's log and annotations remain the diagnostic evidence, and a
-canceled result is still non-mergeable. `CI Gate` allows only `success` or
-`skipped` results; failed or canceled leaf jobs therefore cannot satisfy the
-required aggregate context. The target is for siblings to become canceled
-within 30 seconds of the first failing job completing, while the existing
-workflow-level concurrency cancellation continues to handle newer runs
-independently. Scheduled, manually dispatched, and release-called runs skip
-this sibling cancellation so their aggregate diagnostics and cache post-steps
-can complete normally.
+failed job result when the API is unavailable. It imports only Node builtins,
+so it still runs from a job that failed before `npm ci`
+(`scripts/pre-install-entrypoints.test.js` enforces that).
+
+**Canceled is not mergeable.** A run-wide cancellation lands on the requesting
+job and on `CI Gate`, which is usually still waiting on its `needs` and so ends
+`cancelled` rather than running its comparison. Every consumer treats that as a
+non-pass, by allowlisting the green results rather than denylisting the red
+ones:
+
+- Branch protection requires the `CI Gate` context to conclude `success`;
+ `cancelled` does not satisfy it, and a gate that never publishes leaves the
+ required context unreported, which also blocks.
+- If the gate job does run, it accepts only `success` or `skipped` per job, so
+ the failed leaf (or its own `cancelled` result) fails the gate.
+- `scripts/verify-ci-status.js` accepts a `Full CI Gate` only at
+ `conclusion === 'success'`, so a canceled run can never let a release skip
+ the full suite.
+- PortOS's own auto-merge watcher (`server/services/prWatcher.js`) counts only
+ `SUCCESS`/`NEUTRAL`/`SKIPPED` as green.
+
+The consequence to expect in the UI: on a fail-fast run the required check
+reads *canceled*, not *failed*. The failing step's log and annotations are
+still the diagnosis. The target is for siblings to become canceled within 30
+seconds of the first failing job completing, while the existing workflow-level
+`concurrency.cancel-in-progress` continues to handle superseded runs
+independently — the two are orthogonal, one canceling this run by id and the
+other canceling an older run when a newer commit arrives. Scheduled, manually
+dispatched, and release-called runs skip this sibling cancellation so their
+aggregate diagnostics and cache post-steps can complete normally.
### Impact-planner safety rules
diff --git a/scripts/ci-fail-fast.test.js b/scripts/ci-fail-fast.test.js
index e297503b28..d1279cdd62 100644
--- a/scripts/ci-fail-fast.test.js
+++ b/scripts/ci-fail-fast.test.js
@@ -7,8 +7,20 @@ import { describe, expect, it } from 'vitest';
const REPO_ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
const WORKFLOW = readFileSync(join(REPO_ROOT, '.github/workflows/ci.yml'), 'utf8');
const NON_LEAF_JOBS = new Set(['impact', 'gate', 'full-gate']);
+// The expensive fan-out jobs that exist today. A FLOOR, not a snapshot: a new
+// leaf job has to be discovered on its own and held to the contract below, so
+// nothing here has to be edited to add one. What this list catches is the
+// opposite — discovery silently ceasing to see one of the four while the other
+// three keep every assertion green.
+const EXPECTED_LEAF_JOBS = ['client', 'database', 'server', 'windows-server'];
+const CANCEL_STEP_HEADING = ' - name: Cancel sibling CI jobs after failure';
+// Both spellings of the dependency. Under a scalar-only pattern, a leaf job
+// rewritten to the list form (`needs: [impact]`) dropped out of every assertion
+// below without failing anything — the exact silent coverage loss this contract
+// exists to prevent.
+const NEEDS_IMPACT = /^\s*needs:\s*(?:impact\s*$|\[[^\]]*\bimpact\b)/m;
const FAIL_FAST_STEP = [
- ' - name: Cancel sibling CI jobs after failure',
+ CANCEL_STEP_HEADING,
" if: failure() && github.event_name == 'pull_request'",
' env:',
' GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}',
@@ -35,18 +47,27 @@ function workflowJobs(yaml) {
describe('ci.yml fail-fast cancellation contract', () => {
const jobs = workflowJobs(WORKFLOW);
const leafJobs = Object.keys(jobs).filter((id) => (
- !NON_LEAF_JOBS.has(id) && /^\s*needs:\s*impact\s*$/m.test(jobs[id])
+ !NON_LEAF_JOBS.has(id) && NEEDS_IMPACT.test(jobs[id])
));
it('discovers every direct impact leaf job for contract checks', () => {
- expect(leafJobs).not.toHaveLength(0);
+ expect(leafJobs).toEqual(expect.arrayContaining(EXPECTED_LEAF_JOBS));
+ });
+
+ it('covers every cancellation step the workflow actually installs', () => {
+ // The discovery floor from the other side. A cancellation step added to a
+ // job this file does not classify as a leaf would never be checked for the
+ // `actions: write` grant it needs, and a missing grant fails only at
+ // runtime — inside a job that is otherwise passing.
+ const installed = WORKFLOW.split(CANCEL_STEP_HEADING).length - 1;
+ expect(installed).toBe(leafJobs.length);
});
it('adds the cancellation step as the final step of every expensive leaf job', () => {
for (const id of leafJobs) {
const body = jobs[id];
expect(body, id).toBeTruthy();
- const step = body.slice(body.lastIndexOf(' - name: Cancel sibling CI jobs after failure')).trimEnd();
+ const step = body.slice(body.lastIndexOf(CANCEL_STEP_HEADING)).trimEnd();
expect(step, id).toBe(FAIL_FAST_STEP);
expect(body.match(/GITHUB_TOKEN:/g), id).toHaveLength(1);
}
@@ -66,7 +87,7 @@ describe('ci.yml fail-fast cancellation contract', () => {
for (const id of leafJobs) {
const body = jobs[id];
expect(body, id).not.toMatch(/GITHUB_(?:REPOSITORY|RUN_ID):/);
- const step = body.slice(body.lastIndexOf(' - name: Cancel sibling CI jobs after failure'));
+ const step = body.slice(body.lastIndexOf(CANCEL_STEP_HEADING));
expect(step, id).not.toContain('\n with:');
expect(body, id).toContain('if: failure()');
}
@@ -83,8 +104,11 @@ describe('ci.yml fail-fast cancellation contract', () => {
});
it('grants the reusable release caller the permission leaf jobs require', () => {
+ // Bounded to the full-ci job: slicing to end of file would let a
+ // permissions block on the later `release` job satisfy this instead.
const releaseWorkflow = readFileSync(join(REPO_ROOT, '.github/workflows/release.yml'), 'utf8');
- const fullCi = releaseWorkflow.slice(releaseWorkflow.indexOf('\n full-ci:'));
+ const fullCi = workflowJobs(releaseWorkflow)['full-ci'];
+ expect(fullCi).toBeTruthy();
expect(fullCi).toMatch(/\n permissions:\n contents: read\n actions: write\n/);
});
});