Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/container-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ jobs:
i8_canary_never_reaches_the_agent \
egress_proxy_never_resolves_a_listed_host_to_itself \
controls_e2e_pinned_harness_passes \
parity_one_installed_server_one_traced_call \
control_each_kind_runs_on_the_real_base \
opencode_probe_reads_each_real_base_image_version \
plugin_environment_serves_live_mcp_tools \
Expand Down
125 changes: 125 additions & 0 deletions __reports__/diet/leaves/parity_run_v0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Parity run leaf, v0

One cell with a real MCP server, run on Claude Code and on OpenCode with code mode at its default,
shows on each harness that the server is installed and that the stored trace holds the agent's call
to its tool as the same `ToolOrigin::Mcp`.

Base `a1f14719` (`origin/feat/integrity` at the branch point). Tip: the tip of `leaf/l3-parity-run`.

## Live record (step 2)

Two runs of the guard's experiment shape, one per harness, on RiVault (reachable; `rv_health` ok).
The experiment is the guard's: one cell, `permission_mode = "bypassPermissions"`, model
`RiVault/Reasoning-Medium`, the declared server `parity` (`python3 servers/parity/parity_mcp.py`
from an agent input), code mode left out; only the `[harness]` name differs. The key's variable is
`RIVAULT_LLM_INFERENCE` (`rv_config.py var llm`); no key was printed. No run was repeated.

| | Claude Code | OpenCode |
|---|---|---|
| job | `01a20f84-4e1a-7846-b388-c9ba5c76d190`, completed | `01a20f84-9378-71bd-9f47-12e2da5782fe`, completed |
| alias | `RiVault/Reasoning-Medium` | `RiVault/Reasoning-Medium` |
| model the proxy returned | `RiVault/Reasoning-Medium` (the `model` of the streamed answers, 8 times in stdout, once in stderr) | `RiVault/Reasoning-Medium` (the `model.id` of the export) |
| backing model | `deepseek-ai/DeepSeek-V4-Flash` (`rv_models.py`, the live listing; the proxy answers with the alias, not the backing name) | the same |
| resolved `mcp.*` (`candler inspect`) | `mcp.servers.parity.command = "python3"`, `.args = ["servers/parity/parity_mcp.py"]`, `.codemode = false` | the same three values |
| stored trace, tool calls | `ToolSearch` builtin, `ToolSearch` builtin, `mcp__parity__stamp` with origin `{kind: mcp, server: parity, tool: stamp}` | `parity_stamp` with origin `{kind: mcp, server: parity, tool: stamp}` |

Both traces attribute the call to the same server and tool. The shape matches the guard's: Claude
Code reaches the tool through its own `ToolSearch` (it defers MCP tools), OpenCode lists it at once,
and the one MCP call reads the same in both stored traces. Numbers are not compared. The runs' store,
scratch worktree files and containers are removed (`docker ps -a` shows none of the job's; no
network is left).

## Gates

| Gate | Verdict | Evidence |
|---|---|---|
| Guard in `container-e2e` with real images, production gateway, scripted fake model; per harness the server in the resolved `mcp.*` values and in the rendered MCP file, and the scripted call stored as `ToolOrigin::Mcp` with one server and tool | PASS | `cargo nextest run -p candler --test it -E 'test(parity_one)' --run-ignored only`: PASS, 22.5 s locally; CI `PASS [37.879s] (3/23) ... guard_cli_e2e::parity_e2e::parity_one_installed_server_one_traced_call`; `container-e2e` green on PR 79 |
| Fails on the base on OpenCode with `origin: other` | PASS, on a different base than the leaf names | `origin/feat/integrity` already holds the trace-parity reader, so the failure is shown on `29573006` (merge of #74). The guard does not compile there unchanged (`ToolOrigin::mcp_tool` is absent); with its oracle adapted to the origin that had no `tool` (`{kind: mcp, server: parity}`) it fails: `opencode: MCP tool calls [] among [{"kind":"other"}]`. `candler inspect` shows no `mcp` member there either (`no mcp.servers.parity in null`, both harnesses) |
| No census, no server status | PASS | the guard reads `candler inspect`'s `mcp` member, the files in the run, and the stored trace |
| Same experiment file, harness the only difference; code mode at default, no code-mode case | PASS | the guard asserts the two files differ in exactly the line `name = "claude-code"` / `name = "opencode"`; `codemode` is not written, and the resolved value is `false` |
| Fixture needs nothing outside the base images | PASS | one stdlib `python3` file. Both agent base images carry `python3` (probed: `/usr/local/bin/python3` in the Claude Code and the OpenCode image; neither has `node`) |
| One live run per harness, same shape, call attributed to the server; store and containers removed | PASS | the live record above |
| Container-e2e added time | PASS | see Time |
| "What it leaves" at three levels | PASS | below |
| fmt, clippy `-D warnings`, nextest workspace, doc `-D warnings`, `container-e2e` | PASS | fmt clean; clippy clean after two doc backticks; `732 tests run: 732 passed, 32 skipped`; `cargo doc` exit 0; CI `container-e2e` success |
| Bite (step 3), edit A: OpenCode's reader drops the server from the origin | PASS (fails as it should) | `opencode: MCP tool calls [] among [{"kind":"other"}], expected [{"kind":"mcp","server":"parity","tool":"stamp"}]` |
| Bite, edit B: Claude Code's renderer skips the server | PASS (fails as it should) | `claude-code: 0 .mcp.json files hold the server under /mcpServers: []` and `claude-code: MCP tool calls [] among []` |

Deviations: the guard is in `crates/candler/tests/it/guard_cli_e2e/parity_e2e.rs`, not
`candler-core`'s tests, because the producer it reads (run, resolved values, trace) is the
`candler` binary. The step 1 commit line is 77 characters and the `commit-msg` hook allows 72, so it
reads `test(runner): hold both harnesses to one MCP install and traced call`. The pull request title
is cut to 66 characters. The fresh verifier of step 3 is the lead's.

## Time

- Locally the guard runs in 22.5 s for both harnesses (images cached).
- CI, `Container e2e (Linux)` on PR 79: 7 min 40 s, of which the guard took 37.9 s. The latest run on
a leaf branch before it (`leaf/l3-pages`) took 7 min 12 s: about 28 s more.

## What it leaves

How it is developed. The guard was written by reading the i8 guard and the control runner once,
then run against the real images; two failed runs before the first pass cost seconds, not builds
(the fake model had to learn Claude Code's `ToolSearch`). Docker use: one fake-model image and
container per run, removed by exact id by the guard; the live runs used the cached images and their
stores are removed. No image was built that was not there. The two scratch builds (the old base, the
two bite edits) shared one scratch target dir, removed after.

What it leaves in the code. One guard, one fixture file, one script in the fake model; the i8 guard
and this one share `Made`, `must` and `fake_host` instead of copying them. The guard builds no
state: the run, its resolved values, the rendered file and the trace all come from `candler run`
and `candler inspect`. It asserts what the leaf names and no more. The oracle for the origin is the
type's own constructor. Nothing is kept for another reader.

How it is consumed. The experimenter's view does not change. A maintainer who lets one harness
install or trace a declared server differently now gets a red `container-e2e`, naming the harness,
the file or the origin that differs.

## Not covered

- Permission defaults. The experiment sets `permission_mode = "bypassPermissions"` (the mode both
drivers map; OpenCode refuses `default`), so the guard and the live runs prove MCP install and
trace parity, not what each harness does with no mode. That choice is still open.
- Code mode: no case, by the leaf.
- The rendered file is read from the run's stored home and workspace by name (`.mcp.json`,
`opencode.json`); a harness that renders under another name needs its row in the guard.
- A tool that is deferred behind a harness's own search (Claude Code) is reached by the fake model
through `ToolSearch`; a Claude Code version that changes that protocol breaks the script, not the
guard's assertions.

## Observations for the lead

- The leaf and the lead's reading assumed the OpenCode image has no `python3` and that `node` is on
both images. Probed on the local images: both have `python3`, neither has `node`.
- On the merge of #74 `candler inspect` shows no `mcp` member; it arrived with #77.

## Review

A fresh verifier read PR 79. Five findings, each fixed in a new commit (`a3884e78`, `f3c86903`).

1. **Leak on failure.** `run_once` never gave `Made` the job id, so a timeout or a failed assertion
left the job's containers, sidecar and network. It takes `&mut Made` and sets `made.job` right
after parsing the launcher's output. Shown with a scratch edit that panics just after the id is
known (`leak probe job 01a20f97-f87b-79c0-96b5-1bcf4481c3a7`): after the test, `docker ps -a` and
`docker network ls`, filtered by `label=candler.job=<that id>`, print nothing, and no candler
container or network exists. The probe panics at the first moment after launch, so it shows the
cleanup runs, not what a later phase would hold.
2. **Reachability.** The origin alone is read by name, so a rendered but broken server passed. The
guard now also requires that the fake model received, in the request that follows its call
(`tool_use_id` `toolu_fake_stamp`), a tool result that is not an error and holds the fixture's
stamp `parity-stamp-5c1e`. The stored trace keeps no tool-result content (`tool_result` has
`is_error` and `denied` only), so the text is read from the fake model's recorded requests, the
record of what the model was handed; each run reads only the requests recorded during it.
Bite, the fixture returns `parity-stamp-0000` with the server still rendered and the call still
attributed: `claude-code: the model never received the stamp from the tool: [(false,
"[{\"text\":\"parity-stamp-0000\",...}]")]` and `opencode: ... [(false, "parity-stamp-0000")]`.
Second bite, the args name a file that is not there: Candler's own job ends with no sealed run,
and the guard fails with `a sealed run` followed by the job's events.
3. **Rendered file.** The file is now the one below the run's `workspace` (`.mcp.json`, Claude Code)
or `home` (`opencode/opencode.json`, OpenCode), where each driver writes it, and its program and
arguments must equal the resolved `mcp.servers.parity.command` and `.args`.
4. **Identity.** The two experiment files are compared as whole strings with the harness name
replaced by one placeholder, not line by line.
5. **Oracle.** The expected origin is the literal `{"kind":"mcp","server":"parity","tool":"stamp"}`,
the stored trace's form, not the type's constructor.
37 changes: 35 additions & 2 deletions assets/docker/fakemodel/fakemodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
is answered with text. A user message that carries a background job's completion is
answered with a second text. Anything else is answered with text.
c2 must stop. Every request is answered "hello".
p1 must call a tool. A first user prompt is answered with one call to the tool `stamp` of the
MCP server `parity`, under the name the request offers for it (`parity_stamp` for
OpenCode). A request that defers its MCP tools (Claude Code, which offers ToolSearch) is
answered with a ToolSearch for `mcp__parity__stamp` first, and its result with the call.
Anything else is answered with text.
c3 must be slow. Every request is answered "hello" after FAKE_DELAY_SECS seconds, so that a
run is live and its agent is mid-turn for that long.

Expand All @@ -50,6 +55,7 @@
DIR = os.environ.get("FAKE_DIR", "/tmp/fake")
OUT_TOKENS = int(os.environ.get("FAKE_OUT_TOKENS", "20"))
DELAY_SECS = max(0, min(int(os.environ.get("FAKE_DELAY_SECS", "0")), 120))
PARITY_TOOLS = ("mcp__parity__stamp", "parity_stamp")
JOB_COMMAND = "sleep 20 && date +%s%N > /work/job.done && echo job-finished"
LOCK = threading.Lock()
COUNTER = [0]
Expand Down Expand Up @@ -104,8 +110,34 @@ def last_user_state(messages):
return "prompt"


def script_blocks(model, state):
def stamp_call(name):
"""A call to the stamp tool under `name`."""
return {"type": "tool_use", "id": "toolu_fake_stamp", "name": name, "input": {}}


def last_tool_result(messages):
"""The tool_use_id of the last tool result of the last user message, or None."""
content = messages[-1].get("content") if messages else None
ids = [b.get("tool_use_id") for b in content or []
if isinstance(b, dict) and b.get("type") == "tool_result"] if isinstance(content, list) else []
return ids[-1] if ids else None


def script_blocks(model, state, tools, messages):
"""The content blocks, the stop reason and a label of the answer for one request."""
if model.startswith("p1"):
offered = [name for name in tools if name in PARITY_TOOLS]
if state == "prompt" and offered:
return [{"type": "text", "text": "I will call the stamp tool."},
stamp_call(offered[0])], "tool_use", "p1-call"
if state == "prompt" and "ToolSearch" in tools:
search = {"type": "tool_use", "id": "toolu_fake_search", "name": "ToolSearch",
"input": {"query": "select:" + PARITY_TOOLS[0], "max_results": 1}}
return [{"type": "text", "text": "I will load the stamp tool."}, search], \
"tool_use", "p1-search"
if state == "tool_result" and last_tool_result(messages) == "toolu_fake_search":
return [stamp_call(PARITY_TOOLS[0])], "tool_use", "p1-call"
return [{"type": "text", "text": "done"}], "end_turn", "p1-text"
if model.startswith("c2"):
return [{"type": "text", "text": "hello"}], "end_turn", "c2-hello"
if model.startswith("c3"):
Expand Down Expand Up @@ -206,7 +238,8 @@ def handle_any(self):
decision, status = "unauthorised", 401
elif path == "/v1/messages" and self.command == "POST" and isinstance(body, dict):
state = last_user_state(messages)
blocks, stop, label = script_blocks(model, state)
tools = [t.get("name", "") for t in body.get("tools") or [] if isinstance(t, dict)]
blocks, stop, label = script_blocks(model, state, tools, messages)
decision = "%s/%s" % (label, state)
message = message_json(model, blocks, stop)
elif path == "/v1/messages/count_tokens":
Expand Down
37 changes: 37 additions & 0 deletions crates/candler/tests/fixtures/parity/parity_mcp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""A stdio MCP server with one tool, `stamp`, written with the standard library alone."""
import json
import sys

TOOLS = [{
"name": "stamp",
"description": "Returns the parity stamp, a fixed text. Takes no argument.",
"inputSchema": {"type": "object", "properties": {}, "additionalProperties": False},
}]
STAMP = "parity-stamp-5c1e"


def send(message):
sys.stdout.write(json.dumps(message) + "\n")
sys.stdout.flush()


for line in sys.stdin:
try:
msg = json.loads(line)
except ValueError:
continue
method, msg_id = msg.get("method"), msg.get("id")
if method == "initialize":
send({"jsonrpc": "2.0", "id": msg_id, "result": {
"protocolVersion": msg.get("params", {}).get("protocolVersion", "2025-03-26"),
"capabilities": {"tools": {}},
"serverInfo": {"name": "parity", "version": "1.0.0"},
}})
elif method == "tools/list":
send({"jsonrpc": "2.0", "id": msg_id, "result": {"tools": TOOLS}})
elif method == "tools/call":
send({"jsonrpc": "2.0", "id": msg_id,
"result": {"content": [{"type": "text", "text": STAMP}], "isError": False}})
elif msg_id is not None:
send({"jsonrpc": "2.0", "id": msg_id,
"error": {"code": -32601, "message": "unknown method"}})
4 changes: 4 additions & 0 deletions crates/candler/tests/it/guard_cli_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,3 +806,7 @@ mod shim_refusals {
/// The ground-truth e2e: a real `candler run` of the real agent, seen from inside its container.
#[path = "guard_cli_e2e/i8_e2e.rs"]
mod i8_e2e;

/// Both harnesses install and trace one declared MCP server the same way.
#[path = "guard_cli_e2e/parity_e2e.rs"]
mod parity_e2e;
14 changes: 7 additions & 7 deletions crates/candler/tests/it/guard_cli_e2e/i8_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const DELAY_SECS: u64 = 100;
/// The name or address the fake model's certificate is for and the job's containers reach it by:
/// `host.docker.internal` on Docker Desktop, the default bridge's gateway address on a Linux
/// engine, which resolves no such name in a container the product starts.
fn fake_host(real: &Path) -> String {
pub(super) fn fake_host(real: &Path) -> String {
if cfg!(target_os = "linux") {
must(
real,
Expand Down Expand Up @@ -71,11 +71,11 @@ fn ere_escape(text: &str) -> String {

/// What the test made and must give back, by exact id.
#[derive(Default)]
struct Made {
real: PathBuf,
job: Option<String>,
containers: Vec<String>,
images: Vec<String>,
pub(super) struct Made {
pub(super) real: PathBuf,
pub(super) job: Option<String>,
pub(super) containers: Vec<String>,
pub(super) images: Vec<String>,
}

impl Drop for Made {
Expand Down Expand Up @@ -111,7 +111,7 @@ impl Drop for Made {
}

/// What `docker <args>` printed on stdout, for a command that must succeed.
fn must(real: &Path, args: &[&str]) -> String {
pub(super) fn must(real: &Path, args: &[&str]) -> String {
let out = docker(real, args);
assert!(
out.status.success(),
Expand Down
Loading