Skip to content

fix(agent): symmetric live-side equity-mode clear (pre-live-arming) - #137

Merged
eaitbrahim merged 1 commit into
mainfrom
feat/live-mode-clear-symmetry
Jul 24, 2026
Merged

fix(agent): symmetric live-side equity-mode clear (pre-live-arming)#137
eaitbrahim merged 1 commit into
mainfrom
feat/live-mode-clear-symmetry

Conversation

@eaitbrahim

Copy link
Copy Markdown
Contributor

What

Makes the live-side equity-state mode clear in run_once symmetric with the paper-side clear (_seed_paper_account_if_needed). This is the pre-live-arming fix flagged by a TODO(pre-live-arming) in keel/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_now is None, 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

  • New _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.
  • Deleted the old inline clear + stale TODO.

Tests

  • New regression test test_paper_to_live_flip_clears_stale_scalars_even_when_broker_unreadable — confirmed failing before the fix, passing after.
  • Full suite: 1448 passed, ruff clean. All 5 adjacent drawdown/mode tests unchanged and green.

🤖 Generated with Claude Code

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>
@eaitbrahim
eaitbrahim merged commit 11edef4 into main Jul 24, 2026
1 check passed
@eaitbrahim
eaitbrahim deleted the feat/live-mode-clear-symmetry branch July 24, 2026 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant