Skip to content

fix: harden worktree creation and improve subagent mode support#1889

Merged
mohammedahmed18 merged 4 commits intomainfrom
cf-worktree-subagent-fixes
Mar 25, 2026
Merged

fix: harden worktree creation and improve subagent mode support#1889
mohammedahmed18 merged 4 commits intomainfrom
cf-worktree-subagent-fixes

Conversation

@mohammedahmed18
Copy link
Copy Markdown
Contributor

Summary

  • Worktree creation is now mandatory: setup_worktree exits with an error instead of silently skipping when the git repo check fails or worktree creation returns None. This prevents optimizations from running in an invalid state.
  • Removed redundant git repo check from create_detached_worktree() — the caller in optimizer.py already performs this check, so the parameter and duplicate logic were unnecessary.
  • Subagent mode parity with LSP: Skip was_function_previously_optimized checks in subagent mode (same behavior as LSP), and render optimization result trees as markdown logs instead of Rich console output.
  • Disabled custom benchmark loop overrides (pytest_min_loops/pytest_max_loops) for subagent runs — commented out pending further tuning.
  • Downgraded Jest benchmarking failure logs from info to debug to reduce noise.

Test plan

  • Verify worktree creation fails fast when not in a git repo
  • Run optimization in subagent mode and confirm markdown output is logged
  • Run JS benchmarking with failures and confirm debug-level logging

🤖 Generated with Claude Code

- Make worktree creation mandatory by exiting on failure instead of silently skipping
- Remove redundant git repo check from create_detached_worktree (caller handles it)
- Skip duplicate optimization checks in subagent mode (same as LSP)
- Log optimization results as markdown in subagent mode instead of Rich tree
- Disable custom benchmark loop overrides for subagent runs
- Downgrade Jest benchmarking failure logs from info to debug

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Mar 24, 2026

Claude finished @mohammedahmed18's task in 2m 28s —— View job


PR Review Summary

  • Triage PR size — SMALL (53 lines, 5 production files)
  • Run lint/typecheck — prek clean; mypy errors are pre-existing
  • Resolve stale threads — none found
  • Review code
  • Check for duplicates — none found
  • Post summary

Prek Checks

Clean — no ruff or formatting issues introduced by this PR. Mypy reports 174 pre-existing errors across 4 files (not caused by this PR).


Code Review

Bug: Failure returned when worktree already exists (optimizer.py:784-785)

if self.current_worktree:
    return Failure("There is an existing worktree, Can't create more than one per function")

The original code silently returned here (idempotency — "already initialized, skip"). This PR changes it to a Failure, causing the caller to log an error and abort run() entirely. If worktree_mode() is ever called when a worktree is already set (e.g. retry logic, multi-function runs), this will now silently abort the entire optimization run rather than continuing with the existing worktree. The silent return behavior should be preserved for this branch. Fix this →

Minor: Result[bool, str] with # noqa: FBT003 (optimizer.py:783, 798)

Since the success value is meaningless (True is just a placeholder), Result[None, str] / Success(None) is cleaner and avoids the suppressed ruff warning entirely. Fix this →

Minor: Removed helpful comment (functions_to_optimize.py:761)

The comment explaining why LSP skips was_function_previously_optimized was removed. Since subagent mode now gets the same treatment, a brief comment explaining the reason for both would help future maintainers.


Duplicate Detection

No duplicates detected.


Last updated: 2026-03-25

@aseembits93
Copy link
Copy Markdown
Contributor

LGTM. i have noticed the windows tests are a bit flaky. will investigate a bit.

Copy link
Copy Markdown
Contributor

@aseembits93 aseembits93 left a comment

Choose a reason for hiding this comment

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

@mohammedahmed18 mohammedahmed18 merged commit 5a81195 into main Mar 25, 2026
30 of 31 checks passed
@mohammedahmed18 mohammedahmed18 deleted the cf-worktree-subagent-fixes branch March 25, 2026 22:26
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