Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
90 changes: 90 additions & 0 deletions .agents/checks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# LLM checks

An LLM check is a review rule, written in prose and judged by a model. Add one
when you are about to write the same review comment again and no lint or test
can enforce the rule. For now the checks run locally, before you ask for review.

## Running the checks

```
bin/llm-check run
```

This judges your working tree against where it branched off `main`, together
with the description of its pull request, or with its commit messages while it
has none. Every check whose `paths` match a changed file gets a model run of
its own and prints `pass`, `fail` with its findings, or `error` if the judge
gave no clear verdict. In Claude Code and Codex, ask to "run the LLM checks".

A finding is a claim by a model, and you decide whether it is right. If it is
wrong, add your change to the check as a green example and tune the rule.

## Adding a check

Create `.agents/checks/<name>/CHECK.md`:

```markdown
---
paths: ["src/**/*.rs"]
model: sonnet
effort: low
examples:
send_inside_assert:
expect: red
base: 8327b66ed694407f03c272110d36ed3716d42fb3
finding: src/compute/src/compute_state.rs
soft_assert_conversion:
expect: green
commit: f0cdedca04109ca38ea8fab710bf680e4e00c48b
---

What must hold and why, what to look at in a change, and what looks similar
but is not a violation.
```

The model knows nothing about your subsystem. The text below the frontmatter is
all it gets.

| Field | Meaning |
|---|---|
| `paths` | Globs for the files the check is about, every file if unset. The check runs on a change that touches one of them, and the judge gets the diff of these files only. `*` stays within a directory, `**` crosses them. |
| `model`, `effort` | The Claude model that judges the check, `sonnet` if unset, and its reasoning effort. |
| `examples` | Changes the check must flag, `expect: red`, and changes it must pass, `expect: green`. |

An example is one of:

- `commit`: a commit on `main`. Its diff is the change and its message is the
description.
- `base`: the commit that `<example>.patch`, next to `CHECK.md`, applies to.
This is for a change that never landed, such as a PR before review. Create
the patch with `git diff <base> > .agents/checks/<name>/<example>.patch`.

A red example can name the file at fault as `finding`. The check then has to
report that file, so that a failure for an unrelated reason does not count as
a catch.

```
bin/llm-check eval <name>
```

This replays every example three times, each in a checkout of its own commit,
and prints how many runs gave the expected verdict. A model answers the same
question differently from run to run, so tune the rule until every run is
right. Start with the cheapest `model` and `effort` and raise them only if the
examples need it. An example that touches no file in the check's `paths` counts
as wrong, because `run` would skip the check on it.

## Judges

| Flag | Judge | Model |
|---|---|---|
| none | `claude` | The check's `model` and `effort` |
| `--codex` | `codex` | The CLI's default |
| `--openrouter` | `opencode` with its OpenRouter login | `deepseek/deepseek-v4.1-flash-1017` |

`--model` and `--effort` override the model and the effort for every check.
`opencode` takes no effort.

A judge gets the diff of the check's `paths` and can read the checkout. It
cannot change a file. A diff too large for the model ends in `error`, so keep
`paths` narrow.
45 changes: 45 additions & 0 deletions .agents/checks/catalog_migration_is_frozen/CHECK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
paths: ["src/catalog/src/durable/upgrade/**/*.rs"]
model: sonnet
effort: medium
examples:
# Builds a Config row from the current, unversioned catalog types and from
# USER_VERSION_KEY in initialize.rs.
repair_migration_uses_current_objects:
expect: red
commit: a2c7f7068d8bf166426265b4ba5f5e78f6146faf
finding: src/catalog/src/durable/upgrade/v82_to_v83.rs
# Imports nothing but MigrationAction and its two snapshots.
migration_on_snapshots_only:
expect: green
commit: 3dc710f9b15a4b9da1d3ca0d5d5bf88846d7762d
---

A catalog migration, `src/catalog/src/durable/upgrade/v<N>_to_v<M>.rs`, runs on
every environment that is still at version N, which can be long after the
migration was written. What it writes must be decided by the old rows and by
the migration file alone. The only catalog definitions it may use are the two
frozen snapshots, `objects_v<N>` and `objects_v<M>`.

## How to check

For every migration file the change adds or edits, find what its code outside
`#[cfg(test)]` uses from outside those two snapshot modules. It is a violation
when a value that the migration writes or branches on comes from current code:

- a `const` or `static` defined elsewhere in the codebase,
- a default defined elsewhere, such as a `DEFAULT_*` item or the `Default` impl
of a type that is not in a snapshot,
- a function elsewhere that computes such a value,
- the current, unversioned catalog definitions, such as `objects`, `proto` or a
`StateUpdateKind` without a version.

## Not a violation

- Imports that carry no catalog value: `MigrationAction`, `UpgradeFrom`,
`UpgradeInto`, `JsonCompatible`, `json_compatible!`, collections, error
types, `Diff`, `Timestamp`.
- A literal or a `const` written in the migration file itself, even when it
repeats a constant that exists elsewhere. Repeating it is what keeps the
migration frozen.
- Code under `#[cfg(test)]`.
44 changes: 44 additions & 0 deletions .agents/checks/debug_assert_side_effects/CHECK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
paths: ["src/**/*.rs"]
model: sonnet
effort: low
examples:
# Moves a watch-channel send into debug_assert!. send takes &self, so clippy
# is silent.
send_inside_assert:
expect: red
base: 8327b66ed694407f03c272110d36ed3716d42fb3
finding: src/compute/src/compute_state.rs
# A call inside debug_assert! that only reads.
pure_read_in_assert:
expect: green
base: 8327b66ed694407f03c272110d36ed3716d42fb3
# Rewrites dozens of debug_assert! calls into soft assertions and adds none.
soft_assert_conversion:
expect: green
commit: f0cdedca04109ca38ea8fab710bf680e4e00c48b
---

The arguments of `debug_assert!`, `debug_assert_eq!` and `debug_assert_ne!` are
compiled out whenever debug assertions are off, which includes the optimized and
release profiles. An argument must therefore be free of effects that anything
outside the assertion relies on.

## How to check

For every `debug_assert*!` the change adds or modifies, look at each call inside
its arguments and read the callee if its name does not settle the question. It
is a violation when the call changes state or does work that the program needs
to happen: sending on a channel, inserting into or removing from a collection
behind a lock, `RefCell` or atomic, registering or deregistering something,
advancing a cursor that is read again later, writing a file, bumping a metric.

## Not a violation

- Pure reads: getters, `len()`, `is_empty()`, `contains()`, comparisons,
`matches!`.
- An effect bound to a `let` outside the macro, with the assertion applied to
the bound value.
- `assert!` and the `soft_assert*!` macros. This check covers the `debug_assert`
family only.
- A `debug_assert*!` the change only moves or reindents.
15 changes: 15 additions & 0 deletions .agents/checks/debug_assert_side_effects/pure_read_in_assert.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
diff --git a/src/compute/src/compute_state.rs b/src/compute/src/compute_state.rs
index 9282b71465..2a78da220b 100644
--- a/src/compute/src/compute_state.rs
+++ b/src/compute/src/compute_state.rs
@@ -2167,6 +2167,10 @@ impl CollectionState {
export = ?self.logging.as_ref().map(|l| l.export_id()),
"allowing writes for dataflow",
);
+ debug_assert!(
+ *self.read_only_tx.borrow(),
+ "writes were already allowed for this dataflow",
+ );
let _ = self.read_only_tx.send(false);
}
}
16 changes: 16 additions & 0 deletions .agents/checks/debug_assert_side_effects/send_inside_assert.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/src/compute/src/compute_state.rs b/src/compute/src/compute_state.rs
index 9282b71465..b0a6073c48 100644
--- a/src/compute/src/compute_state.rs
+++ b/src/compute/src/compute_state.rs
@@ -2167,7 +2167,10 @@ impl CollectionState {
export = ?self.logging.as_ref().map(|l| l.export_id()),
"allowing writes for dataflow",
);
- let _ = self.read_only_tx.send(false);
+ debug_assert!(
+ self.read_only_tx.send(false).is_ok(),
+ "read-only receiver dropped before writes were allowed",
+ );
}
}

54 changes: 54 additions & 0 deletions .agents/checks/refactor_changes_no_behavior/CHECK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
paths: ["src/**/*.rs"]
model: sonnet
effort: low
examples:
# A refactor of all visitors that was reverted. children() of the window
# expressions descended into the argument instead of yielding it, so mz_now()
# there was no longer seen as temporal.
visitor_refactor_skips_window_args:
expect: red
commit: dfce26ef97a338c55dcfb77bb4ceefca3ebc5fad
finding: src/sql/src/plan/hir.rs
# An extraction of about 180 changed lines that states "No behavior change".
extract_temporal_bounds:
expect: green
commit: b98eb35aa476a970416e8c23892f68fb03e9a37e
# A mechanical rename across six files.
mechanical_rename:
expect: green
commit: b7c30cce490a0759afc8e59d14c7c2d07bb9cb90
---

A change that presents itself as behavior-preserving gets a lighter review, so
it must not change behavior. This check applies only when the description of
the change, or failing that its commit messages, say that it is a refactor, a
rename, a move, an extraction, a cleanup, or that it has no functional or
behavior change. For any other change it passes.

## How to check

Go through the diff hunk by hunk and compare the code before and after. Moved,
renamed, extracted, inlined and reformatted code must do the same thing in the
same order as before. It is a violation when the new code can produce a
different result, error, panic or side effect than the old code for some input:

- a condition, comparison or bound that changed,
- a constant, default or argument that changed,
- a guard, check or early return that is gone, or new,
- an error that is now swallowed, or raised where it was not,
- an operation with different overflow, ordering or evaluation behavior, such
as `saturating_sub` turned into `-`,
- a traversal or iteration that visits different elements.

When code was restructured and not just moved, read the old and the new version
of each piece side by side. Do not trust that it was copied faithfully.

## Not a violation

- A behavior change that the description names. Only what the description
leaves out counts.
- Changes to tests, comments, documentation, logging and metrics.
- Changes in visibility, naming, module layout, types or signatures that leave
every caller's result the same.
- A difference in performance alone.
1 change: 1 addition & 0 deletions .agents/skills/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ explicitly with `$<skill-name>` in Codex and `/<skill-name>` in Claude Code.
| **mz-release-signoff** | Verifying a release candidate on the Grafana dashboards | Compares metrics across the release boundary per area and region. Metric references with measured baselines for compute, adapter, sources and sinks, persist, and the release-health and networking dashboards |
| **mz-dependencies** | Adding, updating, or removing Rust dependencies | Workspace dependency rules, Cargo.lock discipline, license policy sync between `deny.toml` and `about.toml` |
| **mz-feature-flags** | Adding a feature flag or dyncfg, or reviewing one | Production default policy, enabling flags in CI, `bin/lint-test-flags`, LaunchDarkly caveats |
| **mz-llm-checks** | Running the LLM checks on a change, adding or tuning a check | Runs `bin/llm-check`, and points to the authoring guide in `.agents/checks/README.md` |

## Performance

Expand Down
18 changes: 18 additions & 0 deletions .agents/skills/mz-llm-checks/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
name: mz-llm-checks
description: >
Run the repository's LLM checks (rules in .agents/checks) on the current
change, or add and tune a check. Trigger: "run the LLM checks", "llm-check",
"add an LLM check", "this check is a false positive", or edits under
.agents/checks/.
---

# LLM checks

Run `bin/llm-check run`, with `--codex` if you are Codex. It judges the working
tree against every check in `.agents/checks` that applies, each in a fresh
model run, and takes a few minutes. Read the code behind each finding and
report whether you agree with it. Do not fix a violation unless asked.

To add or tune a check, follow `.agents/checks/README.md`. A change to a rule
is done when `bin/llm-check eval <check>` passes.
1 change: 1 addition & 0 deletions bin/gen-completion
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ completions=(
cargo-test:--print-completion
environmentd:--print-completion
lint:--print-completion
llm-check:--print-completion
mzcompose:completion
mzimage:completion
scratch:completion
Expand Down
14 changes: 14 additions & 0 deletions bin/llm-check
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# Copyright Materialize, Inc. and contributors. All rights reserved.
#
# Use of this software is governed by the Business Source License
# included in the LICENSE file at the root of this repository.
#
# As of the Change Date specified in that file, in accordance with
# the Business Source License, use of this software will be governed
# by the Apache License, Version 2.0.
#
# llm-check Judge a change against the LLM checks in .agents/checks

exec "$(dirname "$0")"/pyactivate -m materialize.cli.llm_check "$@"
1 change: 1 addition & 0 deletions ci/test/lint-main/checks/check-copyright.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ copyright_files=$(grep -vE \
-e '^test/pgtest/.*\.pt' \
-e '^test/pgtest-mz/.*\.pt' \
-e '^test/coordtest/.*\.ct' \
-e '^\.agents/checks/.*\.patch$' \
-e '^test/ldbc-bi/.*\.sql' \
-e '^test/ldbc-bi/.*\.log' \
-e '^src/catalog/tests/snapshots/.*\.snap' \
Expand Down
Loading