Skip to content

fast-exit: scope candle loop by position-persisted preset (preset-switch immunity)#2064

Merged
bayuewalker merged 2 commits into
mainfrom
WARP/root-fast-exit-position-preset-scope
Jun 21, 2026
Merged

fast-exit: scope candle loop by position-persisted preset (preset-switch immunity)#2064
bayuewalker merged 2 commits into
mainfrom
WARP/root-fast-exit-position-preset-scope

Conversation

@bayuewalker

Copy link
Copy Markdown
Owner

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_preset mid-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:

  • Scoping: 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 >threshold straight past resolution, recreating the hold-to-resolution loss flip_hunter: auto-exit ~10s before candle close (per-module exit time) #2062 fixed.
  • Threshold: exit_watcher enrich computed force_at from the (now-switched) active_preset first → 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)

File Change
registry.py fast-loop WHERE additively ORs (strategy_metadata->>'candle_rule') / ('factor_router_selected_rule') = ANY($1) alongside s.active_preset = ANY($1) (same $1).
exit_watcher.py enrich prefers the entry-stamped strategy_metadata.force_exit_at_rem_sec (resolved per rule+tf at scan time) over the active_preset lookup; lookup is the fallback only for legacy unstamped rows.

force_exit_at_rem_sec is stamped at late_entry_v3.scan() (late_entry_v3.py:1398) → persisted to positions.strategy_metadata, so it's the position's own fixed rule.

No-regression

  • Query: pure OR — every previously-matched row still matches; can only add orphaned entry-stamped positions.
  • Threshold: no-switch positions get the identical value (flip stamps 10s = lookup's 10s); legacy unstamped rows use the unchanged lookup.

Invariants

No change to Kelly / sizing / risk caps / balance-ledger / ENABLE_LIVE_TRADING. Exit layer only emits an ExitDecision (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-chosen mid_window/high_conviction positions aren't in _CANDLE_PRESETS, so the OR set doesn't rescue them after a switch away from candle_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 by strategy_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

Copilot AI review requested due to automatic review settings June 21, 2026 18:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread projects/polymarket/crusaderbot/domain/execution/exit_watcher.py Outdated
…k to lookup

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115CGk2UGivLN9Ty3PmC9g7
@bayuewalker bayuewalker merged commit b376d12 into main Jun 21, 2026
5 checks passed
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.

3 participants