Repository navigation
Closed
Description
Context
Scheduled and externally triggered runs happen with nobody watching, which makes them the main cost risk of Agents: a 15-minute schedule against a provider that is already at 95% of its subscription window would burn the remaining quota that interactive work needs. ProPR already has the two ingredients:
- the instance's existing "pause at % of subscription usage" control (the operator-chosen threshold), and
- Agent Tank usage data per provider/credential, exposed in core via
AliasSpecificAgentTankSnapshotProvider(packages/core/src/services/syntheticUsageSnapshotProvider.ts), whichsrc/jobs/ultrafixEscalation.tsalready uses to skip models at 100% before an escalation handoff.
This issue adds a single gate function consulted before starting any unattended run (trigger schedule, api, mcp, cli), before a deferred run is retried, and before an auto acting step starts. Agents v1 performs no model escalation; the gate is exported so any future escalation path must call it (documented).
Requirements
- New
packages/core/src/services/agents/agentRunCostGate.ts:loadUsagePauseThreshold()— reads the existing "pause at % of subscription usage" setting. Locate it first (searchpackages/api/mcp/settingsCatalog.ts,packages/api/routes/configSettings.tsand the synthetic-pool usage routing for the usage-pause threshold) and read it through the same loader that feature uses. Only if no instance-wide control exists, addagent_run_usage_pause_percent(integer 50-100, default 90) to the settings validation,SETTINGS_CATALOGandget/update_execution_settings.evaluateProviderCapacity(agentAlias, threshold)→{ status: 'ok' | 'near_limit' | 'unknown'; sessionPercent?; weeklyPercent?; resetsInMs? ; provider }. Synthetic pools: evaluate every enabled member alias; the pool isnear_limitonly if all members are.createAgentRunCostGate({ now, maxDeferrals = 6, deferStepMs = 30 min })returning thegate(definition, trigger, run?)callback used bytriggerAgentRun(issue 4):manual(UI Run now) → alwaysproceed(attended; the UI shows the capacity warning instead).- capacity
unknown(Agent Tank disabled/unreachable) →proceedand log once — the same fail-open ruleultrafixEscalationuses, so a monitoring outage never silently stops all automation. Documented. - weekly usage ≥ threshold →
skip("weekly subscription usage for claude is at 93% (pause threshold 90%)") — a weekly window will not recover within hours. - session usage ≥ threshold →
deferuntilmin(now + resetsIn + 2 min, now + deferStepMs); aftermaxDeferralsdeferrals →skip.
- Wire the gate:
- REST trigger (issue 5):
services.gatedefaults tocreateAgentRunCostGate();manualpasses through. startActing(issue 10) forauto: when the gate says notproceedfor an unattended run, transitionreport_ready → awaiting_approvalinstead, withskipReason"Acting paused: …" so a human can approve later. No tokens are spent.- Deferred retry (issue 12) calls the gate with the existing run to apply
maxDeferrals.
- REST trigger (issue 5):
GET /api/agent-definitions/:id/capacity→ currentevaluateProviderCapacityfor the UI warning (issue 16).- Tests
test/agentRunCostGate.test.tswith an injected snapshot provider.
Implementation Specification
- Never call the bundled Agent Tank refresh from the gate (it may start a container); read the cached snapshot the provider exposes. A stale snapshot is acceptable; the gate is a brake, not an accounting system.
- Every skip/defer reason is a full human-readable sentence: it is shown verbatim in run history.
Acceptance Criteria
- Scheduled trigger with Claude session at 95% and threshold 90% → run recorded
deferredwith a reason; no job enqueued. - Same with weekly at 95% →
skipped. - After 6 deferrals the 7th evaluation skips.
-
manualtrigger at 99% proceeds. - Agent Tank disabled → proceeds (logged as
unknown). -
autoacting over threshold parks the run inawaiting_approval.
Created by ProPR AI Planner
Activity
propr-dev commentedon Oct 6, 2026
Suggested Implementation:
Implementation Approach
One pure-ish gate function with injected data sources, plugged into the single trigger primitive (issue 4) and the two other places unattended spend can start (deferred retry and
autoacting). Reusing the operator's existing usage-pause threshold means there is one knob for "how close to my subscription limit may automation go", not a second, agent-specific one that could disagree.Defer vs. skip: a session window (≈5 h) recovers soon, so deferring preserves the operator's intent (the report still arrives, just later). A weekly window does not, so we skip with a clear reason instead of retrying for days. Bounded deferrals (6 × 30 min) prevent a run from lingering indefinitely.
Fail-open on missing data mirrors
ultrafixEscalation.resolveModel("missing, stale, disabled, or failed usage monitoring never blocks"); the alternative (fail-closed) would turn an Agent Tank outage into silently dead automation.File:
packages/core/src/services/agents/agentRunCostGate.ts(new file)Why this file: The cost brake for unattended Agents, in one testable module.
Export from
packages/core/src/index.ts(export * from './services/agents/agentRunCostGate.js';).File:
packages/core/src/services/agents/agentRunAutonomy.tsWhy this file:
autoacting is unattended spend too; when capacity is low the run waits for a human instead of acting.(
runDefinitionFromRunloads the snapshot viagetAgentRunRowById+runDefinitionSnapshot.)File:
packages/api/routes/agentDefinitionRoutes.tsWhy this file: Default gate for API/CLI triggers and the capacity endpoint for the UI.
Register
['get', '/api/agent-definitions/:id/capacity', agentDefinitionRoutes.capacity].File:
test/agentRunCostGate.test.ts(new file)Why this file: Each branch of the gate with deterministic fake usage.
propr-dev commentedon Oct 6, 2026
🤖 AI processing has started for this issue using claude agent with claude-opus-5-5 model.
I'll analyze the problem and work on a solution. This may take a few minutes.
Processing Details:
claudeclaude-opus-5-52810/claude-opus-5-5-agents-v1-11-17-agent-tan-20261006-2259-j8w2800-epic-agents-v1-y7tissue-2810-20261006-2259-claude-opus-5-5-j8w🔍 Track Task Execution
I've implemented the Agent Tank usage gate for issue #2810. Scheduled…
I've implemented the Agent Tank usage gate for issue #2810. Scheduled…