xai / grok-4.7-efficient / low / low effort preferred over cursor / composer-2.5 / Composer 2.5 default / unknown 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`.
cursor / composer-2.5 / Composer 2.5 default / unknown effort answer
# Evidence packet: QA/QC flag review and correction flow audit
## 1. Conclusions (source-grounded defects)
### D1 — Orphan inspection selection after queue filter/page change (stale state + invalid `n` transition)
**Evidence:** `QAQCPage.tsx` keeps `selectedInspectionId` in local state (`59–60`) and only updates it via `selectInspection` (`75–80`). Changing queue `status` or `page` updates URL only (`205–215`); it does **not** clear or re-validate selection against the new `items`.
**Trigger:** User selects inspection A on page 1 (or under `needs_review`), then changes status filter or page. `queueQuery` returns a new `items` list that may omit A.
**State transition:**
`(selectedInspectionId=A, items=[...without A])` → UI still has `selectedInspectionId=A`; `validationQuery` remains enabled (`70`). Press **`n`**: `nextUnresolvedInspection` (`94–98`) does `findIndex` → `-1`, then `items[currentIdx + 1] ?? items[0]` → **`items[0]`** (not “next after A”).
**Impact:** Queue highlight vs loaded validation/edit context can disagree; **`n` jumps to queue head** instead of advancing from the current inspection—invalid navigation semantics, risk of editing the wrong inspection while believing you advanced the queue.
**Smallest safe fix:** On `status` / `page` change (or when `items` changes), if `selectedInspectionId` is not in `items`, clear selection and `focusedField` (and URL focus params), or auto-select first item on the new page—pick one product rule and apply consistently in one `useEffect`.
**Regression scenarios:**
- Select item on page 2 → change page to 1 → expect selection cleared or first item on page 1 selected; errors panel not still bound to off-page id.
- Orphan selection → press `n` → must not silently select `items[0]` without user intent; should no-op or re-sync.
**Confidence:** High for stale selection and `n` behavior; medium for queue list visual mismatch (depends on `QaQcQueueList`, outside packet).
---
### D2 — Focus / URL edit target survives revalidate (stale correction context)
**Evidence:** `setFocusForError` / `openErrorInEditor` set `focusedField` and URL (`82–92`, `36–48`). `runRevalidate` only mutates (`106–109`); nothing clears `focusedField` or URL on revalidate success/failure. `selectedErrorIdx` is clamped when `errors.length` changes (`115–118`); **`focusedField` is not**.
**Trigger:** User selects error, Enter opens editor (`focusedField` + `tab`/`obs`/`focus` params), then **`r`** revalidate. Backend removes or changes that error.
**State transition:**
`(focusedField=field X, errors=[...])` → after refetch `(errors' without X, focusedField still X)` → `QaQcEditPanel` still receives stale `focused` (`234–237`).
**Impact:** Edit/save path (in `QaQcEditPanel`, not in packet) may target a field that is no longer failed—stale-state defect at the page orchestration layer; plausible wrong edits or confusing “success” while list shows no matching error.
**Smallest safe fix:** On `validationQuery` data update after revalidate (or in `useRevalidate` `onSuccess`), if current `focusedField` no longer matches any error in `errors_json.errors` (by `inspection_id`, `observation_id`, `field_path`), call `setFocusedField(null)` and `applyFocusedParams(..., null)`.
**Regression scenarios:**
- Open error A → fix via revalidate only → focus and URL `focus`/`obs` cleared.
- Open error A → revalidate leaves A → focus unchanged.
**Confidence:** High for stale `focusedField`; actual save behavior uncertain without `QaQcEditPanel`.
---
### D3 — `QAReviewPanel`: `failed` review rendered like completed (invalid UI transition)
**Evidence:** Loading and `pending`/`running` branches (`32–75`). There is **no** branch for `review.status === 'failed'`. Any non-loading review with truthy `review` and status not `pending`/`running` uses the completed UI (`78–147`), including flags and “No issues found” when `activeFlags.length === 0` (`142–145`).
**Trigger:** API returns `QAReview` with `status: 'failed'` (typed in `qaReview.ts` `20`).
**State transition:**
`status: 'failed'` → UI shows health badge, flags, or green “passed QA” empty state—same as `completed`.
**Impact:** Misleading QA state; dismiss/re-run actions may be offered on a failed run (data/audit confusion, not proven server data loss from this file alone).
**Smallest safe fix:** Add explicit `failed` branch (error message, retry), and gate “passed QA” on `status === 'completed'` only.
**Regression scenarios:**
- Mock `status: 'failed'` → no success copy; retry visible.
- `completed` + zero flags → success copy still shown.
**Confidence:** High.
---
### D4 — Dismiss / re-run: UI stale until refetch (stale flags, brief double-action)
**Evidence:** `useDismissFlag` / `useTriggerQAReview` only `invalidateQueries` on success (`77–79`, `57–59`). `QAReviewPanel` does not pass `dismissFlag.isPending` to `FlagCard` or disable dismiss (`24–26`, `115`). No optimistic cache update.
**Trigger:** User dismisses a flag or clicks re-run; slow network or rapid double-click.
**State transition:** Mutation in flight → `activeFlags` still includes dismissed flag until refetch completes; user can invoke `handleDismiss` again.
**Impact:** Stale flag list; possible duplicate dismiss requests (server idempotency unknown—**not** proven data loss from packet).
**Smallest safe fix:** Disable dismiss per flag while `dismissFlag.isPending` (and/or optimistic remove from cache via `setQueryData`); optionally set local “re-running” UI from mutation + invalidated query `isFetching`.
**Regression scenarios:**
- Single dismiss → flag hidden after success without requiring second action.
- Double-click dismiss → one request or idempotent UI.
**Confidence:** High for stale UI; medium for duplicate API harm.
---
### D5 — `useTriggerQAReview` does not invalidate `qa-summary` (stale aggregate)
**Evidence:** `useTriggerQAReview` and `useDismissFlag` invalidate only `['qa-review', inspectionId]` (`57–59`, `77–79`). `useQASummary` uses `['qa-summary', submissionId]` (`83–91`). No cross-invalidation in supplied hooks.
**Trigger:** Dismiss or re-run on an inspection while a submission summary is mounted elsewhere.
**State transition:** Per-inspection review fresh after refetch; summary counts/scores unchanged until separate refetch.
**Impact:** Stale dashboard/summary metrics relative to flag actions—stale-state defect if summary is shown in the same workflow.
**Smallest safe fix:** If `submissionId` is available at call site, also `invalidateQueries({ queryKey: ['qa-summary', submissionId] })`; or invalidate by prefix `['qa-summary']` when product allows.
**Regression scenarios:**
- Dismiss last red flag → summary `band_counts` updates on same screen.
**Confidence:** High for hook gap; **whether** this affects the scoped QAQC page is **not** established—`QAQCPage` does not use `useQASummary` in the packet.
---
## 2. Alternatives / discarded hypotheses
- **Data loss on inspection switch:** `selectInspection` clears `focusedField` and URL focus params (`75–79`)—reduces cross-inspection focus bleed; not a loss defect in supplied code.
- **Keyboard listener staleness:** Refs mirror latest handlers (`127–140`); empty-deps listener (`188`)—intentional; not a dropped-keystroke defect in this snapshot.
- **QA flag flow on QAQC page:** `QAQCPage` does not import `QAReviewPanel` or `qaReview`—the packet does **not** show flag dismiss integrated with queue/edit; treating them as one UI without other files would be speculative.
- **Edit/save data loss:** No save/mutation logic in scope; cannot demonstrate persistence bugs from these three files alone.
---
## 3. Missing evidence / consequences
| Dependency | Consequence |
|------------|-------------|
| `QaQcEditPanel` | Cannot verify save, field binding to `focused`, or post-save refresh. |
| `qaqc.js` (`useQaqcQueue`, `useInspectionValidation`, `useRevalidate`) | Cannot confirm query keys, cache invalidation after revalidate, or queue refresh when errors clear. |
| `FlagCard` | Cannot confirm dismiss UX guards. |
| `QaQcQueueList` | Cannot confirm how orphan `selectedInspectionId` is highlighted. |
Without `useRevalidate` behavior, **D2’s** fix point (page vs hook) is underspecified; orchestration defect in `QAQCPage` remains valid.
---
## 4. Next useful action
1. Add a `QAQCPage` integration test (or e2e): filter/page change with active selection → assert selection/focus/URL policy.
2. Add test: focus error → revalidate → assert `focusedField` and URL params cleared when error gone.
3. Add `QAReviewPanel` test/fix for `status: 'failed'`.
4. If product ties summary to review actions, extend invalidation in `qaReview.ts` and test summary refresh.
---
**Scope note:** Demonstrable defects in the packet concentrate on **queue orchestration** (`QAQCPage`) and **AI QA review panel** (`QAReviewPanel` + hooks). **Edit/save data-loss** is not demonstrable from the admitted snapshot alone; report **stale focus after revalidate** as the boundary defect tied to the correction flow.Primary judge's stated reason
Prefer A weakly: its accurate reading of the completed-only success guard avoids directing implementation toward a nonexistent failed-to-passed defect. This is a forced whole-answer preference, not an established material quality gap; B provides useful additional orchestration analysis, and an independent review could weigh that benefit differently.
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_74b3e2fd01ae42fd33e1d4f55d4cb0c1edb0f972dd18769896f55cf6726b9c26. A separate independent review is required before calling a concern a verified factual defect. Judge disagreement is not recorded here.