JuliusBrussee/caveman · error

cave_budget_release_invalid

cave_budget_release_invalid

Error message

cave_budget_release_invalid

What it means

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.

Solutions

  1. Clamp the release amount to releasable() (max - releasedAmount) before calling release
  2. Track remaining() and request tranches that fit inside it
  3. Fix the caller that computes the tranche size so it respects the meter's max
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/agent/src/budget.ts:325 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/8d4b6aa05e6df2b2. Report an issue: GitHub.

Appendix: source

Thrown at packages/agent/src/budget.ts:325

  /** Budget available to a new reservation right now. */
  remaining(): number {
    return Math.max(0, this.releasedAmount - this.settledAmount - this.reservedAmount);
  }

  /** Budget that could still be released without breaching `max`. */
  releasable(): number {
    return Math.max(0, this.max - this.releasedAmount);
  }

  /**
   * Release a further tranche. Throws when it would breach `max`: this is
   * pre-flight validation at a developer-controlled checkpoint, so the caller
   * asked for something the contract cannot grant.
   */
  release(amount: number, reason: string): BudgetTranche {
    if (!Number.isFinite(amount) || amount <= 0) {
      throw new Error("cave_budget_release_invalid");
    }
    if (this.denomination === "tokens" && !Number.isSafeInteger(amount)) {
      throw new Error("cave_budget_release_invalid");
    }
    if (typeof reason !== "string" || reason.trim() === "") {
      throw new Error("cave_budget_release_reason_required");
    }
    if (this.revokedFlag) throw new Error("cave_budget_revoked");
    // A breached ledger is dead. Releasing into it would record a tranche and
    // raise an escalation for money that can never be spent, and would read on
    // the receipt as a run that was still being funded after it went past cap.
    if (this.breachedFlag) throw new Error("cave_budget_cap_breached");
    if (amount > this.releasable()) throw new Error("cave_budget_release_exceeds_max");
    this.releasedAmount += amount;
    const tranche: BudgetTranche = Object.freeze({
      amount,
      reason,
      atCall: this.callIndex,

View on GitHub (pinned to 3ee70a1026)