Skip to content

Extract shared thread-analysis vocabulary into pr_threads.py (#600 §5) - #695

Merged
loganfinney27 merged 3 commits into
mainfrom
claude/extract-pr-threads-vocab-u8hlk0
Jun 30, 2026
Merged

loganfinney27 merged 3 commits into
mainfrom
claude/extract-pr-threads-vocab-u8hlk0

Conversation

@loganfinney27

@loganfinney27 loganfinney27 commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

AGENT PR TEMPLATE

Agent: Claude
Date: 2026-06-29
Branch: claude/extract-pr-threads-vocab-u8hlk0


Changes Made

  • New .github/scripts/pr_threads.py — the pure, side-effect-free thread-analysis vocabulary both engine concerns reason over: _author_is_bot, _thread_is_bot_only, _thread_resolved_by, _thread_has_attested_look, _thread_has_committable_suggestion, _thread_resolution_disposition, _count_committable_suggestion_threads, _thread_authors, plus their constants (LOOK_ATTESTATION_RE, SUGGESTION_BLOCK_RE, ATTESTATION_DECISIONS, BARE_RESOLVABLE_DISPOSITIONS). Moved verbatim, doctrine comments intact.
  • .github/scripts/review_feedback_loop.py — deletes that block (net −140 lines) and imports the names back, so the engine's surface is unchanged. The 8 names its control flow still uses are plain imports; _author_is_bot / _thread_has_committable_suggestion (reached now only transitively, but referenced by tests) are explicit re-exports.
  • tests/test_review_feedback_loop.py — the by-path loader now puts .github/scripts on sys.path so the engine's new sibling import resolves under test (production runs the script directly, which already does).

Related Work

Blockers

  • None.

Verification

  • Engine suite: 100/100 (tests/test_review_feedback_loop.py). ruff clean; py_compile OK.
  • Behavior unchanged — pure functions moved verbatim, every test still references them via the engine's surface and passes.
  • Repo-wide there are 4 pre-existing failures in unrelated modules (branch_garden_report, issue_reconciler [needs a real gh binary — passes in CI], uv_dependency_submission, workflow_security_invariants). Verified they fail identically on clean main with this change stashed out — they are not introduced here.

Checklist:

  • Tests pass (engine suite 100/100; the 4 unrelated failures pre-exist on main, verified)
  • No secrets in diff
  • Documentation updated IF needed — module docstring carries the why
  • Reviewer assigned

Risk Level:

  • MEDIUM: pure-function move + re-export, zero behavior change, no engine control-flow touched

Labels to apply:

  • agent:claude-code

Ready for Logan to review and merge.


Generated by Claude Code

Summary by Sourcery

Extract shared review thread-analysis helpers into a new shared module and update the engine and tests to consume it without changing behavior.

Enhancements:

  • Introduce a pr_threads shared module containing pure thread-analysis predicates and constants used by the review/merge engine.
  • Refactor review_feedback_loop to import shared thread-analysis helpers from pr_threads and re-export selected functions on its public surface to preserve existing callers.

Tests:

  • Adjust the review_feedback_loop test loader to put .github/scripts on sys.path so the new sibling import of pr_threads resolves when loading the engine by file path.

Summary by CodeRabbit

  • Bug Fixes
    • Improved how review threads are analyzed and classified, making comment handling and resolution status more consistent.
    • Better support for identifying actionable suggestion comments and resolved-looking review notes.
  • Refactor
    • Consolidated shared review-thread logic into a reusable component, simplifying the review workflow implementation.
  • Tests
    • Updated test loading to match the new module structure.

First de-braiding step toward collapsing review_feedback_loop.py: the pure,
side-effect-free thread predicates that BOTH the review-state projector
(concerns A/B/C) and the looker/attestation subsystem (concern D) reason over
move into a single shared module. The call-site audit confirms the split —
_thread_is_bot_only / _thread_resolution_disposition / _count_committable_
suggestion_threads / _thread_authors / _thread_has_attested_look / _author_is_bot
/ _thread_has_committable_suggestion / _thread_resolved_by and their constants
are used across both concerns, so they're shared-lib (#600 §5 "imported by both,
duplicated by neither"), not thread-witness-only. The attestation/looker-queue
builders stay for the concern-D extraction that lands next.

The engine imports the names back, so its surface and every test reference is
unchanged; the test loader puts .github/scripts on sys.path (production runs the
script directly, which already does). No behavior change: the functions moved
verbatim, doctrine comments intact. Engine suite 100/100, ruff clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MU1zvEUacde5fmYpMvK8aK
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@sourcery-ai

sourcery-ai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Extracts shared, pure thread-analysis helpers and constants from the review engine into a new pr_threads module, then wires the engine and its tests to consume that module without changing behavior or control flow.

File-Level Changes

Change Details Files
Introduce a shared, pure thread-analysis module used by both the review engine and future looker/attestation code. .github/scripts/pr_threads.py
Refactor the review engine to depend on the new shared vocabulary while preserving its public surface.
  • Remove inline thread-analysis helpers and constants from review_feedback_loop.py
  • Import the shared functions and constants from pr_threads at the top of review_feedback_loop.py
  • Explicitly re-export _author_is_bot and _thread_has_committable_suggestion under their original names so callers/tests still see the same API
.github/scripts/review_feedback_loop.py
Adjust tests to load the engine script in a way that supports its new sibling-module import.
  • Update the test harness to add .github/scripts to sys.path before loading review_feedback_loop.py by path
  • Ensure pr_threads sibling import works under tests exactly as in production
tests/test_review_feedback_loop.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions
github-actions Bot enabled auto-merge June 29, 2026 04:02
@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@loganfinney27, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 51 minutes and 22 seconds. Learn how PR review limits work.

To continue reviewing without waiting, enable usage-based billing in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: de7271a0-e3b2-424f-a140-c5d05eb559d9

📥 Commits

Reviewing files that changed from the base of the PR and between 5411a2a and f67ea91.

📒 Files selected for processing (3)
  • .github/scripts/pr_threads.py
  • .github/scripts/review_feedback_loop.py
  • tests/test_review_feedback_loop.py
📝 Walkthrough

Walkthrough

A new .github/scripts/pr_threads.py module is introduced containing shared, pure thread-analysis helpers (regex detection, bot-only checks, look attestation, suggestion detection, disposition routing, and author collection) extracted from review_feedback_loop.py. That script now imports and re-exports these helpers from pr_threads instead of defining them locally. The test loader gains a sys.path insertion so pr_threads is importable.

Changes

Thread-analysis extraction into pr_threads

Layer / File(s) Summary
New pr_threads module
.github/scripts/pr_threads.py
Defines LOOK_ATTESTATION_RE, SUGGESTION_BLOCK_RE, all thread-analysis predicates (_thread_has_attested_look, _author_is_bot, _thread_is_bot_only, _thread_resolved_by, _thread_has_committable_suggestion, _thread_resolution_disposition), BARE_RESOLVABLE_DISPOSITIONS, _count_committable_suggestion_threads, and _thread_authors.
review_feedback_loop.py: import from pr_threads
.github/scripts/review_feedback_loop.py
Replaces local regex, helper function, and constant definitions with imports from pr_threads; re-exports selected helpers; removes ~139 lines of local implementation.
Test loader sys.path fix
tests/test_review_feedback_loop.py
Adds import sys, computes scripts_dir, inserts it into sys.path, and derives script_path from scripts_dir so pr_threads is importable during dynamic module loading.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • LAF-US/IDAHO-VAULT#518: Modifies review_feedback_loop.py around _thread_has_attested_look() and look-attestation logic that this PR extracts into pr_threads.
  • LAF-US/IDAHO-VAULT#529: Implements fenced suggestion block detection and apply-suggestion disposition routing—the same logic this PR moves into pr_threads.py.
  • LAF-US/IDAHO-VAULT#577: Adds review/suggestions-ready label based on _count_committable_suggestion_threads, which this PR relocates to pr_threads.

Poem

🐇 A tidy warren, neatly split,
No tangled roots where helpers sit—
pr_threads blooms in its own burrow,
The feedback loop runs clean and thorough.
One module's job: to know the thread,
The other leads where logic's led! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: extracting shared thread-analysis logic into pr_threads.py.
Description check ✅ Passed The description follows the template and covers changes, related work, blockers, checklist, risk level, and labels, with only reviewer assignment left incomplete.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/extract-pr-threads-vocab-u8hlk0

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • Consider switching the pr_threads imports in review_feedback_loop.py to a relative import (e.g. from . import pr_threads) so the module relationship is explicit and you don’t need tests to mutate sys.path for sibling resolution.
  • Given pr_threads is intended as a shared library, you may want to drop the leading underscores on its functions/constants that are part of the shared vocabulary or explicitly define an __all__ to clarify what is considered public vs engine-internal.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider switching the `pr_threads` imports in `review_feedback_loop.py` to a relative import (e.g. `from . import pr_threads`) so the module relationship is explicit and you don’t need tests to mutate `sys.path` for sibling resolution.
- Given `pr_threads` is intended as a shared library, you may want to drop the leading underscores on its functions/constants that are part of the shared vocabulary or explicitly define an `__all__` to clarify what is considered public vs engine-internal.

## Individual Comments

### Comment 1
<location path="tests/test_review_feedback_loop.py" line_range="17-22" />
<code_context>
 def _load_review_feedback_loop_module():
     project_root = Path(__file__).resolve().parents[1]
-    script_path = project_root / ".github" / "scripts" / "review_feedback_loop.py"
+    scripts_dir = project_root / ".github" / "scripts"
+    # The engine now imports its shared thread-analysis lib (pr_threads) as a
+    # sibling module; loading it by file path needs the scripts dir importable.
+    # Production runs the script directly, which already has this on sys.path[0].
+    if str(scripts_dir) not in sys.path:
+        sys.path.insert(0, str(scripts_dir))
+    script_path = scripts_dir / "review_feedback_loop.py"
     spec = importlib.util.spec_from_file_location("review_feedback_loop_test_module", script_path)
</code_context>
<issue_to_address>
**suggestion (testing):** Avoid permanently mutating sys.path in tests, or scope the change to reduce cross-test coupling

This helper adds `.github/scripts` to `sys.path` for the entire test run, creating global state that can unexpectedly affect other tests (e.g., ones that depend on `sys.path` ordering or on that directory not being present). Please limit the scope of this change—for example, save and restore `sys.path` around the import or use a context manager to temporarily adjust `sys.path` while loading the module—to keep the loader self-contained and avoid cross-test interference.

Suggested implementation:

```python
def _load_review_feedback_loop_module():
    project_root = Path(__file__).resolve().parents[1]
    scripts_dir = project_root / ".github" / "scripts"
    # The engine now imports its shared thread-analysis lib (pr_threads) as a
    # sibling module; loading it by file path needs the scripts dir importable.
    # Production runs the script directly, which already has this on sys.path[0].
    original_sys_path = list(sys.path)
    try:
        if str(scripts_dir) not in sys.path:
            sys.path.insert(0, str(scripts_dir))
        script_path = scripts_dir / "review_feedback_loop.py"
        spec = importlib.util.spec_from_file_location("review_feedback_loop_test_module", script_path)
        module = importlib.util.module_from_spec(spec)
        assert spec.loader is not None
    finally:
        # Restore sys.path so tests don't retain this mutation globally
        sys.path = original_sys_path

```

If there are further lines in `_load_review_feedback_loop_module` that execute the spec loader (e.g., `spec.loader.exec_module(module)` or `return module`), they should be indented to live inside the `try:` block so that all imports that rely on the temporary `sys.path` adjustment occur before it is restored.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread tests/test_review_feedback_loop.py Resolved
@github-actions github-actions Bot added the review/threads-open Current unresolved review threads still need attention before merge. label Jun 29, 2026
- review_feedback_loop: re-export _author_is_bot / _thread_has_committable_
  suggestion via `import pr_threads` + assignment instead of `import … as …`,
  so static analysis (github-code-quality) registers a concrete use rather than
  flagging the re-export as an unused import. Surface unchanged.
- test loader: scope the .github/scripts sys.path insertion to the exec and
  restore it in a finally, so the test run's global sys.path isn't left mutated
  (per Sourcery). The import binds during exec; pr_threads stays in sys.modules.

Engine suite 100/100, ruff clean. No behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MU1zvEUacde5fmYpMvK8aK
@github-actions github-actions Bot removed the review/threads-open Current unresolved review threads still need attention before merge. label Jun 29, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/scripts/review_feedback_loop.py:
- Around line 40-56: Re-export the moved regex constants from
review_feedback_loop.py so the module surface stays backward compatible. Update
the import block that already re-exports pr_threads symbols to also import
LOOK_ATTESTATION_RE and SUGGESTION_BLOCK_RE from pr_threads, alongside the
existing helpers like _author_is_bot and _thread_has_committable_suggestion.
This keeps callers and tests that still import those constants from
review_feedback_loop.py working without changing the new ownership in
pr_threads.py.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 18db90e7-cc6d-4595-b336-9c170cb22314

📥 Commits

Reviewing files that changed from the base of the PR and between 4682242 and 5411a2a.

📒 Files selected for processing (3)
  • .github/scripts/pr_threads.py
  • .github/scripts/review_feedback_loop.py
  • tests/test_review_feedback_loop.py

Comment thread .github/scripts/review_feedback_loop.py Resolved
@github-actions github-actions Bot added review/threads-open Current unresolved review threads still need attention before merge. review/suggestions-ready Has bot review threads with committable ```suggestion blocks ready to apply. labels Jun 29, 2026
github-code-quality flagged the re-export of _author_is_bot /
_thread_has_committable_suggestion every way it was spelled (unused import, then
unused global + mixed import style) — correctly: the engine reaches them only
transitively via _thread_resolution_disposition, so re-exporting them keeps
unused names on its surface. Stop pretending the engine owns them: import only
the 8 names the engine actually uses, and test the two relocated predicates
against pr_threads (their real home), via sys.modules after the engine's load.

Also adds the one missing docstring (_thread_authors) so the new shared module
is fully documented. Engine suite 100/100, ruff clean. No behavior change.

CodeRabbit's separate suggestion to re-export LOOK_ATTESTATION_RE /
SUGGESTION_BLOCK_RE is declined: a repo-wide grep finds no caller importing
those constants from review_feedback_loop, so re-exporting would only add the
unused-import warnings this commit removes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MU1zvEUacde5fmYpMvK8aK
@github-actions github-actions Bot removed review/threads-open Current unresolved review threads still need attention before merge. review/suggestions-ready Has bot review threads with committable ```suggestion blocks ready to apply. labels Jun 29, 2026
@loganfinney27
loganfinney27 added this pull request to the merge queue Jun 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Jun 29, 2026
@loganfinney27
loganfinney27 added this pull request to the merge queue Jun 30, 2026
Merged via the queue into main with commit 3c4520b Jun 30, 2026
29 checks passed
@loganfinney27
loganfinney27 deleted the claude/extract-pr-threads-vocab-u8hlk0 branch June 30, 2026 05:27
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.

2 participants