Skip to content

Release hardening: APR corrections, typed JSON contract, property tests, fail-closed release - #1

Merged
matveygreschner merged 13 commits into
mainfrom
overnight-hardening
Nov 27, 2026
Merged

matveygreschner merged 13 commits into
mainfrom
overnight-hardening

Conversation

@matveygreschner

@matveygreschner matveygreschner commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Hardening pass over the released paths (engine, two skills, workbook). Nothing is tagged or released.

Corrections that change a reported figure

Each earlier figure was wrong; all are in the CHANGELOG.

  • unit: "month" with one month-end payment: Jan 28 → Feb 28 at 1% is 12.00% (was 10.90%).
  • Monthly series on the 29th/30th: monthly unit inferred (22.19%, was 22.37% on five weeks) and no longer flagged irregular, which could flip a disclosure verdict.
  • Average-period fallback rounds to any standard interval; month-end anchoring follows the series.
  • Loan payments round to the cent unless that would refund on the final payment (engine and workbook).
  • SBA 7(a) 90-day combining: the earlier loan's fee must be given with its amount (it defaulted to $0, overstating APR ~0.46 pt); remaining ceiling clamped at 0.
  • Equipment lease with no buyout and no end_of_term: lease_character_unknown, not a nominal-buyout purchase.

Contract and safety

  • Every JSON argument is checked against the command's signature: wrong types are a ValueError naming the argument; true/false is never a number; dates are YYYY-MM-DD on every Python version; 12.0 accepted for a whole number. Remaining engine errors are wrapped with their original type.
  • Skills pass arguments as a JSON file on stdin, treat document text as data, never ask for credentials. Released skills exclude the workbook writer and optimizer.
  • An O(k²) loop that could hang the disclosure CLI for minutes is closed-form; a 20,000-debit schedule solves in ~1.5 s (monotone fast path).

Tests

198 → 321 tests.

  • Hypothesis properties: invariants, a closed form, metamorphic relations.
  • Independent oracles: brentq, the XIRR identity, a separate Appendix J model.
  • JSON fuzz with the fallback disabled, and the skill CLIs under python -I.
  • Every bug found has a regression test.
  • Nightly deep run: 77 properties at 2,000 examples, 6.6 min.

CI and release

  • CI: Python 3.9 / 3.10 / 3.13; ruff, mypy, coverage 85% overall and 94% on apr.py + disclosures.py (measured 94% / 96%); workbook verified against the engine (291 comparisons, 0 mismatches).
  • Release: fails on a tag/version mismatch or an existing release; regenerates and verifies the shipped workbook; publishes SHA256SUMS.

How this was found

  • A red-team of the skills.
  • Differential fuzzing against an independent Appendix J model.
  • Three Codex reviews.
  • A 16-agent bracket of competing hardening plans. The winning plan's patch was applied, then reviewed by Codex; its 4 findings are fixed here with tests.

Matthew Greschner and others added 13 commits November 27, 2026 00:46
… coverage

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…iance, cent rounding, JSON API fuzz

Fast 'ci' profile by default; HYPOTHESIS_PROFILE=deep runs 2000 examples per property.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ata (mocked) and after-tax views

api.py 47% -> 92%, compare.py and live.py 100%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Correctness (differential fuzz against an independent implementation, 10,000 schedules):
- The no-common-period average now rounds to every standard interval of (b)(3)(iii), including
  multiples such as 6 weeks; it previously chose only named units (0.32-point APR error).
- A month-end series keeps its month-end anchor when one payment falls mid-month, and month-end to
  month-end gaps (Feb 28 -> Mar 31) count as a month.
- Cent rounding could compound into a refund on the final payment at high rates over long terms
  (found by the property tests); the payment is then rounded down instead, in the engine and workbook.

Safety (skill red-team):
- Skills pass arguments as a JSON file on stdin; document text never reaches the command line, and is
  treated as data, not instructions. No bank credentials, SSNs or EINs are ever requested.
- Released skills no longer ship the workbook writer or a `python -m capkit` entry point that bypassed
  the command allow-list.
- Long schedules solve in about a second: ordinary schedules (advances before payments) have one
  root, so the solver bisects instead of scanning. Monthly sales paths no longer rebuild their dates
  quadratically. Flow and offer counts are capped and echoed errors are truncated.
- Stop tracking .coverage (it held absolute paths).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ctuarial and U.S. Rule)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Solver fast path: a lower bracket too far out to evaluate (overflow on long schedules) moves toward
  zero; exact roots on the rate floor or ceiling are accepted (found by the deep property run too).
- Month-end anchoring: an isolated February month-end payment in a 15th-of-month schedule is measured
  to the same date; month-end anchors apply only when month-end payments dominate.
- Interval classification uses the series convention, so a 31st payment in a 30th-of-month series is
  irregular again.
- Averaging ties compare in exact integers and go to the shorter interval.
- Cent rounding: integer cents, half up as Excel ROUND, round down only when rounding up would refund,
  with no epsilon that could bump a cent; Python and the workbook formula agree on the edge cases.
- APR flow cap leaves room for a full-length schedule; truncated errors stay within the limit;
  build_skills --check fails if excluded files appear in a released skill.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- unit "month" with a single month-end payment measures whole months
  (Jan 28 -> Feb 28 at 1% is 12.00%, was 10.90%)
- monthly series on the 29th/30th infer a monthly unit and are not
  irregular (22.19%, was 22.37% on a five-week unit)
- SBA 90-day combining requires the earlier loan's fee with its amount
  (a missing fee was taken as $0); the remaining ceiling is never negative
- a lease with no buyout and no end_of_term is lease_character_unknown,
  not a nominal-buyout purchase; end_of_term "return" with a buyout errors
- prepaid fees on the net basis also report the before-fees reading
- closed-form month count removes an O(k^2) loop that could hang the CLI
- every JSON argument is checked against its signature: wrong types are a
  ValueError naming the argument, true/false is never a number, dates are
  YYYY-MM-DD on every Python version, 12.0 is accepted for a whole number
- workbook verifier compares rates to 1e-6 and checks the verdict
- tests: brentq and XIRR oracles, closed-form and metamorphic properties,
  JSON fuzz with and without the fallback, skill CLI contract under -I

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The release checks tag = version, runs lint/types/tests, regenerates and
verifies the shipped workbook, publishes SHA256SUMS, and no longer
replaces assets of an existing release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… don't break the 3.9 check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@matveygreschner
matveygreschner merged commit af4b418 into main Nov 27, 2026
6 checks passed
matveygreschner added a commit that referenced this pull request Nov 27, 2026
Release hardening: APR corrections, typed JSON contract, property tests, fail-closed release
matveygreschner added a commit that referenced this pull request Nov 27, 2026
Release hardening: APR corrections, typed JSON contract, property tests, fail-closed release
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