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:
- First failure:
EnableTrailingDrawdown=TruewithAccountStartingBalance=$0.00— the exactenableTrailingDrawdown && accountStartingBalance <= 0.0guard. - Second failure, immediately after the operator fixed #1:
MaxTradeRisk=$200.00with the code defaultMaxStopTicks=50(NT8StrategyBase.cs:513) and NQ's$5.00/tick (InstrumentTickValueTable.cs:20) —50 * 5.00 = $250 > $200, the exactmaxStopRisk > maxTradeRiskguard. This is the same GAP-045 collision documented inDEC-20260818-19/DEC-20260823-*, recurring becauseMaxTradeRiskreverted 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
src/NT8.Adapters/Strategies/NT8StrategyBase.cs~549-576 — theState.DataLoadedtry/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 — ifInitFileLog()itself is what threw,FileLog()will silently no-op (_fileLog == nullguard), which is fine and expected, not a bug to work around.src/NT8.Adapters/Strategies/NT8StrategyBase.cs~598-611 — theState.Realtimehandler's unconditionalWriteHistoricalReadiness/WriteSettingsFilecalls. Confirm your read matches: neither checks_sdkInitialized.src/NT8.Adapters/Strategies/NT8StrategyBase.cs~675-678 — theOnBarUpdate()guard that currently foldsSdkInitialized=Falseinto the genericWarmupIncompletereason.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.src/NT8.Core/Risk/BasicRiskManager.cs~327-385 —RiskEnvelopeValidator.ValidateStartupConfiguration(), to see the exact set of messages this task needs to get into FileLog.tools/dashboard/parsers.py~557-589 (parse_readiness) andtools/dashboard/console.js~278-380 (renderReadiness/summarizeReadiness/renderWarmups) — the display-layer blind spot this task also closes.docs/00-governance/decisions.md— searchDEC-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
WarmupIncompletecall sites (~629, ~646, ~683, ~689, ~711) — only theSdkInitialized=False/StrategyNull=Truecase 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.DataLoadedattempt — 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)
- 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 — checkTASK_GAP057_STOP_TRAIL_TEST_SEAM_PROMPT.md's precedent), aFileLog-boundSDK INIT FAILED: ...line is produced containing the exception message. - A test proving
OnBarUpdate()'s dead-strategy guard now logs reasonSdkNotInitialized, notWarmupIncomplete, when_sdkInitializedis false or_sdkStrategyis null — and that the other fiveWarmupIncompletecall sites are unchanged (stillWarmupIncomplete). - A
parsers.pytest provingparse_readiness()returnssdk_initialized: falseand a populatedsdk_init_errorwhen aSDK INIT FAILED: ...line is present in the tail, andsdk_initialized: true(or the field absent, whichever you choose as the "normal" default — document which) otherwise. - 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).