Skip to content

feat(zalouser): normalize agent-emitted markdown for Zalo client rendering - #85039

Closed
JOY wants to merge 5 commits into
openclaw:mainfrom
JOY:feat/zalouser-outbound-list-format
Closed

JOY wants to merge 5 commits into
openclaw:mainfrom
JOY:feat/zalouser-outbound-list-format

Conversation

@JOY

@JOY JOY commented May 21, 2026 •

Copy link
Copy Markdown

Summary

The Zalo personal-account client (mobile + web) renders agent-style markdown poorly in two specific ways that the zalouser plugin currently passes through unchanged:

  1. Triple-dash / triple-asterisk horizontal rules (---, ***) render as literal dashes / asterisks on their own line - never as a separator. LLM agents emit them as section dividers; recipients see them as garbage.

  2. List items separated by blank lines render with the blank line preserved, breaking the visual grouping a reader expects from a markdown list. - foo\n- bar reads as one list; - foo\n\n- bar reads as two unrelated items with extra vertical space. LLM agents commonly emit lists this way because Slack / Discord / the web playground render that style best - Zalo is the outlier.

This PR adds a normalizeZalouserOutboundText pre-processor invoked at the top of sendMessageZalouser. Block-aware (skips fenced code blocks), idempotent (only removes characters, never adds), style-safe (skips normalization when caller-supplied plain-mode textStyles are present, since the transport layer does not rebase those offsets).

Tests

outbound-format.test.ts - 25 cases: identity / passthrough, HR stripping positive + negative, inter-item blank-line collapse for bullet / asterisk / numbered, edge cases at list boundaries, hard newline cap, fenced code block preservation (triple-backtick + triple-tilde, longer fences, lists-inside-fence, prose-around-fence, unclosed fence), idempotency property.

send.test.ts - 3 new integration cases: end-to-end normalization on list-with-blanks, fence preservation through sendMessageZalouser, plain-mode skip with caller-supplied textStyles.

Full zalouser package suite: 185 passed, 2 skipped (unrelated).

Real behavior proof

Behavior or issue addressed: Inbound LLM-generated markdown containing a bullet list with blank lines between items rendered on the Zalo personal-account client as visually fragmented paragraphs (one blank line of vertical space between each bullet), instead of as a tight grouped list. Same for --- horizontal-rule lines - they rendered as literal dashes instead of as a separator.

Real environment tested: Em Huyen agent (Tingee customer-support bot, Vietnamese) running on the openclaw runtime with @openclaw/zalouser paired to a real Zalo personal account, talking to a real Zalo group room (Capypara.AI). Tested on both Zalo Mobile (Android client) and Zalo Desktop (dark theme) on the same conversation, after normalizeZalouserOutboundText was wired into sendMessageZalouser.

Exact steps or command run after this patch:

  1. Apply this PR's outbound-format.ts + send.ts changes to the running zalouser plugin.
  2. Restart the agent container so the plugin reloads.
  3. From a separate Zalo account, send a photo of a Tingee soundbox label to the Capypara.AI group with the text @Em Huyền reset loa cho anh.
  4. Wait for Em Huyen to reply (the bot uses markdown with - ... bullets separated by blank lines for its hotline / Zalo OA list).
  5. Open the same conversation on Zalo Android and on Zalo Desktop; screenshot the bot's reply on each.

Evidence after fix:

Zalo Android (Capypara.AI group, dark theme):

Em Huyen reply on Zalo Android

Zalo Desktop (same conversation):

Em Huyen reply on Zalo Desktop

Both screenshots show the reply with two bullets (📞 Hotline: 1900 255 567 + 💬 Zalo OA: Tingee by Heno) rendered as a tight group with NO blank line between them. The agent's raw output emitted blank lines between each bullet - the post-fix normalizer collapses them before they reach the Zalo client.

Observed result after fix: On both Zalo Mobile and Zalo Desktop, the two-bullet list renders as one tight visual group. Recipients no longer see contact options fragmented into separate paragraphs. --- HR lines from the same agent are also no longer emitted as literal dashes (covered in the same normalizer pass).

What was not tested: I have not run a head-to-head BEFORE / AFTER screenshot pair in the same Zalo conversation - the pre-fix rendering was the live deployment state captured separately in a downstream vendor patch's tracking ticket, which is what motivated this PR. The AFTER screenshots above are from a real deployment with the fix in place. Maintainers with a Zalo test account can reproduce the BEFORE state by reverting extensions/zalouser/src/send.ts to the pre-PR version and re-sending the same agent reply.

Screenshots live on a separate proof/zalouser-em-huyen-screenshots branch on the fork so the upstream merge does not import binaries into openclaw history.

Refs

Companion to #84924 (inbound photo support upstream PR). Both came from the same deployment surfacing real rendering gaps in the zalouser plugin.

🤖 Generated with Claude Code

@openclaw-barnacle openclaw-barnacle Bot added channel: zalouser Channel integration: zalouser size: M triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 21, 2026
@clawsweeper

clawsweeper Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed July 1, 2026, 2:55 AM ET / 06:55 UTC.

Summary
The PR adds a Zalo markdown-mode outbound text normalizer plus tests for HR removal, list blank-line collapse, fenced code preservation, CRLF handling, plus bullets, and plain-send pass-through.

PR surface: Source +186, Tests +308. Total +494 across 4 files.

Reproducibility: yes. for the blocking review finding: source inspection shows markdown-mode sends call the new normalizer before the existing parser's indented-code branch can preserve literal code-looking content. The user-facing list-rendering goal also has after-fix Zalo Android/Desktop screenshot proof.

Review metrics: 1 noteworthy metric.

  • Existing Send Behavior Changed: 1 markdown-mode outbound path changed. All Zalo channel replies that set textMode: markdown would have HR/list spacing rewritten before native style parsing.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🦞 diamond lobster ✨ media proof bonus
Patch quality: 🧂 unranked krab
Result: blocked by patch quality or review findings.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Preserve four-space and tab-indented markdown code blocks before HR/list normalization and add focused regression tests.
  • [P2] After that repair, get maintainer acceptance for the markdown-mode Zalo output compatibility change.

Risk before merge

  • [P1] Merging as-is can silently drop or collapse literal content in four-space or tab-indented markdown code blocks on markdown-mode Zalo sends.
  • [P1] Even after the code-block blocker is fixed, the PR intentionally changes existing markdown-mode Zalo output by removing HR marker lines and some blank-line spacing, so maintainers need to accept that compatibility tradeoff.

Maintainer options:

  1. Preserve Indented Code First (recommended)
    Teach the normalizer to pass through four-space and tab-indented markdown code blocks before HR/list prose cleanup, with focused regression coverage.
  2. Accept The Rendering Compatibility Change
    After the code-block blocker is fixed, maintainers can intentionally accept that markdown-mode Zalo sends remove HR markers and some blank-line spacing for better client rendering.
  3. Pause For Channel-Owner Validation
    If maintainers are not ready to change existing markdown-mode output, pause this PR until a Zalo owner validates the rendering policy or chooses an opt-in path.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Preserve 4-space and tab-indented markdown code blocks in `extensions/zalouser/src/outbound-format.ts` before HR/list normalization, add regression tests for indented `---` and blank-line-separated list-looking code, keep default/plain sends literal, and run `node scripts/run-vitest.mjs extensions/zalouser/src/outbound-format.test.ts extensions/zalouser/src/send.test.ts extensions/zalouser/src/text-styles.test.ts`.

Next step before merge

  • [P2] A narrow automated repair can preserve indented code and add regression coverage; maintainer compatibility acceptance remains after that repair.

Security
Cleared: The diff adds local Zalo text normalization and focused tests only; it does not change dependencies, CI, permissions, secrets handling, downloads, or package execution paths.

Review findings

  • [P1] Preserve indented code before prose normalization — extensions/zalouser/src/outbound-format.ts:133-159
Review details

Best possible solution:

Normalize only Zalo markdown prose while preserving every literal/code form the current parser preserves, then let maintainers explicitly accept the channel-specific output change.

Do we have a high-confidence way to reproduce the issue?

Yes for the blocking review finding: source inspection shows markdown-mode sends call the new normalizer before the existing parser's indented-code branch can preserve literal code-looking content. The user-facing list-rendering goal also has after-fix Zalo Android/Desktop screenshot proof.

Is this the best way to solve the issue?

No, not yet: the owner boundary is reasonable, but the normalizer must preserve all code forms already supported by parseZalouserTextStyles before this is the best fix.

Full review comments:

  • [P1] Preserve indented code before prose normalization — extensions/zalouser/src/outbound-format.ts:133-159
    sendMessageZalouser now runs this normalizer before parseZalouserTextStyles, but the existing parser treats four-space and tab-indented lines as literal code. Because these patterns accept leading whitespace, markdown-mode text containing --- or - a\n\n - b is rewritten before the parser can preserve it; segment indented code as literal and add regression coverage.
    Confidence: 0.91

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against b2355ef6a226.

Label changes

Label justifications:

  • P2: This is a normal-priority Zalo channel rendering improvement with a concrete channel-specific correctness blocker.
  • merge-risk: 🚨 compatibility: The PR changes existing markdown-mode Zalo send semantics by removing HR markers and blank-line spacing that previously reached the parser unchanged.
  • merge-risk: 🚨 message-delivery: The current patch can silently drop or collapse literal content in indented markdown code blocks before delivery.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦞 diamond lobster and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (screenshot): The PR body and inspected Zalo Android/Desktop screenshots show after-fix real client behavior with the contact items rendered as a tight group; HR behavior is test-covered rather than visually shown.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body and inspected Zalo Android/Desktop screenshots show after-fix real client behavior with the contact items rendered as a tight group; HR behavior is test-covered rather than visually shown.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The PR body and inspected Zalo Android/Desktop screenshots show after-fix real client behavior with the contact items rendered as a tight group; HR behavior is test-covered rather than visually shown.
Evidence reviewed

PR surface:

Source +186, Tests +308. Total +494 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 187 1 +186
Tests 2 308 0 +308
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 495 1 +494

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs extensions/zalouser/src/outbound-format.test.ts extensions/zalouser/src/send.test.ts extensions/zalouser/src/text-styles.test.ts.

What I checked:

Likely related people:

  • darkamenosa: Merged PR feat(zalouser): add markdown-to-Zalo text style parsing #43324 added parseZalouserTextStyles, textMode: markdown, and the send/tests this PR builds on. (role: introduced markdown formatting behavior; confidence: high; commits: a6711afdc2bb, 99c43e7d052e, 401d8e9c0e7e; files: extensions/zalouser/src/send.ts, extensions/zalouser/src/text-styles.ts, extensions/zalouser/src/text-styles.test.ts)
  • steipete: Recent GitHub history shows repeated Zalo runtime, adapter, send helper, and test maintenance around the affected channel path. (role: recent adjacent contributor; confidence: medium; commits: 05eda57b3c72, c25fb9a6e8c4, f9025c3f5580; files: extensions/zalouser/src/send.ts, extensions/zalouser/src/channel.adapters.ts, extensions/zalouser/src/send.test.ts)
  • shakkernerd: GitHub history shows Zalo test/runtime decoupling work on send and text-style related files after the markdown parser landed. (role: adjacent test/runtime contributor; confidence: medium; commits: 8d805a02fde8; files: extensions/zalouser/src/send.ts, extensions/zalouser/src/text-styles.ts, extensions/zalouser/src/send.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels May 21, 2026
@clawsweeper

clawsweeper Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

✨ Hatched: 🌱 uncommon Sunspot Branchling

Hatch command

Comment @clawsweeper hatch when this PR is hatchable.

Hatchability rules:

  • Merged PRs are hatchable.
  • Open PRs are hatchable when they are status: 👀 ready for maintainer look, status: 🚀 automerge armed, or labeled clawsweeper:automerge.
  • Closed unmerged PRs are hatchable only when one of those hatchable labels is still present in the durable record.

Rarity: 🌱 uncommon.
Trait: watches the merge queue.
Image traits: location green-check meadow; accessory CI status badge; palette plum, gold, and soft gray; mood proud; pose nestled inside a glowing shell; shell woven fiber shell; lighting calm overcast light; background quiet workflow signs.
Share on X: post this hatch
Copy: My PR egg hatched a 🌱 uncommon Sunspot Branchling in ClawSweeper.

What is this egg doing here?
  • Eggs appear after the PR passes real-behavior proof. It is here for vibes, not verdicts: it does not change labels, ratings, merge decisions, or automation.
  • The shell reacts to review momentum: open follow-up work warms it up, re-review makes it wobble, and a clean final review lets it hatch.
  • Hatchability usually comes from sufficient real-behavior proof, no blocking P0/P1/P2 findings, no security attention needed, and clean correctness. A merged PR is already final, so merge makes the egg hatchable independently.
  • The hatch is seeded from this repository and PR number, so the same PR keeps the same creature; the reviewed head SHA can only change safe visual details.
  • Rarity is just collectible sparkle: 🥚 common, 🌱 uncommon, 💎 rare, ✨ glimmer, and 🌈 legendary.

@JOY

JOY commented May 21, 2026

Copy link
Copy Markdown
Author

@clawsweeper Thanks for the careful review. Both P1 and P2 findings were correct - addressed in 11d022974a.

P1 - fenced code block preservation
The normalizer now walks the text fence-by-fence (recognising triple-backtick and triple-tilde fences with any info string) and only applies HR strip + list blank-line collapse to prose segments. Code blocks - including YAML frontmatter, config snippets, or anything that legitimately contains a --- line - pass through verbatim. An unclosed fence treats the tail as code (defensive: do not rewrite content the user might be reading mid-truncation).

6 new outbound-format.test.ts cases pin the contract:

  • --- line inside triple-backtick fence preserved
  • --- line inside triple-tilde fence preserved
  • Blank-lined "list" inside a fence preserved
  • 4+ backtick fences recognised
  • Prose around a fence still normalizes; fence content stays intact
  • Unclosed fence does not normalize the tail

P2 - textStyles offset safety
sendMessageZalouser now skips normalization entirely when textMode !== "markdown" AND options.textStyles is non-empty. Markdown mode is unaffected because parseZalouserTextStyles re-derives style ranges from the post-normalization text. Added an integration test in send.test.ts asserting that a plain-mode send with caller-supplied styles reaches the transport with the original text + original style array verbatim.

Real behavior proof
You are right that I removed the "verified live deployment" line from the PR body - my contributor account cannot attach a redacted Zalo client screenshot from the inside, and I should not have made that claim without an attached artifact. The normalizer was first prototyped as a vendor patch in a downstream deployment where it visibly fixed the rendering, but the proof for upstream review needs to come from a maintainer with their own Zalo test account. The unit + integration tests cover the contract; the visual outcome is best confirmed by a maintainer running the build against a real Zalo client.

Full zalouser suite: 185 passed, 2 skipped (unrelated).

Ready for re-review.

@JOY

JOY commented May 21, 2026

Copy link
Copy Markdown
Author

Real Zalo client proof attached

@clawsweeper Per the proof request, here are screenshots from the Em Huyen agent (Tingee customer-support bot) running this normalizer in a live deployment against real Zalo clients - mobile and desktop, same conversation.

Zalo Android (Capypara.AI group, dark theme):

Em Huyen on Zalo Android

Zalo Desktop (same conversation):

Em Huyen on Zalo Desktop

What to look at:

The bot's reply contains a markdown list with two bullets:

📞 Hotline: 1900 255 567
💬 Zalo OA: Tingee by Heno

Both clients render those two bullets as a tight group with no blank line between them. The original agent output emitted blank lines between each bullet (which is what other channels render best). Without normalizeZalouserOutboundText, the Zalo client would preserve those blank lines and the two contact options would visually fragment into two unrelated paragraphs.

Confirms the fix matches the real client behaviour the PR claims to address. Same fix lands cleanly on both Zalo Mobile and Zalo Desktop because the rendering quirk lives in the Zalo client, not the transport.

Screenshots live on a separate proof/zalouser-em-huyen-screenshots branch on the fork (not on the feature branch) so the upstream merge does not import the binaries into openclaw history. README at docs/proof/zalouser-em-huyen/README.md on that branch documents what each screenshot shows.

@JOY

JOY commented May 21, 2026

Copy link
Copy Markdown
Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 21, 2026
@JOY
JOY force-pushed the feat/zalouser-outbound-list-format branch from c4cb11b to f15de9e Compare May 21, 2026 18:17
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels May 21, 2026
@JOY

JOY commented May 22, 2026

Copy link
Copy Markdown
Author

Heads up on the check-dependencies failure - it is unrelated to this PR's changes.

The knip deadcode shard reports two files as unused:

extensions/qa-lab/src/auth-profile-fixture.ts
extensions/qa-lab/src/codex-plugin-fixture.ts

Both are actually imported by extensions/qa-lab/src/codex-plugin-lifecycle.test.ts (lines 10 + 18), so they are not genuinely dead. They were added very recently on main (bbf3eec786 test(qa-lab): cover codex plugin lifecycle fixtures) alongside a revert (46c8864048), which appears to have left the knip entry/allowlist config out of sync on main itself.

This PR is rebased cleanly onto current main and only touches extensions/zalouser/**. The deadcode false-positive is inherited from main, not introduced here, and fixing the qa-lab knip config from a zalouser PR would be out of scope (and would likely conflict with a maintainer-side fix). Happy to rebase once main is green again.

All other checks pass, including Real behavior proof (after-fix screenshots from Zalo Mobile + Desktop are in the PR body).

@JOY

JOY commented May 22, 2026

Copy link
Copy Markdown
Author

@clawsweeper re-review

The two correctness blockers from the prior verdict are both fixed in the current head (f15de9e85c):

  • Code-fence content loss (P1): the normalizer is now block-aware - it walks the text fence-by-fence and skips all content inside ``` / ~~~ fenced blocks. A --- line or blank-lined list inside a code fence is preserved verbatim. 6 new tests in outbound-format.test.ts pin this.
  • Plain-mode textStyles rewrite (P2): sendMessageZalouser now skips normalization entirely when textMode is not markdown AND caller-supplied textStyles are present, so style offsets never desync. Integration test in send.test.ts pins this.

Real behavior proof (Zalo Mobile + Desktop screenshots) is in the PR body and already accepted (proof: 📸 screenshot).

@clawsweeper

clawsweeper Bot commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@JOY
JOY force-pushed the feat/zalouser-outbound-list-format branch from f15de9e to a6e4b46 Compare May 22, 2026 04:35
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 22, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 22, 2026
@JOY

JOY commented May 22, 2026

Copy link
Copy Markdown
Author

@clawsweeper re-review

Both findings from the last pass are fixed in 3f3da8849c:

  • P1 (plain-send literal contract): normalization now runs ONLY inside the textMode === "markdown" branch of sendMessageZalouser. Default / plain sends (the direct zalouser tool path) pass through byte-for-byte - a literal --- or deliberate blank-line spacing is preserved. The channel reply adapters already set textMode: "markdown" (channel.adapters.ts:116,140), so the Em Huyen agent-reply rendering this PR targets is unaffected. parseZalouserTextStyles re-derives styles from the normalized text inside that branch, so offsets stay aligned with no special-casing.

  • P2 (opener-aware fence matching): the scanner now records the opening fence char + length and closes only on a bare fence of the SAME char with length >= the opener (mirroring the isClosingFence contract in text-styles.ts). A ~~~ line inside a ``` block, or a shorter same-char run, is now treated as code - so following ---/list content is no longer stripped.

New tests pin both: 3 fence cases in outbound-format.test.ts (mismatched marker, shorter run, longer run) and the plain-vs-markdown contract in send.test.ts. Full zalouser suite: 188 passed, 2 skipped.

@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 22, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels May 22, 2026
@RomneyDa

Copy link
Copy Markdown
Member

Heads up: this PR needs to be updated against current main before the new required Dependency Guard check can pass.

@JOY
JOY force-pushed the feat/zalouser-outbound-list-format branch from 55f4b5c to a545877 Compare May 29, 2026 13:04
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 29, 2026
@JOY

JOY commented May 29, 2026

Copy link
Copy Markdown
Author

Rebased onto current main (a545877) to clear the Dependency Guard as requested — check-dependencies, check-guards, check-lint, check-prod-types all green now, and the 34 zalouser outbound-format tests pass.

The remaining check-test-types failure is not in this PR's files — it's in extensions/googlechat/src/targets.test.ts and extensions/matrix/src/matrix/sdk/transport.test.ts (TS2352 Response mock conversion). This diff only touches extensions/zalouser/src/*, so those errors are pre-existing on main (likely a tsgo/Response typing change unrelated to zalouser). Happy to rebase again once main's test-types are green.

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label May 29, 2026
@JOY
JOY force-pushed the feat/zalouser-outbound-list-format branch from a545877 to d6d2ddb Compare June 1, 2026 03:27
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 1, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jun 1, 2026
@JOY

JOY commented Jun 1, 2026

Copy link
Copy Markdown
Author

Rebased onto current main (d6d2ddb) to pick up the check-test-types repair (67697fa test: repair current main extension checks). The check-test-types shard that was red is now green - the failing extensions/googlechat/* and extensions/matrix/* casts were a transient ~43-minute break on main (introduced by 58e82d91, fixed by 67697fa), not from this PR.

The one remaining red check, check-additional-boundaries-a, fails only on prompt:snapshots:check with drift in test/fixtures/agents/prompt-snapshots/codex-runtime-happy-path/*. This PR touches only extensions/zalouser/src/* (4 files) and zero snapshot/fixture files; the drifting fixtures were last modified by #88458 on main. This looks like an unregenerated prompt snapshot on main rather than anything from this change - a maintainer running pnpm prompt:snapshots:gen on main would clear it. Happy to rebase again once that lands.

JOY added 5 commits June 5, 2026 23:17
…ering

The Zalo personal-account client (mobile + web) renders agent-style
markdown poorly in two specific ways:

1. Triple-dash / triple-asterisk horizontal rules (---, ***) render
   as literal dashes / asterisks on their own line, not as a separator.
   They add visual noise without conveying structure.

2. List items separated by blank lines render with the blank line
   preserved, breaking the visual grouping a reader expects from a
   markdown list. LLM agents commonly emit lists with surrounding
   blank lines because that is what Slack / Discord / the web
   playground render best - Zalo is the outlier.

Add a normalizeZalouserOutboundText pre-processor invoked at the top
of sendMessageZalouser. The transform is conservative: it only matches
content that is unambiguously a markdown HR or a blank line inside a
list, so plain prose passes through unchanged. It is also idempotent
(only removes characters, never adds), so applying it twice is
identical to once.

Behavior:
- Strips lines that are nothing but 3+ dashes / asterisks (with optional
  leading / trailing whitespace). Leaves surrounding newlines so adjacent
  paragraphs keep their blank-line break.
- Collapses 1+ blank lines BETWEEN, BEFORE, or AFTER list items
  (-, *, 1.) down to a single newline so the list reads as one block.
- Hard cap of 2 consecutive newlines anywhere else (defensive).

Tests: 19 cases in outbound-format.test.ts covering identity / passthrough,
HR stripping (positive + negative), inter-item blank-line collapse for
bullet, asterisk, and numbered lists, edge cases at list boundaries,
the hard newline cap, and an idempotency property assertion on a
representative agent reply.

Verified live against the Zalo client (mobile) on the Tingee deployment
where this normalizer was first prototyped as a vendor patch.
Addresses both findings from the upstream review pass on #85039:

P1 (confidence 0.91) - the previous version applied HR strip + list
blank-line collapse globally, so a markdown reply containing a fenced
code block with a `---` line (YAML frontmatter, config snippet, etc.)
lost that line. Fix: walk the text fence-by-fence and only normalize
prose segments. ``` and ~~~ fences with any info string are recognised
and their content passes through verbatim. An unclosed fence treats
the tail as code (defensive: don't aggressively rewrite content the
user might be reading mid-truncation).

P2 (confidence 0.82) - in non-markdown mode, caller-supplied
options.textStyles describe offsets into the ORIGINAL text. The
transport layer only clamps style ranges, never rebases them, so
removing characters from the original text could land styles on the
wrong content. Fix: skip normalization entirely when textMode is not
markdown AND textStyles is non-empty. Markdown mode is unaffected
because parseZalouserTextStyles re-derives styles from the
post-normalization text.

Tests:
- 6 new outbound-format.test.ts cases for fence preservation:
  triple-backtick + triple-tilde fences, longer fences, lists inside
  fences, mixed prose-around-fence, unclosed-fence defensive behavior.
- 3 new send.test.ts integration cases: end-to-end normalization on
  list-with-blanks, fence preservation through sendMessageZalouser,
  and the plain-mode-textStyles skip path.

All 185 zalouser package tests pass (2 unrelated skipped).
openclaw's check-lint shard rejects same-line `if (cond) return val;` form
and requires explicit braces. Convert 3 occurrences in outbound-format.ts
to the braced form. No behavior change; all 41 outbound-format + send.test
cases still pass.
Addresses both findings from the second upstream review pass on #85039:

P1 (confidence 0.92) - normalization was applied to default/plain sends
too. The direct zalouser tool calls sendMessageZalouser WITHOUT
textMode, and current main treats those as literal text. Stripping
`---` or collapsing blank lines from a literal send corrupts content the
caller meant to deliver byte-for-byte. Fix: normalize ONLY inside the
`textMode === "markdown"` branch (the agent-reply path - channel
adapters already set textMode: "markdown"). Plain sends now pass through
untouched, and the markdown branch re-derives styles via
parseZalouserTextStyles so caller offsets stay aligned without
special-casing.

P2 (confidence 0.92) - the fence scanner flipped state on ANY 3+
backtick OR tilde line, so a `~~~` line inside a ``` block (or a shorter
run of the same char) wrongly ended the fence and exposed following
`---`/list content to stripping. Fix: opener-aware matching mirroring
text-styles.ts - record the opener char + length, close only on a bare
fence of the SAME char with length >= the opener.

Tests:
- outbound-format.test.ts: 3 new fence cases (tilde line inside backtick
  fence stays code; shorter same-char run does not close; longer run
  >= opener does close and trailing prose re-normalizes).
- send.test.ts: markdown-path normalization proven via HR strip (stable
  under the style parser); plain sends asserted literal both with and
  without caller textStyles.

Full zalouser suite: 188 passed, 2 skipped.
Two polish findings from the third upstream review pass on #85039:

P2 (confidence 0.88) - normalizeZalouserOutboundText split only on \n, so
Windows-style agent output (`---\r\n`, `- a\r\n\r\n- b`) kept a trailing
\r on each line. The $-anchored, [ \t]-only HR / list / fence matchers
then failed to fire and the broken spacing / literal HR reached Zalo.
Fix: normalize \r\n? -> \n up front, mirroring the markdown style parser
in text-styles.ts. Covers CRLF and lone-CR (old-mac) endings.

P3 (confidence 0.82) - the zalouser markdown parser treats `+ item` as an
unordered list, but the blank-line collapse regexes only matched `-`,
`*`, and numbered items. A `+` list separated by blank lines still
rendered fragmented. Fix: add `+` to the shared list-item character
class in all three patterns, and extend the `after` negative lookahead
to exclude `*`/`+` so list-to-list gaps stay with the `between` rule.

Tests: 6 new outbound-format.test.ts cases (CRLF bullets, CR-terminated
HR, lone-CR; `+` bullets, mixed -/*/+/numbered, prose-to-+-list).
Full zalouser suite: 194 passed, 2 skipped.
@JOY
JOY force-pushed the feat/zalouser-outbound-list-format branch from d6d2ddb to 57012bb Compare June 5, 2026 16:17
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 5, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jun 5, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 16, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

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

Labels

channel: zalouser Channel integration: zalouser merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M stale Marked as stale due to inactivity status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants