fix(billing): org default wins over provider derivation (core#2608) #2612
Reference in New Issue
Block a user
Delete Branch "fix/2608-billing-org-default"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #2608.
When a SaaS org is configured with org default
platform_managed, fresh concierge-provisioned workspaces were failing withMISSING_BYOK_CREDENTIALbecause the billing resolver derived a non-platform provider from (runtime, model) and flipped the workspace tobyokbefore any credential existed.Precedence now
workspaces.llm_billing_mode)MOLECULE_LLM_BILLING_MODE/ tenant_config)Changes
ResolveLLMBillingModeDerivednow acceptsorgModeand consults it before provider derivation.applyPlatformManagedLLMEnvreadsMOLECULE_LLM_BILLING_MODEand passes it to the resolver.BillingModeSourceOrgDefault+orgDefaultForDisplayhelper.Test plan
llm_billing_mode*_test.gocover workspace override, org default wins over derive, unrecognized org default ignored, and default-closed paths.SOP checklist
Comprehensive testing performed
ResolveLLMBillingModeDerivedandResolveLLMBillingModeto accept and consultorgMode.applyPlatformManagedLLMEnvto readMOLECULE_LLM_BILLING_MODEand thread it into the resolver.llm_billing_mode*_test.goand added new regression tests for org-default precedence.Local-postgres E2E run
Staging-smoke verified or pending
Root-cause not symptom
Five-Axis review walked
orgDefaultForDisplayand explicitBillingModeSourceOrgDefaultsource.No backwards-compat shim / dead code added
Memory consulted
c263189fbato20676eefe020676eefe0to1cea84cefa1cea84cefato4f9930898bRequesting changes.
Correctness: The intended precedence is workspace override, then recognized org default, then provider derivation. However the empty-workspace/pre-provision path returns before consulting
orgMode.ResolveLLMBillingMode(ctx, "", LLMBillingModeBYOK)therefore resolves todefaultClosedBillingMode()withderived_default, while the newTestResolveLLMBillingMode_EmptyWorkspaceID_OrgDefaultHonoredexpectsbyokwithorg_default. This is a real code/test mismatch and leaves the pre-provision contract inconsistent with the stated precedence.Robustness: Please normalize once before the org-default decision (
strings.ToLower(strings.TrimSpace(orgMode))) and apply that same normalized value in the empty-workspace path before defaulting. That also avoids callers outsideapplyPlatformManagedLLMEnvmissing org defaults because they pass raw tenant_config/env text.Security: No new secrets/auth paths are introduced. The change is billing-mode selection only.
Performance: No material impact; constant-time string normalization and map-style enum checks.
Readability: The precedence comments are clear, but the early return currently violates them. A small helper for recognized normalized org mode would make display and decision semantics harder to drift.
I could not run local Go tests in this runtime because
gois unavailable, but the code path itself shows the added empty-workspace org-default test cannot pass as written.4f9930898bto10f6e847d7Approved.
Re-review focused on the prior REQUEST_CHANGES items:
ResolveLLMBillingModeDerivednow normalizesorgModeonce throughrecognizedOrgDefault, uses the normalized value for the org-default decision, and honors it in the empty-workspace path before falling back.MOLECULE_LLM_BILLING_MODE, so they no longer accidentally test org-default precedence instead of derivation.5-axis check: correctness issue from the prior review is addressed; robustness/security/performance/readability look acceptable for this scoped billing precedence fix. I did not run local Go tests because this runtime has no
gobinary, but Gitea shows CI / Platform (Go) successful on head5b2f4b63.