Skip to content

Share the code-suggestion thread context across providers - #5

Closed
utsab345 wants to merge 12 commits into
fix/gitlab-code-suggestion-thread-contextfrom
refactor/shared-code-suggestion-thread-context
Closed

utsab345 wants to merge 12 commits into
fix/gitlab-code-suggestion-thread-contextfrom
refactor/shared-code-suggestion-thread-context

Conversation

@utsab345

Copy link
Copy Markdown
Owner

Closes The-PR-Agent#3686 (stacked on The-PR-Agent#3684).

What

GitLab (The-PR-Agent#3684) and Azure DevOps each carried their own copy of get_code_suggestion_thread_context with the same four hardcoded limits. This moves the serializing and the budgeting into GitProvider and leaves each provider supplying only a thread iterator, plus one setting: pr_code_suggestions.max_discussion_context_chars (default 24000, 0 disables).

A provider implements _iter_code_suggestion_threads(), yielding thread_id, status, file, start_line, end_line, suggestion and replies (already filtered). The shared code owns the limits (50 threads, 10 replies, 750 chars per message), the marker cleanup and the budget.

Fixes from the issue

  • The budget is now measured on the exact indented JSON that is returned. Azure DevOps measured the compact form (azuredevops_provider.py:1428) and returned the indented one, so its block could overrun 24000.
  • Suggestion text that quotes <!-- pr-agent ... --> is kept. Both providers cut at the first marker occurrence; now only trailing marker lines (the appended HTML comment or the markdown link reference) are removed.
  • Replies are capped after the provider filters system and progress notes, not before, so the last 10 replies are real ones.
  • The thread opener must be attributable to PR-Agent (is_comment_authored_by_pr_agent()), so a human thread is no longer read as the agent's own. Threads are left out when authorship cannot be verified, matching how /review handles unverifiable comment authorship.

Behavior notes

  • Azure DevOps needs azure_devops_server.agent_identity configured for the context to include threads, since that is what makes authorship verifiable. Documented in docs/docs/installation/azure.md.
  • GitLab resolves the authenticated user, which it already does elsewhere for author-based filtering.

Tests

  • New tests/unittest/test_code_suggestion_thread_context.py covers the shared block: indented-budget measurement, 0 disabling without reading threads, a non-numeric budget falling back to the default, thread/reply caps, trailing-only marker stripping, and partial thread payloads.
  • Azure DevOps and GitLab tests cover the author check, the fail-closed path, quoted marker text, and replies after filtering.

@utsab345
utsab345 force-pushed the refactor/shared-code-suggestion-thread-context branch from 3e6624b to e02da50 Compare September 25, 2026 16:37
@utsab345 utsab345 closed this Sep 25, 2026
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