fix(guard): use UTF-8 safe string truncation in output preview logging#3690
Closed
lietblue wants to merge 1 commit intogithub:mainfrom
Closed
fix(guard): use UTF-8 safe string truncation in output preview logging#3690lietblue wants to merge 1 commit intogithub:mainfrom
lietblue wants to merge 1 commit intogithub:mainfrom
Conversation
`label_response` panics when the serialized output JSON contains multi-byte UTF-8 characters (CJK, emoji) and byte index 500 falls mid-character. Replace `&output_json[..500]` with `floor_char_boundary(500)` which finds the nearest char boundary. This crash poisons the WASM guard for the entire session — all subsequent MCP calls fail with "unavailable after a previous trap". Discovered via moeru-ai/airi PR triage workflow (run #24311673575) on a PR with Chinese text in the body.
12 tasks
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
label_responsepanics when the serialized output JSON contains multi-byte UTF-8 characters (CJK, emoji, etc.) and byte index 500 falls in the middle of a character&output_json[..500]withfloor_char_boundary(500)at both occurrences (line 808 and line 939) to find the nearest valid char boundaryRoot cause
Evidence
Discovered via
moeru-ai/airiPR triage workflow (run #24311673575). PR #1649 has a Chinese body —pull_request_readwithmethod: "get"returns the PR body in the tool result, the tool result gets cloned intoLabelResponseOutput, and the serialized JSON has CJK characters within the first 500 bytes.From
mcp-gateway.log:"generated 1 labeled items"(lib.rs around L930)output_preview=...log line is absent — confirming crash between serialization and the preview logdealloccalls (Go defer cleanup after WASM trap)"WASM guard 'github' is unavailable after a previous trap"Test plan
cargo test --lib— 279 tests passbuild.sh— WASM compiles (295 KB)label_responseshould log a truncated preview without crashing