fix(whatsapp): strip leading whitespace from outbound messages#8052
fix(whatsapp): strip leading whitespace from outbound messages#8052FelixFoster wants to merge 2 commits intoopenclaw:mainfrom
Conversation
src/cron/service/jobs.ts
Outdated
| // If it's a one-shot job and we missed the window, run it ASAP | ||
| // unless it's ancient history (which we might want to flag, but for now run it). | ||
| // The previous logic just returned schedule.atMs, which is correct for "next run", | ||
| // but the scheduler needs to know it's *runnable*. | ||
| return job.schedule.atMs; |
There was a problem hiding this comment.
[P3] Comment doesn’t match the code behavior. computeJobNextRunAtMs still returns job.schedule.atMs for one-shot jobs, so overdue jobs remain represented as a timestamp in the past; the scheduler is what interprets now >= nextRunAtMs as runnable. The comment says “run it ASAP … scheduler needs to know it’s runnable”, which implies returning nowMs (or similar) rather than the original atMs.
Consider rewording this comment to reflect the actual behavior (keeping atMs so it stays due until success).
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cron/service/jobs.ts
Line: 46:50
Comment:
[P3] Comment doesn’t match the code behavior. `computeJobNextRunAtMs` still returns `job.schedule.atMs` for one-shot jobs, so overdue jobs remain represented as a timestamp in the past; the scheduler is what interprets `now >= nextRunAtMs` as runnable. The comment says “run it ASAP … scheduler needs to know it’s runnable”, which implies returning `nowMs` (or similar) rather than the original `atMs`.
Consider rewording this comment to reflect the actual behavior (keeping `atMs` so it stays due until success).
How can I resolve this? If you propose a fix, please make it concise.
Additional Comments (1)
This matters when A minimal fix is to Prompt To Fix With AIThis is a comment left during a code review.
Path: src/web/auto-reply/deliver-reply.ts
Line: 101:103
Comment:
[P1] Caption trimming is inconsistent with text-only trimming. `deliverWebReply` now strips leading whitespace for text-only chunks, but media captions (`caption = remainingText.shift() || undefined`) can still start with newlines/spaces (common for LLM output), so the original formatting issue can persist for media-first replies.
This matters when `mediaList.length > 0` and the first caption chunk begins with whitespace.
A minimal fix is to `trimStart()` (and potentially skip empty) for `caption` similarly to the text-only path.
How can I resolve this? If you propose a fix, please make it concise. |
ecba4a7 to
ad354a8
Compare
|
Thanks @greptile-apps! Fixed in bd79b33. Added |
|
Perfect! The media caption fix looks good at src/web/auto-reply/deliver-reply.ts:101-102. You're properly handling the optional text by trimming This closes the gap I flagged in the review. The PR now consistently trims leading whitespace across all WhatsApp text and media caption paths. 🎯 |
LLM responses frequently begin with \n\n, which survives through sanitizeUserFacingText and reaches the channel as visible blank lines. Root cause: the function used trimmed text for empty-checks but returned the untrimmed 'stripped' variable. Two one-line fixes: 1. Return empty string (not whitespace-only 'stripped') for blank input 2. Apply trimStart() to the final return value Fixes the same issue as openclaw#8052 and openclaw#10612 but at the root cause (sanitizeUserFacingText) rather than scattering trimStart across multiple delivery paths.
LLM responses frequently begin with \n\n, which survives through sanitizeUserFacingText and reaches the channel as visible blank lines. Root cause: the function used trimmed text for empty-checks but returned the untrimmed 'stripped' variable. Two one-line fixes: 1. Return empty string (not whitespace-only 'stripped') for blank input 2. Apply trimStart() to the final return value Fixes the same issue as openclaw#8052 and openclaw#10612 but at the root cause (sanitizeUserFacingText) rather than scattering trimStart across multiple delivery paths.
) * fix: strip leading whitespace from sanitizeUserFacingText output LLM responses frequently begin with \n\n, which survives through sanitizeUserFacingText and reaches the channel as visible blank lines. Root cause: the function used trimmed text for empty-checks but returned the untrimmed 'stripped' variable. Two one-line fixes: 1. Return empty string (not whitespace-only 'stripped') for blank input 2. Apply trimStart() to the final return value Fixes the same issue as #8052 and #10612 but at the root cause (sanitizeUserFacingText) rather than scattering trimStart across multiple delivery paths. * Changelog: note sanitizeUserFacingText whitespace normalization Co-authored-by: Tak Hoffman <[email protected]> --------- Co-authored-by: Tak Hoffman <[email protected]>
…nclaw#16158) * fix: strip leading whitespace from sanitizeUserFacingText output LLM responses frequently begin with \n\n, which survives through sanitizeUserFacingText and reaches the channel as visible blank lines. Root cause: the function used trimmed text for empty-checks but returned the untrimmed 'stripped' variable. Two one-line fixes: 1. Return empty string (not whitespace-only 'stripped') for blank input 2. Apply trimStart() to the final return value Fixes the same issue as openclaw#8052 and openclaw#10612 but at the root cause (sanitizeUserFacingText) rather than scattering trimStart across multiple delivery paths. * Changelog: note sanitizeUserFacingText whitespace normalization Co-authored-by: Tak Hoffman <[email protected]> --------- Co-authored-by: Tak Hoffman <[email protected]>
…nclaw#16158) * fix: strip leading whitespace from sanitizeUserFacingText output LLM responses frequently begin with \n\n, which survives through sanitizeUserFacingText and reaches the channel as visible blank lines. Root cause: the function used trimmed text for empty-checks but returned the untrimmed 'stripped' variable. Two one-line fixes: 1. Return empty string (not whitespace-only 'stripped') for blank input 2. Apply trimStart() to the final return value Fixes the same issue as openclaw#8052 and openclaw#10612 but at the root cause (sanitizeUserFacingText) rather than scattering trimStart across multiple delivery paths. * Changelog: note sanitizeUserFacingText whitespace normalization Co-authored-by: Tak Hoffman <[email protected]> --------- Co-authored-by: Tak Hoffman <[email protected]>
…nclaw#16158) * fix: strip leading whitespace from sanitizeUserFacingText output LLM responses frequently begin with \n\n, which survives through sanitizeUserFacingText and reaches the channel as visible blank lines. Root cause: the function used trimmed text for empty-checks but returned the untrimmed 'stripped' variable. Two one-line fixes: 1. Return empty string (not whitespace-only 'stripped') for blank input 2. Apply trimStart() to the final return value Fixes the same issue as openclaw#8052 and openclaw#10612 but at the root cause (sanitizeUserFacingText) rather than scattering trimStart across multiple delivery paths. * Changelog: note sanitizeUserFacingText whitespace normalization Co-authored-by: Tak Hoffman <[email protected]> --------- Co-authored-by: Tak Hoffman <[email protected]>
bfc1ccb to
f92900f
Compare
|
This pull request has been automatically marked as stale due to inactivity. |
bd79b33 to
2467927
Compare
…nclaw#16158) * fix: strip leading whitespace from sanitizeUserFacingText output LLM responses frequently begin with \n\n, which survives through sanitizeUserFacingText and reaches the channel as visible blank lines. Root cause: the function used trimmed text for empty-checks but returned the untrimmed 'stripped' variable. Two one-line fixes: 1. Return empty string (not whitespace-only 'stripped') for blank input 2. Apply trimStart() to the final return value Fixes the same issue as openclaw#8052 and openclaw#10612 but at the root cause (sanitizeUserFacingText) rather than scattering trimStart across multiple delivery paths. * Changelog: note sanitizeUserFacingText whitespace normalization Co-authored-by: Tak Hoffman <[email protected]> --------- Co-authored-by: Tak Hoffman <[email protected]> (cherry picked from commit 3881af5) # Conflicts: # CHANGELOG.md
This comment was marked as spam.
This comment was marked as spam.
…nclaw#16158) * fix: strip leading whitespace from sanitizeUserFacingText output LLM responses frequently begin with \n\n, which survives through sanitizeUserFacingText and reaches the channel as visible blank lines. Root cause: the function used trimmed text for empty-checks but returned the untrimmed 'stripped' variable. Two one-line fixes: 1. Return empty string (not whitespace-only 'stripped') for blank input 2. Apply trimStart() to the final return value Fixes the same issue as openclaw#8052 and openclaw#10612 but at the root cause (sanitizeUserFacingText) rather than scattering trimStart across multiple delivery paths. * Changelog: note sanitizeUserFacingText whitespace normalization Co-authored-by: Tak Hoffman <[email protected]> --------- Co-authored-by: Tak Hoffman <[email protected]> (cherry picked from commit 3881af5) # Conflicts: # CHANGELOG.md # src/agents/pi-embedded-helpers/errors.ts
…nclaw#16158) * fix: strip leading whitespace from sanitizeUserFacingText output LLM responses frequently begin with \n\n, which survives through sanitizeUserFacingText and reaches the channel as visible blank lines. Root cause: the function used trimmed text for empty-checks but returned the untrimmed 'stripped' variable. Two one-line fixes: 1. Return empty string (not whitespace-only 'stripped') for blank input 2. Apply trimStart() to the final return value Fixes the same issue as openclaw#8052 and openclaw#10612 but at the root cause (sanitizeUserFacingText) rather than scattering trimStart across multiple delivery paths. * Changelog: note sanitizeUserFacingText whitespace normalization Co-authored-by: Tak Hoffman <[email protected]> --------- Co-authored-by: Tak Hoffman <[email protected]>
|
This pull request has been automatically marked as stale due to inactivity. |
|
Superseded with #43539. |
Fixes #8036.
The Problem
LLM responses frequently start with newlines, causing empty space at the top of WhatsApp messages. This looks broken or poorly formatted on mobile devices.
The Fix
Added
.trimStart()to the text payload in three key delivery paths:src/web/auto-reply/deliver-reply.ts: The main auto-reply path.src/infra/outbound/deliver.ts: General outbound delivery logic (ensures chunks are also trimmed).src/channels/plugins/outbound/whatsapp.ts: Programmatic sending (e.g., via tools).Verification
Greptile Overview
Greptile Summary
This PR addresses leading blank space in WhatsApp deliveries (often caused by LLMs starting responses with newlines) by applying
trimStart()in multiple outbound paths:textbefore callingsendMessageWhatsApp.deliverOutboundPayloads): trims the overall text and each chunk before sending, and skips sending if trimming produces an empty string.It also includes small, unrelated changes in cron timer/job comments and
runCommandWithTimeoutspawn logic (stdin-inherit fallback).Confidence Score: 4/5
(5/5) You can turn off certain types of comments like style here!