refactor(conversation_loop): extract content normalization slice CL-R4-1 into agent/response_normalization.py - #84473
Conversation
Signed-off-by: Axl Ibiza, MBA <andrexibiza@gmail.com>
Signed-off-by: Axl Ibiza, MBA <andrexibiza@gmail.com>
Contributor email mapping required by check-attribution CI for the god-file kill campaign PRs (Axl Ibiza, MBA <andrexibiza@gmail.com>). Signed-off-by: Axl Ibiza, MBA <andrexibiza@gmail.com>
refactor(conversation_loop): extract content normalization slice CL-R4-1 into agent/response_normalization.pyClean, behavior-preserving extraction with unusually thorough seam tests. A few observations:
|
Summary
Blind extraction of slice CL-R4-1 from
agent/conversation_loop.py(7,757 lines at pinee4bb75b532e932a1055d9a710802a7435163b6a) into a new module, per the repo-wide god-file sharding policy.normalize_assistant_contentinagent/response_normalization.pyaf3d33d2a9e213f9f41b1ebec05785359a5455e523ae38578f0b4c0cb3ef6b68assistant_messageIN PLACE (same object reaches the lifecycle hook — no copy/replacement); preserves exactly the dict precedence (raw.get("text","") or raw.get("content","") or json.dumps(raw)), list part handling (strings appended directly,type=="text"dicts appendpart.get("text",""), other dicts containing text appendstr(part["text"]), others ignored,"\n"join), scalarstr(raw), exception/mutation timing, and no side effects. Call site at the identical response-processing location (afternormalize_response, beforepost_api_request); thepost_api_requesthook band (6103–6143) is NOT absorbed. No false re-export;run_conversationidentity, monkeypatch surfaces, and source scanners preserved;jsonbinding owned by the new module; startup-latency contract held (one stdlib import + function def).tests/agent/test_response_normalization_seam.py— runtime behavioral probes (normalization cases, in-place mutation/object identity, lifecycle-hook ordering via runtime spy,.strip()safety, import identity, monkeypatch transparency)agent/conversation_loop.py22 changed (inline band removed + call + deferred import); new module 21 lines; seam test 115 lines.Method
5×2×3 double-blind decomposition (per the All Gods Must Die mandate): 5 blind region analysts → 5 blind adversarial witnesses → 5 consensus adjudicators → blind implementer → 2 blind re-reviewers. Round 1: BOTH reviewers REQUEST CHANGES (committed seam test violated the test-integrity gate —
inspect.getsource/ast.parse/Path.read_text/subprocess, the repo's banned source-reading-test antipattern). Fix lane replaced them with runtime behavioral probes (commit1a2e6330a8e, test file only). Round 2: both re-reviewers APPROVED:C:/tmp/tg-Feature Package/conversation-loop/review/CLR41-review-1-r2.md(17,942 B) — all gates PASSC:/tmp/tg-Feature Package/conversation-loop/review/CLR41-review-2-r2.md(15,232 B) — APPROVED, all gatesSuite evidence: pristine-pin vs post-extraction failure sets identical (canonical subset 272 passed both sides; seam 6/6). No new failures.
Coordination table
ee4bb75b532e932a1055d9a710802a7435163b6a(origin/main)agent/response_normalization.pyaf3d33d2a9e213f9f41b1ebec05785359a5455e523ae38578f0b4c0cb3ef6b68Dedup statement
No prior extraction of this window exists. No duplicate work.
Credit
614f7b27a36+1a2e6330a8e)This slice is governed by the conversation_loop (posted on #78641). Former whole: 7,757 lines. Fixer roster: #83437.
Part of #78641
Part of #78647