Skip to content

refactor(macro-regime): retire dead _LEGACY_REGIME_COERCION shim (Phase 1B follow-on)#253

Merged
cipher813 merged 1 commit into
mainfrom
fix/retire-dead-regime-coercion-shim
May 29, 2026
Merged

refactor(macro-regime): retire dead _LEGACY_REGIME_COERCION shim (Phase 1B follow-on)#253
cipher813 merged 1 commit into
mainfrom
fix/retire-dead-regime-coercion-shim

Conversation

@cipher813
Copy link
Copy Markdown
Owner

What

Retires the now-dead _LEGACY_REGIME_COERCION migration shim — the P2 audit follow-up filed under the caution-regime-retirement arc (ROADMAP L226) and the residual flagged in ae-config PR #369.

Why it was dead code

_validate_regime is only ever called with parsed.market_regime (macro_agent.py), and with_structured_output(MacroEconomistRawOutput, include_raw=True) already constrains that to the 3-class RegimeLiteral ({bull, neutral, bear}, lib v0.42.0). A raw caution emission fails Pydantic at parse time — it never reaches _validate_regime, so _LEGACY_REGIME_COERCION.get(...) always returned None on the live path.

Now that the macro prompts dropped the 4-class vocabulary (ae-config #369, merged 2026-05-29), the trigger is gone.

Design choice — fail loud, don't re-introduce silent coercion

The shim's intent was graceful degrade-to-neutral. Per feedback_no_silent_fails, that's the wrong posture: a model contract violation (emitting an out-of-vocab regime) should surface loudly via the strict RegimeLiteral schema + STRICT_VALIDATION, not be masked as neutral. So this retires the shim rather than repositioning it — the schema becomes the single fail-loud enforcement point. A new guard test (test_legacy_coercion_shim_stays_retired) asserts the dict stays gone so it can't be silently re-introduced.

Changes

  • agents/macro_agent.py: delete _LEGACY_REGIME_COERCION + the coercion block in _validate_regime; docstring documents the schema-constrained-input contract.
  • tests/test_regime_3class_invariant.py: drop dead-branch coercion tests; add the stays-retired guard; update module docstring + no-guardrails test.
  • tests/test_state_schemas.py: comment fix (schema is the single enforcement point).
  • tests/test_max_tokens_lint.py: critic max_tokens=512 allowlist 580 → 565 (net −15 lines).

Risk / deploy

No live-path behavior change — pure dead-code removal. Not Saturday-SF-critical (the Saturday-critical prompt fix was #369, already merged); merge at leisure.

Test

pytest tests/1647 passed.

🤖 Generated with Claude Code

…se 1B follow-on)

The caution-regime-retirement migration shim was provably dead code on
the LLM path: _validate_regime is only ever called with
parsed.market_regime (macro_agent.py), which with_structured_output
already constrains to the 3-class RegimeLiteral via MacroEconomistRawOutput.
A raw 'caution' emission fails Pydantic at parse time -- it never reaches
_validate_regime, so _LEGACY_REGIME_COERCION.get(...) always returned None.

Now that the macro prompts dropped the 4-class vocabulary (ae-config
PR #369, merged 2026-05-29), the trigger is gone. Retiring the shim
makes the regime contract honest: the strict RegimeLiteral schema +
STRICT_VALIDATION is the single fail-loud enforcement point. We do NOT
re-introduce silent degrade-to-neutral coercion -- a model contract
violation should surface loudly per feedback_no_silent_fails, not be
masked as 'neutral'.

Changes:
- agents/macro_agent.py: delete _LEGACY_REGIME_COERCION dict + the
  coercion block in _validate_regime; docstring now states the input is
  schema-constrained and a non-conforming emission is governed upstream
  by STRICT_VALIDATION (raise) / lax-mode (neutral default).
- tests/test_regime_3class_invariant.py: drop the dead-branch coercion
  tests; add test_legacy_coercion_shim_stays_retired (asserts the dict
  stays gone so it can't be silently re-introduced); module docstring +
  no-guardrails test updated to the shim-retired contract.
- tests/test_state_schemas.py: comment fix -- schema is the single
  enforcement point, not the (now-gone) coercion.
- tests/test_max_tokens_lint.py: critic max_tokens=512 allowlist
  580 -> 565 (net -15 lines from the shim removal).

No live-path behavior change (dead-code removal). Suite: tests/ 1647 passed.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cipher813 cipher813 merged commit 8283b32 into main May 29, 2026
2 checks passed
@cipher813 cipher813 deleted the fix/retire-dead-regime-coercion-shim branch May 29, 2026 15:13
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