diff --git a/pm-stack/aggregator/c4-methodology-log.jsonl b/pm-stack/aggregator/c4-methodology-log.jsonl index 3fdff105c..4a0ad0cf0 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":"The §4 range formatter now implements the design as written: the day form (span ≥ 48h) is checked before the calendar form, so it can fire — previously the cross-day calendar check ran first and every ≥48h-wide range crosses a Chicago day boundary, making the day-form branch unreachable; and mixed spans render compound (\"2 days 4 hours to up to 5 days 4 hours\") when either bound is not an exact tenth of a day, with plain decimal days otherwise. In-progress ranges (earliest at or before issuance) still render calendar form. Downtime and reset-duration records issued under this version carry the new renderings.","evidence":["https://github.com/developing-today/code/issues/13357","doc/2026-11-13T15-12-00Z_design_reporting-architecture-event-driven/c4-forecasting-design.md §4","pm-stack/aggregator/src/quota-downtime.ts (renderPredictionRange)"],"expected_effect":"Prediction ranges 48h or wider render in the specified day/compound forms instead of calendar form, so stored rendered strings match §4; no change to ranges under 48h or to in-progress ranges. Re-scored by the §3 accuracy review against the ledger.","reason":"The design (§4) specifies the day form for span ≥ 48h and the compound form for mixed spans, but the shipped formatter implemented neither: the day-form branch was provably unreachable and no code produced the compound form (#13357). The stored rendered string is what the scorer grades (§1), so the formatter must produce the specified forms.","review_after":"2026-12-21","ts":"2026-11-23T15:19:00.000Z","version":"c4-meth:2"} diff --git a/pm-stack/aggregator/src/quota-downtime.test.ts b/pm-stack/aggregator/src/quota-downtime.test.ts index 6c1144c0b..dbc0a3a7c 100644 --- a/pm-stack/aggregator/src/quota-downtime.test.ts +++ b/pm-stack/aggregator/src/quota-downtime.test.ts @@ -262,6 +262,28 @@ describe("renderPredictionRange", () => { test("a same-day future range renders in duration form, half-hour rounded", () => { expect(renderPredictionRange(at(2.25), at(5.75), AS_OF)).toBe("between 2.5 and 6 hours from now"); }); + + test("a 48h-or-wider future range renders in day form, not calendar form (design §4; #13357)", () => { + // Wed 18:00 CST -> Sat 06:00 CST: 60h wide, crosses day boundaries. + // The day-form branch was unreachable: the calendar check ran first. + expect(renderPredictionRange(at(60), at(120), AS_OF)).toBe("2.5 to 5 days"); + }); + + test("a 48h-wide range on the boundary renders in day form (design §4; #13357)", () => { + // Wed 06:00 CST -> Fri 06:00 CST: exactly 48h wide, both bounds exact tenths of a day. + expect(renderPredictionRange(at(48), at(96), AS_OF)).toBe("2 to 4 days"); + }); + + test("a 48h-or-wider range with non-tenth-day bounds renders compound (design §4; #13357)", () => { + // 52h = 2 days 4 hours, 124h = 5 days 4 hours; neither is an exact tenth of a day. + expect(renderPredictionRange(at(52), at(124), AS_OF)).toBe("2 days 4 hours to up to 5 days 4 hours"); + }); + + test("a 48h-or-wider range already in progress still renders calendar form (#13357)", () => { + // The day form has no "from now" anchor, so a past start stays calendar. + const rendered = renderPredictionRange(at(-2), at(60), AS_OF); + expect(rendered.startsWith("between ")).toBe(true); + }); }); describe("buildDowntimeLedgerRows", () => { diff --git a/pm-stack/aggregator/src/quota-downtime.ts b/pm-stack/aggregator/src/quota-downtime.ts index 961a39cda..1edfb79b1 100644 --- a/pm-stack/aggregator/src/quota-downtime.ts +++ b/pm-stack/aggregator/src/quota-downtime.ts @@ -42,7 +42,7 @@ // Basis (§1: mandatory, singular): since_last_reset — the S1 // projections are fit on the current reset period's same-period // series, and this module fits nothing itself; it intersects the -// oracle's published intervals. Methodology version c4-meth:1 +// oracle's published intervals. Methodology version c4-meth:2 // (c4-methodology-log.jsonl beside this module's package root, // §6). Advisory only: no placement path reads these records — // the C6 pages and forecast alerts named by #9572 consume them. @@ -54,7 +54,7 @@ import type { ForecastLedgerRow, QuotaForecastFile } from "./quota-forecast.ts"; * into the S1 source. */ export const PREDICTION_LEDGER_SOURCE = "quota-prediction"; -export const C4_METHODOLOGY_VERSION = "c4-meth:1" as const; +export const C4_METHODOLOGY_VERSION = "c4-meth:2" as const; export interface C4PredictionRecord { record_version: 1; @@ -84,11 +84,15 @@ interface WallInterval { // --- Range rendering (design §4) ---------------------------------- // One formatter for (earliest, latest, issued_at), in -// America/Chicago wall-clock terms. Duration form under 48h, -// day form at/over 48h, calendar form when the range crosses a -// Chicago day boundary — the form preferred for downtime windows -// and any range whose latest bound falls on a different day than -// its earliest. +// America/Chicago wall-clock terms. Day form at/over a 48h span, +// checked first: a range that wide always crosses a Chicago day +// boundary, so the calendar check below would otherwise swallow +// every day-form range (#13357). Mixed spans render compound — +// whole days + whole hours per bound — when either bound is not +// an exact tenth of a day; otherwise plain decimal days. Calendar +// form when the range crosses a Chicago day boundary, or when it +// is already in progress (a past start has no "days from now" +// reading); duration form otherwise. const CHICAGO = "America/Chicago"; const dayKeyFmt = new Intl.DateTimeFormat("en-US", { timeZone: CHICAGO, year: "numeric", month: "2-digit", day: "2-digit" }); @@ -119,6 +123,25 @@ function chicagoDaypart(ms: number, issuedMs: number): string { const roundHalf = (x: number) => Math.round(x * 2) / 2; const fmtNum = (x: number) => (Number.isInteger(x) ? String(x) : x.toFixed(1)); +/** True when the offset is an exact tenth of a day — the plain + * day form's rounding is then lossless for that bound. */ +function isExactTenthDay(offsetMs: number): boolean { + const tenths = (offsetMs / 86_400_000) * 10; + return Math.abs(tenths - Math.round(tenths)) < 1e-9; +} + +/** A day-form bound as whole days + whole hours, e.g. "2 days + * 4 hours" — the compound form's per-bound rendering (§4). */ +function daysHours(offsetMs: number): string { + const totalHours = Math.round(offsetMs / 3_600_000); + const days = Math.floor(totalHours / 24); + const hours = totalHours - days * 24; + const dPart = `${days} day${days === 1 ? "" : "s"}`; + if (hours === 0) return dPart; + if (days === 0) return `${hours} hour${hours === 1 ? "" : "s"}`; + return `${dPart} ${hours} hour${hours === 1 ? "" : "s"}`; +} + /** The stored `rendered` string for a prediction range (§4): * what was shown is exactly what is scored, so it is produced * once, at issuance, by this formatter. */ @@ -126,15 +149,18 @@ export function renderPredictionRange(earliestISO: string, latestISO: string, is const earliest = Date.parse(earliestISO); const latest = Date.parse(latestISO); const issued = Date.parse(issuedAtISO); - if (dayKeyFmt.format(new Date(earliest)) !== dayKeyFmt.format(new Date(latest))) { - return `between ${chicagoDaypart(earliest, issued)} and ${chicagoDaypart(latest, issued)}`; - } const spanH = (latest - earliest) / 3_600_000; - if (spanH >= 48) { + if (spanH >= 48 && earliest > issued) { const roundTenth = (x: number) => Math.round(x * 10) / 10; - return `${fmtNum(roundTenth((earliest - issued) / 86_400_000))} to ${fmtNum( - roundTenth((latest - issued) / 86_400_000), - )} days`; + const earliestDays = (earliest - issued) / 86_400_000; + const latestDays = (latest - issued) / 86_400_000; + if (isExactTenthDay(earliest - issued) && isExactTenthDay(latest - issued)) { + return `${fmtNum(roundTenth(earliestDays))} to ${fmtNum(roundTenth(latestDays))} days`; + } + return `${daysHours(earliest - issued)} to up to ${daysHours(latest - issued)}`; + } + if (dayKeyFmt.format(new Date(earliest)) !== dayKeyFmt.format(new Date(latest))) { + return `between ${chicagoDaypart(earliest, issued)} and ${chicagoDaypart(latest, issued)}`; } if (earliest <= issued) { // Already in progress: "from now" cannot express a start in diff --git a/pm-stack/aggregator/src/quota-reset-duration.test.ts b/pm-stack/aggregator/src/quota-reset-duration.test.ts index 12ffb719c..1d923dd87 100644 --- a/pm-stack/aggregator/src/quota-reset-duration.test.ts +++ b/pm-stack/aggregator/src/quota-reset-duration.test.ts @@ -97,7 +97,7 @@ describe("deriveResetDurationRecords — published reset, ranged by observed jit expect(r.basis.name).toBe("reset_cadence"); expect(r.basis.detail).toContain("reopening anchored on the published resetsAt"); expect(r.basis.detail).toContain("already walled at issuance"); - expect(r.methodology_version).toBe("c4-meth:1"); + expect(r.methodology_version).toBe("c4-meth:2"); expect(r.state).toBe("predicted"); expect(r.state_reason).toBeNull(); expect(r.supersedes).toBe("c4:reset_duration:claude:5-hour:1"); diff --git a/pm-stack/aggregator/src/quota-reset-duration.ts b/pm-stack/aggregator/src/quota-reset-duration.ts index 78dc06779..a9c6953bc 100644 --- a/pm-stack/aggregator/src/quota-reset-duration.ts +++ b/pm-stack/aggregator/src/quota-reset-duration.ts @@ -51,7 +51,7 @@ // what is scored. // // Basis (§1: mandatory, singular): reset_cadence for every -// record this module emits. Methodology version c4-meth:1 (the +// record this module emits. Methodology version c4-meth:2 (the // C4 methodology log, §6 — the version every C4 kind's first // records name). Advisory only: no placement path reads these // records — the C6 pages and forecast alerts named by #9572