Repository navigation
chore(purchase/server/analytics): low correctness findings from the 2026-09-02 audit [platform part] #339
Description
Split from LeanerCloud/cloud-commitments-cli#2050 (cross-component issue, monorepo split)
Summary
Three low-severity correctness defects across
internal/purchase,internal/serverandinternal/analytics, each confirmed against the audited commit: an execution with nothing selected still emails a purchase confirmation and lands "completed", theconfig_storehealth sub-check reports healthy over a closed pool, and every non-SavingsPlans commitment is labelled "RI" including GCP CUDs. One of these was downgraded from medium by the verifier; the reason is noted inline.Each item is independently actionable; they are grouped so one sitting can clear them.
Findings
An execution with nothing selected still sends a purchase-confirmation email and lands "completed" (
A05-015)
- Location:
internal/purchase/execution.go:117(sendPurchaseNotificationcall inexecuteSingleAccount); short-circuit at:562-566;buildPurchaseConfirmationDataat:938-964at 3c0f8ac94048a2c36fce5ccddee54e6c4849a5cd- Failure scenario: When no recommendation is selected,
processPurchaseRecommendationsreturns(0, 0, nil, nil), thelen(purchaseErrors) > 0guard is false, andsendPurchaseNotificationfires unconditionally;finalizeExecutionstamps "completed". The user receives a "purchase confirmed" email listing zero commitments and $0 savings for a run that never touched a cloud API, and History shows a completed purchase with no history rows. Reachable via the cron path: notification-created execution rows carry an empty Source, whichexecutableBySchedulerpasses, and no recommendations at all.- Evidence:
// At least one rec committed (full or partial success): the confirmation // must go out for the recs that purchased. if notifyErr := m.sendPurchaseNotification(ctx, exec, plan, totalSavings, totalUpfront); notifyErr != nil { logging.Errorf("Failed to send confirmation: %v", notifyErr) }- Suggested fix: Gate the confirmation on
anyRecPurchased(exec.Recommendations), which the function already computes for the failure branch./health reports config_store healthy after a failed post-connect reinitialization (
A06-009)
- Location:
internal/server/health.go:102-130(checkConfigStore);app.Config = pgStoreatinternal/server/app.go:718, pool closed andapp.DB = nilat:633-637at 3c0f8ac94048a2c36fce5ccddee54e6c4849a5cd- Note: Verifier downgraded from medium to low: aggregate status and the probe response are unaffected.
- Failure scenario:
reinitializeAfterConnectsetsapp.Configand can then fail (encryption-key load, analytics collector,LoadDefaultConfig).ensureDBcloses the pool and nilsapp.DBbut leavesapp.Configpointing at a store over the closed pool.checkConfigStorethen skips both branches and returnshealthy. Scope correction from the verifier:checkAuthStorestill fails in every one of those cases so the aggregate staysdegraded, and/healthreturns HTTP 200 unconditionally, so no probe verdict changes; the mis-report is confined to theconfig_storesub-check.- Evidence:
if app.DB != nil { if err := app.DB.HealthCheck(ctx); err != nil { return CheckResult{Status: "unhealthy", ...} } } return CheckResult{Status: "healthy"}- Suggested fix: Report on
app.dbConnected(and the lastensureDBerror) rather than onapp.Config != nil, or clearapp.Configon the reinit-failure path.Every non-SavingsPlans commitment is labelled "RI", including GCP committed-use discounts (
A06-019)
- Location:
internal/analytics/collector.go:196-202(commitmentTypeFor), provider available in the same loop at:160-172; CHECK enforced byvalidateCommitmentTypeatinternal/analytics/postgres_analytics.go:146-151; typed values atpkg/common/types.go:176-183(LeanerCloud/cloud-commitments-go) at 3c0f8ac94048a2c36fce5ccddee54e6c4849a5cd- Failure scenario: A GCP CUD purchase (
Provider: "gcp") is bucketed and stored withcommitment_type = "RI", so the Trends dashboard's commitment-type dimension reports GCP committed-use spend as reserved instances and any per-type filter mixes them. The four typed values inpkg/commonuse a different vocabulary that nothing on this path references, and thesavings_snapshotsCHECK admits only the two literals this function can emit, so the schema and the mapper are wrong together.- Evidence:
func commitmentTypeFor(service string) string { if service == "SavingsPlans" { return "SavingsPlan" } return "RI" }- Suggested fix: Derive the type from
(provider, service)using thepkg/commonconstants (modulegithub.com/LeanerCloud/cloud-commitments-go) and widen the CHECK constraint to match.Verification requirement
(per the sweep) each fix needs a regression test on the real failing path, not an isolated helper.
Found by the 2026-09-02 codebase audit, findings
A05-015,A06-009,A06-019, reported by one reviewer and independently confirmed by a second. Full report:docs/audits/codebase-audit-2026-09-02.md.
Cross-references
pkg/common/types.goreferenced above lives in LeanerCloud/cloud-commitments-go, consumed here as a module dependency; no change needed there for A06-019, only in this repo'sinternal/analytics.- The go-repo half of this same finding set (A06-022,
pkg/reporter/reporter.gomap-order summary) is filed separately as chore(reporter): filtered-reason summary emitted in Go map order (A06-022) [go part] cloud-commitments-go#110, since that file moved out of this repo (internal/reporter->pkg/reporter) in the split. - The cli-repo half (A10-010,
cmd/multi_service_csv.go--outputtruncation) stays in chore(cli): --output silently truncates an existing CSV (A10-010) [cli part] cloud-commitments-cli#2050, sincecmd/is not part of this repo after the split.
Acceptance criteria
-
internal/purchase/execution.gogatessendPurchaseNotificationonanyRecPurchased(exec.Recommendations). -
internal/server/health.gocheckConfigStorereports onapp.dbConnected(or clearsapp.Configon reinit failure) instead ofapp.Config != nil. -
internal/analytics/collector.gocommitmentTypeForderives the commitment type from(provider, service)usingpkg/commonconstants;internal/analytics/postgres_analytics.goCHECK constraint widened to match. - Each fix ships a regression test exercising the real failing path (empty-selection execution, reinit-failure health check, GCP CUD collection).
Activity
IAmJSD commentedon Oct 23, 2026
Claiming: working on this
fix(purchase,server): skip the $0 purchase confirmation and report a …
fix(analytics): label snapshot commitment types from provider and ser…
IAmJSD commentedon Oct 26, 2026
Closing as fixed on main: #1269 fixed A05-015 (no $0 confirmation email) and A06-009 (config_store health after a failed reinit), and #1302 (merged today, migration 000141) fixed A06-019 (snapshot commitment types labelled from provider and service). Both PRs said Refs, so GitHub didn't close this automatically. Follow-up left for later: drop the legacy 'RI'/'SavingsPlan' values from the CHECK once old replicas are gone. Closed by IAmJSD's agent (acting owner).