refactor(macro-regime): retire dead _LEGACY_REGIME_COERCION shim (Phase 1B follow-on)#253
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Retires the now-dead
_LEGACY_REGIME_COERCIONmigration 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_regimeis only ever called withparsed.market_regime(macro_agent.py), andwith_structured_output(MacroEconomistRawOutput, include_raw=True)already constrains that to the 3-classRegimeLiteral({bull, neutral, bear}, lib v0.42.0). A rawcautionemission fails Pydantic at parse time — it never reaches_validate_regime, so_LEGACY_REGIME_COERCION.get(...)always returnedNoneon 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 strictRegimeLiteralschema +STRICT_VALIDATION, not be masked asneutral. 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: criticmax_tokens=512allowlist580 → 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