Fix Swarm inline comment posting: invalid field defaults and dropped content#38
Open
dirtypearltim wants to merge 1 commit into
Open
Fix Swarm inline comment posting: invalid field defaults and dropped content#38dirtypearltim wants to merge 1 commit into
dirtypearltim wants to merge 1 commit into
Conversation
Two issues prevented inline review comments from working: 1. CommentContext.leftLine, rightLine, and content declared default="null" (the string) on Optional[int] / Optional[List[str]] fields. Pydantic rejects the string default when the field is omitted, so any comment without explicit line anchors failed validation. Changed to default=None. 2. ReviewServices.add_comment replaced context.content with an empty list before posting to the Swarm API. Swarm uses the content lines to anchor inline comments to the diff, so comments lost their anchoring. Pass the caller-provided content through unchanged.
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.
Problem
Inline review comments posted through
modify_reviews/ the review comment tools don't anchor to diff lines, and comments that omit line anchors can fail validation.Two causes in the review comment path:
Invalid pydantic defaults.
CommentContext.leftLine,rightLine, andcontentdeclaredefault="null"— the string"null"— onOptional[int]/Optional[List[str]]fields (p4mcp/models/review_models.py).Comment content discarded.
ReviewServices.add_commentreplaces the caller-providedcontext.contentwith an empty list before posting to the Swarm API (p4mcp/services/review_services.py). Swarm uses these content lines to anchor inline comments to the correct diff position, so anchoring breaks even when the caller supplies everything correctly.Fix
default=Noneon the three optional fields.context.contentthrough to the API unchanged (guarded byis not None).Four lines total. We've been running this patch against a production Helix Core + Swarm setup since March with inline comment posting working correctly.
Notes
The removed comment said content was skipped because "AI is adding random content". The field's description already instructs the model to supply the codeline plus four preceding lines; in our usage models follow it reliably, and dropping the field entirely breaks the documented Swarm API contract for inline comments. If bad content is still a concern, validating shape (e.g. list length) seems preferable to discarding it.