GeezerVison is showing github.com — Quota-aware session placement: filter by quota % and session type (root vs subsession) · Issue #566 · developing-today-forks/opencode
Quota-aware session placement: filter by quota % and session type (root vs subsession) #566DescriptionProblem
OpenCode routes sessions to providers/models without considering how much quota is left on a pool or what kind of session is being placed. In our fleet discipline (see the provider quota registry in developing-today/code), plan quotas are meant to be used all the way to 100% and then stop — never spilling into pay-as-you-go. But the shape of usage near the limit matters:
- A subsession (a subtask/subagent spawned inside a running session) is short and bounded. Near the limit, a pool is ideal subsession territory: the subsession can push the pool to 100% and then stop, without ever entering PAYG.
- A root/primary session is long-lived and open-ended. Starting a new root session on a pool that is already near its limit strands that session mid-work when the quota runs out.
Today there is no way to express that distinction, so placement is quota-blind.
Desired behavior
Quota-aware placement filtering, driven by live quota percentage per pool and the session type:
- Subsession gate: subsessions may be placed on a pool up to 100% of its plan quota. At 100% they stop — they must never enter PAYG (configurable, default: hard stop).
- Root session start gate: new root/primary sessions are not started on a pool above a configurable threshold (default 85%). A root session already running on a pool may continue until the quota runs out — or stop exactly at the limit — configurable.
- Per-pool / per-model weights: every rule carries an adjustable weight, and every rule can be individually disabled without removing its configuration.
- All thresholds and behaviors are configuration, not constants: percentages, the PAYG stop, and the at-limit behavior for running root sessions are all settable per pool/provider.
Config sketch
quota:
gates:
rootSessionStartMaxPct: 85 # don't start new root sessions above this
subsessionMaxPct: 100 # subsessions may burn to the limit
subsessionAllowPayg: false # hard stop before PAYG
runningRootAtLimit: continue # continue | stop-at-limit
# each gate: { enabled: true, weight: 1.0, ... } — disable or re-weight per pool
Acceptance criteria
- Placement decisions consult the current quota % for the candidate pool (using the existing quota sources; a stale read older than a configurable age is treated as unknown, not as headroom).
- A subsession request against a pool at 97% is admitted; at 100% it is refused/redirected and no PAYG call is made.
- A root session request against a pool above
rootSessionStartMaxPct is redirected to the next eligible pool; a root session already running is unaffected until its configured at-limit behavior triggers.
- Setting any gate's
enabled: false restores today's quota-blind behavior for that gate, verified by test.
- Weights change selection order among eligible pools, verified by test.
- Behavior is covered by unit tests for: below threshold, at threshold, at 100%, PAYG-stop, disabled gate.
Context
Fleet rule (Drew, 2026-10-27): pools burn to 100%, then stop until reset or until a fresh read shows the quota has dropped off 100% (some providers reset early). Related: time-based weighting and native quota-driven reprioritization are filed as separate issues. Activitydeveloping-today commented on Oct 27, 2026 dezren39 commented on Oct 27, 2026 Intake review
Fleet monitor intake pass (protocol §5), 2026-10-27. Verified still live: no merged PR implements or resolves this issue as of this run, and no duplicate open issue covers it.
Related: Related: companions #567 (time-based weighting) and #568 (native quota intelligence) filed in the same wave; the fleet-side counterparts live in developing-today/code epic #1334. No labels were applied at filing — this pass normalizes them. No queue label/task exists for this issue in repo-health-opencode-pilot as of this run; routing is a producer decision.
Notes / risks / suggested approach: Risk: placement gating on stale quota reads could misroute — the criteria already require stale reads to count as unknown, not headroom. Suggested approach: share the weight model with #567 as the Context section directs.
Labels normalized by this pass: kind/feature, status/needs-triage, priority/normal, effort/l, meta/enriched.
dezren39 commented on Oct 28, 2026 Triage verdict (task 2138, Lane B): CONFIRMED unimplemented on current main 1e28942 — and blocked on a design decision, not on evidence.
Evidence at HEAD:
Blocker: #566 is Phase 3 of design #587, whose first acceptance criterion is a recorded decision — adopt the shared QuotaSnapshot contract (gates filter before weighting; controller writes only through the tuner Adjustment channel) or keep #566/#567/#568 independent. That decision is not recorded on #587 yet (it sits in user/review). Per #587's phased plan, Phase 3 re-scopes #566 itself once the decision lands — #566 is the vehicle — so no separate small_fix packet is enqueued; a packet filed now would presuppose the undecided contract.
Recommendation (for the #587 decision): adopt the shared contract. Phase 1 already landed on that basis (#588 merged: snapshot + single staleness contract) and per-layer weight attribution exists in the route-review surface; rejecting now would orphan that landed work and return to three incompatible config sketches.
dezren39 commented on Nov 15, 2026 agent-note:v1
state: picked-up
task: 16332
lane: any-a (repo-worker-code)
Resuming task 16332 (#566 quota-aware session placement) from checkpoint stage pr_opened. Fresh state: issue #566 OPEN, no hold labels. Slice 1 (root-start predicate + rootStartMaxPct config) already landed via PR #2421 (merged 2026-11-14). Slice 2 is PR #2464 (branch queue/16332-566-slice2-placement, head 903f446, +260/-6 across 7 files, MERGEABLE) — this shift shepherds it: disposition the CodeRabbit review (commented 2026-11-15T07:33Z), run the packages/core targeted suites on the branch, fix valid findings, and merge under the standing criteria. The preserved fb566 worktree's uncommitted slice-1 files are being checked against merged PR #2421 before anything is discarded or reused. dezren39 commented on Nov 15, 2026 agent-note:v1
state: done
task: 16332
lane: any-a (repo-worker-code)
outcome: fixed_merged — PR #2464 MERGED (merge commit d35c434, 2026-11-15T08:44:48Z). Issue #566 CLOSED by this note: with slice 1 (PR #2421, root-start predicate + rootStartMaxPct config, merged 2026-11-14) the packet's remainder is fully landed.
What slice 2 (PR #2464, head e6986dd) adds: root vs subsession placement wiring — sessionKind from session parentID; credentialRootStartBlocked / providerRootStartBlocked / rootStartBlocked judged by QuotaSnapshot.blocksRootStart with the configured rootStartMaxPct (default 85) and the rootStartEnabled switch; subsessions ride the existing known-full gate to 100% as their hard PAYG stop; per-gate enabled/weight config in the model-routes schema.
This shift additionally fixed the one CodeRabbit finding on PR #2464 (Major, thread 4577525271): the root-start wrappers judged the retained snapshot's derivation-time stale flag, so a retained 90% snapshot with resetAt null would have walled root starts indefinitely. Both wrappers now re-derive staleness from observedAt against QuotaSnapshot.DEFAULT_MAX_AGE_MS at judgement time (judgedSnapshot helper), with regression tests for both scopes; CodeRabbit's re-check raced the push and examined the old head — the correction is recorded on thread 4577702332 at head e6986dd.
Verification on merged main (primary clone at d35c434): model-route-root-start + model-route + model-resolver + quota-snapshot = 312 pass / 0 fail. bunx tsc --noEmit in packages/core clean. Push note: husky pre-push (turbo typecheck) fails on the pre-existing clean-main breakage in test/session-step.test.ts tracked as #2442 (verified identical on main), so the fix commit was pushed with HUSKY=0, recorded on PR #2464.
Left untouched, named for the record: the preserved worktree ~/git/fleet/fb566-566-root-start still holds uncommitted slice-1 files (model-route.ts, quota-snapshot.ts, model-routes.ts) that duplicate what PR #2421 merged — not discarded (not this lane's dirt to delete). The queue-16332-566-slice2 worktree carries unrelated uncommitted whats-new changes (packages/app e2e + gui-extensions updater, +13) from an earlier session — also left exactly as found.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|