Skip to content

Add the Kani agent plugin: verify-rust skill, helper scripts, and kani-mcp - #5059

Draft
feliperodri wants to merge 16 commits into
model-checking:mainfrom
feliperodri:agent-plugin-v1
Draft

feliperodri wants to merge 16 commits into
model-checking:mainfrom
feliperodri:agent-plugin-v1

Conversation

@feliperodri

@feliperodri feliperodri commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

This PR adds the Kani agent plugin. The goal is to make Kani easy to try and adopt from the coding agents Rust developers already use (Kiro, Claude Code, Copilot/VS Code, Cursor, Codex). An agent can verify a property, write or improve a proof harness, run Kani, explain a counterexample, and check that a passing proof is not vacuous, without the user first learning every Kani command.

What's included

  • agent-plugin/skills/verify-rust/: the orchestration skill. Steps: pin down the property, check Kani is installed, write the harness, run Kani with --export-json, get a counterexample via concrete playback, check vacuity and assumptions, and report exactly what was proven, with its bounds and stubs. Detailed guidance lives in references/ (Kani, AutoHarness, contracts, Miri, rust-analyzer, vacuity).
  • agent-plugin/scripts/ (Python 3 only, JSON output):
    • summarize-results.py: a compact summary of an RFC 0015 export.
    • check-vacuity.py: unreachable assertions and unsatisfiable covers.
    • check-assumptions.py: contradictory, pinned, or success-assuming kani::assume, and requires(false).
    • inspect-harness.py: harness structure.
    • check-kani-version.py: checks the installed Kani against the plugin's supported range.
  • Proof-integrity checks, so an agent cannot get a green result by weakening the proof:
    • summarize-results.py (and kani_verify_harness) report weakened_checks (disabled checks, raw CBMC arguments) and, per harness, the stubs and stub_verified contracts the result relies on.
    • check-specs.py checks specs with Kani itself, in a temporary copy of the crate: is the end of each harness reachable, are contract preconditions satisfiable, does a clause constrain nothing, and is a changed precondition stronger or weaker than the baseline's. A check that cannot run is reported as unchecked, never as passing.
    • check-proof-diff.py compares harnesses, contracts, and code with the baseline the user approved. It flags removed assertions or covers, new assumptions, stubs, should_panic, lower unwind bounds, changed contracts, and any change to the code under verification.
    • check-witness.py confirms a defect (its concrete playback witness fails) or a fix (the witness fails before the fix and passes after).
    • evidence.py records the run behind a reported result, and re-checks it later.
    • The skill pins the agreed property, forbids silent code changes, and requires evidence for every claim. A new strategy.md reference covers when to write one harness and when to prove contracts bottom-up along the call graph, which comes from rust-analyzer's call hierarchy.
  • tools/kani-mcp: a minimal MCP server, stdio only, with no new dependencies. It has four tools: kani_get_version, kani_list_harnesses, kani_verify_harness, and kani_get_counterexample. It shells out to the user's installed Kani. MCP is optional: the skill falls back to the CLI, which covers every feature, including AutoHarness.
  • Compatibility: the plugin is versioned on its own. compatibility.json says plugin 0.1.0 supports Kani >= 0.68.0, < 1.0.0; 0.68.0 is the first release with --export-json. Both the script and the MCP tool enforce this range.

Testing

  • agent-plugin/tests/validate_plugin.py checks manifests, skill frontmatter, and links.
  • agent-plugin/tests/test_scripts.py has 65 unit tests over the existing RFC 0015 fixtures and Rust samples, and needs no Kani.
  • cargo test -p kani-mcp runs 22 unit tests.
    • The three items above run in a new path-filtered Agent Plugin workflow.
  • The new agent-plugin exec suite in kani-regression.sh runs end to end against a fixture crate with one good proof, one real overflow, and one vacuous proof. It checks:
    • version detection, including a clear error for an old or missing Kani;
    • the CLI-only workflow: JSON summary, concrete playback, vacuity and assumption checks, and AutoHarness through the CLI;
    • all four MCP tools over stdio, including that kani_verify_harness matches summarize-results.py;
    • proof integrity: Kani-backed spec checks catch a vacuous harness and an unsatisfiable precondition; the proof diff catches a cheating edit; a witness confirms the defect and then the fix; an evidence bundle re-verifies and detects a changed source.
  • Manual testing: drove kani-mcp over stdio by hand on sample files. The suite passes locally through compiletest on macOS.

Field testing

A trial run on two real crates found one real defect in each, and a list of false results and usability problems in the scripts and MCP server. All of them are fixed in this PR:

  • multi-line contract attributes are parsed;
  • assumptions in helper functions count toward the harness;
  • built-in checks are no longer reported as vacuous user assertions;
  • contracts on methods are checked;
  • witnesses work when a crate's test targets don't build under cfg(kani), and failures caused only by stubs are reported as spurious;
  • evidence covers every source file;
  • the MCP tools have timeouts, progress notifications, parallel jobs, and export/log paths, and listing returns a summary by default;
  • the version check verifies that the toolchain works.

A second round on three crates confirmed most of those fixes and found more, now also fixed:

  • the plugin no longer lets rustup install a toolchain a project pins (it pins RUSTUP_TOOLCHAIN to an installed toolchain and disables auto-install);
  • unreachable checks are classified by location;
  • a witness only confirms a defect when it panics with the failure Kani reported;
  • the proof diff catches a harness that loses #[kani::proof] and resolves helpers by path;
  • work copies keep external path dependencies resolvable;
  • MCP timeouts return the harnesses that finished.

A third round, on AutoHarness and coverage, added:

  • a kani_autoharness MCP tool (list-only mode, timeouts, partial results, automatic and manual harnesses reported separately);
  • summarize-coverage.py, which merges source coverage across harnesses and lists the regions no harness exercises;
  • reference docs for AutoHarness pitfalls (manual harnesses always run, a default unwind bound of 20, -Z stubbing, no concrete playback) and for coverage.

The latest round makes the plugin contract-first and works through a list of issues found on 87 public crates:

  • the Crate Verifiability Map and its plan steer toward function contracts, loop invariants with decreases clauses, and AutoHarness verifying the contracts bottom-up; AutoHarness results count as evidence;
  • MCP tools for the map (kani_map_crate, kani_plan_verification, kani_update_verification_map, kani_explain_function), plus per_harness runs and a memory limit;
  • new scripts list-harnesses.py, run-harnesses.py (results kept as each harness finishes), and cleanup-playback.py;
  • fixes for harness filters, noisy vacuity output, timeout and out-of-memory reporting, coverage scope, witness replay in no_std crates, and evidence change detection.

Not done yet

  • End-to-end sessions in real agents (Kiro, Claude Code).
  • Review against prior art (KVerus, ExVerus).
  • Marketplace-specific manifests and submissions.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

- agent-plugin/: plugin manifest, MCP registration, compatibility.json
  (plugin 0.1.0 supports Kani >= 0.68.0, < 1.0.0), the verify-rust skill,
  and references for Kani, AutoHarness, contracts, Miri, rust-analyzer, and
  vacuity.
- Scripts: summarize-results.py (compact --export-json summary),
  check-vacuity.py, check-assumptions.py, inspect-harness.py, and
  check-kani-version.py.
- tools/kani-mcp: a minimal stdio-only MCP server with kani_get_version,
  kani_list_harnesses, kani_verify_harness, and kani_get_counterexample.
  It shells out to the installed Kani. MCP is optional; the skill falls
  back to the CLI.
- Tests: Kani-free unit tests and a metadata validator (new Agent Plugin
  workflow), plus an `agent-plugin exec` suite in kani-regression.sh that
  runs the workflow end to end against a fixture crate, with and without
  MCP.
@feliperodri
feliperodri requested a balanced review from Copilot October 23, 2026 20:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

No open issues 🎉

What changed in this PR

Adds a Kani agent plugin plus a minimal MCP server (kani-mcp) to make Kani verification workflows accessible to coding agents, with helper scripts and CI/smoke tests to validate behavior and compatibility.

Changes:

  • Introduces kani-mcp (stdio JSON-RPC/MCP server) with tools for version, harness listing, verification summaries, and counterexamples.
  • Adds Python helper scripts and tests for summarizing --export-json, vacuity/assumption checks, and plugin metadata validation.
  • Adds CI workflow + regression suite hooks and end-to-end smoke tests for CLI fallback and MCP tool parity.
File Description
tools/​kani-mcp/​src/​summary.rs Rust implementation of compact RFC0015 export summary (mirrors Python script) + unit test fixture coverage
tools/​kani-mcp/​src/​main.rs MCP stdio server implementing kani_get_version, kani_list_harnesses, kani_verify_harness, kani_get_counterexample
tools/​kani-mcp/​Cargo.toml New kani-mcp crate definition and dependencies
Cargo.toml Adds tools/kani-mcp to workspace members
tests/​agent-plugin/​version-check/​test.sh Smoke test for version enforcement and error clarity
tests/​agent-plugin/​version-check/​config.yml Registers version-check smoke test
tests/​agent-plugin/​mcp/​test.sh End-to-end MCP tool exercise + parity check vs CLI summary
tests/​agent-plugin/​mcp/​config.yml Registers MCP smoke test
tests/​agent-plugin/​cli-fallback/​test.sh End-to-end skill workflow through CLI-only (export, summary, vacuity/assumptions, playback, autoharness)
tests/​agent-plugin/​cli-fallback/​config.yml Registers CLI-fallback smoke test
scripts/​kani-regression.sh Adds agent-plugin exec suite to regression
.github/​workflows/​agent-plugin.yml New path-filtered workflow to validate plugin + run unit tests
agent-plugin/​plugin.json Plugin manifest (name/version/paths/metadata)
agent-plugin/​mcp.json Registers local stdio MCP server command (kani-mcp)
agent-plugin/​compatibility.json Supported Kani range + required unstable features
agent-plugin/​README.md Plugin documentation, installation, tools/scripts overview
agent-plugin/​tests/​validate_plugin.py Validation for manifests, versions, skill frontmatter, and reference/script presence
agent-plugin/​tests/​test_scripts.py Unit tests for Python scripts using JSON fixtures + Rust source fixtures
agent-plugin/​tests/​smoke-lib.sh Shared harness for smoke tests (temp fixture crate, build kani-mcp, helpers)
agent-plugin/​tests/​mcp_client.py Minimal MCP stdio client used by smoke tests
agent-plugin/​tests/​fixtures/​rust/​assumptions.rs Rust text fixture for assumption scanner tests
agent-plugin/​tests/​fixtures/​crate/​Cargo.toml Fixture crate used by end-to-end smoke tests
agent-plugin/​tests/​fixtures/​crate/​src/​lib.rs Fixture crate code + proof harnesses (good/failing/vacuous)
agent-plugin/​scripts/​kani_plugin_lib.py Shared text-scanning utilities for plugin scripts
agent-plugin/​scripts/​summarize-results.py Python compact summary implementation of RFC0015 export
agent-plugin/​scripts/​check-vacuity.py Python vacuity checker over RFC0015 export
agent-plugin/​scripts/​check-assumptions.py Python assumption checker over Rust source text
agent-plugin/​scripts/​check-kani-version.py Python Kani version-range validator
agent-plugin/​scripts/​inspect-harness.py Python harness structure inspector
agent-plugin/​skills/​verify-rust/​SKILL.md Skill orchestration workflow/policy for agents
agent-plugin/​skills/​verify-rust/​references/​kani.md Reference guidance for harness writing/running Kani
agent-plugin/​skills/​verify-rust/​references/​vacuity.md Reference guidance for vacuity/sanity checks
agent-plugin/​skills/​verify-rust/​references/​contracts.md Reference guidance for contracts
agent-plugin/​skills/​verify-rust/​references/​autoharness.md Reference guidance for autoharness usage
agent-plugin/​skills/​verify-rust/​references/​miri.md Reference guidance for Miri complementing Kani
agent-plugin/​skills/​verify-rust/​references/​rust-analyzer.md Reference guidance for using rust-analyzer in verification workflows

Review effort: Lite

@github-actions github-actions Bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Oct 23, 2026
Make it hard for an agent to get a green result by weakening the proof:

- summarize-results.py and kani_verify_harness report `weakened_checks`
  (disabled checks, raw CBMC arguments) and, per harness, the stubs and
  stub_verified contracts the result relies on.
- check-specs.py checks specifications with Kani itself, in a temporary
  copy of the crate: harness end reachable, preconditions satisfiable,
  clauses that constrain nothing, and whether a changed precondition is
  stronger or weaker than a baseline. Checks that cannot run are reported
  as unchecked, never as passing.
- check-proof-diff.py compares harnesses, contracts, and code with a
  pinned baseline and flags removed assertions or covers, new assumptions,
  stubs, should_panic, lower unwind bounds, changed contracts, and any
  change to the code under verification.
- check-witness.py confirms a defect (its concrete playback witness fails)
  or a fix (the witness fails before and passes after).
- evidence.py records the run behind a reported result and re-checks it.
- The verify-rust skill pins the agreed property, forbids silent code
  changes, requires evidence for every claim, and gains a strategy
  reference (one harness for small targets, contracts bottom-up along the
  call graph from rust-analyzer's call hierarchy for larger ones).
- kani_list_harnesses accepts extra_args, so crates with contracts can be
  listed with -Z function-contracts.
- New proof-integrity smoke test; more unit tests.
Parsing and proof diff:
- Walk back over attributes by matching brackets, so multi-line
  attributes such as `kani::ensures(|r| { ... })` are seen.
- Count assumptions, inputs, and assertions in the Kani-only helpers a
  harness calls (and its stub replacements); list a new harness's
  assumptions; treat files included through `#[cfg(kani)] mod x;` as
  Kani-only; normalize multi-line attribute arguments.
- Loose files are no longer attributed to an enclosing package.

Checks:
- check-vacuity.py: without descriptions, unreachable assertion-class
  checks are warnings (they may be built-in checks the solver folded
  away); `--log` classifies them from Kani's console output.
- check-specs.py: check contracts on methods and associated functions
  through generated predicates in an inherent impl; accept
  `--kani-arg -Z`; keep the crate copy in target/ so dependencies are
  built once; report `harness-fails` for failing harnesses.
- check-witness.py: `--cargo-arg` pass-through, retry with `--lib` when
  test targets do not build under cfg(kani), and report witnesses of
  stubbed harnesses that pass on the real code as spurious.
- evidence.py: hash every package source and the workspace manifests,
  resolve workspace-relative export paths, record a hash of `git diff`
  and of untracked files.
- check-kani-version.py and kani_get_version verify a trivial harness,
  so a missing CBMC or goto-cc is reported up front.
- inspect-harness.py: `--summary`, `--flagged-only`, and `--list-json`
  to report harnesses the scan cannot see (macro-generated).

kani-mcp:
- `timeout_s` (default 1800 s; kills Kani's process group),
  `harness_timeout_s`, `jobs`, `export_path`, `log_path`, and MCP
  progress notifications; return the command line for evidence.
- kani_get_counterexample separates failure and cover witnesses, names
  omitted ones, and warns that playback ignores stubs.
- kani_list_harnesses returns a summary by default, with `filter`.

Docs: re-snapshot the baseline once a harness is approved, bound every
run, --jobs requires terse output, playback ignores stubs, rustup
auto-installs pinned toolchains, and drop glue/recursion performance.

Tests: smoke tests must end with smoke_pass, so a script that stops
early fails; new unit and smoke tests for every fix.
Toolchain:
- The scripts and kani-mcp run Kani with RUSTUP_TOOLCHAIN pinned to an
  installed toolchain (Kani's own, else rustup's default) and
  RUSTUP_AUTO_INSTALL=0. rustup's cargo proxy otherwise installs the
  toolchain a project pins in rust-toolchain.toml before Kani starts.
  kani_get_version and check-kani-version.py print the `cli_env` to use
  for direct CLI runs.

Checks:
- check-vacuity.py: parse property names with spaces; classify by
  location: assertions in the harness are errors, in callees or
  contracts warnings, in Kani or std library code info.
- check-witness.py: a defect is reproduced only when the replay panics
  with the reported failure (`different-failure` otherwise); leftover
  concrete values mean spurious; when the crate's tests do not build
  under cfg(kani), replay in a copy without them; keep the doc comment
  of the witness.
- check-proof-diff.py: flag a harness that loses #[kani::proof];
  resolve helpers by path (never into kani/std, never method calls);
  treat any_where predicates as assumptions; describe an added ensures
  as added; cfg(kani) impl blocks are Kani-only.
- check-specs.py and check-witness.py: mirror external path
  dependencies in their work copies.
- evidence.py: hash untracked files correctly; warn when sources
  changed after the Kani run started.
- inspect-harness.py: recognize any_array and Type::any() generators;
  flag harnesses with branches and fewer than two covers.

kani-mcp:
- On timeout, return the harnesses that finished, read from Kani's
  output.
- Counterexample note handles TIMEOUT/OUT_OF_MEMORY verdicts.
- kani_list_harnesses drops --target-dir, which `kani list` rejects,
  and checks contracts without harnesses against proof_for_contract
  targets in the source.

Docs: toolchain pinning for CLI runs, covers in every harness branch,
witness verdicts, inplace playback in workspace members.
- kani-mcp: new kani_autoharness tool. It validates patterns (Kani rejects
  spaces), supports timeout_s, harness_timeout_s, export_path, and
  log_path, returns the harnesses that finished when the run is cut off,
  splits results into automatic and manual harnesses, and warns that
  AutoHarness runs every manual harness with a default unwind bound of 20
  (kani#5103). With list_only it reports the selected functions and the
  skipped ones grouped by reason, without leaving kani-list.json behind.
- summarize-coverage.py: merge source coverage across harnesses (a region
  is covered if any harness covers it) and list the uncovered regions per
  file; it reads the raw per-harness files, so it avoids kani-cov summary
  (kani#5102). --compare shows what changed between two sets of runs.
- references/autoharness.md: list first; manual harnesses always run;
  the default unwind bound; -Z stubbing; patterns cannot contain spaces;
  no concrete playback; a killed run writes no export; HashMap ICE.
- references/coverage.md and the skill: use coverage to find dead code and
  gaps in the proofs, and classify each uncovered region.
- Tests: unit tests for the coverage merge and the autoharness table and
  output parsers; smoke tests for kani_autoharness and the coverage flow.
This was referenced Nov 6, 2026
A planning aid for choosing what to verify and in which order. map-crate.py
joins cargo metadata, a call graph, the plugin's source scan, and Kani
results into a deterministic, versioned JSON map, and plans bottom-up.

- Call graph from cargo-callgraph when installed (an optional external
  program, never bundled: it is AGPL-3.0), otherwise a labeled text-scan
  approximation. Every edge records how it was resolved; dynamic dispatch,
  name-matched calls, and external calls are never treated as exact.
- Strongly connected components (direct and mutual recursion) and levels.
- Harness index with the functions each harness targets and provably
  reaches, through resolved edges and not through stubs.
- Per-function status: verified, conditional, failed, inconclusive,
  unsupported, stale, not_attempted, with the evidence, configuration, and
  caveats behind it. Freshness uses evidence-bundle hashes or run times.
  A function is never verified through an unverified callee, stub, or
  assumed contract.
- Strategy and priority heuristic (documented, not a predictor), staged
  plan with goals, update (refuses when sources changed), explain, and a
  Mermaid report.
- The five metrics of the proposed `cargo kani complexity` command are
  reserved in every function as `not_computed`; the map defines no
  complexity metric itself.
- Design document (implemented vs proposed), JSON schema, reference doc and
  skill steps.
- Tests: unit tests on a two-crate fixture workspace covering loops,
  recursion, generics, trait dispatch, macros, features, contracts, and
  failed, inconclusive, unsupported, stale, and conditional results; a smoke
  test that runs real Kani and builds the map with both call-graph sources.
Contract-first (the plugin's default method):
- The Crate Verifiability Map steers toward function contracts, loop
  invariants with decreases clauses, #[kani::recursion] for recursive
  groups, and AutoHarness verifying the contracts bottom-up; callers rely
  on verified contracts (stub_verified). Strategies: write-contract-then-
  autoharness, verify-contract-with-autoharness, loop-contract,
  add-loop-decreases, contract-and-recursion.
- Per function: contract_status, loop invariant/decreases signals,
  partial-termination uncertainty, and a caveat when a loop without an
  invariant is only checked within the unwind bound.
- AutoHarness-generated harnesses (not in the source) are read from the
  results and count as evidence for their functions.
- Plan stages carry the workflow steps and the AutoHarness command
  (include patterns, CLI, MCP call), and the plan reports contract progress.
- MCP tools kani_map_crate, kani_plan_verification,
  kani_update_verification_map, kani_explain_function.
- Skill, strategy, contracts (loop contracts, decreases, historic values),
  AutoHarness and map references rewritten around it.

Fixes from the issue list:
- list-harnesses.py, run-harnesses.py (one process per harness, timeouts,
  memory cap, results kept as they finish), cleanup-playback.py.
- Harness filters accept module-qualified names and fail loudly; helper
  scans skip hidden and plugin directories; cfg(any(kani, ..)) is Kani-only.
- summarize-results: inconclusive counts, always-present keys, unsupported
  constructs, log diagnosis of timeouts and OOM, clear missing-export error.
- check-vacuity: info counted, library properties, should_panic, uniform keys.
- summarize-coverage: crate-only, instances merged, corrupt files skipped,
  files never reached, scope stated.
- check-witness: no_std imports, deny(warnings) relaxed, failure classes,
  aborts, --lib first, root-relative baselines, per-copy target dirs.
- check-proof-diff: new-harness stubs, macro invocations, --allow-code-change,
  changed-files-only. evidence.py: snapshots, --log, output directory.
- check-specs: --features, --harness-timeout, work dir excluded from copy.
- kani-mcp: memory_limit_mb, per_harness, default export under the plugin
  output directory, compiler errors surfaced, list/option handling, caps.
A source build puts the binary in <checkout>/target/kani/bin, so the
rust-toolchain.toml is four levels up, not two. Search every ancestor and stop
at the first file, in the scripts and in kani-mcp.
…--export-json

Kani 0.68.0 and older source builds gate --export-json behind -Z unstable-options
and reject -Z export-json; builds since the RFC 0015 export (model-checking#4941) require
-Z export-json and reject -Z unstable-options alone. Probe once with
`kani -Z export-json --version` (Kani validates -Z values before it acts on
--version), cache the answer, and use it in every script, in kani-mcp, in the plan's
AutoHarness command, and when replaying recorded commands. check-kani-version.py
prints export_flags. KANI_PLUGIN_EXPORT_FLAG overrides the probe.
Kani 0.68.0 and older builds write a tree (harness_metadata, verification_results,
property_details); Kani since model-checking#4941 writes a flat document (harnesses, configuration).
The plugin read only the flat one, so a passing run on the older Kani summarized as
0 harnesses and all_ok false.

One reader per language (scripts/kani_export.py, tools/kani-mcp/src/export.rs) converts the
tree to the flat shape and is used by summarize-results, check-vacuity, check-specs,
evidence, run-harnesses, the Crate Verifiability Map and every kani-mcp tool. What the tree
does not record is marked: the run configuration (summaries say weakened checks cannot be
detected from the export), and stubs, which are read from the harness attributes in the
source (stubs_source: source-scan, autoharness-generated, or unknown). The source is
accepted only if the harness fn is where the export says.

check-kani-version.py and kani_get_version now read the export of a trivial run and fail
when it cannot be understood. Tests hold one crate's export in both shapes and check that the
answers agree; a smoke test does the same against the Kani under test.
CBMC can use all the memory of a machine, and the kill took the calling shell or agent with
it. Memory limits existed only in the MCP tools (polling every two seconds), and agents run
Kani from the shell.

kani_run.py (scripts) and process.rs (kani-mcp) run Kani in its own systemd scope
(systemd-run --user --scope -p MemoryMax=.. -p MemorySwapMax=0) where that works, so the
kernel kills only that run and memory.peak and cpu.stat give its real peak and CPU time;
elsewhere the process group is watched and killed above the cap (RLIMIT_AS is not used:
Rust and CBMC reserve far more address space than they use). The cap is --memory-limit-mb /
memory_limit_mb, else KANI_PLUGIN_MEMORY_MB, else half of the memory available to the
process (the smaller of the machine's and its cgroup's limit).

A stopped run writes an export (run_state KILLED or TIMEOUT, the harnesses that finished,
the one that was running, elapsed time and peak); a completed run gets its peak and CPU
added (plugin_run). Summaries say 'killed: memory (peak .., limit ..) after ..s'.

New guarded-run.py wraps any command for agents that run Kani from the shell. run-harnesses,
check-specs and evidence verify use the guard; summarize-results and kani-mcp report it.
Add -p OOMPolicy=continue to the systemd scope (scripts and kani-mcp), so the kernel kills
only the largest process and the wrapper survives to read memory.peak and memory.events.
Exit 137 or 143, or oom_kill > 0, now counts as 'killed: memory'. guarded-run.py no longer
prints 'cpu Nones' when the CPU time is unknown.
- Add the copyright header to the export-probe fixture's Cargo.toml.
- kani-mcp: name the systemd scope and kill it by name (systemctl --user kill) as well as the
  process group, and stop waiting for the output pipes 3 s after a kill, so a process that
  escaped the kill cannot hold a stopped run for its whole lifetime (kills_on_timeout took 30 s
  on the runner). Same in kani_run.py.
- test_compat: the evidence test no longer depends on checkout mtimes (a fresh checkout is newer
  than the fixture's start time, which evidence.py reports with exit status 2).
…meout

kani autoharness defaults to a 60 s harness timeout. On the loaded macos-15-intel runner (the smoke
tests run in parallel with the memory guard test) the total_zero contract proof timed out, failed
the run, and cancelled the other jobs of the matrix.
Two runs started in parallel threads could read the same counter value and name their systemd
scopes alike; the second systemd-run then failed with status 1 (captures_output_and_exit_code on
the CI runner).
wodex1nhaoIeng pushed a commit to wodex1nhaoIeng/kani that referenced this pull request Nov 10, 2026
model-checking#5062)

Resolves model-checking#4983. Part of model-checking#942 (RFC 0015, model-checking#4727). Follows model-checking#4941.

## Description

RFC 0015 says an earlier `--export-json` file is replaced by an
`INCOMPLETE` marker when verification
begins. Without it, a run that is killed during verification leaves the
earlier `COMPLETE` document in
place, and that document looks current (see the
[model-checking#4941
review](model-checking#4941 (comment))).

- After the build and harness selection succeed, Kani builds the run
context once and writes the
marker with the same atomic write as the final document. After
verification, the final document
from the same context replaces it, so `started_at` and the other shared
fields are equal in both.
- The marker has the fields of the RFC presence matrix and `run_state:
"INCOMPLETE"`, and no
  `outcome`, `wall_time_s`, `summary` or `harnesses`.
- A failed marker write stops the run before any harness is verified. A
build error or a rejected
harness selection (a filter that matches nothing) leaves an earlier file
in place.
- `wall_time_s` now also covers the tool version probes and the marker
write. The build is still not
  included.

This implements the marker that the RFC proposes. The RFC's open
question "marker or delete-up-front"
is unchanged; the flag stays unstable. The docs and the RFC text are
updated to match.

Readers of the export should treat a `run_state` other than `COMPLETE`
as incomplete evidence. For example,
kani-mcp in model-checking#5059 deletes any earlier export before a run and reports a
timeout only when no export exists.
With this change, a run that stops after the marker write leaves an
`INCOMPLETE` export, so the existence of
the file alone does not show that verification finished.

## Testing

- Unit tests: the marker's exact key set, and null metadata serialized
as null; a marker and a final
  document from one context have equal shared fields.
- `tests/json-handler/incomplete-marker` runs the real driver with a
fake `cbmc` that waits for a
release file. Killing the driver leaves the marker; releasing it gives a
final document with the
marker's `started_at`; a bad export path and a rejected `--harness`
filter stop the run before
  CBMC verification starts.
- Each of these mutations makes a test fail: the marker written after
verification, the marker
written before harness selection, a marker write error ignored,
`summary: null` in the marker, and
  a recomputed `started_at`.
- Full regression, `cargo clippy` and `cargo fmt --check` pass at
1b6fefa.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
@feliperodri feliperodri self-assigned this Nov 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Z-Autoharness Issue related to autoharness subcommand Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants