fix(pool): enforce unique per-account device_mid to stop UNUSUAL_ACTIVITY 405 flags
Problem
Large generated pools get flagged by Z.ai's edge WAF with UNUSUAL_ACTIVITY / HTTP 405 on /zcode-plan/anthropic/v1/messages, even though the gateway itself is healthy.
Root cause: device fingerprint collapse. Older generator batches wrote the same hardcoded \device_mid\ into every account snapshot. In a 149-account pool, 126 files shared a single \device_mid\ (\234aefe2-...) and all requests left from one egress IP via round-robin. That shared fingerprint + single-IP fan-out is the exact cross-account correlation signal risk control keys on.
The gateway loads \device_mid\ verbatim from each snapshot (\ccounts_dir.py) and falls back to the global fingerprint when it is empty, so nothing enforced uniqueness across the pool.
Fix
- Add _ensure_unique_device_mids()\ in \pool.py, applied at \load_accounts()\ for every source (accounts_dir / pool_file / providers_json).
- Any missing or duplicated \device_mid\ is replaced with a stable per-account \uuid5(NAMESPACE_URL, 'zcode-device:' <access_token>)\ — the same derivation as \generator/plan_check.per_account_device_mid, so gateway and generator agree on one stable id per account. Unique mids are left untouched.
- Align the generated-config default \alance_poll_seconds\ (60 in \paths.py\ / \config.example.yaml) with the code default of 300, so a fresh config doesn't sweep all accounts every minute (another burst signal).
Why this is safe
- Non-destructive by default: only empty/duplicate mids are rewritten, in memory at load.
- Deterministic: re-imports produce the same id per account (no churn).
- Covered by \ ests/test_device_mid_uniqueness.py\ (shared -> all unique, missing -> filled, unique preserved, derivation matches the generator).
- Verified: 12 concurrent gateway requests succeeded (200) after applying the unique mids; the pool no longer collapses onto one fingerprint.
Test plan
- \pytest tests/test_device_mid_uniqueness.py tests/test_jwt_import.py tests/test_accounts_dir.py tests/test_zcode_device.py tests/test_credential_quota_fixes.py\ -> 75 passed.
Summary by cubic
Fixes large pools being flagged UNUSUAL_ACTIVITY (HTTP 405) by Z.ai's WAF because older generator batches wrote the same hardcoded device_mid into every account snapshot. Missing or duplicated device_mid values are now rewritten at load to a deterministic per-account uuid5 derived from the access token, using the same derivation as the generator; unique mids are preserved.
Also aligns the generated-config default balance_poll_seconds (60 → 300) with the code default so a fresh config doesn't sweep the entire pool every minute.