Skip to content

next-campaigns-create 1.3.1: round each unit's discount up to the cent in landed-price forecasts - #92

Merged
next-devin merged 5 commits into
mainfrom
create-landed-round-up
Nov 8, 2026
Merged

next-devin merged 5 commits into
mainfrom
create-landed-round-up

Conversation

@next-devin

Copy link
Copy Markdown
Contributor

landed_unit rounded each unit's percentage discount to the nearest cent. The cart engine rounds it up to the cent, so a forecast could come out a cent too high per unit. With a price_rounding ending, it could come out a dollar too high.

Evidence

carts/calculate on 2026-11-07, for a campaign whose offers have price_rounding: null:

Price Offer Raw discount Engine discount Engine unit Old forecast
89.99 33.34% 30.0027 30.01 59.98 59.99
89.99 44.45% 40.0006 40.01 49.98 49.99
89.99 38.89% 34.9971 35.00 54.99 54.99

Rounding to the nearest cent can't produce the first two. Rounding up gives all three.

Eight discounted lines from recorded calculate fixtures elsewhere also fit rounding up: 7 of 8 directly. The eighth ends in .99, which fits rounding up if that offer had a .99 ending (its settings aren't in the recording). Rounding to the nearest cent fits 4 of 8.

verify didn't catch this because it allows a one-cent-per-unit tolerance.

What changes

  • landed_unit: quantizes the discount with ROUND_CEILING. The price_rounding step is unchanged.
  • Forecasts: some move by a cent per unit. Buy 2 at 55% off 49.95 is now 22.47 a unit (44.94 for two), not 22.48. Buy 2 get 1 at 59.99 now lands at 119.97, not 120.00.
  • Larger moves with an ending: with a .99 ending, 52% off 49.99 now forecasts 23.99, not 24.99, because the up-rounded unit drops below the whole dollar.
  • What the skill sends: the requests are byte-identical. The one golden hash recaptured (quantity) differs only in the Buy 2 landed row.
  • Docs: offer-doctrine.md (a new rounding bullet with the evidence, the buy-2-get-1 and voucher examples), worked-examples.md, admin-api-contract.md, SKILL.md, and one rationale string now say "rounded up to the cent".

Patch release, 1.3.0 → 1.3.1.

Verification

  • python3 -m pytest next-campaigns-create/tests: 736 passed. That includes a new LandedUnitRounding test pinning the three calculate prices above.
  • scripts/check_skill_versions.py --base origin/main passes.
  • scripts/check_public_safety.py passes.

@kilo-code-bot

kilo-code-bot Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
next-campaigns-create/scripts/campaign_admin.py 950 The price_rounding composition is still unconfirmed and the refusal set it governs still silently shrank, with no regression test. The docstring caveat added at lines 947-949 states the confirmation gap, but the requested test for a dollar-boundary anchor was not added, and the refusal-set change (e.g. 20.20 at 1% with --rounding 0.95: was refused at 20.95, now lands at 19.95) is untested. An active inline comment on this line already covers this defect, so it is not repeated inline.
Files Reviewed (2 files)
  • next-campaigns-create/scripts/campaign_admin.py - 1 issue (1 inline)
  • next-campaigns-create/tests/test_campaign_admin.py - 0 issues
Verified correct
  • The previous dollar-off upsell-hint defect is fixed. campaign_admin.py:1483-1486 now searches the actual landing for every whole percentage 1-99 (priced with the plan's --rounding) and picks the one whose landing is nearest the pinned target, breaking ties toward the arithmetic percentage. This removes the continuous-inverse error: with --rounding 0.00 and --upsell 23:39.95:50 the hint now reads "To land near 19.00, pass --upsell 23:49.95:61 (lands at 19.00)" instead of suggesting 62% (which lands at 18.00).
  • The fits filter is correct and preserves the documented contract. Only landings strictly below the package price are suggested, matching check_rounding_discount's refusal rule (campaign_admin.py:964), so the hint never proposes a percentage that recommend would later refuse with "price_rounding ... not below ...".
  • The new test genuinely pins the fix. test_campaign_admin.py:3805-3813 asserts both the suggested percentage/landing in the refusal message and that recommend with that percentage produces the same unit_after (19.00), so the advice and the plan agree.
  • The scan cannot change existing no-rounding behaviour. Without --rounding, landed_unit is continuous in the percentage, so the nearest landing to target is the percentage nearest exact; the tie-break abs(Decimal(w) - exact) reproduces the previous ROUND_HALF_UP choice, which the pre-existing test at test_campaign_admin.py:3784-3794 still asserts (60%, landing at 19.98).
  • No new inline comment was posted. The only unresolved defect is already covered by an active inline comment on campaign_admin.py:950, so re-posting it would be a duplicate.

Fix these issues in Kilo Cloud

Previous Review Summaries (3 snapshots, latest commit 44d986e)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 44d986e)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
next-campaigns-create/scripts/campaign_admin.py 1475 Threading --rounding into the upsell hint's target is correct, but whole is still chosen by inverting that (now pinned) target continuously and rounding to a whole percentage, while the landing it promises is a quantised function of whole. The quoted target and the promised landing can now differ by a full dollar. Verified: --rounding 0.00 with --upsell 23:39.95:50 quotes "To land near 19.00, pass --upsell 23:49.95:62 (lands at 18.00)" (60 lands exactly on 19.00); --rounding 0.99 with --upsell 16:29.95:70 against a 39.95 package quotes "To land near 8.99, ... (lands at 9.99)" (78 lands exactly on 8.99). SKILL.md:920 documents the contract as "the whole percentage that lands nearest the price asked for". (Inline comment posted.)
next-campaigns-create/scripts/campaign_admin.py 950 The price_rounding composition is still unconfirmed and the refusal set it governs still silently shrank, with no regression test. The docstring caveat added at lines 947-949 states the confirmation gap, but the requested test for a dollar-boundary anchor was not added, and the refusal-set change (e.g. 20.20 at 1% with --rounding 0.95: was refused at 20.95, now lands at 19.95) is untested. An active inline comment on this line already covers this defect, so it is not repeated inline.
Files Reviewed (2 files)
  • next-campaigns-create/scripts/campaign_admin.py - 2 issues (1 inline, 1 summary-only)
  • next-campaigns-create/tests/test_campaign_admin.py - 0 issues
Verified correct
  • The incremental commit's string changes are complete and consistent. campaign_admin.py:92 (the ZERO_DECIMAL_CURRENCIES comment) and campaign_admin.py:2066-2068 (the zero-decimal-currency rationale) now both say "up to the cent", matching references/admin-api-contract.md:348 and the rationale string itself. The previous review's finding on the stale "to cents" wording is fully resolved — no operator-facing string in the skill still contradicts the rule.
  • The new test_upsell_percentage_hint_prices_with_the_plan_rounding test is correct and meaningful. Hand-checked: with --rounding 0.99 and --upsell 23:39.95:50, target = landed_unit(39.95, 50, "0.99") = 19.97 -> floor 19 -> 19.99; exact = (49.95 - 19.99) / 49.95 * 100 = 59.9799...% -> whole = 60; landed_unit(49.95, 60, "0.99") = 49.95 - 29.97 = 19.98 -> floor 19 -> 19.99. Both the hint string and the plan's unit_after are 19.99, so the test genuinely pins the fix. The fixture's variant 23 is the hero at 49.95, and the second recommend call reuses hero-23 (same variant, same price), which is the documented path.
  • ending is validated before use. a.rounding is read inside add_extra, but add_extra is first called at line 1722, well after the PRICE_ROUNDINGS validation at lines 1531-1533, so an invalid --rounding still raises CampaignAdminError rather than an InvalidOperation traceback from Decimal(rounding) inside landed_unit.
  • The hint's ending matches what the upsell voucher actually carries. The voucher is built with "price_rounding": rounding at line 1805 from the same rounding = a.rounding if a.rounding else None, so the hint and the offer agree on the ending — the earlier "$0.99 error in the advice" is gone for the case the new test covers.
  • No existing test would now fail. The only hard-coded expectations touched by the ceiling rule were re-derived in the earlier commits (22.47 / 44.94, 19.97, 120.00 -> 119.97, 101.85) and the six rounding-refusal cases still refuse with the same messages, because each of those discounts has a third decimal >= 5 and rounds identically under both modes.

Fix these issues in Kilo Cloud

Previous review (commit 64d52ad)

Status: 3 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
next-campaigns-create/scripts/campaign_admin.py 1642 Two operator-facing strings still say the engine "rounds a percentage discount to cents" — the zero-decimal-currency rationale at campaign_admin.py:2064-2066 and the ZERO_DECIMAL_CURRENCIES comment at campaign_admin.py:92 — contradicting this changed rationale string and references/admin-api-contract.md:348, which this PR changed to "up to the cent". (Inline comment posted.)
next-campaigns-create/scripts/campaign_admin.py 950 The price_rounding composition is still unconfirmed and the refusal set it governs still silently shrank, with no regression test. The docstring caveat added at lines 947-949 states the confirmation gap, but the requested test for a dollar-boundary anchor was not added, and the refusal-set change (e.g. 20.20 at 1% with --rounding 0.95: was refused at 20.95, now lands at 19.95) is untested. An active inline comment on this line already covers this defect, so it is not repeated inline.

SUGGESTION

File Line Issue
next-campaigns-create/scripts/campaign_admin.py 947 The upsell "nearest landing" hint (campaign_admin.py:1473-1480) was not updated for the ceiling rule: it inverts the now-ceiling-derived target with a continuous inverse rounded ROUND_HALF_UP, and hard-codes rounding=None although the upsell voucher carries the plan-level --rounding (campaign_admin.py:1787, :1803). Verified case: an upsell price of 40.00 at 50% against a package already at 40.00 yields a hint of "lands at 20.00", but with --rounding 0.99 the plan lands at 20.99 — a $0.99 error in the advice the operator acts on. (Inline comment posted.)
Files Reviewed (11 files)
  • next-campaigns-create/scripts/campaign_admin.py - 3 issues (2 inline, 1 summary-only)
  • next-campaigns-create/tests/test_campaign_admin.py - 0 issues (prior findings resolved)
  • next-campaigns-create/tests/test_campaign_edit.py - 0 issues (prior finding resolved)
  • next-campaigns-create/references/worked-examples.md - 0 issues (prior finding resolved)
  • next-campaigns-create/references/offer-doctrine.md - 0 issues
  • next-campaigns-create/references/admin-api-contract.md - 0 issues
  • next-campaigns-create/SKILL.md - 0 issues
  • next-campaigns-create/README.md - 0 issues
  • next-campaigns-create/examples/campaign-plan.example.json - 0 issues
  • next-campaigns-create/tests/test_wrapper.py - 0 issues
  • skills.json - 0 issues
Verified correct
  • Every arithmetic claim in the PR, hand-checked against the ceiling rule. 89.99 at 33.34% → 30.01 discount / 59.98 unit; at 44.45% → 40.01 / 49.98; at 38.89% → 35.00 / 54.99; 49.95 at 55% → 27.48 off / 22.47 unit / 44.94 total; BXGY at 59.99 → 119.97 (and the 0.95 case at 49.95 → 33.95 a unit / 101.85); the voucher worked example (45.53 at 9.97% → 4.54 → 40.99; at 10% → 4.56 → 40.97); the reland table (22.47 a unit, 67.41 in all); the 300-anchor BXGY case (600.03 vs 600.00); the EUR 44.00 / JPY 7000 rows (Buy 3 → 52.80; Buy 1 → 3500.00). All correct.
  • The incremental commit's changes are correct. The worked-examples.md:27 prose now reads 27.48 off / 22.47 / 44.94, and README.md:134 plus examples/campaign-plan.example.json:193-194 carry the same pair — the stale 22.48 / 44.96 values are gone from every file. The new test_a_fraction_of_a_cent_rounds_the_discount_up (49.95 at 55% → 22.47) genuinely discriminates ceiling from half-up, which the exact-discount case does not. The test_campaign_edit.py rewrite to 51% restores the pinned/unpinned distinction (24.99 pinned vs 24.49 unpinned), and the inline comment's arithmetic is right. The LandedUnitRounding docstring now correctly says the 33.34% and 44.45% lines discriminate while 38.89% lands on the same cent either way.
  • No existing test would now fail. Every hard-coded landed expectation across the suite was re-derived under the ceiling rule, including all six rounding-refusal cases (20.50, 20.95, the upsell at 39.95, the exit voucher at 24.95, the per-tier exit check at 22.99, and the EUR 20.50 case) — all still refuse with the same messages, because each of those discounts has a third decimal ≥ 5 and rounds identically under both modes.
  • The golden hash recapture is legitimate. The quantity pin's wire requests are unchanged (offer percentages and price_rounding are untouched); only Buy 2's forecast moved. The bxgy and gwp pins are correctly unchanged. The public-safety: allow high-entropy: suppression sits on the correct line.
  • The new landed_unit docstring caveat is accurate. A 1-cent discount change moves the pinned unit by exactly $1.00 only when it crosses a dollar boundary, and verify's 1-cent-per-unit tolerance would fail loudly rather than let a wrong composition through — so "verify is the check" holds.
  • Versioning and packaging comply. 1.3.0 → 1.3.1 is in SKILL.md frontmatter, skills.json and test_wrapper.py; "Patch" is the right classification — no new command, no new write surface, no contract removed.
  • ROUND_CEILING vs ROUND_UP cannot diverge. Every anchor is validated positive and every percentage into (0, 100], so the two modes are identical for all real inputs.

Fix these issues in Kilo Cloud

Previous review (commit 5d5da11)

Status: 8 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 4
SUGGESTION 4
Issue Details (click to expand)

WARNING

File Line Issue
next-campaigns-create/references/worked-examples.md 26 The worked-example prose on line 27 still states the old half-up values (27.47 off, unit 22.48, total 44.96), contradicting the table row changed to 22.47 / 44.94 on line 23. The same stale pair also ships in next-campaigns-create/README.md:134 (merchant-facing price table) and next-campaigns-create/examples/campaign-plan.example.json:193-194 (the example plan SKILL.md:1891 presents as recommend output) — neither file was touched by this PR.
next-campaigns-create/tests/test_campaign_edit.py 597 Pinned and unpinned branches now both assert "23.99", so the test no longer distinguishes the price_rounding path from no rounding; a regression that drops the floor-then-add-cents step would still pass. The pinned to .99 comment is also misleading (floor(23.99) + 0.99 is a no-op).
next-campaigns-create/scripts/campaign_admin.py 948 The ceiling rule is evidenced only for offers with no price_rounding, but it now also governs the price_rounding path, where the floor step amplifies a 1-cent discount change into a $1.00 pinned-unit change. The refusal set in check_rounding_discount silently shrinks (e.g. 20.20 at 1% with --rounding 0.95 was refused at 20.95, now lands 19.95) with no test coverage.
next-campaigns-create/scripts/campaign_admin.py 2063 User-facing rationale string still says "the cart engine rounds a percentage discount to cents in every currency", contradicting references/admin-api-contract.md:348 which this PR updated to "rounds a discount up to the cent". The identical stale wording remains in the ZERO_DECIMAL_CURRENCIES comment at campaign_admin.py:92. (Summary-only: neither line is in the diff.)

SUGGESTION

File Line Issue
next-campaigns-create/tests/test_campaign_admin.py 391 test_exact_discount_is_not_rounded uses 40.00 at 25% → exactly 10.00, identical under ROUND_CEILING and ROUND_HALF_UP, so it does not pin the rounding mode. This matters because the fake cart engine prices through ca.landed_unit itself, so no verify/calculate test can detect a wrong mode.
next-campaigns-create/tests/test_campaign_admin.py 386 The 38.89% case is mode-neutral (34.997111 ceils to 35.00, same as half-up). Only 33.34% and 44.45% discriminate, so the class docstring overstates the evidence.
next-campaigns-create/scripts/campaign_admin.py 1475 The upsell "nearest landing" hint still picks its whole percentage with ROUND_HALF_UP on a continuous inverse computed from a now-ceiling-derived target (lines 1471-1478), so it can be one step off the true nearest landing. It also hard-codes rounding=None while the plan may carry a --rounding, so the promised landing can differ from what check_rounding_discount produces. (Summary-only: not in the diff.)
next-campaigns-create/scripts/campaign_admin.py 4044 The verify tolerance comment still attributes the one-cent-per-unit bound to the forecast's own rounding mismatch, which this PR removes. The residual reason for the tolerance is the unconfirmed price_rounding pin step. Note the tolerance can still mask a 1-cent-per-unit rule error on small carts (3 units → delta 0.03 vs tol 0.03), so the PR's premise rests on the two carts/calculate probes, not on verify. (Summary-only: not in the diff.)
Files Reviewed (9 files)
  • next-campaigns-create/scripts/campaign_admin.py - 4 issues (1 inline, 3 summary-only)
  • next-campaigns-create/tests/test_campaign_admin.py - 2 issues (both inline)
  • next-campaigns-create/tests/test_campaign_edit.py - 1 issue (inline)
  • next-campaigns-create/references/worked-examples.md - 1 issue (inline)
  • next-campaigns-create/references/offer-doctrine.md - 0 issues (all updated claims hand-verified correct)
  • next-campaigns-create/references/admin-api-contract.md - 0 issues
  • next-campaigns-create/SKILL.md - 0 issues
  • next-campaigns-create/tests/test_wrapper.py - 0 issues
  • skills.json - 0 issues

Also read for context (not changed by this PR): next-campaigns-create/README.md, next-campaigns-create/examples/campaign-plan.example.json, next-campaigns-create/tests/test_multi_currency.py, next-campaigns-create/tests/test_campaign_clone.py, next-campaigns-create/tests/test_edit_update_interplay.py, next-campaigns-create/tests/test_update_check.py, next-campaigns-create/tests/fixtures/, CONTRIBUTING.md, scripts/check_skill_versions.py, scripts/check_public_safety.py, scripts/skill_catalog.py.

Verified correct
  • Arithmetic of every new claim in the PR — 89.99 at 33.34% → 30.01 discount / 59.98 unit; at 44.45% → 40.01 / 49.98; at 38.89% → 35.00 / 54.99; 49.99 at 52% → 26.00 / 23.99; buy-2-get-1 at 59.99 → 119.97; 49.95 at 55% → 27.48 / 22.47 / 44.94; the voucher worked example (45.53 at 9.97% → 40.99, at 10% → 40.97); the worked-examples bxgy rows (33.30 / 99.90, 101.85 with .95); the reland table (22.47 a unit, 67.41 in all). All hand-checked and correct.
  • No test would now fail. Every hard-coded landed expectation across the suite was hand-checked against the ceiling rule (including the multi-currency EUR 44.00 and JPY 7000 rows, the rounding-refusal cases at 20.50/20.95/39.95/24.95/22.99, and the golden-pin inputs). All are consistent under the new rule.
  • Golden hash recapture is legitimate. The quantity pin's wire requests are unchanged (offer percentages and price_rounding are untouched); only Buy 2's forecast moved. The bxgy and gwp pins are correctly unchanged — their inputs are exact or round identically under both modes. The # public-safety: allow high-entropy: suppression matches the repo's established convention and sits on the correct line.
  • Versioning and packaging comply. 1.3.0 → 1.3.1 is in both SKILL.md frontmatter and skills.json; no stale version pin remains; the root README skills table needs no regeneration (no version column, description unchanged); SKILL.md has no changelog section to update; the launcher reads the version dynamically. "Patch" is the right classification under CONTRIBUTING.md — no new command, no new write surface, no contract removed.
  • ROUND_CEILING vs ROUND_UP — no divergence is reachable: every anchor is validated positive (DECIMAL_RE, > 0 check, prices-file d < 0 refusal) and every percentage is validated into (0, 100], so the two modes are identical for all real inputs.
  • All landed_unit call sites — the guard in check_rounding_discount still guarantees unit < anchor, the unit <= 0 refusals still hold, the tier ladder still strictly decreases, and the gift (100%) and exit-voucher stacking paths are unaffected.

Fix these issues in Kilo Cloud


Reviewed by minimax-m3 · Input: 63.1K · Output: 2.5K · Cached: 597.5K

…nned edit test distinct, add a case that tells the rounding rules apart
@next-devin
next-devin merged commit fd52fb6 into main Nov 8, 2026
3 checks passed
@next-devin
next-devin deleted the create-landed-round-up branch November 8, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant