Files
nt8-sdk/TASK_GAP063_INIT_FAILURE_VISIBILITY_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

13 KiB

TASK: GAP-063 — SDK initialization failures are invisible in the persistent session log and the dashboard

Staged: 2026-08-26 (live incident this morning — two separate startup-assertion failures

back-to-back, each diagnosable only by reverse-engineering source and settings deltas

because the actual exception was never written to FileLog)

Sprint: Stage 1 — diagnostic/observability only, zero trading-behaviour risk

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 — a live incident, not a hypothetical)

This morning (2026-08-26) the strategy failed to initialize for over 2.5 hours across two consecutive sessions (06:31-08:58, then 08:58-09:00), then hit a second, different startup failure immediately after the first was fixed (09:25-09:30, ongoing as this task is staged). In both cases, every single bar was rejected with the same uninformative line:

REJECT: reason=WarmupIncomplete detail=SdkInitialized=False StrategyNull=True bar=...

with zero indication anywhere in session_*.log of why. Diagnosing both required reading NT8StrategyBase.cs source directly and reverse-engineering which startup assertion in RiskEnvelopeValidator.ValidateStartupConfiguration() (src/NT8.Core/Risk/BasicRiskManager.cs ~327-385, added by GAP-045/046, 2026-08-23) must have thrown, by cross-checking the exported settings file against each assertion's inequality by hand:

  1. First failure: EnableTrailingDrawdown=True with AccountStartingBalance=$0.00 — the exact enableTrailingDrawdown && accountStartingBalance <= 0.0 guard.
  2. Second failure, immediately after the operator fixed #1: MaxTradeRisk=$200.00 with the code default MaxStopTicks=50 (NT8StrategyBase.cs:513) and NQ's $5.00/tick (InstrumentTickValueTable.cs:20) — 50 * 5.00 = $250 > $200, the exact maxStopRisk > maxTradeRisk guard. This is the same GAP-045 collision documented in DEC-20260818-19/DEC-20260823-*, recurring because MaxTradeRisk reverted to $200 at some point after the 2026-08-23 SIM session (where it had been raised to $250) — likely a workspace/parameter reset that is itself worth the operator's attention, but is not this task's scope.

Root cause, confirmed by reading the code:

OnStateChange()'s State.DataLoaded handler (NT8StrategyBase.cs ~549-576) wraps InitFileLog(); InitializeSdkComponents(); InitializeTrailingDrawdownState(); in a try/catch. On exception, the catch block does this and nothing else:

catch (Exception ex)
{
    Print(string.Format("[SDK ERROR] Initialization failed: {0}", ex.Message));
    Log(string.Format("[SDK ERROR] {0}", ex.ToString()), NinjaTrader.Cbi.LogLevel.Error);
    _sdkInitialized = false;
}

Print() and Log() write only to NT8's in-app Output window — never to the persistent FileLog() session log. Nobody reads the Output window after the fact; the whole reason FileLog()/GAP-035 exist is so a session can be diagnosed from disk. InitFileLog() runs before InitializeSdkComponents() in the same try block, so _fileLog is already open and ready — FileLog() calls from inside this catch block will work immediately, no ordering change needed.

Compounding the blindness, the subsequent State.Realtime transition handler makes things look actively fine regardless of whether init succeeded. WriteHistoricalReadiness("REALTIME ELIGIBILITY") and WriteSettingsFile() (~609-610) run unconditionally on that transition — neither checks _sdkInitialized. This is exactly why this morning's log looked completely healthy (Historical readiness, DataSeries[...], FactorWarmup ... SATISFIED, SETTINGS FILE: ...) right up until the first live bar arrived and hit the WarmupIncomplete: SdkInitialized=False guard in OnBarUpdate() — with nothing in between explaining why.

The dashboard inherits this blindness one layer up. tools/dashboard/parsers.py's parse_readiness() (~557-589) derives the "Session Readiness" panel purely from those same three unconditional lines — it has no concept of SdkInitialized/StrategyNull at all, confirmed by grepping the whole tools/dashboard/ tree. console.js's renderWarmups() paints green "good" chips for SATISFIED factors with no cross-check against whether the strategy is actually alive. During both failures this morning, the dashboard would have shown a fully green, healthy-looking readiness panel while the strategy sat completely dead, with the only symptom being an unexplained, climbing WarmupIncomplete count elsewhere on the page.

A second, smaller compounding issue: WarmupIncomplete is reused as the reject reason for six structurally different conditions — this SdkInitialized=False/StrategyNull=True case, BarsInProgress != 0 (~629), the replay-burst guard (~646), CurrentBar < BarsRequiredToTrade (~683), duplicate bar time (~689), and the harmless "first realtime bar marks eligibility" marker that fires exactly once, every session, by design (~711). This is the same reason-taxonomy-conflation class GAP-048 already fixed for KillSwitch/GradeFilter/TrailingDrawdownBreach — but WarmupIncomplete itself was explicitly left alone at the time (DEC-20260818-20: "OrbRangeNotEstablished retains its three sub-states under one reason for now — lower priority"; WarmupIncomplete wasn't even named). Because of this, a dashboard/logtriage aggregate showing WarmupIncomplete: N cannot distinguish "everything's fine, this is just the one-per-session first-bar marker" from "the SDK is dead and every bar this session has been rejected."

READ-FIRST

  1. src/NT8.Adapters/Strategies/NT8StrategyBase.cs ~549-576 — the State.DataLoaded try/catch this task's primary fix targets. Confirm _fileLog/FileLog() really is safely callable from inside the catch (i.e. InitFileLog() on the line above already succeeded) before writing the fix — if InitFileLog() itself is what threw, FileLog() will silently no-op (_fileLog == null guard), which is fine and expected, not a bug to work around.
  2. src/NT8.Adapters/Strategies/NT8StrategyBase.cs ~598-611 — the State.Realtime handler's unconditional WriteHistoricalReadiness/ WriteSettingsFile calls. Confirm your read matches: neither checks _sdkInitialized.
  3. src/NT8.Adapters/Strategies/NT8StrategyBase.cs ~675-678 — the OnBarUpdate() guard that currently folds SdkInitialized=False into the generic WarmupIncomplete reason.
  4. src/NT8.Adapters/Strategies/NT8StrategyBase.cs ~1523-1543 — LogRejectRateLimited()/FileLog(), to match existing conventions for the new reject line and confirm the rate-limiting/session-gating behavior you need to preserve.
  5. src/NT8.Core/Risk/BasicRiskManager.cs ~327-385 — RiskEnvelopeValidator.ValidateStartupConfiguration(), to see the exact set of messages this task needs to get into FileLog.
  6. tools/dashboard/parsers.py ~557-589 (parse_readiness) and tools/dashboard/console.js ~278-380 (renderReadiness/summarizeReadiness/ renderWarmups) — the display-layer blind spot this task also closes.
  7. docs/00-governance/decisions.md — search DEC-20260818-19/DEC-20260823-* for the original GAP-045/046 assertion work this task adds visibility on top of, without changing.

THE CHANGE

Part 1 — get the actual failure into FileLog. In OnStateChange()'s State.DataLoaded catch block, add a FileLog() call alongside the existing Print/Log calls, before _sdkInitialized = false;:

FileLog(string.Format("SDK INIT FAILED: {0}", ex.Message));

Keep the existing Print/Log calls unchanged — this is additive.

Part 2 — give the dead-strategy case its own reject reason, not the WarmupIncomplete catch-all. In OnBarUpdate()'s !_sdkInitialized || _sdkStrategy == null guard (~675-678), change the reason string from "WarmupIncomplete" to a new, distinct reason — e.g. "SdkNotInitialized" — so it shows up as its own line in REJECT SUMMARY, separable from the five other conditions currently sharing WarmupIncomplete. Do not touch the other five WarmupIncomplete call sites (~629, ~646, ~683, ~689, ~711) — they are a legitimate future cleanup (same class as OrbRangeNotEstablished's three sub-states, explicitly deferred in DEC-20260818-20) but out of scope here; this task only carves out the one case that means "the strategy is completely dead," because that is the one whose absence of a distinct label caused this morning's confusion.

Part 3 — surface it in the dashboard. tools/dashboard/parsers.py's parse_readiness() should also scan the tail for the new SDK INIT FAILED: ... line (Part 1) and/or the new SdkNotInitialized reject reason (Part 2), and include something like "sdk_initialized": false and "sdk_init_error": "<message>" in its returned dict when found (default true/null when no such line is present in the tail, i.e. today's ordinary "everything's fine" case must render identically to before). In tools/dashboard/console.js's renderReadiness(), when readiness.sdk_initialized === false, replace the green FactorWarmup chips and the readiness summary text with an unambiguous red/bad state showing the actual error message from sdk_init_error — do not just leave the misleading green chips showing alongside a small note; the whole point is that this state must be impossible to mistake for "warming up normally." When sdk_initialized is true or absent, rendering must be byte-for-byte unchanged from today.

DO NOT

  • Do not change RiskEnvelopeValidator.ValidateStartupConfiguration(), any of its four assertions, or any risk/sizing/order-flow logic. This task is observability-only — it makes existing, correct startup failures visible; it does not change when or why they fire.
  • Do not touch the other five WarmupIncomplete call sites (~629, ~646, ~683, ~689, ~711) — only the SdkInitialized=False/StrategyNull=True case gets a new reason string.
  • Do not add retry, auto-recovery, or any behavior that attempts to re-initialize the SDK after a failed State.DataLoaded attempt — this task is diagnostic visibility only, not resilience.
  • Do not change WriteHistoricalReadiness()/WriteSettingsFile() to skip or gate on _sdkInitialized — leaving them unconditional is fine (and arguably correct, since settings/readiness are still real facts about the session); the fix is making the failure visible elsewhere, not hiding these lines.
  • Do not touch MaxStopTicks, MaxTradeRisk, or any other risk parameter value — the specific $200/$250 collision seen this morning is an operator configuration matter for today, not something this task resolves.

TESTS (required)

  1. A test proving that when InitializeSdkComponents() throws (mock/inject a failure the same way existing tests for this class simulate NinjaScript state, or use the established source-text-assertion pattern for this NinjaScript-derived class if a real execution test isn't practical — check TASK_GAP057_STOP_TRAIL_TEST_SEAM_PROMPT.md's precedent), a FileLog-bound SDK INIT FAILED: ... line is produced containing the exception message.
  2. A test proving OnBarUpdate()'s dead-strategy guard now logs reason SdkNotInitialized, not WarmupIncomplete, when _sdkInitialized is false or _sdkStrategy is null — and that the other five WarmupIncomplete call sites are unchanged (still WarmupIncomplete).
  3. A parsers.py test proving parse_readiness() returns sdk_initialized: false and a populated sdk_init_error when a SDK INIT FAILED: ... line is present in the tail, and sdk_initialized: true (or the field absent, whichever you choose as the "normal" default — document which) otherwise.
  4. Confirm the full existing suite still passes, including any existing parsers.py/dashboard tests.

VALIDATION (operator)

No live order-flow or risk behavior changes — this is pure visibility. Next time a startup assertion fires (including if today's second collision recurs), session_*.log should show SDK INIT FAILED: Invalid risk configuration for NQ: ... immediately after the SETTINGS FILE: line, a REJECT SUMMARY: reason=SdkNotInitialized count=N distinct from WarmupIncomplete, and the dashboard's readiness panel should flip to a visibly broken state showing the same error message — not green SATISFIED chips. Restart the dashboard server after deploying so it picks up the parsers.py change.

GOVERNANCE

Track as [GAP-063] in SPRINT_BOARD.md. Update docs/00-governance/decisions.md with a new dated entry referencing this task, citing this morning's two-in-a-row live incident (both diagnosed only by reading source and hand-checking settings deltas against RiskEnvelopeValidator's assertions) as the motivating evidence. Reference: this task, DEC-20260818-19/DEC-20260823-* (the original GAP-045/046 assertions this task adds visibility on top of), DEC-20260818-20 (GAP-048's precedent for reject-reason taxonomy work and its explicit deferral of WarmupIncomplete's own sub-states).