{"record":{"id":"c9993be3d0945d90","repo":"nexu-io/open-design","slug":"workspace-balance-response-is-invalid-for-reques","errorCode":null,"errorMessage":"workspace balance response is invalid for ${requestedWorkspaceId}","messagePattern":"workspace balance response is invalid for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"apps/daemon/src/integrations/vela-billing.ts","lineNumber":168,"sourceCode":"    if (\n      !(error instanceof VelaWorkspaceBillingSnapshotUnsupportedError) &&\n      !isWorkspaceBillingSnapshotUnsupported(error, '')\n    ) {\n      throw error;\n    }\n    const legacyStdout = await run([\n      'workspace-balance',\n      '--workspace-id',\n      requestedWorkspaceId,\n      '--format',\n      'json',\n    ]);\n    const workspaceBalance = parseWorkspaceWalletBalance(\n      legacyStdout,\n      requestedWorkspaceId,\n    );\n    if (!workspaceBalance) {\n      throw new Error(`workspace balance response is invalid for ${requestedWorkspaceId}`);\n    }\n    return {\n      snapshot: null,\n      workspaceBalance,\n    };\n  }\n}\n\nexport interface BillingCheckoutOptions {\n  /** Team workspace id whose subscription is being purchased. */\n  workspaceId?: string;\n  /** Vela team subscription plan id. */\n  planId?: WorkspaceTeamBillingPlanId;\n  /** Seats to purchase for the team subscription (>= 1). */\n  seats?: number;\n  /** Where Stripe returns the user after success / cancel. */\n  successUrl?: string;\n  cancelUrl?: string;","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/integrations/vela-billing.ts#L150-L186","documentation":"Thrown in the legacy fallback path of resolveVelaWorkspaceBillingProjection: the vela CLI reported workspace-snapshot as unsupported, the code fell back to workspace-balance, but parseWorkspaceWalletBalance() could not extract a valid balance for the requested workspace from the legacy JSON. This is a data/contract mismatch between the vela binary's output and the parser.","triggerScenarios":"workspace-snapshot unsupported → run(['workspace-balance', ...]) succeeds but the returned JSON does not contain the fields parseWorkspaceWalletBalance expects (workspaceId mismatch, missing balanceUsd, or a different envelope). Only happens for a non-empty requestedWorkspaceId after the snapshot fallback.","commonSituations":"Vela CLI version that returns a workspace-balance envelope the parser does not recognise; workspace id that exists for snapshot but the legacy route returns a different workspace or an error body; partial/truncated CLI output; vela binary behaving differently across OS/arch.","solutions":["Upgrade the vela binary so workspace-snapshot is supported (avoids the legacy fallback entirely).","Inspect the raw workspace-balance stdout from the vela CLI and update parseWorkspaceWalletBalance if its contract changed.","Confirm the requestedWorkspaceId is one the CLI actually recognises."],"exampleFix":"// before\nconst workspaceBalance = parseWorkspaceWalletBalance(legacyStdout, requestedWorkspaceId);\nif (!workspaceBalance) {\n  throw new Error(`workspace balance response is invalid for ${requestedWorkspaceId}`);\n}\n\n// after (capture raw output for diagnosis before throwing)\nconst workspaceBalance = parseWorkspaceWalletBalance(legacyStdout, requestedWorkspaceId);\nif (!workspaceBalance) {\n  log.warn('vela workspace-balance parse failed', { requestedWorkspaceId, stdoutHead: legacyStdout.slice(0, 500) });\n  throw new Error(`workspace balance response is invalid for ${requestedWorkspaceId}`);\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isWorkspaceBalanceInvalidError(err: unknown): boolean {\n  return err instanceof Error && err.message.startsWith('workspace balance response is invalid for ');\n}","tryCatchPattern":"try {\n  return await resolveVelaWorkspaceBillingProjection({ workspaceId });\n} catch (err) {\n  if (isWorkspaceBalanceInvalidError(err)) {\n    // snapshot unsupported AND legacy parse failed — degrade billing UI\n    return { snapshot: null, workspaceBalance: null };\n  }\n  throw err;\n}","preventionTips":["Keep the vela binary version aligned with the parser contract.","Log raw CLI stdout on parse failure to diagnose envelope drift quickly.","Prefer workspace-snapshot over the legacy workspace-balance path by upgrading vela."],"tags":["integration","parsing","billing","vela"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}