Skip to content

test(backend): the read-back budget is a bound, not an exact attempt count (TASK-112) - #1839

Merged
lilyshen0722 merged 1 commit into
mainfrom
kai/npm-readback-budget-bound
Sep 23, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
kai/npm-readback-budget-bound

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

The only required check on main (Test & Coverage) flaked red on #1838 — a PR that touches no backend test — with expected 3, received 2 in npmPublishReadback. This fixes that assertion.

The count is a function of the runner's speed, not a contract. The script's budget clock is date +%s, one-second granularity (scripts/verify-npm-publish-readback.sh:55,60), and every attempt spawns a stub process. Measurements on the same code:

stub attempt count
fast (local) 3
loaded CI runner (#1838, job 107092464765) 2
STUB_SLEEP_SECONDS=1 (reproduced on demand) 1

So attempts === 3 was an assertion about the runner. Worse than flaky: it is the only required status check, so it goes red at random for every open PR, and the natural reading of a red required check is that the PR is bad.

What is asserted now — the contract, in two cost profiles:

  • a fast stub: 2..3, because the budget can already be spent at the second attempt;
  • a stub that spends the budget in its own calls (STUB_SLEEP_SECONDS=1): 1..2, deterministic, and it keeps a strict assertion by pinning the cost profile the fast row is racing.

Exit code 1 and the exhaustion message (::error::@commonlyai/cli@<v>) remain strict — the decision the script exists to make is unchanged by the count. A residual is stated in the comment rather than hidden: a first attempt costing more than the entire budget would still read as 1.

Verification. Mutation-proved 3/3 against the script (/tmp/kai112-ledger.py): the budget never reached (lower bound bites); the interval not slept, so the budget is spent in a burst (upper bound bites); exhaustion exiting 0 (the status assertion bites). Baseline: 0 failure lines, 10/10 passed. Three consecutive runs of the file: 10/10 each. Test-only, backend, no version slot.

Disclosure — two more flaky members of the same required check, measured but not diagnosed. A full backend run in this worktree gave Test Suites: 2 failed, 420 passed with registry.runtime-tokens.test.js › issues a runtime token for an installed agent and AgentMemory.test.ts › enforces unique (agentName, instanceId). Both then passed in isolation, in this worktree and in a clean main worktree (21/21 both times), so they are load/parallelism-dependent rather than deterministic. I have not isolated their mechanism, so this is a report and not a diagnosis — but if the required check is going to be trusted as a signal, those two want the same treatment as this one.

…count (TASK-112)

`npmPublishReadback` asserted `attempts === 3` for a 2s budget with a 1s
interval. The script's budget clock is `date +%s` — one-second granularity
(verify-npm-publish-readback.sh:55,60) — and every attempt spawns a stub
process, so the count is a function of the runner's speed. Measured on the same
code: 3 with a fast stub, 2 on a loaded CI runner (#1838's run, job
107092464765: expected 3, received 2, in a PR touching nothing here), and 1
with STUB_SLEEP_SECONDS=1. The assertion was about the runner, not the script.

Asserted as the contract instead: the budget stops the loop within one interval
of expiring, in two cost profiles — a fast stub (2..3) and a stub that spends
the budget in its own calls (1..2, deterministic). Exit 1 and the exhaustion
message stay strict, and the residual (a first attempt costing more than the
whole budget would read as 1) is stated in the comment rather than hidden.

Mutation-proved 3/3 against the script: budget never reached; interval not
slept (the burst case that the upper bound catches); exhaustion exiting 0.
Baseline 0 failure lines, 10/10.
@lilyshen0722
lilyshen0722 force-pushed the kai/npm-readback-budget-bound branch from 3a20e66 to a44a63c Compare September 23, 2026 09:46
@lilyshen0722
lilyshen0722 merged commit 0c4f950 into main Sep 23, 2026
14 checks passed
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