Skip to content

feat(media): make text file size limit configurable via [media] max_text_file_kb#1343

Open
slps970093 wants to merge 2 commits into
openabdev:mainfrom
slps970093:feat/configurable-text-file-size-limit
Open

feat(media): make text file size limit configurable via [media] max_text_file_kb#1343
slps970093 wants to merge 2 commits into
openabdev:mainfrom
slps970093:feat/configurable-text-file-size-limit

Conversation

@slps970093

@slps970093 slps970093 commented Jul 10, 2026

Copy link
Copy Markdown

What problem does this solve?

Text file attachments larger than 512 KB are silently dropped before being passed to the agent. Users have no indication this is happening — the file uploads successfully, the bot receives the message, but the agent simply never sees the file content.

Observed on chisato-bot (2026-07-10): 9 occurrences of \ est-results.txt\ (535–563 KB) being discarded in under 40 minutes, causing the user to repeatedly re-upload the same file.

Discord Discussion URL: https://discordapp.com/channels/1491295327620169908/1491365158868619404/1525027437086380042

At a Glance

\
User uploads test-results.txt (535 KB)

Discord/Slack reports attachment size to OpenAB

download_and_read_text_file(size, max_bytes)

size > max_bytes? ──yes──> return None (silent drop ← bug)
↓ no
HTTP download → inline into prompt → agent sees file
\\

After this change, \max_bytes\ comes from [media] max_text_file_kb\ in config.toml (default: 512, backward-compatible).

Prior Art & Industry Research

Not applicable — this is a local prompt-assembly parameter with no cross-system protocol implications.

Proposed Solution

  • Add \MediaConfig\ struct to \config.rs\ with a single \max_text_file_kb: u64\ field (default 512).
  • Replace the hardcoded \const MAX_SIZE: u64 = 512 * 1024\ in \media.rs\ with a \max_bytes: u64\ parameter.
  • Thread \media_config\ through \discord.rs, \slack.rs, and \main.rs\ following the same pattern as \SttConfig.
  • Add two regression tests confirming the size gate behaviour.

Why this approach?

Keeps the change minimal and targeted. The \TEXT_TOTAL_CAP\ (1 MB aggregate) remains a hard ceiling, so raising the per-file limit cannot cause prompt bloat beyond what was already allowed. All other adapters (Google Chat, Feishu, etc.) have their own download logic and are unaffected.

Alternatives Considered

  • Raise the hardcoded default to 1 MB — affects all deployments without opt-in, violates backward-compat rule.
  • Notify the user when a file is skipped — useful but orthogonal; can be a follow-up.

Validation

  • \cargo fmt\ passes
  • \cargo clippy --workspace -- -D warnings\ passes
  • \cargo clippy --workspace --features unified -- -D warnings\ passes
  • \cargo test --workspace\ passes (916 tests)
  • New regression tests: \ ext_file_rejects_when_size_exceeds_max_bytes, \ ext_file_size_gate_is_strict_greater_than\
  • Manual: adding [media] max_text_file_kb = 1024\ to config.toml resolves the chisato issue

…ext_file_kb

Previously the 512 KB per-file limit for text attachments was hardcoded
in download_and_read_text_file(). Files between 512 KB and 1 MB were
silently dropped, causing users to unknowingly lose file context (e.g.
chisato test-results.txt at 535-563 KB, 9 occurrences on 2026-07-10).

Changes:
- config.rs: add MediaConfig struct with max_text_file_kb field (default 512)
- media.rs: replace const MAX_SIZE with max_bytes parameter
- discord.rs: read media_config from Handler, pass max_bytes to download fn
- slack.rs: thread media_config through run_slack_adapter and handle_message
- main.rs: wire cfg.media into both Discord Handler and Slack adapter

Deployments that do not set [media] are unaffected (backward-compatible).
To raise the limit for a bot, add to config.toml:

  [media]
  max_text_file_kb = 1024  # or any value up to TEXT_TOTAL_CAP (1 MB)
Verify that download_and_read_text_file rejects files when the reported
size exceeds max_bytes (pre-download fast path), and that the gate uses
strict greater-than so a file at exactly the limit is not rejected.
@slps970093 slps970093 requested a review from thepagent as a code owner July 10, 2026 08:00
@openab-app openab-app Bot added the closing-soon PR missing Discord Discussion URL — will auto-close in 24 hours. label Jul 10, 2026
@openab-app

openab-app Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Caution

This PR is missing a Discord Discussion URL in the body.
This PR will be automatically closed in 24 hours if the link is not added.

All PRs must reference a prior Discord discussion to ensure community alignment before implementation.

Please edit the PR description to include a link like:

Discord Discussion URL: https://discord.com/channels/...

@slps970093

Copy link
Copy Markdown
Author

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

Labels

closing-soon PR missing Discord Discussion URL — will auto-close in 24 hours.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant