Skip to content

emrg: fix flaky session ID uniqueness test — 16-bit → 32-bit entropy - #539

Merged
argszero merged 1 commit into
masterfrom
fix/session-id-entropy
Aug 7, 2026
Merged

emrg: fix flaky session ID uniqueness test — 16-bit → 32-bit entropy#539
argszero merged 1 commit into
masterfrom
fix/session-id-entropy

Conversation

@argszero

@argszero argszero commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes a flaky CI failure on master push run 31145421676:

tests/test_session.py::TestGenerateSessionId::test_generates_unique_ids FAILED
E       AssertionError: assert 9 == 10

Root cause

generate_session_id() used secrets.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 remains s_YYMMDD_HHMM_xxxxxxxx; existing format assertions (len >= 14, parts >= 4, YYMMDD/HHMM lengths) all still pass.

Verification

  • 5 consecutive runs of TestGenerateSessionId — all pass
  • Full suite: 502 passed + import OK + CLI OK

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 argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 argszero left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@argszero
argszero merged commit 605468d into master Aug 7, 2026
1 check passed
@argszero
argszero deleted the fix/session-id-entropy branch August 7, 2026 04:03
argszero added a commit that referenced this pull request Aug 7, 2026
…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>
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