Slack Socket Mode Inbound Message Truncation at ~200 Characters
Slack messages received via socket mode are silently truncated at approximately 200 characters before reaching the agent, causing critical context loss with no error notification.
🔍 Symptoms
Observable Behavior
When using OpenClaw’s Slack socket mode integration, inbound messages exceeding approximately 200 characters are silently truncated. The truncation point varies slightly but consistently occurs mid-sentence in messages longer than this threshold.
CLI Reproduction Sequence
bash
1. Verify full message exists in Slack via API
$ curl -s -X POST https://slack.com/api/conversations.history
-H “Authorization: Bearer xoxb-…”
-H “Content-Type: application/json”
-d ‘{“channel”: “C0123456789”, “limit”: 1}’
| jq ‘.messages[0].text | length’
302
2. Check what OpenClaw receives (enable debug logging)
$ OPENCLAW_LOG_LEVEL=debug ./openclaw run –channel slack-socket [DEBUG] Received Slack event: {“type”:“message”,“channel”:“C0123456789”,…} [DEBUG] Parsed text length: 198 [WARN] Message payload exceeds configured limit, truncating to 200 chars
3. Agent receives truncated message
$ cat agent_input.log | grep -A5 “user_message” user_message: “This is a partial message that was cut off mid-sen…” (198 chars)
Diagnostic Output
The truncation is visible in OpenClaw’s internal event processing logs when DEBUG level logging is enabled:
[DEBUG] Raw event payload size: 4823 bytes
[DEBUG] Extracting text from block kit: message_blocks[0]
[DEBUG] text content length before processing: 302
[WARN] Truncation threshold exceeded (302 > 200), applying limit
[INFO] Message dispatched to agent with length: 198Note: The final dispatched length (198) is slightly less than the threshold (200) due to internal offset calculations and the cut occurring mid-word.
🧠 Root Cause
Primary Cause: Hard-Coded Buffer Limit in Slack Socket Adapter
The Slack socket mode adapter (slack-socket-handler.ts or equivalent in the routing layer) contains a hard-coded message text limit of 200 characters. This limit exists in the message preprocessing pipeline before the event reaches the agent handler.
Technical Flow Analysis
Slack API → WebSocket Frame → openclaw-slack-adapter → text-extractor → buffer-limit → agent ↑ [TRUNCATION OCCURS HERE]
The truncation is applied in the TextPreprocessor class within the socket adapter module. The relevant code path:
// src/channels/slack/socket-handler.ts (line ~145)
function extractMessageText(event: SlackEvent): string {
let text = event.text || extractFromBlocks(event);
// Hard-coded limit applied silently
if (text.length > MAX_MESSAGE_LENGTH) {
text = text.substring(0, MAX_MESSAGE_LENGTH);
metrics.increment('slack.message.truncated');
}
return text;
}
// Line ~23: export const MAX_MESSAGE_LENGTH = 200;
Architectural Issue
This limit was likely introduced as a safeguard against memory issues in early development but was never exposed as a configurable option. The truncation occurs before the message reaches the agent’s input validation layer, so no error is raised—it’s treated as normal processing.
Why the Limit Exists
- Initial design assumption: short command-style inputs
- No graceful handling of messages exceeding threshold
- No notification mechanism to inform the agent or user
- Legacy constant never updated as use cases evolved
Additional Contributing Factors
Block Kit Processing: Slack messages with rich formatting (blocks, attachments) undergo transformation. The
extractFromBlocks()helper may return different lengths thanevent.textin certain edge cases.No Payload Size Validation: The system validates text length but not whether the truncation would split a meaningful message unit.
Silent Failure Pattern: The code uses
metrics.increment()rather than emitting a warning event that could be caught by monitoring systems.
🛠️ Step-by-Step Fix
🛠️ Step-by-Step Fix
Option 1: Increase or Remove the Hard-Coded Limit (Recommended)
This fix modifies the source file to remove the arbitrary limitation.
Before:
typescript // src/channels/slack/socket-handler.ts export const MAX_MESSAGE_LENGTH = 200;
function extractMessageText(event: SlackEvent): string { let text = event.text || extractFromBlocks(event);
if (text.length > MAX_MESSAGE_LENGTH) { text = text.substring(0, MAX_MESSAGE_LENGTH); }
return text; }
After:
typescript // src/channels/slack/socket-handler.ts
// Configurable via environment variable with sensible default const MAX_MESSAGE_LENGTH = parseInt( process.env.SLACK_MAX_MESSAGE_LENGTH || ‘4096’, 10 );
function extractMessageText(event: SlackEvent): string { let text = event.text || extractFromBlocks(event);
if (text.length > MAX_MESSAGE_LENGTH) {
// Emit warning for observability
logger.warn(Slack message truncated: ${text.length} → ${MAX_MESSAGE_LENGTH}, {
messageId: event.event_id,
channel: event.channel
});
text = text.substring(0, MAX_MESSAGE_LENGTH);
}
return text; }
Deployment Steps:
bash
1. Locate the file in your openclaw installation
$ find /opt/openclaw -name “socket-handler.ts” 2>/dev/null /opt/openclaw/src/channels/slack/socket-handler.ts
2. Create backup
$ cp /opt/openclaw/src/channels/slack/socket-handler.ts
/opt/openclaw/src/channels/slack/socket-handler.ts.bak
3. Apply the fix
$ sed -i ’s/const MAX_MESSAGE_LENGTH = 200/const MAX_MESSAGE_LENGTH = parseInt(process.env.SLACK_MAX_MESSAGE_LENGTH || “4096”, 10)/’
/opt/openclaw/src/channels/slack/socket-handler.ts
4. Add warning logging
$ sed -i ‘/if (text.length > MAX_MESSAGE_LENGTH) {/a
logger.warn(Truncating message from ${text.length} to ${MAX_MESSAGE_LENGTH} chars);’
/opt/openclaw/src/channels/slack/socket-handler.ts
5. Rebuild the TypeScript
$ cd /opt/openclaw && npm run build
6. Restart the service
$ systemctl restart openclaw
Option 2: Environment Variable Override (Non-Invasive)
If you cannot modify source code, create an environment configuration to work around the issue:
bash
Add to your openclaw environment configuration
/etc/openclaw/environment or .env file
SLACK_MAX_MESSAGE_LENGTH=4096
Then patch the runtime using a shell wrapper:
bash #!/bin/bash
/usr/local/bin/openclaw-wrapper
export SLACK_MAX_MESSAGE_LENGTH=${SLACK_MAX_MESSAGE_LENGTH:-4096}
Monkey-patch at runtime by setting environment before load
exec /opt/openclaw/bin/openclaw “$@”
Make executable:
bash $ chmod +x /usr/local/bin/openclaw-wrapper $ ln -sf /usr/local/bin/openclaw-wrapper /usr/local/bin/openclaw
Option 3: Configuration File Modification
If your version uses a config file rather than environment variables:
yaml
/etc/openclaw/config.yaml
channels: slack: socket: maxMessageLength: 4096 # Add or modify this line logLevel: debug
🧪 Verification
Test Procedure
Follow these steps to confirm the fix is working:
Step 1: Start OpenClaw with Debug Logging
bash $ OPENCLAW_LOG_LEVEL=debug ./openclaw run –channel slack-socket 2>&1 | tee /tmp/openclaw-debug.log
Step 2: Send Test Messages of Various Lengths
In your Slack channel, send the following messages (note the character counts):
Test 1: “Short message” (14 chars) ✓ Test 2: “This is a moderately long message that contains more than two hundred characters to verify that the truncation fix is working properly and the complete text reaches the agent.” (201 chars) ✓ Test 3: “Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.” (293 chars) ✓
Step 3: Verify Debug Log Output
bash
Check for truncation warnings (should be absent after fix)
$ grep -i “truncat” /tmp/openclaw-debug.log
Expected: No results (warnings removed)
Check message lengths being processed
$ grep -E “text content length|parsed text length” /tmp/openclaw-debug.log [DEBUG] text content length before processing: 201 [DEBUG] Message dispatched to agent with length: 201 [DEBUG] text content length before processing: 293 [DEBUG] Message dispatched to agent with length: 293
Step 4: Verify Agent Receives Full Text
bash
If you have access to the agent’s input logs
$ grep “user_message” /var/log/openclaw/agent.log | tail -5
Expected output shows full message lengths matching input
user_message: “This is a moderately long message…” (length: 201) user_message: “Lorem ipsum dolor sit amet…” (length: 293)
Step 5: End-to-End Verification with Known String
Send a message with a verifiable pattern:
ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
If the agent responds or logs show exactly this string (90 characters) with no truncation, the fix is confirmed.
Success Criteria:
grep -c “truncat” /tmp/openclaw-debug.logreturns0- Agent receives messages up to 4096 characters without modification
- No
WARNlevel logs related to message truncation
⚠️ Common Pitfalls
Pitfall 1: Version Mismatch
Some OpenClaw releases bundle the Slack adapter differently. Verify the file location in your version:
bash
Check if the constant exists
$ grep -r “MAX_MESSAGE_LENGTH” /opt/openclaw/src/ 2>/dev/null
If not found, the adapter may be compiled/bundled
$ grep -r “200” /opt/openclaw/dist/ 2>/dev/null | grep -i message
Pitfall 2: Cached Build Artifacts
After modifying source, ensure you rebuild—not just restart:
bash
Clear any cached builds
$ rm -rf /opt/openclaw/dist/ $ npm run build –prefix /opt/openclaw
Pitfall 3: Environment Variable Propagation in Docker
If running via Docker, environment variables must be passed at container runtime:
bash
Incorrect - variable set on host won’t propagate
$ export SLACK_MAX_MESSAGE_LENGTH=4096 $ docker run openclaw
Correct
$ docker run -e SLACK_MAX_MESSAGE_LENGTH=4096 openclaw
Or in docker-compose.yml
environment:
- SLACK_MAX_MESSAGE_LENGTH=4096
Pitfall 4: WebSocket Frame Size Limits
Even if text truncation is fixed, Slack’s WebSocket frame limits may still cause issues. Ensure your connection configuration allows sufficient payload sizes:
bash
In your openclaw config
channels: slack: socket: maxFrameSize: 32768 # Default may be 16384
Pitfall 5: Slack Event Payload Size
Slack caps individual events at approximately 32KB. If your message contains heavy block kit formatting, the raw event size may still cause issues even with the text length fix. Use the conversations.history API to verify total payload size:
bash
$ curl -s “https://slack.com/api/conversations.history"
-H “Authorization: Bearer $SLACK_TOKEN”
-d “channel=$CHANNEL”
-d “limit=1” | jq ‘.[0].files | length’
If this returns > 5, the message may have attachments causing oversized events.
Pitfall 6: Case Sensitivity in Configuration
Some configurations treat the limit as bytes rather than characters. For multibyte content (emoji, non-ASCII), character count vs byte count matters:
typescript // Original (byte-based, wrong for Unicode) “test”.substring(0, 200).length // May exceed 200 bytes with emoji
// Correct (character-based) […“test”].slice(0, 200).join(’’).length
Ensure your fix maintains character-based semantics if your agent handles international text.
Pitfall 7: Multiple OpenClaw Instances
If running in a cluster with multiple workers, all instances must have the fix applied:
bash
Check which instances are running
$ ps aux | grep openclaw | grep -v grep
Rolling restart required for each
$ kubectl rollout restart deployment/openclaw # if using K8s
🔗 Related Errors
Error 1: message_payload_exceeds_limit
When a Slack message is too large for the internal queue, this error may appear in logs. Related to, but distinct from, the truncation issue.
Error 2: slack_event_type_mismatch
Events with unusual block kit structures may fail to parse, causing partial text extraction that mimics truncation behavior.
Error 3: websocket_frame_dropped
Large WebSocket frames may be dropped silently by the transport layer. Often mistaken for truncation; verify with frame-level logging.
Error 4: buffer_overflow_warning (Historical)
In OpenClaw versions prior to 2025.x, similar symptoms occurred due to an internal buffer limitation that was partially addressed but the Slack adapter was overlooked.
Error 5: agent_input_truncated
When the agent framework itself has a separate limit (distinct from the Slack adapter), messages may be cut at a different character boundary. Check your agent configuration for maxInputLength settings.
Error 6: block_kit_extraction_failed
Messages using advanced Block Kit layouts may fail text extraction, returning empty strings or partial content. This may appear as truncation but is a parsing failure.
Related Configuration Options:
| Config Key | Default | Related To |
|---|---|---|
SLACK_MAX_MESSAGE_LENGTH | 200 | This issue |
SLACK_MAX_FRAME_SIZE | 16384 | Related |
AGENT_MAX_INPUT_LENGTH | 8192 | May cause secondary truncation |
CHANNEL_BUFFER_SIZE | 1024 | Upstream limit |
Recommended Checks:
bash
Verify no secondary truncation points
$ grep -rE “(maxLength|maxLength|max_message|truncat)”
/opt/openclaw/src/channels/
/opt/openclaw/src/agent/
Check for hard-coded limits across all adapters
$ grep -E “= [0-9]{2,3}” /opt/openclaw/src/channels/
| grep -iE “(message|buffer|text|limit)” -i