harness: claude
prompt: zstack: users report the CSV export drops the last row
exit: 0  seconds: 40
skill tool calls: zstack
zstack files read: SKILL.md, playbooks/debug.md, playbooks/bug-class-sweep.md, references/principles/$p.md, references/principles/smallest-reversible-change.md
---
**Goal:** CSV export should write every note, the last one included. **Done when** a test that fails on the current code passes after the fix, the checks are recorded at the head commit, and the bug class has been swept for other instances.

```
Route: debug -> bug-class-sweep -> land, shape: inline, principles: reproduce-first, fix-the-class, smallest-reversible-change, evidence-before-the-word
```

I'm working inline because the repo is small (`acme_notes/export.py` with `tests/test_export.py`) and done is clear, so a subagent would only add overhead.

**Todo list** (playbook steps copied word for word):

*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. *(Bisect will be skipped: the repo has a single commit, so there is no known-good commit.)*
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: `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.

*bug-class-sweep*
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.
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 `zcheck.sh --name <guardrail> -- <command>`.
10. Write the report from `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.

*land:* the PR goes through the `land` playbook, which I haven't opened yet. I'll copy its steps in when the work gets there.

**How each principle shapes the work:**
- **reproduce-first:** no code changes until a failing test in `tests/test_export.py` shows the last row going missing.
- **fix-the-class:** a likely cause is an off-by-one slice or range, or an unflushed writer. Once the cause is confirmed I'll grep for the same pattern in `store.py` and `cli.py`.
- **smallest-reversible-change:** the fix and the guardrail go in separate commits.
- **evidence-before-the-word:** I won't call it "fixed" without a `zcheck` record at the fix commit with a non-zero test count.

This is where the dry run stops: I haven't opened the application code or edited anything.
