Witness

Relate by Neo4j hackathon · Case two-hub

Witness cross-examines the graph until only the evidence remains.

Your agent answered from a graph of 57,645 relationships. Witness hands back 22 that still give the same answer, and proves each one is needed: delete any one of them from the witness and the answer changes. One .rl file, re-run with plain Relate.

Run ituv run witness demo

Needs uv. The repository opens at submission; until then the clone does not resolve and the recorded run below is the output.

Source on GitHub opens at submission

Exhibit list · two-hub
The answer PBC QRO TLC UPN Unchanged
The witness: 22 relationships among 12 nodes (10 airports, 2 countries), the 13 routes carry numbered exhibit tags, the 9 country links show as country codes UPNMX QROMX PBCMX TLCMX LAXUS TIJMX DFWUS LASUS ACAMX MEX 1 3 5 7 9 10 12 13 15 17 18 20 21

EXPLAIN plan drops :ON_CONTINENT · −3,504

22 of 22 change the answer
Relationships22of 57,645
Trial371of 371
371 trials · tall 86 kept the answer, applied · short 285 changed it, rolled back. Counters from witnesses/two-hub.trace.json; the map is the real air-routes frame (1,565 airport pairs), faded for the eye.
57,645→22relationships in the air-routes graph, then in its witness (3,748 → 12 nodes)
22of22deleting any one from the witness changes the answer, checked on relate-db and on the Relate CLI
68→22relationships the answer rows bind, then the witness: deleted from the full graph, only 20 of the 68 change the answer (11 of them in the witness); deleted from the witness, all 22 do
517·100%tests against real Relate · line and branch coverage

Read from witnesses/two-hub.manifest.json, evidence/pull-each-tag.json, evidence/neo4j-compare-2026-11-24.md, evidence/pytest-2026-11-27.txt. Relate 1.0.1 · Python 3.12.13.

Exhibit A · pull a tag

Pull any tag. The answer moves.

The witness: 22 relationships among 12 nodes (10 airports, 2 countries), the 13 routes carry numbered exhibit tags, the 9 country links show as country codes UPNMX QROMX PBCMX TLCMX LAXUS TIJMX DFWUS LASUS ACAMX MEX 1 3 5 7 9 10 12 13 15 17 18 20 21
Answer with exhibit none pulledUnchanged
airporthub_countries
PBC[MX, US]
QRO[MX, US]
TLC[MX, US]
UPN[MX, US]

Pick a tag or a register line. Each answer: one relationship deleted in a Relate transaction, query re-run, rolled back.

The agent's question: Which airports of MX have no direct flight to MEX, yet would still reach it in two flights if any one hub closed? The answer is four airports. The 13 red tags are the witness's routes, the 9 country codes its country links; all 22 are in the register. Pull any one to see what Relate returned without it.

The registerpull it and
22 of 22 change the answer
22 of 22 change the answer

Recorded 2026-11-26 19:35:48 UTC by scripts/pull_each_tag.py on a copy of witnesses/two-hub.rl → evidence/pull-each-tag.json. witness check runs the same probes on relate-db and on the Relate CLI.

The run · as your terminal prints it

One command, and the exhibit is filed.

exhibit/two-hub.html
The exhibit page Witness writes beside the witness file: the question, the answer, and the register of 22 tagged relationships
The page witness why writes beside every witness. Open it.
uv run witness demo
Witness 0.1.0 · Python 3.12.13 · relate-db 1.0.1  relate CLI v1.0.1: answers are cross-checked on the CLI too  source data/air-routes.rl · 3,748 nodes · 57,645 relationships · air-routes (krlawrence/graph, Apache-2.0) QUESTION  Which airports of MX have no direct flight to MEX, yet would still reach it in two flights if any one hub closed?  queries/two-hub.cypher · aggregation, NOT EXISTS, OPTIONAL MATCH · params {"country": "MX", "dest": "MEX"} ANSWER  4 rows on the full graph · guard: read-only: Relate query_type 'r' · order check: same answer from a store built in reverse order  airport  hub_countries  PBC      [MX, US]  QRO      [MX, US]  TLC      [MX, US]  UPN      [MX, US] WITNESS  22 relationships · 12 nodes, out of 57,645 · 3,748  reduced in 0.998 s · 371 trials · 0 inconclusive · seed 0 (5.78 s end to end: copy, guard, order check, reduce, check)  68 relationships match the answer rows; 22 of them suffice EXHIBITS  (register order; every one is needed)   1  (ACA)-[:HAS_ROUTE]->(MEX)   2  (ACA)-[:IN_COUNTRY]->(MX)   3  (DFW)-[:HAS_ROUTE]->(MEX)   4  (DFW)-[:IN_COUNTRY]->(US)   5  (LAS)-[:HAS_ROUTE]->(MEX)   6  (LAS)-[:IN_COUNTRY]->(US)   7  (LAX)-[:HAS_ROUTE]->(MEX)   8  (LAX)-[:IN_COUNTRY]->(US)   9  (PBC)-[:HAS_ROUTE]->(DFW)  10  (PBC)-[:HAS_ROUTE]->(TIJ)  11  (PBC)-[:IN_COUNTRY]->(MX)  12  (QRO)-[:HAS_ROUTE]->(DFW)  13  (QRO)-[:HAS_ROUTE]->(TIJ)  14  (QRO)-[:IN_COUNTRY]->(MX)  15  (TIJ)-[:HAS_ROUTE]->(MEX)  16  (TIJ)-[:IN_COUNTRY]->(MX)  17  (TLC)-[:HAS_ROUTE]->(ACA)  18  (TLC)-[:HAS_ROUTE]->(LAS)  19  (TLC)-[:IN_COUNTRY]->(MX)  20  (UPN)-[:HAS_ROUTE]->(LAX)  21  (UPN)-[:HAS_ROUTE]->(TIJ)  22  (UPN)-[:IN_COUNTRY]->(MX) CHECK  22 of 22 change the answer (22 of 22 relationships, 0 of 0 isolated nodes)  relate CLI: sufficiency + 22 of 22 necessity probes cross-checked ABSENT  checked on the full graph, not part of the witness  airport  direct_flights  reaching_hubs  PBC      0               7  QRO      0               9  TLC      0               10  UPN      0               2 PROVE ONE  delete exhibit 9 (PBC)-[:HAS_ROUTE]->(DFW) from a copy of W, re-run  CHANGED: 4 rows → 3 rows (PBC drops out) FILES  out/two-hub.rl (+ .cypher .manifest.json .html .trace.json)LEDGER  out/ledger.rl · r-20261124-005858-b7718770 RE-RUN IT YOURSELF  uv run witness check out/two-hub.rl  uv run witness rerun out/two-hub.rl -f queries/two-hub.cypher --param country=MX --param dest=MEX  relate query --database out/two-hub.rl --read-only --param country=MX --param dest=MEX < queries/two-hub.cypher   # optional CLI VERIFIED · deletion-minimal: no single relationship can be removed without changing the answer · determinism claimed
Verbatim output, recorded 2026-11-24 00:58:52 UTC (evidence/demo-2026-11-24.txt); this run reduced in 0.998 s.

Exhibits B and C · same loop, the other two predicates

When the agent's query is wrong, the evidence still shrinks.

Two queries disagree · India, DEL

57,645→5

An agent's version of the question matches the first flight in either direction. It disagrees with the reference query on 6 of 232 country and busiest-airport pairs. For India and DEL, 5 relationships keep the two disagreeing, and one of them is the flight the agent's query read backwards: (VNS)-[:HAS_ROUTE]->(AGR), as if Agra flew to VNS.

5 of 5 end the disagreement

--predicate disagree · 139 trials. On the witness, plain relate returns AGR for the agent's query and no rows for the reference. witnesses/direction-bug.manifest.json

A wrong answer, reproduced in 92 relationships · India, DEL

57,645→92

Hand Witness the answer you expected (the reference query's 12 rows) and the query that gets it wrong (13 rows: the 12 plus AGR). It keeps that same wrong answer while it deletes; deleting any one of the 92 relationships left changes that wrong answer. The repro is 92, not 5, because it must reproduce all 13 wrong rows, not only the one that disagrees.

92 of 92 change the answer

--predicate differs · 2,099 trials, cross-checked on the Relate CLI. witnesses/wrong-answer.manifest.json

How it works · Relate is the engine

Delete, re-run, roll back. Hundreds of times a second.

Every trial is a transaction

Delete a set of relationships inside a Relate transaction, re-run your query, compare, roll back. Only deletions that keep the answer are applied, on a scratch copy; the source is never opened for writing.

begin_transaction · rollback_transaction
The headline run, one tick per trial86 applied · 285 rolled back · 371 trials
Relate, in-process366.8/s
Neo4j 2026.10.2, Docker90.2/s

Same loop and query, one machine, median of 3 runs, identical answers. It measures this setup (Docker VM, Bolt round trip), not a limit of Neo4j.

EXPLAIN prunes first

Witness collects the labels and types named in the query and in Relate's EXPLAIN plan. :ON_CONTINENT is in neither, so 3,504 relationships go in one verified step, before trial 3.

EXPLAIN · relate.plan/v1

Read-only, checked twice

Witness's own check refuses writes, procedures, clocks and randomness; then Relate must report the query's query_type as "r". Anything refused exits 2.

QueryResult.query_type

A witness is one file

two-hub.rl is the witness: open it with plain relate. Beside it: a Cypher script that rebuilds it, a manifest, the exhibit page, and a line in the witness.rl ledger.

single-file .rl

An agent can ask why

The MCP tools why and check let an agent request the witness of its own answer and re-prove it, beside Relate's own relate serve --mcp.

MCP · why · check

Fixture mode

relate pull brings a slice in from Neo4j once; Witness shrinks it to a test fixture. In the committed run, 1,272 relationships became 126, 126 of 126 needed. Nothing is pushed back.

relate pull

Honest by design · what the stamp does not say

Deletion-minimal. Not smallest.

  1. 1
    Deletion-minimal means: no single remaining relationship (or kept isolated node) can be removed without changing the answer. It does not mean "smallest possible".
    README · The Solution
  2. 2
    Because a query with NOT EXISTS or aggregation is not monotone, a witness proves its own answer on its own file; it does not prove that every superset of it gives the same answer.
    README · The Solution
  3. 3
    The gap mostly reflects an embedded engine versus a Dockerised server with a network round trip per statement; it says nothing about Neo4j's query engine.
    README · Measured against Neo4j

Questions a judge would ask

Before you clone it.

Is the witness the smallest subgraph that gives the answer?

No. It is deletion-minimal: no single remaining relationship can be removed without changing the answer. A smaller witness may exist.

What counts as changing the answer?

The answer is compared exactly: types matter, rows are a bag (order is not part of the answer), floats to 12 significant digits, and this headline run compares lists strictly (--strict-lists). Pulling exhibit 4 keeps all four airports but drops US from two rows, and that is a change.

Does Witness ever write to my graph?

No. The source .rl is copied byte for byte and never opened for writing; every reduction checks its SHA-256 unchanged afterwards. Fixture mode pulls from Neo4j once and never pushes back.

Is anything mocked?

Not the judged path: the graph store, transactions, rollback and queries are real Relate in every test. In tests, relate pull (it needs a Neo4j server) is stood in, and a few tests substitute timers, process calls, a failing CLI, a database wrapper that injects engine faults, or one reducer phase to reach rare branches. The committed fixture run pulled from a real Neo4j server (fixtures/mex-foreign.report.json).

Why Relate rather than a Neo4j server?

The inner loop is one transaction per trial, in process, on a single file: 366.8 trials/s here against 90.2 over Bolt to Neo4j in Docker on the same machine. And a witness is a file you can commit, hand over and open with plain relate, with no server.

How does an agent use it?

Over MCP. The why tool returns the witness of the agent's own answer and check re-proves it. Two recorded sessions are committed: evidence/mcp-transcript.md (a scripted client) and evidence/mcp-agent-session.md (a real model, claude-sonnet-5-5 in Claude Code, writing its own Cypher and attaching the witness).

File the evidence, not the whole house.

git clone https://github.com/edycutjong/witness && cd witness
uv run witness demo

Needs uv. The repository opens at submission; until then the clone does not resolve and the recorded run below is the output.

Source on GitHub opens at submissionPitch deckFor judges