Closes gap #5 (maalbilde §5/§7): generate_via_llm's outer max_attempts loop
built the prompt ONCE and re-sent it identically — a BLIND retry. The validator's
per-attempt Rejection.reason was captured in `last` but never reached the next
prompt, so the proposer re-answered the same question with no knowledge of WHY
the prior candidate failed. Step 5 routes that reason into the next attempt.
- generate.py: _build_messages() gains prior_rejection; when set it appends a
revision block carrying ONLY the falsification reason verbatim (never the
rejected proposal JSON). None -> the byte-identical base prompt, so attempt 1
is unchanged. generate_via_llm() rebuilds messages inside the outer loop with
prior_rejection=`last` (None on attempt 1); _fetch_parsed() takes messages as
an explicit parameter. `last` is overwritten each round -> only the most-recent
falsification ("forrige"), never an accumulated history. Bound unchanged:
max_attempts + meter.tick_round (no new loop; §6 — "improve until good enough"
without a ceiling stays impossible).
- Scope honesty: the only per-attempt falsifier here is the validator. The
checker is a run-level, one-shot signal (run.py, before generation); seeding
generation with the checker critique is separately scoped and NOT done here.
The boundary is written into the generate_via_llm docstring + README + CLAUDE.
Load-bearing (maalbilde §7): tests/test_step5_refine_loadbearing.py is a PAIR —
the positive test keys the proposer's flip on the validator REASON PAYLOAD (the
rejected claim value, derived from validate_proposal(bad).reason so test and SUT
share one source of truth), and asserts the reason reached attempt 2's prompt
VERBATIM (the green-but-dead guard). It goes RED on detach (build messages once):
the flip token never arrives, so the outcome never flips AND the verbatim
assertion fails — proven double-red. The bounded control proves a never-fixed
proposer exhausts exactly max_attempts and returns a Rejection.
Adversarial Plan agent hardened the design pre-implementation (flip on payload
not wrapper/call-count; derive flip-key from the validator reason; drive through
generate_via_llm directly; docstring honesty). Suite 136->138 passed, 4 skipped;
mypy + ruff check clean. New test ruff-formatted; pre-existing ruff-format drift
(budget/verdicts/test_contracts) left untouched for a surgical diff.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MHR8iKxJRxDiDfNw8HZmWE