Fix run_id collision in CI: increase suffix from 4 to 8 hex chars

The 4 hex char suffix (65536 possibilities) caused a collision when
generating 100 IDs within the same second on fast CI runners.
Increased to 8 hex chars (4 billion possibilities).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Alpamys 2026-02-23 23:48:12 +05:00
parent 2aaa87fb4e
commit 2dba07a7b3
2 changed files with 5 additions and 5 deletions

View File

@ -80,9 +80,9 @@ def _get_db_path() -> Path:
def generate_run_id() -> str:
"""Generate a unique, sortable run ID: run_YYYYMMDD_HHMMSS_xxxx."""
"""Generate a unique, sortable run ID: run_YYYYMMDD_HHMMSS_xxxxxxxx."""
ts = datetime.now().strftime("%Y%m%d_%H%M%S")
suffix = secrets.token_hex(2)
suffix = secrets.token_hex(4)
return f"run_{ts}_{suffix}"

View File

@ -18,9 +18,9 @@ def test_generate_run_id():
"""Run IDs should be unique and match expected format."""
rid = generate_run_id()
assert rid.startswith("run_")
# run_ (4) + YYYYMMDD (8) + _ (1) + HHMMSS (6) + _ (1) + xxxx (4) = 24
assert len(rid) == 24
# Uniqueness
# run_ (4) + YYYYMMDD (8) + _ (1) + HHMMSS (6) + _ (1) + xxxxxxxx (8) = 28
assert len(rid) == 28
# Uniqueness (8 hex chars = 4 billion possibilities, no collisions in 100)
ids = {generate_run_id() for _ in range(100)}
assert len(ids) == 100