{"record":{"id":"af4d5fe44b344a40","repo":"paperclipai/paperclip","slug":"managed-session-spend-ceiling-must-be-positive","errorCode":null,"errorMessage":"managed session spend ceiling must be positive","messagePattern":"managed session spend ceiling must be positive","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/paperclip-runner/src/live/live-session.ts","lineNumber":2073,"sourceCode":"    });\n    await this.#persist();\n    return this.snapshot();\n  }\n\n  async increaseManagedSessionBudget(\n    maxSessionListCostUsd: number,\n  ): Promise<CapabilityLiveSessionSnapshot> {\n    if (\n      (this.#config.provider !== \"claude_managed\" &&\n        this.#config.provider !== \"aws_agentcore\") ||\n      this.#transport === null\n    ) {\n      throw new Error(\n        \"remote session budget updates require a connected remote provider session\",\n      );\n    }\n    if (!Number.isFinite(maxSessionListCostUsd) || maxSessionListCostUsd <= 0) {\n      throw new Error(\"managed session spend ceiling must be positive\");\n    }\n    await this.#transport.request(\"session/budget/increase\", {\n      maxSessionListCostUsd,\n    });\n    if (this.#config.managedProfile) {\n      this.#config.managedProfile.maxSessionListCostUsd = maxSessionListCostUsd;\n    }\n    if (this.#config.agentCoreProfile) {\n      this.#config.agentCoreProfile.maxEstimatedSessionCostUsd =\n        maxSessionListCostUsd;\n    }\n    this.#status = this.#activeTurnId === null ? \"warm_idle\" : \"running\";\n    this.#appendEvidence(\"session\", this.#activeTurnId, {\n      action: \"budget_increased\",\n      maxSessionListCostUsd,\n    });\n    await this.#persist();\n    return this.snapshot();","sourceCodeStart":2055,"sourceCodeEnd":2091,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/packages/paperclip-runner/src/live/live-session.ts#L2055-L2091","documentation":"The managed budget update validates maxSessionListCostUsd is a finite number greater than 0 before sending session/budget/increase to the remote transport. Non-finite, zero, or negative ceilings are rejected client-side so an invalid budget never reaches the provider.","triggerScenarios":"Calling the budget-update method with maxSessionListCostUsd = 0, negative, NaN, or Infinity (e.g. from unparsed config, missing env var, or division producing NaN).","commonSituations":"parseFloat of an unset env var yielding NaN; budget configured as 0 to 'disable' spend (unsupported); unit mismatch producing a tiny/negative computed value.","solutions":["Pass a positive finite number for maxSessionListCostUsd","Validate/parse the configured budget before calling; treat unset config as an error, not NaN","Clamp or default the value (e.g. Number.isFinite(v) && v > 0 ? v : DEFAULT_CEILING)","Fix the computation upstream that produced 0/NaN"],"exampleFix":"// before\nconst budget = Number(process.env.MAX_COST); // NaN if unset\nawait session.updateManagedRemoteSessionBudget(budget);\n// after\nconst budget = Number(process.env.MAX_COST);\nif (!Number.isFinite(budget) || budget <= 0) throw new Error('MAX_COST must be a positive USD amount');\nawait session.updateManagedRemoteSessionBudget(budget);","handlingStrategy":"validation","validationCode":"if (!Number.isFinite(maxSessionListCostUsd) || maxSessionListCostUsd <= 0) throw new Error(`maxSessionListCostUsd must be a positive finite number, got ${maxSessionListCostUsd}`);","typeGuard":"function isValidBudgetUsd(v: number): boolean {\n  return Number.isFinite(v) && v > 0;\n}","tryCatchPattern":"try {\n  await session.updateManagedRemoteSessionBudget(usd);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('spend ceiling must be positive')) {\n    // fix configured value and retry\n  } else throw err;\n}","preventionTips":["Parse numeric config with explicit validation (no bare Number(env))","Reject 0/negative budgets at settings entry points","Keep budget units consistent (USD) across the codebase"],"tags":["live-session","budget","validation"],"backgroundTag":"invalid-budget-value","analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-09-02T18:44:00.616Z","contentChangedAt":"2026-09-02T18:44:00.616Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}