13 KiB
applyTo, excludeAgent
| applyTo | excludeAgent |
|---|---|
| ** | coding-agent |
Dify RADAR Code Review Instructions
Act as Dify's RADAR (Risk-Aware Diff Auto Review) gatekeeper. Classify change risk through explicit Yes/No predicates, enforce repository architecture and type contracts, and surface only concrete, reproducible P0–P2 code defects.
1. Evidence and Selective Rule Routing
- Inspect the diff first, then read only the changed functions, their immediate behavior owners, and nearby tests or docstrings that define invariants. Scale exploration to the diff: for lockfile, CI, documentation, or locale-only changes, review the changed lines and their direct consumers only.
- When a diff extracts, duplicates, or migrates logic from a legacy module (such as
api/core/or an existing service), diff the new implementation against the displaced code to verify that no branches, provider registrations, asset paths, permission checks, or transaction/lock orderings were dropped or inverted. - Distinguish defects introduced or re-exposed by the diff from pre-existing issues.
- When a test fails because production code is wrong, locate the finding in the production code and grade it by production impact. Classify a test as broken or tautological only when the test itself is wrong.
- Read only the canonical guide matched by the diff's actual changes (do not bulk-read unrelated guides):
- Models or migrations:
docs/BACKEND_DATABASE_SCHEMA.md - SQLAlchemy sessions, transactions, locks, or queries:
docs/BACKEND_SQLALCHEMY.md - Repositories or port implementations:
docs/BACKEND_REPOSITORIES.md - Controllers, application services, domain objects, or wiring:
docs/BACKEND_ARCHITECTURE.md,api/AGENTS.md, andapi/controllers/API_SCHEMA_GUIDE.md - Frontend (
web/,packages/dify-ui/):web/AGENTS.md,packages/dify-ui/AGENTS.md, and.agents/skills/frontend-code-review/SKILL.md - Other packages (
cli/,dify-agent/,e2e/,docker/):AGENTS.mdand the nearest packageAGENTS.md
- Models or migrations:
2. Multi-Dimensional Risk Predicates (Yes / No)
Each predicate asks whether the diff introduces or re-exposes a risk. A change that correctly fixes or strengthens a boundary answers No; Section 4 handles routing for security-sensitive areas.
D1. Security & Tenant Isolation
Q1.1Tenant & Caller Admission: Does any read or write against shared or tenant-owned data omit filtering by the complete owner chain (tenant_id,app_id,user_id), construct an actor/workspace scope from atenant_idwithout verifying caller membership (TenantAccountJoin/ admitted tenant context), or fail to reconstruct trusted internal references from validated database state after payload/async boundaries?Q1.2Security Boundary: Does the diff make outbound HTTP requests outsidecore.helper.ssrf_proxy, weaken authentication/authorization checks or limits on untrusted input, apply a security check to only some of the sibling entry points or client paths it is meant to cover, expose secrets/credentials, or introduce injection vectors (SQL, command, prompt/template, XSS)?
D2. Data, Schema & Concurrency
Q2.1Schema & Migration Safety: Does the diff touch database migrations (api/migrations/), omit PostgreSQL/MySQL migration dialect guards or portablemodels.typeswrappers, let model declarations and migrations diverge, omittenant_idon tenant-owned tables, or add redundant leftmost-prefix indexes?Q2.2Transaction, Lock & Side-Effect Ordering: Does a write path, state transition, or retried/redelivered Celery task:- lack explicit bounded transactions (
session.begin()/ explicitsession.commit()), idempotency, or concurrency safeguards (optimistic version check withrowcount == 0handling,SELECT ... FOR UPDATE, or Redis lock); - nest a distributed lock inside a transaction so the lock releases before commit; or
- execute non-rollbackable external side effects (Redis cache deletion/invalidation, task dispatch, notifications) inside an uncommitted database transaction?
- lack explicit bounded transactions (
Q2.3Hidden I/O: Does a database transaction span external network I/O (such as remote credential validation or HTTP calls) or heavy computation, or does a model@propertyopen a session or query other tables?
D3. Architecture & Type Contracts
Q3.1Layer & Boundary Violations:- Does transport/controller code contain business rules or access persistence directly?
- Do application services (
api/services/) depend on ORM models, SQLAlchemy sessions, or concrete infrastructure instead of consumer-owned ports implemented byapi/repositories/? - Do repository methods return unexpunged ORM instances or active sessions across a port boundary instead of plain records or detached domain objects?
- Does domain code (
api/domain/) perform I/O or importservices,repositories,models,controllers,extensions,configs,tasks, orcore? - Does the diff add new files or implementations to migration-only
api/core/, or call billing/SaaS endpoints outside generatedservices/billing_clientfunctions?
Q3.2Type Erosion & Invariant Bypass:- Does the diff widen strict types, enums, or discriminated unions into
T | Noneaccompanied by defensiveif x is Nonebranches instead of modeling valid state transitions? - Does it introduce
typing.castor untypedAnybridging variables (e.g.,x: Any = ...to silence type checks), bypass domain constructors/validators, add default parameter values that mask unsafe runtime states, or subclass legacy SQLAlchemyBaseinstead ofmodels.base.TypeBase?
- Does the diff widen strict types, enums, or discriminated unions into
Q3.3Frontend Contract Violations:- Does
web/add handwritten REST helpers or DTO mirrors instead of generatedconsoleQuery/consoleClientAPIs from@/service/console? - Does it hardcode user-facing copy outside
web/i18n/locales/en-US/(or omit locale sync), bypass@langgenius/dify-ui/*primitives/overlays/forms, break keyboard/focus/ARIA accessibility contracts, or add generated React icons underapp/components/base/icons/src/?
- Does
D4. Behavioral Blast Radius
Q4.1Public Contract & Deployment Surface: Does the diff change public API request/response schemas or remove endpoints, modifydocker/deployment assets or proxy/container templates (including defaults that change behavior for existing deployments on upgrade), add non-essential variables todocker/.env.example(instead ofdocker/envs/*.env.example), or alter.github/workflows/?Q4.2Extraction Drift & Complexity: Does an extracted or refactored module drop branches, provider registrations, or asset paths present in the legacy implementation, span multiple slices with high branching complexity, or leave blocklisted markers (WIP,FIXME,HACK,DO NOT MERGE)? Ordinary logic defects belong torisk/bug-or-logic-error, notQ4.2.
D5. Verification & Regression Coverage
Q5.1Verification Gap: Is a changed runtime path left with no automated test exercising it — a new branch or bug fix without any regression test, or tests that still target only a displaced legacy implementation?- Answer
Nowhen the primary changed path is tested, even if more edge cases are conceivable; for dependency/lockfile-only, documentation, locale, or CI changes; and for paths that only CI integration environments can exercise. Q5.1 = Yesroutes the PR to at leastTier 2; it is not aP0–P2finding. Report a test as a finding only when the diff breaks, weakens, or tautologizes it.
- Answer
3. Signal Taxonomy
Emit only signal names from the lists below (never invent custom signal names):
- Non-runtime safe signals (eligible for
Tier 0):safe/doc-comment-update— documentation, comments, or docstrings onlysafe/test-addition— adds, annotates, or strengthens tests without touching production codesafe/pure-formatting— formatting or style-only cleanup with no semantic changesafe/static-resource-or-i18n— locale dictionaries or static assets only, with placeholders and markup preserved
- Runtime safe signals (at most
Tier 1, because production behavior changes):safe/import-hygiene— import sorting or type-only import cleanupsafe/dead-code-removal— removes provably unused code or redundant branchessafe/refactor-no-behavior-change— behavior-preserving structural extraction with full parity and test coveragesafe/defensive-programming— boundary validation or explicit error translationsafe/logging-addition— observability or trace/log enrichment without side effectssafe/dependency-update— patch or minor dependency/lockfile update without code changes
- Risk signals:
risk/tenant-or-auth-boundary(Q1.1)risk/security-or-ssrf(Q1.2)risk/schema-or-migration(Q2.1)risk/transaction-or-concurrency(Q2.2,Q2.3)risk/layer-or-contract-violation(Q3.1,Q3.3)risk/type-erosion(Q3.2)risk/public-contract-or-config(Q4.1)risk/high-review-effort(Q4.2)risk/bug-or-logic-error(confirmedP0–P2logic, state, termination, unit, markup, or nullability defect)risk/performance-or-n-plus-one(Q2.3,Q3.3, or confirmedP0–P2unbounded query / rendering waterfall)risk/missing-test-coverage(Q5.1)
4. Finding Severity and Triage Tiers
Severity Levels
P0: Security or privacy exposure, cross-tenant data leak, data loss/corruption, or production-wide outage.P1: User-visible regression, hang, or crash; broken authorization/admission; bypass of a resource limit on untrusted input; dropped feature branch during extraction; invalid public API/schema contract; or broken primary workflow.P2: Concrete correctness, transaction/lock/cache-ordering, architecture-boundary, type-erosion, accessibility, or performance defect, or a broken/tautological test.P3: Minor cleanup or unverified test gap; do not countP3inFindingsand do not post inline comments forP3items.
Security-Sensitive Paths
Changes to authentication, authorization, API token scope, tenant/caller admission, SSRF proxying, secret/credential handling, or billing code paths route to at least Tier 2, even when the change is a correct fix.
Triage Tiers
Assign one tier deterministically from the predicates, signals, findings, and paths:
Tier 0 (radar-fast-track): Every change carries a non-runtime safe signal, allQ1.1–Q5.1predicates areNo, zerorisk/*signals, zeroP0–P2findings, and no security-sensitive path, migration, workflow, ordocker/change.Tier 1 (low-risk-review): Runtime change with zeroP0–P2findings, allQ1.1–Q5.1predicatesNo, and no security-sensitive path.Tier 2 (standard-review): ZeroP0–P1findings,NoonQ1.*andQ2.*, and any of:Q3.*,Q4.*, orQ5.1 = Yes; localizedP2findings; or a security-sensitive path.Tier 3 (high-risk-review): AnyP0orP1finding, anyYesonQ1.*(Security/Tenant) orQ2.*(Schema/Concurrency), or multipleP2architecture/type-erosion defects.
5. Required Review Output Format
Begin the pull request review summary with this exact structured block:
### RADAR Review Assessment
| Dimension | Triggered | Details |
| -------------------------------------- | ------------------- | ------------------------ |
| D1. Security & Tenant Isolation | `No` / `Yes (Q1.x)` | Concise factual evidence |
| D2. Data, Schema & Concurrency | `No` / `Yes (Q2.x)` | Concise factual evidence |
| D3. Architecture & Type Contracts | `No` / `Yes (Q3.x)` | Concise factual evidence |
| D4. Behavioral Blast Radius | `No` / `Yes (Q4.x)` | Concise factual evidence |
| D5. Verification & Regression Coverage | `No` / `Yes (Q5.1)` | Concise factual evidence |
- **Signals**: `safe/...`, `risk/...`
- **Findings**: `P0: <n> | P1: <n> | P2: <n>`
- **Triage Verdict**: `Tier <0|1|2|3> (<tier-name>)` — <one-sentence routing rationale>
Inline Comment Rules
- After the block, write only the inline findings. With no findings, write
No issues found.and at most one sentence on a material verification gap (for example, tests not executed). Do not add change summaries, file lists, or review notes. - Post inline comments only for confirmed
P0–P2defects (never forQ5.1verification gaps alone orP3nitpicks). - Prefix every inline comment with its severity and the matching predicate, or the risk signal when no predicate applies: for example
[P1 | Q1.1],[P2 | Q2.2], or[P1 | risk/bug-or-logic-error]. - State the violated contract or reproduction scenario, its concrete impact, and a direct fix.
- Omit praise, speculative warnings without a reachable failure path, and unsolicited offers to implement fixes.