Skip to content

feat(exporters): quota-watchdog decision layer — failure classes + repair ladder (#6032 slice 1) - #7788

Merged
dezren39 merged 3 commits into
mainfrom
queue/13006-6032-quota-watchdog-core
Nov 9, 2026
Merged

dezren39 merged 3 commits into
mainfrom
queue/13006-6032-quota-watchdog-core

Conversation

@dezren39

@dezren39 dezren39 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Slice 1 of #6032 (design #6031). This lands the pure decision layer of the generic browser-dependent quota watchdog — the part the issue calls out as the natural fit for PBT/MBT — and leaves the I/O, browser and deployment shell to a follow-up with the boundary written down.

What lands

pm-stack/exporters/src/watchdog-state.ts

  • Failure classes — session-expired, cookie-missing, endpoint-changed, browser-down, cdp-unreachable, rate-limited, unknown, and the single place a class maps to a repair rung.
  • Repair ladder — decide() returns the next action (quiet, wait-cooldown, retry, repair rung N, human-blocked, escalate) plus the next persisted record. Per-rung attempts are capped at 2 per incident; a rate-limited source sets cooldownUntil on disk and the next tick honors it with no browser action; a rate limit whose cooldown rung is spent escalates rather than climbing to a browser repair.
  • Disk state — SourceHealth carries lastAttemptAt, lastSuccessAt, consecutiveFailures, currentClass, sanitized lastDetail, cooldownUntil, per-rung rungAttempts, a bounded (20) repairLog, and the incident identity + surfacing flag. coerceHealth reads a file back without trusting it: garbage yields a fresh record, never a throw and never an assumed-healthy.
  • Sanitization — credential-shaped text is redacted before it can reach the state file or a log.

No I/O, no browser, no secrets, no provider names — the core is provider-agnostic by construction, which is what the adapter-loader criterion asks for.

Tests name their oracles

pm-stack/exporters/test/watchdog-state.test.ts — 12 pass, 0 fail:

  • PBT invariants over generated tick sequences: per-rung attempts never exceed the cap; the repair log stays bounded; consecutiveFailures is monotonic while failing and resets on success; a healthy tick always clears the incident and is quiet; no secret-shaped value survives sanitization.
  • MBT — a reference model of the ladder written independently of the implementation, stepped in lockstep over 300 generated sequences; any divergence in action, rung, or failure count fails.
  • Acceptance fixtures: the broken-source walk (retry → CDP re-validation → re-login → escalation), the rate-limited cooldown persisted and honored then escalating, the human-only challenge marking the incident human-blocked with the surfacing flag and not re-hammering, and the healthy source staying quiet.
cd pm-stack/aggregator && bun test ../exporters/test/watchdog-state.test.ts

Typecheck of both new files is clean under the repo's strict settings.

What remains for #6032 (listed in pm-stack/exporters/README.md)

The oneshot entry point (state read/write, latest.json + heartbeat reads, history append), the adapter loader and adapters/, the rung 2/3 executors, the rung-4 hand-off to #6033, producer scaffolding, and the systemd oneshot + timer. The issue stays open for those.

Refs #6032, #6031.


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

…pair ladder (#6032)

Slice 1 of the generic browser-dependent quota watchdog core (#6032,
design #6031): the pure decision layer the oneshot will drive.

- Failure-class vocabulary and the single class -> repair-rung mapping.
- Repair ladder with per-rung attempt caps (max 2 per incident), a
  disk-honored rate-limit cooldown, and escalation once rungs are spent.
- Persisted per-source health record (attempts, cooldown, bounded repair
  log, incident identity + surfacing flag) and a non-throwing reader for
  a state file that cannot be trusted.
- Detail sanitization so no credential-shaped text reaches disk or logs.

Tests name their oracles per the testing doctrine: PBT invariants over
generated tick sequences, an MBT reference ladder model stepped in
lockstep, and the four acceptance fixtures. 12 pass, 0 fail.

No I/O, no browser, no provider names: the entry point, adapter loader,
rung 2/3 executors, escalation hand-off, producer scaffolding and systemd
units remain for the follow-up (listed in pm-stack/exporters/README.md).
@dezren39
dezren39 requested a review from a team as a code owner November 8, 2026 19:24
@coderabbitai

coderabbitai Bot commented Nov 8, 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 38 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: add8358a-31c9-42b0-b964-715ec013acc4
Commits

Reviewing files that changed from the base of the PR and between acdfd55 and 88b0040.

Files selected for processing: 3

  • pm-stack/exporters/README.md
  • pm-stack/exporters/src/watchdog-state.ts
  • pm-stack/exporters/test/watchdog-state.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 8, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-09T03:47:06.153199Z
We couldn’t complete this review. Comment @codex review to try again.
83b2c3a 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: 5ce48a5297

ℹ️ 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 +121 to +122
.replace(/(cookie|authorization|token|bearer|session|password|secret)\s*[:=]\s*\S+/gi, "$1=<redacted>")
.replace(/[A-Za-z0-9_-]{32,}/g, "<redacted>");

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 Redact complete authorization and cookie values

When a detail contains a normal authorization header such as Authorization: Bearer abc123, this replacement consumes only Bearer, leaving abc123 intact. Likewise, Cookie: sid=abc123; csrf=def456 retains the second cookie. Values shorter than 32 characters also survive the following replacement, so decide, recordRungOutcome, and coerceHealth can retain credentials in fields explicitly intended to be sanitized before persistence. Handle authorization schemes and complete cookie values rather than redacting only the first whitespace-delimited token.

Useful? React with 👍 / 👎.

Comment on lines +192 to +194
rung: 1,
outcome: "succeeded",
detail: "source recovered; incident closed",

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 Record recovery without inventing a rung-1 success

When a source recovers after a rung-0 cooldown, rung-2 browser repair, or rung-3 login, this branch always appends a successful rung-1 repair. For example, a session-expired observation followed by a healthy observation produces a rung-3 attempt followed by a rung-1 success, although rung 1 was never attempted. This makes the persisted repair history misattribute recovery. Represent incident closure separately from a rung outcome, or associate the recovery with the actual repair rather than hard-coding rung 1.

Useful? React with 👍 / 👎.

// - Example tests: the four fixtures the acceptance criteria name
// (broken-source walk, rate-limited cooldown, human challenge, quiet
// when healthy).
import { describe, expect, test } from "bun:test";

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 Register and wire the watchdog suite into a CI venue

The new suite is absent from .github/test-suite-registry.json, and repository-wide searches of the reviewed commit found no workflow or flake invocation naming it; the only explicit invocation is the manual README command. Checked .github/workflows/pm-stack-tests.yml: its push/PR path filters exclude pm-stack/exporters/**, and its test steps do not name this suite. The coverage contract in .github/ci-policy.md:195–201 explicitly requires registration and a venue naming the suite files, so these state-machine invariants currently have no automated verification venue. Register the suite and add an explicit CI test step with the required existence check.

AGENTS.md reference: AGENTS.md:L34-L34

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@dezren39
dezren39 merged commit aa01b61 into main Nov 9, 2026
1 of 4 checks passed
@dezren39
dezren39 deleted the queue/13006-6032-quota-watchdog-core branch November 9, 2026 03:47
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

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

Labels

queue/parked Queue task is parked (waiting on CI, time, or an event) status/parked Deliberately paused with a recorded resume condition

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant