Repository navigation
fix(backtests): size a pipeline risk action as asked and refuse an ambiguous size_pct - #691
Merged
Merged
Conversation
The risk-branch comment in pipeline_output_to_decision said any positive size_pct sells the whole position because the gate does not size a sell. That was written against the pre-#667 gate and reached main through #662's follow-up; since #667 the gate sizes it as a share of the position (0.25 sells a quarter, 1 or more sells all). Comment only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…biguous size_pct - Refuse a size_fraction strictly between 1 and 100 (a fraction and a percentage disagree there) and state size_pct's unit in the last step's execution rules when the step asks for risk_actions (#690). - Carry a risk action's qty/quantity/position_size to the gate (#700). - Execute orders and risk_actions together; an actions list still overrides both, and the dropped lists are logged and recorded on the tape (#701). - Let an unreadable size_pct reach the gate's refusal instead of holding (#702). - Record fraction x held on a refused fraction sell, not 0 (#703). - TAPE_VERSION 2 -> 3; LLM_SELL_SIZING unchanged (no pipeline feeds its readers). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FlyM1ss
marked this pull request as ready for review
October 30, 2026 18:36
…isk sells from one rule Addresses the /code-review of #691: - An order on a symbol drops every risk action on it (named on the tape as ignored_risk_symbols and logged): no double sell of one holding, no stop beside a buy market-selling the old position, and a reply naming each symbol once stays within the gate's action cap. - read_pipeline_output reads a reply once and returns the decision with what it ignored; the gate, the log line and the tape share it (replaces shadowed_envelopes). - _model_qty takes the first share-count key the model filled in, so {"qty": null, "quantity": 10} sells 10, not the whole position. - A risk action's position_size is a share count only beside no size_pct. - The size_pct unit rule reaches a last step when any decision step or an upstream output names the risk envelope. - sell_request returns the ledger count with the size, so _refuse_sell no longer redoes the fraction arithmetic; the count is never negative. - size_fraction 1 is documented as read as the fraction, not 1%. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch was successfully deployed
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.
This PR started as a comment fix. A
/code-reviewof it found five more ways the code under that comment was wrong, and the PR now fixes them all.What changes (
pipeline_output_to_decision,requested_sell_shares, the gate's refusal record)size_fractionbetween 1 and 100 is refused withinvalid_quantityinstead of selling the whole position (fix(backtests): a risk action's size_pct has no defined unit, so 25 meaning 25% sells everything #690, option 2). 1, and 100 or more, still sell everything. At 100 and above a fraction and a percentage agree. At 1 they don't (as a percentage it's a 1% trim), but 1 is read as the fraction: that's the unit the prompt now states, and1.0is how a fraction-writing model says "all of it". 100 stays a full exit, unlike the "≤ 100" in fix(backtests): a risk action's size_pct has no defined unit, so 25 meaning 25% sells everything #690.size_pctline, but only when some decision step's prompt or output format, or an upstream output the last step reads, namesrisk_actionsorsize_pct. Every other pipeline prompt is byte-identical.qty,quantityorposition_sizethe model filled in (a null no longer hides the next key, in orders too) now reaches the gate asposition_size. In a risk action,position_sizecounts only when there is nosize_pctbeside it, since in that envelope it is often a fraction. For a sell the gate uses it beforesize_pct; a buy is no longer sized from confidence.ordersandrisk_actionsin one reply both execute (fix(backtests): a pipeline reply's orders silently drop its risk_actions #701), orders first. An order wins its symbol: a risk action on a name an order already trades is dropped. Without this, an order sell plus a stop-loss sold one holding twice (both sized against the pre-bar holding), a stop beside a buy market-sold the old position, and on a one-symbol universe the pair broke the action cap and failed a strict bar. A non-emptyactionslist still overrides both. Everything dropped is logged and named on the decision tape (intent.ignored_envelopes,intent.ignored_risk_symbols).read_pipeline_outputreads a reply once, so the gate, the log and the tape see the same thing.size_pctreaches the gate (fix(backtests): an unreadable risk-action size_pct holds before the gate, so no rejection is recorded #702), which refuses it and recordsinvalid_quantity, as SECURITY.md says it should.size_pct: 0with no share count still holds.fraction × held(50 for a sub-lot 0.1 of 500), not 0. The count comes fromsell_request(the same rule that sizes the sell) and is never negative.decision_tape._order_triples.Versioning
TAPE_VERSIONgoes from 2 to 3. The gate now reads a recordedsize_fractionof 25 differently, and the intent records more than before.LLM_SELL_SIZINGstays unchanged, on purpose. Only a pipeline's risk branch sendssize_fraction, and neither of the marker's readers (leaderboard pools, Live month resume) runs a pipeline. Changing it would make the Live board replay its month (billable) with no change to any of its trades.Also updated: the Per-order size (SELL) and Action count rows of SECURITY.md, and the tape design spec.
Tests: new cases in
test_pipeline_runner.py,test_llm_sell_sizing.py(including gate-level pipeline runs for the double sell and the stop beside a buy) andtest_decision_tape.py. Full backend suite: 7583 passed. The 12 failures are local-environment only (no reportlab fortest_report_pdf.py, mcp 1.28 vs the 1.30 pin fortest_robinhood_mcp_transport.py) and fail on cleanmaintoo.Closes #690. Closes #700. Closes #701. Closes #702. Closes #703.
🤖 Generated with Claude Code