Skip to content

test(brc105): fix ~1/256 flaky nonce-tamper test (red 3.12 shard)#2

Merged
kryp2 merged 1 commit into
masterfrom
agent/fix-flaky-nonce-tamper-test
Jun 1, 2026
Merged

test(brc105): fix ~1/256 flaky nonce-tamper test (red 3.12 shard)#2
kryp2 merged 1 commit into
masterfrom
agent/fix-flaky-nonce-tamper-test

Conversation

@kryp2

@kryp2 kryp2 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

What

Makes test_tampered_nonce_rejected deterministic. It built the tampered nonce as "ff" + nonce[2:], which is a no-op when the random first byte is already 0xff (~1/256). In that case the unmodified, still-valid nonce verifies and the test fails.

Why this matters

This is the actual cause of the red 3.12 shard on master (135/136 passed, only TestNonceManager::test_tampered_nonce_rejected failed) — not the brc105 lazy-import change in #1, whose middleware tests all pass. The HMAC verification in nonce.py is correct; only the test's tampering was non-deterministic.

Fix

Flip the first byte with ^ 0xff so it always changes regardless of value.

Verification

  • Old tamper logic: 7 false-passes / 2560 runs (~1/256, as predicted)
  • New logic: 0 failures / 600 runs
  • Full suite: 136 passed

🤖 Generated with Claude Code

test_tampered_nonce_rejected built the tampered nonce as "ff" + nonce[2:],
which is a no-op when the random first byte was already 0xff (~1/256), so
the unmodified nonce verified and the test failed. This is what failed the
3.12 shard on master (135/136), not the brc105 lazy-import change.

Flip the first byte via XOR 0xff so it always differs. Verified: old logic
= 7 false-passes / 2560 runs; new logic = 0 / 600; full suite 136 passed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kryp2 kryp2 merged commit 5a1a136 into master Jun 1, 2026
4 checks passed
@kryp2 kryp2 deleted the agent/fix-flaky-nonce-tamper-test branch June 1, 2026 08:05
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.

2 participants