Skip to content

test(conformance): add a live-host first-hop harness that scores real host tool selection - #814

Merged
sumithr merged 13 commits into
mainfrom
feat/issue-732-live-host-first-hop-harness
Oct 2, 2026
Merged

sumithr merged 13 commits into
mainfrom
feat/issue-732-live-host-first-hop-harness

Conversation

@sumithr

@sumithr sumithr commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds scripts/live_first_hop.py, a manual (not PR-CI) harness that runs the deterministic conformance scenarios against a real host with only the sumo-qa MCP attached, records host, host version, model and the ordered tool calls per prompt, and scores each transcript with validate_all / format_report. Before/after mode compares two builds on the same prompts. The default candidate is the weakest model (--model haiku), per the #732 addendum.

Related issue

Closes #732

Changes

  • scripts/live_first_hop.py:
    • Builds: a git ref (archived and built to a wheel) or a .whl, each installed in its own venv under the run dir; every build is installed before any billed host run. Wheels are labelled by their cwd-relative path; a tag resolves to its commit.
    • Child host: claude -p --strict-mcp-config with only that build's sumo-qa, --setting-sources "", slash commands off, CLAUDE.md and auto-memory off, a throwaway cwd, a host-tool allowlist via --tools (ToolSearch, Agent, Read, Glob, Grep) plus --disallowedTools Bash Write Edit NotebookEdit, and a minimal child environment (no parent model overrides; proxy, CA and Bedrock/Vertex settings pass through, including the AWS SDK role, container and IMDS credential chain; backend model aliases only when a backend switch is truthy).
    • sumo-qa tool approval is derived per build from that build's own tools/list annotations (read-only and not open-world); unannotated tools are approved only for the router and that build's skill tools; installing or executing an external skill is never pre-approved. A mis-route is judged against the scored build's own skills.
    • Validity: a run is scored only if MCP connected, every result event is a success, there is no usage-limit text, the stream is not cut off and the exit code is 0. An invalid run reads SKIP and the harness exits 4.
    • Write guard (AC3): for each build, before any scenario, a control prompt asks the host to create a file outside its scratch dir. The guard passes only if the file is absent and the host's own init-event tool pool holds the router and no tool outside the allowlist plus that build's sumo-qa tools. A breach exits 3; a guard with no init event, a usage limit, an unconnected server or a bad pool exits 4 before any scenario.
    • An invalid --only regex is a usage error (exit 2) before anything is built.
  • tests/test_live_first_hop.py: offline tests over real captured stream-json (tests/fixtures/live_first_hop/, paths and ids anonymised, event structure unedited; a test keeps local user paths out); edited captures are marked as such.
  • tests/scenarios/CONFORMANCE.md: "Live host first hop" under "Running it", with the exit-code table.

How it was verified

Live run on ee6a50b, origin/main (042c013) vs the branch wheel, claude-code 2.1.287, claude-haiku-4-5, --only 'DC?0' (D0x/DC0x):

Scenario origin/main branch wheel
D01 PASS SKIP (turn limit, not scored)
D02 PASS FAIL (no sumo-qa call)
D03 PASS PASS
D04 PASS FAIL (no sumo-qa call)
DC01 to DC04 PASS PASS
  • Nothing the server serves differs between the two builds (no change under src/, skills/, knowledge/ or pyproject.toml), so the D02/D04 flips are single-run haiku variance, which one run per prompt cannot separate. The run exits 4 because of the invalid D01 run, as documented.
  • Write guard, both builds: PASS, no file written. Host tool pool Task, Glob, Grep, Read, ToolSearch plus the 48 sumo-qa tools; on origin/main the model called Write, which is not in the pool, and was refused.
  • The default --max-turns 15 cut off the haiku candidate's D01 on the branch build in 2 of 2 runs (ToolSearch loops); raise --max-turns when that scenario matters.
  • CI: all 33 checks pass on 40269e3; mutation gate run 37059057276 success on that head. Targeted: pytest tests/test_live_first_hop.py tests/test_claude_cli_provider.py, 152 passed.

Review: per-file sumo-qa review plus /code-review (high) over the branch; the final delta round came back clean, and the merge-boundary per-file review raised one doc inaccuracy, fixed in 40269e3 (a guard stopped only by a usage limit can still read PASS; CONFORMANCE.md now says so). The one Codex thread (role-based Bedrock credentials) is resolved.

Notes and decisions

  • Main-thread and subagent tool calls are scored as one merged sequence, with subagent calls marked sub:. Whether delegating the first hop to a subagent should count as routing is a measurement decision left open here.
  • sumo_qa_execute_external_skill is annotated read-only and closed-world by the server, which looks wrong for a tool that hands an external skill over to run; the harness refuses it by name regardless.
  • The write guard proves that no host write tool was in the pool; sumo-qa writer tools are present but not pre-approved, so non-interactive mode refuses them by permission (not separately proven by the guard).
  • The guard test reads the committed tools-list snapshot; if the served tool set changes, the frozen write-guard capture needs a new live capture.
  • A --repeat N option would separate model variance from a real regression; not added here (beyond the acceptance criteria).

Checklist

  • PR title follows Conventional Commits
  • Tests pass locally and lint/type checks are green
  • Added or updated tests covering the change
  • Updated the relevant docs in this same PR
  • No breaking changes

… host tool selection

scripts/live_first_hop.py runs every deterministic conformance scenario's
prompt through `claude -p` with only the sumo-qa MCP server of a named
build attached (a git ref built to a wheel, or a .whl), normalises the
host's stream-json tool calls to bare names, and scores them with
validate_all / format_report. Two builds give a before/after comparison.
The report records host, host version, model, MCP status and the ordered
tool calls per prompt, marking calls a subagent made.

The child host runs in a throwaway cwd with --strict-mcp-config, no
settings sources, skills, CLAUDE.md or auto-memory, and --disallowedTools
for Bash, Write, Edit, NotebookEdit and the out-of-cwd host tools. A
write-guard control prompt fails the run if the host writes a file outside
its scratch dir. The default model is haiku, the weakest candidate.

The unit-test fixtures are real captures from the harness's own run.

Closes #732
… invalid run

- A usage-limit stop (the promptfoo provider's own pattern), a non-success
  outcome, a missing result event, a cut-off stream, a non-zero exit or an
  unconnected MCP server makes a run invalid: not scored, exit 2.
- The child gets an allowlist of host tools (ToolSearch, Agent, Read, Glob,
  Grep) with Bash, Write, Edit and NotebookEdit also denied, explicit default
  permission mode, and only sumo-qa's read-only tools pre-approved.
- The child environment is minimal, so model overrides, SUMO_QA_DEBUG_DIR
  and parent session variables do not reach the host or its MCP server.
- Every build installs first; the widened write guard runs per build before
  any scenario and stops the run on a breach (exit 3) or an invalid guard run.
- --out is resolved and must be new or empty; --only matching nothing errors
  before any build; stderr and the exit code of each run are kept.
…n run validity

- parse every result event: output joins all result texts, success only when
  every result is, a usage limit in any result marks the run
- only an undecodable final line is truncation; mid-stream non-JSON lines are
  skipped and counted in the report
- the write guard passes on sentinel absent + MCP connected + no usage limit,
  independent of the guard run's own outcome
- pre-approved sumo-qa tools come from the installed build's own tools/list
  annotations, not the checkout's snapshot or a hand-kept refused list
- pass proxy, CA, config-dir, gateway, Bedrock and Vertex variables to the
  child; model-selecting and SUMO_QA_* variables stay blocked
- an --out that is a file is a parser error; an invalid billed run exits 4
  (2 stays bad arguments); an unobserved exit code is never valid
…nal skill

A by-name floor on top of the per-build annotation rule; the tools/list
derivation can never lift it. The approval tests read this checkout's served
annotations in-process and the stdio reader against a stand-in server, so no
test spawns sumo_qa under mutmut.
…and probe

- Write guard passes only when the model acted (success or turn limit) with
  MCP connected; API errors, execution errors, no result, a cut-off stream or
  a timeout exit 4.
- Unannotated tools are approved only as the router or a skill tool of the
  build, read from the skills its installed wheel bundles; a missing
  openWorldHint is open-world, per the MCP default.
- tools/list probe uses the installer's JSON-RPC transport: one deadline,
  tolerant of non-JSON lines, named errors, terminate-then-kill teardown.
- A usage limit outranks a cut-off final line.
- Bedrock/Vertex alias mapping, VERTEX_REGION_CLAUDE_* and CLOUDSDK_CONFIG
  pass only with a backend switch set.
…ard passes

The write guard passed when the model declined without trying, which proves
nothing about the sandbox. The guard prompt now tells the model to use its
Write tool (or any other tool) on a plainly named file, and the guard passes
only when the transcript shows a non-lookup tool call naming that file; with
no attempt it is inconclusive (exit 4).

child_env now reads CLAUDE_CODE_USE_BEDROCK/_VERTEX as the CLI does (1, true,
yes, on), so a switch set to 0 or false no longer lets an
ANTHROPIC_DEFAULT_*_MODEL override reach a first-party host. server_tools
failures now carry the server's last few non-JSON-RPC output lines.
The write guard now passes only when its own system/init event lists no
tool outside the allowlisted host tools (Agent as the CLI names it, Task)
and that build's sumo-qa tools; any other tool exits 4 naming it. The
model's guard calls are reported for information, never judged, and the
control prompt asks for the file with any tool it has.

server_tools sends the server's stderr to a file and puts its last lines,
where a crash traceback lands, in the failure message.
The write guard now requires the allowlisted host tools and the router in its
pool (the union of every init event) and exits 4 naming any missing one, so a
run stopped before init proves nothing. The model-acted gate is dropped; the
docs state that the guard proves no host write tool was in the pool, not that
sumo-qa writers are refused. server_tools opens its stderr file inside the
protected region, names a binary that cannot start, and reads only the stderr
tail after stopping the server. The guard tests take the build's tool names
from the committed tools/list snapshot.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a08c1157d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/live_first_hop.py Resolved
run_host wrote the host's stdout and stderr through text mode, so on
Windows every captured \r\n became \r\r\n. Write the captured bytes
unchanged. Pass SYSTEMROOT through to the child environment: a Python
3.10 child on Windows cannot start without it. Make the tests portable:
escape the binary path in the start-failure regex, check the cause type
instead of the POSIX error text, and compare the fake binary as str().
…and guard stops

- Pass the AWS SDK credential chain (web identity, container credentials,
  IMDS) to the child so Bedrock authenticates on EKS, ECS and EC2.
- Judge mis-routes against the scored build's own skill tools.
- Stop before any scenario when the guard run hit a usage limit (exit 4).
- Make an invalid --only regex a usage error (exit 2).
- Label wheels by their path relative to the cwd; peel annotated tags to
  their commit for a ref's short sha.
- Dedupe a tool name repeated inside one init event.
- Anonymise local paths and UUIDs in the live_first_hop fixtures.
- State the exit-4 conditions as the code applies them.
@sumithr

sumithr commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner Author

Finish proof, head 40269e3

CI: 33 of 33 checks pass on 40269e3. Mutation gate: run 37059057276 on this head, success. Open review threads: 0 (the Codex role-based Bedrock credentials thread was fixed in ee6a50b and resolved).

Per-file review (sumo-qa-reviewing-before-merge, each changed file's full post-change content vs main, at ee6a50b): SAFE for scripts/live_first_hop.py, tests/test_live_first_hop.py, tests/scenarios/CONFORMANCE.md and the 4 fixtures. One low finding (CONFORMANCE.md said every guard stop reads NOT PROVEN; a usage-limit stop with a proven pool reads PASS and exits 4), fixed in 40269e3.

/code-review (high): final delta round fdfc7d1..ee6a50b SAFE (AWS credential chain, build-owned skills for mis-routes, --only usage error, wheel labels, annotated tags, usage-limit guard stop, tool-pool dedupe, fixture anonymisation checked line by line: 193 ids mapped one-to-one, no local paths). 40269e3 is a one-sentence doc change.

Behaviour ledger (finish-pr 4.7), live run of scripts/live_first_hop.py origin/main dist/sumo_qa-0.70.0-py3-none-any.whl --only 'DC?0' on claude-code 2.1.287, claude-haiku-4-5:

# expected behaviour real-surface call + input observed output Met
1 One command runs every deterministic scenario with a user_prompt against a named build and host and prints the format_report PASS/FAIL/SKIP table uv run --no-sync python scripts/live_first_hop.py origin/main dist/sumo_qa-0.70.0-py3-none-any.whl --only 'DC?0' (real claude-code 2.1.287, haiku candidate, this repo) both builds print the per-scenario PASS/FAIL/SKIP table and N passed, N failed, N skipped; selection is deterministic and user_prompt (select_scenarios); branch D01 hit the 15-turn default (error_max_turns) and was SKIPped, run exit 4 Met: the origin/main build ran all 8 D0x/DC0x scenarios valid and printed the table (8 passed); the branch build printed it with D01 SKIP
2 Before/after mode compares two builds on the same prompts same run == before -> after section, one row per scenario for both builds (D01 PASS -> SKIP, D02 PASS -> FAIL, D03 PASS -> PASS, D04 PASS -> FAIL, DC01-04 PASS -> PASS); no served file differs between builds, so the D02/D04 flips are haiku run-to-run variance Met
3 Child host cannot write outside its scratch dir, proved by a control prompt write-guard control prompt per build, same run both guards PASS, no file at .../build-N/notes/todo.txt; on origin/main the haiku guard called Write, which is not in the pool (host tool pool: Task, Glob, Grep, Read, ToolSearch + 48 sumo-qa tools), refused, no file Met
4 Output records host, host version, model, ordered tool calls per prompt same run host: claude-code 2.1.287, model: claude-haiku-4-5-20251001, per-scenario ToolSearch -> Agent -> sub:using_sumo_qa -> ... Met
5 Test plan: unit tests on normaliser + report assembly from real captured fixtures uv run --no-sync pytest --no-cov tests/test_live_first_hop.py tests/test_claude_cli_provider.py 152 passed; fixtures are real captures, anonymised (paths + ids only), guard test test_the_captures_carry_no_local_user_paths Met
  • real_repo: this repo (sumo-qa) with its real history; builds = origin/main (042c013) archived + the branch wheel.

  • real_surface: real claude -p host with only the built sumo-qa attached (the harness is the surface).

  • existing_flow: N/A, the diff touches nothing under src/, skills/, knowledge/ or pyproject.toml.

  • evals: N/A, no eval input in the diff.

  • note: the default --max-turns 15 cut off the haiku candidate's D01 on the branch build in 2 of 2 runs (ToolSearch loop); the run is reported invalid and exits 4, as documented. Raise --max-turns per run when that matters.

Acceptance criteria (#732): all 4 met (rows 1 to 4); test plan met (rows 5 and the manual run above).

Integration (finish-pr-batch 5.5) with #811, #813, #814, #816 and #818 merged in drain order on a throwaway branch off main: full suite 5323 passed, 100% coverage; live MCP routing reaches the routed skill through dispatch; tools/list unset/full equal main (48), core 40; no conflicts except #811 vs #813 (one import block in tests/test_tools_list_contract.py, resolved by keeping both imports; #811 is rebased after #813 merges).

@sumithr
sumithr merged commit 6e1cac7 into main Oct 2, 2026
34 checks passed
@sumithr
sumithr deleted the feat/issue-732-live-host-first-hop-harness branch October 2, 2026 21:43
sumithr added a commit that referenced this pull request Oct 2, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.70.1](v0.70.0...v0.70.1)
(2026-10-02)


### Bug Fixes

* **skills:** stop downstream skills leaking announce lines and approach
labels ([#816](#816))
([f21f376](f21f376))


### Tests

* **conformance:** add a live-host first-hop harness that scores real
host tool selection
([#814](#814))
([6e1cac7](6e1cac7))


### Continuous Integration

* **tests:** cut the pytest matrix to 9 jobs and run the suite under
pytest-xdist ([#813](#813))
([7a84f9b](7a84f9b))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: release-please[bot] <release-please[bot]@users.noreply.github.com>
sumithr added a commit that referenced this pull request Oct 2, 2026
## Summary

Slice 1 of #515. Every MCP tool now has one `ToolMeta` entry (group,
core, open_world, integration) in `src/sumo_qa/tool_registry.py`, and
the `core` and `full` profiles are derived from it.
`SUMO_QA_MCP_PROFILE=core|full` selects the profile before tools are
listed; unset or empty means `full`, so the default `tools/list` is
byte-identical to `main`. Any other value stops the server, installer
and doctor with one clean line.

A configured profile also survives the documented update flow:
re-running the installer keeps each host entry's `env` (and `envFile`
where the host reads it), and `sumo-qa-doctor --host <host>` probes the
entry the way that host launches it, with that entry's profile.

## Related issue

Closes #806

## Changes

- `tool_registry.py`: the registry, `resolve_profile`,
`resolve_profile_or_exit`, `profile_tool_names`. Core is 40 of 48 tools:
every workflow skill tool, the knowledge and test-data loaders, analysis
and evidence/reporting tools. Out of core: 4 specialist tools and the 4
external-skill search/check/install/execute tools.
- `server.py`: resolves the profile before registration and removes
non-profile tools in registration order; a registered tool without
metadata warns and is served under `full` only, and
`test_tool_registry.py` fails on it.
- `installer.py`: a bad profile exits cleanly before any host config is
written. A refresh keeps the existing entry's `env` in
`claude_desktop_config.json`, `.vscode/mcp.json` and Claude Code's user
registry, and `envFile` in the first two; the registry is re-registered
with `claude mcp add-json` (string env values only; `claude mcp add -e`
fallback for a CLI without `add-json`, warning on keys it cannot pass;
the removed entry is restored if the add fails). `REQUIRED_TOOL_NAMES`
is derived lazily per profile, so importing the installer never exits.
- `doctor.py`: `--host claude-code|claude-desktop|vscode` probes that
host's `sumo-qa` entry with its `env`, expands `${...}` the way that
host does, requires every tool of the entry's profile, and reports an
invalid profile, an unlaunchable command or an unexpandable VS Code
placeholder as a check result instead of crashing. Claude Desktop does
not inherit the doctor shell's profile; the Claude Code CLI and VS Code
keep it.
- Snapshot fixture gains `core_tools`; the regen script writes it and
refuses to pin a tool without metadata.
- `tests/conftest.py`: clears `SUMO_QA_MCP_PROFILE` in
`pytest_configure`, and runs doctor and installer test modules in a temp
HOME so nothing reads the real `~/.claude.json`.
- Docs: `CONFIGURATION.md` (Tool profiles, refresh and doctor behaviour
per host), `INSTALL.md`, `TOOLS.md`, `DEVELOPMENT.md`.

## How it was verified

- CI green on ec7a49d across the full matrix (pytest on macOS, Ubuntu
and Windows, py3.10 to 3.14; mypy; ruff; install and handshake jobs).
Mutation gate run 37062233685 on ec7a49d: success.
- Real install from the built wheel (b1d571f; later commits change one
test assertion and one doc paragraph), 13 of 13 acceptance rows met,
driven by a real `claude -p` (haiku) host with only the built sumo-qa
attached plus JSON-RPC cross-checks: profiles are `core` and `full`
only; the metadata test goes red when a `ToolMeta` is removed; `core` is
40 tools with the external and open-world ones absent; `full` and the
default equal `origin/main`'s names and input schemas; `bogus` exits 1
with `sumo-qa: SUMO_QA_MCP_PROFILE='bogus' is not a valid MCP tool
profile; expected one of: core, full`; order is stable; the installer
keeps `env`/`envFile` for VS Code and Claude Desktop; `claude mcp get`
shows the env kept for Claude Code; the doctor judges 40 required tools
for `core` entries on all three hosts; VS Code `${workspaceFolder}`
resolves. The router plus `load_classifications` return byte-identical
results to `main`.
- Snapshot regenerated into a temp path at the head: identical to the
committed fixture, and its `required_tools` and `schemas` equal
`origin/main`'s.
- Targeted modules (registry, tools-list contract, doctor, installer,
server, skill resources) with `SUMO_QA_MCP_PROFILE=core` exported and a
temp HOME: 298 passed, 0 skipped, including the round trip through the
real `claude` CLI.
- Integration check with #813, #814 and #816: full suite 5291 passed at
100% on the merged tip, live MCP routing and tool surface correct; one
import-block conflict in `tests/test_tools_list_contract.py` with #813.

Review: per-file sumo-qa review plus `/code-review` (high) over several
rounds, and a final per-file pass at the head with every file SAFE. The
two Codex threads (installer refresh dropping the profile env; doctor
probing with the ambient env) are fixed and resolved.

## Decisions recorded here (not changed)

- Under `core`, the external-skill workflow is listed but its
search/check/install/execute tools are absent; the actionable activation
path is #807.
- `ToolMeta.integration` and `open_world` stay: #515's spec lists both
as registry metadata.
- The doctor does not read a VS Code `envFile`; a profile set only there
is probed as the shell's profile (documented in `CONFIGURATION.md`).
- Low review notes left as is: the skill-reference regex can over-match
a hyphen-suffixed token; the doctor test compares stderr exactly; the
regen script keeps a local `PROFILE_ENV` literal so it runs without an
installed package; the conftest pop is not restored after the session;
`_required_tool_names_for` ignores its argument (only caller passes the
env's profile).

## Checklist

- [x] PR title follows Conventional Commits
- [x] Tests pass locally and lint/type checks are green
- [x] Added or updated tests covering the change
- [x] Updated the relevant docs in this same PR
- [x] No breaking changes (default profile is unchanged)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task]: add a live-host first-hop harness that scores real host tool selection

1 participant