Skip to content

fix(auto-attach): skip bad disk attachments and cap message flooding - #229

Open
alex-mextner wants to merge 1 commit into
mainfrom
fix/207-208-autoattach-and-flood-cap
Open

fix(auto-attach): skip bad disk attachments and cap message flooding#229
alex-mextner wants to merge 1 commit into
mainfrom
fix/207-208-autoattach-and-flood-cap

Conversation

@alex-mextner

Copy link
Copy Markdown
Owner

Summary

  • A disk attachment (auto-detected path mention, or explicit --photo/--file) that goes missing, gets truncated to empty, or loses read permission between detection and send is now skipped with a stderr warning naming the path and reason — the primary text still delivers. Previously Telegram's "file must be non-empty" rejection killed the WHOLE send. If every attachment is bad and no text remains, the send now refuses loudly (non-zero exit) instead of a silent no-op success. Fixes auto-attach fails the whole send when the body mentions a nonexistent or empty file path #207.
  • A message long enough to fragment into more than 6 separate Telegram sends is now refused up front, naming the exact character count and message count it would have produced, instead of silently flooding the recipient with dozens of fragments. New flood-cap feature flag (on by default); override with --no-feature flood-cap. Rich messages (tables/headings/lists/formulas) are unaffected — they always send whole. Fixes tg silently fragments an oversized message into dozens of separate Telegram sends instead of warning or refusing #208.
  • Version bump 1.41.0 -> 1.42.0 (minor, not patch): the flood cap can refuse a send that previously succeeded, so this is a behavior change.

Test plan

  • bun test tests/transmitter.test.ts tests/file-check.test.ts tests/cli-attachment-flood-integration.test.ts — 53 pass, 0 fail, 145 expect() calls
  • Full repo suite (bun test, 2451 tests / 147 files) — 2442 pass, 1 skip, 8 fail, 1 error; all 8 failures + the 1 error are in unrelated pre-existing integration tests (ctl-service-cli, ctl-tasks-integration, run-text-hooks, ctl-daemon-integration, hooks-photo-integration — timing-sensitive tmux/daemon races, not touched by this diff). Verified by stashing this change and re-running those same files against clean HEAD: identical failures reproduce without the fix applied.
  • tg --help still runs correctly and documents both new behaviors (missing/empty/unreadable attachments, message-flood cap)
  • End-to-end wiring test spins up a mock Telegram Bot API server and runs the real tg binary — catches entrypoint wiring gaps the pure unit tests can't (e.g. forgetting to pass checkFile/allowFlood through to transmit())

🤖 Generated with Claude Code

A disk attachment (auto-detected from a path mention, or an explicit
--photo/--file) that goes missing, is truncated to empty, or loses read
permission between detection and send used to make Telegram's "file must be
non-empty" rejection kill the WHOLE send, including the primary text.
transmit() now re-validates every disk-sourced attachment right before the
photos/text/documents sandwich runs (features/auto-attach/file-check.ts,
pure checkAttachmentFile with injected stat/canRead), drops a bad one with a
stderr warning naming the path and the reason, and still delivers the rest of
the plan. The same check runs a second, earlier time in the `tg` entrypoint
right before code-as-pdf/md-as-pdf conversion, so a bad original source can't
be silently replaced by a generated PDF that only gets validated on its own
merits. If every attachment is bad and no text remains, the send now refuses
loudly (non-zero exit) instead of a silent no-op success.

A message long enough to fragment into more than FLOOD_CAP_MAX_MESSAGES (6)
separate Telegram sends is now refused up front, naming the exact character
count and message count it would have produced, instead of silently flooding
the recipient with dozens of fragments. New `flood-cap` feature flag (on by
default); disable with --no-feature flood-cap or features.flood-cap: false.
Rich messages (sendRichMessage) are exempt — they always send whole.

Both fixes are covered by unit tests (file-check.test.ts,
transmitter.test.ts) and an end-to-end wiring test that runs the real `tg`
binary against a mock Bot API server (cli-attachment-flood-integration.test.ts),
which is what caught a prior gap where the entrypoint could forget to wire
checkFile/allowFlood through to transmit(). 53 tests pass across the three
touched test files (145 expect() calls).

Version bump 1.41.0 -> 1.42.0 (minor, not patch): the flood cap can refuse a
send that previously succeeded, so this is a behavior change.

Fixes #207
Fixes #208

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant