fix(agent): symmetric live-side equity-mode clear (pre-live-arming) - #137
Merged
Conversation
Hoist the paper->live scalar clear above the broker-equity read and gate it on the prior mode being "paper", mirroring _seed_paper_account_if_needed. Previously the clear lived inside the equity-readable branch, so a paper->live flip whose first live cycle read an unreadable broker let stale paper drawdown scalars survive an extra cycle before self-healing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Makes the live-side equity-state mode clear in
run_oncesymmetric with the paper-side clear (_seed_paper_account_if_needed). This is the pre-live-arming fix flagged by aTODO(pre-live-arming)inkeel/agent.py— harmless today (live is never armed) but must land before any live execution.The bug
The old live-side clear lived inside the equity-readable branch and was gated on
!= "live". On a paper→live flip whose first live cycle reads an unreadable broker,equity_nowisNone, the whole branch is skipped, and stale paper drawdown scalars survive one extra cycle before self-healing — arming Rail 11 on a phantom drawdown for a cycle.The fix
_clear_live_mode_if_needed(repo)mirrors the paper-side clear: gated on the prior mode being"paper", hoisted to the top of the live branch, before the broker-equity read, so it fires unconditionally on the flip regardless of broker readability.Tests
test_paper_to_live_flip_clears_stale_scalars_even_when_broker_unreadable— confirmed failing before the fix, passing after.🤖 Generated with Claude Code