Repository navigation
feat(pm-stack): quota gatherer writes the babysitter pool-state feed (#1338) - #12689
Conversation
…1338) The claimant babysitter's verdict rounds read pool wall state from pool-state.json in the claimant state dir, an input file nothing wrote: on a live install every round recorded pool_state unread and no pool could ever read walled. This lands the writer half of the contract babysitter.py's header named as the follow-up slice. - src/pool-state.ts: pure projection of quota-current.json into the babysitter shape, keyed by the canonical OpenCode provider id (the id a session names as model.providerID). A wall is asserted only from a fresh ok entry (quota-current freshness bounds) under derive.ts poolState's rule (any window >= 100%); stale/errored entries surface as state with no wall and no percent, per quota-exhaustion's stale_source honesty rule. - gather-quota.ts: writes pool-state.json into the claimant state dir (POOL_STATE_PATH override) after quota-current.json, fail-soft like the Turso sink - a failed write warns and never fails the tick. - babysitter.py header now names the landed writer. Evidence (sandbox): fail-before on pristine origin/main (suite load error, no pool-state.ts); pass-after pool-state 11/11, neighbouring quota suites 39/39, claimant hermetic suite 203/203; cross-language contract check - babysitter.read_pool_state reads the projection back (fresh wall lands, stale wall does not). tsc clean for the touched files (3 pre-existing grist/roadmap.json errors from the sparse worktree, unrelated). No new dependencies.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Caution Review failedThe pull request is closed.
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 690bbc7e99
ℹ️ 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".
| if (entry.state !== "ok") return false; | ||
| const t = Date.parse(entry.measuredAt); | ||
| return Number.isFinite(t) && t - nowMs <= QUOTA_CURRENT_FUTURE_SKEW_MS && nowMs - t <= QUOTA_CURRENT_FRESH_MS; |
There was a problem hiding this comment.
Exclude retained readings from fresh pool-wall decisions
When a provider fetch fails on the next 15-minute tick, markRetained() preserves the previous entry's state: "ok" and measuredAt while setting retainedFromFailedTick. That reading is still inside the 20-minute freshness bound, so this predicate accepts it and can publish its old 100% window as a current wall. By contrast, quota-current.ts explicitly classifies retained entries as stale immediately. If the quota has reset, the new feed incorrectly labels genuinely stalled sessions as walled, suppressing stall nudges. Reject entries with retainedFromFailedTick before applying the timestamp check.
Useful? React with 👍 / 👎.
| await writeAtomic(poolStatePath, JSON.stringify(projectPoolState(file), null, 2) + "\n").catch((err) => | ||
| console.error(`quota-gatherer: pool-state write failed (${err}); babysitter pool state stays unread this tick`), |
There was a problem hiding this comment.
Expire published walls when the quota feed stops updating
After a successful tick publishes walled: true, a gatherer outage, early failTick() return, or subsequent write failure leaves that file in place indefinitely. babysitter.read_pool_state() ignores generatedAt and trusts the stored wall on every round, so the write failure does not make the state unread as this log claims. Once quota resets, genuinely stalled sessions can remain classified as walled indefinitely and never receive stall nudges. Add read-time expiry for the published snapshot, returning unknown/unread once its freshness bound is exceeded; checking freshness only during projection cannot protect against a stopped writer.
Useful? React with 👍 / 👎.
| const list = byProvider.get(entry.providerId) ?? []; | ||
| list.push(entry); | ||
| byProvider.set(entry.providerId, list); |
There was a problem hiding this comment.
Preserve the configured OpenAI instance IDs in pool-state keys
For folded OpenAI quota results, entryFromResult() in quota-gather-map.ts preserves providerId: "_openai" but recovers the credential's actual instance ID into serviceId (_openai.main or _openai.alt). The configured openai-plan uses those two instance IDs (.opencode/opencode.jsonc:2635), and the babysitter looks up each session's exact model.providerID. Grouping solely by entry.providerId therefore publishes the OpenAI wall under the retired bare _openai key, so neither configured instance can read as walled and quota-blocked sessions can incorrectly receive stall nudges. Use the recovered instance ID for these folded OpenAI entries rather than collapsing them under _openai.
Useful? React with 👍 / 👎.
Summary
Lands #1338's remaining code slice — the
pool-state.jsonquota feed — under epic #1334 (whose reconciliation is posted at #1334 (comment)).The babysitter's verdict rounds (PR #12687) read pool wall state from
pool-state.jsonin the claimant state dir, an input file nothing wrote: on a live install every round would recordpool_state: "unread"and no pool could ever read walled, so a quota wall would still be misreadable as a stall. babysitter.py's own header named this wiring as the follow-up slice.pm-stack/aggregator/src/pool-state.ts— pure projection of the gatherer'squota-current.jsoninto the babysitter's shape, keyed by the canonical OpenCode provider id (the id a session names asmodel.providerID; the aggregator's service ids are a separate contract and never appear). Wall rule isderive.tspoolState's (any window ≥ 100%); a wall is asserted only from a fresh ok entry (quota-current.ts freshness bounds) — stale/errored entries surface asstatewith no wall and no percent, per quota-exhaustion.ts's stale_source honesty rule. Several credentials sharing a providerId: any fresh ok one at its limit walls the pool.scripts/gather-quota.ts— writes the projection to the claimant state dir (POOL_STATE_PATHoverride, default~/.local/state/opencode-claimant/pool-state.json) after quota-current.json, fail-soft like the Turso sink: a failed write warns and never fails the tick; a missing feed reads as "unread" on the claimant side, never as a false all-clear.babysitter.pyheader now names the landed writer instead of the follow-up slice.No schedule is created or changed (the writer rides the gatherer's existing 15-minute tick), so the schedule registry is untouched. No new dependencies.
Evidence (sandbox venue)
git archive— load error,pool-state.tsabsent.pool-state.test.ts11/11; neighbouring quota suites (quota-gather-map,quota-analytics) — 39/39 across the three files; claimant hermetic suite 203/203.babysitter.read_pool_state— statusread; a fresh 100% pool landswalled: true, a 3-hour-stale 100% pool landswalled: false, state: "stale".tsc --noEmit: no errors in the touched files (3 pre-existing errors aboutgrist/seed/roadmap.json, absent from this sparse worktree, unrelated). Changed files formatted with the repo's pinned biome 2.3.2 / ruff per treefmt.Remaining on #1338 after this
Deployment + live verification only: the laptop claimant and gatherer pick the code up on install; three live babysitter rounds with a live pool-state feed tick criteria 1–2's live arm. This PR does not close #1338.
Refs #1338, #1334.
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.