Repository navigation
fix(ladder): bound amend raises by the config commitment ceiling (#842) - #851
Conversation
Gate verdict (Opus 5.5, independent adversarial review): REQUEST CHANGESReviewed SHA: BlockingF1. A raise can still end above C: the amend creates "counted by neither" rows that a later claim can fire.
Result: in-flight is 15 against C=10. I reproduced this on real PG17 with a throwaway test that uses only the store APIs ( Non-blocking follow-ups
Verified (all PASS except F1)
|
… amend ceiling check (#842) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Re-gate verdict (Opus 5.5): APPROVE at
|
Closes #842
PR-B of the #842 plan (PR-A #849 settled_at, PR-C #850 skew margin are merged; #846 planner lock merged).
AmendLadderTranchenow runs insidewithLadderConfigLock(advisory lock first, thenFOR NO KEY UPDATEon config and run, tranche row after).ladderSettleAnchor(latest non-canceled run.started_at)<= C, where C = trunc(min(target_L, baseline_L * current target_coverage/100) - existing_L). Decrease, re-date-only and cancel skip the check. A NULL target/existing/baseline on the latest run refuses a raise. The original_total and per-run cap terms stay as defence in depth.ErrLadderLockTimeout; the amend handler maps it to 503 withRetry-After: 5(was a 500).TestLadderAmendmentAuditAndSiblingConcurrencyfixture seeds target=10, existing=0, baseline=100.Units blocker: today's target is on-demand-equivalent and E amortized commitment dollars. After go#349 tranche amounts are commitment dollars and target - E overstates the ceiling by 1/rate. Tracked for the commitment_rate PR (persist a unit-correct ceiling or refuse raises on rows with a commitment_rate); not fixed here. #843 (planner side) was the separate PR-C.
Verification (local PG17, the Docker-based
setupLadderStoretemporarily pointed at it; CI runs the normal path): 3-step replay (decrease A, planner tops up B, raise A) refused; completed tranche then raise refused; re-date-only with in-flight > C passes; coverage lowered after the run; gross existing; NULL snapshots; latest-run and canceled ordering; amend x planner with a barrier inside the build closure andpg_lockspolling; skew test with literal offsets (30s counts, 2m does not). Mutations each fail a test: drop-old, count only scheduled, NULL snapshot allows a raise, ORDER BY ASC, remove the lock, drop the settled term,>=, margin 0, margin 1h. Removing the ceiling call (about main) fails 8 tests.Also: the raise path first cancels scheduled rows past the 24h grace window (same sweep as the planner) so a later claim cannot fire a row the sum did not count; amounts above 1e12 USD/hr are refused (micro-dollar overflow guard). Accepted residual: the ceiling comes from the latest run's snapshot, so non-ladder purchases made after that run are not counted (same as drift). #118 item: the go#349 units conversion (commitment dollars vs on-demand target) must land before the executor.
🤖 Generated with Claude Code
Summary by CodeRabbit