Hold a subscription's runs until its usage allowance resets

Open
#200 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
django, python
Domain
ai, backend

Research direction

Start with subscription_problem() in secondshift/jobs/execution.py, failure_reason() in secondshift/runner/agent_image/agent.py, and FAILURE_SUMMARIES in secondshift/runs/execution/cli_agent.py. Use a real exhausted login in the dev stack to check whether Codex or Claude Code exposes a reset time in its events or error output. Done means the reset-time source and held-run behavior are decided; the issue does not yet define those decisions.

Written by the indexing model from the issue text.

Description

Problem

When a subscription's usage allowance runs out, every run on that login fails until the provider resets it.

What happens today:

  • The run starts as usual. subscription_problem() in secondshift/jobs/execution.py blocks only a disconnected login, a sign-in refused at its last check, an owner who left, and the max_runs_per_day cap.
  • The CLI hits its limit. The agent image reports AgentOutcome.QUOTA_EXHAUSTED (failure_reason() in secondshift/runner/agent_image/agent.py).
  • The run fails with "Subscription usage exhausted. Wait for your provider's allowance to reset, then start a new run." (FAILURE_SUMMARIES in secondshift/runs/execution/cli_agent.py). The usual notifications go out.
  • Nothing retries, and nothing falls back to a model API key.
  • The next scheduled runs still start. Each one starts a container and fails the same way until the reset.
  • We don't know the reset time, so the summary can't say when to retry.

Proposal

When a run ends with quota_exhausted, record when the login's allowance resets. Until then, hold that login's runs instead of starting them.

  • Store the reset time on the login, like last_check.
  • Make subscription_problem() report the hold, so Models and the run pages show it. For example: "Usage resets at 3:00 PM."
  • Decide what a held run does. It could wait and start after the reset, or be skipped with a clear reason. Scheduled runs probably wait. Manual runs might ask.
  • Put the reset time in the failure summary.
  • Clear the hold early when a login check or a run succeeds.
  • If no reset time is known, fall back to a short hold or today's behaviour.

Investigate first

Use a real exhausted login in the dev stack. Find out what Claude Code and Codex report when a limit is hit, and whether it includes a reset time.

  • Codex writes rate_limits (used_percent, resets_at, and 5-hour and weekly windows) to its session files. Our agent runs codex exec --ephemeral, so it writes none. Check whether the same data appears in --json events or in the error text.
  • Claude Code has no known machine-readable source. Check its stream-json error events and result text.
  • The agent image must keep returning only reasons and fixed fields, never raw CLI text. A reset time should be a parsed timestamp.

Related

  • Per-login run cap: #187
  • Login check on save: #196
  • Confirm an expired sign-in with a check: #197. A check that ends in quota_exhausted proves the sign-in works. It doesn't block runs.
Dominant language
Python
Stars
1
Forks
1
Avg merge
1h 9m
Merged PRs (30d)
322

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from piotrekno1/second-shift

All issues in piotrekno1/second-shift

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.