Skip to content

test(broker): observe the bump at its seam, and say the retryable backoff is deliberate (TASK-172) - #2004

Merged
lilyshen0722 merged 1 commit into
mainfrom
kai/task172-retryable-lease
Sep 29, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
kai/task172-retryable-lease

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

Follow-up to #2001, cut from merged main. Two things, both from @vera's review of that PR (her message 75320).

1. The retryable path's held lease is deliberate, and now says so

A RETRYABLE vendor failure (refresh_unreachable) throws without calling markError, so the lease stays held until it expires — up to REFRESH_LEASE_MS of retryable credential_refreshing. Both readings were defensible and nothing in the file said which one the code means. It means the backoff: the three releases are the commit, the mark, and the expiry, so holding it for the rest of the window is the release valve. Releasing it on that path would let every caller queued behind the failure retry a vendor that has just answered 500 or 429, which is the storm the lease exists to damp. The generation the failed call bumped cannot strand anything — the fence is relative to the generation a caller read, so whatever refresh follows the lapsed lease starts from the value on the row and commits.

The comment at the throw says all of that, and the new arm makes it a measurement rather than prose:

  • a retryable failure leaves refreshingUntil at the literal T0 + 30s, with the generation bumped and nothing marked;
  • a queued caller is refused credential_refreshing (retryable) with the vendor not called again — vendorCalls === 1;
  • the expiry is the recovery path: the next call refreshes, generation 5, lease released, vendorCalls === 2.

Mutant M41 — release the lease on the retryable path, the exact "fix" a later reader would apply — is killed by that arm, so the documented behaviour is defended rather than merely described.

2. The fence arms no longer poll

waitForGeneration was the suite's only wall-clock budget, and its expiry failed a security arm in the direction that reads as the fence having broken. Vera saw exactly one such run (1 failed / 29 passed, message row never reached refreshGeneration 4) and neither of us could confirm it in 20+ runs since.

The landing is observable at the seam instead: defaultRowDeps() is exported so a test can wrap bumpGeneration around the REAL implementation while the other three row methods stay real. The mid-flight pre-image is then taken after that signal rather than after a poll, so no wall-clock wait remains in either arm and there is no budget left to expire under a slow mongod.

A wholesale row override is required because the deps merge is one level deep: spreading a wrapper onto store.deps.row finds nothing there — this suite injects no row at all. Measured, not assumed: that variant fails with TypeError: Cannot read properties of undefined (reading 'bumpGeneration').

Evidence

Ordering

Cut from merged main after #2001 (squash 986fa6b3's lineage). Nothing else is stacked on this branch; it is the last of the #2001 review round.

…the retryable backoff is deliberate (TASK-172)

Vera's review of #2001 named a residual rather than holding on it: a RETRYABLE
vendor failure throws without releasing the lease, so for up to REFRESH_LEASE_MS
every caller fails the bump and gets `credential_refreshing`. Both readings were
defensible and nothing in the file said which one the code means.

It means the backoff. Releasing the lease there would let every caller queued
behind the failure retry a vendor that has just answered 500 or 429, which is the
storm the lease exists to damp; the cost is bounded and retryable; and the
generation the failed call bumped cannot strand anything, because the fence is
relative to the generation a caller read — whatever refresh follows the lapsed
lease starts from the value on the row and commits normally.

The arm that follows from that sentence: a retryable failure leaves
`refreshingUntil` at the literal `T0 + 30s` with the generation bumped and nothing
marked; a queued caller is refused retryably with the vendor NOT called again; and
the expiry is the recovery path (second call refreshes, generation 5, lease
released). Mutant M41 — release the lease on the retryable path, which is the
"fix" a later reader would apply — is killed by that arm.

Also here, from Vera's review of the same suite: the two fence arms no longer POLL
for the winner's bump to land. `waitForGeneration` was the file's only wall-clock
budget, and its expiry failed a security arm in the direction that reads as the
fence having broken — she saw exactly one such run (1 failed / 29 passed, message
`row never reached refreshGeneration 4`) and neither of us could confirm it in
20+ runs since. The landing is observable at the seam instead: `defaultRowDeps()`
is exported so a test can wrap `bumpGeneration` around the REAL implementation
while the other three row methods stay real, and the mid-flight pre-image is taken
after that signal rather than after a poll. A wholesale `row` override is required
because the deps merge is one level deep, and spreading a wrapper onto
`store.deps.row` finds nothing there — measured, not assumed: it is `TypeError:
Cannot read properties of undefined (reading 'bumpGeneration')`. No wall-clock
wait remains in either arm, so there is no budget left to expire under load.

Evidence: baseline `(2, 31)`, `tsc:check` exit 0. Ledger: 41 mutants, 37 killed,
2 compiler-refused, 2 recorded equivalent, no survivors, no named-arm misses, no
not-applied.
@lilyshen0722
lilyshen0722 added this pull request to the merge queue Sep 29, 2026
Merged via the queue into main with commit 3aee23b Sep 29, 2026
16 checks passed
samxu01 pushed a commit that referenced this pull request Sep 29, 2026
…eam, not on a budget

The arm failed in 4 of 8 isolated runs BEFORE this change, always the same way:
the loser's `WINNER_WAIT_MS` budget elapsed while the winner was still writing
the row, so the loser refused `credential_refreshing` and the arm read as the
fence having broken.

The clock is the reason, and it is the same defect #2004 removed elsewhere. This
suite injects `sleep`, which advances a VIRTUAL clock, while the winner's
progress — its vendor call, its `commit` — is real. A poll loop therefore spends
1500 virtual milliseconds in microseconds of real time: the budget expires faster
than the work it is waiting for, and which side wins is decided by mongod's
scheduling. A budget that expires faster than the work it waits for is not a
budget.

So the loser's first poll still wakes the winner and then WAITS for the winner's
commit at its seam, which the suite now wraps alongside the bump. The arm turns on
the store's state — a fresh row means the winner wrote — instead of on which task
the event loop ran first, and the deadline keeps its deterministic witness in
`a live lease is not takeable`, where nothing else can move the row.

Witnessed by instrument rather than by a quiet re-run:
- 10/10 isolated runs green, against 4/8 red before
- mutant S1 (the fence takes no lease at all — the defect this arm exists for)
  still turns it RED, along with two sibling arms, so the seam did not hollow it
  out
- mutant S2 (`preImageWasStale &&` dropped from the loser's freshness check)
  SURVIVED: that clause is not a tautology, so this is an UNWITNESSED BRANCH, not
  an equivalence — the corner it covers (no `credentialRef` while `expiresAt` is
  fresh) has no arm, and whether refusing `credential_refreshing` there is right
  is a behaviour question for the board, not something to pin inside a test-only
  diff
lilyshen0722 added a commit to thantiklermcirony/commonly that referenced this pull request Oct 9, 2026
…cument claims (TASK-172) (Team-Commonly#2007)

* fix(broker): compose the caller's signal, and check the issuer the document claims (TASK-172)

Two guards the vendor path was missing, both recorded by the Team-Commonly#2006 review rather
than blocking on it:

- `upstreamFetch` composed nothing: `{ ...init, signal: AbortSignal.timeout(…) }`
  reads as though `init` were honoured and silently drops the one field in it that
  cancels. A caller's signal is now composed with the deadline instead of replaced,
  and the arms cover both directions — a caller who aborts stops the call, and a
  caller whose signal never aborts still hits the deadline. No caller passes one
  today (all three take the default), so this is the difference between a wrapper
  that is bounded and one that is bounded AND cancellable.
- Discovery read endpoints out of the metadata without ever comparing the
  document's `issuer` to the issuer the URL was built from. RFC 8414 §3.3 requires
  them identical, and what the check defends is the next line of the flow:
  `authorization_endpoint` is where the person's browser is sent, so a document
  written for another issuer hands that consent to whoever wrote it. A missing
  `issuer` is `issuer_metadata_incomplete` (§2 makes it REQUIRED); a different one
  is the new `issuer_mismatch`, which the start route maps to a 502 with the other
  vendor-side states.

Evidence: baseline (3, 50); tsc:check clean; eslint clean on the three sources;
ledger 10 mutants — 9 killed, 1 recorded equivalent, no survivors, no named-arm
misses, no not-applied. The equivalent is measured rather than argued: applying it
leaves the suite 50/50, because the arm asserts WHICH failure arrives and an
ignored timeout parameter still produces it, fifteen seconds later rather than in
twenty milliseconds.

* test(hosted-mcp): give every metadata fixture the issuer §3.3 requires

The credential suite's METADATA was the only one that failed, because it is the
only one whose discovery is real rather than mocked: with no `issuer`, the new
check refuses the document and the refresh arm dies on
`authorization server metadata names no issuer` — a red that says nothing about
the deadline it is testing. The two mocked stubs (connect's AS_METADATA,
callback's discovery return) are corrected in the same pass: they stand in for a
conformant vendor today and would have been a live trap the moment either was
wired to real discovery.

* test(broker): the mid-flight fence arm waits at the winner's commit seam, not on a budget

The arm failed in 4 of 8 isolated runs BEFORE this change, always the same way:
the loser's `WINNER_WAIT_MS` budget elapsed while the winner was still writing
the row, so the loser refused `credential_refreshing` and the arm read as the
fence having broken.

The clock is the reason, and it is the same defect Team-Commonly#2004 removed elsewhere. This
suite injects `sleep`, which advances a VIRTUAL clock, while the winner's
progress — its vendor call, its `commit` — is real. A poll loop therefore spends
1500 virtual milliseconds in microseconds of real time: the budget expires faster
than the work it is waiting for, and which side wins is decided by mongod's
scheduling. A budget that expires faster than the work it waits for is not a
budget.

So the loser's first poll still wakes the winner and then WAITS for the winner's
commit at its seam, which the suite now wraps alongside the bump. The arm turns on
the store's state — a fresh row means the winner wrote — instead of on which task
the event loop ran first, and the deadline keeps its deterministic witness in
`a live lease is not takeable`, where nothing else can move the row.

Witnessed by instrument rather than by a quiet re-run:
- 10/10 isolated runs green, against 4/8 red before
- mutant S1 (the fence takes no lease at all — the defect this arm exists for)
  still turns it RED, along with two sibling arms, so the seam did not hollow it
  out
- mutant S2 (`preImageWasStale &&` dropped from the loser's freshness check)
  SURVIVED: that clause is not a tautology, so this is an UNWITNESSED BRANCH, not
  an equivalence — the corner it covers (no `credentialRef` while `expiresAt` is
  fresh) has no arm, and whether refusing `credential_refreshing` there is right
  is a behaviour question for the board, not something to pin inside a test-only
  diff

* test(broker): the incomplete-document arm names the issuer, so the endpoint guard is witnessed again

Vera's catch, and it is the good kind: my §3.3 check landed ABOVE the endpoint
guard, and this arm sent a document with no issuer. It went on refusing, with the
SAME error code as a missing endpoint, so deleting the endpoint guard outright
changed no test in the neighbourhood (she measured 102/102 green; I reproduce it).
The refusal was never in doubt — its ATTRIBUTION was. Two defects, one code, and
the arm was pinning whichever ran first.

So the document carries an issuer on purpose, and the arm pins its MESSAGE as well
as its code — the message is the only thing that tells the two apart, which is why
the no-issuer arm pins its own message too.

Witnessed by mutant: delete `if (!body.authorization_endpoint || !body.token_endpoint)`
and this arm is the one that goes red, by name, alone. 13 suites / 155 tests green
otherwise.
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