Skip to content

Harden maker notification layer: kind passthrough, webhook prefix/retry, config validation (fixes #221)#233

Merged
wjllance merged 1 commit into
mainfrom
fix-221-notify-hardening
Jul 13, 2026
Merged

Harden maker notification layer: kind passthrough, webhook prefix/retry, config validation (fixes #221)#233
wjllance merged 1 commit into
mainfrom
fix-221-notify-hardening

Conversation

@wjllance

Copy link
Copy Markdown
Owner

Summary

Six small notification-layer hardening fixes for the maker bot, grouped per issue #221:

  • PositionRiskKind passthrough: position_jump() now reads event.kind and emits distinct kinds (direction_flip / max_position_crossed / inventory_exit_crossed / position_jump), escalating DirectionFlip and MaxPositionCrossed to severity critical. Crossing max_position is no longer indistinguishable from an ordinary 20% jump.
  • Webhook text prefix: the phone webhook now gets the same [severity/kind] symbol: prefix the stderr line carries, so alerts identify their source across multiple instances.
  • Reject unknown config keys: MakerFileConfig gains #[serde(deny_unknown_fields)], so a typo like alert_los errors at load instead of silently leaving the guard off.
  • Threshold range validation: alert_loss / alert_inventory_pct / alert_uptime are validated at startup (negatives and percentages >100 rejected) via a pure validate_alert_thresholds helper, mirroring the existing alert_position_change_pct check.
  • Order-response reconnect notifications: the order-response stream now emits risk_notification on disconnect, reconnect success, and reconnect failure, matching the account-stream path (previously entirely silent on the webhook).
  • Webhook retry + await-capable alert: post_webhook retries twice with linear backoff on 5xx/timeout; alert() gained an await-capable path so a firing alert on the final cycle before shutdown is not dropped with its spawned task.

Test plan

  • cargo fmt -- --check (no diff)
  • cargo clippy --workspace --all-targets -- -D warnings (clean)
  • cargo test -p standx-cli and cargo test -p standx-maker (all pass)
  • New unit tests: risk_kind_descriptor mapping/severity escalation, deny_unknown_fields typo rejection, and validate_alert_thresholds range rejection.

Fixes #221

🤖 Generated with Claude Code

Six small notification-layer fixes grouped together:

1. PositionRiskKind passthrough: position_jump() now reads event.kind and
   maps it to a distinct webhook kind (direction_flip / max_position_crossed
   / inventory_exit_crossed / position_jump), escalating DirectionFlip and
   MaxPositionCrossed to severity "critical" so a reversal or breach is no
   longer indistinguishable from an ordinary threshold jump.
2. Webhook text now carries the same [severity/kind] symbol: prefix the
   stderr line uses, so a phone alert identifies its source across instances.
3. MakerFileConfig gets serde(deny_unknown_fields) so a typo like
   `alert_los` errors instead of silently disabling a guard.
4. alert_loss / alert_inventory_pct / alert_uptime are range-validated at
   startup (reject negatives and percentages >100) via a testable
   validate_alert_thresholds helper, mirroring alert_position_change_pct.
5. Order-response stream now emits risk_notifications on disconnect,
   reconnect success, and reconnect failure, matching the account-stream path
   (previously entirely silent on the webhook).
6. Webhook POST retries twice with linear backoff on 5xx/timeout, and alert()
   gained an await-capable path so a firing alert on the final cycle before
   shutdown is not dropped with its spawned task.

Tests: kind-descriptor mapping, deny_unknown_fields typo rejection, and
alert threshold range validation.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@wjllance
wjllance merged commit c304c9c into main Jul 13, 2026
7 checks passed
@wjllance
wjllance deleted the fix-221-notify-hardening branch July 13, 2026 08:01
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.

[P1][Bug] 通知层硬化:PositionRiskKind 压平 / webhook 缺 symbol / 配置未知键静默忽略 等 6 项

2 participants