Public: anyone can read this; the crew can change it.
On a new forge the first change lands: a green pull is not left waiting behind a paused run, a review loop or credit that reads spent at $0.48 of $2 #11546
scout/forge:scout/11541-on-a-new-forge-the-first-change-lands-a → main 2 commits fork
4 files
changed +59
−2
src/crew/dispatch.ts +1
| @@ -1431,6 +1431,7 @@ function resumeLater(app: App, run: Run, pause: Pause): void { | ||
| 1431 | 1431 | until: pause.resumeAt, |
| 1432 | 1432 | attempt: pause.attempt, |
| 1433 | 1433 | queued: queued?.id, |
| 1434 | why: pause.summary ?? "the provider's limit", | |
| 1434 | 1435 | }); |
| 1435 | 1436 | } |
| 1436 | 1437 |
src/crew/limits.ts +18 −1
| @@ -25,7 +25,7 @@ const SLACK_MS = 60_000; | ||
| 25 | 25 | * the limit, and is checked too in case the ending is named differently. |
| 26 | 26 | */ |
| 27 | 27 | export function isRateLimited(outcome: ClaudeOutcome): boolean { |
| 28 | if (outcome.ok || isNetworkError(outcome)) return false; | |
| 28 | if (outcome.ok || isNetworkError(outcome) || isCreditSpent(outcome)) return false; | |
| 29 | 29 | return ( |
| 30 | 30 | outcome.reason === "api_error" || |
| 31 | 31 | /rate[ _-]?limit|session limit|usage limit|weekly limit|hit your \w+ limit|overloaded|too many requests|\b(?:429|529)\b/i.test( |
| @@ -34,6 +34,23 @@ export function isRateLimited(outcome: ClaudeOutcome): boolean { | ||
| 34 | 34 | ); |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | /** | |
| 38 | * The credit lent to this forge, or the account's budget, is spent: the | |
| 39 | * model door answers 402 `billing_error` ("… from its parent is spent"), and | |
| 40 | * Claude Code ends such a run with `api_error`. Waiting does not lift it, so | |
| 41 | * it is never a pause: the run ends, the person is told, and the slot is free. | |
| 42 | */ | |
| 43 | export function isCreditSpent(outcome: ClaudeOutcome): boolean { | |
| 44 | if (outcome.ok) return false; | |
| 45 | return /billing_error|\b402\b|from its parent is spent|credit balance is too low|budget is spent/i.test( | |
| 46 | outcome.result, | |
| 47 | ); | |
| 48 | } | |
| 49 | ||
| 50 | /** What a person reads when the credit ran out under a run. */ | |
| 51 | export const CREDIT_SPENT_SAID = | |
| 52 | "The included credit is spent; the crew cannot go on. Land the pull as it is, or add a model key."; | |
| 53 | ||
| 37 | 54 | const MONTHS = [ |
| 38 | 55 | "jan", |
| 39 | 56 | "feb", |
src/crew/runner.ts +14
| @@ -144,6 +144,8 @@ import { | ||
| 144 | 144 | import { BUDGET_REACHED, runClaude, type ClaudeOutcome } from "./claude.ts"; |
| 145 | 145 | import { |
| 146 | 146 | isRateLimited, |
| 147 | isCreditSpent, | |
| 148 | CREDIT_SPENT_SAID, | |
| 147 | 149 | limitOf, |
| 148 | 150 | MAX_PAUSES, |
| 149 | 151 | resumeAt, |
| @@ -1673,6 +1675,18 @@ async function work( | ||
| 1673 | 1675 | `claude: ${result.reason}, ${result.turns} turns, $${result.costUsd.toFixed(2)}`, |
| 1674 | 1676 | ); |
| 1675 | 1677 | |
| 1678 | // Spent credit is not a limit that lifts: end the run now, say why, and | |
| 1679 | // leave the slot to the next ask (a pause here held it for a quarter hour). | |
| 1680 | if (isCreditSpent(result) && !signal.aborted) { | |
| 1681 | write(`credit spent: ${result.result.slice(0, 160)}`); | |
| 1682 | return { | |
| 1683 | state: "failed", | |
| 1684 | summary: CREDIT_SPENT_SAID, | |
| 1685 | sessionId: result.sessionId, | |
| 1686 | costUsd: result.costUsd, | |
| 1687 | }; | |
| 1688 | } | |
| 1689 | ||
| 1676 | 1690 | // The provider's refusal, not the agent's failure: the run pauses with |
| 1677 | 1691 | // its clone and session as they are, and goes on when the limit lifts. |
| 1678 | 1692 | // A limit that never lifts is not waited on forever. |
test/subscriptions.test.ts +26 −1
| @@ -30,7 +30,7 @@ import { | ||
| 30 | 30 | } from "../src/core/subscriptions.ts"; |
| 31 | 31 | import { createUser, type User } from "../src/core/users.ts"; |
| 32 | 32 | import { startCrew, type CrewHandle } from "../src/crew/dispatch.ts"; |
| 33 | import { isRateLimited, resumeAt } from "../src/crew/limits.ts"; | |
| 33 | import { isCreditSpent, isRateLimited, resumeAt } from "../src/crew/limits.ts"; | |
| 34 | 34 | import { serve, type Servers } from "../src/http/server.ts"; |
| 35 | 35 | import { stylesheetAsset } from "../src/web/asset.ts"; |
| 36 | 36 | import { adminCookie } from "./helpers/admin.ts"; |
| @@ -277,6 +277,31 @@ describe("the provider's reset time", () => { | ||
| 277 | 277 | }); |
| 278 | 278 | }); |
| 279 | 279 | |
| 280 | describe("spent credit is not a limit that lifts", () => { | |
| 281 | const out = (result: string) => ({ | |
| 282 | ok: false as const, | |
| 283 | sessionId: "", | |
| 284 | result, | |
| 285 | costUsd: 0, | |
| 286 | turns: 0, | |
| 287 | tokensIn: 0, | |
| 288 | tokensOut: 0, | |
| 289 | contextTokens: 0, | |
| 290 | contextWindow: 0, | |
| 291 | reason: "api_error", | |
| 292 | }); | |
| 293 | test("a 402 from the model door ends the run instead of pausing it", () => { | |
| 294 | const o = out("API Error: 402 billing_error: probe's $2 from its parent is spent; the parent's admin can raise it."); | |
| 295 | expect(isCreditSpent(o)).toBe(true); | |
| 296 | expect(isRateLimited(o)).toBe(false); | |
| 297 | }); | |
| 298 | test("a real rate limit still pauses", () => { | |
| 299 | const o = out("API Error: 429 rate_limit_error"); | |
| 300 | expect(isCreditSpent(o)).toBe(false); | |
| 301 | expect(isRateLimited(o)).toBe(true); | |
| 302 | }); | |
| 303 | }); | |
| 304 | ||
| 280 | 305 | describe("a run on a granted account", () => { |
| 281 | 306 | let dataDir: string; |
| 282 | 307 | let app: App; |
new above
offline