Skip to content

Commit 2f7c1a3

Browse files
luisleo526claude
andcommitted
tests: rebuild the row-10 and row-21 ownership probes so they reach the rows they pin (CR-139)
engine/margin_maintenance_overflow entered 1e-10 units, which never became a position, so the maintenance producer (which returns while the book is flat) was never reached and the run completed with no trade. The entry is now one unit; on a box the run fails with engine_command_value_invalid (margin.maintenance, nonfinite), the pinned result. engine/settlement_pnl_overflow failed one stage early: the percent fee quote overflows to NaN before the settlement money predicate runs. A percent commission of 0 cannot avoid that for a single trade, so the probe now uses a price-free cash_per_contract commission of 0 and two lots that are closed together, which takes the staged settlement and fails with engine_invariant at the money predicate, the pinned result. Both expectations are unchanged (they come from the ruled rows, not from an observation); only probe.pine and NOTES.md change. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 6a599fe commit 2f7c1a3

4 files changed

Lines changed: 20 additions & 8 deletions

File tree

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# margin_maintenance_overflow
22

3-
Pinned before execution: D6 row 10 maintenance requirement.
3+
Pinned before execution: D6 row 10 maintenance requirement. The expectation is unchanged; the probe was rebuilt (TX-PROBES, CR-139) because its first form never reached the row.
44

5-
At 1, the tiny held position has a finite placement requirement and a finite kernel unit maintenance (1e306). After the price jumps to 100000, the kernel unit-maintenance product overflows, despite a finite position P&L. Fractions are finite and positive so the model is built. A default lot grid imposed by an external runner could prevent the seed; the spot driver must use the ordinary no-override route and record actual reachability.
5+
The entry quantity was 1e-10; the run completed with no trade and no position, so the maintenance producer (`src/native_execution_consumer.cpp:3836-3863`, which returns while the book is flat) was never reached. The quantity is now 1: the entry fills at the bar-2 open at price 1 with a finite placement requirement (1e306 against equity 1e307) and a finite kernel unit maintenance (1e306). After the price jumps to 100000 at bar 6, the kernel unit-maintenance product overflows, despite a finite position P&L, and the maintenance producer must fail with `engine_command_value_invalid` (`margin.maintenance`, `nonfinite`, stage `margin`). Fractions are finite and positive so the model is built. Why the 1e-10 entry did not fill is not established; the fix does not depend on it.
66

7-
Feed: 40 synthetic one-minute bars, starting at 1736121600000 ms, volume 1. Each OHLC is the same deterministic price in its row. No market data, private fixture, generated C++, or output-derived expectation is used. Run through the P0 ordinary-source driver with input/script timeframe 1; no quantity, tick, FX, commission or margin overrides. Authored only: transpilation, compilation and runtime reachability have not been checked here.
7+
Feed: 40 synthetic one-minute bars, starting at 1736121600000 ms, volume 1. Each OHLC is the same deterministic price in its row. No market data, private fixture, generated C++, or output-derived expectation is used. Run through the P0 ordinary-source driver with input/script timeframe 1; no quantity, tick, FX, commission or margin overrides.
8+
9+
The expectation is the contract row (revision 3: a value derived by the engine from its own margin state that is nonfinite is `engine_command_value_invalid`), not an observation. The box run with qty 1 produced that result with 0 trades and exit 1.
810

911
The native boundary control names the requested source-free test TU. Its relevant native producer/control is an arithmetic counterpart; source-specific cash/equity/placement checks are in the proposed source companion. No source probe claims coverage of the internal pending-deduction corruption used for D6 row 6.
12+
13+
Known edge, not covered here: a 1x long (`margin_long=100`) with a point value other than 1 and no lot grid is never maintenance-checked by the adapter (`src/source/pine_adapter.cpp:18548-18559`, `:22630`), so this row is witnessed on the checked route (margin other than 100, or a short).
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
//@version=6
22
strategy("EN132 margin_maintenance_overflow", initial_capital=1e307, margin_long=1e308, margin_short=1e308, commission_type=strategy.commission.percent, commission_value=0, slippage=0)
33
if bar_index == 1
4-
strategy.entry("L", strategy.long, qty=1e-10)
4+
strategy.entry("L", strategy.long, qty=1)
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# settlement_pnl_overflow
22

3-
D6 row 21, AFTER-g134 follow-up expectation. Entry is four units at 1; the close requested at bar 3 fills at bar 4's finite 1e308 print. The row's PnL overflows and the existing money predicate rejects InvalidAccounting. The typed recode is deliberately deferred in this lane. Forty flat five-minute bars, first four at 1 and the rest at 1e308, volume 1; mintick=1 keeps all price normalization finite. Paired row: d6_21_settlement_pnl. No risk limit is configured. Main fails with engine_invariant, not the pinned settlement G. Do not claim green until the coordinated hunk and executed spot receipt.
3+
D6 row 21, AFTER-g134 follow-up expectation. The expectation is unchanged; the probe was rebuilt (TX-PROBES, CR-139) because its first form never reached row 21.
44

5-
Authoring only: no transpile, compilation, engine execution or driver run in this lane. The expectation comes from D6 FINAL before any observation. A nonzero tripwire hit requires the supervisor's KEEP/ruling procedure; this file is not a sweep verdict.
5+
First form: four units entered at 1 and closed at bar 4's finite 1e308 print with the default percent commission. The fee quote `abs(price) * quantity * pointvalue * fx * (commission / 100)` overflows to infinity and times zero is NaN, so the run failed earlier with `engine_command_value_invalid` (`fee.commission`, `numeric_overflow`, stage `fee`) and the settlement money predicate was never witnessed. With a percent commission of 0 and positive prices a single trade cannot get a nonfinite PnL without that fee quote going NaN first (the fee chain is bounded by the same product), so the fee had to become price-free.
6+
7+
Now: `cash_per_contract` with value 0 makes every fee quote `0 * quantity`, which cannot overflow. Two long lots of 2 at 1 (`pyramiding=2`, entries on bars 0 and 1) are closed together at bar 4's finite 1e308 print. Two lots take the staged settlement, where `prepare_native_settlement_commit` (`src/engine_execution.cpp:1247-1281`) rejects the row whose PnL is `fl(fl(1e308 - 1) * 2)` = +inf with `InvalidAccounting` (`:1271-1272`), reported as `engine_invariant` (KEEP, D6 row 21). The expectation is the ruled row, not an observation; the box run produced `failed / engine_invariant / {}` with 0 trades. The driver cannot tell the staged path from the fused one-lot path, so the staged path is the design (two lots), not a measured fact.
8+
9+
Forty flat five-minute bars, first four at 1 and the rest at 1e308, volume 1; mintick=1 keeps all price normalization finite. No risk limit is configured. Note: a nonfinite PnL always makes `pnl_pct` nonfinite too (row 22), so a single closed row cannot isolate row 21 from row 22.
10+
11+
Authoring note: the earlier "Paired row: d6_21_settlement_pnl" does not exist in `tests/test_native_settlement_row_finite.cpp`; the native control file named in `expect.json` is that file.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//@version=6
2-
strategy("D6 21 settlement money overflow", initial_capital=100000, margin_long=0, margin_short=0)
2+
strategy("D6 21 settlement money overflow", initial_capital=100000, margin_long=0, margin_short=0, pyramiding=2, commission_type=strategy.commission.cash_per_contract, commission_value=0)
33
if bar_index == 0
4-
strategy.entry("entry", strategy.long, qty=4)
4+
strategy.entry("a", strategy.long, qty=2)
5+
if bar_index == 1
6+
strategy.entry("b", strategy.long, qty=2)
57
if bar_index == 3
68
strategy.close_all()

0 commit comments

Comments
 (0)