Skip to content

fix: judge cwd + shared cube state across worktrees (rebase of #182+#183)#184

Merged
jacsamell merged 1 commit into
mainfrom
fix/judge-cwd-and-shared-state-rebase
May 19, 2026
Merged

fix: judge cwd + shared cube state across worktrees (rebase of #182+#183)#184
jacsamell merged 1 commit into
mainfrom
fix/judge-cwd-and-shared-state-rebase

Conversation

@jacsamell
Copy link
Copy Markdown
Contributor

@jacsamell jacsamell commented May 19, 2026

Why

PRs #182 and #183 squash-merged to empty diffs because they were stacked on the verify-gate branch (#181) instead of branched from main. GitHub squashed #181's parent commits into #182's PR, and again into #183's; nothing actually changed for the latter two.

Re-applying both fixes properly against current main HEAD.

What lands

1. `judge_panel.run_judge`: use `review_worktree` as the judge cwd

Stops judges from inheriting the operator's Claude Code session worktree (which may be on a stale unrelated branch). Previously caused judges to review code from a worktree dozens of commits behind the actual PR head — Roy diagnosed this manually on `cool-satoshi-bd8d21`.

2. `_find_git_root`: resolve to the MAIN repo root, not the per-worktree path

Cube state (`.agent-sessions/`, `.prompts/decisions/`, `.cube/`) needs to be shared across all worktrees of the same repo. The naive walk-up stopped at the per-worktree `.git` file. Now uses `git rev-parse --git-common-dir` to find the shared `.git` and returns its parent.

Eliminates the recurring "No session found" regression caused by state scattered across multiple Claude Code worktrees.

Verified

  • 237 tests pass
  • `PROJECT_ROOT` resolves to `/Users/jacob/dev/aetheron-connect-v2` from both the main checkout and any `.claude/worktrees//`
  • Falls back to legacy walk-up when `git rev-parse` isn't available

🤖 Generated with Claude Code

Overview

Re-applies fixes from PRs #182 and #183, addressing worktree isolation and shared repository state issues that arose when judges and cube utilities operate across Git worktrees.

Key Changes

judge_panel.py: run_judge now explicitly uses judge_info.review_worktree as the working directory when available, preventing judges from inheriting the operator's potentially stale/unrelated Claude Code session worktree. Falls back to previous behaviour if no review worktree is set.

config.py: _find_git_root() now uses git rev-parse --git-common-dir to identify the shared .git directory, ensuring it returns the main repository root rather than stopping at per-worktree .git files. This guarantees cube state directories (.agent-sessions/, .prompts/decisions/, .cube/) are shared across all worktrees. Includes fallback to legacy walk-up method when git-based lookup fails.

Verification

  • 237 tests pass
  • PROJECT_ROOT correctly resolves to main repo root from both primary checkout and worktree contexts
  • Fallback logic intact for non-git environments

Review Change Stack

)

PR #182 and #183 squash-merged to empty diffs because they were stacked off the verify-gate branch instead of main. Re-applying both fixes against the actual main HEAD:

1. judge_panel.run_judge: use judge_info.review_worktree as the cwd when the PR review flow synced one. Stops judges from inheriting the operator's Claude Code session worktree (which may be on a stale unrelated branch). Previously: judges reviewed code from cool-satoshi worktree on commits dozens behind the actual PR.

2. config._find_git_root: use 'git rev-parse --git-common-dir' to find the MAIN repo working tree, not the per-Claude-Code-session worktree. All worktrees of the same repo now share .agent-sessions/, .prompts/decisions/, .cube/. Eliminates the 'No session found' regression that came from state being scattered across worktrees.

Verified: PROJECT_ROOT resolves to the main repo root from both the main checkout and any Claude Code session worktree. 237 tests pass.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

Caution

Review failed

Pull request was closed or merged during review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 230a0a68-93b8-4d48-ab52-9faa1cf35ae6

📥 Commits

Reviewing files that changed from the base of the PR and between 8e23e07 and 53f5254.

📒 Files selected for processing (2)
  • python/cube/automation/judge_panel.py
  • python/cube/core/config.py
📜 Recent review details
🧰 Additional context used
🪛 Ruff (0.15.13)
python/cube/core/config.py

[error] 33-33: Starting a process with a partial executable path

(S607)

🔇 Additional comments (2)
python/cube/core/config.py (1)

15-49: LGTM!

python/cube/automation/judge_panel.py (1)

270-281: LGTM!


Walkthrough

This PR fixes git worktree support by improving how the codebase detects the shared git repository root and ensures judge processes execute from the correct PR review worktree directory instead of potentially stale or incorrect working directories.

Changes

Git Worktree Support

Layer / File(s) Summary
Git root detection for worktrees
python/cube/core/config.py
_find_git_root() now uses git rev-parse --git-common-dir to correctly identify the shared repository root when running from git worktrees, with fallback to walking up directories for .git.
Judge working directory selection
python/cube/automation/judge_panel.py
run_judge now selects the process working directory by using judge_info.review_worktree when present, falling back to WORKTREE_BASE.parent for gemini or PROJECT_ROOT for other tools.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • aetheronhq/agent-cube#176: Both PRs modify python/cube/automation/judge_panel.py to respect the dedicated review_worktree (avoiding incorrect/stale working directories by aligning where the judge runs/reads from), so the changes are directly related.
  • aetheronhq/agent-cube#175: Main PR's judge_panel.run_judge now runs the judge in the synced review_worktree directory, which directly complements the retrieved PR's peer_review worktree force-sync and HEAD-verification to prevent stale PR-review content.

Poem

🐰 A worktree hops along its merry way,
Git roots found both night and day,
Judge now knows the path to take,
No more directories to forsake! 🌳

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarises the main changes: fixing judge working directory handling and ensuring shared cube state across git worktrees, with a note about the rebase.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

@jacsamell jacsamell merged commit a3ed1c0 into main May 19, 2026
0 of 2 checks passed
@jacsamell jacsamell deleted the fix/judge-cwd-and-shared-state-rebase branch May 19, 2026 22:34
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.

1 participant