{"record":{"id":"8d4b6aa05e6df2b2","repo":"JuliusBrussee/caveman","slug":"cave-budget-release-invalid","errorCode":"cave_budget_release_invalid","errorMessage":"cave_budget_release_invalid","messagePattern":"cave_budget_release_invalid","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/budget.ts","lineNumber":325,"sourceCode":"\n  /** Budget available to a new reservation right now. */\n  remaining(): number {\n    return Math.max(0, this.releasedAmount - this.settledAmount - this.reservedAmount);\n  }\n\n  /** Budget that could still be released without breaching `max`. */\n  releasable(): number {\n    return Math.max(0, this.max - this.releasedAmount);\n  }\n\n  /**\n   * Release a further tranche. Throws when it would breach `max`: this is\n   * pre-flight validation at a developer-controlled checkpoint, so the caller\n   * asked for something the contract cannot grant.\n   */\n  release(amount: number, reason: string): BudgetTranche {\n    if (!Number.isFinite(amount) || amount <= 0) {\n      throw new Error(\"cave_budget_release_invalid\");\n    }\n    if (this.denomination === \"tokens\" && !Number.isSafeInteger(amount)) {\n      throw new Error(\"cave_budget_release_invalid\");\n    }\n    if (typeof reason !== \"string\" || reason.trim() === \"\") {\n      throw new Error(\"cave_budget_release_reason_required\");\n    }\n    if (this.revokedFlag) throw new Error(\"cave_budget_revoked\");\n    // A breached ledger is dead. Releasing into it would record a tranche and\n    // raise an escalation for money that can never be spent, and would read on\n    // the receipt as a run that was still being funded after it went past cap.\n    if (this.breachedFlag) throw new Error(\"cave_budget_cap_breached\");\n    if (amount > this.releasable()) throw new Error(\"cave_budget_release_exceeds_max\");\n    this.releasedAmount += amount;\n    const tranche: BudgetTranche = Object.freeze({\n      amount,\n      reason,\n      atCall: this.callIndex,","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/budget.ts#L307-L343","documentation":"Thrown by Budget.release when a requested tranche is not a positive amount or would push releasedAmount past max. Per the doc comment this is pre-flight validation at a developer-controlled checkpoint: the caller asked the contract for more budget than it can grant, an API misuse rather than a runtime condition.","triggerScenarios":"Thrown at packages/agent/src/budget.ts:325 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Clamp the release amount to releasable() (max - releasedAmount) before calling release","Track remaining() and request tranches that fit inside it","Fix the caller that computes the tranche size so it respects the meter's max"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}