Skip to content

Fix debug assertion in determine_targets for autoharness with --harness - #5063

Merged
feliperodri merged 3 commits into
model-checking:mainfrom
ivmat:fix-autoharness-harness-debug-assert
Nov 13, 2026
Merged

feliperodri merged 3 commits into
model-checking:mainfrom
ivmat:fix-autoharness-harness-debug-assert

Conversation

@ivmat

@ivmat ivmat commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

In debug builds, kani autoharness -Z autoharness <file> --harness <name> panics in
KaniSession::determine_targets when autoharness generates at least one automatic harness.
The debug check re-filters the harnesses that the compiler kept with find_proof_harnesses
and asserts that both lists are equal. The compiler filters only manual harnesses and keeps
every automatic harness, but find_proof_harnesses skips automatic harnesses. So the lists
differ.

This change makes the debug check compare only the manual harnesses of the compiler list
with their re-filtered list. The check still detects retained manual harnesses that do not
satisfy the filter. It does not check the selection of automatic harnesses. Release builds do
not run this check and are not changed.

Resolves #4939

Testing

  • New test tests/script-based-pre/autoharness_harness_filter, on a file with two manual
    harnesses and one function that autoharness selects:

    • --harness manual_selected: exit code 0, no panic, one verified manual harness and one
      verified automatic harness; the line Checking harness manual_selected... is present and
      the line Checking harness manual_other... is absent.
    • --harness nomatch: a non-zero exit code, no panic, and the usual
      Failed to match the following harness(es): error.

    Both cases panic on the unfixed debug build. The test passes with the change.

  • A temporary change that makes the debug check use a wrong filter makes the test fail with the
    assertion, so the check is still active for retained manual harnesses.

  • scripts/kani-regression.sh (which includes scripts/kani-fmt.sh --check and the debug build),
    both CI clippy commands, and the copyright check pass.

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

…rness`

The debug build of `kani-driver` re-filters the harnesses that the compiler
kept and asserts that both lists are equal. The compiler filters only manual
harnesses and keeps every automatic harness. `find_proof_harnesses` skips
automatic harnesses. So the assertion failed, and the driver panicked, for
every `kani autoharness --harness <name>` run that generates at least one
automatic harness.

Compare only the manual harnesses in the debug check. The check still detects
retained manual harnesses that do not satisfy the filter. Add a regression
test.

Resolves model-checking#4939
@ivmat
ivmat requested review from a team as code owners October 25, 2026 12:52
@feliperodri feliperodri added [C] Bug This is a bug. Something isn't working. [F] Crash Kani crashed Z-Autoharness Issue related to autoharness subcommand labels Nov 6, 2026
@feliperodri feliperodri added this to the Autoharness milestone Nov 6, 2026
@feliperodri

Copy link
Copy Markdown
Member

@acearyanarun @CYJ904 @Tianshu-Huang @wodex1nhaoIeng @srivatsansamraj, could you review this PR?

@feliperodri
feliperodri requested a balanced review from Copilot November 6, 2026 18:59
@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

Fixes a debug-build panic in KaniSession::determine_targets when using kani autoharness with a --harness filter by ensuring the debug assertion compares only manual harnesses (since automatic harnesses are intentionally retained by the compiler but skipped by find_proof_harnesses).

Changes:

  • Update the debug assertion in kani-driver to re-filter and compare only manual harnesses.
  • Add a new script-based-pre regression test covering kani autoharness ... --harness <name> with both manual and automatic harnesses.
File Description
kani-driver/​src/​metadata.rs Adjusts debug-only verification to compare filtered manual harnesses only, preventing a false assertion failure.
tests/​script-based-pre/​autoharness_harness_filter/​harness_filter.sh Adds a regression script validating no panic and correct harness selection behavior.
tests/​script-based-pre/​autoharness_harness_filter/​harness_filter.expected Defines the expected success output for the new regression test.
tests/​script-based-pre/​autoharness_harness_filter/​fixture.rs Provides a fixture with two manual harnesses and one autoharness-selected function.
tests/​script-based-pre/​autoharness_harness_filter/​config.yml Registers the new script-based-pre test.

Review effort: Lite

Comment thread kani-driver/src/metadata.rs Resolved

@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 fix is right: the debug check compared lists that could never match for automatic harnesses. Narrowing it to manual harnesses keeps the check where it can hold, and release builds are unchanged.

Before merge:

  1. The test's manual_other assertion matches anywhere in the output, including harness lists. Match the execution line instead.
  2. The code comment should say that automatic harness selection is not checked by this assertion.
  3. Nit: the clone() could go if find_proof_harnesses took a slice.
  4. Three macOS jobs are cancelled. Please re-run them.

@feliperodri feliperodri assigned ivmat and unassigned feliperodri Nov 7, 2026
ivmat added 2 commits November 8, 2026 23:33
Match the `Checking harness manual_other...` line in the regression test, so
that a harness list that names `manual_other` does not fail the test. State
in the comment that the debug check does not cover automatic harness
selection. Pass the manual harnesses by reference instead of cloning them;
`find_proof_harnesses` already accepts any iterator of harness references.
Issue model-checking#4939 also reports the panic for a filter that matches nothing. Add
that case to the regression test: the run must fail with the no-match error
and must not panic. Match the summary lines as fixed strings.
@ivmat

ivmat commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Fixed in 38c81ab and 74ea9db:

  1. The test matches Checking harness manual_other... instead of the bare name.
  2. The comment says the check does not cover automatic harness selection.
  3. The clone() is removed; find_proof_harnesses already accepts &manual_harnesses through its generic bound.

The test also covers the issue's --harness nomatch case.

@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 @ivmat, this addresses everything from my last review: the test now checks Checking harness manual_other... rather than the bare name, the comment states what the assertion does not cover, and the clone() is gone.

I built the head as a debug build and ran the new test; it passes, and with the base metadata.rs it panics at the assertion from #4939, so the test covers the regression. I also tried --exact and a filter matching both manual harnesses; neither panics, and the right harnesses run.

Please ignore my earlier request to re-run the macOS jobs: macos-14 runners were retired, and #5138 moves those jobs to macos-15.

@feliperodri
feliperodri added this pull request to the merge queue Nov 13, 2026
Merged via the queue into model-checking:main with commit 948f8d2 Nov 13, 2026
22 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[C] Bug This is a bug. Something isn't working. [F] Crash Kani crashed Z-Autoharness Issue related to autoharness subcommand

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kani autoharness with --harness panics in determine_targets on debug builds

3 participants