fix(review): 28 verified bugs across gateway, pool, generator and GUI
MA
2d ago+1768+1768+0123456789012345678901234567890123456789-149-149-012345678901234567890123456789
fix(review): 28 verified bugs across gateway, pool, generator and GUI
A full-codebase review found 28 bugs that the test suite did not
catch. This PR fixes all of them, each with a regression test that
failed before the change and passes after.
High
- One U+2028/U+2029/U+0085 character in a model reply killed the whole
request: SSE frames were split with str.splitlines(), which also
breaks on those separators that ensure_ascii=False JSON carries raw
(upstream.py, translate_anthropic.py). - Missing ddddocr defeated the entire auto captcha strategy: the lazy
OCR factory raised RuntimeError instead of returning None, so all 15
attempts failed with a misleading log (captcha_solver.py).
Pool / accounts
- cool()/kill_after_strikes() downgraded quota-drained (EXHAUSTED)
accounts to COOLING, putting them back in rotation after the
cooldown (pool.py). - upsert/enable/apply_credentials(reset=True) never reset
quota_strikes, so an account that recovered from quota exhaustion
re-retired on its first rejection with 3 banked strikes (pool.py,
tokens.py); upsert also force-flipped live state to READY against
its own docstring - re-add/login/import flows now revive explicitly
via enable() (api_admin.py, api_dash.py). - The edge-block notification callback fired per blocked response
instead of once per block episode (breaker.py).
API / service
- /health returned 500 (hmac TypeError) on a non-ASCII update header;
after any in-app update the nonce persists for the process lifetime,
so internet scanners kept hitting it (api_health.py). - generator/locate left the old manager's ClaimScheduler, captcha-mint
thread and proxy checker running; a second scheduler then fired
duplicate daily claims (api_dash.py). - Worker/claim stop and proxy-checker endpoints ran subprocess kills
(up to 5s) and multi-MB pool.json parsing directly on the event
loop, freezing all traffic including live SSE streams
(api_admin.py, api_dash.py); _check_update_idle also iterated
manager dicts without the lock (500 on a rare race). - The request body was deep-copied on the event loop for every
recorded request even when JSONL capture was disabled
(service.py). - proxy auto-verify 500'd on a non-numeric interval_min instead of
400 (api_admin.py); a non-ASCII comment in proxies.txt aborted the
whole Auto Generate preflight (generator.py).
Relays
- The relay retry re-sent through the relay that had just failed,
hammering the same dead relay for every attempt while never trying
the others (upstream.py). - An unreadable relays.json was cached as authoritative defaults, so
the next save permanently wiped the user's relays
(relay_manager.py); update_options(models="GLM-5.3") exploded the
string into single characters and silently routed nothing.
Generator
- Telemetry and exported snapshots carried one shared hardcoded
x-device-mid and a hardcoded Asia/Tehran timezone while headers
claimed the exit IP's zone - the cross-account correlation signals
risk control clusters on (invite_claim.py, export_starter.py,
plan_check.py, claim500.py). - One flaky account aborted the whole recheck/export batch
(recheck_plans.py, export_starter.py); a portless ZAI_PROXY became
socks5://host:None and crashed the Playwright launch
(invite_claim.py); leading-zero octets (0177.0.0.1 = 127.0.0.1
octal) bypassed the loopback SSRF guard (proxy_parse.py).
GUI / desktop
- Clicking Stop during a pending Save & Restart was silently
overridden and the gateway restarted itself; Stop during the startup
import window was a no-op and the server bound anyway; wait_ready()
could health-check a foreign process on the default port (gui.py). - config.yaml - which holds the per-install admin/client keys - was
written non-atomically from four GUI paths; a crash mid-write
truncated it (gui.py). - The live smoke script closed the store under a pending usage-record
write (scripts/smoke/live.py).
Verification
- 1364 passed / 147 skipped / 0 failed (full suite, clean venv)
- ruff E9,F63,F7,F82,F811,F841: clean
- captcha-mint sidecar (bun): 30/30
- Known pre-existing flake test_overload_rotates_accounts_after_wait_
without_cooling reproduces on the unmodified tree and passes here;
unrelated to these changes.
Every fix has a regression test that was observed failing before and
passing after; 5 new test files + extensions to test_relays.py.
Summary by cubic
A full-codebase review found 28 bugs that the test suite did not catch. This PR fixes all of them, each with a regression test that failed before the change and passes after.
High-impact fixes
- SSE frames now split on real line terminators, so a stray U+2028/U+2029/U+0085 in a reply no longer fails the request.
- Missing ddddocr degrades captcha solving instead of aborting the whole auto captcha strategy.
- Quota-drained (EXHAUSTED) accounts stay retired; fresh credentials get a clean strike budget.
- Relay retries no longer hammer a just-failed relay, and an unreadable
relays.jsoncan no longer be overwritten by defaults. - Subprocess kills, pool parsing, and request-body deep copies moved off the event loop, so live SSE traffic is no longer frozen.
- All GUI
config.yamlwrites are atomic; a user Stop now wins over a pending restart. - Generator telemetry uses per-account device IDs and the exit IP's timezone instead of shared hardcoded values.
Verification
- 1364 passed / 147 skipped / 0 failed; ruff and the captcha-mint sidecar are clean.