Skip to content

Show average savings per extra dollar over a forward window - #116

Merged
MaxGhenis merged 6 commits into
mainfrom
next-dollar-followups
Dec 3, 2026
Merged

MaxGhenis merged 6 commits into
mainfrom
next-dollar-followups

Conversation

@MaxGhenis

@MaxGhenis MaxGhenis commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Replaces the nearest-grid central difference on the US results card with the average reduction in net taxes per extra dollar over a forward window above the gift (includes and supersedes #113).

What changes

  • Forward-window marginal savings rate (api/main.py, api/schemas.py, api/simulations.py): /api/calculate computes (net tax at gift − net tax at gift + window) / window using NEXT_DOLLARS ($100) or 2,000 float32 spacings of |net_tax| when wider, shares the point cache with /api/savings, and returns marginal_savings_window in CalculateResponse.
  • Sweep overlap (api/main.py, api/simulations.py): Splits point_metrics_many into start_points and point_results so the wizard sweep launches immediately after the baseline resolves rather than waiting for the extra-gift point run.
  • Rollout-safe card copy & sign (frontend/src/components/Results.tsx, frontend/src/lib/types.ts): Displays "Average savings per extra dollar" / "Reduction in net taxes if you give a little more" when marginal_savings_window is present, and falls back to step-agnostic copy ("Marginal tax savings rate" / "Estimated tax savings per dollar over a small extra gift") if an older API deployment omits the field.
  • FAQ & tests (frontend/src/components/faq/questions.tsx, frontend/src/lib/faqRules.json, tests/test_next_dollar_rate.py, tests/test_faq_numbers.py): Documents the $100 window, the ~$500,000 net-tax widening threshold, and negative-rate model estimates (including itemization-election flip artifacts, Itemization choices ignore state subtractions for non-itemizers, so state tax jumps when a gift tips the choice (Colorado, Minnesota) policyengine-us#11282); pins the § 170(p) cap cases, $925 blend, overlap scheduling, and fallback card rendering.

MaxGhenis and others added 4 commits December 1, 2026 10:13
/api/calculate's marginal_savings_rate was the donation sweep's central
difference at the nearest grid point, which averages the rates on either
side of a kink. A single filer giving $1,000 in 2026 sits on the 170(p)
cap, so Texas showed 14.7% where the next dollar saves nothing, and
Massachusetts 19.7% where it saves 5%.

The rate now comes from a point run at the gift plus $100, in the same
parallel batch as the $0 and gift runs: (net tax at the gift - net tax
$100 above) / 100. Smaller steps turn float32 rounding into rate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
policyengine-us returns taxes as float32, whose spacing grows with the
tax. Over a fixed $100 window, a $100 million earner's 35% read 32% and a
$25 million earner's 37.7% read 39.0%, worse than the old sweep figure.
The window is now $100, or 2,000 float32 spacings of the net tax when that
is wider ($125 from $524,288 of net tax, $8,000 at $40 million). A wider
window costs one more point run, alongside the sweep.

The FAQ states the window from faqRules.json, which a test ties to the
API. Comments in App.tsx, headlineFirst.ts and CLAUDE.md now say where
the card's rate comes from.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Round 1 of the review (a Codex cloud review at 83f8269) found the card
promised the next $1 while showing the average over a $100 window: a
Texan giving $925 saves 22% on the next $75 and 0% after the cap, so the
card read 16.5%. The card now reads "Average savings per extra dollar",
"Change in net taxes if you give a little more", and the FAQ says the
figure is the reduction in net taxes per dollar over the next $100, how
the range widens, and what a negative rate means.

Also from the review: the FAQ threshold uses the magnitude of net tax
(a -550,000 check), a comment notes that intermediate rounding can still
move the displayed figure, and the float32 spacing example is corrected.
A test pins the $925 blend.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An in-session check of #113 at bfcda89 confirmed three P2 findings:

- The card's description, "Change in net taxes if you give a little
  more", sat under a figure that is positive when net taxes fall. It
  now reads "Reduction in net taxes if you give a little more", the
  FAQ's convention, and a test pins it.
- After the site's /api/savings call the gift + $100 run is
  /api/calculate's only new point run, and the wizard sweep waited for
  it. calculate_donation now starts the three point runs, waits for $0
  and the gift, starts the sweep, then waits for the rate's run. A test
  with fake runs on a thread pool fails at bfcda89 and passes here.
  point_metrics_many is now start_points plus point_results.
- A step in net tax inside the window counts in full. A comment and a
  unit test say so, and point to PolicyEngine/policyengine-us#11282,
  where a gift that tips an itemization election makes such a step.

Also pins the Giving Tuesday posts' joint link (TX, $150,000, $2,000:
0%) and renames the parametrized test, which covers a blend case too.

Tests: test_next_dollar_rate 18 passed; test_simulation_cache,
test_workers and test_faq_numbers 41 passed; test_household_payload
-k agree_at_the_endpoint 5 passed; vitest 274 passed; tsc clean; lint
0 errors (1 existing warning); black and isort clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
givecalc Ready Ready Preview Dec 3, 2026 2:48pm UTC

Request Review

@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Agent review for Max, written by Codex and posted by Antigravity for Max Ghenis (exact reviewed head 85885938b2f8d8ca7b26def6870f4c29c4922617).

VERDICT: REQUEST_CHANGES
HEAD: 8588593

  • P1 frontend/src/components/Results.tsx:283 — The new label can display the old rate. Vercel and Modal deploy independently, and the default Vercel configuration points to production Modal (frontend/next.config.ts:7, README.md:68, .github/workflows/deploy-modal.yml:3). In the inferred rollout scenario where Vercel updates first, a Texas single filer earning $75,000 and giving $1,000 would see 14.7% labeled as the forward average. I reproduced the legacy calculation, ($100 × 22%) / $150 = 14.7%, and confirmed the new endpoint returns 0.0%. Have the API identify the forward window in its response and gate the new card on that field.
  • P2 api/main.py:408 — The prior rounding request is partially addressed. The comment quantifies endpoint rounding and names intermediate rounding as a remaining source of display error. It should explicitly say final endpoint rounding can move the displayed tenth. Over $100, synthetic endpoint taxes of $300,000 and $299,994.951 yield 5.049%, displayed as 5.0%. Casting those endpoints to float32 makes the second $299,994.9375, yielding 5.0625%, displayed as 5.1%.
  • P2 frontend/src/components/faq/questions.tsx:149 — Qualify the explanation of negative rates. For the documented Colorado single filer with $25,532 in wages and $6,000 in property taxes, I reproduced the $9,319-to-$9,419 window. The default election gave ($2,790.6641 − $3,168.7593) / $100 = −378.1%. Keeping the standard deduction gave ($2,790.6641 − $2,786.2642) / $100 = +4.4%. Describe a negative rate as a model estimate and acknowledge the known itemization artifact. PolicyEngine US #11282

The other two prior findings are closed. The subtitle describes a positive rate as a reduction in net taxes at frontend/src/components/Results.tsx:285. With workers available, the wizard starts the sweep before waiting for the extra-gift result at api/main.py:453 and api/main.py:464. The regression test at tests/test_next_dollar_rate.py:182 passed.

Cap arithmetic

For 2026, § 170(p) caps the federal deduction for qualifying cash gifts by nonitemizers at $1,000 single and $2,000 joint. At api/main.py:418, the rate is (net tax at gift − net tax at gift + window) / window, with the second tax evaluated at the higher gift. The window is the greater of $100 and 2,000 float32 spacings at the absolute net tax. All examples below use $100. Above the cap the code still runs the full window, and the federal deduction stays flat while the filer remains a nonitemizer. 26 U.S.C. § 170(p) · Effective date

2026 household Federal taxable income over the window Savings per extra dollar
Single, $75,000 wages, $1,000 gift $75,000 − $16,100 − $1,000 = $57,900 at both ends TX $0 / $100 = 0%. MA ($100 × 5%) / $100 = 5%.
TX single, $75,000 wages, $500 gift $58,400 → $58,300, both in the 22% bracket ($100 × 22%) / $100 = 22%.
Joint, $120,000 wages, $2,000 gift $120,000 − $32,200 − $2,000 = $85,800 at both ends TX (12% × $0) / $100 = 0%. MA ($100 × 5%) / $100 = 5%.
Joint, $150,000 wages, $2,000 gift $150,000 − $32,200 − $2,000 = $115,800 at both ends TX (22% × $0) / $100 = 0%. MA ($100 × 5%) / $100 = 5%, also confirmed in the pinned model.

At a $925 Texas gift, the literal next dollar saves 22 cents and the card averages ($75 × 22% + $25 × 0%) / $100 = 16.5%. Texas has no personal income tax. Massachusetts allows its own deduction for these nonitemizers at a 5% wage-income rate. IRS 2026 brackets and deductions · Texas taxes · MA deduction · MA federal conformity · MA rates

Verification

Reviewed the combined diff from main, including all frontend changes. git diff --check passed. The specified environment had PolicyEngine US 2.23.4 and collected zero tests across the four attempts because FastAPI or SciPy was missing. I reran each file separately in an existing environment with GiveCalc’s locked 2.156.4. All 60 passed: rate 18, FAQ 20, cache 16, workers 6.

Frontend tests, lint, and tsc were left to CI under the no-install rule. Exact-head CI passed the frontend tests, lint, and build, and the build log confirms TypeScript checking completed. The live rollout order remains unverified. The shared clone and temporary folders were removed. Exact-head CI

@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Addressed the P1 and two P2 findings at 366abe81a288ae888f960abd02712f5694ae83fd:

  • P1 (frontend/src/components/Results.tsx:283, api/schemas.py, api/main.py, frontend/src/lib/types.ts): Added optional marginal_savings_window to CalculateResponse and gated the new card label (Average savings per extra dollar / Reduction in net taxes if you give a little more) on that field, falling back to Saved on the next $1 / Tax saved if you gave a little more when an older API deployment omits it.
  • P2 (api/main.py:408): Noted explicitly that final net_tax endpoint float32 rounding can also move the displayed tenth near a half-tenth.
  • P2 (frontend/src/components/faq/questions.tsx:149): Qualified negative rates as a model estimate that includes known deduction steps when crossing an itemization threshold.

Verified locally in .venv: pytest tests/test_next_dollar_rate.py tests/test_faq_numbers.py (38 passed), vitest run (20 files, 275 passed), black --line-length 79 --check, isort --check, eslint . (0 errors), and npx tsc --noEmit.

@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Updated 8f22d9c7de45b1fbe4fb829c294dbd6a820ee773 to address Sol r2 findings:

  1. Updated the unmarked-response fallback copy in frontend/src/components/Results.tsx (Marginal tax savings rate / Estimated tax savings per dollar over a small extra gift) so both pre-Show the average savings per extra dollar above the gift #113 and unmarked Show the average savings per extra dollar above the gift #113 API responses stay accurately described when marginal_savings_window is absent.
  2. Clarified frontend/src/components/faq/questions.tsx to explicitly describe negative rates at threshold flips as model-choice artifacts overlooking state non-itemizer subtractions.
  3. Verified eslint (0 errors), tsc --noEmit, vitest (20 files / 275 passed), and pytest tests/test_next_dollar_rate.py tests/test_faq_numbers.py (38 passed).

@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Sol r3 independent review (gpt-6.2-sol, ultra) returned VERDICT: APPROVE at 8f22d9c7de45b1fbe4fb829c294dbd6a820ee773:

  • Both round-2 findings (unmarked fallback copy in Results.tsx and artifact clarification in faq/questions.tsx) are closed with zero new P0–P3 findings.
  • Local post-edit checks (eslint 0 errors, tsc --noEmit, vitest 20 files / 275 tests, pytest 38 tests) and FAQ numbers CI (47130738965) passed; waiting on CI / test (3.13) (47130738879) on 8f22d9c7de (keeping PR in Draft until full CI completes).

@MaxGhenis MaxGhenis changed the title Overlap the rate run with the sweep and fix the card's sign Show average savings per extra dollar over a forward window Dec 3, 2026
@MaxGhenis
MaxGhenis marked this pull request as ready for review December 3, 2026 19:01
@MaxGhenis
MaxGhenis merged commit 50f0d6f into main Dec 3, 2026
7 checks passed
@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Agent-written for Max, by Antigravity for Max Ghenis.

Merge audit for 8f22d9c7de45b1fbe4fb829c294dbd6a820ee773 (squash commit 50f0d6fe01328af1c9c1272734a667bd2b203060):

  • Independent review:
    • Round 1 (combined diff from main at 85885938b2): VERDICT: REQUEST_CHANGES (1 P1 rollout label gate, 2 P2 endpoint rounding comment & FAQ negative-rate qualification).
    • Round 2 scoped (gpt-6.2-sol, ultra, at 366abe81a2): closed r1 P1 for pre-Show the average savings per extra dollar above the gift #113 API and r1 P2 rounding; flagged 1 new P1 (unmarked fallback copy) and 1 open P2 (FAQ artifact wording).
    • Round 3 scoped (gpt-6.2-sol, ultra, at 8f22d9c7de): VERDICT: APPROVE — both r2 findings closed, zero new P0–P3 findings.
    • Supersedes Show the average savings per extra dollar above the gift #113: all three findings from Show the average savings per extra dollar above the gift #113's round-2 review at bfcda89e35 (1 P1 subtitle sign, 2 P2 sweep overlap & endpoint rounding comment) are incorporated and closed here, allowing Modal and Vercel to deploy the forward window and marginal_savings_window field atomically.
  • CI: All 7/7 checks passed at exact head 8f22d9c7de45b1fbe4fb829c294dbd6a820ee773 (CI run 47130738879: test (3.13), Frontend build, Frontend tests, Frontend lint; FAQ numbers run 47130738965: regenerate; Vercel Preview Comments; Vercel – givecalc).

@MaxGhenis

Copy link
Copy Markdown
Contributor Author

Post-merge production verification (50f0d6fe01328af1c9c1272734a667bd2b203060, Modal deploy run 47180413888 succeeded, Vercel production deployed, https://givecalc.org/us/givecalc HTTP 200):

  • Live /api/health: 200, healthy, tax_year: 2026, simulation_workers: 4.
  • Live /api/calculate (wizard household payload, recorded 2026-12-03T19:05:09Z):
    • TX single, $75,000 wages, $1,000 gift: tax_savings $220.00, marginal_savings_rate 0.00% (was 14.67%).
    • MA single, $75,000 wages, $1,000 gift: tax_savings $270.00, marginal_savings_rate 5.00% (was 19.67%).
    • TX joint, $120,000 wages, $2,000 gift: tax_savings $240.00, marginal_savings_rate 0.00% (was 4.00%).
    • MA joint, $120,000 wages, $2,000 gift: tax_savings $340.00, marginal_savings_rate 5.00% (was 9.00%).
  • Live /api/calculate (legacy payload, verifying marginal_savings_window):
    • TX single $75k @ $1,000: 0.00%, marginal_savings_window: 100.0.
    • MA single $75k @ $1,000: 5.00%, marginal_savings_window: 100.0.
    • TX single $75k @ $925: 16.50%, marginal_savings_window: 100.0.
    • TX joint $150k @ $2,000: 0.00%, marginal_savings_window: 100.0.

This branch was successfully deployed

1 active deployment
Preview – givecalc — 8f22d9c7 Deployed Dec 3, 2026 by vercel[bot]
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