--- name: code-review-agent description: The working guide for effy-fe — reviewing code for bugs, gating a branch before a PR, keeping GraphQL codegen in sync, and writing user-facing UI copy. Use when asked to review a diff, branch, PR or component; to check whether a branch is ready to push; when a build fails with missing generated types or after touching a .graphql file; and whenever writing or auditing any user-facing string in apps/mgsa, apps/analytics or packages/yooeye. --- # Code Review Agent One guide, four jobs. Read the section you need; they are independent. | Doing this | Go to | | ----------------------------------------------- | ------------------------- | | Reviewing code for bugs | §1 Review, §2 Bug classes | | Getting a branch ready to push | §3 Pre-PR gates | | Touched a `.graphql` file, or types are missing | §4 Codegen | | Writing or auditing a user-facing string | §5 UI copy | Stack: pnpm + Vite+ monorepo, React 19, TypeScript 7, Tailwind 4, urql + graphql-codegen, react-aria-components. **Not Next.js** — ignore any advice about RSC, `"use client"`, hydration, streaming, `next/font` or `next/image`. None of it applies here. **Never** commit, push, open a PR, amend history, or use `--no-verify` unless asked in the moment. Report; let the user act. --- ## 1. Review ### Reference docs Review against these. A violation of any of them is a finding: - [`docs/engineering/backend-contract.md`](../../../docs/engineering/backend-contract.md) covers opaque IDs and keeping logic, search, filter, sort and pagination on the backend. - [`docs/engineering/component-reference.md`](../../../docs/engineering/component-reference.md) says which component to use for forms, async states, picklists, pagination and filters. A hand-rolled replacement for one of them is a finding, including filter dropdowns, filter `useState` or URL params instead of `useFilterState` and the filter bar. - [`docs/engineering/graphql.md`](../../../docs/engineering/graphql.md) covers operations, codegen, the two urql clients and graphcache updaters. ### Scope Take the target from the user. If they did not name one, review the branch against its base, and include uncommitted work — that is usually what they mean. The base is **`origin/hangar`** — the only base for now. Do not detect or fall back to `airspace`: ```bash git status --porcelain git fetch -q origin BASE=$(git merge-base HEAD origin/hangar) git diff --stat "$BASE" ``` The bare `"$BASE"` (not `"$BASE"..HEAD`) is deliberate — it includes staged and working-tree changes. State the base and file count in one line before starting. Stop if the diff is empty. Report uncommitted or untracked files that look like part of the change. Do not stage them. ### Read the file, not the hunk **Open every changed file in full before judging it.** Diff hunks hide the thing that makes a finding real or bogus: the guard twelve lines up, the early return, the cleanup in a different effect. Two greps that repeatedly change the verdict: - **Who calls this?** A changed signature or a new nullable return is only a bug at a call site. Find them before claiming breakage. - **What else touches this state?** Grep the hook or store name across the feature folder. If a finding depends on context you have not read, read it or drop the finding. ### Verify before reporting The failure mode is not missing a bug — it is twenty findings of which three are real, because then nobody reads the list. **A short report that is all true beats a long one that needs triage.** Zero findings is a valid outcome; say so plainly. Apply to every candidate, in order: 1. **Write the failure.** Concrete inputs or state → what actually goes wrong. If you cannot write that sentence, it is not a finding. 2. **Try to refute it.** Look for the guard, the default, the early return, the caller that makes it unreachable. Most first-pass candidates die here. 3. **Confirm it is in scope.** If the same code exists untouched on the base, it is pre-existing. Mention at most the one or two most serious, clearly labelled. 4. **Confirm the fix.** Name the specific change. "Consider refactoring" is not a fix. Only report a gap you have evidence for. Checked and missing → finding. Checked and present → omit. Could not check → say so, phrased as a question. Never guess about something that would produce a fabricated finding. Every finding needs three parts: **where** (file and line, never "the app"), **what happens now** (actual current behavior, not the absence of an ideal), and **why it matters** (consequence for the user or the team). > Bad: "Missing error state on the dashboard." > > Good: "`dashboard-metrics.tsx:42` renders `data.map(...)` with no rejection branch. When > the query returns an error the component throws and the nearest boundary blanks the whole > dashboard — empty screen, no explanation, no retry." **Do not report:** formatting or import order (`vp check` owns it); missing tests as a general observation (the repo has ~60 test files, mostly pure logic and hooks — raise it only where the change is genuinely risky, and say why); naming preferences; speculative performance with no measurement; the same pattern in eight files (report once, with a count). ### Severity Assign by **impact**, not by how hard it is to fix. A one-line fix for a data-loss bug is Critical; a two-week polish rewrite is Minor. - **Critical** — blocks release. User cannot complete a core task, loses work, or is misled about their data. A race that persists wrong data. Auth enforced only on the client. Secrets in client code. One component throwing blanks the app. A primary flow impossible by keyboard. - **Major** — fix before or right after release. Missing loading/empty/error state causing real confusion. Error with no recovery path. Double submission on an action with side effects. Deep link, refresh or back breaking the view. Derived state stored and synced by an effect. `any` on an API boundary. Focus lost or invisible after a significant interaction. - **Minor** — noticeable friction, user not blocked. Spinner where a skeleton belongs. Naming, magic values, dead code. Missing memoization with no measured cost. - **Nice-to-have** — real improvements the feature does not require. Keep separate from Minor, or the whole list reads as optional. **Frequency and context escalate.** A Minor annoyance on a screen every user hits ten times a day is Major. The same missing empty state is Major on a signup flow and Minor on an internal admin tool. Say so in the finding when it changes the call. ### Output Open with one line: base, files reviewed, and the headline — the single most important thing to fix, or that you found nothing. Then findings, most severe first: > **[Severity] Short title** — `path/to/file.tsx:42` > What is wrong, and the failure it produces. > **Fix:** the specific change. Close with **Not reviewed** — anything skipped, unopenable, or out of scope. A reviewer who silently skips something is worse than one who says what they skipped. Order by impact, not by checklist order. Omit empty sections rather than writing "None found" under four headings. Naming what is well handled is worth one line — it shows you looked, and protects good work from being refactored away. --- ## 2. Bug classes that actually recur here Ordered by how often they are genuinely wrong in this codebase. Everything here is a **candidate** — §1's verify pass decides. ### urql and GraphQL Background for all of these is in `docs/engineering/graphql.md`. - **Wrong client.** A productivity hook rendered outside `ProductivityClientProvider` fails at runtime, not compile time — check provider nesting for new top-level routes and portals. The highest-value check here. - **Missing graphcache updater.** A new create/delete mutation with no entry in `packages/productivity-api/src/cache/mutations.ts` leaves stale lists on screen. Invisible in the diff, and recurring. Refetching in the component instead is also a finding. - **`pause` and variables.** Unready variables with no `pause` fire a bad request; a variables object rebuilt inline each render can loop. - **Deep imports**, never a barrel. - **`TS2307: Cannot find module '*/generated/*'` is not a bug in the diff** — see §4. ### React 19 - **Infinite re-render loops — Critical, always.** An effect that unconditionally sets state listed in its own dependency array; a dependency object, array or function rebuilt inline every render (deps compare with `Object.is`, so a fresh reference re-fires the effect each time — the urql variant is an inline-built `variables` object looping the request); a `setState` inside an effect with no dependency array. - **State derived in an effect** — the single most common React defect. A `useEffect` whose only job is `setX` from props or other state should be computed during render. Filtered, sorted or totaled lists stored in state instead of derived. State initialized from props with no key reset, so it goes stale. Resetting state when an identity prop changes is done with `key`, not an effect. - **Chained effects** — effect A sets state that triggers effect B. Collapse into one computation or one handler. - **Effects that are not synchronization.** For each `useEffect`, ask what external system it syncs with. "Nothing" means it probably should not exist — reacting to a user action belongs in the handler. - **Missing cleanup and stale closures.** Subscriptions, timers, listeners, observers, abort controllers. Async work resolving after unmount. A dependency removed to silence the lint rule is a symptom, not a fix. - **Races.** Fast-changing args (search, filter, tab) where an earlier response resolves after a later one and overwrites it. Look for an abort controller or a request-id guard. Submissions with no in-flight guard **on the handler itself** — disabling a button via a state update that lands after the second click is not prevention. - **Keys.** Array index as key on a list that reorders or filters; keys from unstable values. A deliberate `key` change to reset state is a valid pattern — recognize it rather than flag it. - **Context.** Provider value not memoized, so every consumer re-renders. A frequently changing value in a context read by a wide subtree. - **Memoization, in both directions.** `React.memo` on a component receiving a new inline object every render never helps. `useMemo` on trivially cheap work is noise. The bar is a measured or clearly reasoned cost — say which. - **New state derived from old** uses the functional form (`setCount(c => c + 1)`). Two stale-closure increments in one handler is a real bug, not a nit. For every effect flagged, name the replacement — _derive in render_, _move to handler_, _`key` reset_, _`useMemo`/`useRef`_, _add cleanup/abort_, or _delete_. "Consider removing this effect" is not a fix. ### TypeScript - `any`, `as`, or non-null `!` on data from the network, `localStorage`, a URL param, or `JSON.parse`. An assertion over unvalidated external data is a crash waiting for one null field. `unknown` at a boundary followed by real narrowing is correct — do not flag it. - `as unknown as T` almost always hides a real problem. - Optional properties where a discriminated union expresses the real shape. `{ data?, error?, loading? }` permits states that cannot exist. - Optional chaining hiding a genuine "this should never be undefined" — silent wrong behavior is worse than a throw. - A widened or loosened exported type: check consumers. ### Translation keys (mgsa, analytics) Rules and examples: [component-reference.md](../../../docs/engineering/component-reference.md#translation-keys). The lint rule `lyearn-i18n/namespaced-keys` catches literal keys; review for what it can't see. - A key built with `${…}` (``t(`status.${s}`)``, ``t(`${base}.title`)``), even inside a helper. Ask for a map of full keys typed `as const satisfies Record>`. - A stored key typed `string` (`labelKey: string`, `Record` of keys), or cast to get past `t` (`as NamespacedKey`, `as never`, `as any`). The fix is a key type, not a cast. - A key without its namespace, or a non-array namespace (`useTranslation("okrs")`). These fail lint, so they mean the check wasn't run. - A map or union of keys copied into a second file. Export it from one place. - A helper calling `i18nInstance.t` or `getFixedT` while a component is above it. It should take the caller's `t` as `t: TFunction<["ns"]>`. ### react-aria and yooeye - A diff that strips `aria-*`, keyboard handlers or focus management from a react-aria-components-based component is a **regression**, not a style question. - A component flipping between controlled and uncontrolled — `value` becoming `undefined` on a later render. - **yooeye sweep — every changed component, not only new ones.** For each changed `.tsx`, list the UI it renders (button, input, select, badge, tooltip, tabs, drawer, modal, empty/error/loading view, chart) and confirm each comes from `@lyearn/yooeye`. Anything hand-rolled — a raw `