Process & Discipline

Incident Postmortems for Deriv Bot Failures: A Blameless Template

· 6 min read

A blameless postmortem turns an unexpected drawdown, a WebSocket disconnect, or a misfired order into a written record that a reviewer can replay line by line. The goal is not to assign fault but to reconstruct the timeline, separate the trigger from the root cause, and convert each finding into a concrete code or configuration change with a test behind it. This article provides a template and a worked example that traces counter states loss by loss, so the stated halt rule and the recorded outcome cannot drift apart.

Trading involves significant risk and you can lose your entire stake. Test every strategy on a demo account first.

The template: five fields that force precision

A postmortem is only useful if it is falsifiable. Each field below should contain facts that another engineer could check against logs, statements, or the bot’s own state output.

  1. Incident summary. One paragraph: instrument, contract type, stake, session start and end, and the observable failure (for example, “session continued past the configured consecutive-loss halt”).
  2. Timeline with counter states. Every relevant event with a timestamp, and for any risk counter, the value before and after the event. “The bot lost twice” is not a timeline entry; “consecutive_losses: 0 → 1 at 10:14:02, 1 → 2 at 10:14:41” is.
  3. Trigger versus root cause. The trigger is the event that exposed the problem (a reconnect, a rejected order). The root cause is the defect that let the trigger produce a bad outcome (a counter reset on reconnect, a limit evaluated against stale data).
  4. Arithmetic reconciliation. Any claim about a limit being reached must show the evaluation points and the values seen at each one. If a limit was crossed but not enforced, state the exact order at which the crossing occurred and why the check did not fire.
  5. Corrective actions with owners and tests. Each action maps to a change in code or config, plus a pre-live check that would catch a regression.

Keep the language neutral. “The counter was reset by the reconnect handler” is a finding; “the developer was careless” is not.

Worked example: a consecutive-loss halt that never fired

Consider a fixed-stake Rise/Fall bot on a synthetic index. The rule set is written before the session:

  • Stake: 1 unit per contract (fixed stake; the stake is the maximum loss per contract).
  • Hard halt: stop the session when `consecutive_losses` reaches 3.
  • Daily loss limit: 50 units, checked at order time against realised profit and loss.

The operator starts the session, and after a network interruption the bot reconnects. The reconnect handler reinitialises the session object, which resets `consecutive_losses` to 0. The handler does not preserve the pre-disconnect count. The following sequence is traced loss by loss:

Loss Counter before Event Counter after Halt check

| 1 | 0 | loss settled | 1 | 1 < 3, continue |
| 2 | 1 | loss settled | 2 | 2 < 3, continue |
| — | 2 | WebSocket disconnect, reconnect handler runs | 0 | counter reset |
| 3 | 0 | loss settled | 1 | 1 < 3, continue |
| 4 | 1 | loss settled | 2 | 2 < 3, continue |
| 5 | 2 | loss settled | 3 | 3 = 3, halt fires |

Two facts follow from this trace. First, the counter reset to zero at the reconnect, so the correct consecutive count (which would have reached 3 at the third loss) was never held by the bot. Second, the halt did eventually fire, but only after the fifth loss, because the reset discarded two losses from the count. The session recorded five losing contracts of 1 unit each, a total of 5 units, before the halt stopped it. Note that the earlier draft of this example claimed the bot "records two consecutive losses rather than the correct count" and then continued to five losses; that phrasing was internally inconsistent, because a counter that is merely off by two would still reach three at the third loss and halt there. The trace above removes the ambiguity: the reset, not an off-by-two error, is the defect.

Now reconcile the daily loss limit. Realised profit and loss at each order-time check:

– After loss 1: −1 unit. Check at next order: |−1| < 50, proceed.
– After loss 2: −2 units. Check: 2 < 50, proceed.
– After the reset and loss 3: −3 units. Check: 3 < 50, proceed.
– After loss 4: −4 units. Check: 4 < 50, proceed.
– After loss 5: −5 units. Check: 5 < 50, proceed.

The 50-unit daily limit was never crossed in this session; the session ended at −5 units because the consecutive-loss halt fired at the fifth loss. The earlier claim that the daily limit was "reached exactly" was arithmetically false and has been removed. Had the session continued, the daily limit would have been crossed at the order following the loss that took realised P&L to −50 units or below, and the order-time check would have blocked that next order — but only if the check read settled P&L rather than a lagging snapshot. If the check reads a value that lags settlement, state the lag explicitly and identify the order at which the stale value would still have passed the check; in this trace no such order exists because the session halted first.

The root cause is the reconnect handler's reinitialisation of session state. The trigger was the disconnect. The corrective action is to persist `consecutive_losses` and `realised_pnl` outside the session object, restore them on reconnect, and add a pre-live check that simulates a disconnect mid-sequence and asserts the counter is unchanged.

A minimal rule set for the fix, as DBot-style block steps:

1. On session start, load `consecutive_losses` and `realised_pnl` from persistent storage.
2. On each contract settlement, update both values and write them to storage before evaluating halts.
3. On reconnect, reload both values; do not reset them.
4. Evaluate the consecutive-loss halt and the daily loss limit at settlement, not only at order time.
5. If either limit is breached, stop the bot and log the counter values that triggered the stop.

### Limitations

This template does not recover losses, prove a strategy, or substitute for a backtest with out-of-sample data. It cannot reconstruct events the bot did not log; if the bot does not record counter values at settlement, the timeline will have gaps. It also does not resolve platform-side ambiguities: whether a settlement is final at the moment the bot reads it depends on platform settings and should be stated as an assumption, not a fact. Finally, a clean postmortem says nothing about future performance — past results do not predict future results.

### Frequently Asked Questions

**Does a blameless postmortem mean no one is accountable?**
No — it means the review separates people from mechanisms, so each finding produces an owned code or config change with a test, rather than a judgment about intent.

**Should the halt check run at order time or at settlement?**
Both: settlement-time checks catch breaches as they happen, and order-time checks act as a second barrier, but only if they read settled values rather than a lagging snapshot.

**Can this template be used for demo sessions?**
Yes, and it should be — running the review on demo sessions is how you find counter-reset and stale-read defects before real money is involved.

### Key Takeaways

– A postmortem entry must record each counter value before and after every event; "lost twice" is not a timeline.
– Separate the trigger (disconnect, rejected order) from the root cause (state reset, stale read).
– Reconcile every limit claim with arithmetic: show the evaluation points and the values seen at each.
– Convert each finding into a persistent-state fix and a pre-live check that simulates the trigger.
– Run the review on demo sessions first; real money only after a recorded demo sample and with minimum stake.

The template and the worked example above are the same review applied at different scales: one session, traced loss by loss, with every counter state written down. Open-source bots that implement persistent risk counters and halt logic are available in the ORSTAC repository; they run on Deriv, where a free demo account is available to test them. Questions and template variants are welcome in the ORSTAC Telegram group.

Trading involves significant risk and you can lose your entire stake. Test every strategy on a demo account first.