Order Discipline and Memory Safety Sweep
Audit / Issue Found
The lead-dev checklist for a Gunbot strategy pre-flight covers four areas that this sweep audited: every order placement is validated with the exchange-rounded quantity, no audit-log array grows without bound, every cancel call is guarded against a fill-in-flight, and the strategy decides safety exits before take-profit exits. Three real issues were found and fixed; one whole category came back clean.
Before the patch
Nine strategies were pushing entries into the fill log on multiple code paths without a length cap on the array. A long-running bot accumulating fills for weeks would grow the log into the thousands of entries, which silently slows every sidebar render and every history scan.
Four strategies were calling the exchange cancel method on stale orders without wrapping the call in a try-catch. The fact pattern that triggers the bug is normal: the strategy reads the open-orders list, picks a stale entry, and tries to cancel it. Between the read and the call, the exchange may have filled the order. Most exchanges respond to a cancel-on-already-filled by throwing, and without the guard the whole cycle aborted at that point.
One strategy, the Kalman grid, had a notification line that referenced a variable named net that only exists in the stop-loss block. When the strategy placed a normal grid sell, the stop-loss block had already returned, so net was undefined. The notification either threw a ReferenceError or rendered NaN, and either way the operator's notification panel was getting garbage on every grid placement.
After the patch
All nine strategies have a single global fill-log trim added near end-of-cycle, before the chart draw. The trim keeps the log to a maximum of two hundred entries by removing the oldest excess, which covers every push site regardless of which code path it came from. Memory usage is now flat across long uptime.
All four cancel sites now wrap the cancel call in a try-catch that swallows the throw and continues the cycle. The strategy logs a one-line note when the cancel is rejected so the operator can still see what happened, but the rest of the cycle proceeds normally.
The Kalman grid notification now reports the placement event accurately, the resting price and the targeted gain percent, without referencing a variable that does not exist in scope. The realized profit-and-loss is emitted later by the fill detector when the order actually fills.
Two categories were checked and found clean across all thirty-three strategies. Safety-exit precedence, the rule that stop-loss and circuit-breaker checks must run before take-profit math, is correct everywhere. Notification discipline, the rule that the notifications panel should only be updated on event cycles, is correct everywhere apart from the Kalman grid bug.
Bottom line
Long-running bots will not accumulate fill-log entries without bound. A normal fill-in-flight on a cancel attempt no longer kills the cycle. The Kalman grid notification reports the right information. The safety-exit and notification disciplines were already correct across the rest of the library.