[GAP-025]: runner order lifecycle logging complete

- src/NT8.Adapters/Strategies/NT8StrategyBase.cs: add ORDER lifecycle FileLog and FILL signal name

- tests/NT8.Core.Tests/Adapters/NT8StrategyBaseOrderLifecycleTests.cs: add source-text regression coverage

- SPRINT_BOARD.md: GAP-025 prompted -> implemented/deployed

- docs/00-governance/current_status.md: record GAP-025 implementation

- docs/00-governance/decisions.md: record DEC-20260826-04

Build: clean | Tests: 572 passing | Dual-deployed: yes, backup 20260826_010153
This commit is contained in:
2026-08-26 01:03:12 -04:00
parent 34c3767fbf
commit 49bcd0b43c
5 changed files with 134 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
# NT8 SDK — Sprint Board # NT8 SDK — Sprint Board
**Last Updated:** 2026-08-26 (GAP-025/GAP-030 prompted; GAP-062 deployed by operator request — see DEC-20260826-02) **Last Updated:** 2026-08-26 (GAP-025 implemented/deployed; GAP-030 prompted next)
**Truth source:** compiler output, test output, deployed-file comparisons, and runtime artifacts override board claims. **Truth source:** compiler output, test output, deployed-file comparisons, and runtime artifacts override board claims.
## Current gate state ## Current gate state
@@ -147,10 +147,10 @@ The dirty working tree — several modified/untracked files including live strat
## 📋 QUEUE — no deploy to the gate machine during a run ## 📋 QUEUE — no deploy to the gate machine during a run
**[GAP-025] Runner/scaler order lifecycle invisible in the persistent session log** | Sprint 2.7 | 🟡 PROMPTED **[GAP-025] Runner/scaler order lifecycle invisible in the persistent session log** | Sprint 2.7 | ✅ IMPLEMENTED — deployed 2026-08-26
- Reading `OnOrderUpdate`/`OnExecutionUpdate` (`NT8StrategyBase.cs` ~1270-1345) on 2026-08-26 found the actual gap behind the old "runner no-fill anomaly" framing: `OnOrderUpdate` never writes to `FileLog` for any order state except `Rejected` (everything else — submitted, accepted, working, cancelled — is Print-only, invisible outside NT8's live Output window), and the `FILL` line in `OnExecutionUpdate` doesn't include the order/signal name, so scaler vs. runner fills can't be told apart from the file log at all. - Reading `OnOrderUpdate`/`OnExecutionUpdate` (`NT8StrategyBase.cs` ~1270-1345) on 2026-08-26 found the actual gap behind the old "runner no-fill anomaly" framing: `OnOrderUpdate` never writes to `FileLog` for any order state except `Rejected` (everything else — submitted, accepted, working, cancelled — is Print-only, invisible outside NT8's live Output window), and the `FILL` line in `OnExecutionUpdate` doesn't include the order/signal name, so scaler vs. runner fills can't be told apart from the file log at all.
- Scoped diagnostic-only: adds an `ORDER {signal} State=... Filled=.../... AvgFillPrice=...` FileLog line to `OnOrderUpdate` for every transition, and adds the signal name to the existing `FILL` line. Zero change to order submission, sizing, or execution-adapter logic. - Scoped diagnostic-only: adds an `ORDER {signal} State=... Filled=.../... AvgFillPrice=...` FileLog line to `OnOrderUpdate` for every transition, and adds the signal name to the existing `FILL` line. Zero change to order submission, sizing, or execution-adapter logic.
- Prompt: `TASK_GAP025_RUNNER_ORDER_LIFECYCLE_LOGGING_PROMPT.md`. - Prompt: `TASK_GAP025_RUNNER_ORDER_LIFECYCLE_LOGGING_PROMPT.md`. Implemented as additive logging only: `OnOrderUpdate` now writes realtime `ORDER SDK_... State=... Filled=.../... AvgFillPrice=...` lines for SDK-managed order transitions, and the existing `FILL` line now includes `Signal=...` so scaler/runner fills are distinguishable. Existing circuit-breaker, execution-adapter, and portfolio-risk callbacks were left unchanged. Verification: focused Adapter tests 81/81, `verify-build.bat` 572/572. Deploy backup `20260826_010153`.
**[GAP-022-FOLLOWUP] Connection-State Test Seam** | Sprint 2.7 | ⏳ QUEUED — branch-only during Gate Run #2 **[GAP-022-FOLLOWUP] Connection-State Test Seam** | Sprint 2.7 | ⏳ QUEUED — branch-only during Gate Run #2
- Add an injectable connection-state seam around `NT8StrategyBase`. - Add an injectable connection-state seam around `NT8StrategyBase`.

View File

@@ -1,5 +1,13 @@
# Current Status — NT8 SDK # Current Status — NT8 SDK
**Last Updated:** 2026-08-26 (GAP-062 implemented; deploy skipped pending SIM before/after observation) **Last Updated:** 2026-08-26 (GAP-025 implemented; GAP-030 next)
---
## 2026-08-26 — GAP-025 implemented; runner/scaler order lifecycle logging added
Implemented and deployed `TASK_GAP025_RUNNER_ORDER_LIFECYCLE_LOGGING_PROMPT.md` as additive logging only. `NT8StrategyBase.OnOrderUpdate()` now writes realtime `ORDER SDK_... State=... Filled=.../... AvgFillPrice=...` lines for SDK-managed order transitions, making submitted/accepted/working/cancelled/rejected lifecycle state visible in the persistent session log. `OnExecutionUpdate()` keeps the existing `FILL` line shape but adds `Signal=...` so scaler (`SDK_*_S_*`) and runner (`SDK_*_R_*`) fills are distinguishable after the fact.
Verification passed: focused Adapter tests 81/81 and `verify-build.bat` 572/572. Existing order-management behavior was not changed: `SubmitOrderToNT8`, managed order calls, `_circuitBreaker.RecordOrderRejection`, `_executionAdapter.ProcessOrderUpdate`, `_executionAdapter.ProcessExecution`, and `PortfolioRiskManager.ReportFill` remain intact. Deploy completed with backup `20260826_010153`; `NinjaTrader.Custom.dll`/`.pdb` were invalidated.
--- ---

View File

@@ -13,6 +13,17 @@ Use this file to record durable project decisions that affect implementation pat
## Decision Log ## Decision Log
### DEC-20260826-04
- **ID:** DEC-20260826-04
- **Date:** 2026-08-26
- **Status:** implemented and deployed by operator request
- **Context:** GAP-025 was prompted by `DEC-20260826-03` after reading current `NT8StrategyBase` order/execution handling. The persistent session log could show `SUBMIT` and `FILL`, but not order lifecycle transitions, and `FILL` omitted `execution.Order.Name`, making scaler and runner legs indistinguishable after the fact.
- **Decision:** Add realtime-only `FileLog` output in `OnOrderUpdate()` for SDK-managed order names (`SDK_...`) using `ORDER {signal} State={state} Filled={filled}/{quantity} AvgFillPrice={averageFillPrice}`. Extend the existing `FILL` line in `OnExecutionUpdate()` with `Signal={execution.Order.Name}`. Leave order submission and callback behavior unchanged.
- **Proof:** New source-text tests confirm the `ORDER` line is logged before the Rejected-only branch so non-rejected transitions are covered, the `FILL` line includes the signal name and remains historical-replay gated, and `_circuitBreaker.RecordOrderRejection`, `_executionAdapter.ProcessOrderUpdate`, `_executionAdapter.ProcessExecution`, and `PortfolioRiskManager.ReportFill` remain present with the expected call shapes.
- **Verification:** `dotnet test tests\NT8.Core.Tests\NT8.Core.Tests.csproj --configuration Release --filter "FullyQualifiedName~Adapters" --verbosity minimal` passed 81/81. `verify-build.bat` passed 572/572. Deploy completed with backup `20260826_010153`; `NinjaTrader.Custom.dll`/`.pdb` were invalidated.
- **Related Files:** `TASK_GAP025_RUNNER_ORDER_LIFECYCLE_LOGGING_PROMPT.md`, `src/NT8.Adapters/Strategies/NT8StrategyBase.cs`, `tests/NT8.Core.Tests/Adapters/NT8StrategyBaseOrderLifecycleTests.cs`, `SPRINT_BOARD.md`, `docs/00-governance/current_status.md`.
- **Action Required:** Manual NinjaScript compile after deploy. Next SIM trade with an active runner should show separate `ORDER SDK_..._S_...` and `ORDER SDK_..._R_...` lifecycle lines plus `FILL ... Signal=...` lines.
### DEC-20260826-03 ### DEC-20260826-03
- **ID:** DEC-20260826-03 - **ID:** DEC-20260826-03
- **Date:** 2026-08-26 - **Date:** 2026-08-26

View File

@@ -1285,6 +1285,16 @@ namespace NinjaTrader.NinjaScript.Strategies
if (string.IsNullOrEmpty(order.Name) || !order.Name.StartsWith("SDK_")) if (string.IsNullOrEmpty(order.Name) || !order.Name.StartsWith("SDK_"))
return; return;
if (EnableFileLogging && State == State.Realtime)
{
FileLog(string.Format("ORDER {0} State={1} Filled={2}/{3} AvgFillPrice={4:F2}",
order.Name,
orderState,
filled,
quantity,
averageFillPrice));
}
// Record NT8 rejections in circuit breaker // Record NT8 rejections in circuit breaker
if (orderState == NinjaTrader.Cbi.OrderState.Rejected && _circuitBreaker != null) if (orderState == NinjaTrader.Cbi.OrderState.Rejected && _circuitBreaker != null)
{ {
@@ -1323,11 +1333,12 @@ namespace NinjaTrader.NinjaScript.Strategies
if (State != State.Realtime) if (State != State.Realtime)
return; return;
FileLog(string.Format("FILL {0} {1} @ {2:F2} | OrderId={3}", FileLog(string.Format("FILL {0} {1} @ {2:F2} | OrderId={3} Signal={4}",
execution.MarketPosition, execution.MarketPosition,
execution.Quantity, execution.Quantity,
execution.Price, execution.Price,
execution.OrderId)); execution.OrderId,
execution.Order.Name));
var fill = new NT8.Core.Common.Models.OrderFill( var fill = new NT8.Core.Common.Models.OrderFill(
orderId, orderId,

View File

@@ -0,0 +1,98 @@
using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace NT8.Core.Tests.Adapters
{
[TestClass]
public class NT8StrategyBaseOrderLifecycleTests
{
[TestMethod]
public void OnOrderUpdate_LogsEverySdkOrderTransitionToSessionFile()
{
string source = File.ReadAllText(FindStrategyBaseSourceFile());
string method = ExtractMethodBlock(source, "protected override void OnOrderUpdate");
Assert.IsTrue(method.Contains("!order.Name.StartsWith(\"SDK_\")"), "Order lifecycle logging must stay scoped to SDK-managed signals.");
Assert.IsTrue(method.Contains("if (EnableFileLogging && State == State.Realtime)"), "Order lifecycle logging must be realtime file-log gated.");
Assert.IsTrue(method.Contains("FileLog(string.Format(\"ORDER {0} State={1} Filled={2}/{3} AvgFillPrice={4:F2}\""), "OnOrderUpdate must emit the ORDER lifecycle line.");
int orderLogIndex = method.IndexOf("ORDER {0} State={1}", StringComparison.Ordinal);
int rejectedIndex = method.IndexOf("orderState == NinjaTrader.Cbi.OrderState.Rejected", StringComparison.Ordinal);
Assert.IsTrue(orderLogIndex >= 0 && rejectedIndex >= 0 && orderLogIndex < rejectedIndex, "ORDER logging must occur before the Rejected-only branch so non-rejected transitions are logged too.");
}
[TestMethod]
public void OnExecutionUpdate_FillLineIncludesSignalName()
{
string source = File.ReadAllText(FindStrategyBaseSourceFile());
string method = ExtractMethodBlock(source, "protected override void OnExecutionUpdate");
Assert.IsTrue(method.Contains("FileLog(string.Format(\"FILL {0} {1} @ {2:F2} | OrderId={3} Signal={4}\""), "FILL line must include the order signal name.");
Assert.IsTrue(method.Contains("execution.Order.Name));"), "FILL line must populate Signal from execution.Order.Name.");
Assert.IsTrue(method.Contains("if (State != State.Realtime)"), "FILL line must remain historical-replay gated.");
}
[TestMethod]
public void OrderLifecycleLogging_KeepsExistingCallbacksUnchanged()
{
string source = File.ReadAllText(FindStrategyBaseSourceFile());
string orderMethod = ExtractMethodBlock(source, "protected override void OnOrderUpdate");
string executionMethod = ExtractMethodBlock(source, "protected override void OnExecutionUpdate");
Assert.IsTrue(orderMethod.Contains("_circuitBreaker.RecordOrderRejection(reason);"), "Rejected-specific circuit breaker behavior must remain present.");
Assert.IsTrue(orderMethod.Contains("_executionAdapter.ProcessOrderUpdate("), "Order adapter update callback must remain present.");
Assert.IsTrue(orderMethod.Contains("order.OrderId,"), "ProcessOrderUpdate must still receive order.OrderId.");
Assert.IsTrue(orderMethod.Contains("order.Name,"), "ProcessOrderUpdate must still receive order.Name.");
Assert.IsTrue(orderMethod.Contains("orderState.ToString(),"), "ProcessOrderUpdate must still receive orderState.ToString().");
Assert.IsTrue(orderMethod.Contains("filled,"), "ProcessOrderUpdate must still receive filled quantity.");
Assert.IsTrue(orderMethod.Contains("averageFillPrice,"), "ProcessOrderUpdate must still receive average fill price.");
Assert.IsTrue(orderMethod.Contains("(int)errorCode,"), "ProcessOrderUpdate must still receive error code.");
Assert.IsTrue(orderMethod.Contains("nativeError);"), "ProcessOrderUpdate must still receive native error.");
Assert.IsTrue(executionMethod.Contains("PortfolioRiskManager.Instance.ReportFill(Name, fill);"), "Portfolio risk fill reporting must remain present.");
Assert.IsTrue(executionMethod.Contains("_executionAdapter.ProcessExecution(orderId, executionId, price, quantity, time);"), "Execution adapter callback must remain unchanged.");
}
private static string FindStrategyBaseSourceFile()
{
DirectoryInfo dir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
while (dir != null)
{
string candidate = Path.Combine(dir.FullName, "src", "NT8.Adapters", "Strategies", "NT8StrategyBase.cs");
if (File.Exists(candidate))
return candidate;
dir = dir.Parent;
}
throw new FileNotFoundException("Could not locate src\\NT8.Adapters\\Strategies\\NT8StrategyBase.cs from test output directory.");
}
private static string ExtractMethodBlock(string source, string signature)
{
int start = source.IndexOf(signature, StringComparison.Ordinal);
if (start < 0)
Assert.Fail("Source does not contain method: " + signature);
int brace = source.IndexOf("{", start, StringComparison.Ordinal);
if (brace < 0)
Assert.Fail("Method has no opening brace: " + signature);
int depth = 0;
for (int i = brace; i < source.Length; i++)
{
if (source[i] == '{')
depth++;
else if (source[i] == '}')
{
depth--;
if (depth == 0)
return source.Substring(start, i - start + 1);
}
}
Assert.Fail("Method has no closing brace: " + signature);
return string.Empty;
}
}
}