Skip to content

test(ci): make stalled audit budget tests deterministic - #137983

Closed
steipete wants to merge 1 commit into
mainfrom
steipete/fix-pnpm-audit-stalled-budget-flake
Closed

steipete wants to merge 1 commit into
mainfrom
steipete/fix-pnpm-audit-stalled-budget-flake

Conversation

@steipete

@steipete steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Related: #137960 (advisory validation and total outage budget); observed in #137971 (This Mac settings PR CI).

What Problem This Solves

Resolves a problem where the production-audit stalled-body tests intermittently fail unrelated PR CI with “expected vi.fn() to be called once, but got 2 times.” The reported failure occurred in core-tooling-12-hosted-3 in run 33843525043. The HTTP 503 case also reproduced locally before this change.

Why This Change Was Made

The tests now advance fake request timers and performance.now() together to the exact 20 ms budget boundary, retaining the assertions for one fetch, cancelled body, and timeout/permanent-403 error. Real timers round fractional milliseconds while the deadline uses a high-resolution clock, so the old real-backoff test could reach the retry check with a small positive remainder.

The implementation deliberately clamps each attempt to the remaining budget; it does not require the full configured request timeout before retrying. Ordinary CI itself uses a 30-second budget with a 60-second default request timeout. Changing that policy to stabilize this assertion would alter legitimate recovery behavior. The fix belongs in the test's timing control; timers are restored in finally, and separate real-timer lifecycle and backoff-budget coverage remains.

User Impact

Developers get deterministic stalled-body CI coverage. Production audit behavior, retry policy, budgets, and error classification are unchanged.

Evidence

Before the fix, node scripts/run-vitest.mjs test/scripts/pnpm-audit-prod.test.ts -t stalled reproduced the reported failure:

FAIL bounds stalled HTTP 503 bodies by the total budget
AssertionError: expected "vi.fn()" to be called once, but got 2 times
Tests  1 failed | 6 passed | 55 skipped (62)

After the fix:

  • node scripts/run-vitest.mjs test/scripts/pnpm-audit-prod.test.ts: 62 tests passed.
  • The requested loop (for i in $(seq 1 15); do node scripts/run-vitest.mjs test/scripts/pnpm-audit-prod.test.ts -t "stalled" || exit 1; done) passed every iteration:
Run  1/15: Tests  7 passed | 55 skipped (62); [test] passed 1 Vitest shard in 1.73s
Run  2/15: Tests  7 passed | 55 skipped (62); [test] passed 1 Vitest shard in 1.32s
Run  3/15: Tests  7 passed | 55 skipped (62); [test] passed 1 Vitest shard in 1.34s
Run  4/15: Tests  7 passed | 55 skipped (62); [test] passed 1 Vitest shard in 1.45s
Run  5/15: Tests  7 passed | 55 skipped (62); [test] passed 1 Vitest shard in 2.22s
Run  6/15: Tests  7 passed | 55 skipped (62); [test] passed 1 Vitest shard in 1.56s
Run  7/15: Tests  7 passed | 55 skipped (62); [test] passed 1 Vitest shard in 1.40s
Run  8/15: Tests  7 passed | 55 skipped (62); [test] passed 1 Vitest shard in 1.31s
Run  9/15: Tests  7 passed | 55 skipped (62); [test] passed 1 Vitest shard in 1.24s
Run 10/15: Tests  7 passed | 55 skipped (62); [test] passed 1 Vitest shard in 1.39s
Run 11/15: Tests  7 passed | 55 skipped (62); [test] passed 1 Vitest shard in 1.41s
Run 12/15: Tests  7 passed | 55 skipped (62); [test] passed 1 Vitest shard in 1.22s
Run 13/15: Tests  7 passed | 55 skipped (62); [test] passed 1 Vitest shard in 1.46s
Run 14/15: Tests  7 passed | 55 skipped (62); [test] passed 1 Vitest shard in 1.38s
Run 15/15: Tests  7 passed | 55 skipped (62); [test] passed 1 Vitest shard in 1.57s
15/15 runs passed (7 stalled tests per run; 105 total passes).
  • CPU-pressure proof: node scripts/run-vitest.mjs test/scripts/pnpm-audit-prod.test.ts -t stalled with eight parallel Node busy loops: 7 passed, 55 skipped; all eight workers terminated afterward.

  • node scripts/check-changed.mjs: exit 0 (formatting, root test types, script lint, changed-test lint, and repository guards).

  • Independent Codex autoreview: scoped-clean, no actionable P0–P2 findings.

Production/tooling LOC: +0/-0. Tests: +7/-6 (net +1).

@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 06:34
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 2:44 AM ET / 06:44 UTC.

ClawSweeper review

What this changes

The PR makes the stalled advisory-response tests advance fake time and the deadline clock together before asserting that the audit aborts after its total budget.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 2 items remain

No introduced correctness defect was found. Current main still lacks this test-only clock alignment, and this maintainer-authored PR should remain open for normal maintainer handling.

Priority: P2
Reviewed head: 90f3e6b2b4aa7bd48e94ff70f449ba4a0d813314

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A small, coherent test-harness correction with an observed prior failure and repeated reported after-fix runs.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored, test-only PR includes reported before/after terminal runs; the external-contributor real-behavior gate does not apply.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored, test-only PR includes reported before/after terminal runs; the external-contributor real-behavior gate does not apply.
Evidence reviewed 5 items Introduced test change: The verified PR-introduced hunk replaces a real backoff timer with fake timers that include performance, advances exactly 20 ms, and restores real timers in finally.
Production owner boundary: The audit implementation derives its total deadline from performance, bounds each request timeout by the remaining budget, and rechecks that budget after retry backoff; the PR does not modify this production code.
Current-main necessity: The fetched main advanced from the PR base through two unrelated commits, and neither the audit implementation nor this test changed in that range; the focused fix is therefore not already on current main.
Findings None None.
Security None None.

How this fits together

The dependency-audit script calls npm’s advisory endpoint and bounds each request, response-body read, and retry by a total deadline. Its tooling tests simulate stalled HTTP bodies and assert that the request is cancelled without an extra retry.

flowchart LR
A[Audit test] --> B[Stalled HTTP response]
B --> C[Total deadline]
C --> D[Timeout and cancellation]
D --> E[Retry decision]
E --> F[One request assertion]
E --> G[Error outcome assertion]
Loading

Before merge

  • Resolve merge risk (P1) - The unavailable Vitest dependency source prevents an independent API-contract check in this read-only environment; this is a reviewer limitation, not missing contributor proof.
  • Resolve review confidence - ClawSweeper must reach high confidence before merge readiness is known.
Agent review details

Security

None.

PR surface

Tests +1. Total +1 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 7 6 +1
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 7 6 +1

Review metrics

Metric Value Why it matters
Production versus test delta production +0/-0; tests +7/-6 The change is confined to the timing harness for an existing stalled-response regression test.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the single-clock fake-timer harness so the test deterministically verifies the existing total-budget behavior without changing production retry policy.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the single-clock fake-timer harness so the test deterministically verifies the existing total-budget behavior without changing production retry policy.

Do we have a high-confidence way to reproduce the issue?

Yes. The supplied pre-change terminal trace records the focused HTTP 503 failure, and source inspection shows the old test mixed a real backoff timer with a performance-based deadline.

Is this the best way to solve the issue?

Yes. Controlling the test’s timeout and deadline clocks together fixes the test-only race at the owner boundary while preserving the production audit client’s remaining-budget behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against fcdd8533696b.

Labels

Label changes:

  • add P2: This repairs an intermittent CI test failure with limited blast radius and no production behavior change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored, test-only PR includes reported before/after terminal runs; the external-contributor real-behavior gate does not apply.

Label justifications:

  • P2: This repairs an intermittent CI test failure with limited blast radius and no production behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored, test-only PR includes reported before/after terminal runs; the external-contributor real-behavior gate does not apply.

Evidence

What I checked:

  • Introduced test change: The verified PR-introduced hunk replaces a real backoff timer with fake timers that include performance, advances exactly 20 ms, and restores real timers in finally. (test/scripts/pnpm-audit-prod.test.ts:622, 90f3e6b2b4aa)
  • Production owner boundary: The audit implementation derives its total deadline from performance, bounds each request timeout by the remaining budget, and rechecks that budget after retry backoff; the PR does not modify this production code. (scripts/pre-commit/pnpm-audit-prod.mjs:892, 90f3e6b2b4aa)
  • Current-main necessity: The fetched main advanced from the PR base through two unrelated commits, and neither the audit implementation nor this test changed in that range; the focused fix is therefore not already on current main. (test/scripts/pnpm-audit-prod.test.ts:619, fcdd8533696b)
  • Feature history: History places the merged total-outage-budget audit work immediately before this follow-up, while the earlier stalled-body cancellation work dates to commit 975340f. (scripts/pre-commit/pnpm-audit-prod.mjs:882, ec87f919535c)
  • Vitest contract limitation: The patch directly uses Vitest fake-timer APIs, but this read-only worktree has no installed Vitest source and GitHub was unreachable, so the supplied repeated test output remains the available confirmation of those API semantics.

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded by the already-landed audit-test hunk in commit 5871f31ab78d6be12a1e3767931e6d5ac57f358e, included in PR #137853.

I compared this PR's diff with the raw landed commit and current main 0d2169fdabc48931e666ab227daca779fa9cba65. Main uses the same fake setTimeout, clearTimeout, and performance clock, keeps the one-fetch, cancellation, error, and finally/useRealTimers assertions, and strengthens the boundary proof by asserting no cancellation at 19 ms before advancing the final 1 ms. Resolving the conflict here would duplicate that existing repair.

Fresh proof on the diagnostic branch rebased onto that main commit:

node scripts/run-vitest.mjs test/scripts/pnpm-audit-prod.test.ts

68 passed on Node 24.20.0. The audit test and production owner are identical to that main commit; the branch's only delta is the four-file SQLite diagnostic patch in #137999. This full-file run includes the newer retry-policy tests, and the production audit owner from PR #137989 is preserved unchanged.

I also personally checked Vitest v4.1.11's async advancement and fake/real timer lifecycle, resolving the earlier review's dependency-source retrieval limitation. The author's branch and worktree are retained.

@steipete steipete closed this Sep 4, 2026
@RomneyDa
RomneyDa deleted the steipete/fix-pnpm-audit-stalled-budget-flake branch October 22, 2026 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant