Public: anyone can read this; the crew can change it.

An OpenAI-type account that fails during a run hands the run to the next account and says so on it #17897

opened this

Merged 21h 34m ago, live in production

An OpenAI-type account that is still answering 429 after the runner's own waits now hands the run to the next account in order. I did not cover a timeout (below), and I did not run bun scripts/design-lint.ts since no web files changed.

Notes

opened this

An OpenAI-type account that is still answering 429 after the runner's own waits now hands the run to the next account in order. I did not cover a timeout (below), and I did not run bun scripts/design-lint.ts since no web files changed. Tests pass: test/crew-openai-account.test.ts, test/crew-limit-words.test.ts and test/crew-breath.test.ts (33 pass), and bun x tsc --noEmit is clean. bun scripts/gate.ts still notes two comment lines over 100 columns, which it says the nightly rewrap handles. The new test is a unit-level one, not a full run through the crew.

What changed

  • Hand-off: in src/crew/run_limits.ts, a new connectionHandOff runs inside limitEnding. When a run on an OpenAI-type account ends on a per-minute 429, it rests that account and picks again with the existing order logic (the repository's order first). If another account is awake, the run pauses and resumes there.
  • What the log says: it writes handed off: First refused (429…) and rests until …; Second takes the run. The next run's choiceLine then also lists First as passed over, with the cause. I changed no code in account_choice.ts.
  • Once per account: the refused account stays resting for the provider's default wait, about 15 minutes, so the run cannot hand off from it again meanwhile. A run that is still going after the rest ends could hand off from it a second time.
  • No double-spend: a 429 reports no cost, and the test asserts the first account was charged $0.
  • If there is nobody to take over: the account is woken again and the old per-minute wait applies.
  • Test: test/crew-openai-account.test.ts runs two fake endpoints. The first answers 429, and the run finishes on the second, with the log line and the passed-over record checked. It is a unit-level test that drives runOpenAI and limitEnding directly.
  • Already there: a 401, 402, 403 or 5xx from an OpenAI-type account already rested it and handed the run on before this change.

Left out

  • Timeout: the OpenAI runner's timeout is the whole run's deadline, so moving on to another account would only restart a run that has already run out of time. Say if you want a separate per-request timeout.
  • One combined failure: "if all fail, the run fails once with each cause listed" is not done. When every account has failed, the run still waits for the earliest account to wake, as before. Each cause stays on the log through the hand-off lines and the passed-over record.
  • Real-time end-to-end test: the runner's waits total about 112 seconds, so I did not write one.

No door: this is crew-runner behaviour with no new page, action, route or tool.

To try it, grant two OpenAI-type connections to a repository and make the first answer 429. The run log shows the handed off: line, and the next run's account: line names the first as passed over.

🤖 Generated with Claude Code

Closes #17889

3 earlier comments
commented

An OpenAI-type account that is still answering 429 after the runner's own waits now hands the run to the next account in order. I did not cover a timeout (below), and I did not run bun scripts/design-lint.ts since no web files changed. Tests pass: test/crew-openai-account.test.ts, test/crew-limit-words.test.ts and test/crew-breath.test.ts (33 pass), and bun x tsc --noEmit is clean. bun scripts/gate.ts still notes two comment lines over 100 columns, which it says the nightly rewrap handles. The new test is a unit-level one, not a full run through the crew.

What changed

  • Hand-off: in src/crew/run_limits.ts, a new connectionHandOff runs inside limitEnding. When a run on an OpenAI-type account ends on a per-minute 429, it rests that account and picks again with the existing order logic (the repository's order first). If another account is awake, the run pauses and resumes there.
  • What the log says: it writes handed off: First refused (429…) and rests until …; Second takes the run. The next run's choiceLine then also lists First as passed over, with the cause. I changed no code in account_choice.ts.
  • Once per account: the refused account stays resting for the provider's default wait, about 15 minutes, so the run cannot hand off from it again meanwhile. A run that is still going after the rest ends could hand off from it a second time.
  • No double-spend: a 429 reports no cost, and the test asserts the first account was charged $0.
  • If there is nobody to take over: the account is woken again and the old per-minute wait applies.
  • Test: test/crew-openai-account.test.ts runs two fake endpoints. The first answers 429, and the run finishes on the second, with the log line and the passed-over record checked. It is a unit-level test that drives runOpenAI and limitEnding directly.
  • Already there: a 401, 402, 403 or 5xx from an OpenAI-type account already rested it and handed the run on before this change.

Left out

  • Timeout: the OpenAI runner's timeout is the whole run's deadline, so moving on to another account would only restart a run that has already run out of time. Say if you want a separate per-request timeout.
  • One combined failure: "if all fail, the run fails once with each cause listed" is not done. When every account has failed, the run still waits for the earliest account to wake, as before. Each cause stays on the log through the hand-off lines and the passed-over record.
  • Real-time end-to-end test: the runner's waits total about 112 seconds, so I did not write one.

No door: this is crew-runner behaviour with no new page, action, route or tool.

To try it, grant two OpenAI-type connections to a repository and make the first answer 429. The run log shows the handed off: line, and the next run's account: line names the first as passed over.

🤖 Generated with Claude Code

commented

A run on an OpenAI-type account now hands off at most once per account, and fails once with every cause listed when no account is left. A hung endpoint is cut at its own limit. The tests in test/crew-openai-account.test.ts pass (23) and tsc is clean. The gate only noted over-wide comments, which --fix rewrapped. I did not run the full suite.

  • All failed: when a hand-off finds nobody to take over after an earlier hand-off, connectionHandOff in src/crew/run_limits.ts ends the run as failed. It writes one log line and one summary of the form every account failed: First: 429…; Second: 429…. The run no longer waits for the earliest account to wake. The first refusal of a run, with nobody else awake, still falls through to the existing wait.
  • Once per account per run: the accounts already handed from are read back from the run's own handed off: log lines. An account on that list is not handed from again, and neither is one it would hand to. A second refusal from it fails the run, even if another account is awake.
  • Timeout: the OpenAI runner (src/crew/openai_runner.ts) now has a per-request timeout of 90 s to the response headers, separate from the run's deadline. A hung account on a connection ends with limit: { said: "the account's endpoint did not answer in N s" }. That is the same shape as the 5xx case, so it rests the account and the next one takes the run through the existing path. Talk is unchanged.
  • Tests: two fake endpoints both answering 429 give one failure listing both causes. A later refusal from an already-handed-from account is refused while another account is awake, and the log keeps a single handed off: line. A never-answering endpoint is cut and reported as a failing account.

Design choices:

  • Log as the record: I used the run log rather than module state, because the check forbids a module-level Map or Set that functions write to. This depends on the exact handed off: <name> refused (<cause>) and rests until wording, which the all-failed test exercises.
  • Account names: names are assumed unique, as they are for subscriptions.
  • Left out: a hang during a retry inside the 429 wait loop, or while the answer streams, is not cut by the per-request limit. A hung connection also goes through the existing rest-and-next path instead of the new once-per-run tracking or the all-failed summary. Both could be done later.
  • No door: no web, TUI or docs change; the summary and log already show on the run.
commented

The check failed because the new per-request timeout in src/crew/openai_runner.ts used a bare setTimeout. Its callback now runs inside background("openai-headers", …), as the timer rule requires. Behaviour is unchanged.

test/timers-named.test.ts and test/crew-openai-account.test.ts pass (32 tests), and tsc is clean. I did not run the full suite. I pushed the fix as a new commit on the same branch.

The pull description from my earlier message still stands.

commented

The check failed because the new openai-headers timer runs under background, and test/job-slices.test.ts wants every such job timed or listed in its UNTIMED table with a reason. I added it to UNTIMED as a one-shot timer that only aborts one request. That test now passes, 3 of 3. I did not rerun the full suite. The fix is pushed as a new commit on the same branch.

The pull description from my earlier message still stands.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs