Repository navigation
feat(risk-guard): tail-risk guard P1 — SPX speed / account ratio / BLIND alerts (no orders) - #268
Merged
Merged
Conversation
added 18 commits
November 8, 2026 22:38
…(P1 tasks 1,4,5,6)
…onnects, log IB info codes P0 finding (docs/research/2026-11-08-risk-guard-p0.md §1): on 11-03..05 IB sent no SPX ticks in RTH and the relay published the prior close as last with HTTP 200; the stale-data check reconnected every ~2.5 min (166/day) because the tick clock was not reset on connect.
…otifier hardening (review)
Same-expiry spreads arrive from ib_sync as one 'Combo (N legs)' row without max_risk, so leverage under-counted the user's 11-27 spreads. Max loss is now the worst expiry P&L over {0} + strikes; unbounded or unreadable positions are counted, not summed.
…tes, /health block (P1 tasks 9, 10)
…, spec status (P1 task 13)
…en grace, warming sources, error isolation, narrower relay mask
…T-capped incidents XENON_RISK_WATCH_SYMBOLS (/admin) adds single-source cash indexes (IB exchanges verified with reqContractDetails 2026-11-08). Each gets market:<SYM> with its own ack, same speed thresholds, capped at FAST, no BLIND when stale. One new subscription per read; removed symbols cancel their line. SPX/SPY stay fixed; VIX deferred (rise rule open). Design advice: Fable.
…resubscribe, per-day session, basis BLIND, bounded event writes
…and send revision, retry only drops on a later ack, per-key dispatch revision
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
P1 of the tail-risk guard (spec
docs/superpowers/specs/2026-11-08-tail-risk-guard-design.md, plandocs/superpowers/plans/2026-11-08-tail-risk-guard-p1.md). Alerts only: it never places, cancels or modifies an order (test_risk_guard_no_order_path.py). Off by default (XENON_RISK_GUARD=1).src/xenon/api/services/risk_guard/): every 1 s it reads SPX + SPY streaming tickers on the IBdatarole and every 30 s the latest account snapshot.xenon.risk_events(no write underXENON_READ_ONLY).GET /risk/state,POST /risk/incidents/{key}/ack(internal token, top-levelreason_code), a/healthrisk_guardblock, and runtime settingsXENON_RISK_GUARD/XENON_RISK_THRESHOLDS/XENON_RISK_KEY_LEVELS. Migration2026_11_09_risk_events. Shutdown budget is now 58 s < 60 s.RiskGuardBannerwith an ACK button and a details panel. Screenshots:output/playwright/risk-guard-2026-11-08*.png(local).us_equity_session(rth / extended / overnight / closed).last: null, and the stale-restart loop backs off.docs/research/2026-11-08-risk-guard-replay.md, UW SPY bars):docs/runbooks/risk-guard.md,src/xenon/api/CLAUDE.md, CHANGELOG.Review
A different-model (Sonnet) review found 9 items.
Ticker.timeis a receive time; the relay has no holiday table, so the masked indexes show---on holidays.runtime_settingsread on the event loop (a project-wide pattern).Test plan
uv run python scripts/infra/dev/run_pytest_affected.py --base origin/master→ 973 passed (local scratch PG)npm test --prefix scripts/infra/ib_realtime→ 124 passedorder-e2e.test.tsfailures also fail onorigin/masterlocally (FastAPI harness env)..nextcache errors locally.e2e/risk-guard-banner.spec.tspassed, with screenshotsUpdate 2026-11-09
004ea0f9): runtime settingXENON_RISK_WATCH_SYMBOLSover NDX / RUT / DJX (IB exchanges NASDAQ / RUSSELL / CBOE verified withreqContractDetailson the live gateway). Ownmarket:<SYM>incident and ack, same speed thresholds, capped at FAST, no BLIND. SPX + SPY fixed; VIX deferred (rise rule open). Design: Fable advice.RISK_INCIDENT_CHANGED); a send that reached no channel retries every 30 s (max 10) with a per-key revision; IB 1101 re-subscribes; session high/low per trading date; BLINDBASIS_UNAVAILABLE;risk_eventswrites 5 s deadline and max 4 in flight;/risk/stateevents read 5 s deadline. Each fix has a regression test; the ack-race, next-day-session and basis tests were confirmed red on004ea0f9.🤖 Generated with Claude Code