fix(cli): reject an overflowing feedback attachment list before reading any file

Merged
KI
2mo ago
+125-36

Problem

Follow-up to #7214, from CodeRabbit's review there. Attachments were sized up front, but each was still read and base64-encoded inside the loop, and the aggregate check ran only afterwards. A list that could never fit was read in full, up to five files already tailed to 3.3 MB each, before the user got the rejection. The PR description claimed otherwise; this makes it true.

Change

  • planAttachmentUploads(requested) builds the whole plan from stat sizes alone: per-file tail length, truncation notices, and the aggregate check. It throws the same "exceed the total limit" error naming the files before any file is opened.
  • The command stats every path, plans, prints notices, and only then reads tails. Behavior for lists that fit is unchanged. Diagnostics accounting stays as shipped, through the 200 KB headroom.

Testing

  • New test makes both fixture files unreadable after creation: a read before the rejection fails with EACCES, the fix yields the limit message. It fails on the merged code and passes here.
  • Pure test for the planner (lone oversized file tailed with a notice, two-file overflow rejected naming both).
  • bun test src/commands/feedback/submit (9 pass), bun run typecheck in packages/cli, biome clean.

https://claude.ai/code/session_01UWyngsh3WSdEM6kmf1P8s5


Summary by cubic

Rejects an overflowing feedback attachment list before reading any of its files.

Previously each attachment was read and base64-encoded inside the loop, so an oversized list was read in full before the total-limit rejection. Now planAttachmentUploads builds the whole plan from stat sizes alone and throws the same error (naming the files) before any file is opened. Behavior for lists that fit is unchanged.

The tail read now also re-sizes the file and clamps to what currently exists, so a log that shrank or rotated after planning produces a short read instead of a range error.

Summary by CodeRabbit

  • Bug Fixes

    • Feedback attachments are validated against individual and combined size limits before upload processing begins.
    • Oversized submissions are rejected earlier with clearer limit handling.
    • Oversized files are safely truncated, with notices accurately reflecting each file’s allowed size.
    • Attachments remain readable when files shrink or rotate during processing, preserving available content without errors.
  • Tests

    • Added coverage for total-size validation, per-file size calculations, truncation notices, unreadable files, shrinking files, and empty reads.