rust-guard: dedupe unsafe output write-back and unify search scope labeling arms#7629
Merged
Merged
Conversation
Copilot
AI
changed the title
[WIP] Deduplicate unsafe write-back pattern in Rust Guard
rust-guard: dedupe unsafe output write-back and unify search scope labeling arms
Jun 16, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the Rust GitHub guard to reduce duplicated unsafe pointer write-back code in its WASM FFI entrypoints and to consolidate duplicated labeling logic for repo-scoped search tools, while preserving existing behavior.
Changes:
- Introduced a single
unsafe fn write_bytes_to_output(output_ptr, bytes)helper and replaced repeated raw-pointer slice copy blocks inlabel_agent,label_resource, and bothlabel_responsereturn paths. - Consolidated
search_codeandsearch_commitsinto a single match arm in tool labeling, including unified scoped description formatting and removal of redundantbaseline_scopereassignment.
Show a summary per file
| File | Description |
|---|---|
| guards/github-guard/rust-guard/src/lib.rs | Deduplicates unsafe output-buffer write-back logic into a single helper used by multiple FFI entrypoints. |
| guards/github-guard/rust-guard/src/labels/tool_rules.rs | Unifies search tool labeling logic for search_code and search_commits into one consistent match arm. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
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.
This PR removes duplicated unsafe buffer write-back code in Rust guard FFI entrypoints and consolidates duplicated
search_code/search_commitslabeling logic. The result keeps behavior the same while reducing unsafe surface area and eliminating redundant branching.Unsafe output write-back deduplication (
src/lib.rs)unsafe fn write_bytes_to_output(output_ptr: u32, bytes: &[u8])label_agentlabel_resourcelabel_response(path-based return)label_response(legacy return)Search tool arm consolidation (
src/labels/tool_rules.rs)search_codeandsearch_commitsinto a single match arm:"search_code" | "search_commits" => { ... }format!("{}:{}", tool_name, s_repo_id).baseline_scopein the priorsearch_commitsbranch.