refactor: reduce complexity of execute_safe_output in src/execute.rs#307
Conversation
Extract generic dispatch_tool<T> helper to replace 17 near-identical match arms, each of which repeated the same parse-then-execute pattern. Also collapse three trivially-equivalent informational arms (noop, missing-tool, missing-data) into one. Before: cognitive complexity 58/25 After: below threshold (not flagged by Clippy) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| "upload-attachment" => dispatch_tool::<UploadAttachmentResult>(tool_name, entry, ctx).await?, | ||
| "submit-pr-review" => dispatch_tool::<SubmitPrReviewResult>(tool_name, entry, ctx).await?, | ||
| "reply-to-pr-review-comment" => dispatch_tool::<ReplyToPrCommentResult>(tool_name, entry, ctx).await?, | ||
| "resolve-pr-thread" => dispatch_tool::<ResolvePrThreadResult>(tool_name, entry, ctx).await?, |
There was a problem hiding this comment.
@copilot Anyway we could clean this up further with a macro approach instead? Is there something clever we could do with serde to deserialize the SafeOutputs by name automatically?
There was a problem hiding this comment.
Implemented a macro-backed dispatch table in execute_safe_output to reduce the remaining repetitive tool-name/type mapping (6f8c02f). I also adjusted it to return Result<Option<_>> instead of using ? inside the macro body for clearer error flow. For serde auto-deserialization by name, we could model a tagged enum, but that would require broader per-tool type reshaping; this keeps the change minimal and localized.
No UI changes in this PR, so there isn’t a UI screenshot to share.
|
/rust-review |
|
✅ Rust PR Reviewer completed successfully! |
Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/58f1afb6-0295-4593-9ad7-fce1005c1ac7 Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com>
🔍 Rust PR ReviewSummary: Looks good — clean, correct refactor with one minor observability tradeoff worth noting. Findings
|
Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/58f1afb6-0295-4593-9ad7-fce1005c1ac7 Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot src/execute.rs:229-232 — field-level debug logs removed: The old arms logged tool-specific fields before dispatch (e.g., debug!("create-pull-request: title='{}', repo='{}', branch='{}', patch='{}'", ...), debug!("add-pr-comment: pr_id={}, content length={}", ...)). The new dispatch_tool only logs "Parsing {} payload". When Stage 3 fails or behaves unexpectedly in production, those per-field logs were the first signal for diagnosing which payload values were actually Move the logs into each executor to compensate for lost logs. |
Agent-Logs-Url: https://github.com/githubnext/ado-aw/sessions/0cb82419-b049-4b08-9430-6d959a95135e Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com>
Done in No UI changes were made, so there is no UI screenshot. |
What was complex
execute_safe_outputdispatched to 17 safe-output tools via amatchstatement where every arm repeated the identical 4-step pattern:debug!("Parsing <tool> payload")serde_json::from_value(...).map_err(...)?debug!logoutput.execute_sanitized(ctx).await?With 17 arms × multiple statements each, Clippy reported a cognitive complexity of 58/25 — more than double the threshold.
What changed
New private helper:
dispatch_tool<T>Simplified match arms
All 17 standard tool arms are now one-liners:
Merged informational arms
noop,missing-tool, andmissing-datawere three identical arms; collapsed into one:report-incompleteremains a special case (does not implementExecutor).Before / After
src/execute.rsnet changeVerification
cargo build✅cargo test✅ (all tests pass)cargo clippy --all-targets --all-features✅ (no warnings)execute_safe_outputno longer flagged byclippy::cognitive_complexityWarning
The following domain was blocked by the firewall during workflow execution:
dev.azure.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.