Skip to content

fix(discord): apply effective maxLinesPerMessage in live replies#40133

Merged
altaywtf merged 5 commits intoopenclaw:mainfrom
rbutera:fix-discord-message-length
Mar 9, 2026
Merged

fix(discord): apply effective maxLinesPerMessage in live replies#40133
altaywtf merged 5 commits intoopenclaw:mainfrom
rbutera:fix-discord-message-length

Conversation

@rbutera
Copy link
Contributor

@rbutera rbutera commented Mar 8, 2026

Summary

Describe the problem and fix in 2-5 bullets:

  • Problem 1: Discord live reply surfaces could read a partial runtime discordConfig object, miss maxLinesPerMessage, and silently fall back to the default 17-line chunking even when the effective account config was higher.
  • Problem 2: Discord auto-replies could still be split at 17 lines even after the effective value was resolved correctly, because the optimized fast path dropped maxLinesPerMessage and chunkMode before calling sendDiscordText(...), causing a second re-chunking pass to use defaults.
  • Why it matters: Users configured for longer Discord replies still saw noisy multi-message splits in normal live replies, preview/final delivery, slash replies, component replies, and auto-replies that should have remained within the configured line cap.
  • What changed: Added resolveDiscordMaxLinesPerMessage(...) in src/discord/accounts.ts, switched the live Discord reply surfaces to use explicit runtime value first and then merged effective account config, and threaded maxLinesPerMessage plus chunkMode through the reply-delivery fast path so already-valid chunks are not re-split at 17 lines; added regressions for root-level fallback, per-account override, higher-level slash/native reply handling, and fast-path propagation.
  • What did NOT change (scope boundary): This PR does not change Discord chunking defaults, Discord character-limit behavior, account selection/routing rules, webhook/thread-binding semantics, or non-Discord channels.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

  • Discord live replies now honor the effective maxLinesPerMessage value for the active Discord account instead of falling back to the default 17-line chunking when the runtime discordConfig object is partial.
  • Root channels.discord.maxLinesPerMessage now applies correctly to live reply paths when no per-account override is set.
  • Per-account channels.discord.accounts.<account>.maxLinesPerMessage continues to override the root Discord value in live reply paths.
  • Discord auto-replies sent through the optimized deliverDiscordReply(...) fast path now preserve maxLinesPerMessage and chunkMode all the way into sendDiscordText(...), so a chunk that is already valid under the configured limit is not re-split at the default 17-line boundary.

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: Ubuntu 24.04
  • Runtime/container: source checkout / pnpm dev
  • Model/provider: N/A for the regression coverage added here
  • Integration/channel (if any): Discord
  • Relevant config (redacted): channels.discord.maxLinesPerMessage: 120; verified account-level override with channels.discord.accounts.work.maxLinesPerMessage: 80

Steps

  1. Configure Discord with channels.discord.maxLinesPerMessage: 120 and optionally channels.discord.accounts.work.maxLinesPerMessage: 80.
  2. Exercise a live Discord reply path with a runtime discordConfig object that omits maxLinesPerMessage.
  3. Send or generate a reply with more than 17 short lines but fewer than the effective configured line cap.
  4. Exercise the optimized auto-reply fast path so the reply is delivered through deliverDiscordReply(...) and then sendDiscordText(...).

Expected

  • The live reply path uses the effective Discord account config when runtime discordConfig omits maxLinesPerMessage.
  • A reply or already-chunked reply that is still under the configured line cap is delivered without being re-split at the default 17-line boundary.

Actual

  • Before the first fix, some live reply surfaces could treat maxLinesPerMessage as missing and fall back directly to the default 17-line limit.
  • Before the second fix, even when outer delivery used the configured limit, the fast path could drop maxLinesPerMessage and chunkMode before sendDiscordText(...), causing a second chunking pass to re-split at 17 lines.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: ran pnpm test src/discord/accounts.test.ts src/discord/monitor/message-handler.process.test.ts src/discord/monitor/native-command.commands-allowfrom.test.ts; confirmed root fallback, per-account override, explicit runtime override precedence, live message-handler preview/finalization, and a higher-level slash/native reply path. Also ran pnpm test src/discord/monitor/reply-delivery.test.ts; confirmed the fast path preserves maxLinesPerMessage and chunkMode instead of re-splitting at 17. Ran pnpm build after the follow-up fast-path fix.
  • Edge cases checked: runtime discordConfig omits maxLinesPerMessage; explicit runtime value still wins; per-account override beats root config; a reply chunk longer than 17 lines but shorter than the configured limit is not re-split in the fast path.
  • What you did not verify: no manual Discord UI run against a live gateway session in this branch; no webhook/thread-binding-specific manual smoke test beyond the updated code-path coverage.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: revert commits 6acb57223 and 0b5d29b46, or restore the previous direct discordConfig?.maxLinesPerMessage reads in live reply paths plus the previous fast-path sendDiscordText(...) call.
  • Files/config to restore: src/discord/accounts.ts, src/discord/monitor/message-handler.process.ts, src/discord/monitor/native-command.ts, src/discord/monitor/agent-components.ts, src/discord/monitor/reply-delivery.ts, src/discord/monitor/reply-delivery.test.ts
  • Known bad symptoms reviewers should watch for: Discord live replies unexpectedly splitting at 17 lines again when only root-level Discord config is set, or Discord auto-replies that were already chunked under the configured cap getting split again in the fast path.

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk: A live Discord path could still bypass the new resolver if another reply surface sources chunking limits independently.
    • Mitigation: This patch updates the known live surfaces that previously used raw discordConfig?.maxLinesPerMessage and adds direct plus higher-level regressions around the known failing paths.
  • Risk: The fallback could hide a miswired runtime config object by making behavior look correct via merged account config.
    • Mitigation: The tests explicitly cover runtime omission, root fallback, per-account override, and explicit runtime precedence so the intended resolution order stays documented and enforced.
  • Risk: The optimized delivery path could regress again if future chunking options are added to sendDiscordText(...) but not threaded through sendDiscordChunkWithFallback(...).
    • Mitigation: The new regression in src/discord/monitor/reply-delivery.test.ts asserts the fast path forwards both maxLinesPerMessage and chunkMode.

@openclaw-barnacle openclaw-barnacle bot added channel: discord Channel integration: discord size: S labels Mar 8, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 8, 2026

Greptile Summary

This PR fixes two related bugs where Discord live reply surfaces could ignore the configured maxLinesPerMessage and fall back silently to the 17-line default: first, by adding resolveDiscordMaxLinesPerMessage to properly merge the effective per-account config when the runtime discordConfig object omits the field; and second, by threading maxLinesPerMessage and chunkMode through sendDiscordChunkWithFallback into the sendDiscordText fast path so already-valid chunks are not re-split at the default boundary.

  • src/discord/accounts.ts: New resolveDiscordMaxLinesPerMessage correctly prioritises the explicit runtime value, then falls back through resolveDiscordAccount which merges per-account overrides over the root config.
  • src/discord/monitor/reply-delivery.ts: sendDiscordChunkWithFallback now accepts maxLinesPerMessage and chunkMode and passes them positionally to sendDiscordText (indices 5 and 8 in the current signature); both the primary and voice-message fallback call sites in deliverDiscordReply are updated.
  • message-handler.process.ts, native-command.ts, agent-components.ts: All previously-raw discordConfig?.maxLinesPerMessage reads are replaced with resolveDiscordMaxLinesPerMessage(...).
  • Tests: Three new unit tests in a proper resolveDiscordMaxLinesPerMessage describe block, plus integration regressions for the message-handler, slash-command, and fast-path delivery surfaces. The one minor concern is that the fast-path test asserts sendDiscordText arguments by positional index, which is slightly fragile if the function signature changes in the future.

Confidence Score: 4/5

  • PR is safe to merge; the fix is targeted, well-tested, and backward-compatible.
  • The logic is correct, all previously-raw reads are replaced consistently across the known surfaces, and regression coverage covers root fallback, per-account override, explicit runtime precedence, preview/finalization, and fast-path propagation. Score is 4 rather than 5 only because one new test asserts sendDiscordText arguments by positional index, making it slightly brittle if the function signature evolves.
  • No files require special attention beyond the minor positional-index concern in src/discord/monitor/reply-delivery.test.ts.

Last reviewed commit: d15fdd1

@rbutera
Copy link
Contributor Author

rbutera commented Mar 9, 2026

hmm i'm still experiencing 17 line splits on discord even with the fixes in this PR applied. It must be another cause for fallback behaviour. I'll have a look at other potential failure modes and update this PR accordingly

@rbutera
Copy link
Contributor Author

rbutera commented Mar 9, 2026

found another cause of the issue: issue #41017

fixing that now and rolling it into this PR

@rbutera rbutera marked this pull request as draft March 9, 2026 13:13
@rbutera rbutera marked this pull request as ready for review March 9, 2026 14:47
@rbutera
Copy link
Contributor Author

rbutera commented Mar 9, 2026

@altaywtf mind asking greptile to review this? i've manually tested discord and it looks good from my side

@rbutera
Copy link
Contributor Author

rbutera commented Mar 9, 2026

i asked one of my agents to send me a really long message with at least 240 lines and he cooked up this:

image

safe to say this issue is fixed now by this branch

here's a screenshot from before the patch:

image

@altaywtf
Copy link
Member

altaywtf commented Mar 9, 2026

@greptileai review

@rbutera
Copy link
Contributor Author

rbutera commented Mar 9, 2026

@altaywtf addressed Greptile's concerns

I've been using this patch all day and it works great

@altaywtf altaywtf self-assigned this Mar 9, 2026
@altaywtf
Copy link
Member

altaywtf commented Mar 9, 2026

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Can't wait for the next one!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@altaywtf altaywtf force-pushed the fix-discord-message-length branch from 94295b4 to da48317 Compare March 9, 2026 22:23
@altaywtf altaywtf force-pushed the fix-discord-message-length branch from da48317 to 031d032 Compare March 9, 2026 22:29
@altaywtf altaywtf merged commit 64746c1 into openclaw:main Mar 9, 2026
25 of 26 checks passed
@altaywtf
Copy link
Member

altaywtf commented Mar 9, 2026

Merged via squash.

Thanks @rbutera!

@openclaw openclaw deleted a comment from aisle-research-bot bot Mar 9, 2026
mrosmarin added a commit to mrosmarin/openclaw that referenced this pull request Mar 9, 2026
* main: (33 commits)
  Exec: mark child command env with OPENCLAW_CLI (openclaw#41411)
  fix(plugins): expose model auth API to context-engine plugins (openclaw#41090)
  Add HTTP 499 to transient error codes for model fallback (openclaw#41468)
  Logging: harden probe suppression for observations (openclaw#41338)
  fix(discord): apply effective maxLinesPerMessage in live replies (openclaw#40133)
  build(protocol): regenerate Swift models after pending node work schemas (openclaw#41477)
  Agents: add fallback error observations (openclaw#41337)
  acp: harden follow-up reliability and attachments (openclaw#41464)
  fix(agents): probe single-provider billing cooldowns (openclaw#41422)
  acp: add regression coverage and smoke-test docs (openclaw#41456)
  acp: forward attachments into ACP runtime sessions (openclaw#41427)
  acp: enrich streaming updates for ide clients (openclaw#41442)
  Sandbox: import STATE_DIR from paths directly (openclaw#41439)
  acp: restore session context and controls (openclaw#41425)
  acp: fail honestly in bridge mode (openclaw#41424)
  Gateway: tighten node pending drain semantics (openclaw#41429)
  Gateway: add pending node work primitives (openclaw#41409)
  fix(auth): reset cooldown error counters on expiry to prevent infinite escalation (openclaw#41028)
  fix(cron): do not misclassify empty/NO_REPLY as interim acknowledgement (openclaw#41401)
  iOS: reconnect gateway on foreground return (openclaw#41384)
  ...
ademczuk pushed a commit to ademczuk/openclaw that referenced this pull request Mar 10, 2026
…nclaw#40133)

Merged via squash.

Prepared head SHA: 031d032
Co-authored-by: rbutera <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
mukhtharcm pushed a commit to hnykda/openclaw that referenced this pull request Mar 10, 2026
…nclaw#40133)

Merged via squash.

Prepared head SHA: 031d032
Co-authored-by: rbutera <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
jenawant pushed a commit to jenawant/openclaw that referenced this pull request Mar 10, 2026
…nclaw#40133)

Merged via squash.

Prepared head SHA: 031d032
Co-authored-by: rbutera <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
aiwatching pushed a commit to aiwatching/openclaw that referenced this pull request Mar 10, 2026
…nclaw#40133)

Merged via squash.

Prepared head SHA: 031d032
Co-authored-by: rbutera <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
Moshiii pushed a commit to Moshiii/openclaw that referenced this pull request Mar 11, 2026
…nclaw#40133)

Merged via squash.

Prepared head SHA: 031d032
Co-authored-by: rbutera <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
Moshiii pushed a commit to Moshiii/openclaw that referenced this pull request Mar 11, 2026
…nclaw#40133)

Merged via squash.

Prepared head SHA: 031d032
Co-authored-by: rbutera <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
dominicnunez pushed a commit to dominicnunez/openclaw that referenced this pull request Mar 11, 2026
…nclaw#40133)

Merged via squash.

Prepared head SHA: 031d032
Co-authored-by: rbutera <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
dhoman pushed a commit to dhoman/chrono-claw that referenced this pull request Mar 11, 2026
…nclaw#40133)

Merged via squash.

Prepared head SHA: 031d032
Co-authored-by: rbutera <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
Ruijie-Ysp pushed a commit to Ruijie-Ysp/clawdbot that referenced this pull request Mar 12, 2026
…nclaw#40133)

Merged via squash.

Prepared head SHA: 031d032
Co-authored-by: rbutera <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
qipyle pushed a commit to qipyle/openclaw that referenced this pull request Mar 12, 2026
…nclaw#40133)

Merged via squash.

Prepared head SHA: 031d032
Co-authored-by: rbutera <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord size: M

Projects

None yet

2 participants