Tasks: Commit the first real LegalBench baseline¶
Each task references
FR-*/NFR-*/AC-*IDs from spec.md. CI'sspec_validator.pyenforces that every requirement is referenced by at least one task.
Conventions¶
- Status:
[ ]todo /[~]in-progress /[x]done. - Owner: GitHub handle or
@copilot/@agent:<role>. - Each task lists exact files to touch and how to verify.
- Order matters: T-001..T-006 land in one harness PR before any baseline is recorded, because the pinned options and metadata are part of the measurement.
T-001 — Pin the gate model once, in the Makefile¶
- Refs: FR-3, NFR-DOCKER-1, AC-7
- Owner: @agent:claude-code
- Status:
[ ] - Files:
Makefile,tests/test_legalbench_workflows.py(new) - Steps:
- Add
LEGALBENCH_MODEL ?= mistral:7b-instruct-q4_K_Mnext toLEGALBENCH_SUBSETS. - Pass
--model $(LEGALBENCH_MODEL)intest-legalbench,test-legalbench-gateandlegalbench-baseline. - Repo-level test:
make -nof each target contains--model mistral:7b-instruct-q4_K_M, andLEGALBENCH_MODEL=x make -n …contains--model x. - Verify: the ci.yml root-tests tier (
pytest tests/ -m "not backend and not frontend") passes on the PR;make -n legalbench-baselineshows the explicit model.
T-002 — Pin decoding options and make timeouts honest¶
- Refs: FR-3, FR-4, FR-8, AC-6
- Owner: @agent:claude-code
- Status:
[ ] - Files:
backend/law_ai/eval/legalbench.py,backend/law_ai/settings/base.py,.env.example,backend/tests/eval/test_legalbench_measurement.py - Steps:
- Settings
LEGALBENCH_ITEM_TIMEOUT_S(300),LEGALBENCH_NUM_CTX,LEGALBENCH_NUM_PREDICT, read viasettings_proxy; document them in.env.example. _call_ollama()sends{"temperature": 0.0, "seed": 0, "num_ctx": …, "num_predict": …}and catchesTimeoutError/socket.timeoutas well asURLError, raising the existingRuntimeErrorso the item is counted errored.- Keep
_call_ollama()as the only transport; add a test asserting the module imports nothing fromlaw_ai.core.llm(FR-4). - Stub HTTP server test: a read that sleeps past the timeout yields one errored item and no traceback.
- Verify:
docker compose run --rm backend pytest tests/eval -q;make typecheckclean (no new baseline entries).
T-003 — Report header and baseline schema v2¶
- Refs: FR-1, FR-2, FR-5, FR-8, NFR-PERF-1, AC-5
- Owner: @agent:claude-code
- Status:
[ ] - Files:
backend/law_ai/eval/legalbench.py,backend/law_ai/eval/report.py,backend/law_ai/eval/fetch.py,backend/tests/eval/test_baseline_v2.py(new) - Steps:
- Once per run, read
model_digest(Ollama/api/show),ollama_version(/api/version); computemanifest_sha256frombackend/var/legalbench/manifest.json; takeDATA_REVISION,PROMPT_REVISION,DEFAULT_MAX_ITEMS_PER_TASKfromfetch.py;git_shafromGITHUB_SHAorgit rev-parsewhen available;runnerfromGITHUB_ACTIONS+platform. - Report rows gain per-task
n/correct(fromitem.metadata.task) and per-subset wall-clock seconds; report gainsitem_outcomesanditem_outcomes_sha256(sorted JSON, indices + 0/1 only). update_baseline()writesschema_version: 2with all FR-5 fields; refuses stubs (existing), any--limit, and anyerrored > 0, each with a distinct message.- Tests: v2 file round-trips; each refusal writes nothing and exits 1;
item_outcomescontains no strings other than indices. - Verify:
docker compose run --rm backend pytest tests/eval/test_baseline_v2.py -q.
T-004 — Comparability, --require-baseline, exit code 3¶
- Refs: FR-6, FR-7, AC-3, AC-4
- Owner: @agent:claude-code
- Status:
[ ] - Files:
backend/law_ai/eval/legalbench.py,backend/tests/eval/test_legalbench_cli.py - Steps:
- Extend
baseline_comparability()with the FR-6 fields for v2 baselines; keep the v1 model+scorer check. - In
_apply_gates(), an incomparable baseline under--check-regressionreturns exit 3 (not a warning + 0); add--require-baseline(missing file → exit 3). - Parametrised test, one case per FR-6 field → exit 3 naming the field; 1.01 pp drop → 1; exactly 1.00 pp → 0; v1 baseline + changed digest → still comparable (v1 does not record it).
- Update the exit-code table in the CLI
--helptext. - Verify:
docker compose run --rm backend pytest tests/eval/test_legalbench_cli.py -q.
T-005 — Provenance fields and the baseline event¶
- Refs: FR-12, NFR-AUDIT-1, AC-10
- Owner: @agent:claude-code
- Status:
[ ] - Files:
backend/law_ai/eval/legalbench.py,backend/tests/eval/test_legalbench_measurement.py - Steps:
_emit_item_event()addsprompt_sha256,response_sha256(raw response, before normalisation),model_digest,data_revision;agent_version→law_ai.eval.legalbench.v2.update_baseline()emits onelegalbench.baseline_recordedevent viaaudit_jsonl.recordwith the file sha256 and header.- Correct the module docstring: per-item events go to the audit JSONL/
AuditEvent, not OpenTelemetry spans. - Test with a captured
recordthat every item event has the fields and exactly one baseline event is written. - Verify:
docker compose run --rm backend pytest tests/eval -q.
T-006 — Hosted baseline workflow and nightly decoupling¶
- Refs: FR-9, NFR-COST-1, NFR-PERF-1, NFR-DET-1, NFR-SEC-1, NFR-HITL-1, AC-8, AC-9
- Owner: @agent:claude-code
- Status:
[ ] - Files:
.github/workflows/legalbench-baseline.yml(new),.github/workflows/nightly-tests.yml,tests/test_legalbench_workflows.py - Steps:
- New workflow:
on: workflow_dispatchonly;permissions: contents: read;runs-on: ubuntu-latest;timeout-minutes: 330; steps: checkout, the nightly disk-cleanup step, build backend image,docker compose up -d ollama postgres redis --wait, pullLEGALBENCH_MODEL,make legalbench-cache, run A and run B (--update-baselinewith the baseline path redirected per run,--reportper run), compareitem_outcomes_sha256, uploadbaseline.json+ reports +history.jsonl(retention-days: 90), write a step summary (accuracies, n/scored/errored, wall-clock, header). - No
secrets.reference, nogit push, nogh pr, no merge step. - Nightly: the four LegalBench steps use
if: ${{ !inputs.dry_run && !cancelled() }}so a failed coverage step no longer skips them; the pull step readsLEGALBENCH_MODEL. Schedule change only per OQ-5's answer. - Repo-level tests parse both YAML files (stdlib text checks, no PyYAML on host) for AC-8 and AC-9.
- Verify: the ci.yml root-tests tier passes on the PR;
make nightly-dry-run(act) if available;make lint-specs.
T-007 — Record and commit the baseline (human-gated)¶
- Refs: FR-1, FR-2, FR-10, FR-11, NFR-DET-1, NFR-HITL-1, AC-1, AC-2, AC-11
- Owner: @bamr87
- Status:
[ ] - Files:
backend/var/legalbench/baseline.json(new),docs/legalbench.md,backend/var/legalbench/LICENSES.md - Steps:
- After T-001..T-006 merge:
gh workflow run legalbench-baseline.yml --ref main; wait; confirm AC-1 in the step summary. - Download the artifact; copy
baseline.jsonintobackend/var/legalbench/. - Fill the
docs/legalbench.mdbaseline table (scores, n, run id, runner, baseline commit SHA — the SHA is filled in a follow-up commit on the same PR once known) and remove both_TBD_s; add the FR-11 citation, licences, pinned revisions and each task README's source line; add the §13 note on theprecedent_retrievalrow; document exit code 3 and the re-baseline triggers (FR-10). - Open the PR (draft if opened by an agent), label
no-visual-change; Amr reviews and merges. - Verify:
make test-legalbench-gateon the hosted runner (dispatch nightly or the baseline workflow in gate mode) exits 0 with 0.00 pp deltas (AC-2).
T-008 — Make the gate require the baseline; prove nightly green; backlog bookkeeping¶
- Refs: FR-7, FR-9, AC-2
- Owner: @agent:claude-code
- Status:
[ ] - Files:
Makefile,docs/legalbench.md,BACKLOG.md - Steps:
- Add
--require-baselinetotest-legalbench-gate. gh workflow run nightly-tests.yml; record the first green scored run id and date indocs/legalbench.md§ "CI status of the scored gate".- Move BL-20260906-28, BL-20260906-34, BL-20260811-10 and BL-20260810-04 to
## Donewith evidence (baseline commit SHA, run ids); add a note to BL-20260511-06 that its precondition is now met. - Verify:
make lint-specs; nightly step "Run LegalBench eval (regression gate)" green.
Done-When (Definition of Done)¶
- All tasks
[x]. - All
AC-*fromspec.mdcovered by passing tests or the recorded hosted run. make lint && make typecheck && make testgreen.- LegalBench: first baseline recorded and committed (this spec's whole point); later PRs report deltas against it.
- Provenance logging verified: one sample
legalbench.itemand thelegalbench.baseline_recordedevent inspected in the audit JSONL. ## Follow-ups Discoveredsection below populated.
Follow-ups Discovered¶
Append-only. Mirror each item into BACKLOG.md with a
BL-YYYYMMDD-NNid. CI (scripts/spec_validator.py) checks this section exists. CI (scripts/backlog_lint.py) checks the BACKLOG mirror.
- BL-20261018-01 — feature, med — Extend the gated LegalBench set beyond
core_reasoning/precedent_retrievalto the already-fetchablecontract_nli,definitions(CC BY-SA 4.0) andcausationsubsets, each with its own baseline row, once spec 056's hosted run proves the CPU budget. - BL-20261018-02 — feature, low — A non-gating reference lane that scores the same items on
claude-sonnet-5-5throughlaw_ai.core.llmwith a pinned single-tierLLM_PROVIDER_CHAIN; needs an ADR amending constitution §1 ("LegalBench does not route through the chain"), theANTHROPIC_API_KEYsecret, and a per-run cost cap (spec 056 OQ-3). - BL-20261018-03 — test-gap, high — Four backend tests fail in the nightly "Run test coverage" step (run 38212032910:
test_tutor_reports_no_trace_when_telemetry_is_disabled, twotest_run_autonomy_integrationcases,test_densify_backfill_commit_writes_the_missing_cites_edge), and the digest step logsrelation "audit_auditevent" does not exist, so the 2026-10-05 and 2026-10-17 nightly runs failed before reaching LegalBench (the LegalBench steps were skipped). - BL-20261018-04 — refactor, low — Report item counts and a binomial confidence interval next to every LegalBench pp delta, and decide by ADR whether the constitution §3 1 pp rule should become item-count-aware (on ~100
precedent_retrievalitems, 1 pp is one item) (spec 056 OQ-2). - BL-20261018-05 — infra, low — Protect
backend/var/legalbench/baseline.json: a CODEOWNERS entry for @bamr87 and alegalbench-baselinelabel so a baseline change cannot ride along unnoticed in an unrelated PR. - BL-20261018-06 — feature, low — Per-item flip report for LegalBench (
regressed/recovereditem indices between a run'sitem_outcomesand the baseline's), mirroring the LSATregression_report(), surfaced in the nightly step summary.