fix: one bad SPY fetch stopped outcome scoring for nineteen days

The outcome worker kept one price series per symbol in a map that never expired,
and on the null path it only ever dropped the instrument, never the benchmark. So
a single degraded-but-200 SPY response poisoned the benchmark for the whole life
of the worker. calculateOutcome then returned null for every symbol, and each
matured prediction got retired as "no market data" the moment its grace ran out.

Outcomes stopped dead on 2026-09-20. Three unrelated tickers failing in the same
pass was the tell. I ran calculateOutcome against the exact predictions the worker
was retiring and all three scored fine, with GSBC sitting there on yahoo with
6,732 bars through yesterday. Nothing was ever missing.

Fourth time now that unmanaged state in a long lived loop has quietly broken this
pipeline, so the cache gets a ttl, a dud series is treated as a failed fetch
rather than cached as though it were real, and the benchmark is dropped alongside
the instrument when a score comes back empty.

The guard that actually matters is coversHorizon. A prediction is only retired
when the prices we hold genuinely reach its horizon. If the series stops short
then the exit bar has not published yet, which is a hole in what we fetched and
not a prediction nobody can score. That distinction is the whole bug.

scripts/repair-unresolvable-outcomes.js re-asks every mislabeled row with fresh
data and leaves anything genuinely unscorable alone. Dry run by default, writes
through openRuntimeDb so it honours the configured backend, and prints row counts
either side.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ImBenji
2026-10-09 14:13:32 +01:00
co-authored by Claude Opus 5
parent 1c75e4171e
commit a4cf6462d0
3 changed files with 270 additions and 10 deletions
+18 -1
View File
@@ -9,7 +9,7 @@ const { calibrateOutcomes, cohortKey } = require('../src/autonomy/calibration');
const { decide } = require('../src/autonomy/policy');
const { validatePaperIntent, createSimulator } = require('../src/autonomy/execution');
const { calculateOutcome, addTradingDays } = require('../src/autonomy/outcomes');
const { yahooSymbol } = require('../workers/outcomeAutonomyWorker');
const { yahooSymbol, coversHorizon } = require('../workers/outcomeAutonomyWorker');
const { createOrderIntent } = require('../src/autonomy/orderIntents');
const { enqueueCoordinatorEvent, reconcileArchiveBatch, reconcileLiveBatch, isTransientCoordinatorFailure } = require('../workers/autonomyWorker');
const { buildGraphContext } = require('../src/autonomy/graphContext');
@@ -210,6 +210,23 @@ test('a leftover job from an older run cannot hijack the active run', () => {
assert.equal(runForJob(db, { id: 12, idempotency_key: 'replay:999:article:1' }, active).id, second);
});
test('a price series that stops short of the horizon is a data gap, not an unresolvable prediction', () => {
const bars = [
{ date: '2026-09-01', close: 10 },
{ date: '2026-09-15', close: 11 },
];
// the exit bar simply has not published yet. the worker used to retire these,
// which is how ~400 scorable rows got labelled unresolvable
assert.equal(coversHorizon(bars, '2026-09-29'), false);
assert.equal(coversHorizon(bars, '2026-09-15'), true, 'the horizon bar itself counts');
assert.equal(coversHorizon(bars, '2026-09-10'), true);
// an empty or missing series can never cover anything, and must not read as true
assert.equal(coversHorizon([], '2026-09-01'), false);
assert.equal(coversHorizon(undefined, '2026-09-01'), false);
assert.equal(coversHorizon(null, '2026-09-01'), false);
});
test('calibration and policy abstain on insufficient evidence', () => {
const calibration = calibrateOutcomes([
{ excess_return: 0.02, direction_correct: 1 },