feat: add configurable discord message_limit with code-fence-preserving chunks#140
feat: add configurable discord message_limit with code-fence-preserving chunks#140the3mi wants to merge 1 commit intoopenabdev:mainfrom
Conversation
eff3f0d to
8da5032
Compare
- New [platforms] config section; each platform has its own message_limit Reference limits: Discord=2000, Telegram=4096, Slack=39000, Signal=8000 - Discord streaming uses limit-100 buffer; final chunking uses full limit - split_message(text, limit, add_indicator): third param controls (N/N) indicators - split_message_for_streaming(): calls split_message(..., false) — no indicators - test_very_long_line: uses dynamic indicator_len instead of hardcoded +20 - PlatformSettings: default_message_limit() consistent with PlatformsConfig defaults - Discord and Telegram both use their platform-specific defaults (2000 / 4096) - Fix clippy: remove unnecessary trim() before split_whitespace() - All 6 tests pass, clippy clean
8da5032 to
83d2a11
Compare
chaodu-agent
left a comment
There was a problem hiding this comment.
🔴 Changes Requested — Good idea but has compile-breaking issues and a Unicode regression. Needs rebase + significant rework.
Baseline Check (Step 0)
| Field | Value |
|---|---|
| State | OPEN |
| Mergeable | CONFLICTING |
| Created | 2026-04-08 (23 days ago) |
| Last commit | 2026-04-08 |
| Author | @brettchien |
| Labels | closing-soon |
Main has: split_message() in format.rs with Unicode-safe .chars().count() splitting, 12 thorough tests including fence-reopening and hard-split edge cases. Message limit is hardcoded at 2000 in discord.rs. No PlatformsConfig or configurable limits.
Net-new: PlatformsConfig struct, configurable message_limit per platform, add_indicator flag on split_message, split_message_for_streaming helper.
四問框架
1. 解決什麼問題
Message limit is hardcoded at 2000 (Discord). Adding Telegram/Slack/other platforms requires per-platform configurable limits.
2. 怎麼解決
Adds PlatformsConfig with per-platform defaults, threads message_limit from config through to split_message(), adds add_indicator flag to control (1/N) markers.
3. 考慮過什麼
Streaming edits use limit - 100 buffer for Discord edit overhead. Final chunking uses full limit. Indicator suppressed during streaming.
4. 最佳方案嗎
The config design is clean, but the implementation has critical issues (see below).
🟢 INFO
- Making
message_limitconfigurable is the right direction — hardcoded 2000 is fragile. PlatformsConfigwith per-platform defaults (discord=2000, telegram=4096) is a clean design.- The
add_indicatorflag is a nice touch — streaming edits shouldn't show "(1/N)" markers.
🟡 NIT
config.toml.examplenot updated — Users won't discover[platforms.discord]without reading source.- Telegram placeholder — Defined in config but no Telegram adapter exists. Consider removing until needed.
- Indicator length hardcoded to 10 — Breaks for >99 chunks. Minor but worth a comment.
default_message_limit()returns 2000 — Consider a larger generic default (e.g. 4096) so new platforms don't silently truncate.
🔴 SUGGESTED CHANGES
-
Compile error —
adapter.rscallsformat::split_message(&final_content, message_limit)with 2 args. This PR changes the signature to 3 args(text, limit, add_indicator)but does NOT updateadapter.rs. This will not compile. -
Unicode regression — Main's
split_messageuses.chars().count()for Unicode-safe splitting. The PR replaces this with.len()(byte length). For CJK/emoji content (common in Discord), a 3-byte UTF-8 char counts as 3 toward the limit, producing unnecessarily small chunks. Discord counts Unicode codepoints, not bytes. -
Byte-boundary split can panic —
remaining[..headroom.min(remaining.len())]slices by byte offset. Ifheadroomfalls in the middle of a multi-byte UTF-8 character, this panics at runtime. Needremaining.char_indices()or similar. -
Existing tests deleted — Main has 12 thorough tests (including fence-reopening, hard-split lines, Unicode invariants). The PR replaces them with 6 simpler tests that don't verify the chunk-size invariant with
.chars().count(). -
Merge conflict — Needs rebase onto current main.
超渡法師 Review — PR #1401. What problem does it solve?The message character limit is hardcoded at 2000 (Discord's limit). As the project adds multi-platform support (Telegram=4096, Slack=39000), each platform needs its own configurable limit. The PR also adds an 2. How does it solve it?
3. What was considered?
4. Is this the best approach?The config design is sound, but the implementation has critical issues against current Traffic Light🟢 INFO
🔴 SUGGESTED CHANGES
Verdict🔴 Changes requested — The feature direction is correct, but the implementation needs a full rebase onto current
|
Summary
Implements configurable
message_limitper platform, with an extensible config structure. Currently only Discord is wired up. Telegram placeholder is present but not yet implemented.Config
Reference limits for future platforms:
Behavior
message_limit - 100buffer (Discord edit overhead)message_limitsplit_message(..., false)— no(1/N)indicators to avoid live-edit noisesplit_message(..., true)— includes(1/N)indicatorsCode changes
config.rs:PlatformSettings+PlatformsConfigreplaces the old flatdiscord.message_limitfield.default_limit_for_platform()centralizes per-platform defaults soPlatformSettings::default()andPlatformsConfig::default()stay consistent.format.rs:split_message(text, limit, add_indicator)— third arg controls indicator injection.split_message_for_streaming()wraps it withadd_indicator=false.discord.rs: Both call sites updated to pass the third arg.Bug fixes in this PR
split_message_for_streaming()was callingsplit_message()directly with no indicator flag, so it still added(1/N)markers despite the name implying otherwise. Fixed by making the indicator behavior explicit.test_very_long_lineused2000 + 20instead oflimit + indicator_len. Now uses dynamic values.PlatformSettings::default()returned 2000, butPlatformsConfig::default()hardcoded telegram at 4096. Now both usedefault_limit_for_platform().Quality checks
cargo test: 6/6 passingcargo clippy: warnings only (no errors)