Skip to content

fix: deduplicate write paths in label_response#8345

Merged
lpcox merged 3 commits into
mainfrom
lpcox-fix-8328-dedup-write-paths
Jun 30, 2026
Merged

fix: deduplicate write paths in label_response#8345
lpcox merged 3 commits into
mainfrom
lpcox-fix-8328-dedup-write-paths

Conversation

@lpcox

@lpcox lpcox commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Fixes #8328

Summary

The label_response function 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 unsafe as u32 and as i32 casts, buffer size checks, and write_bytes_to_output calls.

The try_write_json_output helper already exists and is used by label_agent and label_resource, but label_response was never updated to use it.

Changes

Replaced both 8-line manual write blocks with calls to try_write_json_output:

  • Path-based branch (~line 975): now uses try_write_json_output(..., "label_response/path")
  • Legacy item-based branch (~line 1037): now uses 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 i32 casts in favor of the helper's safe u32::try_from conversion.

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>
Copilot AI review requested due to automatic review settings June 30, 2026 13:27
GitHub Advanced Security started work on behalf of lpcox June 30, 2026 13:27 View session
GitHub Advanced Security finished work on behalf of lpcox June 30, 2026 13:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_response output write block with a try_write_json_output call and mapped -10 (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

Comment thread guards/github-guard/rust-guard/src/lib.rs Outdated
Comment thread guards/github-guard/rust-guard/src/lib.rs Outdated
lpcox and others added 2 commits June 30, 2026 06:32
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>
GitHub Advanced Security started work on behalf of lpcox June 30, 2026 13:34 View session
GitHub Advanced Security started work on behalf of lpcox June 30, 2026 13:34 View session
GitHub Advanced Security finished work on behalf of lpcox June 30, 2026 13:34
GitHub Advanced Security finished work on behalf of lpcox June 30, 2026 13:35
@lpcox lpcox merged commit 9e1750a into main Jun 30, 2026
25 checks passed
@lpcox lpcox deleted the lpcox-fix-8328-dedup-write-paths branch June 30, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[rust-guard] Rust Guard: Deduplicate write paths in label_response and author_association lookup

2 participants