Skip to content

Autoharness: configurable bounded-argument bounds, reported in the summary - #4793

Merged
feliperodri merged 3 commits into
model-checking:mainfrom
srivatsansamraj:autoharness-configurable-bounds
Sep 17, 2026
Merged

feliperodri merged 3 commits into
model-checking:mainfrom
srivatsansamraj:autoharness-configurable-bounds

Conversation

@srivatsansamraj

Copy link
Copy Markdown
Contributor

Description

--bounded-arguments generates slice, string and BoundedArbitrary values up
to fixed bounds of 16, 4 and 4. They were compile-time constants with no way to
override them, and the summary note did not state them, so a reader could not
tell what a bounded result actually covered.

This adds three options to the autoharness subcommand:

Option Applies to Default
--slice-bound &[T], &mut [T] 16
--string-bound &str, in bytes 4
--bounded-arbitrary-bound types implementing BoundedArbitrary 4

The defaults are unchanged, so a run that does not pass them behaves as before.

The summary note now names the values the run used:

Note: harnesses marked "(bounded)" use bounded nondeterministic values for some arguments (--bounded-arguments):
slices up to 16 elements, strings up to 4 bytes, and BoundedArbitrary values up to 4 elements.
Their verification results only hold up to those bounds, i.e., bugs that require larger input values may be missed.

A bound at or above the effective unwinding bound leaves loops over that
argument partially unwound, so the result no longer holds up to the bound that
was asked for. Kani warns when that happens:

warning: --slice-bound is 20, which is not below the unwinding bound (20). Loops iterating over such an argument may not be fully unwound, so verification results may not hold up to the bound.

Context

The three defaults move to kani_metadata as pub const. The driver prints
them and the compiler generates with them, so a copy in each crate would be free
to drift. AUTOHARNESS_BOUNDED_ANY_BOUND is renamed
AUTOHARNESS_BOUNDED_ARBITRARY_BOUND to match the new option and the trait it
refers to.

The driver passes the values to the compiler alongside
--autoharness-bounded-arguments. The compiler carries them on AnyModels
next to constructor_args, so call_kani_any_for_ty reads them where it
previously read the constants.

Three notes on scope:

  • Autoharness: make --bounded-arguments bounds configurable and surface them in the output #4751 names only the slice and string bounds. The BoundedArbitrary bound
    has the same reporting gap, so this makes it configurable as well.
  • The issue lists the interaction with --harness-timeout as a consideration.
    This change does not address it. A larger bound costs more solver time and can
    still exceed the default 60s harness timeout with no adjustment or warning.
  • The defaults themselves are untouched, so the question of what the optimum
    values are stays open.

Option names are open, as the issue notes. The subcommand's own options carry no
autoharness- prefix (c.f. --bounded-arguments) while the compiler flags do,
so these follow both conventions. Happy to rename.

Resolved issues

Resolves #4751

Testing

New test tests/script-based-pre/cargo_autoharness_bounds, one function per
bound. Each asserts that its argument never exceeds the bound and covers the
bound itself, run at --slice-bound 2 --string-bound 2 --bounded-arbitrary-bound 2. The assertions fail at the defaults, so the test
catches a bound that is ignored as well as one that is applied but never
reached. A first --list run at --slice-bound 20 exercises the warning
without verifying.

cargo_autoharness_slices and cargo_autoharness_bounded are updated for the
new note text, and confirm the defaults are unchanged.

Manual testing on x86_64 Linux:

  • cargo build-dev, cargo fmt --check
  • cargo clippy --workspace --tests -- -D warnings, and the same with
    RUSTFLAGS="--cfg=kani_sysroot"
  • cargo test -p kani_metadata -p kani-driver
  • the three script tests above, via cargo run -p compiletest -- --suite script-based-pre --mode exec

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

…mmary

The bounds that --bounded-arguments generates slice, string and
BoundedArbitrary values with were fixed constants, and the summary note
did not state them, so a reader could not tell what a bounded result
covered.

Add --slice-bound, --string-bound and --bounded-arbitrary-bound,
defaulting to the current 16/4/4. The defaults move to kani_metadata so
that the driver, which prints them, and the compiler, which generates
with them, share one definition. The summary note now names the values a
run used, and Kani warns when a bound is not below the effective
unwinding bound.

Resolves model-checking#4751
@srivatsansamraj
srivatsansamraj requested review from a team as code owners September 14, 2026 19:37
@srivatsansamraj

Copy link
Copy Markdown
Contributor Author

@Tianshu-Huang @acearyanarun @CYJ904 @wodex1nhaoIeng

This is the fix for #4751. Feel free to take a look and verify when you get a chance.

@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 Sep 14, 2026
@feliperodri feliperodri added the Z-Autoharness Issue related to autoharness subcommand label Sep 15, 2026
@feliperodri feliperodri added this to the Autoharness milestone Sep 15, 2026
@feliperodri feliperodri self-assigned this Sep 15, 2026
@feliperodri
feliperodri requested a balanced review from Copilot September 15, 2026 15:50

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.

🟡 Changes recommended

Bound options can be silently ignored, unwind warnings can use the wrong effective value, and the summary misstates BoundedArbitrary semantics.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Adds configurable bounded-argument limits for autoharness, addressing #4751 by threading bounds through the driver/compiler and reporting them to users.

Changes:

  • Adds slice, string, and BoundedArbitrary bound options.
  • Warns when bounds reach the configured unwind limit.
  • Updates documentation and regression tests for custom/default bounds.
File summaries
File Description
tests/script-based-pre/cargo_autoharness_slices/src/lib.rs Clarifies default slice/string bounds.
tests/script-based-pre/cargo_autoharness_slices/slices.expected Updates the summary expectation.
tests/script-based-pre/cargo_autoharness_bounds/src/lib.rs Tests all configurable bounds.
tests/script-based-pre/cargo_autoharness_bounds/config.yml Registers the new script test.
tests/script-based-pre/cargo_autoharness_bounds/Cargo.toml Defines the test crate.
tests/script-based-pre/cargo_autoharness_bounds/bounds.sh Exercises warnings and custom bounds.
tests/script-based-pre/cargo_autoharness_bounds/bounds.expected Captures expected bound behavior.
tests/script-based-pre/cargo_autoharness_bounded/src/lib.rs Updates the renamed default constant.
tests/script-based-pre/cargo_autoharness_bounded/bounded.expected Updates bounded summary output.
kani-driver/src/session.rs Stores bounds in driver sessions.
kani-driver/src/autoharness/mod.rs Passes, warns about, and reports bounds.
kani-driver/src/args/autoharness_args.rs Defines the new CLI options and bound structure.
kani-compiler/src/kani_middle/transform/automatic.rs Applies configured bounds during generation.
kani-compiler/src/args.rs Accepts compiler-side bound flags.
kani_metadata/src/lib.rs Centralizes shared default constants.
docs/src/reference/experimental/autoharness.md Documents configuration and warnings.
Review details

Suppressed comments (2)

kani-driver/src/args/autoharness_args.rs:43

  • An explicitly supplied --string-bound has no effect without --bounded-arguments, but the parser accepts it without warning and bounded string harnesses remain skipped. Declare the dependency so this configuration fails clearly instead of being silently ignored.
    #[arg(long, default_value_t = AUTOHARNESS_STR_BOUND, value_name = "N")]

kani-driver/src/args/autoharness_args.rs:49

  • An explicitly supplied --bounded-arbitrary-bound is likewise accepted but discarded when --bounded-arguments is absent, leaving affected functions skipped. Require the enabling option to prevent this silent no-op.
    #[arg(long, default_value_t = AUTOHARNESS_BOUNDED_ARBITRARY_BOUND, value_name = "N")]
  • Files reviewed: 16/16 changed files
  • Comments generated: 3
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread kani-driver/src/autoharness/mod.rs Resolved
Comment thread kani-driver/src/autoharness/mod.rs Resolved
Review follow-ups on the configurable bounds.

The bound options had no effect unless --bounded-arguments was also
passed, so a valid-looking command silently skipped every bounded
harness. Make the dependency explicit, as `format` already does for
`list` in the same struct, and cover all three directions with unit
tests: the option alone is rejected, the option with
--bounded-arguments parses, and a default does not stand in for the
option being supplied.

The unwind warning compared against --default-unwind only, but --unwind
takes precedence when CBMC arguments are resolved, c.f.
resolve_unwind_value. Automatic harnesses carry no unwind attribute, so
those two are the whole precedence at this point.

BoundedArbitrary's N is not a total element count: each implementation
defines what its bound limits, and the derive passes the same N to every
#[bounded] field independently. Report the bound without calling it an
element limit.

The new script test hit the autoharness default 60s harness timeout on
slower CI runners, which the two existing autoharness tests already
raise --harness-timeout to avoid.
@srivatsansamraj

Copy link
Copy Markdown
Contributor Author

@feliperodri the three review comments are addressed, along with the macOS CI failure.

  1. Bound options silently ignored. The three options now carry requires = "bounded_arguments", matching what format already does for list in the same struct. Added unit tests covering all three directions: the option on its own is rejected with MissingRequiredArgument, the option alongside --bounded-arguments parses, and a default does not stand in for the option being supplied.

  2. Wrong effective unwind value. The warning now resolves --unwind ahead of --default-unwind, matching resolve_unwind_value. Automatic harnesses carry no #[kani::unwind] attribute, so those two are the whole precedence at that point.

  3. BoundedArbitrary semantics. The summary reports the bound without calling it an element limit: "BoundedArbitrary values at bound N, which each implementation defines for itself". Expected files updated to match.

CI. regression (macos-15-intel) failed because the string_bound harness hit the default 60s harness timeout, so its cover never reported SATISFIED. bounds.sh now raises --harness-timeout, as cargo_autoharness_slices and cargo_autoharness_bounded already do for the same reason.

Rebased onto your merge of main. Locally: cargo fmt --check, clippy with and without --cfg=kani_sysroot, build-dev, the unit tests, and all three autoharness script tests pass.

@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.

LGTM. Clean threading of the bounds through metadata → compiler → driver, and I like the requires = "bounded_arguments" relationship plus the unwind-bound warning and the bounds being reported in the summary. Good test and doc coverage. Thanks!

@feliperodri
feliperodri added this pull request to the merge queue Sep 17, 2026
Merged via the queue into model-checking:main with commit e5f2e75 Sep 17, 2026
34 checks passed
@feliperodri feliperodri added the [C] Feature / Enhancement A new feature request or enhancement to an existing feature. label Nov 6, 2026
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. 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.

Autoharness: make --bounded-arguments bounds configurable and surface them in the output

3 participants