Spec: HITL Quarantine Enforcement — Test Coverage & Regression Guard¶
- ID: 023-hitl-quarantine-enforcement
- Status: shipped
- Owner: @copilot
- Created: 2026-06-02
- Roadmap Epic: BACKLOG BL-20260511-30
- Constitution Compliance: confirmed against docs/constitution.md §3, §5, §6
1. Problem & Motivation¶
Constitution §5 and specs/018 NFR-HITL-1 require that when any SourceAdapter.requires_human_approval is True, every RawDoc it produces MUST route through PendingReview (quarantine) regardless of confidence score. This prevents high-stakes or new-source documents from being committed directly to Neo4j without a human reviewer.
The production code is already wired correctly:
_node_dispatch
→ force_quarantine=adapter.requires_human_approval
→ _dispatch_target(..., force_quarantine=True)
→ scout.run_and_commit(..., force_quarantine=True)
→ _quarantine() always called when force_quarantine=True
However, the only existing test (test_sets_human_approval_when_adapter_requires_it) checks only that state["human_approval_required"] is True. It never asserts that scout.run_and_commit was actually called with force_quarantine=True, and its mock returns {"committed": True} — the wrong value for a quarantined doc. A regression (e.g. accidental removal of force_quarantine= kwarg in _dispatch_target) would pass silently.
This spec adds the safety-net tests that make the HITL enforcement verifiable and regression-proof, closing BL-20260511-30.
2. Goals¶
- G1: Add a unit test asserting
run_and_commitis called withforce_quarantine=Truewhen the adapter hasrequires_human_approval=True. - G2: Add a unit test asserting the dispatch summary records
committed: False(quarantined) whenforce_quarantine=Truereaches the realIngestionScout. - G3: Add an
@pytest.mark.integrationtest confirming that arequires_human_approval=Trueadapter produces aPendingReviewrow (not a Neo4jCasenode) after a full_node_dispatchcall against a live stack. - G4: Strengthen
test_sets_human_approval_when_adapter_requires_itto also assertrun_and_commit.call_argsincludesforce_quarantine=True.
3. Non-Goals¶
- NG1: Changes to production code in
topic_frontier.pyorscout.py(implementation is confirmed correct; only tests are added). - NG2: Adding new adapters or changing
requires_human_approvalvalues on existing adapters (all three current adapters haverequires_human_approval=False). - NG3: Frontend UI changes.
4. User Stories¶
- As a legal reviewer, I want confidence that documents from
requires_human_approval=Truesources always land in the HITL queue, so that no unreviewed ingestion bypasses the approval gate. - As a developer, I want CI tests that catch any accidental removal of
force_quarantine=Truein the dispatch chain, so that HITL regressions are surfaced immediately.
5. Functional Requirements¶
- FR-1: A unit test
test_force_quarantine_true_passed_to_run_and_commitcalls_node_dispatchwith an adapter whoserequires_human_approval=True, captures the mockscout.run_and_commitcall args, and assertscall_kwargs["force_quarantine"] is True. - FR-2: A unit test
test_dispatch_summary_shows_not_committed_when_force_quarantinecalls_dispatch_targetwithforce_quarantine=Trueand a mockedIngestionScoutwhoserun_and_commitreturns{"committed": False, "pending": True, "confidence": 0.5}, and asserts the resulting dispatch entry hascommitted=False. - FR-3: Strengthen the existing
test_sets_human_approval_when_adapter_requires_itby addingscout.run_and_commit.assert_called_once_with(ANY, force_quarantine=True). - FR-4: An
@pytest.mark.integrationtesttest_requires_human_approval_produces_pending_review_rowthat: - Creates an in-memory adapter stub with
requires_human_approval=Truereturning oneRawDoc. - Calls
_node_dispatchwith a realIngestionScoutusingCELERY_TASK_ALWAYS_EAGER=Trueand@pytest.mark.django_db(transaction=True). - Asserts a
PendingReviewrow exists in Postgres for the dispatched doc'ssource_url(viaPendingReview.objects.filter(source=...)). - Asserts the dispatch result entry has
committed=False.
6. Non-Functional Requirements¶
- NFR-PERF-1: All unit tests (FR-1 to FR-3) complete in < 1 s each (no network calls, Celery eager).
- NFR-AUDIT-1: No changes to
core.provenancelogging; existing provenance coverage is sufficient. - NFR-HITL-1: This spec exists to enforce §5 compliance — it must not introduce any code change that weakens the HITL gate.
- NFR-COV-1: Backend line coverage on
topic_frontier.pyandscout.pymust not decrease.
7. Data Model Impact¶
No new Neo4j nodes, Postgres tables, or vector collections. The integration test reads from the existing ingestionapp_pendingreview table.
Reference: docs/data-model.md — PendingReview model (law_ai.ingestionapp.models).
8. API Surface¶
No new or changed API routes.
9. Agent / Crew Impact¶
No new agents. Touches test files only:
- TopicFrontier (
backend/law_ai/agents_runtime/graphs/topic_frontier.py) — test-only; production code is unchanged. - IngestionScout (
backend/law_ai/ingestionapp/services/scout.py) — test-only; confirmsforce_quarantinepath is exercised.
10. Acceptance Criteria¶
- AC-1: Given an adapter with
requires_human_approval=True, when_node_dispatchis called, thenscout.run_and_commitis called withforce_quarantine=True(verified viaassert_called_once_with). - AC-2: Given
force_quarantine=True, when_dispatch_targetreturns a dispatch entry, thenentry["committed"] is False. - AC-3: (Integration) Given a live Postgres +
CELERY_TASK_ALWAYS_EAGER=Trueand an adapter withrequires_human_approval=True, when_node_dispatchexecutes, then aPendingReviewrow exists with the dispatched doc'ssource_urlandcommitted=Falsein the dispatch summary. - AC-4:
make test-backendexits 0 and backend coverage does not decrease. - AC-5:
make lintexits 0 (ruff + black).
11. LegalBench Impact¶
- No reasoning logic changed; LegalBench regression run not required.
- Expected delta: 0 pp on all tasks.
12. Risks & Open Questions¶
- R-1: The integration test (FR-4) requires
CELERY_TASK_ALWAYS_EAGER=Trueand Django ORM access in an async test context. Use@pytest.mark.django_db(transaction=True)and wrap the async dispatch call inasyncio.runorasgiref.sync.async_to_syncfrom a sync test body to avoidSynchronousOnlyOperation(mirrors fix from BL-20260510-01 /tests/ingestion/test_scout_integration.py).
No open questions — spec is self-contained and implementation is confirmed correct.
13. Out of Scope / Follow-ups¶
- BL-20260511-31 — Migrating
TopicFrontierto a properStateGraph(separate spec; does not affect HITL enforcement). - BL-20260510-01 — Full Celery/Django-ORM integration path for
PendingReview(broader than this spec; this spec only adds the HITL-path verification test).
Origin & Background¶
Claimed from: BL-20260511-30 (feature, high) — "Enforce requires_human_approval=True quarantine path in TopicFrontier._node_dispatch". Surfaced during specs/018-autonomous-framework PR review.