Repository navigation
Conversation
Add rules for detecting and preventing common AI coding agent mistakes.
🔒 PR Risk Scan ResultsScanned 1 changed file(s).
✅ No matching risk patterns were detected in changed files.
|
🚦 Submission status: 🛠️ Requires submitter fixesRisk tier: Why this tier
Automated checks
Action needed
Review
Commands
Updated for |
There was a problem hiding this comment.
🟡 Changes recommended
The new instruction contains multiple moderate correctness and scope issues in its detection rules and is also missing from the required README catalog.
9 open issues
Add the new instruction to the generated catalog · New Test-count check misses skipped tests and deleted assertions · New Scan staged file contents for secrets · New SQL injection detector misses common query patterns · New Make ORM N+1 guidance conditional on lazy loading · New Limit blocking-call checks to event-loop code · New Scope timeout requirements to supported operations · New Require lockfiles only when repository policy uses them · New Preserve intentional CLI output and diagnostics · New
What changed in this PR
Adds a repository-wide instruction file to help coding agents avoid common mistakes when modifying existing codebases.
Changes:
- Adds guidance for test integrity, secret handling, SQL and migration safety, async-runtime behavior, ORM performance, and error handling.
- Provides command-based detection checks for several anti-patterns.
- Adds diff-hygiene guidance covering lockfiles, commits, debugging output, and oversized changes.
| File | Description |
|---|---|
instructions/coding-agent-anti-patterns.instructions.md |
New global coding-agent safety and editing guidance, including prevention rules and detection examples. |
Review effort: Lite (auto)
| --- | ||
| description: 'Detection-and-prevention rules for the most common mistakes AI coding agents make when editing an existing codebase: silently deleting tests, leaking secrets, breaking async/ORM/SQL safety, and oversized diffs. Apply when generating or editing code in any language.' | ||
| applyTo: '**' |
| ## Test integrity | ||
|
|
||
| - Never delete or skip an existing test to make a suite pass. Fix the code under test, not the test, unless the test itself has a verified bug. State the bug before changing it. | ||
| - Detect: a diff that removes test files or lowers the test count (`git diff --stat` on `test*/`, `*_test.*`, `*.test.*` paths). |
| ## Secrets | ||
|
|
||
| - Never commit `.env` files, API keys, tokens, or connection strings. If a secret is staged, unstage it immediately; if it was already committed, rotate the secret before cleaning history. | ||
| - Detect: `git diff --cached --name-only | grep -E '\.env|secret|credential'`. |
| ## Database and query safety | ||
|
|
||
| - All queries must use parameterized queries or the ORM's query builder. Never concatenate user input into a SQL string, including via f-strings or template interpolation. | ||
| - Detect: `grep -rnE '"\s*\+.*(SELECT|INSERT|UPDATE|DELETE)'` and `grep -rn 'f".*SELECT.*{'`. |
| - Every relation access in an ORM loop needs eager loading (`select_related`/`prefetch_related` in Django, `includes`/`eager_load` in Rails, `.with` in Ecto, etc.) or it becomes an N+1 query. | ||
| - Detect: query-count assertions in tests, or `EXPLAIN`/debug-toolbar output showing one query per row. |
| - Inside async functions, use only async I/O. Blocking calls (sync file reads, `thread::sleep`, blocking HTTP clients) stall the whole runtime, not just the caller. | ||
| - Detect: in Rust/Tokio, `grep -rn 'std::fs::\|thread::sleep\|reqwest::blocking' src/` inside `async fn` bodies. In Node, `grep -rn 'fs\.readFileSync\|execSync'` inside async handlers. |
| - Detect: in Rust/Tokio, `grep -rn 'std::fs::\|thread::sleep\|reqwest::blocking' src/` inside `async fn` bodies. In Node, `grep -rn 'fs\.readFileSync\|execSync'` inside async handlers. | ||
| - Never use `.unwrap()` (Rust) or an equivalent force-unwrap in a path reachable from a network request. A `None`/`Err` there panics or crashes the handler. Use `?`, `.map_err()`, or an explicit fallback. | ||
| - Catch specific exception/error types, not a bare `Exception`/`Error`. Re-raise what you cannot handle (`KeyboardInterrupt`, `SystemExit`, OOM signals). | ||
| - Every external call (HTTP, database, filesystem, third-party API) needs a timeout, error handling that does not crash the caller, and a fallback or explicit error surfaced to the user. |
| - Make the smallest change that solves the problem. To fix one function, edit that function. Do not rewrite or reformat the whole file. | ||
| - Detect: `git diff --stat` shows a full file rewritten for what the task described as a small fix. | ||
| - One logical change per commit. Do not combine a refactor with a feature or a style pass; commit the refactor first, verify, then commit the feature. | ||
| - After changing a dependency manifest, run the install command and commit the updated lockfile in the same commit. A manifest change without a matching lockfile change breaks CI (`npm ci`, `uv sync --locked`, etc.) for every other contributor. |
| - Detect: `git diff --stat` shows a full file rewritten for what the task described as a small fix. | ||
| - One logical change per commit. Do not combine a refactor with a feature or a style pass; commit the refactor first, verify, then commit the feature. | ||
| - After changing a dependency manifest, run the install command and commit the updated lockfile in the same commit. A manifest change without a matching lockfile change breaks CI (`npm ci`, `uv sync --locked`, etc.) for every other contributor. | ||
| - Remove debugging output (`console.log`, `print`, `println!`, `dbg!`) before the final commit; use the project's logging framework for anything that should stay. |
|
Thanks for the contribution. We're not able to take this one, for the same reason as #5190: almost all of the rules are general practice that current models already follow without an instruction file. Examples include "Never delete or skip an existing test to make a suite pass", "All queries must use parameterized queries", "Make the smallest change that solves the problem", and "Catch specific exception/error types". Applying them globally with The detection commands are meant to be the differentiator, but they're too coarse to check the rules they're attached to:
There's also a factual slip: If you'd like to contribute again, the best fit is something narrowly scoped that a model genuinely gets wrong without help. Examples include version-specific breaking changes, non-obvious tool behaviour, or a script that deterministically performs one of these checks, paired with a concrete before/after showing the difference it makes. |

Adds instructions/coding-agent-anti-patterns.instructions.md: detection-and-prevention rules for mistakes AI coding agents make when editing an existing codebase (silent test deletion, secret leaks, N+1 queries, blocking calls on an async runtime, unparameterized SQL, oversized diffs).
Why this is a different gap than agent-safety.instructions.md
agent-safety.instructions.md covers building governed agent frameworks (tool allowlists, audit trails, multi-agent trust). This file covers the opposite direction: constraints on an agent editing someone else's codebase. No existing file in instructions/ addresses that.
Why this is not duplicating existing model strengths
Each rule pairs a prevention instruction with a grep/git command that makes the violation mechanically checkable, rather than restating generic best practice. These patterns come from a kit I maintain and test against real agent-produced diffs, not hypothetical cases.
Checklist