GeezerVison is showing github.com — fix(aggregator): surface quota sanitization loss + reconcile choices … · developing-today/code@880b038
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: pm-stack/aggregator/src/feed.ts +23-3Lines changed: 23 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -340,11 +340,31 @@ export function sanitizeQuotaView(quota: QuotaView): QuotaSanitization { | 340 | 340 | return out; | 341 | 341 | }); | 342 | 342 | const burn = arrayOf(isBurnSegment)(quota.burn); | | 343 | + const droppedPools = pools?.dropped ?? 0; | | 344 | + const droppedBurn = burn?.dropped ?? 0; | | 345 | + // Guidance must describe the surviving usable pools only: the | | 346 | + // retained choices were computed over the pre-sanitization pools, | | 347 | + // and computeChoices() (quota-guidance.ts) gives no guidance for a | | 348 | + // pool with no windows — so filter every list to kept pools that | | 349 | + // still have windows. A pool whose data was discarded must not | | 350 | + // stay recommended under hasHeadroom or burnBeforeReset. | | 351 | + const usable = new Set(keptPools.filter((p) => p.windows.length > 0).map((p) => p.id)); | | 352 | + const choices = { | | 353 | + hasHeadroom: quota.choices.hasHeadroom.filter((id) => usable.has(id)), | | 354 | + burnBeforeReset: quota.choices.burnBeforeReset.filter((id) => usable.has(id)), | | 355 | + doNotStart: quota.choices.doNotStart.filter((id) => usable.has(id)), | | 356 | + }; | | 357 | + const view: QuotaView = { ...quota, pools: keptPools, burn: burn?.values ?? [], choices }; | | 358 | + // Surface the loss on the view itself (its consumers project the | | 359 | + // view, e.g. /api/quota.json), not only on the feed wrapper. | | 360 | + if (droppedPools + droppedWindows + droppedBurn > 0) { | | 361 | + view.dropped = { pools: droppedPools, windows: droppedWindows, burn: droppedBurn }; | | 362 | + } | 343 | 363 | return { | 344 | | - view: { ...quota, pools: keptPools, burn: burn?.values ?? [] }, | 345 | | - droppedPools: pools?.dropped ?? 0, | | 364 | + view, | | 365 | + droppedPools, | 346 | 366 | droppedWindows, | 347 | | - droppedBurn: burn?.dropped ?? 0, | | 367 | + droppedBurn, | 348 | 368 | }; | 349 | 369 | } | 350 | 370 |
| |
Collapse file Copy file name to clipboardExpand all lines: pm-stack/aggregator/src/model.ts +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -325,6 +325,12 @@ export interface QuotaView { | 325 | 325 | /** Gatherer overlay provenance (#1151); absent when no | 326 | 326 | * quota-current.json was read. Additive for existing consumers. */ | 327 | 327 | gatherer?: GathererSummary; | | 328 | + /** Feed-load sanitization counts (#2429): present only when the | | 329 | + * loader dropped malformed pools/windows/burn segments, so an | | 330 | + * incomplete read is distinguishable from a successful empty one | | 331 | + * in the public payload (/api/quota.json projects this view). | | 332 | + * Additive for existing consumers. */ | | 333 | + dropped?: { pools: number; windows: number; burn: number }; | 328 | 334 | burn: BurnSegment[]; | 329 | 335 | /** Guidance for choosing the next pool (burn order + reset rules). */ | 330 | 336 | choices: { | |
Collapse file Copy file name to clipboardExpand all lines: pm-stack/aggregator/src/sources/live.ts +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -816,6 +816,10 @@ export function liveSource(cfg: Config, opts?: { standingAuto?: () => Promise<bo | 816 | 816 | if (feed) { | 817 | 817 | provenance.quota = `live (fleet feed · ${feedAgeText(feed.generatedAt)} · collected ${feed.generatedAt})`; | 818 | 818 | view = feed.quota; | | 819 | + const dropped = feed.quotaDropped; | | 820 | + if (dropped && dropped.pools + dropped.windows + dropped.burn > 0) { | | 821 | + provenance.quota += ` · sanitized at load: dropped ${dropped.pools} pool(s), ${dropped.windows} window(s), ${dropped.burn} burn segment(s) (#2429)`; | | 822 | + } | 819 | 823 | } else { | 820 | 824 | provenance.quota = "fixtures (no fleet feed file yet)"; | 821 | 825 | view = await fix.quota(); | |
Collapse file Copy file name to clipboardExpand all lines: pm-stack/aggregator/test/feed.test.ts +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -203,6 +203,20 @@ describe("feed quota section gate + sanitization (#2429)", () => { | 203 | 203 | expect(out.view).toEqual(q); | 204 | 204 | }); | 205 | 205 |
| | 206 | + test("choices are reconciled to surviving pools with usable windows", () => { | | 207 | + const noWindows = { ...POOL, windows: [null] }; | | 208 | + const out = sanitizeQuotaView(quotaWith([noWindows]) as never); | | 209 | + expect(out.view.pools.length).toBe(1); | | 210 | + expect(out.view.choices).toEqual({ hasHeadroom: [], burnBeforeReset: [], doNotStart: [] }); | | 211 | + expect(out.view.dropped).toEqual({ pools: 0, windows: 1, burn: 0 }); | | 212 | + }); | | 213 | + | | 214 | + test("a dropped pool leaves the retained choices and surfaces dropped on the view", () => { | | 215 | + const out = sanitizeQuotaView(quotaWith([null, POOL]) as never); | | 216 | + expect(out.view.choices.hasHeadroom).toEqual(["opencode-go"]); | | 217 | + expect(out.view.dropped).toEqual({ pools: 1, windows: 0, burn: 0 }); | | 218 | + }); | | 219 | + | 206 | 220 | test("loadFeed returns the sanitized remainder with drop counts attached", async () => { | 207 | 221 | const dir = mkdtempSync(join(tmpdir(), "agg-feed-quota-")); | 208 | 222 | const file = join(dir, "feed.json"); | @@ -213,6 +227,7 @@ describe("feed quota section gate + sanitization (#2429)", () => { | 213 | 227 | expect(loaded?.quota.pools.length).toBe(1); | 214 | 228 | expect(loaded?.quota.pools[0]?.windows).toEqual([WINDOW]); | 215 | 229 | expect(loaded?.quotaDropped).toEqual({ pools: 1, windows: 1, burn: 0 }); | | 230 | + expect(loaded?.quota.dropped).toEqual({ pools: 1, windows: 1, burn: 0 }); | 216 | 231 | }); | 217 | 232 |
| 218 | 233 | test("loadFeed rejects a feed missing burn/choices (fixture-fallback path)", async () => { | |
|