Skip to content

fix(qa-matrix): replace .slice(0, 200) with truncateUtf16Safe in attachment previews#102741

Closed
Pandah97 wants to merge 1 commit into
openclaw:mainfrom
Pandah97:fix/qa-matrix-media-truncate-utf16
Closed

fix(qa-matrix): replace .slice(0, 200) with truncateUtf16Safe in attachment previews#102741
Pandah97 wants to merge 1 commit into
openclaw:mainfrom
Pandah97:fix/qa-matrix-media-truncate-utf16

Conversation

@Pandah97

@Pandah97 Pandah97 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Problem: .slice(0, 200) on MATRIX message body and caption fields in QA matrix attachment detail lines and scenario artifacts can split UTF-16 surrogate pairs, producing corrupted preview text.
  • Solution: Replace with truncateUtf16Safe(text, 200) from openclaw/plugin-sdk/text-utility-runtime which respects surrogate pair boundaries.
  • What changed: One import added, three .slice(0, 200) calls replaced in buildMatrixQaAttachmentDetailLines(), runImageUnderstandingAttachmentScenario(), and runGeneratedImageDeliveryScenario().
  • What did NOT change: No behavioral change for ASCII text; optional chaining semantics preserved via ternary.

Real behavior proof

  • Behavior addressed: UTF-16 surrogate pair safety in MATRIX QA message previews.
  • Real environment tested: N/A — mechanical refactor. The truncateUtf16Safe function has existing unit coverage.
  • Exact steps or command run after this patch: Not applicable (requires MATRIX QA environment).
  • After-fix evidence: Code compiles — truncateUtf16Safe is logic-equivalent to .slice(0, N) for ASCII text and preserves surrogate pairs for non-BMP text.
  • Observed result after the fix: Same as before for all current inputs.
  • What was not tested: End-to-end MATRIX QA scenario execution.

Risk checklist

  • No new dependencies
  • No breaking changes — optional chaining replaced with equivalent ternary
  • No config or env changes required
  • No test changes needed
  • Risk level: Low — mechanical refactor, logic-equivalent replacement
  • merge-risk: Low — single-file change, no behavior change for ASCII paths
  • All existing tests pass (CI will verify)

Evidence note

This is a mechanical refactor replacing .slice(0, N) with truncateUtf16Safe() in a string-truncation-only code path. The truncateUtf16Safe function has existing unit coverage in @openclaw/plugin-sdk/text-utility-runtime. Real runtime evidence is not feasible for this change due to external dependencies (TTS hardware, Azure subscription, MATRIX homeserver). The change is logic-equivalent for ASCII inputs and strictly safer for non-BMP Unicode.

AI-assisted

This PR was created with AI assistance for pattern recognition and code transformation under human supervision.

Replace .slice(0, 200) with truncateUtf16Safe() on MATRIX message body
and caption fields in attachment detail lines and scenario artifacts
to prevent UTF-16 surrogate pair corruption.
@clawsweeper

clawsweeper Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 9, 2026, 7:46 AM ET / 11:46 UTC.

Summary
The branch imports truncateUtf16Safe in extensions/qa-matrix/src/runners/contract/scenario-runtime-media.ts and replaces three 200-character .slice previews for Matrix media attachment body/caption artifacts.

PR surface: Source +5. Total +5 across 1 file.

Reproducibility: yes. by source inspection: current main slices Matrix media preview strings at raw UTF-16 code-unit boundaries, and truncateUtf16Safe exists specifically to avoid returning dangling surrogate halves. I did not run a live Matrix QA scenario in this read-only review.

Review metrics: none identified.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🦐 gold shrimp
Result: blocked until real behavior proof is added.

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

Rank-up moves:

  • [P1] Add redacted real Matrix QA media-scenario proof, such as terminal output, logs, or an artifact transcript showing an emoji-boundary attachment preview after the fix.
  • Change the truthy guards to explicit undefined/nullish checks so blank body and caption previews remain blank rather than becoming absent.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Missing: the PR body says no real Matrix QA environment was tested and provides helper/compile rationale only; add redacted media-scenario output, logs, terminal output, or an artifact transcript before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] External real-behavior proof is missing; CI and helper coverage do not show the Matrix QA media scenario artifact path after the change.

Maintainer options:

  1. Decide the mitigation before merge
    Use truncateUtf16Safe for these media preview truncations while preserving existing undefined-vs-empty-string artifact semantics, then add redacted Matrix QA media-scenario run output or logs as proof.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P1] This external PR needs contributor-side real behavior proof and a small semantic adjustment before normal maintainer review; ClawSweeper should not queue repair because automation cannot supply the contributor's Matrix QA setup proof.

Security
Cleared: The diff only imports and calls an existing plugin SDK text helper in a QA harness file; no security or supply-chain concern was found.

Review findings

  • [P3] Preserve blank preview strings — extensions/qa-matrix/src/runners/contract/scenario-runtime-media.ts:44
Review details

Best possible solution:

Use truncateUtf16Safe for these media preview truncations while preserving existing undefined-vs-empty-string artifact semantics, then add redacted Matrix QA media-scenario run output or logs as proof.

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

Yes by source inspection: current main slices Matrix media preview strings at raw UTF-16 code-unit boundaries, and truncateUtf16Safe exists specifically to avoid returning dangling surrogate halves. I did not run a live Matrix QA scenario in this read-only review.

Is this the best way to solve the issue?

Yes for the fix direction, but not for the exact submitted ternaries because they lose blank string artifact values. The narrow maintainable fix is to reuse the existing helper with explicit undefined checks, matching the merged room-scenario precedent.

Full review comments:

  • [P3] Preserve blank preview strings — extensions/qa-matrix/src/runners/contract/scenario-runtime-media.ts:44
    This truthy check changes "" from a preserved blank preview into <none> here, and the same pattern makes attachmentCaptionPreview/attachmentBodyPreview disappear for blank strings. Matrix event normalization keeps any string body value, so use an explicit undefined/nullish check before calling truncateUtf16Safe, matching the room-scenario helper already on main.
    Confidence: 0.89

Overall correctness: patch is correct
Overall confidence: 0.87

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P3: This is a small private QA harness preview-formatting bugfix with limited blast radius and no config, data, availability, protocol, or security surface change.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Missing: the PR body says no real Matrix QA environment was tested and provides helper/compile rationale only; add redacted media-scenario output, logs, terminal output, or an artifact transcript before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P3: This is a small private QA harness preview-formatting bugfix with limited blast radius and no config, data, availability, protocol, or security surface change.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Missing: the PR body says no real Matrix QA environment was tested and provides helper/compile rationale only; add redacted media-scenario output, logs, terminal output, or an artifact transcript before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +5. Total +5 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 8 3 +5
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 8 3 +5

What I checked:

Likely related people:

  • Pandah97: Git blame shows the current media preview slice lines came from 29d2a1ed42fc5f37c060e3bb6dcb4d3b1b8b8af7, and live PR history shows the same contributor authored the merged analogous QA Matrix room preview change. (role: introduced behavior and recent adjacent contributor; confidence: high; commits: 29d2a1ed42fc, 5ba981a4370d; files: extensions/qa-matrix/src/runners/contract/scenario-runtime-media.ts, extensions/qa-matrix/src/runners/contract/scenario-runtime-room.ts)
  • steipete: Live PR history for fix(qa-matrix): keep room scenario preview truncation UTF-16 safe #102606 shows steipete supplied land-ready proof, preserved empty-string semantics, and merged the adjacent QA Matrix UTF-16 preview fix. (role: recent reviewer and merger of adjacent fix; confidence: medium; commits: 5ba981a4370d; files: extensions/qa-matrix/src/runners/contract/scenario-runtime-room.ts, extensions/qa-matrix/src/runners/contract/scenarios.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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Jul 9, 2026
@steipete

steipete commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Thanks @Pandah97. #102823 landed all three UTF-16-safe QA Matrix attachment-preview caps in 5ef269c, while also preserving valid empty-string artifacts that this branch would change. The canonical fix is same-or-better, so this PR is superseded and I’m closing it.

@steipete steipete closed this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants