- src/NT8.Adapters/NinjaTrader/ConnectionStateMonitor.cs: added plain testable connection-state monitor - src/NT8.Adapters/Strategies/NT8StrategyBase.cs: wired monitor and added pre-submit ConnectionLost check - tests/NT8.Core.Tests/Scenarios/ScenarioTests.cs: added disconnect scenario coverage - SPRINT_BOARD.md: GAP-022-FOLLOWUP implemented/deployed - docs/00-governance/current_status.md: updated - docs/00-governance/decisions.md: added DEC-20260826-07 Build: clean | Tests: 580 passing | Dual-deployed: yes, backup 20260826_011650
8.9 KiB
TASK: GAP-022-FOLLOWUP — injectable connection-state seam + 2 of 3 deferred scenario tests
Staged: 2026-08-26 (long-queued Sprint 2.7 item, now prompted; DEC-20260826-05)
Sprint: Stage 1 — new testable component + tests, zero production order-flow logic change
Owner: Kilocode
Deploy: COMMIT ONLY — do NOT run deploy-to-nt8.bat or copy build output to
the live NT8 install as part of this task. Verify-build and commit
as usual; leave the deploy step for the operator to run manually
once ready.
─────────────────────────────────────────────────────────────────
THE DEFECT (why this is worth doing)
tests/NT8.Core.Tests/Scenarios/ScenarioTests.cs has a TODO block at the
bottom (read it — it's the actual, honest scope statement, more precise
than SPRINT_BOARD's one-line summary) listing three scenarios GAP-022
could not honestly cover:
// TODO GAP-022 follow-ons (not claimed as covered):
// NEWS_DAY_REDUCED_SIZE requires high-impact-event calendar and sizing-policy APIs.
// MID_TRADE_DISCONNECT requires an injectable connection-state seam around NT8StrategyBase.
// PRE_ENTRY_DISCONNECT requires an atomic pre-submit connection check and test seam.
This task covers only the second and third. NEWS_DAY_REDUCED_SIZE is a
different, much larger scope — it needs a high-impact-event economic
calendar and a sizing-policy API that don't exist anywhere in this repo
yet, not just a test seam. Bundling it into this task (as SPRINT_BOARD's
old one-line summary implied) would be scope creep against something that
isn't even designed yet. Leave it out; it needs its own future task once
someone decides what a news-day calendar/sizing-policy API should look
like.
Confirmed by direct source read on 2026-08-26:
NT8StrategyBase.csowns connection state as a bare private field,_connectionLost(declared ~136), set only insideOnConnectionStatusUpdate(~1411-1431, a NinjaScript-overridden callback), and read only once, early inOnBarUpdate(~746) — well before order submission happens later in the same call (ProcessStrategyIntent~2059,SubmitOrderToNT8~2171+). There is no re-check of_connectionLostanywhere between that early guard and the actual order submission calls. BecauseNT8StrategyBaseis a NinjaScript-derived class that cannot be instantiated outside a live NT8 host, there is currently no way to driveMID_TRADE_DISCONNECTorPRE_ENTRY_DISCONNECTas a real execution test — exactly what the TODO says.
READ-FIRST
tests/NT8.Core.Tests/Scenarios/ScenarioTests.cs(full file, it's short) — the existing passing scenarios and the TODO block this task closes two-thirds of.src/NT8.Adapters/Strategies/NT8StrategyBase.cs~136, ~526, ~746, ~1411-1431, ~1633 — every current read/write site of_connectionLost.src/NT8.Adapters/Strategies/NT8StrategyBase.cs~2059-2075 (ProcessStrategyIntent) and ~2171+ (SubmitOrderToNT8) — confirm there is genuinely no connection re-check between the earlyOnBarUpdateguard and order submission, i.e. confirm thePRE_ENTRY_DISCONNECTgap is real, not just apparent.TASK_GAP057_STOP_TRAIL_TEST_SEAM_PROMPT.mdand its resultingNT8StrategyBaseRunnerTrailTests.cs— the nearest precedent in this codebase for a NinjaScript-derived class that couldn't be tested directly, and the source-text-assertion pattern chosen there (Option B) when a genuine seam wasn't built. This task takes the other path (Option A below) because the fix is small and self-contained enough to extract cleanly — but read GAP-057's reasoning so your writeback can explain why this task didn't need the same fallback.
THE CHANGE
Option A (build the seam) — do this unless your own read of the code finds it genuinely impractical, in which case fall back to a GAP-057-style source-text seam and explain why in your writeback.
- Extract connection-state tracking out of
NT8StrategyBaseinto a new, plain (non-NinjaScript-derived) class — e.g.src/NT8.Adapters/NinjaTrader/ConnectionStateMonitor.cs— that owns the connected/disconnected boolean and exposes whatever read/write surfaceNT8StrategyBaseneeds (at minimum: a way to report a status change, and a way to query current state). This class must be instantiable and testable on its own, with no NT8 dependencies. NT8StrategyBase.OnConnectionStatusUpdatedelegates to this new component instead of directly mutating_connectionLost.OnBarUpdate's existing connection-loss guard (~746) andProcessStrategyIntent/SubmitOrderToNT8read from it instead of the bare field. Behavior must be unchanged for the existing guard at ~746 — this task does not change when or how the existing guard fires, only where its underlying state lives.- Add the missing pre-submit check:
ProcessStrategyIntent(orSubmitOrderToNT8, whichever is the more correct single choke point — read both and decide) should re-check the connection-state component immediately before submitting an order, not rely solely on the earlyOnBarUpdate-level guard from earlier in the same bar's processing. Reject with the existingConnectionLostreason (LogRejectRateLimited("ConnectionLost", ...), matching the existing convention at ~746) if disconnected at that point. This closes the actual gapPRE_ENTRY_DISCONNECT's TODO names. - With the new component in place, implement the two scenario tests in
ScenarioTests.cs, replacing their TODO lines:MID_TRADE_DISCONNECT: with an open position and a connected state, report a disconnect via the new component, and prove no new entry is attempted while disconnected (do not invent flatten-on-disconnect behavior — that isn't what the existing code does today; only prove new entries are blocked, matching currentConnectionLostsemantics).PRE_ENTRY_DISCONNECT: prove that a connection loss reported after a signal is generated but before the order is actually submitted results in the order being blocked by the new pre-submit check added in step 3, not silently submitted.
DO NOT
- Do not implement
NEWS_DAY_REDUCED_SIZE— separate, larger, not-yet designed scope (see THE DEFECT). Leave its TODO line in place. - Do not change the existing
OnBarUpdateconnection-loss guard's behavior (still fires at the same point, sameConnectionLostreason). - Do not add flatten-on-disconnect or any other new order-management behavior beyond the pre-submit block described in step 3 — this task is about making existing "no new entries while disconnected" behavior atomic and testable, not about adding new disconnect-response logic.
- Do not touch risk, sizing, grade-filter, or ORB-building code.
- Do not touch
OnOrderUpdate/OnExecutionUpdate(GAP-025, separate, already in progress).
TESTS (required)
- Unit tests for the new connection-state component in isolation (report disconnect → query returns disconnected; report reconnect → query returns connected).
MID_TRADE_DISCONNECTandPRE_ENTRY_DISCONNECTinScenarioTests.csas described in THE CHANGE step 4 — real execution tests against the new component and the pre-submit check, not source-text assertions, since the whole point of building the seam is to make these genuine.- A test proving the pre-submit check added in step 3 doesn't change behavior for the connected case (order proceeds normally when connected — no regression for the common path).
- Confirm the full existing suite still passes, including
ScenarioTests.cs's existing four passing scenarios.
VALIDATION (operator)
No live order-flow behavior change for the connected case — the pre-submit
check only adds a rejection path for a state that was already supposed to
block orders (per the existing OnBarUpdate guard), just closes the
narrow timing gap where a mid-bar disconnect wasn't re-checked. Nothing to
validate on SIM beyond the test suite passing; this is exercised whenever
a genuine disconnect occurs during a live/SIM session going forward,
should be visible as an unchanged ConnectionLost reject reason in the
log either way.
GOVERNANCE
Track as [GAP-022-FOLLOWUP] in SPRINT_BOARD.md — move out of the "QUEUED —
branch-only during Gate Run #2" framing (stale gate-sequencing language)
into an entry reflecting Option A implemented (or the Option B fallback,
if your own read finds Option A impractical). Note explicitly that
NEWS_DAY_REDUCED_SIZE remains open and out of scope. Update
docs/00-governance/decisions.md with a new dated entry referencing this
task and DEC-20260826-05.
Reference: this task, DEC-20260826-05, TASK_GAP057_STOP_TRAIL_TEST_SEAM_PROMPT.md
(nearest precedent for a NinjaScript-derived-class test-seam decision).