Tasks: Ingest CourtListener Opinions¶
Every requirement in spec.md —
FR-1..6,NFR-PERF-1,NFR-SEC-1,NFR-AUDIT-1,NFR-HITL-1,NFR-IDEMPOTENT-1,AC-1..5— must be referenced by at least one task. CI (scripts/spec_validator.py) enforces this.
T-001 — Add ExtractionResult Pydantic models¶
- Refs: FR-2
- Owner: @copilot
- Status:
[x] - Files:
backend/app/models/extraction.py(new)backend/tests/models/test_extraction.py(new)- Steps:
- Define
Citation,Entity,ExtractionResultPydantic v2 models withconfidence: float = Field(ge=0, le=1). - Re-export from
backend/app/models/__init__.py. - Verify:
cd backend && pytest tests/models/test_extraction.py -qpasses.mypy app/models --strictclean.
T-002 — Implement CourtListenerClient with httpx + tenacity¶
- Refs: FR-1, NFR-SEC-1, NFR-AUDIT-1
- Owner: @copilot
- Status:
[x] - Files:
backend/app/ingestion/__init__.py(new)backend/app/ingestion/courtlistener.py(new)backend/tests/ingestion/test_courtlistener.py(new).env.example(addCOURTLISTENER_API_TOKEN=)- Steps:
- Async client wrapping
https://www.courtlistener.com/api/rest/v4/opinions/withhttpx.AsyncClient, 30 s timeout,tenacityretry (max 3, exponential). - Read
COURTLISTENER_API_TOKENfrom settings; attach asAuthorization: Token …if present. - Log every fetch via
core.provenancewithsource="courtlistener",source_url. - Verify:
pytest tests/ingestion/test_courtlistener.py -qpasses (usesrespxmock).- Test asserts retry on 503 and bail-out on 4xx (other than 429).
T-003 — Implement IngestionScout agent + Neo4j commit path¶
- Refs: FR-2, FR-3, FR-6, NFR-AUDIT-1, NFR-HITL-1, NFR-IDEMPOTENT-1, AC-3, AC-5
- Owner: @copilot
- Status:
[x] - Files:
backend/app/db/__init__.py(new)backend/app/db/neo4j.py(new — async driver singleton)backend/app/db/queries.py(new —MERGE-based Cypher)backend/app/db/neo4j_migrations/001_case_constraints.cypher(new)backend/app/db/postgres_migrations/001_pending_review.sql(new)backend/app/ingestion/scout.py(new —IngestionScoutclass)backend/app/agents/registry.py(registerIngestionScout)backend/tests/ingestion/test_scout.py(new — unit + integration)- Steps:
extract(payload)runs Eyecite + Blackstone, returnsExtractionResult.run_and_commit(payload)branches onconfidence:>= 0.7→MERGECase+Citation+CITES/HAS_CITATIONedges;< 0.7→ insert intopending_review(Postgres) or append tobackend/var/pending_review/<date>.jsonlif Postgres is unreachable.- Every Cypher
MERGEsetssource,source_url,ingest_timestamp,agent_version,confidence. - Register agent in
backend/app/agents/registry.py. - Verify:
- Unit:
pytest tests/ingestion/test_scout.py::test_extract_high_confidence -qpasses. - Unit:
pytest tests/ingestion/test_scout.py::test_low_confidence_routes_to_pending -q(AC-5). - Integration (needs
docker compose up -d neo4j postgres):pytest -m integration tests/ingestion/test_scout.py::test_run_and_commit_creates_case_and_edge(AC-3). - Integration:
pytest -m integration tests/ingestion/test_scout.py::test_idempotent_recommit(NFR-IDEMPOTENT-1).
T-004 — CLI entry point + Makefile target¶
- Refs: FR-4, FR-5, NFR-PERF-1, AC-1, AC-2
- Owner: @copilot
- Status:
[x] - Files:
backend/scripts/ingest_sample.py(new)Makefile(addingesttarget)- Steps:
argparseCLI with--source courtlistener,--limit N(default 500),--dry-run.- Orchestrate fetch → extract → commit, print a run summary (
committed,pending,skipped,elapsed_s). make ingestinvokescd backend && python scripts/ingest_sample.py --limit 500 --source courtlistener.- Verify:
make ingest --dry-runprints summary against arespx-mocked client without network.- Manual:
make dev && make ingestpopulates Neo4j with ≥ 450 cases inside 10 minutes (AC-1, NFR-PERF-1). - Manual: re-run
make ingestand confirmcommitted=0,skipped=500(AC-2).
T-005 — Surface last_ingest_at on /api/health¶
- Refs: AC-4
- Owner: @copilot
- Status:
[x] - Files:
backend/app/api/health.pybackend/app/db/queries.py(addget_last_ingest_at())backend/tests/api/test_health.py(extend or create)- Steps:
- Add Cypher
MATCH (c:Case) RETURN max(c.ingest_timestamp) AS last_ingest_at. - Include in health response; default
nullwhen noCaseexists. - Verify:
- Unit: monkeypatch
get_last_ingest_atand assert the field appears (defaults tonull). - Integration: commit a fixture case,
GET /api/healthreturns the matching ISO-8601 timestamp (AC-4).
T-006 — Documentation refresh¶
- Refs: FR-6
- Owner: @copilot
- Status:
[x] - Files:
docs/data-model.md(new)docs/data-sources.md(new)docs/agent-roles.md(flipIngestionScoutrow from "planned/stub" to "live")- Steps:
docs/data-model.md: documentCase,Citation,CITES,HAS_CITATIONshapes from spec §7; include the Cypher constraints from the migration.docs/data-sources.md: one table row per source; add CourtListener with API endpoint, license, rate limits.- Update the
IngestionScoutrow indocs/agent-roles.mdto point atbackend/app/ingestion/scout.py. - Verify:
python3 scripts/spec_validator.py specs/001-ingest-courtlistener-opinionsexits 0.- Links resolve (manual).
Done-When (Definition of Done)¶
- All tasks
[x]. - All
AC-1..5covered by passing tests;AC-1andAC-2confirmed manually with the run summary captured in the PR description. make lint && make testgreen; backend coverage on changed files ≥ 75 %.- LegalBench: not run (no reasoning change; spec §11).
- Provenance manually verified by tailing logs during a live
make ingest. python3 scripts/spec_validator.pyexits 0.
Follow-ups Discovered¶
Mirrored into BACKLOG.md. Append, never delete.
- BL-20260429-01 — test-gap, med — Docker-backed integration tests for
IngestionScout.run_and_commit(AC-3, NFR-IDEMPOTENT-1). - BL-20260429-02 — refactor, med — Convert
_quarantine_postgresto async (asyncpg) so HITL items reach Postgres in production. - BL-20260429-03 — feature, low — Reintroduce Blackstone NER for
_extract_entitiesonce lazy-loadable. - BL-20260429-05 — feature, high — Spec 002 candidate: resolve
Citation.normalizedstrings to existingCasenodes; create(:Case)-[:CITES]->(:Case)edges. - BL-20260429-06 — test-gap, low — Smoke test for
scripts/ingest_sample.py --dry-runagainst arespxcassette. - BL-20260429-07 — doc-gap, low — Add
docs/api.mddocumenting the/healthJSON contract.