Skip to content

fix(insight): fail loudly when incident-export CSV is truncated - #168

Merged
ysyneu merged 2 commits into
mainfrom
fix/insight-export-truncation
Aug 27, 2026
Merged

fix(insight): fail loudly when incident-export CSV is truncated#168
ysyneu merged 2 commits into
mainfrom
fix/insight-export-truncation

Conversation

@ysyneu

Copy link
Copy Markdown
Contributor

Problem

fduty insight incident-export could exit 0 with a silently truncated CSV: the /insight/incident/export endpoint answers a one-shot CSV stream with no pagination cursor and caps its row count server-side without indicating so in the payload. For a wide time window the written CSV could contain far fewer rows than the number of incidents matching the filter, with no error or warning.

Fix

insight incident-export is now a curated command (identical flag surface; the generated twin is dropped by genAddLeaf, the established curated-wins mechanism). After writing the CSV to stdout it:

  1. Counts the CSV data rows with encoding/csv (quoted fields with embedded newlines count as one record).
  2. Fetches the authoritative total from /insight/incident/list with the same filter (a single 1-item page).
  3. On a shortfall, the partial CSV is still written, stderr reports the actual written count as rows=N, and the command exits non-zero with an explicit message stating written vs total and advising to narrow the time window.

If completeness cannot be verified (the list call fails), the command also exits non-zero rather than letting an unverified export pass for a complete one.

Tests

New internal/cli/insight_export_test.go covers: complete export (exit 0, rows=N on stderr), truncated export (non-zero exit, written-vs-total message, partial CSV still written), quoted-newline row counting, filter forwarding to both endpoints, and the countCSVDataRows edge cases.

make fmt, make lint (0 issues), and make test (full suite, -race) all pass.

The export endpoint returns a one-shot CSV with no pagination cursor and
caps its row count server-side, so a wide time window can come back
silently truncated while the command exits 0. insight incident-export is
now a curated command (same flags; the generated twin is dropped by
genAddLeaf): after writing the CSV it counts the data rows with
encoding/csv and compares against the incident-list total for the same
filter. On a shortfall the partial CSV is still written, stderr reports
the actual written count as rows=N, and the command exits non-zero
stating written vs total.
@ysyneu
ysyneu changed the base branch from feat/ai-sre to mainAugust 27, 2026 01:55
@ysyneu
ysyneu merged commit d0c1262 into mainAug 27, 2026
12 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@ysyneu