Spec: Truthful Agent Harness + Resilient Dev Substrate¶
- ID: 026-truthful-harness-dev-substrate
- Status: shipped
- Owner: @bamr87
- Created: 2026-08-10
- Roadmap Epic: continuous-evolution hardening (repo-wide audit 2026-08-10)
- Constitution Compliance: confirmed against docs/constitution.md — §4 (provenance), §11 (continuous evolution), §12 (autonomy invariants), §13 (jurisprudential honesty)
1. Problem & Motivation¶
A seven-subsystem audit (2026-08-10) found the flagship analysis path violating the constitution's honesty rules: the default POST /api/analysis returned a hardcoded negligence IRAC at confidence 0.82 plus a fabricated precedent ("Smith v. Jones", 0.88, "Found 12 highly relevant precedents"), averaged to 0.85 — clearing the HITL threshold so fabricated legal content shipped without human review, logged to the audit trail under real model names. Related integrity holes: log_agent_call used Python's salted hash() (irreproducible audit hashes), logged_node hashed the class instance instead of the workflow state, the LangGraph refusal path reported "citations verified", unverified citations were stripped before reviewers saw them, and the autonomy loop silently no-opped in CI (AUTONOMY_ENABLED never set; proposals written to backend/backend/… where nothing read them). The dev substrate raced its databases at boot, shipped a ~1 GB frontend build context, recommended a constitutionally forbidden AI extension, and made server-side frontend breakpoints unbindable.
2. Goals¶
- G1: The analysis surface never fabricates legal content; unimplemented paths say so (degraded, confidence 0.0) and always require human review (BL-20260803-02 partially addressed: retrieval coverage envelope; claims that item's retrieval-tool half).
- G2: Audit-trail hashes are reproducible and hash the actual inputs (§4).
- G3: The autonomy/evolution loop actually runs in CI and its artifacts land where reviewers and CI look (§12 I4/I5).
- G4: The Docker dev/test substrate is race-free, reproducible, and bounded; VS Code run/debug works end-to-end for all three services.
- G5: Dev-time MCP servers give sanctioned agents direct introspection of the local stack without touching the product runtime (§1).
3. Non-Goals¶
- NG1: Real GraphRAG retrieval implementation (stays BL-20260502-04).
- NG2: New data-source adapters (each needs its own
/specifycycle per §12 I2); this spec only documents candidates indocs/data-sources.md. - NG3: Frontend rendering of the new coverage envelope / verified flags (follow-up).
- NG4: Devcontainer + host-toolchain-free editor IntelliSense (follow-up).
4. User Stories¶
- As a lawyer reviewing Analysis Studio output, I want unimplemented paths to say so explicitly, so that I never mistake placeholder text for legal analysis.
- As a reviewer, I want every citation shown with its verification status, so that hallucination-flagged citations are inspectable instead of silently dropped.
- As a maintainer, I want audit hashes reproducible across restarts, so that the provenance trail can actually prove what an agent saw.
- As a developer, I want
make dev/make debugto come up deterministically with attachable debuggers, so that I can fix issues instead of fighting the stack.
5. Functional Requirements¶
- FR-1:
PrecedentHunter.runreturns zero precedents,confidence=0.0,degraded=true, and a summary stating no retrieval ran; the provenance event uses model labeldegraded/not-implemented, never a real model id. - FR-2:
LegalAnalyst._run_legacyreturns a degraded refusal (no fabricated IRAC,confidence=0.0,degraded=true,requires_review=true) logged asdegraded/not-implemented. - FR-3:
/api/analysisexcludes degraded agents from the confidence mean and forcesrequires_human_review=truewhen any agent is degraded or flags review; the HITL flag is a structured field, not prose string-matching. - FR-4:
LegalWorkflowemits a retrieval coverage envelope (retrieval_stats: queries, result_count, jurisdiction_requested, coverage_note) distinguishing "no results in our corpus" from "no such law" (§13), surfaced throughIRACOutput.retrieval. - FR-5:
_cite_checksetshuman_approval_required=truewhen there are zero citations; the LangGraph conclusion reports refusal / N-unverified / N-verified states truthfully and keeps unverified citations insourceswith averifiedflag. - FR-6:
_analyze/_retrievesurvive malformed LLM output shapes (JSON arrays, non-dict citations, non-numeric confidence) by degrading to the refusal default. - FR-7:
log_agent_calluses the deterministic_stable_hash;logged_nodehashes the state argument (neverself); WS delivery bookkeeping is logged under a distinct event type (ws_event_sent), notagent_call. - FR-8:
TestSynthesizer._PROPOSED_DIRis anchored to the backend package root; nightly CI setsAUTONOMY_ENABLED=Trueon the synthesis step. - FR-9: docker-compose gates app services on database health
(
condition: service_healthy), adds healthchecks for backend/frontend/ollama/ phoenix, pinsollamaandphoeniximage tags, bounds neo4j/ollama memory, plumbs the root.envviaenv_file(optional), and gives the workerOLLAMA_BASE_URL. - FR-10:
docker-compose.debug.ymlpreserves worker semantics (--beat -Q autonomy,celery) and propagates the Node inspector viaNODE_OPTIONSso Next.js server-side breakpoints bind (port 9230). - FR-11:
.dockerignorefiles exclude hostnode_modules/caches from both build contexts; the backend Dockerfile uses a BuildKit pip cache mount. - FR-12: VS Code config drops the forbidden
continue.continuerecommendation (moved tounwantedRecommendations), removes the invalid$pytestmatcher and deprecated ruff/black arg overrides, and adds tasks for single-test runs, evolve audit, autonomy dry-run, LSAT export, and agent demos;launch.jsonmatches the debug ports. - FR-13: Project
.mcp.jsonprovides dev-time Postgres (read-only) and Neo4j Cypher MCP servers against the compose stack, documented in AGENTS.md as dev-tooling only.
6. Non-Functional Requirements¶
- NFR-AUDIT-1: All new/changed logging goes through
law_ai.core.provenance; no fabricated output may be attributed to a real model name. - NFR-SEC-1: No secrets added;
.mcp.jsoncontains only local dev-default credentials;.envstays uncommitted (env_filemarked optional). - NFR-DX-1:
make test-backend(with DBs up),make lint,make typecheckall pass in containers after the change.
7. Data Model Impact¶
None. New Pydantic fields (degraded, requires_review, retrieval, retrieval_stats, verified on source dicts) are additive API-response fields; no Neo4j/Postgres schema change.
8. API Surface¶
POST /api/analysis response is additive-extended: irac.degraded, irac.requires_review, irac.retrieval (coverage envelope), precedents.degraded, and verified/resolved_case_id keys on irac.sources entries. No route changes; no breaking removals.
9. Agent / Crew Impact¶
PrecedentHunter, LegalAnalyst (all three paths), LegalWorkflow (retrieve/analyze/cite_check nodes), TestSynthesizer (output location). No new agents. No prompt-template changes.
10. Acceptance Criteria¶
- AC-1: Given the default
/api/analysispath, the response hasconfidence == 0.0,requires_human_review == true, empty precedents withdegraded == true, and no fabricated sources. - AC-2: Given a LangGraph run with empty retrieval, the output has
human_approval_required == true,retrieval_stats.result_count == 0, and a coverage note stating absence-in-corpus ≠ absence-of-law. - AC-3: Given two
logged_nodeinvocations on different instances with the same state, both audit events carry the identicalinput_hash == _stable_hash(state);log_agent_callevents likewise. - AC-4: Given an LLM response that is a JSON array or has junk citation entries or non-numeric confidence, the workflow completes with the refusal default instead of raising.
- AC-5:
docker compose configis valid;docker compose up -d postgres redis neo4j --waitreaches healthy; the debug override keeps--beat -Q autonomy,celeryon the worker. - AC-6:
TestSynthesizer._PROPOSED_DIRis absolute, ends intests/autonomy/proposed, and contains nobackend/backendsegment.
11. LegalBench Impact¶
- Tasks affected: none (no reasoning-prompt changes; honesty labels only).
- Expected delta: 0 pp. The eval harness itself is unchanged.
12. Risks & Open Questions¶
- R-1: Downstream consumers relying on the fabricated default-path output will now see a degraded refusal — this is intended (the old behavior was a constitution violation), and the frontend already renders confidence/HITL flags.
- R-2: Pinned
ollama/phoenixtags can go stale; bumping is now a deliberate, reviewable act instead of a silent drift.
13. Out of Scope / Follow-ups¶
See tasks.md → ## Follow-ups Discovered (mirrored into BACKLOG.md as BL-20260810-01 … BL-20260810-12).