xai / grok-4.7-efficient / low / low effort preferred over deepseek / deepseek-flash / none / unknown effort · clear win.
Primary judge: Sol 6.1, requested Low. Effective provider effort and internal attempts were not verified. A close win is still a scored preference; it does not establish a material defect.
Reviewed public evidence
Task goal
Audit [REDACTED: private project name] QA/QC flag review and correction flow for data-loss, stale-state, and invalid-transition defects across queue selection, edit/save, and refresh. Report only defects demonstrable from supplied code, with exact trigger and state transition, smallest safe fix, and targeted regression scenarios.
xai / grok-4.7-efficient / low / low effort answer
The supplied files contain six demonstrable defects. The edit/save persistence and query invalidation inside `useRevalidate`, `useQaqcQueue`, and `useInspectionValidation` are outside the packet, so those paths are not treated as proven.
## Defects
1. **QA review `pending`/`running` is a sink (stale state).**
Trigger: `useQAReview` returns `status: 'pending' | 'running'`, including after `useTriggerQAReview` succeeds and invalidates once (`qaReview.ts` 57–59).
Transition: any review → `QAReviewPanel.tsx` 67–75 spinner. That branch has no poll, no error, and no re-run control. Nothing in these files schedules another fetch.
Fix: while status is `pending` or `running`, set `refetchInterval` (about 2s) and a timeout/failure exit that restores re-run. Do not early-return without a refresh path.
Regression: POST/GET returns `running`, then a later GET returns `completed` with flags; UI must leave the spinner without a remount. A still-`running` result after the timeout must show failure + re-run, not spin forever.
2. **Initial QA fetch failure is shown as “no review” (invalid transition).**
Trigger: `useQAReview` errors (`isLoading === false`, `data` undefined). `isError` is never read (`QAReviewPanel.tsx` 32–41).
Transition: fetch error → “No QA review has been run” + Run.
Fix: if `isError`, render the error and retry; only the success-null case may show “no review”.
Regression: 404/null still shows Run; 500 does not, and Run is not offered as if no review exists.
3. **Failed QA run is rendered as a normal completed review.**
Trigger: `review.status === 'failed'` after the `pending`/`running` check (`QAReviewPanel.tsx` 78–146).
Transition: `failed` → health badge, summary, and flags, with no failed banner. Empty flags do not show the pass line (that requires `completed`), but the layout is still the success layout.
Fix: explicit `failed` branch with the server summary and re-run; do not render health/flags as a finished pass.
Regression: `failed` with leftover flags must not look like a completed review; `completed` + no active flags still shows the pass line.
4. **Keyboard revalidate allows overlapping runs (invalid transition).**
Trigger: `r` calls `runRevalidate` (`QAQCPage.tsx` 106–109, 164–166) with a new `crypto.randomUUID()` and no `revalidate.isPending` check. The pending flag is only passed to the child button (230).
Transition: in-flight revalidate → second mutate for the same inspection, different idempotency key. Completion order is unconstrained here.
Fix: return immediately in `runRevalidate` when `selectedInspectionId === null` or `revalidate.isPending`.
Regression: double `r` and button + `r` send one request; a new `r` after settle sends one new request.
5. **Error index survives a same-length validation refresh (stale selection).**
Trigger: `errors` is replaced (revalidate/refetch) with the same length. The only resync is the shrink clamp (`QAQCPage.tsx` 115–119). `Enter` then uses that index (`88–92`, `161–163`).
Transition: selected error A at index i → list replaced, index i still selected → `Enter` focuses a different error.
Fix: when the validation result identity changes (`dataUpdatedAt` or an error-id fingerprint), reset `selectedErrorIdx` to 0 and clear `focusedField` unless the focused error id is still present.
Regression: length shrink still clamps; same-length reorder does not `Enter` into the old index’s new row; switching inspection still starts at 0.
6. **Refresh drops the correction position; `n` / `gg` do not move through the queue (data-loss + invalid transition).**
Trigger A: open an error (`applyFocusedParams` writes `tab`/`obs`/`focus` only, `QAQCPage.tsx` 36–48), then reload. Init state is `selectedInspectionId === null` and `focusedField === null` (59–61). No effect reads those params, and inspection id is never written.
Transition A: focused correction → refresh → empty error list and editor.
Trigger B: `n` uses only `queueQuery.data.items` and `items[currentIdx + 1] ?? items[0]` (94–98). Missing id (`findIndex === -1`) or last row selects `items[0]` on this page. `gg` selects `items[0]` of the current page (101–104), not page 1.
Transition B: last row or page > 1 → first row of the same page, not the next unresolved inspection or the top of the queue.
Fix: persist `inspection_id` in the query string; hydrate selection and focus from the URL when the queue/validation data contains that id. For `n`, if the current id is last or absent, request the next page instead of wrapping; for `gg`, set `page=1` and select the first item of that result.
Regression: reload restores the same inspection and field; `n` on the last row of page 1 loads page 2 rather than row 0; `gg` on page 3 lands on page 1 row 0.
## Discarded
- The default React Query behavior does not prove that the validation `data` from inspection A is shown after selecting B. These files never check `data.inspection_id === selectedInspectionId`, but the mismatch is not established without `qaqc.js`.
- Unsaved editor loss on `selectInspection` is not established; `QaQcEditPanel` is outside the packet. The page does clear `focusedField` with no dirty check.
- Flag-id reuse across QA runs hiding new flags is not established; only client filtering is visible (`QAReviewPanel.tsx` 15–19).
- Dismiss/trigger `onSuccess` invalidates the mutated `inspectionId`, not a stale prop. That part is correct.
## Missing evidence
`client.js`, `qaqc.js`, `QaQcEditPanel`, `QaQcErrorList`, `QaQcQueueList`, and `FlagCard` are outside the packet. Whether revalidate or dismiss actually refreshes server state, and whether the editor saves, cannot be judged here. The defects above are client state-machine bugs visible without those files.
## Next action
Add regression tests for the six transitions above, then apply the four local guards: poll/exit for `pending`/`running`, separate `isError` and `failed`, single-flight `runRevalidate`, and URL hydration plus non-wrapping `n`/`gg`.
deepseek / deepseek-flash / none / unknown effort answer
I'll analyze the three supplied files for data-loss, stale-state, and invalid-transition defects in the QA/QC flag review and correction flow.
## Evidence Packet
### 1. Defect: Dismissed-flag state is derived only from server-cached `dismissed_flags`; the flag list itself is not filtered server-side
**Location:** `qaReview.ts:63-81` (`useDismissFlag`), `QAReviewPanel.tsx:15-19`.
**Mechanism:** `useDismissFlag.onSuccess` only calls `qc.invalidateQueries({ queryKey: ['qa-review', inspectionId] })`. The panel recomputes `dismissedIds` from `review.dismissed_flags` and filters `review.flags`. So correctness of the dismiss UI depends entirely on the refetched payload carrying both an updated `dismissed_flags` array *and* an unchanged `flags` array.
**Trigger/transition:** Dismiss flag F → POST succeeds → invalidate → refetch in flight. Until the refetch resolves, the flag still renders (because the cache still holds the pre-dismiss `dismissed_flags`). If the server is eventually consistent, or returns flags without appending to `dismissed_flags`, F reappears with no local optimistic state to prevent it. There is no `onMutate`/rollback, so the UI offers no feedback and no reconciliation if the response omits the dismissal.
**Severity:** Stale-state / silent-failure. Not demonstrable as data loss within the packet alone — it requires knowing the server contract, which is **outside the packet** (`apiClient`, backend). Report as conditional.
**Smallest safe fix:** In `useDismissFlag`, add an optimistic `onMutate` that snapshots the `['qa-review', inspectionId]` cache, appends `{ flag_id: flagId, ... }` to `dismissed_flags`, and rolls back `onError`; keep `onSuccess` invalidation. This makes the dismissal idempotent-looking on the client regardless of refetch timing.
**Regression scenarios:** (a) dismiss then immediately refetch with a delayed/unchanged payload; (b) dismiss two flags concurrently; (c) dismiss on a flag whose `id` collides with an existing `dismissed_flags.flag_id`.
### 2. Defect: `useQAReview` has no `staleTime`/polling, but `QAReviewPanel` treats `running`/`pending` as terminal-render states
**Location:** `qaReview.ts:39-48`, `QAReviewPanel.tsx:66-76`.
**Mechanism:** When `review.status` is `'running'` or `'pending'`, the panel renders a static "QA review in progress..." spinner and returns. The query has no `refetchInterval`, and nothing invalidates `['qa-review', inspectionId]` on a timer. The only paths to a status change are a manual re-run (`handleTrigger`) or an external invalidation.
**Trigger/transition:** Trigger QA check on a review already in `running`/`pending` → component renders progress state → unless some other factor invalidates the query, the UI stays "in progress" indefinitely even after the backend completes. This is a **stale-state defect** (stuck loading), demonstrable from the supplied code because no polling mechanism exists in the packet.
**Caveat:** The actual completion signal may arrive via the trigger mutation's `onSuccess` invalidation or via external websocket/global invalidation outside the packet. If a websocket exists (not in packet), this is mitigated. Report as *conditional on absence of external invalidation*.
**Smallest safe fix:** Add `refetchInterval` guarded on running/pending status, e.g. a small `refetchInterval: (q) => (q.state.data?.status === 'running' || q.state.data?.status === 'pending') ? 2000 : false` in `useQAReview`.
**Regression scenarios:** (a) review transitions running→completed, assert panel updates within interval; (b) a completed review must not poll; (c) disabled query (`inspectionId` null) must not poll.
### 3. Defect: `useTriggerQAReview` invalidation is not awaited and the trigger button remains enabled immediately after `'running'`
**Location:** `qaReview.ts:50-61`; `QAReviewPanel.tsx:28-30, 49-57, 89-97`.
**Mechanism:** `triggerReview.isPending` is true only during the POST. Once it succeeds, `isPending` is false and the button re-enables. If the POST creates a *new* run whose `status` is `running`, the panel only reflects that after the invalidation refetch resolves. Between POST success and refetch, `review` is the *old* completed review (e.g. `run_number N`), and the user can click "Re-run QA" again, producing another run.
**Trigger/transition:** Click Re-run → POST succeeds → `isPending` false → old completed review still cached → click Re-run again → duplicate QA runs. This is an **invalid-transition / duplicate-mutation** defect demonstrable from the code.
**Smallest safe fix:** Disable the button when `triggerReview.isPending || review.status === 'running' || review.status === 'pending'`, and/or optimistically set the cached review status to `running` in `onSuccess` before invalidating.
**Regression scenarios:** (a) double-click on Re-run issues exactly one POST; (b) after the refetch, run_number increments once; (c) button disabled while status is running.
### 4. Observation (not a demonstrated defect): `selectedInspectionId` is not persisted or synced from URL
**Location:** `QAQCPage.tsx:59-61, 75-80, 94-104`.
**Mechanism:** `selectedInspectionId` lives only in `useState`. `selectInspection` writes `tab`/`obs`/`obs_idx`/`focus` params via `applyFocusedParams(prev, null)` but **not an inspection id**. On refresh or back-navigation, `selectedInspectionId` resets to `null` while the focus params (e.g. `?tab=full_log&obs=123`) may persist, and `focusedField` also resets to `null`.
**Trigger/transition:** Select inspection → `Enter` on an error (sets `focus`, `obs`) → refresh page → `selectedInspectionId` is `null`, `focusedField` is `null`, but URL still carries `obs=...`/`focus=...`. The URL now claims a focus target the component does not resolve. These are the **stale-URL-state** symptoms the question asks about, but the packet does not show a reader that hydrates `focusedField` from URL params; whether this is a true defect depends on `QaQcEditPanel` (outside packet) possibly reading params itself.
**Assessment:** Cannot be confirmed as a defect from the packet alone. If `QaQcEditPanel` independently reads URL params, behavior could be correct. Flag as **uncertain, dependency outside packet**.
### 5. Observation (not a defect, but a latent indexing hazard): `j`/`k`/`Enter` operate on `errors` that can change identity during async validation
**Location:** `QAQCPage.tsx:88-92, 127-128, 142-188`; `validationQuery` at line 70-73.
**Mechanism:** `openErrorInEditorRef.current(selectedErrorIdxRef.current)` uses the current index into the current `errors` array. `errors` is recomputed each render from `validationQuery.data`. There is a guard at 115-119 to clamp `selectedErrorIdx`, but that runs in an effect *after* render. React Query refetcafter a successful `revalidate.mutate` (line 106-109) can replace `errors` with a different array/order.
**Trigger/transition:** User highlights error at index k → revalidate resolves and reorders/replaces `errors` → before the clamp effect runs, `Enter` opens `errors[k]` which is now a *different* error than the highlighted one. This is an **index-vs-identity** stale-state defect. It is a real hazard, but whether revalidation actually reorders errors is not established by the packet.
**Smallest safe fix:** Key selection by a stable error identity (e.g. `observation_id` + `field_path` from `NasscoErrorEntry`) rather than numeric index; or reset/clamp `selectedErrorIdx` synchronously in `openErrorInEditor` by comparing against a captured identity.
**Regression scenarios:** (a) revalidate that removes an error above the selected index, then Enter; (b) revalidate that reorders errors, then j/k/Enter; (c) empty errors followed by Enter.
### 6. Observation: `nextUnresolvedInspection` advances to `items[currentIdx + 1]` without filtering unresolved items
**Location:** `QAQCPage.tsx:94-99`.
**Mechanism:** Despite the name "next unresolved," the function naively advances one index and wraps to `items[0]`. If `selectedInspectionId` is not found in `items` (e.g. it was filtered out by the current `status`/`page` query, or the user navigated pages), `currentIdx` is `-1` and `items[0]` is selected — a surprising jump.
**Assessment:** This is a naming/behavior mismatch and a possible invalid transition, but the question is specifically about flag review/correction flow. It is in-scope peripherally. Demonstrable as a logic observation, low severity.
## Summary
| # | Defect | Demonstrable from packet? |
|---|--------|----------------------------|
| 2 | Stuck "in progress" — no polling | Yes (conditional on no external invalidation) |
| 3 | Duplicate QA runs via re-enabled Re-run button | Yes |
| 1 | Dismiss relies solely on refetch; no optimistic state | Mechanism yes; harm conditional on server contract |
| 5 | Index-based selection vs. changing `errors` array | Hazard yes; reorder behavior unproven |
| 4 | Selected inspection not reflected in URL; focus params orphaned on refresh | Uncertain (depends on `QaQcEditPanel`) |
The two defects I can assert cleanly from the packet alone are **#2 (no polling for running/pending)** and **#3 (re-enabled Re-run enabling duplicate runs)**. #1 and #5 require knowing backend/component contracts outside the packet; #4 requires `QaQcEditPanel`.
**Missing evidence / dependencies and consequence:**
- `./client` (apiClient behavior: does it throw? retry? transform `dismissed_flags`?) — affects whether dismiss failures surface.
- Server endpoints for `qa-review`, `dismiss`, `qa-summary` — determines whether `flags` is filtered server-side and whether refetch returns updated `dismissed_flags`.
- `QaQcEditPanel.js` — determines whether URL params hydrate `focusedField` (defect #4) and how save is performed.
- `QaQcErrorList.js`, `QaQcQueueList.js` — determine whether `errors` reorder and whether `n`/`g g` semantics match.
- `../api/qaqc` (`useRevalidate`, `useInspectionValidation`) — determines refetch/reorder behavior for defect #5.
**Next useful action:** Confirm defect #2 and #3 first (self-contained, high confidence); then supply the backend dismiss contract and `QaQcEditPanel.js` to resolve #1 and #4.
MATERIAL_EVIDENCE_CONFLICT: The packet describes a keyboard listener "registered ONCE on mount" (QAQCPage.tsx:121-188, empty deps) while several handlers dispatch through `*Ref.current` that are reassigned every render (lines 127-140); state freshness depends entirely on refs, not the effect deps — the inline comment's claim of non-reactivity is accurate for the listener but the ref-reassignment pattern means behavior after prop/callback replacement is not verifiable from the packet alone.Primary judge's stated reason
A offers better demonstrated transition coverage and more immediately usable remediation for query-error rendering and repeated keyboard revalidation. B's useful trigger/refetch race and greater caution on some hypotheses do not offset those omissions and its unsupported conflict claim. This is a clear comparative advantage in audit usefulness, not a claim that every finding in A is established.
This reason is the judge's assessment. No independent factual-defect finding is asserted by this record.
Battle wave: 73088e6c-242b-4408-960f-d09feaae160d. Pair: brp1_83b0a6f28d46da36809ed514acada58f03f2b0d399d2a9569f5416d866c6a2f1. A separate independent review is required before calling a concern a verified factual defect. Judge disagreement is not recorded here.