diff --git a/pm-stack/aggregator/src/derive.ts b/pm-stack/aggregator/src/derive.ts index 44637ce262..7775580686 100644 --- a/pm-stack/aggregator/src/derive.ts +++ b/pm-stack/aggregator/src/derive.ts @@ -1097,7 +1097,12 @@ export function projectPace(records: SnapshotRecord[], metricId: string): PacePr if (Number.isFinite(candidate.getTime())) projectedExhaustionAt = candidate.toISOString(); } let projectedPercentAtReset: number | null = null; - if (last.resetsAt) { + // Same out-of-domain guard as projectedExhaustionAt above (#6316): + // a negative last pct cannot support a percent-at-reset projection + // either -- the unguarded extrapolation rendered absurd values + // (e.g. -999999995.5) for poisoned series whose last record carried + // a future resetsAt. Slope and points are still reported. + if (lastVal >= 0 && last.resetsAt) { const toReset = (Date.parse(last.resetsAt) - Date.parse(last.ts)) / 86_400_000; if (toReset > 0) projectedPercentAtReset = Math.round((lastVal + slope * toReset) * 10) / 10; } diff --git a/pm-stack/aggregator/test/usage.test.ts b/pm-stack/aggregator/test/usage.test.ts index 6ea489d7a8..b084d99264 100644 --- a/pm-stack/aggregator/test/usage.test.ts +++ b/pm-stack/aggregator/test/usage.test.ts @@ -534,6 +534,19 @@ describe("pace + freshness (§4, §1.1)", () => { const ok = projectPace([rec("2026-10-22T00:00:00Z", 30), rec("2026-10-24T00:00:00Z", 40)], "weekly")!; expect(ok.projectedExhaustionAt?.slice(0, 10)).toBe("2026-11-05"); }); + test("pace: negative pct with a future resetsAt yields no percent-at-reset projection (#6316)", () => { + // The #2346 poison fixture, now with resetsAt on the last record: + // -1e9 -> -999999999 over 2 days, reset +7 days. Before the guard, + // projectPace returned projectedPercentAtReset -999999995.5. + const poison = projectPace( + [rec("2026-10-22T00:00:00Z", -1e9), rec("2026-10-24T00:00:00Z", -999999999, "2026-10-31T00:00:00Z")], + "weekly", + )!; + expect(poison.projectedPercentAtReset).toBeNull(); + expect(poison.projectedExhaustionAt).toBeNull(); + expect(poison.slopePerDay).toBe(0.5); + expect(poison.points).toBe(2); + }); test("no projection from a single point or a flat series", () => { expect(projectPace([rec("2026-10-24T00:00:00Z", 30)], "weekly")).toBeNull(); expect(projectPace([rec("2026-10-22T00:00:00Z", 30), rec("2026-10-24T00:00:00Z", 30)], "weekly")).toBeNull();