Data-Trust Foundation — Spec
Before any "me vs strategies" scoring: every graded fact must be provenanced, reconciled against an independent witness, drillable to evidence, and
fail-loud. Goal = zero
silent errors.
← J3P hub ·
the provenance/drill model →
Headline: Grades ride on aggregated round-trips with silent P&L fallbacks and no fill spine; build reconciliation and versioning FIRST, then grade.
Principle — ZERO SILENT ERRORS. Every graded number must be (1) PROVENANCED — it names the exact rule version (strategy_id + strategy_version + content_hash) and the source rows it came from; (2) RECONCILED against an independent witness — realized P&L ties to kti positions GrossPNL to the penny, every fill sits inside its karb 1-min bar; (3) DRILLABLE — grade → fill → signal → the exact bars, the way j3p-replay already does for charts; and (4) FAIL-LOUD — a trust gate failure DETECTS → FLAGS → QUARANTINES (excluded from every rollup, never averaged in) → SURFACES visibly. A grade you cannot back with evidence is worse than no grade. Single source of truth per concept; the registry JSON authors rules, everything else is generated and reconciled against it; HUD stays read-only, quarantine is a data-layer flag.
🧪 The good news — the trust primitives already exist: the single-source-of-truth contract, the order-log↔GrossPNL reconcile pattern (gen_replay), and the verified provenance+drill+no-lookahead replay model. They're just not wired into grading yet.
🕹️ HUD is READ-ONLY — this spec builds the trust layer around the scorecard/registry on a2; nothing edits the live Accountability HUD or the Pine.
The 4 biggest data-trust risks right now (verified against live a2 code)
1. The grade James sees is OUTCOME-ONLY and rides on a silent price-based P&L fallback. compute_overall_grade() scores purely from win_rate + profit_factor + net_pnl sign — zero plan-obeyed content — and normalize_trade() (gen_scorecard.py:226-230) silently recomputes pnl=(exit-entry)*shares when EntryPNL is 0: no commission, no flag, averaged straight into the grade. The authentic pure-evaluator path (evaluate.py + live_trade_evaluations) is built and tested but UN-DEPLOYED — the table does not exist (to_regclass returns NULL) and live_eval_orchestrator.py is fully stubbed.
Two grade spines exist: the intended process-graded one (dark) and the outcome-only one (live). The live one credits luck, not discipline — the exact anti-pattern the contract forbids — and can be silently wrong by exactly the commission it drops.
Fix: Apply live_trade_evaluations.sql to trsports_tradingjournal_dev; wire live_eval_orchestrator.py to real fetch fns + write path; kill the pnl==0 → price-estimate fallback (if P&L can't be sourced with commission, the trade is incomplete → quarantine, never estimate); demote compute_overall_grade to a P&L stat and make evaluate() the grade of record with a process term.
2. No penny reconcile against the firm feed anywhere, and no fill spine feeds grades. The graded surface uses aggregated `kti trades date` round-trips (never sees ExecType/partial fills), so the two hard-won order-log traps — partial-fill drop and UTC-mislabeled-as-local +4h TransactTime — are UNDEFENDED on the surface that produces grades. gen_replay.py's 'reconciles with the firm P&L feed' (line 527) is a hardcoded NOTE string, not a computed check.
Realized P&L behind a grade is never independently verified against kti positions GrossPNL, and fill provenance (the correct ExecType/UTC parse) lives ONLY in the standalone replay HTML generator that nothing writes back. Grade and fill-truth are two disconnected worlds.
Fix: Port gen_replay's load_fills / validate_fills_vs_bars / GrossPNL tie UP into the graded pipeline as a HARD GATE (not a note): before any grade is written, net realized P&L must equal kti positions GrossPNL to the penny AND every fill price must sit inside [bar low-0.10, bar high+0.10]; on failure quarantine the trade. Single-source the order-log parse in vcet-replay-viewer — do NOT fork a second fill parser.
3. No signal pins the rule version that graded it, and multiple classifiers disagree on the same signal. indicator_alerts carries only free-text `strategy` — no strategy_id/strategy_version/content_hash — so the scorecard re-classifies LIVE each run and silently re-grades a 3-month-old trade against today's rules. Meanwhile gen_scorecard uses regime_classifier.classify_entry, audit_trades uses classify_v2, and the HUD modal uses band-blind strategies-fuzzy.js: the same signal can grade to different strategy_ids on three surfaces.
Without a pinned (strategy_id, strategy_version, content_hash) frozen at classification time, grades are not reproducible and not point-in-time honest; classifier divergence means the strategy behind a grade is ambiguous — a silent divergence on the graded fact itself.
Fix: Collapse to ONE classifier (classify_v2.py loading the registry, not inline constants) used live AND batch. Add strategy_id/strategy_version/strategy_content_hash/classified_by to indicator_alerts + sidecar main.trade_classification; add per-entry strategy_version + content_hash to strategies.json with a generator that REFUSES to publish when the rule-bearing hash changed without a version bump; stamp the version FROM the loaded def at classification time so later registry edits can't retro-change it.
4. No nightly drift/reconcile job and no quarantine state — suspect data degrades grades silently. Nothing checks scorecard P&L == monthly aggregate, alerts-non-empty-per-day, or identity-mapping resolution; there's no commission source flag (actual vs estimated_rolling) on trade_context, so a stale estimate grades identically to an actual — the exact month-long silent-estimate incident already caught once. evaluate() has OFF-BOOK but no reconciliation-failure/QUARANTINE state, so a suspect trade is averaged into win_rate/profit_factor today.
Silent zeros (dead commission actuals, empty alerts day, drift between daily and monthly) produce an estimate-based grade with no alarm, and one un-provable trade can inflate or deflate the day.
Fix: Add a QUARANTINE/SUSPECT grade state (reasons: pnl_mismatch, fill_outside_bar, unknown_strategy_id, schema_skew, classifier_divergence, no_signal/no_fill, lookahead) EXCLUDED from every rollup and rendered de-emphasized with a 'NO GRADE — evidence incomplete' chip; add a commission source flag so estimated can never masquerade as actual (T+1 guard); stand up a nightly drift detector (scan_strategy_drift.py pattern) that alerts on P&L-vs-monthly drift, missing alerts, unresolved mappings, and a rising quarantine rate.
Per-fact-type trust spec
Each: canonical source · reconciliation (independent witness + tolerance + status) · drill-path · fail-loud behavior · gaps · where it lives.
FILLS — execution truth (individual fills → round-trips → per-trade realized P&L that grades are built on)
Canonical source (single spine)
SPINE AS-BUILT vs AS-SPECIFIED — the two diverge, and that gap is the whole problem.
AS-SPECIFIED (SIP/system contract): fills come from `kti order log` FULL (ExecType IN {1,2}, LastShares>0), UTC→ET at ingest, land in main.journal as the single per-trade spine; realized P&L reconciles to kti portfolio positions GrossPNL to the penny.
AS-BUILT (verified live 2026-07-02, ssh a2):
1. GRADE SPINE = `kti trades date --account --date --json` (InfoCenter/Gr8Trade pre-AGGREGATED round-trips), fetched in gen_scorecard.py fetch_trades() (/home/trsports/setup_daily_reporting/reports/gen_scorecard.py:~163). This feed never exposes ExecType or partial fills — aggregation already happened upstream, so the two silent order-log traps (partial-fill drop, UTC mislabel) are invisible here, not defended. normalize_trade() (line 200-250) reads pnl from EntryPNL/realizedPnl/net_pnl and, if that is 0, SILENTLY recomputes pnl=(exit-entry)*shares (line 226-230) — a price-based estimate with no commission, no flag, averaged straight into the grade. Timestamps convert UTC→ET with a hardcoded -4h (line 235), DST-naive.
2. GRADE DB BASIS = main.trade_context.net_pnl (gen_scorecard reads FROM main.trade_context for strategy/regime/aggregate P&L; verified fresh through 2026-07-01, computed_at 20:46 UTC nightly, 100% net_pnl coverage last 30d). trade_context has commissions/fees columns but NO source flag (actual vs estimated_rolling) and no GrossPNL reconcile column. No writer for main.trade_context was found under /home/trsports — it is populated by the HOME/Windows nightly pipeline, so the fill→context hop is off-server and unverified from a2.
3. FILL-LEVEL TRUTH (the real order-log parse) exists ONLY in the standalone replay generator /home/trsports/trading/dev/vcet-replay-viewer/gen_replay.py (load_fills, line 255): correctly filters ExecType IN {1,2} & LastShares>0, and correctly derives ET from TransactTimeUTC (documents the +4h mislabel bug, verified 36/37 fall outside bar as-ET vs 0/37 as-UTC). But this output is a review HTML page — it is NEVER written back to main.journal / main.trade_context, so the grade and the fill-truth are two disconnected worlds.
CONCLUSION: there is no single fill spine feeding grades. The grade rides on aggregated kti trades + trade_context; the authentic fill provenance lives only in a viewer that nothing reconciles against.
Drill-path (grade → evidence)
TARGET (replay-style, EXISTS only in gen_replay.py; must be ported to the graded surface):
grade → trade (round-trip) → its fills → the exact 1-min bars.
As built in /system/j3p-replay/*.html and vcet-replay-viewer: PROVENANCE BOX tags each layer REAL (candles/VWAP/±σ from real karb 1-min→2-min OHLC4) vs COMPUTED vs MODEL (plan levels); NO-LOOKAHEAD verified (post-entry only, MFE never an exit); band math independently RECOMPUTES to 5e-5 (adversarial HLC3 diverges 0.37 → proves OHLC4); click-a-signal DRILLS to entry/stop/target + the exact bars; fills_check {n, outside_bar_range, no_bar} published in-page.
ACTUAL on the GRADED surface (gen_scorecard): drill BOTTOMS OUT at the aggregated round-trip. There is no fill list, no ExecType, no fill-in-bar marker, no GrossPNL tie-out — you cannot click a grade and land on the individual fills that produced it. The replay drill and the grade are not linked: same trade, two surfaces, no shared fill record.
SIGNAL side of the drill (entry→signal→bars) is wired: main.trade_context / alerts_tradingview.indicator_alerts (ENTRY/EXIT, testing=false, isdeleted=false) carry vwap/bands/regime/strategy, receiver /home/trsports/trading/dev/a1p_journal/src/php/webhooks/tradingview_smb_indicator_trigger.php. Fill→signal join is by symbol+time only (no fill-id FK), so it inherits the DST-naive -4h clock risk on the trades side.
| Reconciliation check | Independent witness | Tolerance | Status |
|---|
| Realized P&L parsed from fills == firm feed GrossPNL, to the penny | kti portfolio positions GrossPNL (firm P&L feed) vs order-log position_trace realized | $0.00 (penny) | PLANNED |
| Every fill price within its 1-min karb bar [low-0.10, high+0.10] | karb price server 1-min bars vs order-log LastPx | ±$0.10 on bar low/high | PARTIAL |
| Partial fills retained (ExecType 1 not dropped) so net position closes flat | order-log ExecType {1,2} full log vs eod_pos==0 flat-to-flat check | eod_pos == 0 for closed campaigns | PARTIAL |
| TransactTime interpreted as UTC (not local) so fills fall inside their bar | as-UTC vs as-ET placement against 1-min bar ranges | 0 fills outside range when UTC | EXISTS |
| Grade P&L (scorecard) == fill-derived realized P&L for the same trade | gen_replay order-log realized vs gen_scorecard kti-trades EntryPNL / trade_context.net_pnl | $0.00 (penny) | PLANNED |
| Commission on each trade is ACTUAL, not estimated_rolling, before grading | broker actuals (commission cascade 5/10/30/60d) vs trade_context.commissions | source='actual' required; T+1 guard | PLANNED |
| Scorecard daily/period P&L == monthly aggregate (nightly drift detection) | per-day scorecard sum vs monthly rollup / kti trades period total | $0.00 | PLANNED |
Fail-loud behavior (detect → flag → quarantine → surface)
CURRENT (as-built) = mostly SILENT, which violates the contract:
- gen_replay.py validate_fills_vs_bars() DETECTS out-of-bar and no-bar fills but only PUBLISHES the count into page provenance — it does NOT abort the write, does NOT quarantine, does NOT block the narrative. The memory's 'if either check fails, DO NOT write the narrative' rule is documented in load_fills' docstring but NOT enforced as a gate.
- gen_replay never actually loads kti positions GrossPNL; the string 'reconciles with the firm P&L feed' (line 527) is a hardcoded NOTE, not a computed penny-check. Silent.
- gen_scorecard.normalize_trade() pnl==0 → recompute-from-price fallback is fully silent: no flag, no source tag, estimate averaged into the grade.
- No commission source flag (actual vs estimated_rolling) surfaces in trade_context, so a stale/estimated commission grades identically to an actual one (the exact month-long silent-estimate failure already caught once).
- No nightly drift job runs (none found in /home/trsports/setup_daily_reporting).
TARGET (fail-LOUD, to build): detect (fill outside bar OR realized≠GrossPNL to the penny OR partial-fill count anomaly OR commission source≠'actual' under T+1) → FLAG the trade with a machine-readable reason → QUARANTINE it out of the graded aggregate (never averaged in) → SURFACE it visibly on the scorecard + nightly drift report. Suspect data must change the grade's completeness, never silently degrade its number.
Current gaps
- HIGH Grade spine uses aggregated `kti trades date`, not `kti order log` — the graded surface never sees ExecType/partial fills, so the two hard-won order-log traps are undefended on the surface that actually produces grades.gen_scorecard.py fetch_trades() cmd = ['kti','trades','date',...]; no ExecType/LastShares handling anywhere in the file.
- HIGH No penny reconcile against kti positions GrossPNL is executed anywhere. The replay's 'reconciles with firm P&L feed' is a hardcoded note string, not a check.gen_replay.py:527 note literal; grep for GrossPNL/positions/portfolio in gen_replay returns only that note; validate call at line 706 checks bars only.
- HIGH Fill-in-bar validation does not gate the write — out-of-bar fills are counted and published but the narrative still ships. Contract's 'DO NOT write on failure' unenforced.validate_fills_vs_bars returns counts (line 296-309); line 706-707 stores fills_check but no sys.exit/raise/quarantine follows.
- HIGH Silent price-based P&L fallback in the scorecard: pnl==0 → (exit-entry)*shares, no commission, no flag, averaged into the grade.gen_scorecard.py:226-230.
- HIGH No commission source flag (actual vs estimated_rolling) on the graded record; trade_context has commissions/fees but no source column, so an estimated commission grades identically to an actual — the exact class of the month-long silent-estimate incident.information_schema: main.trade_context has commissions,fees but no source/actual/estimated column.
- HIGH Fill-level truth is never persisted — order-log parse lives only in the standalone replay HTML generator, disconnected from main.journal/trade_context; grade and fill-truth are two worlds that nothing reconciles.load_fills output → HTML payload only; no writer for main.trade_context found under /home/trsports; trade_context populated off-server (HOME nightly).
- MED No nightly drift-detection job (scorecard P&L == monthly aggregate; fills vs GrossPNL) exists in the reporting pipeline despite being in the contract.grep drift/reconcile/GrossPNL over /home/trsports/setup_daily_reporting + scorecard_pipeline returns only python-lib false positives.
- MED DST-naive UTC→ET conversions on the graded side: hardcoded -4h in both normalize_trade time-format and _fmt_time, will be one hour off outside EDT and push fills out of their bar during EST.gen_scorecard.py:235 and _fmt_time 'et = dt - timedelta(hours=4)'.
- MED Fill→signal join is symbol+time only (no fill-id FK), so any clock skew mis-attributes a fill to the wrong bar/signal silently.indicator_alerts join in gen_scorecard by symbol/time; no fill identifier column in trade_context.
Lives where: SERVER: a2 (ssh a2), DB trsports_tradingjournal_dev @127.0.0.1:5432 (user trsports_trader), schema main.
GRADE SPINE / P&L: /home/trsports/setup_daily_reporting/reports/gen_scorecard.py (fetch_trades via `kti trades date`; normalize_trade P&L + silent fallback), + scorecard_enrichments.py, trader_state.py, classify_v2.py (grade classification). DB: main.trade_context (net_pnl, commissions, fees, computed_at — the graded aggregate the scorecard reads); per-trade journal spine main.journal (entry/exit/commissions/net_profit) and main.closed_trades (has entry_fill_time/exit_fill_time, commissions, fees). Self-grade: main.daily_report_cards.
FILL-LEVEL TRUTH (the model to reuse, do NOT rebuild): /home/trsports/trading/dev/vcet-replay-viewer/gen_replay.py (load_fills / validate_fills_vs_bars / position_trace / segment_campaigns) → pages /home/trsports/trsports_gd/html/system/j3p-replay/*.html and *_VCET_VISUAL_REPLAY.html. This is where ExecType filtering, UTC→ET fix, and fill-in-bar honesty-check already live correctly — port its penny-reconcile + fill-in-bar GATE up into the graded pipeline rather than duplicating.
SIGNALS: alerts_tradingview.indicator_alerts (DB), receiver /home/trsports/trading/dev/a1p_journal/src/php/webhooks/tradingview_smb_indicator_trigger.php. Strategy defs: /home/trsports/trsports_gd/html/system/strategies.json (+ strategy-schema-v1.md).
OFF-SERVER (unverified from a2, owns the fill→trade_context hop + commission cascade): HOME/Windows nightly pipeline writes main.trade_context; commission actual-vs-estimated cascade (5/10/30/60d, T+1 guard, source='actual'|'estimated_rolling') lives in the HUD/commission pipeline, NOT surfaced into trade_context. One system: keep the order-log parse single-sourced in vcet-replay-viewer and reconcile trade_context.net_pnl against it — do not fork a second fill parser.
SIGNALS — what the strategy said (the intended play), vs. what actually happened. A signal = the TradingView webhook event in alerts_tradingview.indicator_alerts (ENTRY/EXIT, with vwap + vwap_upper/lower_1..3 + band_spread + market_regime + strategy + indicator) JOINED to the pinned, versioned strategy definition in /system/strategies.json. A signal is only trustworthy when it is REPRODUCIBLE: the same bands recompute from real karb bars (OHLC4 VWAP/±σ), and ONE classifier — not band-blind fuzzy vs classify_v2 — maps it to a strategy_id.
Canonical source (single spine)
alerts_tradingview.indicator_alerts (Postgres, alerts_tradingview schema) is the single spine for the SIGNAL EVENT, filtered event_type IN (ENTRY,EXIT) AND testing=false AND isdeleted=false. It is written by exactly ONE receiver: /home/trsports/trading/a1p_journal/src/php/webhooks/tradingview_smb_indicator_trigger.php (INSERT at line 450 targets alerts_tradingview.indicator_alerts — NOTE the file's header docstring still says 'fashionably_late_trades', which is stale/misleading but the actual INSERT is correct). The signal's MEANING (entry/stop/target rules, gating, version) lives in the versioned strategy def at /home/trsports/trsports_gd/html/system/strategies.json (schema_version 2, strategy_count 9, doc /system/strategy-schema-v1.md). There is NO playbook_type column on indicator_alerts — playbook is computed live by classify_entry(). Spine = the alert row; authority for what it MEANS = the pinned strategies.json version.
Drill-path (grade → evidence)
grade -> fill -> signal -> bars, replay-style, modeled on /system/j3p-replay/AMZN_2026-07-01.html (generator /home/trsports/trading/dev/vcet-replay-viewer/gen_replay.py). (1) GRADE: scorecard card cites a strategy_id + P&L. (2) FILL: click through to the reconstructed position from the FULL order log (ExecType {1,2}, LastShares>0), whose net P&L ties to firm GrossPNL. (3) SIGNAL: the indicator_alerts ENTRY/EXIT row that named the play, plus the pinned strategies.json version whose entry/stop/target rules were evaluated. (4) BARS: the exact real karb 1-min->2-min bars, with a PROVENANCE BOX tagging each layer REAL (candles/VWAP/±σ from OHLC4 on real bars, 2-day VWAP, CBO) vs COMPUTED vs MODEL (plan levels), band math independently RECOMPUTING to 5e-5 (HLC3 diverges 0.37 as proof of OHLC4), and NO-LOOKAHEAD verified. This full drill exists for the J3P replay pages; it is NOT yet wired as the click-through from the scorecard grade itself.
| Reconciliation check | Independent witness | Tolerance | Status |
|---|
| Band geometry is real, not asserted: recompute VWAP and ±0.5/1/2/4 SD bands from real karb 1-min bars using OHLC4 and compare to the vwap/vwap_upper_lower_1..3 values carried on the indicator_alert. | kti price (karb 1-min bars) recomputed independently; adversarial HLC3 must DIVERGE to prove OHLC4 is the true source basis. | OHLC4 recompute agrees to 5e-5; adversarial HLC3 diverges ~0.37 (divergence is the proof). | PARTIAL |
| No-lookahead: every signal-derived exit/target uses only bars at-or-after entry; MFE is never used as an exit. | Bar timeline vs entry timestamp in the replay generator. | Post-entry bars only; zero pre-entry leakage. | EXISTS |
| Fills land inside their bar and net P&L ties to the firm feed (guards the two silent order-log traps). | kti portfolio positions GrossPNL (firm P&L feed) AND the karb 1-min bar the fill falls in. | Net pos + realized P&L match GrossPNL to the penny; each fill price within [bar low-0.10, bar high+0.10]; use FULL order log filtered ExecType IN {1,2} & LastShares>0 (never --exec-type fill, which DROPS partials); TransactTime is UTC-mislabeled-as-local (+4h) — correct before binning. | PARTIAL |
| ONE classifier: the strategy_id shown on a grade must match across every surface (scorecard, HUD modal, audit). | classify_v2.py (schema-driven, single strategy_id) vs the band-blind strategies-fuzzy.js the HUD modal uses vs regime_classifier.classify_entry() the scorecard uses. | Exact strategy_id equality across all three; any disagreement = quarantine. | PLANNED |
| strategy_id refs resolve: every signal's strategy_id exists in strategies.json at a pinned version; refuse publish on unknown id. | strategies.json registry (schema_version must == SCHEMA_VERSION_REQUIRED in evaluate.py). | 100% of referenced ids resolve; schema_version match exact. | PARTIAL |
| Nightly drift: alerts non-empty per trading day; identity mapping resolves; scorecard P&L == monthly aggregate; row counts stable. | main.journal trade rows, the identity fn (account_id->user_id->trader_name), and the monthly dashboard aggregate. | Alerts >0 per RTH day; P&L equals monthly aggregate to the penny; 100% mapping resolution. | PLANNED |
Fail-loud behavior (detect → flag → quarantine → surface)
DETECT -> FLAG -> QUARANTINE -> SURFACE, never average a suspect signal into a grade. gen_replay establishes the intended discipline: it filters the FULL order log for partial fills and computes P&L 'that reconciles with the firm P&L feed'; the design rule is that if net-pos/realized-P&L do not match GrossPNL to the penny OR any fill falls outside its bar, the parse is WRONG and the narrative is NOT written. Band recompute divergence beyond 5e-5 means the stored bands are not OHLC4 and the signal is not reproducible -> hold. Classifier disagreement (fuzzy vs classify_v2 vs classify_entry) on the same signal -> the strategy_id is ambiguous -> do not grade, surface the conflict. Every generator is required to be idempotent + declare provenance + refuse publish on an unknown strategy_id. GAP TO CLOSE: in the code as read, gen_replay's P&L tie is emitted as a NOTE on the scenario rather than a hard raise/abort gate, and gen_scorecard.py has NO drift/reconcile/quarantine step and emits NO provenance footer — so today a suspect signal can still reach a grade silently. HUD stays READ-ONLY (edits hook-blocked); quarantine is a data-layer flag, never a HUD edit.
Current gaps
- HIGH ONE classifier not enforced. gen_scorecard.py imports classify_entry from regime_classifier (and also runs a separate in-file heuristic classify_trade), NOT classify_v2.py. classify_v2 is imported ONLY by audit_trades.py (a cutover-comparison harness whose own header says 'validate the cutover BEFORE wiring classify_v2.py into gen_scorecard.py'). The HUD modal uses band-blind strategies-fuzzy.js. So the same signal can grade to different strategy_ids on scorecard vs HUD vs audit — a silent divergence directly on the graded fact.gen_scorecard.py:28 'from regime_classifier import classify_entry'; classify_v2 imported only in audit_trades.py:51; strategies-fuzzy.js present in hud/js/ and cockpit/js/.
- HIGH Live evaluator is a STUB — 'same evaluator live+batch' is not real. live_eval_orchestrator.py docstring: 'STATUS: Stub ... Wiring to psycopg + the actual DB is the next concrete task once the DDL at live_trade_evaluations.sql has been applied.' The pure evaluate.py exists (writes to main.live_trade_evaluations), but nothing populates the table live. No append-only in-flight signal evaluation reaches a grade today.live_eval_orchestrator.py header 'STATUS: Stub'; depends on un-applied DDL and a queued strategy_id column on indicator_alerts + main.journal.
- MED No provenance footer on the scorecard. gen_scorecard.py / scorecard_enrichments.py emit no generated_at / generator_version / source_tables / row_counts. The contract requires every generator to declare provenance; without it a grade cannot be drilled back to its exact inputs.grep for provenance/generated_at/source_tables/row_counts in gen_scorecard.py returned nothing.
- HIGH No runtime reconcile/drift gate in the scorecard pipeline. The only 'drift' matches in gen_scorecard.py are code COMMENTS about past slug renames (backside->backside-scalp, vwap-pullin->vwap-pull-in); there is no penny-level scorecard-P&L-vs-monthly-aggregate check, no alerts-non-empty-per-day check, no mapping-resolution check running nightly. No cron entry for gen_scorecard/audit_trades/drift was found.gen_scorecard.py drift hits are all comments (lines 131,132,445,459,473,1519); crontab/*.sh grep for scorecard|audit|drift returned nothing.
- MED Band-recompute-to-5e-5 gate not enforced at signal ingest or at grade time. scorecard_enrichments.py pulls real bars (kti price query five_min) but does not independently recompute OHLC4 VWAP/±σ and compare to the vwap_upper/lower_1..3 stored on the alert, so a mis-sourced (HLC3 or stale) band on an indicator_alert would not be caught before it feeds a grade.scorecard_enrichments.py only reference is the kti price query call at line 171; no recompute/compare logic.
- MED gen_replay P&L reconcile is a soft NOTE, not a hard fail-loud abort. The 'reconciles with the firm P&L feed' text is emitted as a scenario note; no raise/sys.exit gate was found that blocks page generation on a penny mismatch or an out-of-bar fill. The discipline is documented but not machine-enforced in the code read.gen_replay.py:527 note text 'reconciles with the firm P&L feed'; grep for raise/sys.exit/mismatch found only arithmetic abs()/state logic, no reconcile-abort.
- LOW Webhook receiver header docstring is stale ('fashionably_late_trigger.php ... Inserts into alerts_tradingview.fashionably_late_trades') while the real INSERT (line 450) targets indicator_alerts. Cosmetic but a provenance-trust hazard: a reader auditing where signals land could believe the wrong table.docstring lines 3-8 say fashionably_late_trades; INSERT at line 450 targets alerts_tradingview.indicator_alerts.
Lives where: All on the a2 server (ssh a2), ONE system, no duplication: SIGNAL SPINE (table) = Postgres alerts_tradingview.indicator_alerts. RECEIVER (only writer) = /home/trsports/trading/a1p_journal/src/php/webhooks/tradingview_smb_indicator_trigger.php (dev mirror under trading/dev/a1p_journal/...). STRATEGY DEFS (versioned meaning) = /home/trsports/trsports_gd/html/system/strategies.json + /home/trsports/trsports_gd/html/system/strategy-schema-v1.md (web-served as /system/strategies.json). CLASSIFIERS (must collapse to one) = /home/trsports/setup_daily_reporting/reports/classify_v2.py (schema-driven, target of record) vs regime_classifier.py::classify_entry (what gen_scorecard actually calls today) vs hud/js/strategies-fuzzy.js (HUD modal). GRADE GENERATORS = /home/trsports/setup_daily_reporting/reports/gen_scorecard.py + scorecard_enrichments.py + trader_state.py. PURE EVALUATOR (rules-engine, separate from UI) = /home/trsports/setup_daily_reporting/reports/evaluate.py -> writes main.live_trade_evaluations (append-only). LIVE ORCHESTRATOR (stub) = /home/trsports/setup_daily_reporting/reports/live_eval_orchestrator.py (needs live_trade_evaluations.sql DDL applied + strategy_id column on indicator_alerts & main.journal). PROVENANCE+DRILL MODEL TO REUSE = /home/trsports/trading/dev/vcet-replay-viewer/gen_replay.py -> /home/trsports/trsports_gd/html/system/j3p-replay/{AMZN,EBAY,NVDA}_2026-07-01.html. CLASSIFIER-DIVERGENCE HARNESS = /home/trsports/setup_daily_reporting/reports/audit_trades.py (the one place all classifiers are compared side-by-side). HUD is READ-ONLY (edits hook-blocked) — quarantine lives in the data layer, never as a HUD edit.
GRADES
Canonical source (single spine)
main.live_trade_evaluations (append-only eval log) is the DESIGNED single spine for grades — one row per (trade_id, evaluated_at_et), written ONLY by the pure evaluate(strategy_def, trade_state, market_context)->eval_record function via its orchestrator, carrying grade, quality_score_raw/normalized, rules_satisfied/failed, invalidation, recommended_action, evaluator_version, schema_version, plus trade_state_snapshot + market_context_snapshot JSONB for self-contained replay. VERIFIED STATE 2026-07-02: this table is NOT the live spine yet — it does NOT exist in trsports_tradingjournal_dev (to_regclass('main.live_trade_evaluations') returns NULL). Today the ACTUAL grade shown to James comes from gen_scorecard.py::compute_overall_grade(stats), which scores purely from win_rate + profit_factor + net_pnl sign (OUTCOME-only, zero plan-obeyed content). So there are currently TWO spines: the intended pure-fn one (built, tested, un-deployed) and the outcome-only scorecard one (live). The contract's single-source-of-truth rule is satisfied by DESIGN but VIOLATED in production until the evaluator path is wired and the outcome-only grade is retired or demoted to a P&L stat.
Drill-path (grade → evidence)
Reuse the J3P replay model (/system/j3p-replay/AMZN_2026-07-01.html — EXISTS: REAL/COMPUTED/MODEL provenance box + client recompute() re-deriving bands to 5e-5). Grade drill chain: (1) GRADE badge -> click opens the eval row; (2) EVAL ROW shows rules_satisfied[]/rules_failed[]/invalidation + quality_score breakdown, each rule tagged REAL (fill/price) / COMPUTED (band, mae_r, mfe_r) / MODEL (plan level: chosen_stop_id/target) with live recompute proving band math; (3) each rule DRILLS to the exact FILL(s) it used — price, ExecType, LastShares — from the FULL order log; (4) each fill DRILLS to its 1-min karb BAR with the [low-0.10, high+0.10] envelope drawn so the fill visibly sits inside its bar (NO-LOOKAHEAD: post-entry bars only, MFE never an exit); (5) each band/regime input DRILLS to its indicator_alerts source row (vwap, vwap_upper/lower_1..3, band_slope, market_regime) recomputed from kti OHLC4. Self-contained because trade_state_snapshot + market_context_snapshot JSONB live ON the eval row. STATUS: the J3P signal-drill exists; the GRADE->eval->fill->bar wiring is NOT built (no eval rows to link yet).
| Reconciliation check | Independent witness | Tolerance | Status |
|---|
| Grade inputs are trustworthy fills: the trade_state feeding evaluate() (entry/exit/size/mae_r/mfe_r) must derive from FULL order log filtered ExecType IN {1,2} & LastShares>0 (never --exec-type fill, which drops partials), and net position + realized P&L must match kti portfolio positions GrossPNL to the penny before any grade is written | kti portfolio positions GrossPNL (independent of the journal/order-log parse) — same pattern gen_replay.py already enforces for J3P | to the penny ($0.00 on net realized P&L); on failure DO NOT grade | PLANNED |
| Every fill price used to compute mae_r/mfe_r/entry lies inside its own 1-min karb bar [low-0.10, high+0.10] (guards the UTC-mislabeled-as-local +4h TransactTime trap that drops fills outside their bar) | kti price minute (karb 1-min OHLC) — independent of the order log | fill within [bar_low-0.10, bar_high+0.10]; any fill outside quarantines the trade's grade | PLANNED |
| Grade is reproducible: re-running evaluate() on the row's stored trade_state_snapshot + market_context_snapshot + the schema_version'd registry yields the identical grade (deterministic pure fn, no lookahead) | evaluate.py replayed against strategies.json at the row's schema_version (self-contained JSONB snapshot is the independent witness) | exact match on grade + quality_score_normalized (rounded 4dp); mismatch = evaluator/registry skew, flag | PARTIAL |
| Band/±σ market_context that drives band-relative rules independently recomputes from real kti 1-min->2-min OHLC4 (adversarial HLC3 must diverge), same guarantee as the J3P replay provenance box | kti 1-min bars recomputed to OHLC4 VWAP/bands, cross-checked vs indicator_alerts vwap/vwap_upper/lower_1..3 | 5e-5 vs OHLC4; HLC3 must diverge ~0.37 (proves the source formula) | EXISTS |
| Same signal grades identically across surfaces: the strategy classification feeding the grade must use ONE classifier, not band-blind fuzzy on the HUD and a different one in batch | classify_v2.classify(features) as the single reference vs whatever the scorecard/HUD actually call | identical playbook/strategy_id for identical (band, regime, extension) features | PARTIAL |
| schema_version on each eval row equals /system/strategies.json meta.schema_version at eval time, and strategy_id resolves to a known registry id (refuse publish on unknown id) | strategies.json meta.schema_version (currently 2) + registry id set (9 strategies) | exact integer match; unknown strategy_id => skip+flag, never grade | PARTIAL |
| Scorecard aggregate sanity: published grade-set P&L == monthly aggregate, mapping account_id->user_id->trader_name resolves, alerts non-empty per trading day | monthly P&L aggregate + identity function + indicator_alerts daily presence (contract's nightly drift checks) | P&L equal to the penny; every mapping resolves; alerts>0 per RTH day | PLANNED |
Fail-loud behavior (detect → flag → quarantine → surface)
FAIL-LOUD, never averaged. DETECT: before writing any grade, the orchestrator runs the reconciliation gates (GrossPNL-to-penny vs kti positions, fill-inside-karb-bar, schema_version + strategy_id resolve, classifier agreement, no-lookahead). FLAG: on ANY gate failure the eval is stamped with an explicit quarantine reason (pnl_mismatch, fill_outside_bar, unknown_strategy_id, schema_skew, classifier_divergence) — never silently downgraded. QUARANTINE: the grade is written as a distinct non-letter state (extend evaluate()'s OFF-BOOK with a QUARANTINE/SUSPECT state) and EXCLUDED from every rollup — not averaged into symbol/playbook/overall grades, not counted in the win_rate/profit_factor that feed compute_overall_grade. SURFACE: quarantined trades render in a loud live-emphasis panel with a drill link to the failing gate + the exact evidence bar; the nightly drift detector (scan_strategy_drift.py pattern) emits row-count/mapping/alerts-per-day/P&L-vs-monthly-aggregate so a silent zero (dead commission actuals, empty alerts day) trips an alarm instead of quietly producing an estimate-based grade. Inherited hard rule from the commission trap: a grade built on estimated/rolling inputs carries source='estimated' and can never masquerade as source='actual'. Writes go to main.live_trade_evaluations only; HUD stays READ-ONLY.
Current gaps
- HIGH main.live_trade_evaluations table is NOT deployed in trsports_tradingjournal_dev (to_regclass returns NULL). The entire authentic-grade spine has nowhere to land.psql to_regclass('main.live_trade_evaluations') => empty; SELECT count(*) => ERROR relation does not exist
- HIGH live_eval_orchestrator.py is fully STUBBED — fetch_open_trades_stub/fetch_market_context_stub/fetch_prior_eval_stub all return {} or [], write_eval_stub only prints. evaluate() never runs on real data, so zero authentic grades are produced.orchestrator docstring 'STATUS: Stub'; every data-layer fn returns empty; write is a print()
- HIGH The LIVE grade James sees is OUTCOME-ONLY: gen_scorecard.py::compute_overall_grade scores from win_rate+profit_factor+net_pnl sign with no plan-obeyed content — the exact anti-pattern the contract forbids. It does not call evaluate() and does not read live_trade_evaluations.compute_overall_grade(stats) uses stats['win_rate']/['profit_factor']/['net_pnl']; grep of gen_scorecard.py for 'evaluate'/'live_trade_eval' returns nothing
- HIGH main.journal lacks the columns evaluate() needs to grade plan-obeyed: no strategy_id, chosen_stop_id, mae_r, mfe_r (only trade_id present). indicator_alerts has strategy/band_slope/market_regime but no strategy_id FK to the registry.information_schema query on main.journal returned only trade_id of {strategy_id,chosen_stop_id,mae_r,mfe_r}; indicator_alerts has strategy but not strategy_id
- HIGH No fill/P&L reconciliation guards the grade path. gen_scorecard.py has zero GrossPNL check, zero fill-in-bar check, zero P&L==monthly-aggregate assert — so the partial-fill (ExecType) and +4h UTC TransactTime traps can silently corrupt grade inputs.grep of gen_scorecard.py for GrossPNL/reconcile/monthly_aggregate/sanity/assert.*pnl => no matches
- MED Classifier divergence persists in the grades path: gen_scorecard.py imports classify_entry from regime_classifier, NOT classify_v2.classify — so the strategy feeding the grade can disagree with the canonical classifier (and with the HUD's band-blind fuzzy path).gen_scorecard.py line 28 'from regime_classifier import classify_entry'; classify_v2.classify exists separately and is not imported
- MED gen_scorecard.py declares NO provenance: no generated_at/generator_version/source_tables/row_counts on its output, so a stale or partial scorecard cannot be distinguished from a fresh one.grep count of generated_at/provenance/source_tables/row_count in gen_scorecard.py == 0
- MED No QUARANTINE/SUSPECT grade state wired into rollups. evaluate() has OFF-BOOK but no reconciliation-failure state, and the outcome-only scorecard has no exclusion path — a suspect trade would be averaged into win_rate/PF today.evaluate() grade set is A/B/C/F/OFF-BOOK only; compute_overall_grade averages all trades' stats with no quarantine filter
Lives where: Server a2 (trsports), one system, no duplication. EVALUATOR (pure fn, EXISTS/tested): /home/trsports/setup_daily_reporting/reports/evaluate.py (evaluator_version evaluate.py/0.1.0, requires schema v2). ORCHESTRATOR (I/O owner, STUBBED): /home/trsports/setup_daily_reporting/reports/live_eval_orchestrator.py. SPINE TABLE (DDL written, NOT applied): /home/trsports/setup_daily_reporting/reports/live_trade_evaluations.sql -> main.live_trade_evaluations in Postgres db trsports_tradingjournal_dev (host 127.0.0.1:5432, user trsports_trader). STRATEGY DEFS (canonical, schema_version 2, 9 strategies): /home/trsports/trsports_gd/html/system/strategies.json (docroot /system/strategies.json) with strategy-schema-v1_1-draft.md. LIVE (outcome-only) GRADE TODAY: /home/trsports/setup_daily_reporting/reports/gen_scorecard.py::compute_overall_grade; classifier it uses = regime_classifier.classify_entry (canonical classify_v2.py sits alongside, unused by scorecard). DRILL/PROVENANCE MODEL TO REUSE (EXISTS): /home/trsports/trsports_gd/html/system/j3p-replay/{AMZN,EBAY,NVDA}_2026-07-01.html + index.html (REAL/COMPUTED/MODEL box + client recompute() to 5e-5). REGISTRY-DRIFT DETECTOR (EXISTS, term-drift only, not grade reconcile): /home/trsports/setup_daily_reporting/reports/scan_strategy_drift.py -> /system/drift-report.{json,html}. INPUT SOURCES: fills = FULL kti order log (ExecType IN {1,2}); truth P&L = kti portfolio positions GrossPNL; bars = kti price minute; bands/regime = alerts_tradingview.indicator_alerts.
Strategy library — finalize + version (so a signal is reproducible)
Versioning scheme
TWO-AXIS VERSIONING, JSON-primary (matches schema-v1 open-question default: JSON primary + generated DB mirror).
AXIS 1 — registry schema: keep the existing top-level field but reconcile the name. Live file uses `_schema_version` (currently int 1); schema-v1.md/v1.1 mandate `meta.schema_version` (v1.1 promoted = 2). FIX: have `extract_strategies_master.js` emit BOTH `_schema_version` and a nested `meta.schema_version` (single source, computed once) and bump to 2 to reflect the v1.1 live-eval arrays already merged. Breaking changes bump this integer.
AXIS 2 — per-strategy version + content hash (THE GAP: all 24 entries currently have strategy_version=None and zero hashes). Add to every entry in `strategies.json`:
- `strategy_version`: semver string, hand-bumped when rules change (schema-v1 already requires this field; it is simply unpopulated). Start every existing strategy at "1.0.0".
- `content_hash`: sha256 (first 12 hex) computed by the GENERATOR over the canonicalized rule-bearing subset ONLY — the fields that change a signal's meaning: {direction, family, entry, stop, target, entry_band_sd, entry_band_sd_max, stop_band_sd, target_band_sd, min_extension_sd, setup_type, plus the v1.1 arrays validation_rules/invalidation_conditions/management_rules/quality_indicators}. EXCLUDE cosmetic fields (name, thesis, subtitle, aka, provenance, stats) so a wording edit does not churn the hash. json.dumps(subset, sort_keys=True, separators) then sha256.
- `version_effective_from`: ISO ET date the version went live (for point-in-time resolution).
The pin identity a signal records is the pair `(strategy_id, strategy_version)` plus `content_hash` as a tamper/consistency check. content_hash mismatch on a recorded version = drift-detector RED.
GENERATOR ENFORCEMENT (extract_strategies_master.js, the LIVE master builder): on each build, recompute content_hash per entry; if the hash changed but strategy_version did NOT bump, REFUSE to publish (fail-closed, same posture as validate_strategy_refs). This makes "rules changed silently" impossible. Also append/maintain an immutable `strategy_versions` history table (see below) so old versions are reproducible.
DB MIRROR (new, generated — never authored): `main.strategies` (current snapshot, one row per id) + append-only `main.strategy_versions` (strategy_id, strategy_version, content_hash, effective_from, retired_at, full_json JSONB, generated_at, generator_version). A nightly generator loads strategies.json and UPSERTs current + INSERTs any new (id,version) into strategy_versions. This gives the evaluator a joinable, point-in-time-resolvable definition so a 3-month-old trade re-renders against the EXACT rules that graded it (schema-v1 open question resolved: freeze to strategy_version at trade time, never re-classify silently).
REPRODUCIBILITY RULE (single source of truth per concept, per system_contract): the registry JSON is the ONLY place rules are authored; strategy_versions is a generated append-only ledger; no consumer hand-codes rules. classify_v2.py loads the registry (not inline constants) and STAMPS the (strategy_id, strategy_version, content_hash) it used onto every eval_record — so any grade can name the exact rule bytes behind it.
Signal reproducibility
HOW A SIGNAL ROW PINS THE EXACT STRATEGY VERSION + strategy_id MIGRATION (schema-v1 migration table line: "indicator_alerts / main.journal: Add strategy_id column; backfill via classifier — Phase 0 #5").
Today indicator_alerts carries only a FREE-TEXT `strategy` column (Pine-supplied, unmapped to the registry) and an int `version` (indicator schema, not strategy). No strategy_id, no strategy_version, no content_hash. classify_entry-equivalent computes playbook_type LIVE at scorecard time (gen_scorecard enrich_trades_from_db:263 notes "column not in schema; always classify live") — so today NOTHING records which rule version graded a trade; re-running the scorecard silently re-grades against whatever the registry says now.
MIGRATION (additive, 3 columns, backfill via existing classify_v2.py which is already the "schema-v2 single-strategy_id classifier"):
ADD COLUMN strategy_id text NULL -- FK-by-convention to strategies.json id (validate_strategy_refs on write; refuse unknown)
ADD COLUMN strategy_version text NULL -- semver pinned at classification time
ADD COLUMN strategy_content_hash text NULL-- the 12-hex hash of the version that fired
ADD COLUMN classified_by text NULL -- e.g. "classify_v2@<generator_version>" (provenance)
Same 4 columns mirror onto main.journal (or a sidecar main.trade_classification keyed by trade_id/leg_id to keep journal — a trades source-of-truth table — clean; sidecar preferred so we don't co-mingle broker truth with derived classification).
WRITE PATH — pin at classification, one evaluator both live+batch (system_contract: SAME evaluator live+batch, rules-engine SEPARATE from UI):
evaluate(strategy_def, trade_state, market_context) -> eval_record is the pure fn in classify_v2.py. It resolves the registry ONCE per run, and for the chosen strategy_id writes back onto the alert/eval row: strategy_id + the def's strategy_version + content_hash + classified_by. Because the version/hash are copied FROM the loaded def AT classification time and stored, the row is frozen: later registry edits cannot retro-change it. Point-in-time reproduce = look up strategy_versions WHERE strategy_id=? AND strategy_version=? → get exact rule JSON → re-run evaluate → must reproduce the same eval_record (and content_hash must match, else drift RED).
BACKFILL: run classify_v2.py over historical ENTRY alerts (event_type IN ENTRY/EXIT, testing=false, isdeleted=false) using the band/vwap/regime columns already present, stamping (strategy_id, strategy_version=current, content_hash). Because history predates versioning, backfilled rows carry strategy_version="1.0.0" + a `classified_backfill=true` flag so they are never mistaken for having been graded live at trade time. Idempotent: re-running only fills NULLs / updated rows (upsert by id). Nightly drift check already in contract extends to: every graded trade day has strategy_id non-null and its (id,version) resolves in strategy_versions.
RESULT: given any trade you can name (a) which strategy_id, (b) which strategy_version, (c) the content_hash proving the exact rule bytes, (d) classified_by/generator_version — full chain from grade back to definition.
strategy_id migration (pin the version onto every signal)
indicator_alerts today: free-text `strategy` (Pine, unmapped) + int `version` (indicator schema) + market_regime + full band/vwap columns, but NO strategy_id / strategy_version / content_hash — so no trade currently records which rule version graded it (scorecard classifies LIVE each run and silently re-grades). MIGRATION (additive, Phase 0 #5): ALTER TABLE alerts_tradingview.indicator_alerts ADD COLUMN strategy_id text, strategy_version text, strategy_content_hash text, classified_by text (all NULL-able). Mirror the same 4 onto a new sidecar main.trade_classification (keyed trade_id/leg_id) rather than into main.journal to keep broker truth clean. BACKFILL via classify_v2.py (already the schema-driven single-strategy_id classifier) over ENTRY/EXIT alerts where testing=false and isdeleted=false, using the band/vwap/regime columns already present; stamp strategy_version="1.0.0" + classified_backfill=true so backfilled rows are never confused with live-at-trade-time grades. Idempotent upsert-by-id; refuse to write any strategy_id that fails validate_strategy_refs against strategies.json. On the go-forward live path, classify_v2.evaluate() copies (strategy_version, content_hash) FROM the loaded registry def at classification time onto the row, freezing it against later registry edits — point-in-time reproducible via main.strategy_versions.
Scorecard — authentic grades with click-to-evidence audit (reuse the replay, don't rebuild)
Audit design
SCORECARD AUTHENTIC-GRADE + CLICK-TO-EVIDENCE, REUSING THE J3P REPLAY PROVENANCE/DRILL PATTERN (do NOT rebuild it).
WHAT THE REPLAY ALREADY IS (verified /system/j3p-replay/AMZN_2026-07-01.html): a self-contained generated page whose contract = a PROVENANCE BOX tagging each layer REAL (candles/VWAP/±sigma from real kti 1-min->2-min OHLC4) vs COMPUTED vs MODEL (plan levels), a NO-LOOKAHEAD assertion (post-entry only, MFE never an exit), band math that independently RECOMPUTES to 5e-5 with an adversarial HLC3 divergence of 0.37 proving OHLC4, and click-a-signal -> DRILL to entry/stop/target + the exact bars. It carries the vocabulary inline (REAL/COMPUTED/MODEL, "No lookahead", "recompute", OHLC4, 0.37) but has NO reusable DOM component API. So REUSE = call its GENERATOR and honor its provenance/drill CONTRACT, not import its markup.
DESIGN — three reuse moves:
1) GRADE PROVENANCE BOX (new, on each scorecard trade card) mirrors the replay's box 1:1 but for the GRADE instead of the chart: it names, per graded trade, the four evidence layers — REAL (the fills: broker execution rows from main.journal / order log — entry_price, exit_price, size, times), COMPUTED (the eval_record from the pure evaluate() fn: which entry_rules passed/failed, stop/target adherence, quality score), MODEL (the plan: stocks_in_play_daily if_then / entry-stop-target_hint), and DEFINITION (strategy_id + strategy_version + content_hash it was graded against). No-lookahead assertion carried through: the grade uses only bars up to each decision point; MFE/MAE are reported but can never be the exit the grade credits.
2) CLICK-TO-EVIDENCE DRILL: every headline sub-grade is a link. Grade -> (a) which strategy VERSION (opens the registry entry at that version from strategy_versions, showing the exact entry_rules/stop/target that were checked), (b) which SIGNAL (the indicator_alerts row: id, timestamp_ny, the band/vwap values that fired it), (c) which FILLS (the journal execution rows), (d) DRILL-TO-REPLAY-CHART: deep-link into the SAME j3p-replay generator for that symbol+date with the entry/stop/target and the exact bars highlighted — i.e. the scorecard hands the replay generator {symbol, date, entry_ts, stop, target, strategy_id, strategy_version} and the replay renders the authenticated chart. One provenance engine, two surfaces.
3) AUTHENTICITY (independent recompute, reused idea): the scorecard's grade generator re-derives the boolean entry_rules from the REAL band/vwap columns (not from the free-text `strategy` string) using the SAME evaluate() the live path uses, and asserts the recomputed result matches the stored eval_record to tolerance — the grade-side analogue of the replay's 5e-5 band recompute. A mismatch flags the trade suspect (see quarantine).
HEADLINE GRADE FIX (system_contract: process not just outcome): compute_overall_grade (gen_scorecard.py:552, currently f(win_rate, profit_factor, pnl_sign) only) gains a PROCESS term from the eval_record — base_play match, regime match, rule_followed, mistake_tag (the open stage-5 taxonomy) — so the headline reflects "did you trade your plan/registry", with the outcome terms kept but no longer sole. The taxonomy fields live ON the eval_record so every one is drill-backed.
LIVES: grade generator + provenance box + drill links = gen_scorecard.py / scorecard_enrichments.py, output Z:/public_html/scorecards. evaluate() = classify_v2.py (shared live+batch). Replay = existing j3p-replay generator, invoked by deep-link. Hub-first: reached via /system/ scorecards property; drill target is the existing /system/j3p-replay/ surface.
Quarantine UI (suspect data shown NOT graded)
SUSPECT / QUARANTINED TRADE = SHOWN, NEVER GRADED (fail-closed; a grade you cannot back with evidence is worse than no grade).
A trade is QUARANTINED when any authenticity gate fails: (a) strategy_id NULL or does not validate against the registry (validate_strategy_refs), (b) (strategy_id, strategy_version) does not resolve in main.strategy_versions, (c) recorded strategy_content_hash != the hash of that version in the ledger (definition tampered/skewed), (d) the grade-side independent recompute disagrees with the stored eval_record beyond tolerance, (e) no matching signal row (indicator_alerts) or no matching fills (journal) — i.e. an off-book/orphan execution, (f) NO-LOOKAHEAD violation detected (an input postdates the decision). Off-book sentinel trades (schema off_book:true / auto_grade "F") are a SEPARATE, expected state — those get the honest F, not quarantine.
UI: the trade card renders with a neutral, de-emphasized treatment (per live-emphasis rule — suspect = static/dim, not loud) and a "NO GRADE — evidence incomplete" chip in place of a letter grade. It is EXCLUDED from all aggregate scores (win_rate, profit_factor, headline Grade, P&L-vs-plan) so one un-provable trade cannot inflate or deflate the day — the scorecard footnotes "N trades quarantined, not scored." The provenance box still renders, showing exactly WHICH layer failed (e.g. "DEFINITION: version 1.2.0 not found in ledger" or "COMPUTED: recompute diverged 0.14 > tol"), and the drill links still work so James can inspect the raw signal/fills/replay and either fix the mapping or accept it as genuinely off-book. Nightly drift detector (already in contract) counts quarantined trades and alerts if the rate rises — quarantine is a health signal, not a silent drop.
This keeps the single-source-of-truth guarantee intact: the scorecard only ever grades trades whose full chain (fills -> signal -> strategy_version -> content_hash -> recomputed eval) is verifiable, exactly the authenticity bar the replay set for its chart.
Build order — reconciliation + versioning BEFORE any scoring
- STEP 0 — Trust the inputs before grading anything. Port gen_replay's fill parse (ExecType IN {1,2} & LastShares>0; UTC→ET fix, never DST-naive -4h) and the GrossPNL penny-reconcile + fill-in-bar check up into a shared, gated function. Make it fail-loud: mismatch or out-of-bar fill → quarantine, do NOT write a grade. This defends the two order-log traps on the surface that actually grades.
- STEP 1 — Versioning + registry hardening. Add per-entry strategy_version (start 1.0.0) + content_hash (sha256/12hex over the rule-bearing subset only) + version_effective_from to strategies.json; reconcile _schema_version vs meta.schema_version (emit both, bump to 2); generator REFUSES to publish when hash changed without a version bump; stand up generated append-only main.strategies + main.strategy_versions ledger for point-in-time re-render.
- STEP 2 — Pin the version onto signals + collapse classifiers. ALTER indicator_alerts to add strategy_id/strategy_version/strategy_content_hash/classified_by + sidecar main.trade_classification; make classify_v2.py THE single evaluator (live + batch), loading the registry and stamping (id, version, hash) it used; backfill history with classify_v2 (strategy_version 1.0.0 + classified_backfill=true); refuse any strategy_id that fails validate_strategy_refs.
- STEP 3 — Deploy the authentic-grade spine. Apply live_trade_evaluations.sql; wire live_eval_orchestrator.py to real fetch/write (retire the stubs); add the columns evaluate() needs (strategy_id, chosen_stop_id, mae_r, mfe_r); route grades through evaluate() with reconciliation gates + QUARANTINE state; retire compute_overall_grade to a P&L stat and kill the pnl==0 price-estimate fallback.
- STEP 4 — Scorecard authenticity + drill. Add a GRADE PROVENANCE BOX (REAL fills / COMPUTED eval_record / MODEL plan / DEFINITION strategy_id+version+hash) and click-to-evidence drill that deep-links into the existing j3p-replay generator with {symbol,date,entry_ts,stop,target,strategy_id,strategy_version}; add the process term to the headline grade; every generator declares provenance (generated_at/generator_version/source_tables/row_counts).
- STEP 5 — Nightly drift + guardrails. Stand up the drift detector: scorecard P&L == monthly aggregate to the penny, alerts>0 per RTH day, 100% identity-mapping resolution, content_hash matches the ledger, quarantine-rate alarm. This is the standing tripwire so a silent zero trips an alarm instead of quietly producing an estimate-based grade.
Layer-location map — one system, single source, no duplication
| Layer | Lives where |
|---|
| FILLS (execution truth — order-log parse, ExecType filter, UTC→ET fix, fill-in-bar + GrossPNL penny reconcile) | a2 server. The CORRECT parse lives ONLY in /home/trsports/trading/dev/vcet-replay-viewer/gen_replay.py (load_fills / validate_fills_vs_bars / position_trace). Truth witness = kti portfolio positions GrossPNL; bars = kti price minute (karb). Broker rows = main.journal / main.closed_trades. Single-source this parser — do NOT fork it; port its gate up rather than rebuild. |
| SIGNALS (the intended play — webhook event + versioned strategy meaning) | a2 server. SPINE = alerts_tradingview.indicator_alerts (Postgres, event_type IN ENTRY/EXIT, testing=false, isdeleted=false). ONLY writer = /home/trsports/trading/a1p_journal/src/php/webhooks/tradingview_smb_indicator_trigger.php (stale 'fashionably_late' docstring; real INSERT targets indicator_alerts). Rule MEANING = /home/trsports/trsports_gd/html/system/strategies.json (versioned). |
| STRATEGY RULES + VERSION LEDGER (author-once + generated point-in-time history) | a2 server. Authored: /home/trsports/trsports_gd/html/system/strategies.json (+ strategy-schema-v1.md / v1.1) — the ONLY place rules are authored, built by extract_strategies_master.js. Generated append-only: main.strategies (current) + main.strategy_versions (id, version, content_hash, effective_from, retired_at, full_json) in trsports_tradingjournal_dev. Never hand-edited. |
| CLASSIFIER (must collapse to ONE, shared live + batch) | a2 server, /home/trsports/setup_daily_reporting/reports/. TARGET OF RECORD = classify_v2.py (schema-driven, stamps id/version/hash). Currently divergent: regime_classifier.classify_entry (what gen_scorecard calls today) and hud/js/strategies-fuzzy.js (HUD modal, band-blind). Side-by-side comparison harness = audit_trades.py. |
| EVALUATOR (pure rules-engine, separate from UI) + GRADE SPINE | a2 server, /home/trsports/setup_daily_reporting/reports/. Pure fn: evaluate.py (evaluate.py/0.1.0, needs schema v2) — EXISTS/tested. Orchestrator: live_eval_orchestrator.py — STUBBED. Spine table: main.live_trade_evaluations (DDL live_trade_evaluations.sql written, NOT applied). Live outcome-only grade today: gen_scorecard.py::compute_overall_grade — to be demoted. |
| GRADE DB BASIS (the aggregate the scorecard reads) | a2 DB trsports_tradingjournal_dev, schema main. main.trade_context.net_pnl (computed nightly ~20:46 UTC, 100% coverage 30d) — but has commissions/fees with NO source flag and NO GrossPNL reconcile column. WRITER is OFF-SERVER (HOME/Windows nightly pipeline); the fill→trade_context hop is unverified from a2 and must be reconciled, not re-forked. |
| SCORECARD (grade + provenance box + drill links) + QUARANTINE | a2 server: /home/trsports/setup_daily_reporting/reports/gen_scorecard.py + scorecard_enrichments.py + trader_state.py → published to Z:/public_html/scorecards (reached via /system/ hub). Quarantine is a data-layer flag here — never a HUD edit. |
| DRILL / PROVENANCE ENGINE (reuse, do NOT rebuild) | a2 server. Existing generator behind /home/trsports/trsports_gd/html/system/j3p-replay/{AMZN,EBAY,NVDA}_2026-07-01.html (REAL/COMPUTED/MODEL box, client recompute() to 5e-5, HLC3 diverges 0.37, no-lookahead). Scorecard deep-links INTO its generator; its parameter/input contract still needs to be located and verified. |
| DRIFT DETECTION (nightly tripwire) | a2 server, /home/trsports/setup_daily_reporting/. Pattern to extend: scan_strategy_drift.py (today term-drift only → /system/drift-report.{json,html}). Must add P&L-vs-monthly-aggregate, alerts-per-day, mapping-resolution, content_hash-vs-ledger, and quarantine-rate checks. No cron entry currently exists — one must be added. |
Generated from a 5-agent verification workflow (fills/signals/grades/library + synthesis) that read the live a2 pipeline read-only. Reconciliation status and file:line claims verified 2026-07-02; re-verify before implementing.