Skip to content

Include issue comments in issue-mode context#69

Merged
wwind123 merged 2 commits into
mainfrom
fix-issue-68-comments-context
May 17, 2026
Merged

Include issue comments in issue-mode context#69
wwind123 merged 2 commits into
mainfrom
fix-issue-68-comments-context

Conversation

@wwind123
Copy link
Copy Markdown
Owner

Summary

  • fetch issue title, body, and comments for issue-mode runs
  • include bounded issue context in coder prompts and issue-origin review prompts
  • document issue comment handling and add regression coverage

Fixes #68

Tests

  • /tmp/coding-review-agent-loop/scratch/issue68-venv/bin/python -m pytest -q

@wwind123
Copy link
Copy Markdown
Owner Author

Implemented and opened PR #69: #69

Changes include issue comment fetching, bounded issue context in coder/reviewer prompts, docs updates, and regression coverage.

Tests passed:
/tmp/coding-review-agent-loop/scratch/issue68-venv/bin/python -m pytest -q

-- OpenAI Codex

@wwind123
Copy link
Copy Markdown
Owner Author

Review: Include issue comments in issue-mode context (PR #69)

This PR correctly implements issue comment fetching and inclusion in issue-mode prompts. The core design is solid: frozen dataclasses, ISO 8601 sort ordering, bounded truncation with a clear fallback message, and good test coverage. The changes flow cleanly from get_issue_context through the orchestrator into both the coder prompt and the reviewer prompt.

Specific observations

github.pyget_issue_context

The --comments flag is included in the gh issue view call, JSON fields are correct (number,title,body,url,comments), and the createdAt/created_at dual-key fallback is a thoughtful hedge. Sorting by ISO 8601 string is correct.

prompts.pyformat_issue_context truncation logic

The greedy reverse-iteration strategy (newest-first) works correctly for the typical case. There is one edge case worth noting: if the single newest comment is too large to fit on its own (exceeding the remaining budget), the algorithm does not break — it falls through and silently begins evaluating older comments in isolation. This can produce a selection that omits the newest comment while retaining older ones, inverting the stated preference. In practice this requires an absurdly large single comment (> ~16 000 chars given the defaults), and the output is still safe and bounded, so this is not blocking.

Orchestrator — issue_context threading

issue_context is correctly fetched before the coder turn and passed through run_pr_loop into build_review_prompt. Because coder_session_id threads the coder's conversation across rounds, the coder retains issue context from its initial turn in any follow-up fix rounds, so the gap described below is mitigated in practice.

Tests

The new test verifies oldest-to-newest comment ordering, presence of the header block in both coder and reviewer prompts, title/body/issue number, and the "later comments may supersede" notice. FakeRunner correctly dispatches gh issue view before the existing gh api .../issues/... handler. Coverage is sufficient for the feature.

Future follow-ups

  1. Coder follow-up prompts lack re-injected issue context. build_followup_prompt and build_same_pr_followup_prompt in orchestrator.py do not receive or include issue_context. Agents with active sessions will retain the context from round 1, but stateless or resumed sessions will lose it. Adding an issue_context parameter to those builders (and threading it through run_pr_loop) would make the design complete and consistent.

  2. Truncation edge case for oversized newest comment. When the newest comment alone exceeds the character budget, the greedy loop should break early and fall directly to the "all omitted" path. Instead it iterates through all remaining comments, potentially selecting older ones over the newest. A guard like if not kept_comments and len(issue_header + notice + comment_text) > max_chars: break before the elif not kept_comments branch would fix this.

-- Anthropic Claude

@wwind123
Copy link
Copy Markdown
Owner Author

Review: Include issue comments in issue-mode context (PR #69)

The PR successfully implements fetching and including GitHub issue comments in the coder and reviewer prompts for issue-mode runs. This significantly improves the context available to agents, allowing them to benefit from discussions that may refine the original issue description.

Analysis

  • GitHub Integration: The use of gh issue view with --comments and --json is efficient and safe.
  • Context Management: Sorting comments by creation time (ISO 8601) ensuring chronological discussion flow.
  • Prompt Design: Truncation logic is robust for most cases, ensuring prompts stay within LLM token limits while prioritizing the newest discussion.
  • Testing: New test coverage in tests/test_agent_loop.py correctly verifies comment ordering and prompt inclusion. All tests passed in my local environment.

Same-PR follow-ups

  1. Truncation logic polish: In src/coding_review_agent_loop/prompts.py, the greedy loop in format_issue_context currently skips a comment if it's too large to fit the remaining budget and continues to evaluate older ones. If the newest comment is the one that's too large, it might be better to either truncate it or stop early to avoid confusing the "newest comments kept preferentially" priority.
  2. Coder follow-up context: Re-inject issue_context into build_followup_prompt and build_same_pr_followup_prompt in orchestrator.py. While stateful agents will retain this in their session history, re-injecting it ensures consistency with the reviewer's prompt and supports stateless or resumed sessions.

Future follow-ups

  • PR-mode Issue Context: Consider extending PullRequestMetadata to include associated issue numbers (if any), allowing agent-loop pr to also benefit from issue context.

-- Google Gemini

@wwind123
Copy link
Copy Markdown
Owner Author

Implemented and pushed commit 1a76e9c to origin/fix-issue-68-comments-context.

Changed:

  • Truncates an oversized newest issue comment instead of skipping it and considering older comments.
  • Re-injects issue_context into blocking and same-PR coder follow-up prompts.
  • Added regression coverage for both prompt paths and truncation behavior.

Verified:

  • /tmp/coding-review-agent-loop/scratch/pr69-venv/bin/python -m pytest tests/test_agent_loop.py -> 132 passed

-- OpenAI Codex

@wwind123
Copy link
Copy Markdown
Owner Author

Review: Include issue comments in issue-mode context (PR #69, round 2)

Both round 1 follow-ups have been addressed correctly.

Truncation edge case (oversized newest comment)

The new elif not kept_comments: branch breaks the earlier "fall through and evaluate older comments" problem. When the newest comment doesn't fit alone, the code now:

  1. Computes remaining_chars = max_chars - len(prefix) with the omission notice already baked in
  2. Truncates the newest comment to that budget via _truncate_issue_text
  3. Returns immediately, never evaluating older comments

The math is sound: _truncate_issue_text produces output of at most remaining_chars characters, so the if len(prefix) + len(truncated_comment) <= max_chars: guard is always satisfied when remaining_chars > 0 — it's a harmless defensive check. The final omitted_count = len(comments); break correctly handles the degenerate case where the prefix itself exceeds max_chars.

Issue context in follow-up prompts

issue_context is now threaded into build_followup_prompt and build_same_pr_followup_prompt in both prompts.py (parameter + _issue_context_block insertion) and orchestrator.py (keyword argument at both call sites). The propagation is symmetric with how it was done for build_issue_prompt and build_review_prompt.

New tests

Three targeted additions:

  • test_format_issue_context_truncates_oversized_newest_comment: verifies the oldest comment body is absent and the newest comment is truncated-but-present within max_chars=700
  • test_blocking_followup_prompt_reinjects_issue_context: end-to-end check that the coder's blocking-followup prompt contains the issue context
  • Extended test_pr_loop_fix_and_summarize_sends_same_pr_followups_to_coder_then_rereview: same-PR followup path also carries issue context

All three directly target the behaviors fixed in this round. Coverage is complete for the touched code paths.

No blocking issues.

-- Anthropic Claude

@wwind123
Copy link
Copy Markdown
Owner Author

Review: Include issue comments in issue-mode context (PR #69, round 2)

This PR successfully implements fetching and including GitHub issue comments in the coder and reviewer prompts for issue-mode runs. The implementation is robust, well-tested, and correctly handles context window constraints.

Analysis

  • Context Completeness: By including comments ordered oldest-to-newest, the agents now have access to the full discussion that often refines or clarifies the original issue body.
  • Robust Truncation: The updated truncation logic in prompts.py correctly prioritizes newer comments while ensuring the prompt remains within safe token limits. The edge case where a single newest comment is too large is now handled by truncating that comment rather than omitting it.
  • Consistency: issue_context is now consistently re-injected into follow-up prompts (build_followup_prompt and build_same_pr_followup_prompt), ensuring that even stateless or resumed sessions retain the necessary context.
  • Testing: The new tests in tests/test_agent_loop.py provide good coverage for the new data structures, the truncation logic, and the end-to-end threading of context through the orchestrator.

Future follow-ups

  • PR-mode Issue Context: Consider extending agent-loop pr to also benefit from issue context when a PR is associated with a GitHub issue.

No blocking issues found.

-- Google Gemini

@wwind123
Copy link
Copy Markdown
Owner Author

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.

Include issue comments in issue-mode agent context

1 participant