Silence IBKR precheck notifications and add probe#66
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c9881565d6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| @app.route("/probe", methods=["POST", "GET"]) | ||
| def handle_probe(): | ||
| return _handle_probe() |
There was a problem hiding this comment.
Restrict /probe execution to POST requests
The new route explicitly allows GET, but handle_probe() immediately runs _handle_probe() without a method guard, so any GET hit to /probe will open an IBKR connection, persist a dry-run report, and potentially send failure notifications. This is a production-risk side effect for routine GET traffic (health check tooling, accidental browser hits, or crawlers), and it is inconsistent with /precheck, which returns a safe message on GET instead of executing strategy logic.
Useful? React with 👍 / 👎.
Summary
This PR changes the IBKR detection paths so normal successful checks are logged and persisted without sending Telegram cycle notifications. The error handling path is unchanged, so connection failures, strategy exceptions, and probe failures still publish Telegram alerts.
Issue
The open-after-market
/precheckscheduler is intended as a detection/dry-run check. It should give us machine-readable reports and Cloud Logging detail, but only page the user when something is wrong. Before this change, precheck used the same notification sink as live execution, so normal heartbeat or simulated rebalance output was sent to Telegram.There are also Cloud Scheduler jobs calling
/probeat 10:00 ET. Today those requests return 404 because the service has no probe route, so the post-open broker/account connectivity check is not actually running.Root Cause
run_strategy_core(..., dry_run_only_override=True)built the normal rebalance runtime. That runtime always used the real notification port, soNotificationPublisher.publish(...)logged the detailed message and sent the compact Telegram message even during precheck.The scheduler-side probe was configured before the Flask route existed in the service.
Fix
IBKRRuntimeComposer.build_rebalance_runtime()now acceptssilent_cycle_notifications. The precheck path passes this flag whendry_run_only_overrideis set, replacing the cycle notification sink with a no-op notification port. Existing exception handlers still callpublish_notification(...)directly, so failures are still surfaced./probenow performs a dry-run report-scoped broker connection and account snapshot check. Success records structured runtime events and an execution report without Telegram output; failure records the report and sends a health-probe alert.Validation
PYTHONPATH=/home/ubuntu/Projects/QuantPlatformKit/src:/home/ubuntu/Projects/UsEquityStrategies/src python -m pytest tests/test_runtime_composer.py -qpython -m py_compile main.py application/runtime_composer.py notifications/telegram.py tests/test_runtime_composer.py tests/test_request_handling.pytests/test_request_handling.pycould not be run on this VPS because the local environment is missingpandas; the changed modules compile and the focused composer test passes.