Skip to content

Add deadman alert, live-mode webhook enforcement, and panic hook (fixes #220)#232

Merged
wjllance merged 1 commit into
mainfrom
fix-220-deadman-panic-hook
Jul 13, 2026
Merged

Add deadman alert, live-mode webhook enforcement, and panic hook (fixes #220)#232
wjllance merged 1 commit into
mainfrom
fix-220-deadman-panic-hook

Conversation

@wjllance

Copy link
Copy Markdown
Owner

Summary

Issue #220 (P0 monitoring): when the maker process dies silently (SIGKILL / OOM / panic / host down) nothing notifies anyone — cleanup only runs after the loop breaks normally, OpenObserve has zero alert rules, and the in-process webhook is off by default. This closes the three reachable gaps.

  1. Deadman alertscripts/openobserve_alerts.py provisions an OpenObserve scheduled alert (template + destination + alert, all upserted) that fires when the standx_maker stream has had no action='cycle_summary' event for ~3 minutes (OPENOBSERVE_ALERT_MINUTES, default 3). It POSTs to OPENOBSERVE_ALERT_WEBHOOK. Structure/auth/env vars mirror the existing scripts/openobserve_dashboard.py. This push channel is decoupled from the maker process, so it still fires when the process itself can no longer notify. Documented in docs/15-openobserve.md (new section 6).

  2. Live forced webhookrun_maker now refuses to start under --live when --alert-webhook is unset (hard error), or when every alert threshold (--alert-loss, --alert-inventory-pct, --alert-position-change-pct, --alert-uptime) is 0 so the webhook could never fire. Added next to the existing live-gate validation. The STANDX_ENABLE_LIVE_MAKER lock is unchanged.

  3. Panic hookmain chains a panic hook (keeping the default hook that prints the panic/backtrace) that POSTs one last critical notification, reusing the maker webhook payload shape via commands::panic_webhook_body. It only arms when a maker run configured a webhook, and runs the blocking POST on a dedicated thread with its own current-thread runtime so it is safe to fire while the main tokio runtime is mid-unwind. Best-effort and bounded (5s timeout); never re-panics.

Test plan

  • cargo fmt -- --check — clean
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo test -p standx-cli — 31 passed
  • python3 -m py_compile scripts/openobserve_alerts.py — OK
  • Manual: --live without --alert-webhook now errors before any order path; panic hook only arms for maker runs with a webhook configured.

Follow-up

Not implemented here (per issue item 4): moving OpenObserve off the trading host. Today OpenObserve runs on the same box as the maker, so a host-level failure (OOM/hardware/network) can take down both the maker and the very monitor meant to detect its death. The deadman alert still helps for process-level deaths (SIGKILL/panic/OOM of the maker alone), but a truly independent monitor should run off-host. Tracking as a separate infra change.

Fixes #220

🤖 Generated with Claude Code

Silent process death (SIGKILL/OOM/panic/host down) currently notifies
nobody: cleanup only runs after the loop breaks normally, OpenObserve has
no alert rules, and the in-process webhook is off by default. Close the
three reachable gaps from issue #220.

1. Deadman alert: scripts/openobserve_alerts.py provisions an OpenObserve
   scheduled alert (template + destination + alert, upserted) that fires
   when the standx_maker stream has no action='cycle_summary' event for
   ~3 minutes. Mirrors the existing dashboard script's Basic-auth + env
   var + upsert structure. Documented in docs/15-openobserve.md.

2. Live forced webhook: run_maker now refuses to start under --live when
   --alert-webhook is unset, or when every alert threshold is 0 (the
   webhook could never fire). Added alongside the existing live-gate
   checks; STANDX_ENABLE_LIVE_MAKER lock unchanged.

3. Panic hook: main chains a panic hook that POSTs one last critical
   notification, reusing the maker webhook payload shape. It runs the
   blocking POST on a dedicated thread with its own runtime so it is safe
   to fire mid-unwind, and only when a maker run configured a webhook.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@wjllance wjllance merged commit eb56d38 into main Jul 13, 2026
7 checks passed
@wjllance wjllance deleted the fix-220-deadman-panic-hook branch July 13, 2026 07:59
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.

[P0][Monitoring] deadman 告警 + live 强制 webhook + panic hook——进程静默死亡时无人被通知

2 participants