emrg: fix flaky session ID uniqueness test — 16-bit → 32-bit entropy - #539
Conversation
generate_session_id() used secrets.token_hex(2)[:4] (16 bits, 65536 possibilities). The 10-sample uniqueness test collides ~0.07% per run (birthday paradox) — observed on master push run 31145421676 (PR CI green, master push red: 'assert 9 == 10'). Suffix now uses 4 random bytes (8 hex chars = 32 bits): collision probability drops ~65500x to ~1e-8 per run. Format remains s_YYMMDD_HHMM_xxxxxxxx; all existing format assertions still pass. 502 tests green.
argszero
left a comment
There was a problem hiding this comment.
✅ LGTM — cycle (1/3). Self-review: 16-bit → 32-bit suffix entropy fixes the flaky 10-sample uniqueness test (birthday-paradox collision ~0.07% → ~1e-8 per run); format assertions unaffected; 502 tests pass + 5x repeat of TestGenerateSessionId green.
argszero
left a comment
There was a problem hiding this comment.
✅ LGTM — cycle (1/3). Self-review: 16-bit → 32-bit suffix entropy fixes the flaky 10-sample uniqueness test (birthday-paradox collision ~0.07% → ~1e-8 per run); format assertions unaffected; 502 tests pass + 5x repeat of TestGenerateSessionId green.
argszero
left a comment
There was a problem hiding this comment.
✅ LGTM — cycle (2/3). Re-verified: token_hex(2)[:4] → token_hex(4) (16→32-bit entropy); collision probability ~0.07% → ~1e-8 per run (~65500x); format assertions (s_YYMMDD_HHMM_xxxxxxxx) unaffected; 502 tests pass + 5x TestGenerateSessionId repeat green. CI green (31145767064).
argszero
left a comment
There was a problem hiding this comment.
✅ LGTM — cycle (3/3). Final re-verification: token_hex(4) gives 32-bit entropy (collision ~0.07% → ~1e-8 per run); format s_YYMMDD_HHMM_xxxxxxxx preserved; flake empirically confirmed via rerun of 31145421676 (same commit, one red one green); 502 tests + 5x repeat green. CI green (31145767064). 3 consecutive ✅ from different cycles — mergeable.
…uler work (#540) Version bump 0.2.9 → 0.2.10 across all 6 version sources (pyproject.toml / emrg/__init__.py / gui/package.json / uv.lock / make-installer.sh / build-runtime.sh). test_version_sync all green. Release includes #539 flaky session-ID entropy fix, #533/#534 README restructure (core differentiator front + MANIFESTO anglicized), #535 scheduler projects.yml self-heal, #537/#538 quick-ref updates. Co-authored-by: EMRG Evolution <emrg@argszero.dev>
Summary
Fixes a flaky CI failure on master push run 31145421676:
Root cause
generate_session_id()usedsecrets.token_hex(2)[:4]— only 16 bits of entropy (65536 possibilities) for the per-minute suffix. The test generates 10 IDs in the same minute, so the birthday paradox gives a ~0.07% collision chance per run. It happened on the master push after #538 merged (PR CI was green because it sampled a different random draw).Fix
Suffix now uses
secrets.token_hex(4)(4 bytes = 8 hex chars = 32 bits). Collision probability drops ~65500x to ~1e-8 per run. Format remainss_YYMMDD_HHMM_xxxxxxxx; existing format assertions (len >= 14,parts >= 4, YYMMDD/HHMM lengths) all still pass.Verification
TestGenerateSessionId— all pass