Skip to content

Add review checklists, domain invariants, and a migration CI gate to agent instructions - #1335

Closed
mihow wants to merge 3 commits into
mainfrom
docs/agent-instructions-restructure
Closed

mihow wants to merge 3 commits into
mainfrom
docs/agent-instructions-restructure

Conversation

@mihow

@mihow mihow commented Jun 9, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This restructures the agent/contributor instructions (.agents/AGENTS.md, symlinked as CLAUDE.md) so they actively prevent the kinds of issues that show up over and over in this repo's PR review history, instead of mostly documenting query patterns. The changes come from reviewing roughly fifty merged PRs across the last two years and grouping the recurring reviewer feedback — from both human reviewers and the review bots — into categories, then writing guidance (and one CI gate) targeted at the most frequent ones.

The most common recurring findings were: new code paths missing a permission check or the default occurrence filters (bugs invisible in the diff), unbounded/Python-side query work that doesn't scale, query params that return a 500 instead of a 400, PII leaking through nested serializers, single-row test fixtures that can't catch N+1s, and forgotten migrations shipping to main and needing standalone follow-up PRs. Nothing here changes application behavior except the new CI step and the migration it required.

List of Changes

# Change (what it does) How
1 Agents get a "definition of done" before opening a PR, mapped to the most frequent review findings New checklists in AGENTS.md for endpoint/queryset changes, model changes, and a pre-review pass (permissions matrix tests, default filters, param validation → 400, no PII in serializers, assertNumQueries with multi-row fixtures, self-review for debris)
2 Agents are warned about silent-bug classes that don't show up in a diff New "Domain Invariants & Correctness Rules" section: one feature-extractor per clustering query, timezone.now() vs datetime.now(), the ML-backend schema boundary, raise-don't-return, no assert in prod, migration-in-same-PR
3 CI now fails when a model change is missing its migration Added makemigrations --check --dry-run step to test.backend.yml
4 Fixes a migration that was already missing on main Job.job_type_key builds its choices from VALID_JOB_TYPES; two job types were added without the (state-only) migration. The new CI gate caught it
5 The always-loaded instructions are ~325 lines shorter and faster to load Moved the DB schema table, query guide, and QuerySet catalog to docs/claude/reference/query-patterns.md; worktree-vs-main-stack testing to docs/claude/reference/worktree-testing.md; chaos-testing section to a pointer to the existing runbook
6 Agents can find and reuse existing helpers instead of reinventing them New docs/claude/reference/canonical-patterns.md — reuse table with file:line refs (SingleParamSerializer, ProjectMixin, permission classes, stats pattern, fixtures)
7 The frontend finally has its own conventions doc New ui/CLAUDE.md: strings through the translation layer, no any in data-services models, disable mutation buttons in-flight, naming, and which lint rules are actually configured (note: there is no Stylelint config, so bot Stylelint findings should be ignored)
8 Agent docs are discoverable New docs/claude/INDEX.md indexing all reference docs, runbooks, and plans
9 Agents handle review-bot feedback better New section: verify bot findings against the actual lint configs, push back with evidence, and split PRs over ~150 files (CodeRabbit skips them)

Detailed Description

The guidance is evidence-based: each checklist item and invariant corresponds to a category of feedback that recurred across multiple PRs and multiple reviewers. The intent is to shift that feedback from review-time to author-time (or to CI), and to make the always-loaded instruction file smaller and more rule-focused by moving bulk reference material into load-on-demand docs.

A separate, higher-level "why Antenna exists / design grounding" section was considered for this PR but is being held back for team review since it's more strategic than mechanical.

How to Test the Changes

  • The behavioral change is the CI gate. On this branch python manage.py makemigrations --check --dry-run exits 0; without change Bump docker/setup-buildx-action from 1 to 2 #4 it exits 1. Verified locally against the CI compose file.
  • Everything else is documentation.

Checklist

  • I have tested these changes appropriately.
  • I have added and/or modified relevant tests. (N/A — docs + CI; the migration is state-only)
  • I updated relevant documentation or comments.
  • I have verified that this PR follows the project's coding standards.
  • Any dependent changes have already been merged to main.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes / Tests

    • Added CI verification to prevent unapplied database migrations in test workflows.
  • Documentation

    • Expanded development guides with canonical patterns, query optimization, and worktree testing procedures.
    • Added frontend convention documentation for React/TypeScript development.
    • Created searchable documentation index for agent reference materials.
  • Chores

    • Updated job type configuration with new default value and classification options.

mihow and others added 3 commits June 9, 2026 15:17
…reference files

Slim CLAUDE.md (.agents/AGENTS.md) from 899 to ~600 lines and add the guidance
that two years of PR review history shows is missing:

- Definition-of-done checklists (endpoint/queryset, model change, pre-review)
  mapping 1:1 to the most frequent review findings: missing permission checks
  and default filters, 500s from unvalidated params, PII in serializers,
  N+1-blind single-row test fixtures, WIP debris, stale PR descriptions.
- Domain invariants section: one feature extractor per clustering query,
  timezone.now() rule, ML-backend schema boundary, raise-don't-return,
  no assert in prod code, migration-in-same-PR rule.
- Automated review bots section: verify bot findings against actual lint
  configs, push back with evidence, 150-file CodeRabbit limit.
- Split bulk reference out of the always-loaded file:
  - DB schema table + query guide + QuerySet catalog -> docs/claude/reference/query-patterns.md
  - Worktree-vs-main-stack testing -> docs/claude/reference/worktree-testing.md
  - Chaos testing section -> pointer to existing docs/claude/debugging/chaos-scenarios.md
- New docs/claude/reference/canonical-patterns.md: reuse-before-reinventing
  table with file:line refs (SingleParamSerializer, ProjectMixin, permissions,
  stats pattern, fixtures).
- New ui/CLAUDE.md: frontend conventions (i18n via language.ts, no any in
  data-services models, mutation button states, naming, which lint rules are
  actually configured).
- New docs/claude/INDEX.md: searchable index of all agent docs.

Co-Authored-By: Claude <noreply@anthropic.com>
Add makemigrations --check --dry-run step before the test run. Forgotten
migrations have repeatedly shipped to main and required standalone follow-up
PRs (#722, #897, #946); this catches them at PR time.

Co-Authored-By: Claude <noreply@anthropic.com>
Job.job_type_key builds its choices from VALID_JOB_TYPES, so registry changes
(post_processing and data_export job types added since the last migration)
alter the field definition. The migration is state-only — no database schema
change — but Django requires it, and the new makemigrations --check CI step
fails without it. Documented the gotcha in the agent instructions.

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 9, 2026 22:49
@netlify

netlify Bot commented Jun 9, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for antenna-ssec ready!

Name Link
🔨 Latest commit a5ed180
🔍 Latest deploy log https://app.netlify.com/projects/antenna-ssec/deploys/6a28988501e02f0008d4ee9d
😎 Deploy Preview https://deploy-preview-1335--antenna-ssec.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Jun 9, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for antenna-preview ready!

Name Link
🔨 Latest commit a5ed180
🔍 Latest deploy log https://app.netlify.com/projects/antenna-preview/deploys/6a289885223a460009a25c00
😎 Deploy Preview https://deploy-preview-1335--antenna-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 62 (🔴 down 3 from production)
Accessibility: 81 (🔴 down 8 from production)
Best Practices: 92 (🔴 down 8 from production)
SEO: 92 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b7b26923-ec93-4031-8b4f-590703cc8445

📥 Commits

Reviewing files that changed from the base of the PR and between 0e329fb and a5ed180.

📒 Files selected for processing (8)
  • .agents/AGENTS.md
  • .github/workflows/test.backend.yml
  • ami/jobs/migrations/0023_alter_job_job_type_key.py
  • docs/claude/INDEX.md
  • docs/claude/reference/canonical-patterns.md
  • docs/claude/reference/query-patterns.md
  • docs/claude/reference/worktree-testing.md
  • ui/CLAUDE.md

📝 Walkthrough

Walkthrough

This PR establishes comprehensive documentation standards and pattern catalogs across backend and frontend, updates agent guidance to reference these materials, and enforces database field consistency through migration standardization and CI validation.

Changes

Documentation and Pattern Standards

Layer / File(s) Summary
Agent guidance updates and correctness rules
.agents/AGENTS.md
Updated agent direction to establish documentation-first workflow, added domain invariants and correctness rules (feature extractor constraints, timezone usage, schema boundaries, error handling), consolidated database/query guidance into reference docs, shortened chaos-testing procedures, and added pointers to new agent reference materials and bot interpretation guidance.
Documentation index and catalog
docs/claude/INDEX.md
Created searchable documentation index with guidance to search first, organized reference materials, architecture notes, debugging runbooks, planning docs, archived snapshots, and external references including .agents/* and ui/CLAUDE.md.
Backend patterns and query optimization reference
docs/claude/reference/canonical-patterns.md, docs/claude/reference/query-patterns.md
Added canonical patterns reference for reusable backend conventions (serializers, permissions, schema locations, update hooks) and comprehensive query patterns guide covering core model relationships, indexed field usage, preferred select/prefetch patterns, custom QuerySet methods across models, and ORM anti-patterns with corrections.
Frontend conventions and practices
ui/CLAUDE.md
Documented React/TypeScript conventions including i18n string handling via translate(STRING.KEY), typed data service models, React Query hook patterns, async mutation and null/empty state handling, accessibility labeling, naming conventions (kebab-case files, SCREAMING_SNAKE constants), and lint/format configuration expectations.
Worktree testing documentation
docs/claude/reference/worktree-testing.md
Documented two workflows for testing Git worktree changes: bind-mounting subdirectories into main Docker Compose stack, or running isolated duplicated stack with separate ports and volumes, with decision guidance based on change type.

Database Field Standardization and CI Enforcement

Layer / File(s) Summary
Job field standardization and migration check
ami/jobs/migrations/0023_alter_job_job_type_key.py, .github/workflows/test.backend.yml
Django migration updates job_type_key with explicit choice set (ml, populate_captures_collection, data_storage_sync, unknown, data_export, post_processing), default "unknown", and CI workflow adds makemigrations --check --dry-run validation to ensure migrations are properly tracked before test execution.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly Related PRs

  • RolnickLab/antenna#1023: Introduces the initial .agents/AGENTS.md agent instruction documentation that this PR expands and corrects.

Suggested Reviewers

  • carlosgjs

Poem

A rabbit's paws dance 'cross the docs so bright,
From AGENTS to INDEX, from patterns to light,
With queries and fields all properly aligned,
And frontend conventions of well-ordered mind,
The codebase now sparkles with guidance and grace! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: adding review checklists, domain invariants, and a migration CI gate to agent instructions, matching the PR's primary objectives.
Description check ✅ Passed The description is comprehensive, following the template structure with Summary, List of Changes, Detailed Description, How to Test, and Checklist sections. All required information is included with clear explanations of what was changed and why.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch docs/agent-instructions-restructure

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

Pull request overview

This PR restructures and expands the repository’s agent/contributor guidance by moving large reference material into docs/claude/, adding “definition of done” checklists + domain invariants, and introducing a CI gate to fail builds when model changes are missing migrations (plus adding the migration that gate detects on main).

Changes:

  • Add a backend CI step to enforce “no missing migrations” (makemigrations --check --dry-run) and include the missing state-only migration for Job.job_type_key choices.
  • Split previously always-loaded guidance into focused “load on demand” reference docs under docs/claude/ (index + canonical patterns + query patterns + worktree testing).
  • Add a dedicated frontend conventions doc (ui/CLAUDE.md) and expand .agents/AGENTS.md with invariants/checklists and pointers to the new docs.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
ui/CLAUDE.md Adds frontend-specific conventions and tooling guidance.
docs/claude/reference/worktree-testing.md Extracts worktree testing instructions into a dedicated doc.
docs/claude/reference/query-patterns.md Adds a query patterns + schema reference doc extracted from agent instructions.
docs/claude/reference/canonical-patterns.md Documents reusable backend patterns with file:line pointers.
docs/claude/INDEX.md Introduces an index for agent-oriented docs.
ami/jobs/migrations/0023_alter_job_job_type_key.py Adds the state-only migration updating Job.job_type_key choices.
.github/workflows/test.backend.yml Adds CI migration check step to fail on missing migrations.
.agents/AGENTS.md Adds invariants/checklists and points to the new reference docs; removes bulky inline reference sections.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/claude/INDEX.md
@@ -0,0 +1,58 @@
# docs/claude/ Index
| Pattern | Where | Use for |
|---|---|---|
| `SingleParamSerializer` | `ami/base/serializers.py:108` (usage: `ami/base/views.py:47`) | Validating individual GET params — returns 400 on bad input instead of a 500 |
| `url_boolean_param()` | `ami/utils/fields.py:5` (usage: `ami/jobs/views.py:126`) | Boolean query params, e.g. `?incomplete_only=true` |

#### Option A — Bind-mount worktree subdirs into main stack (preferred for code-only changes)

Main `docker-compose.yml` mounts `.:/app:z`. You **cannot** override the `/app` mount itself (Docker keeps both, the broader one wins for path resolution), but you **can** mount a deeper path on top of it. Add to `/home/michael/Projects/AMI/antenna/docker-compose.override.yml` (note: that file is a symlink to `docker-compose.override-example.yml` by default — break the symlink first by `rm`-ing it, then write a real file copying the example contents):
django:
volumes:
- ./compose/local/django/start:/start # keep existing entries from example
- /home/michael/Projects/AMI/antenna/.claude/worktrees/<branch>/ami:/app/ami:z
Comment thread ui/CLAUDE.md
Comment on lines +28 to +29
- Disable mutation buttons while the request is in flight (React Query `isLoading` /
`isPending`). A fast double-click must not enqueue duplicate jobs.
Comment on lines 48 to 55
- name: Run DB Migrations
run: docker compose -f docker-compose.ci.yml run --rm django python manage.py migrate

- name: Check for missing migrations
run: docker compose -f docker-compose.ci.yml run --rm django python manage.py makemigrations --check --dry-run

- name: Run Django Tests
run: docker compose -f docker-compose.ci.yml run --rm django python manage.py test
Comment thread .agents/AGENTS.md
```python
# UNIQUE constraint - perfect for lookups
(deployment, group_by)
- **Always filter by `project` first** on Occurrence/SourceImage/Event queries — the composite indexes lead with it, and it enforces visibility.
@mihow

mihow commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

Folding these commits into fix/ci-concurrency-per-workflow so the CI workflow changes ship together. Superseded by the new PR from that branch.

@mihow mihow closed this Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants