Skip to content

refactor(qa): conservative QARunner decomposition (E2)#58

Merged
CognitiveCodeAI merged 3 commits into
mainfrom
refactor/e2-extract-qarunner
Jun 8, 2026
Merged

refactor(qa): conservative QARunner decomposition (E2)#58
CognitiveCodeAI merged 3 commits into
mainfrom
refactor/e2-extract-qarunner

Conversation

@CognitiveCodeAI

Copy link
Copy Markdown
Owner

E2 — conservative, behavior-preserving QARunner decomposition

Part of the remediation (#25). Designed and adversarially reviewed by a workflow that deliberately scoped this small and safe — not a rewrite. Three commits, suite green after each; each extraction is a pure relocation/delegation, and because the audit found QARunner internals are barely covered by the default suite, each ships a new focused characterization test.

Extractions (runner.py: 2899 → 2677 lines)

  1. RerankerGate trio → app/qa/reranker_gate.py — already-standalone classes; re-exported from runner.py so from app.qa.runner import RerankerGate, RerankerGateContext (used by gate_metrics.py) and the bare RerankerGate.should_rerank() call keep working. + test_reranker_gate.py (full decision matrix).
  2. metadata helpers → app/qa/metadata_queries.py — three pure db-only functions; QARunner keeps delegating wrappers. + test_metadata_queries.py (incl. the None/empty short-circuits).
  3. _detect_structured_targets + patterns → app/qa/structured_targets.py — pure regex; QARunner aliases patterns + delegates. + test_structured_targets.py (detection + delegation parity). MAX_INJECTED_SEEDS stays on QARunner.

Behavior-preserving

Every change is a verbatim move + delegation; method names/signatures/call sites and all constants/thresholds are unchanged; public imports preserved via re-exports. Default suite stayed green after each commit (330 passed).

Deferred (by design — need characterization tests / more entangled)

_call_llm_reranker, fallback search, node-by-label/section queries, inject_structured_seeds, expansion audit, _hydrate_citations, the run()/propagation orchestration. Noted for a future pass.

Closes #21

Relocate the already-standalone RerankerGate / RerankerGateContext /
RerankerGateResult (no QARunner coupling) from runner.py to
app/qa/reranker_gate.py, re-exported from runner.py so existing imports
keep working (app/qa/gate_metrics.py and the bare RerankerGate call in run()).

Pure relocation, zero logic change. Adds tests/qa/test_reranker_gate.py
(should_rerank decision matrix + re-export identity) since this logic had
NO prior test coverage. Full default suite: 319 passed.

Refs #21
Move the three pure db-only helpers (_get_doc_total_pages,
_get_doc_collection_version, _get_nodes_metadata) from QARunner into
app/qa/metadata_queries.py as functions taking db; QARunner keeps thin
delegating wrappers (signatures/call sites unchanged).

Pure relocation. Adds tests/qa/test_metadata_queries.py (incl. the
None/empty short-circuits that avoid a DB hit). Full suite: 325 passed.

Refs #21
Move the pure regex _detect_structured_targets + its 4 patterns from
QARunner into app/qa/structured_targets.py; QARunner aliases the patterns
(back-compat) and delegates the method. MAX_INJECTED_SEEDS stays on
QARunner (used by inject_structured_seeds, not extracted).

Pure relocation. Adds tests/qa/test_structured_targets.py (figure/table/
appendix/section detection + delegation parity). Full suite: 330 passed.

Refs #21
@CognitiveCodeAI CognitiveCodeAI added this to the Phase 3 – Modernize milestone Jun 8, 2026
@CognitiveCodeAI CognitiveCodeAI added WS-E Workstream E: Modernize architecture refactor Structural refactor — no behavior change intended labels Jun 8, 2026
@CognitiveCodeAI CognitiveCodeAI merged commit d032c10 into main Jun 8, 2026
4 checks passed
@CognitiveCodeAI CognitiveCodeAI deleted the refactor/e2-extract-qarunner branch June 8, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Structural refactor — no behavior change intended WS-E Workstream E: Modernize architecture

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[E2] Decompose QARunner (2847-line god object) into focused components

1 participant