refactor: eliminate duplicate code in DIFC labels and RPC logger#2006
Merged
refactor: eliminate duplicate code in DIFC labels and RPC logger#2006
Conversation
Copilot created this pull request from a session on behalf of
lpcox
March 16, 2026 04:13
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors two previously duplicated patterns to reduce boilerplate and centralize logic in DIFC label flow checks and RPC message logging, aligning with the duplicate-code analysis issues (#2002, #2003).
Changes:
- Added
getLabel() *Labelhelpers onSecrecyLabelandIntegrityLabelto remove repeated nil-unwrapping blocks and simplifyClone(). - Extracted
newRPCMessageInfohelper to avoid duplicatedRPCMessageInfoconstruction inlogRPCMessageToAll.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/difc/labels.go | Adds getLabel() helpers and refactors flow-check and clone methods to use them. |
| internal/logger/rpc_logger.go | Adds newRPCMessageInfo constructor and uses it to build text/markdown log payloads without duplication. |
Comments suppressed due to low confidence (1)
internal/difc/labels.go:310
- Same as the SecrecyLabel version: this comment implies nil is only possible when the receiver is nil, but l.Label may also be nil. Please adjust the comment to mention both cases to keep docs accurate.
// getLabel returns the underlying Label, or nil if the receiver is nil.
func (l *IntegrityLabel) getLabel() *Label {
if l == nil {
return nil
}
return l.Label
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Mar 16, 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.
Closes #2001, closes #2002, closes #2003
Summary
Addresses the duplicate-code analysis report by refactoring two patterns identified in issues #2002 and #2003.
internal/difc/labels.go (issue #2002)
Added a
getLabel() *Labelhelper method to bothSecrecyLabelandIntegrityLabel. The helper safely handles nil receivers and returnsnilin that case. This eliminates four identical 6-line nil-guard extraction blocks that preceded every call tocheckFlowHelper, and simplifies bothClone()methods.CanFlowToandCheckFlowon both types now calll.getLabel()/target.getLabel()directly — the nil-unwrapping blocks are goneClone()on both types usesl.getLabel() == nilto guard the early-return path (covers both nil-receiver and nil-Label cases)internal/logger/rpc_logger.go (issue #2003)
Extracted an unexported
newRPCMessageInfoconstructor that builds anRPCMessageInfoand sets theErrorfield when the supplied error is non-nil.logRPCMessageToAllnow calls this helper twice (once withMaxPayloadPreviewLengthText, once withMaxPayloadPreviewLengthMarkdown) instead of repeating the struct literal +if err != nilblock.Impact
make agent-finished✓)RPCMessageInfofields or nil-guard logic now have a single place to update