Skip to content

obr_shock: household lever no longer fails when the shock is shorter than the solve window - #283

Open
vahid-ahmadi wants to merge 1 commit into
mainfrom
vahid/r6-obr-shock-short-window
Open

vahid-ahmadi wants to merge 1 commit into
mainfrom
vahid/r6-obr-shock-short-window

Conversation

@vahid-ahmadi

Copy link
Copy Markdown
Contributor

What was wrong

obr_shock(var="HHDI_ADDFACTOR", ...) fails for any periods below 12, locally and on the hosted server:

TypeError: float() argument must be a string or a real number, not 'NoneType'

The model always solves to 2027Q4 at least (12 quarters from 2025Q1). It leaves the GDP-per-pound ratio undefined (None) in the quarters after the shock ends, because there is no revenue to divide by. The adapter rounded every entry with float(), so the call raised after both solves had finished. The household lever is the costing channel score_reform uses and the one lever the tool text recommends reading, so a short household shock is an ordinary request.

The ratio was added on 16 Nov 2026 (9b2c8e1d). The existing test patched the solve window down to the two shocked quarters, so it never saw a post-shock quarter.

Evidence

  • Local, obr-macroeconomic-model 0e44ec8 (the pin): core.obr_shock("HHDI_ADDFACTOR", 1000, periods=8) raises the error above. run_reform itself returns gdp_per_revenue_real = [0.0931, ..., 0.2793, None, None, None, None].
  • Hosted, 24 Nov 2026: start_job(tool="obr_shock", arguments={"var": "HHDI_ADDFACTOR", "shock": 1000, "periods": 8}), job fc-01M87ZTT0D4QEQB69M51NSAWFE, ran for about four minutes and then get_job_result returned the same float() error.
  • The default periods=12 is unaffected, which is why the drift canary and the site's worked example (both 12 quarters) pass.

What changed

  • core.obr_shock: gdp_per_revenue_current_price, gdp_per_revenue_real and cpi_pct_delta go through one helper that keeps None for an undefined quarter (None or NaN from the model). The lists stay the same length as results, so index i is still quarter i. I kept the None entries and did not truncate the lists, so a caller cannot misalign them with the rows.
  • mcp_server.obr_shock docstring: says the ratio is null after the shock ends.
  • Tests: a mocked-frame test over the real 12-quarter window with a None and a NaN tail, which also checks the payload is strict JSON; and a slow test that runs the installed model with periods=4.
  • Changelog entry.

No published number changes. Every site figure from this lever uses 12 shocked quarters, where each ratio is defined.

How verified

  • The new mocked test fails on main's core.py and passes with the fix.
  • pytest tests -q in integration/: 496 passed, 80 skipped (obr-macro-model 0e44ec8 and boe_var 17f5d82 installed).
  • pytest tests/test_wiring.py --runslow -k real_solve_shorter: passed against the real model (75 s).
  • Repo root: pytest tests -q 3281 passed; site_contract.py and site_nav.py clean.

Note for the merge

Merging redeploys the hosted MCP server (deploy-mcp.yml runs on integration/**), which is what clears the hosted failure.

🤖 Generated with Claude Code

… of raising

obr_shock(var='HHDI_ADDFACTOR') with periods < 12 raised TypeError after
both solves: the model leaves gdp_per_revenue_* None in post-shock quarters
and the adapter rounded them with float(). The lists now keep None there
and stay aligned with the result rows.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
macromod Ready Ready Preview Nov 25, 2026 12:05am UTC

Request Review

@vahid-ahmadi

Copy link
Copy Markdown
Contributor Author

Coverage note: the new slow test (test_obr_shock_household_lever_real_solve_shorter_than_window) is not in the nightly contract job's list, so it runs only under a local pytest --runslow. The mocked test in the same file runs in the fast CI suite and is the one that fails on main's code.

🤖 Generated with Claude Code

This branch was successfully deployed

1 active deployment
Preview — c07c1661 Deployed Nov 25, 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