This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new eea5c84c61 docs: add API stability, unsafe, and performance guidance
for agents (#12107)
eea5c84c61 is described below
commit eea5c84c61cca79eb86547adaa248fab5d949c2b
Author: Matt Butrovich <[email protected]>
AuthorDate: Tue Nov 10 20:20:32 2026 +0000
docs: add API stability, unsafe, and performance guidance for agents
(#12107)
# Which issue does this PR close?
<!--
It is not necessary to raise an issue, but it is encouraged if it is a
non-trivial
enhancement/bug.
If this PR relates to an existing issue, but does not fully resolve it,
please change
the wording below from "Closes #NNN" to "Relates to #NNN" or "Part of
#NNN" to avoid
false closing an issue.
-->
- N/A.
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly
in the
issue then this section is not needed. Explaining clearly why changes
are proposed
helps reviewers understand your changes and offer better suggestions for
fixes.
Please try to explain the problem you are trying to solve in terms of
the user-visible
behavior, rather than the implementation.
-->
- Seeing repeated undesired patterns from what look like agent-generated
PRs and reviews that I'd like to cut down on.
# What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it
is
sometimes worth providing a summary of the individual changes in this
PR.
-->
- Adding some guidance based on recurring themes I am seeing across
arrow-rs, iceberg-rust, and DataFusion (and its subprojects like
datafusion-iceberg and Comet).
# Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they
covered by existing tests, if so identify these tests)?
If this PR claims a performance improvement, please include evidence
such as
benchmark results.
DO NOT simply paste a list of commands ran to verify the code; this is
what our
CI is for and it pollutes the PR. ONLY explain if testing was included
with this
PR, or why it wasn't.
-->
- N/A.
# Are there any significant user-facing changes?
<!--
Significant user-facing changes include:
- Breaking public API change
- Significant change to existing functionality (e.g. function returns
something different)
These need to be explicitly called out to ensure we have proper
documentation if
required and to ensure we follow proper semantic versioning.
DO NOT restate the changes of this PR; if a bug was fixed and already
explained
above, we don't need this to be restated as a user-facing change.
-->
No.
## AI Disclosure
Claude Sonnet helped draft this, but I stand by the content.
---
AGENTS.md | 21 ++++++++++++++++++---
CONTRIBUTING.md | 13 +++++++++++--
2 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/AGENTS.md b/AGENTS.md
index 5cfd643627..04e313a6e4 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -42,10 +42,25 @@ cargo test --workspace
See the [testing](CONTRIBUTING.md#running-the-tests),
[formatting](CONTRIBUTING.md#code-formatting),
[Clippy](CONTRIBUTING.md#clippy-lints), and
[spelling](CONTRIBUTING.md#spell-checking) guidance for details.
-## Additional Checks
+## Code Guidelines
-For performance work, see
[benchmarks](CONTRIBUTING.md#performance-improvements). For memory-safety
checks, see [Miri](CONTRIBUTING.md#miri).
-For public API changes, see [breaking
changes](CONTRIBUTING.md#breaking-changes).
+- A PR merges as one squashed commit titled with the PR title, so it should do
only what that title says. Put unrelated renames, reformatting, refactors, and
drive-by fixes in a separate PR.
+- Default to no comment. Comment only what the code cannot say: invariants,
non-obvious constraints, and why a choice that looks wrong is right. Do not
restate the code or describe how it changed. Public items get a one-line doc
summary of what they do for the caller.
+- Return an error for invalid input instead of panicking, as described in
[Guidelines for `panic` vs `Result`](README.md#guidelines-for-panic-vs-result).
+
+### Public API
+
+Released API is permanent. Breaking changes land only in major releases, and
deprecated items stay for at least two major releases. Read [breaking
changes](CONTRIBUTING.md#breaking-changes) and the [deprecation
guidelines](README.md#deprecation-guidelines) before adding or changing a `pub`
item. Items shared between workspace crates are public API too, because
arrow-rs does not hide them. Add an item only when the change needs it, prefer
private or `pub(crate)`, and give it a defined res [...]
+
+`cargo-semver-checks` reports breakage only, so it does not flag additions. In
a review, name every new or changed public item.
+
+### Unsafe Code
+
+Prefer safe code. Use `unsafe` only when a benchmark shows a gain over the
safe version on the path downstream callers use. A safe function must be sound
for every input its signature accepts: check the input, return an error or
panic, or make it an `unsafe fn` with a `# Safety` section. A `debug_assert!`
does not make code sound, because release builds skip it. Add one for each
`SAFETY` precondition, and run [Miri](CONTRIBUTING.md#miri) on `unsafe` changes.
+
+### Performance
+
+A performance PR needs benchmarks that show why the change is faster. Name the
benchmark(s) the change targets. Say which part of the change produces the
gain, and cover both well-predicted input (constant lengths, all valid) and
poorly predicted input (random). Name the inputs that get slower. Prefer the
smallest change that keeps the gain, and do not add code tuned to the
benchmark's data. See [benchmarks](CONTRIBUTING.md#performance-improvements).
## Issue Ownership
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 996355e94a..92e100fdc1 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -332,8 +332,17 @@ git checkout feature
cargo bench --bench parse_time -- --baseline main
```
-If your PR proposes a performance improvement, include a summary of the
benchmark results (for example, from `cargo-criterion` or `critcmp`) in the PR
description.
-If you need to add new benchmarks to cover your change, make a separate PR
first (for example, [#9729]) so we can run the benchmarks on an automated
runner.
+If your PR proposes a performance improvement, include a summary of the
benchmark results (for example, from `cargo-criterion` or `critcmp`) in the PR
description. Name the benchmark(s) the change targets, so reviewers know which
to run.
+
+A benchmark that improves is not enough on its own. State which part of the
change produces the gain, for example by removing it and rerunning. Cover both
well-predicted input (constant lengths, all valid) and poorly predicted input
(random), because branchless code wins on the second and can lose on the first.
Name the inputs that get slower and say whether real workloads are likely to
hit them.
+
+If you need to add new benchmarks to cover your change, add them in a separate
PR first (for example, [#9729]) or as the first commit of your PR. Either way,
the automated benchmark runner can compare the change against a revision that
already has the benchmarks. For a first commit, pass its SHA as the baseline:
+
+```yaml
+run benchmark <bench>
+baseline:
+ ref: <benchmark commit SHA>
+```
[#9729]: https://github.com/apache/arrow-rs/pull/9729