Files
nt8-sdk/TASK_GAP066_SETDEFAULTS_ORDERING_PROMPT.md
mo 5907e9cc54
Some checks failed
CI Build & Test / Build & Test (Windows) (push) Has been cancelled
CI Build & Test / Build & Test (Linux/mono) (push) Has been cancelled
[GOV]: sync governance to v9.0 + 2026-10-24 findings; stage GAP-077/067 prompts
2026-10-26 08:12:20 -04:00

101 lines
6.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# TASK: GAP-066 — `base.OnStateChange()` runs last and silently overwrites four ORB defaults
# Staged: 2026-09-22 — v9.0 task P0-C / next-action N-05
# Sprint: Stage 0 — restore trust in the artifact
# Owner: Kilocode
# Deploy: COMMIT ONLY — do NOT run deploy-to-nt8.bat as part of this task. The operator is
# performing a manual orphan-file cleanup and recompile (P0-A/N-01) and deploy
# sequencing must stay under operator control until that completes.
# ─────────────────────────────────────────────────────────────────
## THE DEFECT
`SimpleORBNT8.OnStateChange()` calls `base.OnStateChange()` at **line 163**, *after* its own
`State.SetDefaults` block. `NT8StrategyBase.OnStateChange()`'s own `SetDefaults` branch then
reassigns the base-owned properties, overwriting four values the subclass had just set:
| Property | `SimpleORBNT8` sets | `NT8StrategyBase` then sets | Live export confirms |
|---|---|---|---|
| `RunnerTrailTicks` | 20 (`SimpleORBNT8.cs:143`) | **12** (`NT8StrategyBase.cs:507`) | `Runner : True \| Trail=12ticks` |
| `MinTradeGrade` | 5 (`:135`) | **4** (`:498`) | `MinTradeGrade : 4` |
| `MaxOpenPositions` | 2 (`:128`) | **3** (`:485`) | `MaxOpenPositions : 3` |
| `BarsRequiredToTrade` | 50 (`:134`) | **1** (`:480`) | `BarsRequiredToTrade: 1` |
All four confirmed against `settings_Simple_ORB_NT8_20260908_082122.txt`. This is not theoretical:
the strategy has been trading a **12-tick** trailing stop while its own subclass asked for 20, which
means every prior analysis of runner economics — including GAP-054's — used the wrong trail
distance. `deploy-to-nt8.bat` closes by instructing the operator to *"Verify defaults: …
RunnerTrailTicks=20 …"*, a check that is unsatisfiable from source and has presumably been skipped
or mis-passed at every deploy.
Properties the subclass sets to the *same* value the base sets (`DailyLossLimit`, `MaxTradeRisk`,
`RiskPerTrade`, `MinContracts`, `MaxContracts`, `BreakevenTriggerTicks`, `BreakevenOffsetTicks`,
`EnableAutoBreakeven`, `EnableRunner`, `EnableLongTrades`, `EnableShortTrades`) are unaffected —
which is exactly why this went unnoticed for so long.
## READ-FIRST
1. `src/NT8.Adapters/Strategies/SimpleORBNT8.cs` `OnStateChange()` — the whole method, especially
the `State.SetDefaults` branch (~`114–157`) and the `base.OnStateChange()` call at `:163`.
Note what else the method does after the base call and whether any of it depends on base state
having been initialised first.
2. `src/NT8.Adapters/Strategies/NT8StrategyBase.cs` `OnStateChange()` `State.SetDefaults` branch
(~`461–540`). Confirm the four assignments above and enumerate **every** property it sets, so
the fix can be reasoned about completely rather than for these four alone.
3. `tests/NT8.Core.Tests/Adapters/SimpleORBNT8DefaultsTests.cs` — the existing source-text defaults
tests. Understand why they did not catch this: they assert on source literals, not on effective
post-initialisation values.
## THE FIX
Reorder so the base initialises first and the subclass's intent wins. The obvious shape is to move
`base.OnStateChange()` to the **top** of `SimpleORBNT8.OnStateChange()`, but **verify before
implementing** that nothing later in the subclass method depends on the current ordering — in
particular, check the `State.Configure` and `State.DataLoaded` branches, which share the same
method and must keep working.
If moving the call wholesale is unsafe, the acceptable alternative is to call
`base.OnStateChange()` first *within the `State.SetDefaults` branch only*, leaving other states'
ordering untouched. State clearly in the implementation note which of the two you chose and why.
**Do not** change any of the four values themselves in this task. The point here is that the
subclass's stated intent should take effect. Whether 20 or 12 is the *right* trail is a separate
operator decision (v9.0 task P2-B) and must not be pre-empted by this fix.
## REQUIRED TEST
Add a test that asserts **effective post-initialisation values**, not source literals. Since
`SimpleORBNT8` is NinjaScript-derived and cannot be instantiated outside NT8, the established
source-text pattern (see `NT8StrategyBaseRunnerTrailTests.cs`) applies — but a pure text assertion
on "20 appears in the subclass" would reproduce exactly the blind spot that let this through.
The test must verify the *ordering*, not the values: assert that within
`SimpleORBNT8.OnStateChange()`, the `base.OnStateChange()` call appears **before** the subclass's
`RunnerTrailTicks` / `MinTradeGrade` / `MaxOpenPositions` / `BarsRequiredToTrade` assignments in the
`State.SetDefaults` path. A brace-depth or index comparison over the extracted method body is
sufficient and is the same technique
`tests/NT8.Core.Tests/Adapters/NT8StrategyBaseOnBarUpdateVisibilityTests.cs` already uses.
If you can see a way to make this a genuine execution test rather than a source-text one, propose
it in the implementation note rather than implementing it unasked — that would be a real
improvement to the project's weakest test surface and deserves its own decision.
## DO NOT
- Do not change the four values. Ordering only.
- Do not deploy.
- Do not touch `NT8StrategyBase.OnStateChange()`'s own `SetDefaults` branch — the base defaults are
correct *as base defaults*; the defect is that they run second.
- Do not "fix" this by removing the subclass's assignments. The subclass's intent is the thing being
restored, not the thing being deleted.
## VALIDATION (operator, after P0-A/N-01 and a recompile)
Export settings from a fresh session and confirm the export reads `Runner : True | Trail=20ticks`,
`MinTradeGrade : 5`, `MaxOpenPositions : 2`, `BarsRequiredToTrade: 50` — or, if the operator has
since made the P2-B decision differently, whatever values that decision selected.
## GOVERNANCE
Track as **GAP-066** in `SPRINT_BOARD.md` under BLOCKERS. Reference `DEC-20260922-01` and
Master Document v9.0 §1.3 Finding 3 and §4.10 in the commit and in `decisions.md`.