Skip to content

Load One Copy of the Gate When pr_review.py Dispatches cleanup - #3481

Merged
ptr727 merged 1 commit into
developfrom
fix/cleanup-one-gate-copy
Oct 25, 2026
Merged

ptr727 merged 1 commit into
developfrom
fix/cleanup-one-gate-copy

Conversation

@ptr727

@ptr727 ptr727 commented Oct 25, 2026

Copy link
Copy Markdown
Owner

Summary

Answers #3461. Run as a script, the gate is __main__, so pr_review.py cleanup imported pr_cleanup, whose import pr_review as core loaded a second copy of the gate with its own memoized readers and constants.

  • The cleanup dispatch in main now runs sys.modules.setdefault("pr_review", sys.modules[__name__]) before import pr_cleanup, so that import resolves to the running module. When the gate is imported as pr_review (the tests), setdefault changes nothing.
  • This takes neither route the issue suggested. A separate entry point would break the pr_review.py cleanup command that the host-safety allow rule and the drive-pr and merge-and-release skills name. Moving the six helpers pr_cleanup takes into a new module would also move every test patch point, while adding no safety today: pr_cleanup is the only module importing pr_review.
  • Test: TestCleanupLoadsOneGate runs the real script as python -X importtime scripts/pr_review.py cleanup --help. It asserts pr_cleanup is imported and pr_review is not. It fails against the unfixed source. In script mode a second copy can only come from a fresh import under that name, so the import log answers the issue's sys.modules condition.

Verification

  • Full suite: uv run --no-project --with-requirements tests/requirements.txt python -m unittest discover -s tests, 2953 tests run, OK (7 skipped).
  • Local strict review: one pass, no findings. It checked every launch mode (python3, uv run --script, python -m, import, runpy), every sibling's local imports for the same cycle, and the test's parsing.

🤖 Generated with Claude Code

Run as a script the gate is __main__, so pr_cleanup's import of
pr_review loaded a second copy with its own module state. The dispatch
now registers the running module under that name first. A test runs
the script under -X importtime and finds no second import.

Closes #3461

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings October 25, 2026 20:00
@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@ptr727

ptr727 commented Oct 25, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 1747bd78866c44c7bf0cdbd3951ea557164dcbfe, the content this pull request carries at that commit against develop, and it recorded 0 findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved review issues remain, and the changes are covered by a focused regression test.

No open issues 🎉

What changed in this PR

This pull request ensures pr_review.py cleanup reuses the running gate module instead of loading a second copy, preserving shared state and constants.

Changes:

  • Registers the executing module under pr_review before importing pr_cleanup.
  • Adds a subprocess regression test verifying that cleanup loads without a duplicate pr_review module.
File Description
tests/​test_pr_cleanup.py Verifies script-mode cleanup imports pr_cleanup without loading a duplicate gate module.
scripts/​pr_review.py Aliases the active script module before dispatching cleanup.

Review effort: Lite

@codecov

codecov Bot commented Oct 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@c0ff838). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #3481   +/-   ##
==========================================
  Coverage           ?   81.00%           
==========================================
  Files              ?       25           
  Lines              ?     8903           
  Branches           ?        0           
==========================================
  Hits               ?     7212           
  Misses             ?     1691           
  Partials           ?        0           
Flag Coverage Δ
python-3.13 81.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ptr727
ptr727 merged commit 0da95bc into develop Oct 25, 2026
14 checks passed
@ptr727
ptr727 deleted the fix/cleanup-one-gate-copy branch October 25, 2026 20:11
ptr727 added a commit that referenced this pull request Oct 25, 2026
## Summary

Promotes the pull requests merged into develop since release 2.0.1181.

- [#3479](#3479):
`status=COVERAGE_IS_PARTIAL` no longer says the head's own review read
fewer files on the carry paths. It leads with the carried reason there
and names the remedy that clears it.
- [#3480](#3480):
`cleanup` re-reads a ref still at the deleted tip for a few seconds
before it reports `DELETE_NOT_CONFIRMED`, since the ref read can lag a
delete that landed.
- [#3481](#3481):
`pr_review.py cleanup` loads one copy of the gate rather than a second
one under the name `pr_review`.

Closes #3424
Closes #3436
Closes #3461

## Constituent coverage

Each change this promotion carries had coverage on its own pull request
into develop, at its merged head:

| Pull request | Merged head | Coverage |
| --- | --- | --- |
| [#3479](#3479) |
`81ca8d88` | attested local pass at the merged head, base `develop`, and
a Copilot table on the merged head naming exactly its 3 changed files,
no open findings |
| [#3480](#3480) |
`2c71411c` | attested local pass at the merged head, base `develop`, and
a Copilot table on the merged head naming exactly its 3 changed files,
no open findings |
| [#3481](#3481) |
`1747bd78` | attested local pass at the merged head, base `develop`, and
a Copilot table on the merged head naming exactly its 2 changed files,
no open findings |

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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