Skip to content

Write the RFC 0015 INCOMPLETE marker before --export-json verification - #5062

Merged
feliperodri merged 2 commits into
model-checking:mainfrom
ivmat:export-json-rfc0015-incomplete-marker
Nov 9, 2026
Merged

feliperodri merged 2 commits into
model-checking:mainfrom
ivmat:export-json-rfc0015-incomplete-marker

Conversation

@ivmat

@ivmat ivmat commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Resolves #4983. Part of #942 (RFC 0015, #4727). Follows #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
#4941 review).

  • 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 #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.

RFC 0015 says an earlier --export-json file is replaced by an INCOMPLETE
marker when verification begins, so a killed run cannot leave an older
COMPLETE document that looks current. Kani now builds the run context
once after harness selection, writes the marker atomically, and then
replaces it with the terminal document from the same context. A failed
marker write stops the run before any harness is verified.

The new json-handler/incomplete-marker test blocks a fake cbmc, then
kills the driver (the marker stays) or releases it (the terminal
document keeps the marker's fields), and checks a bad export path and a
rejected harness filter.
@ivmat
ivmat requested review from a team as code owners October 25, 2026 08:23
@feliperodri
feliperodri requested a balanced review from Copilot November 6, 2026 18:57
@feliperodri feliperodri self-assigned this Nov 6, 2026

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

2 open issues
What changed in this PR

Implements RFC 0015 behavior where --export-json is atomically replaced with an INCOMPLETE marker before verification, preventing stale COMPLETE exports from appearing current after a killed run.

Changes:

  • Add begin_export_json() to write an INCOMPLETE marker and reuse a single run context for the terminal export.
  • Update driver flow to write the marker after harness selection and before verification, and adjust wall_time_s semantics accordingly.
  • Add integration + unit tests and update RFC/docs to describe the new marker behavior.
File Description
tests/​json-handler/​incomplete-marker/​test.sh Adds a test entrypoint that runs the integration script with resolved kani/cbmc paths.
tests/​json-handler/​incomplete-marker/​test.rs Adds a minimal proof harness for the integration test project.
tests/​json-handler/​incomplete-marker/​run.py Adds an end-to-end harness that verifies marker persistence on kill and replacement on completion.
tests/​json-handler/​incomplete-marker/​fake_cbmc.py Adds a fake CBMC wrapper that blocks until released to simulate in-verification interruption.
tests/​json-handler/​incomplete-marker/​config.yml Registers the new JSON-handler test.
rfc/​src/​rfcs/​0015-export-json.md Updates RFC 0015 text for marker behavior and revised wall_time_s definition.
kani-driver/​src/​main.rs Writes the marker context after harness selection and uses it for the terminal export.
kani-driver/​src/​frontend/​schema_utils.rs Introduces RunContext reuse, marker serialization, and updates export API/signatures + tests.
docs/​src/​verification-results.md Updates user docs to describe marker behavior and how to interpret incomplete exports.

Review effort: Lite

@feliperodri feliperodri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The design is right: the marker is written once, before verification, through the same atomic write, and the final document reuses its context. Killing the run leaves an honest INCOMPLETE.

Before merge:

  1. write_export_json silently returns Ok when ctx is None and --export-json is set. That hides a missed begin_export_json. Please make it an error or an assert.
  2. run.py discards stdout and stderr. Please keep the output and print it on failure.
  3. This is an RFC feature, so please add [C] Feature / Enhancement and a milestone.
  4. Please link this to #5059 (kani-mcp), which must treat a non-COMPLETE run_state as incomplete.

@feliperodri feliperodri assigned ivmat and unassigned feliperodri Nov 7, 2026
`write_export_json` returned `Ok` without writing when `--export-json` was
set but no run context was passed, so a missed `begin_export_json` call
went unnoticed. `begin_export_json` now returns a `PendingExport` that holds
the output path and the run context, and `write_export_json` takes one by
value. The only way to reach the terminal write is through the marker.

The incomplete-marker test now keeps the output of each Kani run: the
background runs write to log files, which are printed when an assertion
fails, and a run that times out reports its captured output.
@ivmat

ivmat commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Fixed in 03bd1ea:

  1. write_export_json now takes a PendingExport, which only begin_export_json returns, so a terminal write without the marker cannot be expressed.
  2. run.py keeps the output of each Kani run and prints it on failure, including timeouts.
  3. Setting labels and milestones needs triage rights, which this account does not have. Please add [C] Feature / Enhancement and a milestone as you see fit.
  4. Related: Add the Kani agent plugin: verify-rust skill, helper scripts, and kani-mcp #5059, which must treat a run_state other than COMPLETE as incomplete.

@feliperodri feliperodri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, PendingExport is a better fix than an assert: the final write can't happen without the marker. run.py keeps each run's output, and the PR body links #5059. I added [C] Feature / Enhancement, and I'm leaving the milestone off since none of the current ones fits machine-readable output.

@feliperodri feliperodri added the [C] Feature / Enhancement A new feature request or enhancement to an existing feature. label Nov 9, 2026
@feliperodri
feliperodri added this pull request to the merge queue Nov 9, 2026
Merged via the queue into model-checking:main with commit e08fef2 Nov 9, 2026
24 of 27 checks passed
feliperodri pushed a commit to feliperodri/kani that referenced this pull request Nov 13, 2026
Part of model-checking#942 (RFC 0015, model-checking#4727). Follows model-checking#5062 (the INCOMPLETE marker).
This PR changes only tests and the test helper
`scripts/validate_json_export.py`.

## Description

Adds end-to-end tests for `--export-json` and fixture-based tests for
two reading-rule helpers. The unit tests in `kani-driver` build their
inputs by hand; each suite below runs `kani` or `cargo kani` and covers
a path those unit tests do not reach. The end-to-end tests run `kani` or
`cargo kani` and check the exported documents or the rejected requests.
Only `structured-warnings` substitutes a CBMC wrapper, which injects
warnings or simulates non-completed outcomes. The gate-rejection and
no-harness cases do not reach verification.

New suites in `tests/json-handler/`:

- `additive-output`: checks that `--export-json` preserves exit status
and SARIF output for one passing and one failing harness, and preserves
stdout and per-harness `--output-into-files` output after masking
runtime and verification-time lines. The expected exit status and the
exported verdict are checked. `--export-json -` writes a file named `-`.
Covers the real stdout, SARIF and per-harness file writers running next
to the export.
- `autoharness-export`: `kani autoharness --bounded-arguments` exports
`is_automatically_generated` and `is_bounded` for each harness. Covers
the harness metadata that the autoharness pipeline passes to the export.
- `gate-rejections`: argument errors (a missing `-Z export-json`,
`--output-format=old`, `--only-codegen`, `--no-codegen`, `-Z lean`, a
directory as the target) are reported before compilation. A rejected
argument and a compilation error both leave an existing file or
directory at the target untouched. Covers the argument checks of the
real command line and their order relative to compilation.
- `jobs-ordering-stable`: checks that `harnesses[]` is sorted by
`(crate_name, file, line, name)` and matches between `--jobs 4` and
`--jobs 1` after excluding `resources.verification_time_s`. Covers the
order of real parallel and sequential runs.
- `live-configuration`: the precedence of unwind and solver settings,
`cbmc_args` kept verbatim, a bare `--smt2`, `--coverage` and the
check-flag toggles. For each solver case, the exported `resolved_solver`
is compared with the solver line that CBMC prints. Covers the
configuration of real runs, and the solver that CBMC actually runs.
- `multi-crate-export`: `cargo kani --workspace` writes one document,
and harnesses with the same name in two crates stay apart by
`crate_name`. Covers a real Cargo workspace.
- `no-harnesses-selected`: `run_state` is `NO_HARNESSES_SELECTED`, with
zero counts. Covers a real project without proof harnesses.
- `structured-warnings`: the caps and the exact text of `warnings[]`
records, the ERROR classification of an ignored quantifier, and the
CRASHED, TIMEOUT and OUT_OF_MEMORY shapes and elapsed times, against a
fake `cbmc`. Covers the handling of a real child process: its output
stream, a timeout kill, a crash exit and a kill signal.
- `vacuity-check`: the `vacuous_pass` and `vacuity_suspect` predicates
on live exports, including a partly vacuous harness, with and without
reach checks. Covers the reach checks that CBMC reports for real
harnesses.

Existing tests changed:

- `fail-fast`: also checks `harness_selection.matched_count`, and that
the run is `PARTIAL` when a selected harness was skipped and `COMPLETE`
when the abort lands on the last selected harness.
- `multiple-harnesses`: also checks `matched_count` and `run_state`.
- `schema-validation`: also tests the two new reading-rule helpers
(below) directly, on a new fixture, `fixture-completed-success.json`.

`scripts/validate_json_export.py` gains two helpers that implement the
vacuity reading rules of the RFC:
`vacuous_pass` and `vacuity_suspect`. `vacuity-check` imports them, and
`schema-validation`'s `check_fixtures.py` tests them on fixtures.

The branch merges `main` instead of rebasing, so its commit list
includes an earlier version of the model-checking#5062 commit. The diff against `main`
contains only the changes above.

## Testing

- `./scripts/kani-regression.sh` passed on Linux with CBMC 6.11.0,
including the 17 `tests/json-handler` tests, and the two `cargo clippy`
commands of the clippy CI job passed.
- Each assertion added after review was checked to fail when the
behaviour it covers is broken (a changed expectation, a changed fixture,
or an edited export document).
- Not run on macOS.

A record of which RFC 0015 clauses these tests assert, with the
mutations observed to turn a test red, is kept outside this PR:
https://github.com/ivmat/kani/tree/export-json-rfc0015-acceptance-2026-11/acceptance/rfc0015

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[C] Feature / Enhancement A new feature request or enhancement to an existing feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Write the RFC 0015 INCOMPLETE marker before verification

3 participants