Skip to content

fix(ladder): net locked tranches in on-demand units - #891

Merged
cristim merged 3 commits into
mainfrom
fix/ladder-provenance-netting
Oct 15, 2026
Merged

cristim merged 3 commits into
mainfrom
fix/ladder-provenance-netting

Conversation

@cristim

@cristim cristim commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Locked planning currently adds raw stored amounts across different bases. A verified OD tranche of 15 plus a native tranche of 20 at stored rate 1/2 nets 35 instead of 55 OD. Normalize each selected row with its own persisted provenance before the existing aggregate planner; reject unknown units before building or persisting a run.

Keep the config lock, in-flight-first read order, scheduled grace window and settled anchor unchanged. Sum exact rationals and round upward only at the existing float boundary. SDK pins, provider capacity models and the current OD writer remain unchanged; this does not add per-layer netting or activate the newer allocator.

Verification at 93d4345 / tree c917ea4567fb88092a834ad809e65cbf676774d9: two retained independent source/staged passes and fresh independent committed verification cleared the revision. Actual PostgreSQL fixtures exercised store→pinned old planner→persist, unknown refusal, selection boundaries, read errors, config-lock concurrency and the intentional duplicate observation during settlement. Parent regressions and five independent semantic scratch mutations failed at intended assertions, then restored code passed. Affected race suites, full backend build, pinned lint and all normal commit hooks passed. Economics are synthetic fixtures; no provider purchase was performed.

Current main adds disjoint frontend work and purchase-plan write-helper extraction. The ladder paths, DB interface and module pins are unchanged, so the reviewed head is retained without rebase; required PR CI checks the merged result.

Closes #890

Summary by CodeRabbit

  • Bug Fixes
    • Ladder planning now accounts for in-flight and recently settled tranches using their on-demand-equivalent value, improving totals across mixed amount bases.
    • Invalid or unknown commitment data and read failures now prevent a run from being planned or saved, rather than producing an unreliable total.

Normalize verified on-demand and native tranche amounts at their stored
rates before the existing aggregate planner. Refuse unknown provenance
before building or persisting a new run.

Preserve the config lock, in-flight-first read order, grace window and
settlement anchor. Convert the exact sum upward at the old SDK boundary
so rounding cannot understate already committed coverage.

Closes #890
@cristim cristim added urgency/this-sprint Within the current sprint triaged Item has been triaged priority/p1 Next up; this sprint severity/high Significant harm impact/many Affects most users effort/m Days type/bug Defect labels Oct 15, 2026
@cristim

cristim commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

Exact-head gate: independently verified 93d4345, tree c917ea4567fb88092a834ad809e65cbf676774d9. Retained source/staged review and fresh committed native verification are recorded in the PR description. Required CI remains pending. Current-main compatibility was checked against the actual disjoint frontend and purchase-plan helper changes; no SDK pin or capacity-model change is included.

@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

  • Run on-demand review

This review includes 1 billable file and costs up to $0.25.

  • Ask an admin to make reviews automatic

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 36 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 63 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: LeanerCloud/cloud-commitments-platform/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 6000b43b-2979-45aa-b2ca-3853cdc342d2
📥 Commits

Reviewing files that changed from the base of the PR and between 25865ee and ca47cfa.

📒 Files selected for processing: 1
  • internal/config/store_postgres_ladder_settled_plan_integration_test.go

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: LeanerCloud/cloud-commitments-platform/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 71294323-03db-454f-b1a2-baa4ae2e33c4
📥 Commits

Reviewing files that changed from the base of the PR and between 93d4345 and 25865ee.

📒 Files selected for processing: 1
  • internal/config/store_postgres_ladder_amend_ceiling_integration_test.go

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

📝 Walkthrough

Ladder planning now converts stored tranche amounts to on-demand-equivalent values using each tranche’s persisted amount basis and commitment rate. It accumulates exact rational totals before converting the combined amount to float64. Invalid provenance and conversion errors stop planning.

Changes: Ladder netting

Layer / File(s) Summary
Provenance validation and exact conversion
internal/config/ladder_provenance.go, internal/config/ladder_provenance_test.go
Commitment-rate parsing is centralized. Netting validates amount provenance and amounts, converts commitment amounts using their stored rate, and rounds floating-point results upward when needed. Tests cover validation and conversion boundaries.
Locked aggregation and planner integration
internal/config/store_postgres_ladder_lock.go, internal/config/store_postgres_ladder_lock_integration_test.go, internal/config/store_postgres_ladder_netting_integration_test.go, internal/config/store_postgres_ladder_amend_ceiling_integration_test.go, internal/server/handler_ladder.go, internal/server/handler_ladder_lock_integration_test.go
Locked planning aggregates in-flight and settled tranche values as exact on-demand-equivalent totals before conversion. Integration tests cover mixed amount bases, selection boundaries, read failures, planner persistence, and planner-wait behavior.

Priority: ⬆️ High

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: High

Merge Risk: ⚪ Minimal · up to 25865

No actionable current-head risk was identified in the reviewed changes.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 5.88% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: converting locked ladder tranches to on-demand units during netting.
Linked Issues check Passed Issue #890 requires mixed-basis netting, provenance validation before planning or persistence, preserved selection boundaries, and one upward-safe OD total for the existing planner. The reviewed chang…
Out of Scope Changes check Passed The production changes remain limited to provenance-aware ladder netting and related comments. The incremental changes affect only regression-test fixture provenance and test wait handling. These chan…
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@cristim

cristim commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

The docstring coverage advisory is not adopted. This focused change reuses private helpers and names their behavior directly; the repository favors brief comments explaining non-obvious reasoning rather than comments that restate code. The conservative rounding reason is documented, and the actual store/planner behavior is covered by native regression and mutation proofs. Adding docstrings solely to meet this advisory percentage would add unrelated comment churn.

@cristim

cristim commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

Verified revision: 25865ee (tree 6909527a31e9e3df2deb1787e814a4d154c8d74a). The CI failures reproduced locally: the amendment fixtures omitted their known on-demand basis, and a pre-callback planner error left the concurrency test waiting indefinitely. This follow-up labels only those two fixture constructors and makes that wait fail promptly on planner error or context cancellation. Production behavior and ceiling assertions are unchanged. All normal commit hooks passed. The same independent verifier completed two clean passes on this exact revision, ran the full native PostgreSQL amendment-ceiling suite (21.735s), demonstrated prompt failure after removing the fixture provenance, restored the passing concurrency case, and exercised context cancellation (2.910s). Original production-path verification and five mutation proofs transfer because those files are byte-identical. New CI runs are being watched; merge remains gated on required checks and current findings.

@cristim

cristim commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

Verified revision: ca47cfa (tree 4c5e5c11ec29d57fd39623ca9634bf19e94564fa). The previous CI run passed the amendment cases and exposed one further settled-planner fixture that omitted its known on-demand basis. This two-line test-only correction preserves every amount, anchor, skew and status assertion; production files remain byte-identical to the originally verified implementation. The actual config planner regression groups (settled, locked netting, lock coordination and amendment ceilings) pass together locally in native PostgreSQL with the race detector (53.285s). All normal commit hooks passed. The same independent verifier completed two clean passes on this exact revision: native settled test passed (4.013s), removing the fixture provenance reproduced the intended unknown-basis runtime failure (1.459s), and restoration passed (2.706s); archived source bytes matched the commit. New CI runs are watched, and normal merge still requires green checks, current findings and protections.

@cristim
cristim merged commit e003025 into main Oct 15, 2026
25 checks passed
@cristim

cristim commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

Merged normally as e003025 after required checks passed at reviewed ca47cfa. The current-head findings check found no inline threads; the optional CodeRabbit quota notice did not replace the exact-revision independent review. A read-only comparison of merged main confirms every changed backend/test file, dependency pin and migration is byte-identical to the verified revision; the intervening main delta is the previously inspected frontend and purchase-plan helper work. All four actual main workflows are watched. Deployment identity and terminal post-merge workflow outcomes remain pending.

@cristim

cristim commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

Post-merge verification complete at e003025: main CI 38754577274, pre-commit 38754577328, frontend sentinel 38754577440 and automatic deployment 38754577322 all completed successfully. The deployment artifact records that exact SHA as both commit and image tag in dev, and Test Deployment passed. Affected backend/test files, dependency pins and migrations match the independently verified revision. No manual deployment or provider purchase was performed. Original workflow watchers are terminal and reaped. Broader allocator adoption remains tracked in #631.

@cristim
cristim deleted the fix/ladder-provenance-netting branch October 15, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/m Days impact/many Affects most users priority/p1 Next up; this sprint severity/high Significant harm triaged Item has been triaged type/bug Defect urgency/this-sprint Within the current sprint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(ladder): normalize locked tranche amounts before netting

1 participant