Skip to content

fix(app): keep new sessions in their selected worktree - #52094

Closed
Dante-dan wants to merge 6 commits into
anomalyco:devfrom
Dante-dan:fix/51196-desktop-session-location
Closed

Dante-dan wants to merge 6 commits into
anomalyco:devfrom
Dante-dan:fix/51196-desktop-session-location

Conversation

@Dante-dan

@Dante-dan Dante-dan commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Fixes #51196

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

A new-session draft opened from an existing Git worktree could use the saved destination instead of that worktree, placing the session under the project root. Prefer the draft's current directory when it matches a known non-main worktree. An explicit worktree choice still wins, and ordinary project-root drafts keep their configured destination.

How did you verify your code works?

  • cd packages/app && bun run test:unit: 931 passed, 1 skipped.
  • cd packages/app && bun typecheck: passed.
  • The focused controller tests cover the worktree path, explicit choice, project root, and stale inventory.

Base refresh against v2 (a2b6005627): 17 focused controller tests, app typecheck, changed-file lint, and bun run check passed (36 typecheck tasks; Node 24). The app unit run before the final automatic base merge passed 733 tests; no controller behavior changed during that merge. The browser-condition suite passed 162 tests and failed 5 Playwright-config subprocess checks at their 5-second timeout. The earlier implementation validation above remains historical.

I could not run the production entry benchmark or real Windows Desktop flow here: Chromium startup was denied by the macOS sandbox (MachPortRendezvousServer permission error). The behavior should be checked in Desktop on Windows 11 with an existing worktree.

Screenshots / recordings

Not captured because the browser could not launch in this environment.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@thdxr
thdxr changed the base branch from v2 to dev October 10, 2026 19:23
@imyu37

imyu37 commented Oct 15, 2026

Copy link
Copy Markdown

Thanks for working on this — one gap worth flagging before merge.

This PR's condition only prefers the draft's current directory when it matches a known non-main worktree. The plain-subdirectory case (no worktree/sandbox at all) appears to fall through to the same project-canonical-path substitution, and it reproduces 100% on v2.0.26 Desktop:

CLI run, cwd = plain subdirectory:   location.directory = D:\vault\2-AI\notes-tuning   subpath = 2-AI/notes-tuning   OK
Desktop, footer = same subdirectory: location.directory = D:\vault                      subpath = (empty)            BROKEN
POST /api/session with explicit location.directory = subdirectory: stored correctly   OK

So the server accepts a plain subdirectory fine; the client just does not send it. The footer shows the selected subdirectory, but the created session lands at the repo root. Detailed repro and timeline: see the plain-subdirectory comment in #51992.

Two data points that may help locate the regression:

  • fix(app): keep new local sessions in the selected directory #46713 (keep new local sessions in the selected directory) was merged on 2026-09-02, yet plain-subdirectory sessions from Desktop started binding to the repo root after 2026-10-08 — the earlier fix appears to have been bypassed, or a second substitution path exists in the new-session draft flow.
  • Sessions created from the same bundled CLI 2.0.26 with cwd set to the subdirectory still record the subdirectory correctly, so this is specific to the app-side draft destination.

If the draft's current directory were trusted whenever it is a valid descendant of the project (not only when it maps to a known worktree), the worktree and plain-subdirectory variants would be covered by the same condition. If that is out of scope here, a pointer to where the plain-subdirectory case should be tracked would be appreciated.

@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

session: new session created from a project binds to the service default location and is missing from that project's history

2 participants