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

Parked opened this in answer to
Closed without merging

scout/forge:scout/11541-on-a-new-forge-the-first-change-lands-a → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
4 files changed +59 −2
src/crew/dispatch.ts +1
@@ -1431,6 +1431,7 @@ function resumeLater(app: App, run: Run, pause: Pause): void {
14311431 until: pause.resumeAt,
14321432 attempt: pause.attempt,
14331433 queued: queued?.id,
1434 why: pause.summary ?? "the provider's limit",
14341435 });
14351436 }
14361437
src/crew/limits.ts +18 −1
@@ -25,7 +25,7 @@ const SLACK_MS = 60_000;
2525 * the limit, and is checked too in case the ending is named differently.
2626 */
2727 export function isRateLimited(outcome: ClaudeOutcome): boolean {
28 if (outcome.ok || isNetworkError(outcome)) return false;
28 if (outcome.ok || isNetworkError(outcome) || isCreditSpent(outcome)) return false;
2929 return (
3030 outcome.reason === "api_error" ||
3131 /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 {
3434 );
3535 }
3636
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
3754 const MONTHS = [
3855 "jan",
3956 "feb",
src/crew/runner.ts +14
@@ -144,6 +144,8 @@ import {
144144 import { BUDGET_REACHED, runClaude, type ClaudeOutcome } from "./claude.ts";
145145 import {
146146 isRateLimited,
147 isCreditSpent,
148 CREDIT_SPENT_SAID,
147149 limitOf,
148150 MAX_PAUSES,
149151 resumeAt,
@@ -1673,6 +1675,18 @@ async function work(
16731675 `claude: ${result.reason}, ${result.turns} turns, $${result.costUsd.toFixed(2)}`,
16741676 );
16751677
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
16761690 // The provider's refusal, not the agent's failure: the run pauses with
16771691 // its clone and session as they are, and goes on when the limit lifts.
16781692 // A limit that never lifts is not waited on forever.
test/subscriptions.test.ts +26 −1
@@ -30,7 +30,7 @@ import {
3030 } from "../src/core/subscriptions.ts";
3131 import { createUser, type User } from "../src/core/users.ts";
3232 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";
3434 import { serve, type Servers } from "../src/http/server.ts";
3535 import { stylesheetAsset } from "../src/web/asset.ts";
3636 import { adminCookie } from "./helpers/admin.ts";
@@ -277,6 +277,31 @@ describe("the provider's reset time", () => {
277277 });
278278 });
279279
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
280305 describe("a run on a granted account", () => {
281306 let dataDir: string;
282307 let app: App;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs