Skip to content

fix(repo_tests): reach base trees are shared per commit and cleaned on SIGTERM (#20875) - #21073

Closed
mrveiss wants to merge 3 commits into
mainfrom
issue-20875-reach-base-leak
Closed

mrveiss wants to merge 3 commits into
mainfrom
issue-20875-reach-base-leak

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 7, 2026

Copy link
Copy Markdown
Owner

Thinking Path

The reach base tree was a registered detached worktree removed only by atexit, so a killed run held a worktree-cap slot. The tree is now exported per commit into a shared cache and is never registered. A layout version marks the tree, so a tree built by an older layout is rebuilt rather than reused. SIGTERM removes only this process's partial builds.

What Changed

  • repo_tests/_reach_base.py: shared per-commit tree (no git worktree add), layout version, SIGTERM cleanup of partial builds.
  • repo_tests/reach_base_floor_19676_test.py: adapted to the new tree.
  • repo_tests/reach_base_shared_tree_20875_test.py: new tests (concurrent workers, not a registered worktree, reuse, stale layout rebuilt, SIGTERM leaves no partial dir).

Verification

Merged current main (clean, no conflicts). repo_tests/reach_*_test.py run with -n 2, plus black, isort and flake8 on the touched files; results are in the PR checks. The reach floors were not repinned and _reach_roots_record.py was not regenerated.

Risks

Reach guards now read a cached tree. Mitigated by the layout version, which forces a rebuild on a layout change. SIGINT handling and a SIGKILL test (ACs 1 and 3) are not covered here.

Model Used

Claude Sonnet 5.5 (claude-sonnet-5-5)

Issue Link

Refs #20875

Milestone: M1 - Seamless install and consistent docs. Phase label: phase:M1.7.
Refs, not Closes: the SIGINT handler and the SIGKILL leftover and sweep tests (ACs 1 and 3, and AC 4 by test) are not delivered.

Changelog fragment

  • N/A (internal test-infrastructure change)

Checklist

  • Code follows AutoBot patterns from CLAUDE.md
  • Tests added or updated
  • Documentation updated if behavior changed (N/A)
  • PR targets main (not release)
  • No secrets or credentials in the diff

Single-issue rationale: this fixes one shared test-infrastructure file (repo_tests/_reach_base.py) for one defect; nothing else shares it.

@mrveiss mrveiss added the phase:M1.7 Docker docs and the docs close-out label Nov 7, 2026
@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 18 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 250ddc4 and 709f8ef.

Files selected for processing: 3

  • repo_tests/_reach_base.py
  • repo_tests/reach_base_floor_19676_test.py
  • repo_tests/reach_base_shared_tree_20875_test.py
  • 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

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Notice: 29 open PRs — past the runaway threshold (25)

This is not a request to defer this PR. There is no cap on open PRs (#19397) -- nothing blocks opening or pushing a PR.

This notice only means the count is high enough to be worth a glance for a runaway — something opening PRs in a loop, or a merge pipeline that has stalled so nothing is draining.

Currently open:

If the queue is draining normally, ignore this. Otherwise:

  1. Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
  2. Approved PRs land through the merge train the coordinator sequences (merge commits, never squash) -- check the open chore(merge-train) PR is moving, not each PR on its own
  3. Look for a loop opening near-identical PRs

Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.

@mrveiss

mrveiss commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Code review (code-reviewer pass) at e09e45e

Verdict: APPROVE. 3 files changed, 78 behind main (needs a sync before CI). First review of this PR.

Slice completeness: internally complete. remove_base_tree and _sweep_stale_trees are removed with no remaining caller anywhere in the tree; nothing else reads the old .git file layout; the old atexit path is gone, not left beside the new one. The base tree is no longer a registered worktree, so a killed run cannot hold a cap slot (the issue's second criterion, answered by the first option it offered).

# Severity Where Finding Fix
1 Low Remaining criteria of #20875 No test for SIGKILL leftovers being pruned on the next start (_prune after the TTL) and none for SIGINT. SIGINT is covered by the except BaseException path in _build, but untested. The PR uses Refs, so the issue stays open. Add both tests in the follow-up slice, then close.
2 Low base_tree() signal.signal(SIGTERM, _PREVIOUS_HANDLER.pop(...)) fails with a TypeError if the previous handler was installed from C and returned None. Rare. Restore signal.SIG_DFL when the saved handler is None.
3 Low _prune shutil.rmtree without ignore_errors runs on trees of other commits; a failure there aborts an unrelated guard run. Use ignore_errors=True and keep the TTL as the retry.
4 Info _extract filter="data" makes a symlink pointing outside the tree raise; none exist in the repo today. None.

Checked and fine: one tree per commit under an owner-checked, mode-0700 cache with an env-backed location and TTL; built once under an exclusive file lock into a temp directory and renamed into place; layout version in the directory name with a legacy-layout rebuild test; the concurrent test uses real spawned processes and the SIGTERM test waits on a ready file with a deadline (no fixed sleeps); _reach_base.py is 340 lines; every function is under 30 lines; floors were not repinned.

Threads: none unresolved.

@mrveiss

mrveiss commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Code review (code-reviewer pass) follow-up at 0e05c4b

Item Status Where
(a) restoring a C-installed SIGTERM handler raised TypeError (signal.signal reports it as None) Fixed: the restore now passes signal.SIG_DFL when the saved handler is None. repo_tests/_reach_base.py::_restore_sigterm, called from base_tree's finally
(a) test Added: makes signal.signal report None for the handler it replaced, runs base_tree(), and asserts SIGTERM ends up at SIG_DFL. repo_tests/reach_base_shared_tree_20875_test.py::test_a_sigterm_handler_installed_from_c_is_restored_as_the_default
(b) one failing shutil.rmtree in _prune stopped an unrelated guard run Fixed: OSError is caught per tree and logged as a warning with the path and the exception (autobot_shared.logging_manager.get_logger). The loop goes on to the next tree, and nothing is swallowed silently. repo_tests/_reach_base.py::_prune
(b) test Added: the first rmtree fails with PermissionError. The test asserts the failed tree is still there, the second stale tree was pruned, the kept tree is untouched, and the warning names the path and the error. repo_tests/reach_base_shared_tree_20875_test.py::test_one_unremovable_stale_tree_is_logged_and_the_prune_goes_on

Verified: reach_base_shared_tree_20875_test.py and reach_base_floor_19676_test.py passed locally (17 passed), run from an archived scratch copy. The branch is synced with main (125 commits merged, no conflicts). Pre-push fast guards passed (17 files), and no reach floor is stale for this branch.

@mrveiss

mrveiss commented Nov 7, 2026

Copy link
Copy Markdown
Owner Author

Code review (code-reviewer pass) at 0e05c4b

Verdict: APPROVE. 3 files changed, 0 behind main. Reviewed the author commit e4b02e8 since e09e45e. No unresolved threads.

# Severity Where Finding Status
1 LOW (prior) repo_tests/_reach_base.py _restore_sigterm previous = _PREVIOUS_HANDLER.pop(SIGTERM), then signal.signal(SIGTERM, SIG_DFL if previous is None else previous). A C-installed handler (reported as None) is restored as the default instead of raising TypeError. Called from the finally in base_tree. Fixed. Test test_a_sigterm_handler_installed_from_c_is_restored_as_the_default makes signal.signal report None, runs base_tree() and asserts getsignal(SIGTERM) == SIG_DFL; it restores the real handler in finally.
2 LOW (prior) repo_tests/_reach_base.py _prune shutil.rmtree is wrapped in try/except OSError, logged with logger.warning (path and error), and the loop continues. Fixed. Test test_one_unremovable_stale_tree_is_logged_and_the_prune_goes_on has the first rmtree raise PermissionError, then asserts the failed tree still exists, the second was pruned, keep is untouched, and the path and message are in the log.
3 nit _restore_sigterm A bare except is not needed; pop cannot miss because can_trap guards the call. No action.

Both delta items are implemented and each has a test that fails without it.

This was referenced Nov 7, 2026
@mrveiss

mrveiss commented Nov 8, 2026

Copy link
Copy Markdown
Owner Author

Landed via merge train #21184, merge commit 209d547 (frozen head a0a8558 is an ancestor of it).

@mrveiss mrveiss closed this Nov 8, 2026
timothybrush pushed a commit to timothybrush/AutoBot-AI that referenced this pull request Nov 9, 2026
@mrveiss mrveiss reopened this Nov 18, 2026
@mrveiss

mrveiss commented Nov 18, 2026

Copy link
Copy Markdown
Owner Author

Branch audit (zero-change deletion). This PR shows 0 changed files against main (head c0143a13de): every change it carried is already in main. Closing and deleting the branch through this PR; it can be restored with the Restore branch button below.

@mrveiss mrveiss closed this Nov 18, 2026
@mrveiss
mrveiss deleted the issue-20875-reach-base-leak branch November 18, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

phase:M1.7 Docker docs and the docs close-out

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant