Skip to content

[APIView Copilot] Include full comment thread in Report Issue context#15524

Merged
tjprescott merged 3 commits intomainfrom
fix/report-issue-thread-context
May 8, 2026
Merged

[APIView Copilot] Include full comment thread in Report Issue context#15524
tjprescott merged 3 commits intomainfrom
fix/report-issue-thread-context

Conversation

@helen229
Copy link
Copy Markdown
Member

@helen229 helen229 commented May 6, 2026

Summary

When a user clicks Report Issue on a comment in APIView, the backend currently sees only the anchor comment — sibling replies in the same thread are dropped, so the LLM has no view of the conversation that motivated the report.

This PR fetches the full thread and renders it for the LLM.

Changes

_apiview.pyget_comment_with_context

  • After loading the anchor comment, runs a second query against the Comments container filtered by ThreadId, ordered by CreatedOn ASC.
  • Drops IsDeleted entries; falls back to [anchor] when no siblings exist or the lookup fails.
  • Exposes the list as a new thread_comments field in the return dict (the anchor comment shape is unchanged).

_report_issue.py

  • _lookup_comment_context forwards the thread as a normalized list of {id, comment_text, comment_source, created_by, created_on} dicts.
  • _format_comment_context_for_prompt emits a chronological Thread: transcript (@author (timestamp): text) only when the thread has 2+ comments. Single-comment threads keep the existing one-line Comment: rendering.

generate_issue.prompty

  • Documents the new Thread: block in the comment_context description so the LLM knows to use the full transcript instead of only the anchor Comment: line.

Tests

  • Updated TestLookupCommentContext.test_maps_db_payload_to_comment_context to assert the new thread_comments mapping.
  • Added two transcript-rendering tests:
    • test_single_comment_thread_does_not_emit_transcript
    • test_multi_comment_thread_emits_transcript
  • All 61 tests pass.

Follow-up

Pairs with the FE fix on PR #15347 (commit c2a75678a) which makes the dialog card use the clicked comment instead of comments[0].

get_comment_with_context now also fetches sibling comments sharing the anchor's ThreadId, ordered by CreatedOn, and exposes them as 'thread_comments'. _lookup_comment_context forwards the list (id, text, source, author, created_on) to the prompt context, and _format_comment_context_for_prompt renders them as a chronological 'Thread:' transcript when there is more than one comment so the LLM sees the full conversation, not just the anchor comment. Single-comment threads keep the existing single-line 'Comment:' rendering.
Copilot AI review requested due to automatic review settings May 6, 2026 18:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 improves the APIView Copilot “Report Issue” flow by including the full comment thread (not just the anchor comment) in the context sent to the LLM and (when needed) in the deterministic fallback issue body, enabling better issue triage from the surrounding discussion.

Changes:

  • Extend APIView DB lookup to fetch all comments in the same ThreadId (chronological) and return them as thread_comments.
  • Update report-issue context mapping and prompt formatting to optionally emit a Thread: transcript when 2+ comments exist.
  • Update the prompt documentation and unit tests to reflect and verify the new thread behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
packages/python-packages/apiview-copilot/src/_apiview.py Adds thread-level Cosmos query and returns thread_comments alongside the anchor comment context.
packages/python-packages/apiview-copilot/src/_report_issue.py Normalizes thread comment payload and formats a Thread: transcript for the prompt/fallback body.
packages/python-packages/apiview-copilot/prompts/report_issue/generate_issue.prompty Documents the new Thread: block semantics for the LLM.
packages/python-packages/apiview-copilot/tests/report_issue_test.py Adds/updates tests for thread mapping and transcript rendering behavior.

Comment thread packages/python-packages/apiview-copilot/src/_report_issue.py
Comment thread packages/python-packages/apiview-copilot/src/_apiview.py Outdated
Comment thread packages/python-packages/apiview-copilot/src/_apiview.py Outdated
helen229 and others added 2 commits May 6, 2026 12:48
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1. Avoid GitHub mention spam in fallback issue body: _format_comment_context_for_prompt now accepts escape_mentions=True (used by _build_fallback_body) to wrap thread-author tokens in backticks (e.g. `@alice`) so the deterministic fallback body can never accidentally @-notify real users. The LLM prompt path still gets bare @author so the model sees authorship clearly.

2. Push the IsDeleted filter into the Cosmos thread query (AND (NOT IS_DEFINED(c.IsDeleted) OR c.IsDeleted = false)) so we no longer transfer/sort tombstoned comments client-side.
@tjprescott tjprescott merged commit 1e8447e into main May 8, 2026
8 checks passed
@tjprescott tjprescott deleted the fix/report-issue-thread-context branch May 8, 2026 18:30
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.

3 participants