Skip to content

feat(tooling): tracked flaky-test quarantine (cli, vitest-wired) - #275

Merged
heavygee merged 4 commits into
mainfrom
feat/flaky-quarantine
Nov 9, 2026
Merged

heavygee merged 4 commits into
mainfrom
feat/flaky-quarantine

Conversation

@heavygee

Copy link
Copy Markdown
Owner

Summary

Operator-directed: flaky tests were being adjudicated one red light at a time, each time an agent escalating to the operator for a judgement call on a test it didn't write. This tracked a week-long block on PR #222 (iOS app-build, 3 different failures, #273) and a tripped remat gate (agentCliGuard.test.ts, #274) back to their actual CI evidence, filed both as issues, and builds the quarantine mechanism to stop future instances from needing a human in the loop.

A quarantined test still runs and still reports. This is a tracked quarantine, not an ignore list:

  • Known id + matching failure signature → excused (non-blocking)
  • Known id + a DIFFERENT signature → BLOCKS (closes most of "new bug lands in the same test")
  • An expired entry excuses nothing — it drops out of the active set and goes back to blocking
  • A ceiling on active entries (default 8) fails the gate regardless of test outcomes once exceeded

Full design rationale: docs/tooling/flaky-quarantine.md.

What's wired vs. drafted

  • cli (vitest): fully wired, both in hapi-driver-rebuild.sh --verify and .github/workflows/test.yml (fork-only — upstream keeps plain bun run test), via the shared scripts/tooling/flaky-quarantine-gate.sh.
  • iOS (XCTest): the from-xcodebuild-log adapter is built and proven against the three real PR feat(cli): land upstream #1564 display_links on the fork #222 attempt logs, but not wired into ios.yml/test-transcript.sh — no macOS runner available to verify the shell integration (bun-on-runner, PIPESTATUS behavior). Wiring it blind risked turning a flake into a hard break on a live gating workflow.

Review history

A cold review (full diff trace, empirically tested against the real vitest 4.0.16 reporter source and the hand-rolled YAML parser) caught two Critical and two Important issues before this reached a live gate, all fixed in the second commit:

  1. Cross-package coupling — check validated the whole registry regardless of which package ran, so an unrelated ios: entry going invalid (e.g. its issue closing) would fail a cli-only gate for an unrelated reason. Fixed with --package PREFIX scoping; the ceiling stays deliberately whole-registry via a separate validate step.
  2. Dangerously generic signature on the one live cli: entry — would have silently excused a real, different bug in a sibling assertion two lines below. Anchored to the failing stack frame instead; verified against both the real flake (excuses) and a synthetic sibling failure (now blocks).
  3. Expiry had a sub-day off-by-one (entry expired at the first instant of its date, not the end of it) — fixed.
  4. The new CI step's gh issue view call had no GH_TOKEN wired — would have silently failed the gate on every run. Fixed to match the pattern already used elsewhere in this repo.

Verification

Test plan

  • bash scripts/tooling/flaky-quarantine.test.sh
  • bun scripts/tooling/flaky-quarantine.mjs validate
  • Full flaky-quarantine-gate.sh run against the driver tree
  • Smoke-test the iOS wiring on an actual macOS CI run before applying it (follow-up, not in this PR)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d6b4c7d50

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread config/flaky-quarantine.yaml Resolved
Comment thread scripts/tooling/flaky-quarantine.mjs Resolved
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T15:08:17.003872Z 18ae769 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 26d4180476

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/tooling/flaky-quarantine.mjs Resolved
@heavygee

heavygee commented Nov 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: c2aaa005fc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@heavygee
heavygee force-pushed the feat/flaky-quarantine branch from c2aaa00 to fa8f306 Compare November 2, 2026 23:05
@heavygee

heavygee commented Nov 2, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: fa8f306cac

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

heavygee and others added 4 commits November 5, 2026 15:05
Operator-directed: flaky tests were adjudicated one red light at a time,
costing a week on PR #222 (iOS app-build, 3 different failures, #273) and
tripping the #270 remat gate (agentCliGuard.test.ts, #274). A tolerated red
teaches everyone red doesn't mean red.

config/flaky-quarantine.yaml is the single source of truth both the remat
gate and CI consult (scripts/tooling/flaky-quarantine-gate.sh). Three rules:
known id + matching failure signature excuses; a DIFFERENT signature under
the same id blocks (closes most of the "new bug in the same test" gap);
an expired entry excuses nothing. A ceiling on active entries (default 8)
fails the gate independent of test outcomes once exceeded.

Wired for cli (vitest JSON reporter -> adapter -> check) in both
hapi-driver-rebuild.sh --verify and .github/workflows/test.yml (fork-only;
upstream keeps plain `bun run test`). The iOS xcodebuild-log adapter is
built and proven against the real PR #222 failure logs but NOT wired into
ios.yml/test-transcript.sh yet — no macOS runner available here to verify
the shell integration; wiring it blind risked turning a flake into a hard
break on a live gating workflow.

scripts/tooling/flaky-quarantine.test.sh fires three negative controls
(matching signature excuses, mismatched signature blocks, expired entry
blocks) plus schema/ceiling checks, picked up automatically by the existing
tooling-tests CI job.

via HAPI (https://hapi.run)

Co-Authored-By: HAPI <[email protected]>
Cold review caught two Critical and two Important issues before this
reached a live gate:

- Cross-package coupling: `check` validated the WHOLE registry regardless
  of which package actually ran, so an unrelated ios: entry going invalid
  (e.g. its issue closing) would fail a cli-only gate for a reason that
  has nothing to do with cli. Added `--package PREFIX` to `check`, scoping
  both validation and excuse/block matching to that namespace; the ceiling
  stays deliberately whole-registry (validate), run as its own explicit
  step in flaky-quarantine-gate.sh.
- The one live cli: entry's signature ("expected true to be false") was
  generic enough to also match a second, unrelated assertion two lines
  below in the same test — a real bug there would have been silently
  excused. Anchored the signature to the failing stack frame
  (agentCliGuard.test.ts:309:) instead; verified the real flake still
  excuses and a synthetic line-310 failure now correctly blocks.
- Expiry had a sub-day off-by-one: an entry expired at the first instant
  of its `expires` date rather than at the end of it. Fixed to stay valid
  through the whole calendar day.
- The new CI step's `gh issue view` (issue-must-be-open check) had no
  GH_TOKEN wired, unlike every other gh-using workflow in this repo —
  would have silently failed the gate on every run. Added the same
  GH_TOKEN/GITHUB_TOKEN pattern used elsewhere.

Added a regression test for the cross-package fix (an ios: schema error
no longer fails a --package cli check; unscoped validate still catches
it) and a direct verification of the expiry boundary.

via HAPI (https://hapi.run)

Co-Authored-By: HAPI <[email protected]>
…2 x6)

- Preserve non-assertion vitest failures: a runner-level crash (import
  error, zero tests discovered) exiting non-zero with no per-test
  assertions previously normalized to an empty results list and the gate
  reported a clean pass. check now takes --runner-exit-code and
  unconditionally blocks when it's non-zero with nothing attributable.
- Require the known assertion text AND its call site to both match, not
  either alone: signature now supports " && "-joined required substrings.
  A location-only anchor (this session's own prior fix) could still
  mis-excuse a genuinely different failure that happens to throw from the
  same line; the live cli: entry now requires both.
- Reject day-overflow dates (2026-02-30 normalizes to 2026-03-02 under
  plain `new Date()` instead of failing) via a round-trip check.
- Make quarantine test fixtures independent of wall-clock expiry — they
  used the same near-term dates as the real registry, so every "currently
  active" scenario (including the ceiling fixture) would silently flip to
  expired/inactive on 2026-10-30 and permanently redden the tooling-tests
  CI job. Dates are now computed relative to the actual test run.
- Honor an inherited $BUN instead of bare `bun`/`bunx` throughout the gate
  script; hapi-driver-rebuild.sh now passes it through explicitly (it was
  never exported, so the previous refactor into a separate script silently
  dropped a custom bun path despite the rebuild script itself resolving it
  via "${BUN:-$HOME/.bun/bin/bun}").
- Reject partially-numeric issue/renewal_count values (parseInt("27O") ===
  27) — now requires the entire scalar to match integer syntax.
- Parse every quarantine list item regardless of field order: only a
  literal `- id:` line started an entry before, so `id` reordered or
  misspelled silently dropped the whole entry instead of raising a schema
  error.
- Default issue-open check now derives the repo from the `origin` git
  remote (overridable with --repo) instead of hardcoding heavygee/hapi,
  matching the module's own "generic mechanism" header.

Six new regression tests cover all of the above; full suite now 16/16.
Re-verified end-to-end against the real registry, the real PR #222/#270
captured failures, and a full gate run on the driver tree.

via HAPI (https://hapi.run)

Co-Authored-By: HAPI <[email protected]>
… x2, P2 x4)

- Represent suite-level vitest failures (collection/import errors, zero
  assertions) as their own normalized result instead of silently vanishing
  when results also contains an unrelated quarantined assertion failure —
  the id never matches a registry entry, so it blocks as "not quarantined"
  by the same path a real failure would.
- Require EVERY attached failure message to match the signature, not just
  one joined into a blob: normalized results now carry `messages: string[]`
  end to end. A quarantined test with a known-signature failure plus a
  second, different message (multiple expect.soft() failures is a real
  shape already used in cli/src/agent/permissionJson.test.ts) now blocks
  on the second message instead of being excused by the first.
- Start a YAML list item on ANY `- <key>:` marker, not only known field
  names — `- iid: "..."` (typo'd id) now still creates an entry (which
  then correctly raises "id is required") instead of silently discarding
  the whole item and everything indented under it.
- Distinguish "renewal_count absent" (defaults to 0, fine) from "present
  but malformed" (now a schema error) — coerceField returns an {invalid}
  marker instead of collapsing both cases to the same default.
- Reject a future `added` date — a year typo (2099 vs 2026) previously
  still satisfied the 14-day added/expires window and the entry read as
  currently active.
- Reject an empty " && "-joined signature clause (trailing delimiter, or
  an all-whitespace clause) — message.includes('') is true for every
  message, so an empty clause silently excused anything under that id.
  matchesSignature also defends against this directly, independent of
  validation having run first.

Six new regression tests cover all of the above (22/22 total), including
one against the REAL vitest collection-error JSON captured from a live
`import of a nonexistent module` run, not just synthetic fixtures.
Re-verified end-to-end against the real registry and the real PR #222/#270
captured failures with the new messages[] shape.

via HAPI (https://hapi.run)

Co-Authored-By: HAPI <[email protected]>
@heavygee
heavygee force-pushed the feat/flaky-quarantine branch from fa8f306 to 18ae769 Compare November 5, 2026 15:06
@heavygee

heavygee commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 18ae769d4c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@heavygee

heavygee commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Note: the green oos-linux/test status above is the estate's local CI bridge (scripts/tooling/hapi-local-ci.sh), standing in while GitHub Actions dispatch is disabled on this fork (see #301, 32+ days now). It's a real test run via the Statuses API, not a GitHub Actions run — don't mistake it for one later.

heavygee added a commit that referenced this pull request Nov 9, 2026
The gate asked GitHub for check-runs and nothing else. Check-runs are written
by Actions; the Statuses API is a separate surface that check-runs never
reflects. heavygee/hapi has had Actions disabled since 2026-10-08 (#301/#243),
so its only real signal arrives as a commit status posted by the estate bridge
(hapi-local-ci.sh:98, context oos-linux/test).

Net effect: PRs that were genuinely verified were refused with "no check-runs
found" — the gate failing for a reason that was factually wrong. That is the
fastest way to teach people to route around a gate, which is precisely what
this one exists to prevent (tiann#1842).

Still fails closed:
  - trusted-context allowlist, NOT "any status"
    (HAPI_GATE_TRUSTED_STATUS_CONTEXTS, default oos-linux/test)
  - every accepted context must be success
  - neither surface having anything is a refusal, exactly as before

Verified by control matrix against live PRs:
  - POS  #275 (status green, 0 check-runs)      -> PASS
  - NEG1 same PR, bogus allowlist                        -> BLOCKED
         proves it accepts the trusted context, not any status
  - NEG2 #303 (no statuses, no check-runs)       -> BLOCKED
  - REG  tiann#1424 (5 real check-runs)                  -> check-runs path
         unchanged; correctly blocks on its mention-response failures

Also guards the new branch against `fail` being non-fatal: an empty trusted
set would otherwise pass the awk filter vacuously and print a bogus "ok"
underneath the refusal.

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <[email protected]>
@heavygee
heavygee merged commit c5f3568 into main Nov 9, 2026
1 check passed
@heavygee
heavygee deleted the feat/flaky-quarantine branch November 9, 2026 13:43
heavygee added a commit that referenced this pull request Nov 9, 2026
…ng the gate repo

`gh` treats --repo, -R, --repo=X and -RX as the same flag. The wrapper matched
only the literal "--repo", so `gh pr merge 275 -R heavygee/hapi` left repo_arg
empty, fell through to `gh repo view` (the cwd default repo), and ran the
pre-merge gate against the WRONG repository.

Observed today: a #275 merge was gated against tiann#275.
It failed closed only because upstream's #275 happened to be CLOSED and a draft.
A green same-numbered PR in the other repo would have produced RESULT: PASS for
a merge that nothing had verified — the exact failure mode tiann#1842 put this gate
here to prevent. The same gap let an out-of-scope `-R` repo inherit the cwd's
in-scope verdict.

4 new cases in gh-wrapper.test.sh asserting the gate receives the repo the
caller named, for each flag form. 13 passed / 0 failed.

Negative control: the same suite against the pre-fix wrapper → 10 passed /
**3 failed**, exactly the -R, --repo= and -RX cases, with --repo still passing.
The tests detect the real defect rather than passing vacuously.

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <[email protected]>
heavygee added a commit that referenced this pull request Nov 20, 2026
Reported by the flake-quarantine seat in its #275 exit reflection:
"hapi-pr-merge-gate.sh only reads check-runs, never the local-CI-bridge's
status API." Correct, and my earlier fallback patch did NOT cover it — that
fixed "no check-runs at all → fall back to statuses". Statuses were still only
read in that `else`, so the instant a repo produces check-runs the trusted
status stops being looked at.

Latent today, live imminently. Fork PRs currently have zero check-runs
(#275: check-runs=0, oos-linux/test=success), so the else branch still
reads them. Actions on the fork was dead for 32 days — root-caused in that same
reflection as a per-fork one-time consent flag on the /actions tab, not billing
— and now that it is re-enabled, check-runs will start appearing on fork PRs.
On that day the bridge's verdict would have gone silently unread.

New step 2b runs only when check-runs exist, and blocks solely on a trusted
context that is PRESENT and not success. Absence does not block: the bridge
legitimately never runs on upstream PRs (2147, 2544 and 945 all have zero
statuses), so requiring one would refuse every upstream merge.

Verified end to end on tiann#2544 (check-runs present, zero statuses):
  ok  all checks green on head bc6235c
  ok  trusted commit statuses ok (or absent) alongside check-runs
with RESULT unchanged (lane B only).

The present-and-failing path could NOT be exercised on a live PR — no upstream
PR carries statuses and the one fork PR that does is green — so it is verified
by a logic check over crafted input (failure → block, pending → block,
success → ok, untrusted context → ignored) rather than against real CI. Stated
rather than implied.

shellcheck -S error clean.

Refs #338

via [HAPI](https://hapi.run)

Co-Authored-By: HAPI <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant