in reviewhumanPR #349Identity
Locard: add coverage-gated vendor integration with suspension, tamper and fail-closed tests
Locard is a risk market for AI agents: it scores an agent from its tool manifest and trace history, prices and binds cover, and issues a signed policy token.
Author
@AlfredYWong
github profile →- Status
- In review
- Opened on
- Nov 11
- Branch
- integration/locard-coverage-gate
Description
The pitch.
## Summary
**Locard** is a risk market for AI agents: it scores an agent from its tool manifest and trace history, prices and binds cover, and issues a signed policy token. A counterparty checks the token with Locard before admitting the agent, and Locard's live monitoring suspends the policy as soon as the agent breaks its declared limits.
This PR adds `integrations/locard/`. It runs the whole Locard workflow (underwrite, quote, bind, verify at the door, monitor and suspend) inside Town's existing **Track quote task**, as two command participants: an insured buyer and a coverage-gated vendor. Town's own scripted buyer serves as the uninsured "other agent". It also adds evidence bundles from a run against the real Locard service and `tests/test_locard_integration.py`. Nothing under `src/` changes.
## Integration
- **Locard runs separately:** [zaccytoymas/locard-mvp](https://github.com/zaccytoymas/locard-mvp) (`locard/`, FastAPI), at `http://127.0.0.1:8700`. The PR holds only the Town side.
- **`buyer.py` (buyer role):** before messaging the vendor it calls Locard's submissions, quote and accept endpoints with the procurement agent's manifest and 150 synthetic trace events (in `fixtures/`). It then sends Town's `quote_request` with `coverage: {provider: "locard", agent_id, policy_token}` and judges the reply like Town's stock buyer. Its `--mode violate` reports an over-cap purchase to Locard's monitoring first, and `--mode tamper` alters the token's signature.
- **`vendor.py` (seller role):** calls Locard's `/v1/verify` (token, agent id, order value) before any work.
- Covered: `quote_response`, ack `processed` with `applied: true`.
- Not covered, or Locard unreachable: `quote_refused`, ack `rejected` with `applied: false` and Locard's reasons.
It fails closed. The verdict is in the ack note, so it lands in Town's evidence. Redelivered work is answered from Town's `Journal`, without a second verification.
- **Shared infrastructure exercised:** Town's coordinator (mailbox delivery, leases, fenced acks), its fault injection (`quote-duplicate-delivery`, `quote-lost-ack`), its stage evaluator, and `nandatown verify`.
## Reproduce
- **Town:** commit `6f9a7c0` (`nandatown 0.2.0`, Track evaluator `0.5.0`).
- **Locard:** `zaccytoymas/locard-mvp@96b6c51`.
- **Tested on:** Python 3.14 (full suite: 1871 passed) and 3.11 (the Locard tests).
```bash
# Town
python3 -m venv .venv && source .venv/bin/activate && python -m pip install -e '.[dev]'
# Locard, in another terminal
git clone https://github.com/zaccytoymas/locard-mvp && cd locard-mvp && git checkout 96b6c51
cd locard && python3 -m venv .venv && .venv/bin/pip install -r requirements.txt
LOCARD_DB=/tmp/locard-town.db .venv/bin/uvicorn app.main:app --port 8700
# The compatibility check (from Town's root): every case, expected vs observed, nandatown verify on each bundle
python integrations/locard/run_checks.py --locard-version 96b6c51
# Without the Locard service (stand-in Locard with the same API shapes)
python -m pytest -q tests/test_locard_integration.py
# The recorded evidence, offline
nandatown verify integrations/locard/evidence/insured-buyer
```
## Results and limitations
Run against the real Locard service. Full table with run ids: `integrations/locard/evidence/RESULTS.md`. All 7 cases matched, and all bundles verify.
| Case | Town profile | Expected | Observed |
|---|---|---|---|
| Insured agent asks for a quote | `quote-clean` | Quote served | ✅ verdict passed, all six stages; Locard verified once |
| Town's scripted buyer, no policy | `quote-clean` | Refused `coverage_required`, Locard not called | ✅ |
| Over-cap purchase reported to Locard monitoring, then a quote request | `quote-clean` | Refused `policy_suspended:over_spend_cap` | ✅ |
| Token signature altered | `quote-clean` | Refused `invalid_signature` | ✅ |
| Locard unreachable from the vendor | `quote-clean` | Refused `locard_unreachable` (fail closed) | ✅ |
| Same request delivered twice | `quote-
…Try it
Open PR on GitHubView diffCheckout locally
git fetch origin pull/349/head:pr-349
git checkout pr-349