Skip to content

fix: 4 proactive bugs from codebase scan#192

Merged
jacsamell merged 1 commit into
mainfrom
fix/proactive-bugs-batch
May 20, 2026
Merged

fix: 4 proactive bugs from codebase scan#192
jacsamell merged 1 commit into
mainfrom
fix/proactive-bugs-batch

Conversation

@jacsamell
Copy link
Copy Markdown
Contributor

@jacsamell jacsamell commented May 20, 2026

Found via proactive scan. All real, all independent of the user-reported bugs.

  1. create_worktree branch verify — was silently reusing stale worktrees on wrong branch; now reset+recreate when wrong, preserve when right
  2. has_uncommitted_changes / has_unpushed_commits timeouts — could hang cube on stuck git lockfile
  3. Claude rate-limit pattern misses 'monthly usage limit' — Anthropic's org-monthly cap bypassed detection; claude judges silently failed (fixes Jacob's diagnostic Issue 4)
  4. find_decision_file scoped scan — was walking all 90+ project worktrees on every lookup

238 tests pass.

Summary

Four independent proactive bug fixes addressing stability and performance issues:

1. Worktree reuse now validates state (git.py)

Previously, create_worktree could blindly reuse stale worktrees on the wrong branch. Now verifies both branch and cleanliness before reusing; if incorrect, attempts reset via git checkout -B ... origin/main followed by hard reset and clean. Falls back to removing and recreating if reset fails. Includes new test coverage for the wrong-branch reset path.

2. Git subprocess timeouts prevent indefinite hangs (git.py)

Added 10-second timeout to has_uncommitted_changes and 15-second timeout to has_unpushed_commits to prevent hangs when git lockfiles block subprocess operations.

3. Extended Claude rate-limit detection (claude.py)

Expanded error pattern recognition to catch Anthropic's org-monthly usage cap message ("You've hit your org's monthly usage limit") alongside existing "rate limit" and "capacity" matches. Previously missed this variant, causing judges to fail silently.

4. Optimised decision file lookup (decision_files.py)

Scoped find_decision_file worktree search to the specific project directory rather than iterating all 90+ worktrees under WORKTREE_BASE. Eliminates O(N×M) disk scans on each lookup.

Tests: 238 passing; 1 new test added for wrong-branch reset validation.

Review Change Stack

…ts, rate-limit pattern, scan scope)

Found by proactive grep, all real:

1. create_worktree returned stale worktrees without verifying branch — matched Roy's slice-3 post-mortem symptom (detached HEAD + staged junk from prior failed run). Now branch + cleanliness check; reset to writer-<name>/<task> + origin/main when wrong; recreate when even that fails. Preserves in-progress writer state when worktree is on the correct branch (existing test pattern kept and renamed).

2. has_uncommitted_changes / has_unpushed_commits had no subprocess timeout — could hang cube indefinitely on stuck git locks. Added 10s/15s timeouts.

3. Claude rate-limit pattern only matched 'rate limit'/'capacity'/'overloaded'. Anthropic's org-monthly cap message is 'You've hit your org's monthly usage limit' — bypassed detection. claude judges silently failed, panel showed '0/2 approved'. Extended pattern to include monthly/usage limit/quota/hit-your-org.

4. find_decision_file scanned every project under WORKTREE_BASE (90+ on Jacob's machine) on every decision lookup. O(N*M) disk hit per judge per panel. Scoped to PROJECT_ROOT's project dir only.

238 tests pass (was 237 + 1 new for the wrong-branch reset path).
@jacsamell jacsamell merged commit 571a135 into main May 20, 2026
0 of 2 checks passed
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 69e9bee8-d2cf-4ef8-92d5-b68ceb416b30

📥 Commits

Reviewing files that changed from the base of the PR and between 424521f and 24579f1.

📒 Files selected for processing (4)
  • python/cube/core/adapters/claude.py
  • python/cube/core/decision_files.py
  • python/cube/core/git.py
  • tests/core/test_git_worktree.py

Walkthrough

This PR hardens git worktree management by adding conditional reuse checks and timeout guards, narrows decision-file worktree search scope, and expands Claude rate-limit error phrase matching. Existing worktrees are now validated for correctness before reuse; stale ones are reset or removed. Tests verify both reuse and reset paths.

Changes

Worktree robustness and error handling

Layer / File(s) Summary
Claude adapter rate-limit error classification
python/cube/core/adapters/claude.py
ClaudeAdapter.run() now matches case-insensitive rate-limit phrases including "capacity", "monthly usage", "quota", and "hit your org", storing truncated errors with a "Rate limit:" prefix.
Conditional worktree reuse and reset
python/cube/core/git.py
create_worktree checks whether an existing worktree is on the expected branch and clean; if not, it attempts reconfiguration via checkout, hard reset, and clean operations; on failure, it removes the stale worktree to force recreation.
Git status and push checks with timeout guards
python/cube/core/git.py
has_uncommitted_changes and has_unpushed_commits add timeout-guarded subprocess calls, returning False on timeout or exception rather than hanging.
Decision file worktree search scope restriction
python/cube/core/decision_files.py
find_decision_file restricts worktree fallback search to the current project's worktree directory under WORKTREE_BASE instead of scanning all projects' worktrees.
Worktree reuse and reset test coverage
tests/core/test_git_worktree.py
Replaces the old "return existing without resetting" test with test_create_worktree_reuses_existing_when_on_correct_branch and adds test_create_worktree_resets_existing_when_on_wrong_branch to cover clean-reuse and dirty-reset paths.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • aetheronhq/agent-cube#175: Both PRs update worktree sync logic to prevent stale content by adding stronger fetch/reset/clean behaviour and explicit worktree HEAD verification.
  • aetheronhq/agent-cube#69: Both PRs modify ClaudeAdapter error handling within python/cube/core/adapters/claude.py.

Poem

🐰 A worktree's tale, now cleaned with care,
Branch checks and timeouts in the air,
Rate limits caught in phrases wide,
Stale worktrees swept aside,
The cube now robust and fair!


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

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