Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b798933
Code review improvements
mernst Apr 26, 2026
2fabad0
Tweak types
mernst Apr 26, 2026
031ed4d
Don't use full name
mernst Apr 26, 2026
e445712
Adjust expected error
mernst Apr 26, 2026
7116a33
Document 1-based indexing
mernst Apr 26, 2026
bb2891a
Add module documentation
mernst Apr 26, 2026
e2f077c
More changes
mernst Apr 26, 2026
5e1baf5
Diagnostics
mernst Apr 26, 2026
4e29093
Merge ../rust_verification into module-doc
mernst Apr 26, 2026
b2914e9
Merge ../rust_verification into end-line
mernst Apr 26, 2026
fef27cc
Merge ../rust_verification-branch-end-line into review-pre
mernst Apr 26, 2026
f4c86ff
Merge ../rust_verification-branch-review-pre into review
mernst Apr 26, 2026
263d23d
Tweak documentation
mernst Apr 26, 2026
f10b572
Formatting
mernst Apr 26, 2026
866c147
Fix type annotations
mernst Apr 26, 2026
d87c18c
Merge ../rust_verification-branch-end-line into review-pre
mernst Apr 26, 2026
5633d65
Merge ../rust_verification-branch-types into review-pre
mernst Apr 26, 2026
517cdf5
Merge ../rust_verification-branch-review-pre into review
mernst Apr 26, 2026
125687f
Improve Python style
mernst Apr 26, 2026
5e3880c
Merge ../rust_verification-branch-style into review-pre
mernst Apr 26, 2026
51bc5d3
Style
mernst Apr 26, 2026
60e84d6
Merge ../rust_verification-branch-review-pre into review
mernst Apr 26, 2026
2ff15b0
Raise `TypeError` for `isinstance()` failure
mernst Apr 26, 2026
6925cf3
Don't change the type of error raised
mernst Apr 26, 2026
60f3167
Merge ../rust_verification-branch-style into review-pre
mernst Apr 26, 2026
2456f0f
Merge ../rust_verification-branch-value-error-to-type-error into revi…
mernst Apr 26, 2026
bdb3fa9
Merge ../rust_verification-branch-review-pre into review
mernst Apr 26, 2026
825e8fb
Fix
mernst Apr 26, 2026
9cf9aa8
Merge branch 'main' into end-line
jyoo980 Apr 26, 2026
077808f
Merge branch 'main' into end-line
jyoo980 Apr 26, 2026
5c2e704
Merge branch 'main' into end-line
jyoo980 Apr 26, 2026
051f493
Merge branch 'main' into end-line
jyoo980 Apr 26, 2026
d44b4cc
Merge ../rust_verification into end-line
mernst Apr 26, 2026
af089ea
Merge ../rust_verification-branch-end-line into review-pre
mernst Apr 26, 2026
3044b9b
Merge ../rust_verification-branch-review-pre into review
mernst Apr 26, 2026
c9cdb02
Fixes
mernst Apr 26, 2026
e57fbe0
Merge ../rust_verification-branch-end-line into review-pre
mernst Apr 26, 2026
2356f69
Merge ../rust_verification-branch-review-pre into review
mernst Apr 26, 2026
2aeed9e
Merge ../rust_verification into review-pre
mernst Jul 18, 2026
19c3b08
Merge ../rust_verification-branch-review-pre into review
mernst Jul 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions models/default_llm_backend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Default module for LLM-based generation."""

# ruff: noqa
# TODO: Vikram, please document.
# Vikram would be best suited to document this class.

Expand All @@ -23,9 +22,31 @@


class DefaultLlmBackend(LlmBackend):
"""Encapsulate LLM-based generation logic."""
"""Encapsulate LLM-based generation logic.

Wraps `litellm` to support both direct API access (via `LLM_API_KEY`) and
Google Cloud Vertex AI (via `VERTEX_AI_JSON`). Automatically retries on
transient errors and compacts the conversation when the context window is
exceeded.

Attributes:
model (str): The litellm model string (e.g. `vertex_ai/claude-sonnet-4-6`).
max_tokens (int): Maximum tokens allowed in a single response.
api_key (str | None): API key for direct access; `None` when using Vertex AI.
vertex_credentials (str | None): JSON credentials for Vertex AI; `None` otherwise.
"""

def __init__(self, model: str, use_vertex_api: bool):

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix Ruff warnings by adding a return type and suppressing FBT001.

As per coding guidelines, all code must pass linting with make checks yielding 0 errors or warnings. Ruff flagged a missing return type (ANN204) and a boolean positional argument (FBT001). Adding -> None and # noqa: FBT001 resolves this without breaking existing callers.

🛠️ Proposed fix
-    def __init__(self, model: str, use_vertex_api: bool):
+    def __init__(self, model: str, use_vertex_api: bool) -> None:  # noqa: FBT001
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def __init__(self, model: str, use_vertex_api: bool):
def __init__(self, model: str, use_vertex_api: bool) -> None: # noqa: FBT001
🧰 Tools
🪛 Ruff (0.15.21)

[warning] 39-39: Missing return type annotation for special method __init__

Add return type annotation: None

(ANN204)


[warning] 39-39: Boolean-typed positional argument in function definition

(FBT001)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@models/default_llm_backend.py` at line 39, Update the __init__ method in the
default LLM backend to declare an explicit None return type and add a targeted
noqa suppression for Ruff’s FBT001 boolean-positional-argument warning,
preserving the existing signature behavior for callers.

Sources: Coding guidelines, Linters/SAST tools

"""Create a new DefaultLlmBackend.

Args:
model (str): The model name to use (e.g. `claude-sonnet-4-6`, `gpt-4o`).
use_vertex_api (bool): If True and `VERTEX_AI_JSON` is set, route requests
through Google Cloud Vertex AI using the credentials in that file.

Raises:
ModelError: Raised when `model` is not a supported model name.
"""
if use_vertex_api and "VERTEX_AI_JSON" in os.environ:
litellm.vertex_location = "us-east5"
with pathlib.Path(os.environ["VERTEX_AI_JSON"]).open(encoding="utf-8") as file:
Expand Down Expand Up @@ -53,13 +74,23 @@ def send_messages(
) -> list[str]:
"""Return `top_k` sampled responses from the LLM for the given messages.

Retries up to 5 times on transient errors (rate limits, server errors, connection issues)
with a 10-second delay between attempts. On a context-window overflow, the conversation
is compacted and retried once.

Args:
messages (tuple[ConversationMessage, ...]): The conversation to send to the LLM.
temperature (float): The sampling temperature. Must be non-zero when `top_k > 1`.
top_k (int): The number of responses to sample.
messages (tuple[ConversationMessage, ...]): The conversation history to send.
temperature (float): Sampling temperature. Must be non-zero when `top_k > 1`.
top_k (int): Number of independent completions to request.

Returns:
list[str]: The sampled responses. `len(returned) == top_k`.
list[str]: The text content of each completion, with `len(result) == top_k`.

Raises:
GenerationError: Raised for unrecoverable API errors or invalid arguments.
ContextWindowExceededError: Raised when the context window is exceeded and the
conversation is already too short to compact further.
ModelError: Raised after 5 consecutive transient failures.
"""
if top_k < 1:
raise GenerationError("top_k must be >= 1")
Expand Down Expand Up @@ -165,9 +196,9 @@ def _send_with_retry(
raise ModelError(msg) from e
logger.warning(f"LLM Error {e}. Waiting 10 seconds and retrying")
time.sleep(10)
except Exception as e:
except Exception as e: # noqa: BLE001
msg = f"LLM Error: {e}"
raise GenerationError(msg)
raise GenerationError(msg) # noqa: B904

@staticmethod
def get_instance(model_name: str, use_vertex_api: bool) -> LlmBackend:
Expand Down
13 changes: 8 additions & 5 deletions test/util/test_spec_syntax_fixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
CLAUSES_WITH_ILLEGAL_ARRAY_RANGES_TO_FIXED_CLAUSES = {
"__CPROVER_assigns(arr[lo...hi], a, arr2[i])": "__CPROVER_assigns(*arr, a, arr2[i])",
"__CPROVER_assigns(a, arr[1..2], arr2[i])": "__CPROVER_assigns(a, *arr, arr2[i])",
"__CPROVER_assigns(a, arr2[i], arr[lo+2:3])": "__CPROVER_assigns(a, arr2[i], *arr)"
"__CPROVER_assigns(a, arr2[i], arr[lo+2:3])": "__CPROVER_assigns(a, arr2[i], *arr)",
}

# These are some examples of specifications that contain ellipses (...), which are illegal.
Expand Down Expand Up @@ -52,16 +52,19 @@ def test_fix_illegal_ellipses() -> None:
# We only care about the postconditions.
assert fixed_spec.postconditions == ["__CPROVER_assigns(a, b, c)"]


def test_fix_illegal_array_ranges_with_unrelated_assigns_targets() -> None:
for illegal_clause, fixed_clause in CLAUSES_WITH_ILLEGAL_ARRAY_RANGES_TO_FIXED_CLAUSES.items():
spec_with_illegal_clause = FunctionSpecification(preconditions=[], postconditions=[illegal_clause])
spec_with_illegal_clause = FunctionSpecification(
preconditions=[], postconditions=[illegal_clause]
)
fixed_spec = fix_syntax(spec_with_illegal_clause)
assert fixed_spec.postconditions == [fixed_clause]


def test_fix_multiple_illegal_ellipses() -> None:
spec_with_multiple_illegal_ellipses = FunctionSpecification(preconditions=[], postconditions=["__CPROVER_assigns(a, b, ..., c, ..., d)"])
spec_with_multiple_illegal_ellipses = FunctionSpecification(
preconditions=[], postconditions=["__CPROVER_assigns(a, b, ..., c, ..., d)"]
)
fixed_spec = fix_syntax(spec_with_multiple_illegal_ellipses)
assert fixed_spec.postconditions == ["__CPROVER_assigns(a, b, c, d)"]


9 changes: 6 additions & 3 deletions translation/ast/cbmc_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@

# Ideally we'd like to type check this file, but Lark does not yet support type annotations.
# mypy: ignore-errors
# ruff: noqa
# ruff: noqa: D101, D102, N802, DOC502

from __future__ import annotations

import sys
from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Any, Protocol
from typing import TYPE_CHECKING, Any, Protocol

from lark import Transformer, ast_utils, v_args
from lark.tree import Meta

if TYPE_CHECKING:
from lark.tree import Meta


class Mutable(Protocol):
Expand Down
6 changes: 5 additions & 1 deletion util/text_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ def prepend_line_numbers(lines: list[str], start: int, end: int) -> list[tuple[s
if len(lines) != end - start:
msg = (
f"Mismatch between length of lines ({len(lines)}) and "
f"range of lines (start = {start}, end = {end})"
f"range of lines (start = {start}, end (exclusive) = {end}). Lines = \n"
)
lineno = 1
for line in lines:
msg += f"{lineno}\t{line}\n"
lineno = lineno + 1
raise RuntimeError(msg)
line_number_width = len(str(end))
return [(f"{str(n).ljust(line_number_width)}", lines[n - start]) for n in range(start, end)]
Expand Down
Loading