Bot Stopped Trading: The Silent Failure
A trading bot can stop trading without errors due to a clean exit code, bypassing failure detection and restarts.
Key takeaways
- A restart-on-failure policy does not restart a process that exited cleanly, and a shutdown signal produces a clean exit.
- You cannot detect a dead process by searching its logs, because a dead process writes no logs.
- Check machine or container state before reading log content; absence of errors often means absence of a process.
- Health checks that hit a different service than the one doing the work will report green through a total outage of the worker.
- Alert on the absence of an expected heartbeat rather than on the presence of errors, and pair it with a watchdog that can start a stopped machine.
The Bot Was Dead for Five Days and the Dashboard Looked Fine
Your trading bot stopped trading because it exited cleanly with a status code of 0. This is not interpreted as a failure by most host environments, so no alerts were triggered, no restarts were initiated, and the process simply remained stopped. Absence of errors is not evidence of health.
What went wrong
In one incident, our trading bot process exited cleanly at 08:05 UTC and remained in a stopped state for five days. During this period, users interacting with a Discord button that relied on this bot experienced failed interactions because the underlying process was gone. The outage was completely invisible in our log platform; a dead process emits no new logs, so searches for errors within that window returned nothing. The web machine continued to serve HTTP requests, meaning all external health checks and the website itself reported as healthy. A noisy, unrelated database error storm that occurred hours before the exit was a red herring; it was a separate, already-handled bug and not the cause of the bot's stoppage.
Why it happens
Automated trading systems often rely on host environments or orchestration layers to manage process uptime. These systems typically monitor processes for failures and initiate restarts or alerts when they detect them. However, the definition of "failure" is critical. Many systems are configured to restart processes only when they exit with a non-zero status code, which conventionally indicates an error. A process that exits cleanly with a status code of 0 is, by definition, not considered to have failed. This is a deliberate design choice in many operating systems and container orchestrators to distinguish between an intentional shutdown and an unexpected crash. In our case, a shutdown signal was sent during a routine host migration. Because this signal resulted in a clean exit (code 0), the host's restart policy, which was set to "restart on failure," did not trigger. This policy had been intentionally configured to avoid an earlier zombie-retry loop, but it had the unintended side effect of leaving the bot in a stopped state indefinitely after this specific type of shutdown.
What we changed
We implemented an hourly watchdog process. This watchdog's detection signature is a machine in a stopped state with no stop requested and an exit code of 0. When this condition is met, the recovery verb is start (not restart), ensuring the bot is brought back online. This watchdog now automatically initiates the process, preventing the silent, indefinite stoppage we experienced.
How to check your own system
To avoid similar silent failures in your automated trading systems, consider the following checks:
- Review Host/Orchestrator Restart Policies: Verify that your process manager or orchestrator (e.g., systemd, Kubernetes, Docker Swarm) is configured to handle clean exits (exit code 0) in a way that aligns with your uptime requirements. Does it restart on any stop, or only on explicit failures?
- Implement External Uptime Monitoring: Beyond internal application logs, use external services to ping critical endpoints or check the health of your trading bot's API. Ensure these checks are granular enough to detect a lack of trading activity, not just network connectivity.
- Establish a "Heartbeat" Mechanism: Have your trading bot periodically send a "heartbeat" signal to an external monitoring service. This signal should indicate not just that the process is running, but that it is actively performing its intended function (e.g., attempting trades, processing data).
- Develop a "Stopped but Not Requested" Alert: Configure your monitoring to alert you if a process is found in a stopped state, but no explicit stop command was issued by an operator or automated system. This is the core of our watchdog's detection.
- Monitor Exit Codes: Ensure your logging and monitoring capture the exit code of your trading bot processes. This data point is crucial for distinguishing between crashes and intentional shutdowns.
Disclaimer
This article describes engineering decisions in a trading system. It is not investment advice. Trading involves substantial risk of loss and is not suitable for all investors. Past performance does not guarantee future results. Always do your own research and consider your financial situation before trading.
Frequently asked questions
Why does my trading bot stop without logging an error?
- Because it was not an error. Orchestrators send a termination signal during host migrations, deploys and evictions, and a well-behaved process handles that signal by shutting down cleanly. The exit is successful from the platform's point of view, so nothing is logged and, under a restart-on-failure policy, nothing is restarted.
How do you monitor a trading bot for silent death?
- Emit a heartbeat on a fixed interval from inside the trading loop and alert when it stops arriving, rather than alerting on error volume. Add an independent watchdog that inspects machine state on a schedule and starts anything found stopped without an operator having asked for the stop.
Does a healthy website mean the trading engine is running?
- No, and assuming so is how a multi-day outage goes unnoticed. In a multi-service deployment the web front end and the worker are separate processes on separate machines. The site can serve every page perfectly while the process that places trades has been gone for days.
Related Topics
Tradewink builds explainable market research for self-directed traders. Build a watchlist, inspect signal reasoning and risk context, and paper-track ideas before you decide. Live broker workflows are invite-only when available.
Put this knowledge to work
Tradewink uses AI to scan hundreds of stocks daily and delivers trade ideas with full signal breakdowns — free to start.
Save a signal preview for later
Get a concise AI signal example in your inbox, then build a watchlist when you are ready. No spam, unsubscribe anytime.
Start with free AI trade ideas
See how Tradewink turns market structure, momentum, and risk rules into trade-ready signals. Free to start, with your broker staying in control.
More in Engineering Learnings
Measuring Missed Exit Profits
Quantify exit strategy performance by tracking Maximum Favorable Excursion (MFE) and Maximum Adverse Excursion (MAE) against realized profit and stop.
Read articleDetecting Market Regime Changes
We detect market regime changes using a dual-clock system: a daily Hidden Markov Model for broad market classification and an intraday efficiency ratio…
Read articleSecurely Storing User Broker API Keys
A data-driven approach to securing user broker API keys, detailing a production incident and the implemented safeguards.
Read article