Skip to content

feat(pm-stack): C4.1 complete-downtime window records on gatherer ticks (#13257) - #13295

Merged
dezren39 merged 1 commit into
mainfrom
lane-wa-13257
Nov 23, 2026
Merged

dezren39 merged 1 commit into
mainfrom
lane-wa-13257

Conversation

@dezren39

@dezren39 dezren39 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

What

Implements acceptance criteria 1 and 3 of #13257 (C4.1, component of #9572): complete-downtime window predictions, published on gatherer ticks in the C4 design's record format.

Design conformance note: the C4 design (c4-forecasting-design.md, PR #13268) landed while this slice was in flight. This PR was reconciled to it before merge — record schema (§1), storage (the quota-predictions.jsonl log + Turso mirror under source quota-prediction), basis enum, honesty states, and §7's derivation are all the design's, not a parallel shape.

  • pm-stack/aggregator/src/quota-downtime.ts (new): pure derivation over one tick's Stage-3 forecast product (quota-forecast.json, impl(quota-plane): stage-3 S1 — forecast product: per-tick quota-forecast from the analytics pace math #12695). Per-pool wall intervals [wall, reset) are intersected across every routing pool (canonical provider id; a provider is down while any of its pool rows' windows is down). Each record: earliest = the last member wall, latest = the earliest member reset (the first reopening), basis = since_last_reset with detail, inputs (series/samples/span, adjustments: []), the §4 rendered string produced at issuance by the shared formatter (renderPredictionRange: duration / day / calendar forms, America/Chicago), methodology_version: c4-meth:1, and the supersedes link.
  • pm-stack/aggregator/c4-methodology-log.jsonl (new): the §6 methodology log's first entry, versioned into the repo with the code change that implements it.
  • pm-stack/aggregator/scripts/gather-quota.ts: fail-soft block after the forecast publication — derives the tick's records, appends them to quota-predictions.jsonl beside the forecast product (path overridable via QUOTA_PREDICTIONS_PATH), and mirrors them into the ledger via the existing forecast Turso sink. The supersedes chain reads the log's tail (fail-soft). A null forecast derives nothing; previous records stand and age with the previous forecast. Advisory only: no placement path reads these records.
  • Tests: src/quota-downtime.test.ts (15 tests) plus a new assertion block in test/gather-quota.test.ts proving the tick appends the downtime record beside the forecast product.

Honesty rules (§1, criterion 3)

  • A predicted window is asserted only from known wall intervals. Providers the forecast cannot project (insufficient-history windows) can only add downtime, so a known overlap still publishes as predicted with the unknown providers named in the basis detail — but unknowns veto a no-window verdict: no known overlap + any unknown provider publishes an insufficient_history record with a named reason, never a silent absence and never an invented range.
  • An all-walled overlap that no member reset bounds is an honesty state, not an unbounded prediction.
  • A defensible no-window tick publishes no record — per §3 scoring, absence is the no-prediction signal (a realized downtime with no prediction scores as a miss).

Verification (laptop route)

  • bun test src/quota-downtime.test.ts — 15 pass / 0 fail.
  • Mutation check: flipping the intersection quantifier (every → some) fails 9 of 15 tests; restored, all green.
  • bun test test/gather-quota.test.ts src/quota-forecast.test.ts src/quota-forecast-accuracy.test.ts — 38 pass / 0 fail.
  • bunx tsc --noEmit — 0 errors (worktree node_modules symlinked from the primary checkout; a bare worktree lacks the bun type definitions).
  • Remote dispatch attempted (run 45178762980, handle fp_696c5e6b26f9d0b684d51b10efaa9778): failed at the "Execute target command" step — the fleet-build container has no bun (the fleet: fleet-command dispatch container cannot run nix develop out of the box (experimental features, nixbld group, homeless-shelter purity) #13159 environment-gap family), so it is not a test result; the laptop runs above are the verifying route.

Remaining on #13257

Criterion 2 — scoring downtime windows per §3 (start/end error, interval overlap) in the accuracy ledger — is the next slice; the records mirrored here are its input. The issue stays open.

Refs #13257, #9572.

@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 39 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: e1d14026-ee3f-4dda-8ad3-5d650b90b82f
Commits

Reviewing files that changed from the base of the PR and between 1845798 and 6569d04.

Files selected for processing: 5

  • pm-stack/aggregator/c4-methodology-log.jsonl
  • pm-stack/aggregator/scripts/gather-quota.ts
  • pm-stack/aggregator/src/quota-downtime.test.ts
  • pm-stack/aggregator/src/quota-downtime.ts
  • pm-stack/aggregator/test/gather-quota.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 23, 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-23T13:16:42.437318Z 6569d04 New commits
ℹ️ 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.

@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: b11b655e9b

ℹ️ 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".

const spans: DowntimePoolSpan[] = [];
let latest = -Infinity;
for (const intervals of perPool) {
const iv = covers(intervals, start) as WallInterval;

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 Account for every binding limit in the latest reopening

When a pool has multiple overlapping wall intervals, covers() selects only the first one, so latest ignores other limits that still block that pool. For example, a single pool with two already-walled windows resetting at +1h and +10h produces reopening.earliest = +10h but reopening.latest = +1h; reversing the window order changes the result. This publishes an inverted reopening range and an incorrect full-restoration bound in both the JSON product and ledger. Compute the bound from all relevant blocking intervals rather than the first covering window.

Useful? React with 👍 / 👎.

Comment on lines +45 to +46
describe("deriveDowntimeWindow", () => {
test("overlapping walls predict a window with the intersection range and named basis", () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add generated coverage for the downtime interval model

This suite contains only hand-written examples, although the new engine has union/intersection, maximal-window, and input-order invariants. AGENTS.md requires “property tests” where code has invariants and “model-based tests” where a model exists; acceptance examples alone do not satisfy that requirement. Add generated pool/window combinations checked against an independent interval-set oracle, including overlapping limits within a pool and permutation invariance—the current examples miss the order-dependent reopening calculation.

AGENTS.md reference: AGENTS.md:L37-L39

Useful? React with 👍 / 👎.

)

Publish downtime_window prediction records on gatherer ticks, in
the C4 design's record format (doc/2026-11-13T15-12-00Z_design_
reporting-architecture-event-driven/c4-forecasting-design.md §1/§7,
landed by PR #13268): appended to quota-predictions.jsonl beside
the forecast product and mirrored into the Turso ledger under the
C4 source "quota-prediction".

src/quota-downtime.ts derives each record from the tick's Stage-3
forecast product (#12695): per-pool wall intervals [wall, reset)
intersected across every routing pool (canonical provider id);
earliest = the last member wall, latest = the earliest member
reset; basis since_last_reset, named with its detail; the §4
range rendering stored at issuance; supersedes linked from the
log's tail. Honesty per §1 and #13257 criterion 3: providers the
forecast cannot project publish insufficient_history with a named
reason (and veto a no-window verdict); an overlap no member reset
bounds is an honesty state, not an unbounded prediction; a
defensible no-window tick publishes no record — absence is the
scored no-prediction signal. First methodology entry c4-meth:1
recorded in c4-methodology-log.jsonl (§6).

Acceptance: criteria 1 (records published on gatherer ticks) and
3 (honesty state) of #13257. Criterion 2 (scoring per §3 in the
accuracy ledger) is the next slice; the mirrored records are its
input.

Tests: src/quota-downtime.test.ts (15 tests: record shape,
intersection range, in-progress windows, union within a provider,
disjoint overlaps, honesty states, supersedes, §4 rendering,
ledger mirror), mutation-checked; the gather-quota integration
test now also asserts the tick appends the downtime record.
Oracle: the C4 design §1/§7 over the #12695 forecast product.
@dezren39
dezren39 merged commit 619b7e5 into main Nov 23, 2026
1 check passed
@dezren39
dezren39 deleted the lane-wa-13257 branch November 23, 2026 13:15

@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: 6569d04a58

ℹ️ 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 +276 to +278
const bounded = overlaps.filter((o) => Number.isFinite(o.end));
if (bounded.length > 0) {
return bounded.map((o) => {

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 Preserve the honesty state for an unbounded trailing overlap

When a tick contains both a finite complete-downtime interval and a later unbounded one, this early return silently drops the unbounded interval and bypasses the insufficient_history branch below. For example, a single provider with windows [+1h, +2h) and [+3h, Infinity) publishes only the first prediction, without disclosing that another all-walled interval cannot be bounded. Preserve an honesty record for the unbounded overlap even when finite predictions also exist, so the JSONL log and ledger distinguish an unbounded forecast from no prediction.

Useful? React with 👍 / 👎.

const records = deriveDowntimeWindowRecords(forecast, previous);
if (records.length) {
await mkdir(dirname(predictionsPath), { recursive: true });
await appendFile(predictionsPath, records.map((r) => JSON.stringify(r)).join("\n") + "\n", "utf8");

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 Separate new records from a torn log tail before appending

If a previous append was interrupted before its terminating newline, the parser skips the torn final line, but this append concatenates the next tick's first record directly onto that fragment. The resulting line is invalid JSON, so the first new prediction is also lost from the readable log and cannot become a subsequent supersedes target; for the usual single-record tick, this loses the entire tick locally even though the ledger write proceeds. Repair or delimit an unterminated tail before appending new records so the intended torn-log recovery preserves the next prediction.

Useful? React with 👍 / 👎.

): C4PredictionRecord[] {
const issuedAt = forecast.generatedAt;
const issuedMs = Date.parse(issuedAt);
const providerIds = Object.keys(forecast.pools).sort();

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 Restrict the downtime intersection to enabled routing providers

The forecast's provider keys are not exclusively routing pools: gather-quota.ts:264–278 explicitly requests quota for disabled doors, and collectRuns() retains those results in the entries passed to buildQuotaForecast(). In the checked .opencode/opencode.jsonc:350–363, _commandcode and deepseek are disabled but still explicitly gathered. Consequently, when every enabled routing provider is walled but one of these disabled providers has a no-wall-before-reset forecast, its empty down-set makes this function return no downtime prediction, even though that provider cannot serve as a fallback. Pass the enabled routing set into the derivation and intersect only those providers, while retaining disabled-provider measurements in the broader forecast product.

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.

1 participant