Skip to content

feat: Improve thread resolution with referenced commit context#230

Open
finxo wants to merge 2 commits into
masterfrom
feat/improve_thread_resolution_with_sha
Open

feat: Improve thread resolution with referenced commit context#230
finxo wants to merge 2 commits into
masterfrom
feat/improve_thread_resolution_with_sha

Conversation

@finxo

@finxo finxo commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Pull Request

📝 Summary

This PR improves the pull request thread resolution workflow in the GitHub plugin. It filters thread review candidates to only include those started by the current user (where the PR author has replied), and adds support for extracting and embedding context from referenced commit SHAs mentioned in the discussion threads to improve AI-driven resolution analysis.

🔧 Changes Made

  • Thread Filtering: Filtered thread review candidates to only include the current user's threads where the PR author provided the last reply.
  • Commit Context Extraction: Added get_commit_review_context to the GitHub client API to retrieve compact file changes and patch excerpts for referenced SHAs.
  • Prompt Enrichment: Updated the thread resolution prompt builder to include retrieved commit messages, changed files, and patch excerpts from referenced commits.
  • Documentation: Updated generated step references and workflow docs to reflect new input fields (review_threads, review_pr, review_current_user) and documented the new client API.

🧪 Testing

  • Unit tests added/updated (poetry run pytest)
  • All tests passing (make test)
  • Manual testing with titan-dev

Unit tests were added to cover:

  • Filtering thread review candidates to ensure only current user threads are included.
  • Excluding threads that do not have the PR author's last reply.
  • Verifying that referenced commit context is properly formatted and included in the AI prompt.
  • Mocking GitHub API network calls for successfully fetching and parsing referenced commit data, as well as handling JSON parse errors.

📊 Logs

  • No new log events

✅ Checklist

  • Self-review done
  • Follows the project's logging rules (no secrets, no content in logs)
  • New and existing tests pass
  • Documentation updated if needed
  • Plugin documentation updated when plugin functions or parameters changed (Plugins > Git Plugin, GitHub Plugin, Jira Plugin)

@finxo finxo added the improvement Enhancement to existing functionality label Jun 9, 2026
@finxo finxo self-assigned this Jun 9, 2026
return Skip("No thread_review_candidates in context")

contexts = build_thread_review_contexts_operation(candidates, threads, diff)
commit_contexts_by_thread = _load_referenced_commit_contexts(ctx, threads)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_load_referenced_commit_contexts is passed the full threads list (all PR threads), but the result is only applied to contexts, which was built from candidates. Any SHA reference inside a resolved or foreign-reviewer thread will trigger a real API call whose result is immediately discarded.

Filter to only the threads that correspond to candidates before fetching:

candidate_ids = {c.thread_id for c in candidates}
candidate_threads = [t for t in threads if t.thread_id in candidate_ids]
commit_contexts_by_thread = _load_referenced_commit_contexts(ctx, candidate_threads)

return Skip("No thread_review_candidates in context")

contexts = build_thread_review_contexts_operation(candidates, threads, diff)
commit_contexts_by_thread = _load_referenced_commit_contexts(ctx, threads)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_load_referenced_commit_contexts is called with all review_threads (every thread on the PR), but only candidate threads are ever enriched. Any non-candidate thread (resolved, from a different reviewer, etc.) whose replies mention a hex SHA will trigger a get_commit_review_context API call whose result is immediately discarded.

The call should filter to candidate threads only:

candidate_thread_ids = {c.thread_id for c in candidates}
candidate_threads = [t for t in threads if t.thread_id in candidate_thread_ids]
commit_contexts_by_thread = _load_referenced_commit_contexts(ctx, candidate_threads)

result = pr_service.get_commit_review_context("343e2e9")

assert isinstance(result, ClientError)
assert result.error_code == "PARSE_ERROR"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new get_commit_review_context tests cover success and PARSE_ERROR but skip the API_ERROR branch. The implementation explicitly catches GitHubAPIError and returns ClientError(error_code="API_ERROR"), and test_merge_pr_failure shows this pattern is expected to be tested. Please add:

def test_get_commit_review_context_returns_api_error_on_network_failure(pr_service, mock_gh_network):
    mock_gh_network.run_command.side_effect = GitHubAPIError("Not Found")
    result = pr_service.get_commit_review_context("343e2e9")
    assert isinstance(result, ClientError)
    assert result.error_code == "API_ERROR"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Enhancement to existing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant