Skip to content

fix: Auto Run docs directory resolves to worktree path (#584)#589

Draft
jSydorowicz21 wants to merge 7 commits intoRunMaestro:rcfrom
jSydorowicz21:fix/584-autorun-worktree-path
Draft

fix: Auto Run docs directory resolves to worktree path (#584)#589
jSydorowicz21 wants to merge 7 commits intoRunMaestro:rcfrom
jSydorowicz21:fix/584-autorun-worktree-path

Conversation

@jSydorowicz21
Copy link
Copy Markdown
Contributor

@jSydorowicz21 jSydorowicz21 commented Mar 18, 2026

Summary

  • Worktree sessions now resolve autoRunFolderPath to their own directory instead of inheriting the parent's path verbatim
  • When dispatching a batch run from parent to worktree, queued docs are copied to the worktree's Auto Run Docs/ folder so subsequent runs find them locally
  • Pre-existing worktree sessions (including those created outside Maestro) are migrated on restore to point at their own directory
  • Platform-aware path comparison: case-insensitive on Windows, case-sensitive on Unix

Changes

File What
worktreeSession.ts Extract isPathUnderRoot() helper + normSep(), use in resolveWorktreeAutoRunPath
useAutoRunHandlers.ts Copy-on-dispatch: read queued docs from parent, write to worktree via Promise.all. Toast on partial failure
useSessionRestoration.ts Migration for stale worktree sessions whose autoRunFolderPath points at parent
useBatchProcessor.ts Comment update
worktreeSession.test.ts 7 new tests: 6 for isPathUnderRoot, 1 Unix case-sensitivity for buildWorktreeSession
useAutoRunHandlers.worktree.test.ts Updated test verifies copy-on-dispatch reads from parent, writes to worktree

Test plan

  • All 104 existing + new tests pass
  • Create a new worktree from parent, dispatch Auto Run - docs should copy to worktree and run succeeds
  • Switch to worktree session, start another Auto Run - should read from worktree's own Auto Run Docs/
  • Restart app with pre-existing worktree session - autoRunFolderPath should migrate to worktree's directory
  • Worktree created outside Maestro (via git worktree add) is discovered with correct path
  • Windows backslash paths and mixed-case drive letters handled correctly

closes #584

Summary by CodeRabbit

  • Improvements

    • Batch runs now copy queued Auto Run documents into a worktree so runs use the worktree’s own Auto Run folder; resolved folder paths are used and warnings shown on sync failures.
    • Worktree sessions automatically rebase/migrate Auto Run folder paths to be rooted in the worktree; path handling is more robust across platforms.
  • Tests

    • Expanded coverage for worktree path resolution, containment checks, cross-session copying, and various platform/path scenarios.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 18, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0470a46b-8ac6-4f7a-bc22-685c581e28d3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Copies queued Auto Run documents from a parent session into a worktree's Auto Run folder when dispatching batch runs to a different session, rebases worktree autoRunFolderPath onto the worktree root when needed, and adds cross-platform path utilities plus expanded tests for resolution and containment logic.

Changes

Cohort / File(s) Summary
Worktree utilities
src/renderer/utils/worktreeSession.ts
Added isPathUnderRoot, normSep, and resolveWorktreeAutoRunPath; rebases/resolve autoRunFolderPath for worktrees in buildWorktreeSession.
Batch dispatch & copying
src/renderer/hooks/batch/useAutoRunHandlers.ts
When target session ≠ active session, copy queued docs from parent autoRunFolderPath to worktree autoRunFolderPath; update folderPath to destination before starting run and emit a warning on copy failures.
Session restoration
src/renderer/hooks/session/useSessionRestoration.ts
Import and use isPathUnderRoot; add migration to rebase worktree autoRunFolderPath onto projectRoot when path lies outside the worktree root.
Docs / comments
src/renderer/hooks/batch/useBatchProcessor.ts
Updated doc comment to state queued documents are copied into the worktree Auto Run folder prior to dispatch.
Tests
src/__tests__/renderer/hooks/batch/useAutoRunHandlers.worktree.test.ts, src/__tests__/renderer/utils/worktreeSession.test.ts
Test updates: validate copy/read/write behavior between parent and worktree, new autoRunFolderPath rebasing logic, isPathUnderRoot behavior, and multiple path resolution scenarios including Windows/unix cases.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Active as Active Session (parent)
    participant Handler as useAutoRunHandlers
    participant FS as File System
    participant Worktree as Worktree Session
    participant Batch as Batch Processor

    User->>Handler: Trigger batch run (target session)
    activate Handler
    alt target ≠ active
        Handler->>Active: Read queued docs from parent autoRunFolderPath
        Active->>FS: Read files
        FS-->>Handler: File contents
        Handler->>Worktree: Write files into worktree autoRunFolderPath
        Worktree->>FS: Write files
        FS-->>Handler: Write results
        Handler->>Handler: Set folderPath = worktree autoRunFolderPath
    else target = active
        Handler->>Handler: Use activeSession.autoRunFolderPath
    end
    Handler->>Batch: startBatchRun(folderPath)
    Batch->>FS: Process files at folderPath
    FS-->>Batch: Execution results
    deactivate Handler
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

RC

Suggested reviewers

  • pedramamini

Poem

🐰 I hopped from parent to worktree lane,
I copied docs through sun and rain.
Paths rebased, tests gave a cheer,
Batches run where files appear.
Hooray — now worktrees behave again!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing Auto Run documentation directory path resolution to use the worktree path instead of inheriting from the parent repository.
Linked Issues check ✅ Passed The PR fully implements all objectives from issue #584: resolves Auto Run paths to active worktree root, copies docs on dispatch, handles external worktrees, and supports platform-specific path handling.
Out of Scope Changes check ✅ Passed All changes are directly related to resolving Auto Run folder paths for worktrees. No extraneous modifications detected outside the scope of issue #584.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 18, 2026

Greptile Summary

This PR fixes a bug where worktree sessions inherited their parent's autoRunFolderPath verbatim instead of resolving it to the worktree's own directory. It adds three coordinated mechanisms: (1) resolveWorktreeAutoRunPath in worktreeSession.ts rebases the path at session-creation time, (2) a copy-on-dispatch step in useAutoRunHandlers.ts copies queued documents to the worktree's folder when dispatching from a parent, and (3) a migration in useSessionRestoration.ts corrects stale paths on app restore.

Key issues found:

  • Windows path separator in migration (useSessionRestoration.ts): The new migration constructs autoRunFolderPath with a hard-coded / separator (`${session.projectRoot}/${AUTO_RUN_FOLDER_NAME}`), producing mixed-separator paths like C:\...\Maestro-worktree/Auto Run Docs on Windows. This directly undermines the Windows-awareness added in worktreeSession.ts. The separator style should be inferred from session.projectRoot.
  • Silent failure logging: When readDoc returns success: false during the copy-on-dispatch loop, copyFailed is set but no log is written — yet the warning toast tells the user to "check logs for details."
  • isWin detection scope: isPathUnderRoot derives Windows vs. Unix mode from filePath only; checking root as well would make it more robust to edge-case path combinations.
  • Misleading test comment: The create-new test asserting folderPath === '/projects/autorun-docs' comments that the path "still comes from the parent session," which was the old behavior. It now passes because the mock folder is external to the parent cwd (so no rebasing occurs), not because parent ownership is preserved — a companion test for the in-cwd case would close this gap.

Confidence Score: 3/5

  • Mostly safe on Unix/macOS, but the Windows path separator bug in the new migration would break worktree sessions on Windows.
  • The core logic in worktreeSession.ts and the copy-on-dispatch mechanism are well-implemented and thoroughly tested. However, the new migration in useSessionRestoration.ts hard-codes a forward-slash separator, which would produce malformed paths on Windows and directly contradict the Windows-awareness the PR otherwise demonstrates. That issue affects the migration path (app restart with legacy sessions) on Windows. The rest of the PR — path rebasing, copy-on-dispatch, and the new tests — is solid.
  • src/renderer/hooks/session/useSessionRestoration.ts — the new migration block uses a hard-coded / separator that will produce broken paths on Windows.

Important Files Changed

Filename Overview
src/renderer/utils/worktreeSession.ts Adds isPathUnderRoot() (exported) and resolveWorktreeAutoRunPath() (private) helpers, then wires the latter into buildWorktreeSession to rebase inherited autoRunFolderPath onto the worktree's own cwd. Logic is sound for both Unix and Windows; minor concern about Windows detection relying solely on filePath.
src/renderer/hooks/batch/useAutoRunHandlers.ts Adds copy-on-dispatch logic: when dispatching to a worktree with a different autoRunFolderPath, queued docs are read from the parent's folder and written to the worktree's folder via Promise.all. A partial-failure toast is shown. One gap: the readResult.success === false branch is silent while the toast instructs users to "check logs".
src/renderer/hooks/session/useSessionRestoration.ts New migration block rebases stale worktree autoRunFolderPath values onto projectRoot. The rebased path is constructed with a hard-coded / separator (${session.projectRoot}/${AUTO_RUN_FOLDER_NAME}), which will produce mixed-separator paths on Windows and break the fix this PR intends to deliver.
src/tests/renderer/utils/worktreeSession.test.ts Adds comprehensive tests for isPathUnderRoot (6 cases) and resolveWorktreeAutoRunPath via buildWorktreeSession (9 cases covering Unix, Windows, relative, external, empty-string, and case-sensitivity scenarios). Coverage is thorough.
src/tests/renderer/hooks/batch/useAutoRunHandlers.worktree.test.ts Updated test verifies that docs are read from parent's folder and written to the worktree's folder. The create-new copy-on-dispatch path is not explicitly tested for the "path-under-cwd" scenario, and one comment is now misleading after the refactor.
src/renderer/hooks/batch/useBatchProcessor.ts Comment-only change updating the JSDoc for startBatchRun to reflect the new copy-on-dispatch model. No logic changes.

Sequence Diagram

sequenceDiagram
    participant U as User (Parent Session)
    participant H as handleStartBatchRun
    participant WT as buildWorktreeSession
    participant FS as Filesystem (autorun.readDoc/writeDoc)
    participant BP as startBatchRun

    U->>H: dispatch with worktreeTarget
    alt create-new / existing-closed
        H->>WT: spawnWorktreeAgentAndDispatch()
        WT->>WT: resolveWorktreeAutoRunPath(parentPath, parentCwd, worktreeCwd)
        WT-->>H: newSessionId (session stored with own autoRunFolderPath)
    else existing-open
        H->>H: find targetSession in store
    end

    H->>H: folderPath = activeSession.autoRunFolderPath
    alt targetSession.autoRunFolderPath ≠ folderPath
        loop each queued document
            H->>FS: readDoc(parentFolder, doc.md)
            FS-->>H: content
            H->>FS: writeDoc(worktreeFolder, doc.md, content)
        end
        H->>H: folderPath = worktreeFolder
    end

    H->>BP: startBatchRun(targetSessionId, config, folderPath)

    note over U,BP: On app restore, useSessionRestoration migrates\nstale worktree autoRunFolderPath → projectRoot/AUTO_RUN_FOLDER_NAME
Loading

Comments Outside Diff (1)

  1. src/__tests__/renderer/hooks/batch/useAutoRunHandlers.worktree.test.ts, line 662-667 (link)

    P2 Misleading test comment after copy-on-dispatch refactor

    The comment says:

    // Folder path should still come from the parent session
    expect(folderPath).toBe('/projects/autorun-docs');

    After this PR's changes, the test passes not because the parent's folder path is intentionally preserved, but because the mock parent's autoRunFolderPath (/projects/autorun-docs) is external to the parent cwd (/projects/my-repo), so resolveWorktreeAutoRunPath keeps it unchanged — and the copy condition targetSession.autoRunFolderPath !== folderPath is false, so no copy happens.

    The comment implies the old pre-PR behavior ("documents stay with the parent session's path") which is now a coincidence of the test setup rather than the intended behavior. Consider updating the comment, e.g.:

    // The parent's autoRunFolderPath is external to its cwd, so it is not rebased
    // and equals the worktree's path — no copy needed, both use '/projects/autorun-docs'
    

    It may also be worth adding a companion test where the parent's autoRunFolderPath is under its cwd for the create-new flow, to verify that the copy-on-dispatch path is exercised in that mode.

Last reviewed commit: "fix: copy queued doc..."

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/renderer/utils/worktreeSession.ts`:
- Around line 43-55: isPathUnderRoot currently detects Windows by testing only
filePath which misclassifies cases where root is a Windows absolute path and
filePath is relative; update the platform detection in isPathUnderRoot to test
both filePath and root (e.g., check for a drive-letter pattern on either input),
then use the resulting isWin branch when comparing normalizedFile and
normalizedRoot (perform case-insensitive comparisons when isWin is true and
preserve the existing prefix logic using normalizedRoot). Ensure you reference
the existing symbols normalizedFile, normalizedRoot, prefix, and isWin when
making the change so comparisons and startsWith checks behave correctly for
Windows roots.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 659812ca-0e85-4b6d-bae6-1b5501fb726c

📥 Commits

Reviewing files that changed from the base of the PR and between 62e3d64 and 46c7e9d.

📒 Files selected for processing (6)
  • src/__tests__/renderer/hooks/batch/useAutoRunHandlers.worktree.test.ts
  • src/__tests__/renderer/utils/worktreeSession.test.ts
  • src/renderer/hooks/batch/useAutoRunHandlers.ts
  • src/renderer/hooks/batch/useBatchProcessor.ts
  • src/renderer/hooks/session/useSessionRestoration.ts
  • src/renderer/utils/worktreeSession.ts

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/renderer/utils/worktreeSession.ts`:
- Around line 77-80: The bug is caused by slicing parentAutoRunPath using
normalizedParentCwd that may include or exclude a trailing separator; update the
logic in worktreeSession.ts to normalize the parent CWD consistently before
slicing: compute a canonical parent prefix (using normSep) that either always
ends with the path separator or always has the trailing separator removed, then
derive relativePart by removing that canonical prefix from normalized
(parentAutoRunPath); finally build result via joining normSep(worktreeCwd) and
the relativePart with a separator (or use a safe join) so symbols to edit are
normalizedParentCwd, normalized, relativePart, result and the helper
normSep/worktreeCwd/parentAutoRunPath.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9e19b0df-2171-4108-824d-9b59ad5c1b68

📥 Commits

Reviewing files that changed from the base of the PR and between 46c7e9d and 5e287d2.

📒 Files selected for processing (2)
  • src/renderer/hooks/batch/useAutoRunHandlers.ts
  • src/renderer/utils/worktreeSession.ts

@jSydorowicz21
Copy link
Copy Markdown
Contributor Author

This one needs some test time so I'm going to retarget RC so it can have some time to bake

@jSydorowicz21 jSydorowicz21 force-pushed the fix/584-autorun-worktree-path branch from acf1bbe to de9f022 Compare March 20, 2026 00:06
@jSydorowicz21 jSydorowicz21 changed the base branch from main to rc March 20, 2026 00:06
@jSydorowicz21 jSydorowicz21 marked this pull request as draft March 20, 2026 00:06
buildWorktreeSession() previously copied the parent session's
autoRunFolderPath verbatim, causing worktree sessions to use the
parent repo's Auto Run folder instead of their own. Added
resolveWorktreeAutoRunPath() that rebases absolute paths under
the parent cwd onto the worktree cwd, keeps relative and external
absolute paths unchanged, and handles Windows backslash separators.
When dispatching a batch run to a worktree session, look up the target
session's autoRunFolderPath (resolved relative to its cwd) instead of
always using the parent/active session's path. Falls back to the active
session's path if the target doesn't have one set.

Also verified useAutoRunDocumentLoader.ts - it already uses the active
session's own autoRunFolderPath via selectActiveSession, so it's
correct after the worktreeSession.ts fix.

Fixes RunMaestro#584
…ndently

Confirmed that handleAutoRunFolderSelected already stores the selected
folder path directly on the active session with no parent-session
resolution logic. Added clarifying comment documenting this behavior
for worktree sessions.
…o#584)

Worktree sessions now resolve their Auto Run folder path relative to
their own working directory instead of inheriting the parent repo's
absolute path. Batch run dispatch also now uses the target session's
resolved path.

Changes in this commit:
- Add case-insensitive path comparison for Windows in
  resolveWorktreeAutoRunPath to handle mixed-case drive letters
- Update stale comment in useBatchProcessor.ts to reflect that
  folderPath may come from the target worktree session
- Add edge case tests: empty string path, path-equals-cwd, and
  case-insensitive Windows matching
…isPathUnderRoot helper

- Extract shared `isPathUnderRoot()` and `normSep()` into worktreeSession.ts
- Copy-on-dispatch: when dispatching from parent to worktree, copy only
  the queued docs to the worktree's Auto Run folder via Promise.all
- Show toast on partial copy failure so users know if docs are missing
- Add session restoration migration for pre-existing worktree sessions
  whose autoRunFolderPath still points at the parent directory
- Platform-aware: Windows case-insensitive, Unix case-sensitive comparison
- Add 6 direct unit tests for isPathUnderRoot, update dispatch test
…gs for Windows detection

- Log warning when readDoc returns success:false so "Check logs" toast is useful
- Check both filePath and root for drive letter in isPathUnderRoot
@jSydorowicz21 jSydorowicz21 force-pushed the fix/584-autorun-worktree-path branch from de9f022 to 55d867b Compare March 28, 2026 19:01
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.

Auto Run tab uses source repo path instead of worktree path

1 participant