Skip to content

Fix Swarm inline comment posting: invalid field defaults and dropped content#38

Open
dirtypearltim wants to merge 1 commit into
perforce:mainfrom
dirtypearltim:fix/swarm-inline-comment-posting
Open

Fix Swarm inline comment posting: invalid field defaults and dropped content#38
dirtypearltim wants to merge 1 commit into
perforce:mainfrom
dirtypearltim:fix/swarm-inline-comment-posting

Conversation

@dirtypearltim

Copy link
Copy Markdown

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:

  1. Invalid pydantic defaults. CommentContext.leftLine, rightLine, and content declare default="null" — the string "null" — on Optional[int] / Optional[List[str]] fields (p4mcp/models/review_models.py).

  2. Comment content discarded. ReviewServices.add_comment replaces the caller-provided context.content with 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

  • Use default=None on the three optional fields.
  • Pass context.content through to the API unchanged (guarded by is 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.

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.
@dirtypearltim dirtypearltim marked this pull request as ready for review July 5, 2026 21:00
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.

1 participant