Skip to content

hey attachments re-walks the same page ~100 times; returns 0, 100x duplicates, or a 500 #279

Description

@rsalesas

hey attachments walks the same page ~100 times, so discovery returns wrong results and the command is effectively unusable. Every invocation ends with:

"notice": "Attachment discovery stopped after 100 pages of thread messages"

including on threads with a single message. -vv on a one-message thread shows 201 HTTP requests.

The page appears to be re-fetched rather than advanced, and the visible outcome depends on where the attachment sits. On threads that hey search --attachment pdfs returns, I get three different wrong answers:

1. Attachment reported 100 times — one copy per re-fetched page, all byte-identical:

$ hey attachments 2065075618 --json
100 entries, 1 distinct  (id "2194754328:1", application/pdf, 119857 bytes)
"summary": "100 attachments in thread 2065075618"

2. Zero attachments, though search says the thread has a PDF:

$ hey search --attachment pdfs --from mail.anthropic.com --date last_30_days --json
2094196841  Your receipt from Anthropic, PBC #...

$ hey attachments 2094196841 --json      # thread has exactly 1 message
"summary": "0 attachments in thread 2094196841"

3. API error: 500 Internal Server Error — threads 1914117743 and 2008389069 in the same sample.

The zero case is deterministic, not a race: three consecutive runs all returned 0, and --account all / an explicit --account <id> make no difference.

That thread really does have a PDF. --attachment pdfs discriminates correctly — as a control, two senders whose mail is known to carry no PDF return nothing at all:

$ hey search --attachment pdfs --from notify.cloudflare.com --date last_30_days   # 0 threads
$ hey search --attachment pdfs --from email.apple.com      --date last_30_days   # 0 threads

save inherits the failure, because it resolves its id through the same discovery:

$ hey attachments save 2225707884:1     # message id of the thread above
attachment "2225707884:1" not found     # same for :2, :3

The download path itself is fine. When discovery does surface an id, save fetches it correctly:

$ hey attachments save 2194754328:1 --output ./probe.pdf
Attachment saved  (119857 bytes; PDF document, version 1.7, 1 pages)

So the defect looks confined to the pagination walk in discovery, not to fetching.

Why it matters: there is currently no way to get an attachment out of the CLI unless discovery happens to land on it, and no way to distinguish a genuinely attachment-free thread from a failed walk, since both report 0. For archiving receipts and invoices off Paper Trail that is the whole use case.

Likely the same walk as #181 (hey box --all returning one page twice) and #109 — the duplicate-page symptom there and the 100x duplicate here look like the same cursor failing to advance.

Two smaller things noticed alongside:

  • The help examples (hey attachments save 67890:1) read as though the id is a thread id. Real ids are <message_id>:<index>, and passing a thread id returns resource not found, which sends you looking in the wrong place. The index is 1-based; :0 is rejected as malformed.
  • An invalid --attachment value surfaces as a raw API 500 rather than a client-side usage error: hey search --attachment pdf (singular) 500s, while hey search filters lists the valid value as pdfs. Cheap to validate against that list before the request.

Against 0.1.1 (c0d3441), macOS, release install.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions