fast-exit: scope candle loop by position-persisted preset (preset-switch immunity)#2064
Conversation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115CGk2UGivLN9Ty3PmC9g7
There was a problem hiding this comment.
Code Review
This pull request implements preset-switch immunity for the candle fast-exit loop. It ensures that both the fast-loop query scoping in registry.py and the force-exit threshold sourcing in exit_watcher.py rely on the position's immutable entry-stamped metadata rather than the user's mutable active preset. This prevents mid-candle preset switches from dropping positions from the fast loop or swapping their exit thresholds. The changes are accompanied by comprehensive unit tests and detailed documentation. There are no review comments, so no additional feedback is provided.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 45c1ebc392
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…k to lookup Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0115CGk2UGivLN9Ty3PmC9g7
WARP•R00T MAJOR — capital-path (fast-exit scoping + threshold)
Follow-up to PR #2062, addressing the Codex P2: a candle position's fixed-time exit must survive the user switching
active_presetmid-candle.Problem
Both the 5s fast-exit loop and the force-exit threshold keyed off the user's mutable
user_settings.active_preset, not the position's entry-time rule. After a mid-candle preset switch:list_open_candle_positions_for_exit(s.active_preset = ANY($1)) dropped the position from the 5s loop → only the 30s watcher saw it → could step from>thresholdstraight past resolution, recreating the hold-to-resolution loss flip_hunter: auto-exit ~10s before candle close (per-module exit time) #2062 fixed.exit_watcherenrich computedforce_atfrom the (now-switched)active_presetfirst → swapped the live position's threshold (flip's 10s → safe_close's 30s).Fix — source from the immutable entry stamp (mirrors
_position_family, Codex P1 #2042)registry.py(strategy_metadata->>'candle_rule')/('factor_router_selected_rule') = ANY($1)alongsides.active_preset = ANY($1)(same$1).exit_watcher.pystrategy_metadata.force_exit_at_rem_sec(resolved per rule+tf at scan time) over theactive_presetlookup; lookup is the fallback only for legacy unstamped rows.force_exit_at_rem_secis stamped atlate_entry_v3.scan()(late_entry_v3.py:1398) → persisted topositions.strategy_metadata, so it's the position's own fixed rule.No-regression
OR— every previously-matched row still matches; can only add orphaned entry-stamped positions.Invariants
No change to Kelly / sizing / risk caps / balance-ledger /
ENABLE_LIVE_TRADING. Exit layer only emits anExitDecision(existing executor boundary closes). Fail-closed on malformed stamps.Tests
tests/test_fast_exit_preset_switch.py(3): query ORs entry-stamped rule (no-regression); flip→safe_close switch holds at rem≈20s on its own 10s rule and exits at rem≈8s; legacy unstamped row still exits via fallback. Full suite 4737 passed; ruff clean.Residual (separate follow-up)
candle_auto-chosenmid_window/high_convictionpositions aren't in_CANDLE_PRESETS, so the OR set doesn't rescue them after a switch away fromcandle_auto. Low severity (mid_window's 30s == watcher cadence; only high_conviction's 8s is at real risk). Closing fully = a "fast-loop coverage" lane (scope bystrategy_type='late_entry_v3'), kept out to stay strictly no-regression.Report:
projects/polymarket/crusaderbot/reports/root/fast-exit-position-preset-scope.md🤖 Generated with Claude Code
Generated by Claude Code