harness: codex
prompt: The CSV export is dropping rows for some users and I don't know why. Fix it.
exit: 0  seconds: 27
zstack files read: SKILL.md, playbooks/debug.md, playbooks/bug-class-sweep.md, references/harness-capabilities.md, references/principles/reproduce-first.md, references/principles/fix-the-class.md, references/principles/evidence-before-the-word.md
---
Goal: find why CSV exports omit rows for some users, fix the cause, and verify that all expected rows are exported.

Route: debug -> bug-class-sweep, shape: inline, principles: reproduce-first, fix-the-class, evidence-before-the-word

Inline for this planning-only dry run. No files edited; all steps below are pending.

Todo — `debug`:

1. Write the symptom as one line: observed, expected, where.
2. Reproduce it. Prefer a failing automated test; fall back to a script or a recorded manual sequence. If it cannot be reproduced, write down what you tried and why, and ask the user before going further.
3. Shrink the reproduction until every remaining step is needed to trigger it.
4. List at least two candidate causes and the observation that would tell them apart.
5. Run those observations (logging, a debugger, `git bisect run <repro>` when a known good commit exists) until one cause is left standing. Record the evidence that ruled out each other candidate.
6. Name the root cause in one sentence that explains every observed symptom. A cause that leaves a symptom unexplained is a partial cause; return to step 4.
7. Make sure the reproduction is captured as a test that fails on the current code.
8. Make the smallest change that fixes the root cause, in its own commit.
9. Record the checks at the fix commit on a clean tree: `<zstack dir>/scripts/zcheck.sh --name <check> -- <test command>` for the new test and the suite that covers the area. A check that ran zero tests failed.
10. Confirm the original symptom is gone the way it was first seen (same environment, same steps).
11. Chain into `bug-class-sweep` with the root cause as its input. When the bug is a true one-off (a typo, a single wrong constant), write `no class: <reason>` in the PR body instead.

Todo — `bug-class-sweep`, after the cause is known:

1. Accept the root cause from a finished `debug`, or reproduce and root-cause it first using the `debug` steps.
2. Decide whether a class exists. If the mistake cannot recur elsewhere (a one-character typo, a single wrong constant), write `no class: <reason>` in the PR body and the ticket, and stop here.
3. Name the class in one line, for example "money written after a read with no lock between".
4. Write the class as a searchable pattern. Start with a `git grep -nE '<regex>'`; move to an `ast-grep` or `semgrep` rule only when the regex returns too much noise. Keep the exact command.
5. Run the pattern across every app and package in this repo, then in each repo listed in `sweep_repos=`.
6. Classify every hit as confirmed, suspect or safe, each with `path:line` and one sentence of reasoning. Read each hit; a hit you have not opened is suspect.
7. Fix confirmed hits in this batch when they share the same fix and their files sit inside this lane's lease, one commit per fix. Ticket every other confirmed or suspect hit by impact, with the `path:line` and reasoning attached.
8. Write the "why tests and QA missed it" note: one paragraph on the gap that let the class through.
9. Add a guardrail in its own commit: a lint rule, guard test or validator that fails on the pattern. Prove it by running it against the unfixed code (it fails) and the fixed code (it passes), and record it with `<zstack dir>/scripts/zcheck.sh --name <guardrail> -- <command>`.
10. Write the report from `<zstack dir>/templates/sweep-report.md` to `.git/zstack/sweeps/<YYYY-MM-DD>-<class-slug>.md`.
11. Link the original bug, every fix commit, every ticket and the guardrail in the PR body and on the original ticket.

Principles shaping the plan:

- `reproduce-first`: establish the missing-row failure before changing code.
- `fix-the-class`: search for the same cause elsewhere once identified.
- `evidence-before-the-word`: require recorded verification before claiming the export is fixed.

Stopped at the requested dry-run boundary.
