Skip to content

Commit cf058cc

Browse files
fix(delivery): natural stdout exit for the adversarial runner — Linux piped reports kept their tail
process.exit() after the report truncated the perf/verdict lines on Linux (review-table contract red on CI); exitCode now drains the queue. Plus index-safe row parsing and the [C14] lesson in AGENTS.md. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 53bff50 commit cf058cc

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎AGENTS.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ title to jump.
5353
| C11 | NegativeSuite premise path | contained: the suite fails correctly — just run it from the platform dir |
5454
| C12 | Stale GREEN — session-persisted candidates mutate between verdict and use | near-miss class: defensive re-reading made it contained |
5555
| C13 | Hand-built ZIP without unix external attrs extracts mode-0000 on Linux | real red CI run (EACCES); invisible on Windows — CI caught it |
56+
| C14 | `process.exit()` after a big stdout report truncates its tail on Linux | real red CI run (reviewer-table contract lost the perf/verdict tail); invisible on Windows |
5657

5758
- [C1] **Multi-line plain scalar with `": "` kills the whole workflow (zero jobs)**: a `run:` value written as a plain (non-block) multi-line YAML scalar containing a JS literal like `console.error('health check failed: ...')` — the `": "` inside a plain scalar is unparseable → GitHub marks the run `failure` with **zero jobs built**. That zero-jobs conclusion IS the signature of an unparseable workflow file (not a failing step). Fix: any multi-line `run:` must be a real block scalar (`run: |` on its own line). Trap within the trap: a string-matching "validator" whose `||` fallback jumped to a fake parser reported PASS — only a real YAML parser or GitHub itself building the job proves the file parses (cost a push + a red run). Now enforced mechanically: `test/ci/workflow-yaml-contract.test.js` parses every `.github/workflows` file and the composite action with the real `yaml` parser (dev dep) plus an Actions schema walk — an unparseable or schema-deviant file fails the push locally with file+line naming, before GitHub ever sees it. Runs inside `npm run prepush` too (scripts/pre-push-check.mjs), the mechanical pre-push checklist built from the YAML/workflow lessons: workflows-parse [C1] · freeze-integrity [C2] · pin-eol-cover [C3] · no-skip-ci (the skip-token vortex) · repin-reachable (the rebase rewrite trap) · remote-fresh (the bot race, with the autostash remedy named).
5859
- [C2] **Commit-anchored verification (4.2.6+)**: `validate-freeze.mjs` hashes `git show <gitCommit>:<path>` blobs, not disk bytes. Disk mode (`--disk`) is triage-only, prints "not evidence". Records without `gitCommit` fail COMMIT-UNANCHORED (historical included — correct). Editing a file whose bytes exist only in a future commit requires a **two-phase re-anchor**: commit phase 1, then point `gitCommit`/`postCommitRePins` at that hash in phase 2. Release entries are platform-dir relative; quarantine entries repo-root relative; repo-root files outside the platform dir use `../` prefixes (stripped by `treePath`/`repoRelPath` — the honesty test must mirror this or bare-name pins hash the wrong file).
@@ -67,6 +68,7 @@ title to jump.
6768
- [C11] **NegativeSuite premise path**: `-Manifest` is resolved via `Test-Path -LiteralPath` from the CWD — run the suite from the platform dir, not the repo root, or the manifest premise becomes PRECONDITION_FAILURE and fails the whole cycle (correctly). It rewrites frozen `negative-tests.json`; determinism proof = git diff empty after rerun.
6869
- [C12] **Stale GREEN: session-persisted candidates mutate between verdict and use (read scope consent defensively)**: a candidate directory that survives across steps or sessions is a mutable surface — the consent/disclosure scope (and any record) can change between the gate's GREEN verdict and the moment a consumer (e.g. `convert-to-fixture.mjs`) reads the files, so a **remembered** GREEN from an earlier step would package records the gate never saw. Defensive reading: a verdict binds to exact bytes (pins), and every consumer re-runs the gate on the same tree it reads — never trust a verdict carried across steps. The intake pipeline does exactly this: `convert-to-fixture.mjs` re-runs the gate as its first act on the directory it then reads, and re-verifies pins against disk after write — the reason the pipeline never converts on stale consent.
6970
- [C13] **Hand-built ZIP needs unix external attrs or Linux extracts mode-0000**: writing only the local headers/CRC leaves the central-directory external-attributes field zero; `made-by: unix (0x031e)` makes Info-ZIP derive the mode from it → every extracted file is 0000 and reads EACCES on Linux (red CI run on `1a49d16`). Windows masks this entirely — always write `(0o100644 << 16)` at offset 38 when made-by is unix. The archive's determinism tests stay green on Windows either way, so only a Linux runner catches it.
71+
- [C14] **`process.exit()` right after a large piped stdout report truncates the tail on Linux**: stdout writes to a pipe are asynchronous — exit before the queue drains silently drops whatever is still buffered (the new reviewer-table contract on `09b4aae` lost exactly the `perf` and `verdict` lines from a ~300-line runner report; local Windows runs are synchronous and always green, so only Linux CI showed it). Rule: CLIs that print a report set `process.exitCode` and let the event loop drain — reserve `process.exit()` for usage-error exits where the (tiny) stderr message going missing is harmless. The runner now uses `process.exitCode` in both its text and JSON branches, with the drain rule commented at each site.
7072

7173
## Files That Change Together
7274

‎examples/delivery-fixture/adversarial-runner.mjs‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,16 @@ if (jsonMode) {
470470
: "ALL MUTATIONS CAUGHT (single + compound) — the gate bites where it claims to")
471471
: "GATE HOLE — see results",
472472
}, null, 2));
473-
process.exit(allClear ? 0 : 1);
473+
// Exit naturally (process.exitCode, NOT process.exit): after a big report,
474+
// piped stdout is still draining asynchronously — process.exit() would
475+
// truncate the report tail on Linux. Set the code and let the loop drain.
476+
process.exitCode = allClear ? 0 : 1;
474477
}
475478

479+
// The text report lives in a labeled block: --json mode set its exit code
480+
// above and breaks straight past it (top-level ESM cannot `return`).
481+
textReport: {
482+
if (jsonMode) break textReport;
476483
console.log(line);
477484
console.log("CoreGuard DDE — Adversarial Runner (one mutation per fail-closed check)");
478485
console.log(line);
@@ -536,4 +543,9 @@ if (perf.overBudget.length) {
536543
console.log(`perf verdict: ${perf.overBudget.length} cycle(s) over the ${perf.budgetMs}ms per-cycle budget — engine slowdown under combinational load (correctness verdict above is unaffected)`);
537544
}
538545
console.log(`boundary: ${BOUNDARY_BANNER.statement}`);
539-
process.exit(allClear ? 0 : 1);
546+
// Natural exit — same stdout-drain rule as the JSON branch above. The perf
547+
// budget line and the verdict itself live at the tail of a piped report;
548+
// process.exit() here silently truncates them on Linux (caught live by the
549+
// reviewer-table contract test on CI).
550+
process.exitCode = allClear ? 0 : 1;
551+
}

0 commit comments

Comments
 (0)