fix: deduplicate write paths in label_response#8345
Merged
Conversation
Replace duplicated manual write blocks (unsafe as u32/i32 casts, buffer size checks, write_bytes_to_output calls) in label_response's two output branches with calls to the existing try_write_json_output helper, matching the pattern already used by label_agent and label_resource. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Rust guard’s exported label_response WASM function to reuse the existing try_write_json_output helper for writing serialized JSON to the host output buffer, eliminating duplicated output-write logic and unsafe integer casts.
Changes:
- Replaced the path-based
label_responseoutput write block with atry_write_json_outputcall and mapped-1→0(skip labeling). - Replaced the legacy item-based fallback write block with the same helper-based write path and error mapping.
Show a summary per file
| File | Description |
|---|---|
| guards/github-guard/rust-guard/src/lib.rs | Deduplicates label_response output-buffer write logic by delegating to try_write_json_output in both path-based and legacy branches. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Low
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Jun 30, 2026
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.
Fixes #8328
Summary
The
label_responsefunction in the Rust guard had two separate output-write branches (path-based labeling and legacy item-based fallback) that both manually reimplemented the same write pattern with unsafeas u32andas i32casts, buffer size checks, andwrite_bytes_to_outputcalls.The
try_write_json_outputhelper already exists and is used bylabel_agentandlabel_resource, butlabel_responsewas never updated to use it.Changes
Replaced both 8-line manual write blocks with calls to
try_write_json_output:try_write_json_output(..., "label_response/path")try_write_json_output(..., "label_response/legacy")This removes 36 lines of duplicated code (replaced with 4 lines) and eliminates the unsafe
as u32/as i32casts in favor of the helper's safeu32::try_fromconversion.