Skip to content

fix(aggregator): re-derive the price overlay at serve time for cached AA batches (#8211) - #8349

Merged
dezren39 merged 1 commit into
mainfrom
queue/14715-8211-aa-price-overlay
Nov 10, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/14715-8211-aa-price-overlay

Conversation

@dezren39

@dezren39 dezren39 commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Fixes #8211 (queue task 14715): cached historical AA batches froze the v_current_prices overlay.

Context

PR #7564 (merged after this issue was filed from its Codex review) validity-keyed the collector caches on the price overlay: on a price change the collector invalidates historical caches and rebuilds them a few per tick, and the live source stale-marks versions awaiting rebuild. What remained: a cache entry the collector still considered valid was served verbatim — batch-bound payload and frozen price snapshot together — and there was no serve-time separation of the overlay from the batch payload, so a historical batch could report old token rates as current with no marker.

Change

  • aaApplyPriceOverlay(section, prices) (src/aa.ts): re-derives a section's price overlay — replaces prices and recomputes every catalog entry's rate through the same full-id / model-part lookup aaCatalogFromConfig uses — leaving all batch-bound data (rankings, configs, thresholds, test runs, sources, cai, coverage, catalog membership) untouched and not mutating the input.
  • Live source, historical branch (src/sources/live.ts): when a cached entry's pricesFingerprint differs from the fingerprint of the feed's current (latest-section) prices, the served section is the cached payload with the current overlay applied — same prices and catalog rates as the latest section, with no refetch of batch-bound measurements. When the feed carries no current overlay and the cached section has prices, it is served stale with a reason naming the price overlay, never silently. The collector-flagged awaiting-rebuild path is unchanged.

Tests

bun test test/aa.test.ts test/aa-batches.test.ts — 65 pass, 0 fail:

  • aa.test.ts: two cached batches built with differing prices both report the refreshed overlay's prices/rates after one aaApplyPriceOverlay; batch-bound fields untouched, inputs unmutated; empty overlay clears prices and nulls rates like a fresh build.
  • aa-batches.test.ts: live source serves a stale-fingerprint cached batch with the feed's current overlay (not stale-marked); and serves a priced cached batch stale with a price-overlay reason when the feed has no AA section.

Note for local runs: aa.test.ts boots a server whose freshness IPC port defaults to 4871; with a standing aggregator on the laptop that collides (pre-existing, also on clean main) — PM_AGG_FRESHNESS_PORT=<free port> avoids it. bunx tsc --noEmit error count is unchanged from main (16, all pre-existing in test files).


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

… AA batches (#8211)

aaApplyPriceOverlay separates the batch-bound payload from the
batch-independent v_current_prices overlay: prices and catalog rates
are recomputed from the current overlay, batch data untouched. The
live source applies it to historical cache entries whose stored
overlay fingerprint differs from the feed's current one, and serves
priced cached batches stale-marked when no current overlay exists
to refresh from.
@dezren39
dezren39 requested a review from a team as a code owner November 10, 2026 23:22
@coderabbitai

coderabbitai Bot commented Nov 10, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 54 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 268522a2-12cb-434a-8b55-91ebf6bef437
Commits

Reviewing files that changed from the base of the PR and between 1bfc91d and 94ab3d4.

Files selected for processing: 4

  • pm-stack/aggregator/src/aa.ts
  • pm-stack/aggregator/src/sources/live.ts
  • pm-stack/aggregator/test/aa-batches.test.ts
  • pm-stack/aggregator/test/aa.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-10T23:25:42.087647Z 94ab3d4 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39
dezren39 merged commit 0babf81 into main Nov 10, 2026
1 of 9 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 94ab3d41fe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +1853 to +1854
provenance.aa = `live (fleet feed · historical batch ${batch.slice(0, 8)} · collected ${parsed.section.generatedAt} · price overlay refreshed at serve)`;
return { ...aaApplyPriceOverlay(parsed.section, currentPrices), batches: batchList };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Verify the latest overlay is current before replacing cached prices

When prices change without a new workbook batch or config change, this can replace freshly collected historical prices with older prices and serve them without a stale marker. In scripts/collect-fleet-feed.ts:658–675, the collector reuses lastGood.section for the latest batch without checking its price fingerprint, while historical batches are rebuilt against the new prices at lines 704–705 and marked cached. Consequently, the historical cache contains the new overlay but feed.aa.prices still contains the old one; this fingerprint mismatch then triggers a rollback of the historical prices and catalog rates. Ensure the feed overlay is validated against the collector's current-price fingerprint before treating it as authoritative.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aggregator(aa-explorer): cached historical AA batches freeze the v_current_prices overlay — version switching silently switches token rates

1 participant