xai / grok-4.7-efficient / low / low effort preferred over xai / grok-4.7-efficient / high / high effort · close 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`.
xai / grok-4.7-efficient / high / high effort answer
The supplied code contains eight demonstrable data-loss, stale-state, and invalid-transition defects. Save payloads and query invalidation inside the missing hooks are not established.
## Defects
### 1. Pending/running review is a dead-end (stale state, no exit transition)
**Confidence:** high
**Trigger:** `useQAReview` returns `status: 'pending' | 'running'` (initial GET, or GET after `useTriggerQAReview` invalidates). Typical path: click Run / Re-run, POST returns, `onSuccess` only invalidates, refetch still shows `pending` or `running`.
**Transition:** `QAReviewPanel` takes the early return at lines 67–75 and unmounts flags, dismiss, and the re-run control. `useQAReview` has no `refetchInterval`. Nothing in this component calls `refetch`. The view does not transition to `completed` or `failed` until some outside invalidation.
**Fix:** While status is `pending` or `running`, poll (`refetchInterval`) and show a manual Refetch control. Do not auto-POST again. Keep Re-run off until a terminal status so a stuck job is not double-started.
**Regression:** Mock GET as `running` for two polls, then `completed` with flags. UI must leave “in progress” without a remount. A still-`running` fixture must expose Refetch and must not POST.
### 2. Re-run discards the POST body and overlaps dismiss (stale state + invalid transition)
**Confidence:** high
**Trigger:** On a `completed` review, click Re-run while a dismiss reason is open, or dismiss a flag while `triggerReview.isPending`. `handleTrigger` / `handleDismiss` do not check each other. Re-run `disabled` is only `triggerReview.isPending` (lines 89–97). Flag actions stay live. `onSuccess` ignores `_data` and invalidates (qaReview.ts lines 57–59, 77–79).
**Transition:** Until the follow-up GET settles, `review` stays the previous run and `isPending` is already false, so another dismiss or re-run can target the stale run. `isPending` is not scoped to `variables.inspectionId`, so a prop change to inspection B shows A’s spinner and A’s completion does not update B. If the GET then returns `running`, the early return unmounts FlagCards and drops the in-progress dismiss reason. Last invalidate wins; dismiss and new run are unordered.
**Fix:** `setQueryData(['qa-review', inspectionId], data)` from the POST body before invalidate. Disable dismiss when a trigger for this `inspectionId` is pending, and disable trigger when a dismiss for this id is pending. Treat `isPending` as active only when `variables.inspectionId === inspectionId`.
**Regression:** Re-run response is `run_number: 2, status: 'running'` while the next GET is delayed; UI must show run 2 / in progress, and dismiss must not fire. Switch `inspectionId` mid-mutation; B must not spin or invalidate as A. Dismiss-then-re-run in one tick must be one ordered transition, not two overlapping POSTs.
### 3. Failed review fetch is shown as “no review” (invalid transition)
**Confidence:** high for the branch; medium that Run then creates a second run (depends on `apiClient` reject behavior, outside the packet)
**Trigger:** `useQAReview` errors and `data` is undefined. The panel only reads `isLoading` and `data` (line 11). `isError` is ignored.
**Transition:** `isLoading === false` and `!review` render “No QA review has been run” and an enabled Run button (lines 41–62). A 500/network failure is indistinguishable from an absent review, so Run can POST over an existing review that simply failed to load. Trigger errors are also unread, so a failed POST leaves the old screen with no error state.
**Fix:** If `isError`, render a retry-GET state and do not mount Run. Surface `triggerReview.isError` / `dismissFlag.isError` without clearing the last good `review`.
**Regression:** GET 500 with no cache must not show Run or “passed”/empty copy. GET 404 may still show Run. POST 500 must keep the previous review and show failure.
### 4. Refresh drops the correction target; URL focus is write-only (data loss)
**Confidence:** high
**Trigger:** Select an inspection, Enter an error (`setFocusForError` writes `tab` / `obs` / `obs_idx` / `focus`), then refresh or use Back/Forward.
**Transition:** `selectedInspectionId`, `selectedErrorIdx`, and `focusedField` are `useState` only (lines 59–61). Nothing hydrates them from `searchParams`. `applyFocusedParams` never writes the inspection id (lines 36–48). After refresh, selection and `focused` are null, so validation is disabled and `QaQcEditPanel` gets `focused={null}`, while the URL can still carry `obs` / `focus` / `tab` for an inspection that is no longer identified. Back restores or clears those params without updating React state, so URL and editor diverge.
**Fix:** Persist `inspection_id` (and error index) in the query string. On load and on `searchParams` change, hydrate selection, error index, and `focusedField` from the URL. Ignore focus params that lack an inspection id.
**Regression:** Set focus, reload; same inspection, error index, and field must be selected. Back from a focused error to the cleared-focus entry must clear the editor. A URL with `obs`/`focus` but no inspection id must not open an editor.
### 5. Validation refresh does not rebind the editor (stale edit target)
**Confidence:** high that the transition is missing; medium that `useRevalidate` itself updates `errors` (hook is outside the packet). Any update of `validationQuery.data` is enough, and the page already renders that data.
**Trigger:** Enter opens error N (`focusedField` + URL set). Then `errors` changes length or content (revalidate, refetch) so index N is gone or now a different row.
**Transition:** The effect at lines 115–119 only clamps `selectedErrorIdx`. It does not clear or rebind `focusedField`, and it does not rewrite URL focus. The editor keeps the old observation/field while the list highlights another row. A later save follows the stale focus, not the selected error.
**Fix:** When validation data for this inspection id changes, if the focused observation/field is not in the new `errors`, clear focus and URL focus params (or rebind to the clamped index only when the identity still matches). Key the reconciliation on inspection id plus a data revision, not length alone.
**Regression:** Focus error 2 of 3; refetch with one remaining error. Editor and URL must not still point at the removed field. Refetch that still contains the same observation/field must not clear the editor.
### 6. `n` / `gg` / re-select wipe correction context (data loss + invalid transition)
**Confidence:** high for focus wipe; medium for unsaved field values (dirty state would live in `QaQcEditPanel`, outside the packet)
**Trigger:**
- One queue row, or the selected row is last: `n` uses `items[currentIdx + 1] ?? items[0]` (lines 94–98) and calls `selectInspection` on the same id.
- `gg` calls `selectFirstInspection` with no same-id guard.
- Selected id is not in `items` (page/status change does not clear selection, lines 205–216): `findIndex` is -1, so `n` selects `items[0]` and abandons the off-queue inspection.
**Transition:** `selectInspection` always sets `focusedField` to null, error index to 0, and deletes focus params (lines 75–79), even when `inspection_id` is unchanged. There is no dirty check and no save call before the switch. In-progress correction focus is discarded. `n` from an off-list selection jumps to an unrelated row.
**Fix:** If `next.inspection_id === selectedInspectionId`, return. If `currentIdx < 0`, do not wrap to `items[0]`. Add an explicit same-id guard in `selectInspection`. Before changing id, call a child dirty/save handshake if one exists; do not invent one inside the missing panel.
**Regression:** One-item queue, focus an error, press `n` and `gg`; focus and URL must remain. Selection not in the current page, press `n`; selection and editor must stay. Changing to a different id may clear focus only after the handshake allows it.
### 7. Revalidate is not single-flight and rotates its idempotency key (invalid duplicate transition)
**Confidence:** high
**Trigger:** Press `r` twice quickly, or press `r` while the button path is already pending. `runRevalidate` (lines 106–109) does not read `revalidate.isPending`. The keyboard path does not use `isRevalidating`. Each call passes a new `crypto.randomUUID()`.
**Transition:** Overlapping revalidates for the same inspection, each with a distinct idempotency key, so the key cannot collapse them. Completion order is undefined. The page never checks mutation error, so a failed revalidate looks like a finished refresh.
**Fix:** If `revalidate.isPending` for this inspection, return. Hold one idempotency key in a ref for the in-flight attempt and clear it when the mutation settles.
**Regression:** Two `r` keydowns in one pending window produce one mutate and one key. After settle, the next `r` may send a new key. Button and keyboard share that guard.
### 8. Sticky `g` chord and failed fetches rendered as empty queues/lists (invalid transition)
**Confidence:** high
**Trigger A:** Press `g` (`pendingGRef = true`, lines 176–182), then hit an early return (focus an `INPUT`, or move focus outside `rootRef`) before the second `g`. The early returns at lines 147–151 do not clear `pendingGRef`. A later lone `g` takes the `pendingGRef` branch and runs `selectFirstInspection`, which is defect 6’s wipe.
**Trigger B:** Queue or validation query errors with no cached data. The page never reads `isError`. It passes `items ?? []` and `errors ?? []` with `isLoading === false` (lines 73, 200–201, 223–225).
**Transition A:** Stale chord becomes `gg` and resets selection/focus. **Transition B:** Failed validation looks like an empty error list (false pass); a failed queue looks like an empty queue. `n` / `gg` then operate on that false empty set.
**Fix:** Clear `pendingGRef` on every early return and on a short timeout. Pass `isError` through and do not render empty-success copy, clamp-to-passed, or `n`/`gg` when the active query is in error.
**Regression:** `g`, focus an input, blur, press `g` once; must not select-first. Validation GET 500 must not show an empty pass or allow `n` to advance. Queue GET 500 must not show a zero-item success list.
## Discarded hypotheses
- `j`/`k` moving the highlight without moving the editor is intentional; Enter is the open step. Not a defect by itself.
- Dismissed flags hidden via `flag_id` vs `id` match the types shown. No id-collision bug is established.
- `obsIdx` hardcoded to `null` in `toFocusedField` is incomplete only if observation errors can lack `observation_id`. `NasscoErrorEntry` is not in the packet, so this is not reported as a defect.
- “No issues found” after every flag is dismissed is copy, not a state-machine bug.
- Keeping the detail pane when the queue page changes is not by itself data loss. It becomes a defect only through `n`’s `-1` wrap (defect 6) and refresh (defect 4).
- Cross-inspection stale `errors` from `keepPreviousData` is not established; the validation hook is outside the packet.
- Accidental dismiss with no undo is not established; dismiss UI is in `FlagCard`, outside the packet.
## Missing evidence
Outside the packet: `api/client.js`, `api/qaqc.js` (`useQaqcQueue`, `useInspectionValidation`, `useRevalidate`), `QaQcEditPanel`, `QaQcErrorList`, `QaQcQueueList`, `FlagCard`. Consequences: cannot confirm save/dirty behavior, whether revalidate or save invalidates the queue, query `placeholderData`, or axios 404 mapping. Those gaps do not weaken defects 1–8, which are fully determined by the three supplied files. No queue invalidation after a successful correction is visible here; if the missing hooks also omit it, queue status stays stale after a fix. That second half is not claimed as proven.
## Next action
Patch the three supplied files for defects 1–8, in that order, with the regression cases above. Do not change the missing edit/save modules until their dirty and invalidation behavior is in scope.Primary judge's stated reason
B receives a slight forced preference for more reliable separation of visible state transitions from speculative mutation effects, reducing the risk of acting on an unsupported concurrency diagnosis. This is not an established material quality gap; B's own debatable diagnoses and less complete focus-state coverage leave room for an independent review to prefer A.
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_6990dc70789cba7df856f5293ac3f6b728b8a38f7117cb48573bfcb9ce870e84. A separate independent review is required before calling a concern a verified factual defect. Judge disagreement is not recorded here.