Skip to content

impl(quota-plane): stage-3 S3 — shadow placement: forecast ordering logged beside live ordering (#12697) - #12748

Merged
dezren39 merged 2 commits into
mainfrom
felix/12697-shadow-placement
Nov 23, 2026
Merged

dezren39 merged 2 commits into
mainfrom
felix/12697-shadow-placement

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Stage-3 S3 implementation for #12697 (epic #12694, design D3 in doc/2026-11-22T22-35-00Z_design_quota-plane-stage-3). Deliberately does not close #12697: its first acceptance criterion is one week of accumulated shadow diff records, which is calendar time after this lands and the laptop aggregator redeploys; the issue stays open for that, with the summary to be posted on #12694.

What lands

pm-stack/aggregator/src/quota-shadow-placement.ts — a pure per-tick projection (S1/pool-state idiom: no I/O, clock only through arguments) emitting the per-decision diff record:

  • Live ordering — burn-by-expiry from the measured data (quota-current) alone: tiers open → unknown → caution (≥85%, NEAR_PCT) → walled, soonest reset first within a tier. Unknown is not closed: an unreadable pool stays in the ordering, it just has no measured expiry to burn by.
  • Shadow ordering — the same ordering with one adjustment: an open-tier pool whose consumed forecast projects a wall before its reset is demoted into the caution tier — before it reaches the caution zone. That is the whole forecast effect.
  • The record (quota-shadow-placement.json latest + one appended line per tick in quota-shadow-placement-history.jsonl): both orderings, the decision point (gatherer tick + the current/forecast products' generatedAt stamps), and per pool the measured inputs, every forecast window row with its honesty state and whether it was consumed or excluded (and why), both ranks, and movement reasons — everything S7 needs to score shadow-vs-live after the fact.

Consumption rules, binding S2's findings (#12696):

  • The bare opencode-go pool's monthly forecast is never consumed — S2 showed that series is a cross-workspace mixing artifact (precision 0.054 vs 0.93–1.0 per-workspace); the exclusion is logged on the record. Per-workspace pools consume their monthly rows normally.
  • insufficient-history rows are logged with state + reason, never consumed — no ordering is invented from an unscoreable series.
  • A forecast window whose underlying reading is outside quota-current's freshness bounds degrades to no forecast for that window (the design's freshness contract), logged as an exclusion.
  • The forecast can never promote a measured demotion, never remove a pool, never close anything. Weekly projections running late (S2) is calibration knowledge for S7, not a consumption rule — v1 consumes the projection as published and lets the shadow record measure how the demotions fare.

scripts/gather-quota.ts — after the forecast block (i.e. after every live output is written), the tick builds the record from the in-process forecast (null if the forecast failed — the record still lands, shadow == live) and writes both files, fail-soft like the forecast and pool-state writes. QUOTA_SHADOW_PLACEMENT_PATH / QUOTA_SHADOW_PLACEMENT_HISTORY_PATH override the defaults beside QUOTA_CURRENT_PATH. No live path reads the record.

Evidence (sandbox venue)

  • Fail-before: the new suite on pristine origin/main fails with module-not-found (./quota-shadow-placement.ts), the expected whole-surface-missing failure.
  • Pass-after: quota-shadow-placement.test.ts 14/14 (63 expects), including the no-live-effect battery — live ordering identical across forecast variants (null, empty, every-pool-projected-to-wall, honesty-only, stale) and equal to the exported liveOrderingFor(current) — the demotion-before-caution case, the bare-opencode-go exclusion vs per-workspace consumption, and the permutation property (shadow never adds/removes a pool).
  • Neighbours: quota-forecast + quota-forecast-accuracy + pool-state + quota-analytics + quota-gather-map suites green (82/82 across the six files).
  • Full aggregator suite: 3,225 pass / 4 fail — the same 4 tests fail identically on pristine origin/main in the same venue (verified by a scratch-worktree run): deriveEpicEta censored-distribution (timing), charges feed-gate fallback, parsePhaseMapping real-file read, dashboard: clean up the page list (12 registered pages, overlaps to resolve) #1497 curation manifest. Zero new failures.
  • tsc --noEmit clean; biome check clean on the three changed files. No new dependencies.

What remains


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

felix added 2 commits November 23, 2026 01:08
…live ordering (#12697)

Stage-3 S3 (design D3): a pure projection over the tick's
quota-current + quota-forecast that computes the live placement
ordering (burn-by-expiry, measured data only) and the shadow
ordering (an open pool projected to wall before its reset is
demoted into the caution tier, before the caution zone), and emits
the per-decision diff record S7 scores: both orderings, the
decision point, per-pool measured inputs, every forecast window
row with its honesty state and consumption verdict, both ranks,
movement reasons.

Consumption binds S2's findings: the bare opencode-go monthly
forecast (cross-workspace mixing artifact) is never consumed and
the exclusion is logged; insufficient-history rows are logged,
never consumed; a stale forecast reading degrades to no forecast.
The forecast can never promote a measured demotion, remove a
pool, or close anything; the live ordering is a function of the
measured data alone (pinned by tests across forecast variants:
null, empty, all-wall, honesty-only, stale).
After the forecast block, each tick writes quota-shadow-placement
.json beside quota-current.json and appends the record to
quota-shadow-placement-history.jsonl (QUOTA_SHADOW_PLACEMENT_PATH
/ QUOTA_SHADOW_PLACEMENT_HISTORY_PATH override). Fail-soft like
the forecast: a shadow failure never fails the tick, and a failed
forecast still yields a record with shadow == live. No live path
reads the record.
@dezren39
dezren39 requested a review from a team as a code owner November 23, 2026 01:08
@coderabbitai

coderabbitai Bot commented Nov 23, 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 48 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: a369c4d4-d25d-4d91-8a9c-bd1f42fe43e9
Commits

Reviewing files that changed from the base of the PR and between a7e088c and 8675bbc.

Files selected for processing: 3

  • pm-stack/aggregator/scripts/gather-quota.ts
  • pm-stack/aggregator/src/quota-shadow-placement.test.ts
  • pm-stack/aggregator/src/quota-shadow-placement.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

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.

impl(quota-plane): stage-3 S3 — shadow placement: forecast-informed ordering logged beside live ordering

1 participant