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 #11542
mason/forge:mason/11541-on-a-new-forge-the-first-change-lands-a → main 3 commits fork
8 files
changed +101
−3
src/crew/autonomy.ts +5
| @@ -293,6 +293,7 @@ function activeRuns(app: App, repoId: string) { | ||
| 293 | 293 | export function slottedRuns( |
| 294 | 294 | active: readonly Run[], |
| 295 | 295 | crew: readonly { readonly agent: Agent; readonly role: CrewRole }[], |
| 296 | now: Date = new Date(), | |
| 296 | 297 | ): Run[] { |
| 297 | 298 | const notBuilders = new Set( |
| 298 | 299 | crew.filter((c) => c.role !== "builder").map((c) => c.agent.user.id), |
| @@ -300,6 +301,10 @@ export function slottedRuns( | ||
| 300 | 301 | return active.filter( |
| 301 | 302 | (r) => |
| 302 | 303 | r.reason !== "review" && |
| 304 | // A queued run paused until a later time (a provider's limit, the | |
| 305 | // credit) is waiting, not working: it holds no slot, so the pull that | |
| 306 | // needs its builder is not left behind it (#11541). | |
| 307 | !(r.state === "queued" && r.notBefore !== null && r.notBefore > now.toISOString()) && | |
| 303 | 308 | (r.actorId === null || !notBuilders.has(r.actorId)), |
| 304 | 309 | ); |
| 305 | 310 | } |
src/crew/dispatch.ts +1
| @@ -1429,6 +1429,7 @@ function resumeLater(app: App, run: Run, pause: Pause): void { | ||
| 1429 | 1429 | log.info("run paused", { |
| 1430 | 1430 | run: run.id, |
| 1431 | 1431 | until: pause.resumeAt, |
| 1432 | why: pause.why ?? pause.summary ?? "the provider's limit", | |
| 1432 | 1433 | attempt: pause.attempt, |
| 1433 | 1434 | queued: queued?.id, |
| 1434 | 1435 | }); |
src/crew/limits.ts +11
| @@ -26,6 +26,8 @@ const SLACK_MS = 60_000; | ||
| 26 | 26 | */ |
| 27 | 27 | export function isRateLimited(outcome: ClaudeOutcome): boolean { |
| 28 | 28 | if (outcome.ok || isNetworkError(outcome)) return false; |
| 29 | // Spent credit does not lift by waiting: not a pause (#11541). | |
| 30 | if (isCreditSpent(outcome.result)) return false; | |
| 29 | 31 | return ( |
| 30 | 32 | outcome.reason === "api_error" || |
| 31 | 33 | /rate[ _-]?limit|session limit|usage limit|weekly limit|hit your \w+ limit|overloaded|too many requests|\b(?:429|529)\b/i.test( |
| @@ -34,6 +36,15 @@ export function isRateLimited(outcome: ClaudeOutcome): boolean { | ||
| 34 | 36 | ); |
| 35 | 37 | } |
| 36 | 38 | |
| 39 | /** The credit lent to this forge, or an account's budget, is spent: the model door's 402, in its words. */ | |
| 40 | export function isCreditSpent(message: string): boolean { | |
| 41 | return /billing_error|credit balance is too low|from its parent is spent|\b402\b/i.test(message); | |
| 42 | } | |
| 43 | ||
| 44 | /** What a run that met spent credit says, on the pull and in its log. */ | |
| 45 | export const CREDIT_SPENT_WORDS = | |
| 46 | "the crew's credit is spent; land the pull as it is, or add a model key to go on"; | |
| 47 | ||
| 37 | 48 | const MONTHS = [ |
| 38 | 49 | "jan", |
| 39 | 50 | "feb", |
src/crew/runner.ts +16 −1
| @@ -141,8 +141,11 @@ import { | ||
| 141 | 141 | NETWORK_RETRY_SECONDS, |
| 142 | 142 | pause, |
| 143 | 143 | } from "./network.ts"; |
| 144 | import { refreshFunding } from "../spawn/funding.ts"; | |
| 144 | 145 | import { BUDGET_REACHED, runClaude, type ClaudeOutcome } from "./claude.ts"; |
| 145 | 146 | import { |
| 147 | CREDIT_SPENT_WORDS, | |
| 148 | isCreditSpent, | |
| 146 | 149 | isRateLimited, |
| 147 | 150 | limitOf, |
| 148 | 151 | MAX_PAUSES, |
| @@ -511,6 +514,9 @@ async function runClaimed( | ||
| 511 | 514 | await reapOrphans(app, run, write); |
| 512 | 515 | await forgetLandedClone(app, run); |
| 513 | 516 | meterUsage(app, claimed, outcome, meter, started); |
| 517 | // A forge on lent credit hears the host's count now, so its home, app and | |
| 518 | // pull pages read the same figure the run just moved (#11541). | |
| 519 | void refreshFunding(app); | |
| 514 | 520 | if (overran) { |
| 515 | 521 | const summary = budgetSummary( |
| 516 | 522 | "a review run", |
| @@ -539,7 +545,7 @@ async function runClaimed( | ||
| 539 | 545 | }); |
| 540 | 546 | const paused = cancelRun(app.db, run.id, outcome.summary); |
| 541 | 547 | if (paused) announceRun(app, paused); |
| 542 | return { resumeAt: outcome.resumeAt, attempt: run.attempt + 1 }; | |
| 548 | return { resumeAt: outcome.resumeAt, attempt: run.attempt + 1, why: outcome.summary }; | |
| 543 | 549 | } |
| 544 | 550 | // A run the provider or a restart cut short says so, and when it goes |
| 545 | 551 | // on: interrupted, never a park (`interrupted.ts`). |
| @@ -897,6 +903,8 @@ export interface Pause { | ||
| 897 | 903 | readonly attempt: number; |
| 898 | 904 | /** What the queued task says while it waits, when not the provider's limit. */ |
| 899 | 905 | readonly summary?: string | undefined; |
| 906 | /** Why the run paused, for the log line: the run's own words. */ | |
| 907 | readonly why?: string | undefined; | |
| 900 | 908 | } |
| 901 | 909 | |
| 902 | 910 | /** The file names a conflict or converge run's summary carries, after "main|parent|upstream moved: ". */ |
| @@ -1729,6 +1737,13 @@ async function work( | ||
| 1729 | 1737 | limitLifts = resumeAt(result.result, new Date()); |
| 1730 | 1738 | } |
| 1731 | 1739 | |
| 1740 | // The credit is spent: waiting does not bring it back. The run ends | |
| 1741 | // here, holding nothing, and says so in words a person can act on. | |
| 1742 | if (!result.ok && !signal.aborted && isCreditSpent(result.result)) { | |
| 1743 | write(CREDIT_SPENT_WORDS); | |
| 1744 | return { state: "failed", summary: CREDIT_SPENT_WORDS, costUsd: result.costUsd }; | |
| 1745 | } | |
| 1746 | ||
| 1732 | 1747 | watch.lap("harness"); |
| 1733 | 1748 | ran.inHarness = false; |
| 1734 | 1749 | // The reserve: the same session gets one more turn, to land what exists |
src/web/studio/cannot_finish.ts added +40
| @@ -0,0 +1,40 @@ | ||
| 1 | /** | |
| 2 | * The crew cannot finish a change (#11541): its credit is spent, so no run | |
| 3 | * will answer a review. Said plainly on the pull, with the two ways forward: | |
| 4 | * land it as it is (the preview is right there) or add a model key. | |
| 5 | */ | |
| 6 | ||
| 7 | import type { App } from "../../app.ts"; | |
| 8 | import { CREDIT_SPENT_WORDS } from "../../crew/limits.ts"; | |
| 9 | import type { Pull } from "../../core/pulls.ts"; | |
| 10 | import { checkSummary, latestRunsForIssues } from "../../core/runs.ts"; | |
| 11 | import { html, type Html } from "../html.ts"; | |
| 12 | import { btn } from "../ui.ts"; | |
| 13 | import { crewCanRun, includedCredit } from "./crew_key.ts"; | |
| 14 | ||
| 15 | /** Whether the crew has stopped for want of credit: its last run on this pull said so, or the lent credit is gone. */ | |
| 16 | export function creditStopped(app: App, pull: Pull): boolean { | |
| 17 | const last = latestRunsForIssues(app.db, [pull.id], ["agent"]).get(pull.id); | |
| 18 | if (last?.state === "failed" && (last.summary ?? "").includes(CREDIT_SPENT_WORDS)) return true; | |
| 19 | return includedCredit(app) !== undefined && !crewCanRun(app); | |
| 20 | } | |
| 21 | ||
| 22 | /** The card, or null when the crew can go on, the change is not open, or its check is not green. */ | |
| 23 | export function cannotFinishCard( | |
| 24 | app: App, | |
| 25 | pull: Pull, | |
| 26 | headOid: string, | |
| 27 | thread: string, | |
| 28 | admin: boolean, | |
| 29 | ): Html | null { | |
| 30 | if (pull.state !== "open" || pull.mergedAt !== null) return null; | |
| 31 | if (checkSummary(app.db, pull.id, headOid).state !== "ok") return null; | |
| 32 | if (!creditStopped(app, pull)) return null; | |
| 33 | return html`<section class="settings-block mt mb" id="cannot-finish" role="status"> | |
| 34 | <p>The crew's credit is spent, so it cannot answer the review. The change is green and its preview is above: land it as it is, or add a model key to let the crew finish.</p> | |
| 35 | <div class="bar mt"> | |
| 36 | <form method="post" action="${thread}/ship">${btn("Land it as it is", { size: "sm", variant: "primary" })}</form> | |
| 37 | ${admin ? html`<a class="btn btn-sm" href="/settings/subscriptions">Add a key</a>` : html`<span class="muted small">Its admin can add a key.</span>`} | |
| 38 | </div> | |
| 39 | </section>`; | |
| 40 | } |
src/web/studio/change.ts +4 −1
| @@ -87,6 +87,7 @@ import { tellLine, tellsAnswered } from "./branch_tell.ts"; | ||
| 87 | 87 | import { previewVision } from "../../crew/vision.ts"; |
| 88 | 88 | import { visionPreviewCard } from "./direction.ts"; |
| 89 | 89 | import { holdCard } from "./hold.ts"; |
| 90 | import { cannotFinishCard } from "./cannot_finish.ts"; | |
| 90 | 91 | import { pullMayRun } from "../../core/pull_trust.ts"; |
| 91 | 92 | import { landingLine } from "../../flow/landing_line.ts"; |
| 92 | 93 | import { nextOfPull } from "../../flow/next_actor.ts"; |
| @@ -756,7 +757,9 @@ async function changeConversation( | ||
| 756 | 757 | </p>`, |
| 757 | 758 | )} |
| 758 | 759 | <div id="pull-check">${checkLine}</div> |
| 759 | ${when(runLine, (l) => l)} ${gate} ${decisionSection} | |
| 760 | ${when(runLine, (l) => l)} ${gate} | |
| 761 | ${writer && status !== undefined && pull.state === "open" ? cannotFinishCard(ctx.app, pull, status.headOid, thread, ctx.auth.user?.isAdmin === true) : null} | |
| 762 | ${decisionSection} | |
| 760 | 763 | ${when(visionPreview, (v) => visionPreviewCard(v))} |
| 761 | 764 | ${look} |
| 762 | 765 | <div class="split"> |
test/credit-spent-not-paused.test.ts added +23
| @@ -0,0 +1,23 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import { CREDIT_SPENT_WORDS, isCreditSpent, isRateLimited } from "../src/crew/limits.ts"; | |
| 3 | import { slottedRuns } from "../src/crew/autonomy.ts"; | |
| 4 | import type { ClaudeOutcome } from "../src/crew/claude.ts"; | |
| 5 | ||
| 6 | const failed = (result: string): ClaudeOutcome => ({ ok: false, reason: "api_error", result }) as unknown as ClaudeOutcome; | |
| 7 | ||
| 8 | test("spent credit is not a pause", () => { | |
| 9 | const said = "API Error: 402 billing_error: lab's $2 from its parent is spent; the parent's admin can raise it."; | |
| 10 | expect(isCreditSpent(said)).toBe(true); | |
| 11 | expect(isRateLimited(failed(said))).toBe(false); | |
| 12 | expect(isRateLimited(failed("API Error: 429 rate_limit_error"))).toBe(true); | |
| 13 | expect(CREDIT_SPENT_WORDS).toContain("land the pull as it is"); | |
| 14 | }); | |
| 15 | ||
| 16 | test("a run paused until later holds no builder slot", () => { | |
| 17 | const run = (state: string, notBefore: string | null) => | |
| 18 | ({ id: "r", state, reason: "feedback", actorId: null, notBefore }) as never; | |
| 19 | const now = new Date("2026-11-12T00:35:00Z"); | |
| 20 | const later = "2026-11-12T00:52:00Z"; | |
| 21 | expect(slottedRuns([run("queued", later), run("running", null)], [], now)).toHaveLength(1); | |
| 22 | expect(slottedRuns([run("queued", "2026-11-12T00:30:00Z")], [], now)).toHaveLength(1); | |
| 23 | }); |
test/pages-budget.test.ts +1 −1
| @@ -37,7 +37,7 @@ const DEFAULT = { statements: 60, git: 8 }; | ||
| 37 | 37 | const HEAVIER: Record<string, { statements?: number; git?: number }> = { |
| 38 | 38 | "/:owner/:name/issues/:number": { statements: 70 }, |
| 39 | 39 | "/:owner/:name/next": { statements: 64 }, |
| 40 | "/:owner/:name/pulls/:number": { statements: 110 }, // +1: the header Talk count (#10327); +1: the landing line (#10860) | |
| 40 | "/:owner/:name/pulls/:number": { statements: 111 }, // +1: the cannot-finish card reads the last run (#11541); +1: the header Talk count (#10327); +1: the landing line (#10860) | |
| 41 | 41 | "/board": { statements: 70 }, // +6: the money line (#510) — one settings read, then the month's and the 30 days' meter, storage and ledger reads; constant in the number of apps |
| 42 | 42 | "/settings/capacity": { statements: 71 }, |
| 43 | 43 | }; |
new above
offline