diff --git a/pm-stack/aggregator/c4-methodology-log.jsonl b/pm-stack/aggregator/c4-methodology-log.jsonl index 3fdff105c..6e0ad872f 100644 --- a/pm-stack/aggregator/c4-methodology-log.jsonl +++ b/pm-stack/aggregator/c4-methodology-log.jsonl @@ -1 +1,2 @@ -{"change":"First C4 methodology. downtime_window records (C4.1, #13257) derive the complete-downtime interval by intersecting the Stage-3 S1 per-pool wall intervals [wall, reset) across every routing pool (keyed by canonical provider id), basis since_last_reset; the prediction range is [latest member wall, earliest member reset), rendered by the §4 formatter at issuance. Providers the forecast cannot project publish insufficient_history and veto a no-window verdict; a defensible no-window tick publishes no record. No day-type or spike-day adjustments (inputs.adjustments is []).","evidence":["doc/2026-11-13T15-12-00Z_design_reporting-architecture-event-driven/c4-forecasting-design.md","#12695 forecast product (quota-forecast.json)"],"expected_effect":"Downtime-window predictions exist on every gatherer tick and are scorable per design §3 (start/end error, interval overlap); §3's accuracy bar is coverage inside the calibrated band with median window error under one gatherer tick span at one-tick lead.","reason":"The C4 design (doc/2026-11-13T15-12-00Z_design_reporting-architecture-event-driven/c4-forecasting-design.md, PR #13268) specifies the record, scoring, and methodology-log formats, and S1's same-period pace projection is the only measured per-pool wall source; §5 adjustments are data-gated below their sufficiency thresholds.","review_after":"2026-12-21","ts":"2026-11-23T13:10:00.000Z","version":"c4-meth:1"} \ No newline at end of file +{"change":"First C4 methodology. downtime_window records (C4.1, #13257) derive the complete-downtime interval by intersecting the Stage-3 S1 per-pool wall intervals [wall, reset) across every routing pool (keyed by canonical provider id), basis since_last_reset; the prediction range is [latest member wall, earliest member reset), rendered by the §4 formatter at issuance. Providers the forecast cannot project publish insufficient_history and veto a no-window verdict; a defensible no-window tick publishes no record. No day-type or spike-day adjustments (inputs.adjustments is []).","evidence":["doc/2026-11-13T15-12-00Z_design_reporting-architecture-event-driven/c4-forecasting-design.md","#12695 forecast product (quota-forecast.json)"],"expected_effect":"Downtime-window predictions exist on every gatherer tick and are scorable per design §3 (start/end error, interval overlap); §3's accuracy bar is coverage inside the calibrated band with median window error under one gatherer tick span at one-tick lead.","reason":"The C4 design (doc/2026-11-13T15-12-00Z_design_reporting-architecture-event-driven/c4-forecasting-design.md, PR #13268) specifies the record, scoring, and methodology-log formats, and S1's same-period pace projection is the only measured per-pool wall source; §5 adjustments are data-gated below their sufficiency thresholds.","review_after":"2026-12-21","ts":"2026-11-23T13:10:00.000Z","version":"c4-meth:1"} +{"change":"model_plan_arrival records (C4.4, #13260) now render their prediction range with the one shared \u00a74 formatter (renderPredictionRange in quota-downtime.ts: duration, day, compound, and calendar forms) instead of this kind's own two-form copy in quota-arrival.ts, which is deleted. Stored rendered strings for arrival ranges change accordingly (a range crossing a Chicago day boundary now renders in calendar form, e.g. \"between Wednesday evening and this evening\", where the kind-local renderer emitted a days-from-now string). The downtime_window and reset_duration kinds are unchanged \u2014 the shared formatter was already their method \u2014 and keep naming c4-meth:1.","evidence":["doc/2026-11-13T15-12-00Z_design_reporting-architecture-event-driven/c4-forecasting-design.md \u00a74, \u00a76","#13408","#13357 (PR #13406, FDR-0013: the design is right; one formatter produces rendered)"],"expected_effect":"Every C4 kind's stored rendered string comes from the single \u00a74 formatter, so a rendering fix or form change lands for all kinds at once; arrival records issued under c4-meth:2 are attributable to the unified method, and pre-unification c4-meth:1 arrival records keep their original strings for scoring.","reason":"The design (\u00a74) says rendered is produced by one formatter, but quota-arrival.ts carried its own renderPredictionRange with only the duration and day forms (no compound, no calendar), so identical ranges rendered differently by kind. #13408 files the unification as a methodology-visible change requiring this log entry and the version bump, not a silent edit.","review_after":"2026-12-21","ts":"2026-11-23T17:50:00.000Z","version":"c4-meth:2"} diff --git a/pm-stack/aggregator/src/quota-arrival.test.ts b/pm-stack/aggregator/src/quota-arrival.test.ts index 9b21e965b..218d9c64f 100644 --- a/pm-stack/aggregator/src/quota-arrival.test.ts +++ b/pm-stack/aggregator/src/quota-arrival.test.ts @@ -1,11 +1,11 @@ import { describe, expect, test } from "bun:test"; import { buildArrivalRecords, - renderPredictionRange, scoreArrivalPrediction, validateArrivalRecord, type ArrivalPredictionRecord, } from "./quota-arrival.ts"; +import { renderPredictionRange } from "./quota-downtime.ts"; import type { AnomalyFinding } from "./quota-anomaly.ts"; // Oracle: the C4 design record (doc/2026-11-13T15-12-00Z_design_ @@ -93,7 +93,11 @@ describe("detector_history basis", () => { expect(rec.prediction?.likely).toBe(iso(T0 + 37.5 * DAY)); expect(rec.inputs.samples).toBe(3); expect(rec.inputs.span).toEqual({ from: iso(T0), to: iso(T0 + 25 * DAY) }); - expect(rec.prediction?.rendered).toContain("days from now"); + // Rendered by the one shared §4 formatter (#13408): the range + // crosses Chicago day boundaries, so the calendar form carries + // it — the kind-local renderer's "days from now" string is gone. + expect(rec.prediction?.rendered).toBe("between Wednesday evening and this evening"); + expect(rec.methodology_version).toBe("c4-meth:2"); }); test("several findings at one instant are one arrival", () => { @@ -235,13 +239,24 @@ describe("validateArrivalRecord — the no-speculative-dates guard", () => { }); }); -describe("renderPredictionRange (§4 forms)", () => { - test("spans under 48h render in half-hour-rounded hours", () => { - expect(renderPredictionRange(T0 + 4 * HOUR, T0 + 6.4 * HOUR, T0)).toBe("between 4 and 6.5 hours from now"); +describe("renderPredictionRange (§4 forms, the shared formatter)", () => { + // Since #13408 the arrival builder renders through the one shared + // formatter in quota-downtime.ts; these pin its forms at the + // arrival call shape (ISO strings in, stored string out). The + // formatter's own suite (quota-downtime.test.ts) is the primary + // oracle for the forms themselves. + const ISSUED_MIDDAY = Date.parse("2026-10-01T17:00:00.000Z"); // Oct 1, 12:00 in Chicago + + test("spans under 48h on one Chicago day render in half-hour-rounded hours", () => { + expect( + renderPredictionRange(iso(ISSUED_MIDDAY + 4 * HOUR), iso(ISSUED_MIDDAY + 6.4 * HOUR), iso(ISSUED_MIDDAY)), + ).toBe("between 4 and 6.5 hours from now"); }); - test("spans of 48h or more render in days", () => { - expect(renderPredictionRange(T0 + 2.5 * DAY, T0 + 5.7 * DAY, T0)).toBe("between 2.5 and 5.7 days from now"); + test("a range crossing a Chicago day boundary renders in calendar form", () => { + expect(renderPredictionRange("2026-10-02T15:00:00.000Z", "2026-10-04T20:00:00.000Z", iso(ISSUED_MIDDAY))).toBe( + "between tomorrow morning and Sunday afternoon", + ); }); }); diff --git a/pm-stack/aggregator/src/quota-arrival.ts b/pm-stack/aggregator/src/quota-arrival.ts index 8a189f818..2d7a40033 100644 --- a/pm-stack/aggregator/src/quota-arrival.ts +++ b/pm-stack/aggregator/src/quota-arrival.ts @@ -38,9 +38,13 @@ // no_basis / insufficient_history records are never scored — they // are the honest answer, and scoring them would pay for guessing. // -// rendered (§4): the duration and day forms are implemented; the -// calendar form (day names / dayparts) is not yet, and the machine -// range never leaves the record regardless. +// rendered (§4): produced by the one shared formatter +// (renderPredictionRange in quota-downtime.ts — duration, day, +// compound, and calendar forms), never by a kind-local copy; the +// machine range never leaves the record regardless. Arrival +// records issued before the unification carried strings from this +// module's own two-form renderer; the change of stored strings is +// the methodology-visible change logged as c4-meth:2 (§6). // // Pure functions over plain values — no I/O, no clock reads except // through arguments (the quota-anomaly.ts discipline). The live @@ -48,11 +52,14 @@ // mirror under source "quota-prediction", design §1) is a follow-up // slice; this module is the record contract that wiring writes. import type { AnomalyFinding } from "./quota-anomaly.ts"; +import { renderPredictionRange } from "./quota-downtime.ts"; -/** First methodology-log entry for the arrival kind (design §6): - * every record this module emits names it, so a score is always - * attributable to the method that produced it. */ -export const ARRIVAL_METHODOLOGY_VERSION = "c4-meth:1"; +/** Methodology version for the arrival kind (design §6): every + * record this module emits names it, so a score is always + * attributable to the method that produced it. c4-meth:2 is the + * unification of this kind's range rendering on the one shared §4 + * formatter (c4-methodology-log.jsonl, §6). */ +export const ARRIVAL_METHODOLOGY_VERSION = "c4-meth:2"; /** Ledger source the live wiring mirrors arrival records under * (design §1) — distinct from S1's "quota-forecast"; C4 records @@ -154,24 +161,6 @@ function dur(ms: number): string { return `${Number.isInteger(d) ? String(d) : d.toFixed(1)} days`; } -const roundHalf = (n: number): number => Math.round(n * 2) / 2; -const round1 = (n: number): number => Math.round(n * 10) / 10; -const fmtNum = (n: number): string => (Number.isInteger(n) ? String(n) : n.toFixed(1)); - -/** The §4 range rendering, duration and day forms: duration form - * (span < 48h) "between X and Y hours from now" with X/Y rounded to - * the half hour; day form (span >= 48h) in days to one decimal. */ -export function renderPredictionRange(earliestMs: number, latestMs: number, issuedMs: number): string { - if (latestMs - earliestMs < 48 * HOUR_MS) { - const x = roundHalf((earliestMs - issuedMs) / HOUR_MS); - const y = roundHalf((latestMs - issuedMs) / HOUR_MS); - return `between ${fmtNum(x)} and ${fmtNum(y)} hours from now`; - } - const x = round1((earliestMs - issuedMs) / DAY_MS); - const y = round1((latestMs - issuedMs) / DAY_MS); - return `between ${fmtNum(x)} and ${fmtNum(y)} days from now`; -} - /** The distinct arrival instants a pool's plan-change findings * record, ascending. Findings are per-window; several at one * instant are one arrival (the plan changed once). Findings with no @@ -260,7 +249,7 @@ export function buildArrivalRecords(input: ArrivalBuildInput): ArrivalPrediction earliest: iso(earliest), latest: iso(latest), likely: iso(last + median(sorted)), - rendered: renderPredictionRange(earliest, latest, issuedMs), + rendered: renderPredictionRange(iso(earliest), iso(latest), input.issuedAt), }, state: "predicted", state_reason: undefined, @@ -318,7 +307,7 @@ export function buildArrivalRecords(input: ArrivalBuildInput): ArrivalPrediction earliest: iso(earliest), latest: iso(latest), likely: iso(anchorMs + k * cad.periodMs), - rendered: renderPredictionRange(earliest, latest, issuedMs), + rendered: renderPredictionRange(iso(earliest), iso(latest), input.issuedAt), }, state: "predicted", state_reason: undefined,