Skip to content

fix: Resolve symlinks when adding a worktree and matching sessions - #30

Open
cdamus wants to merge 4 commits into
eclipse-enclave:mainfrom
cdamus:issues/27-untracked-worktree-symlinks
Open

cdamus wants to merge 4 commits into
eclipse-enclave:mainfrom
cdamus:issues/27-untracked-worktree-symlinks

Conversation

@cdamus

@cdamus cdamus commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Fixes #27

Git lists a worktree at its real path, so adding an untracked worktree by a path through a symlink was refused as not an untracked worktree of the project. The add now compares paths with symlinks resolved, as the survey already does. The reconciler does the same when it matches sessions to workstreams and suggestions, because a session reported by another path to a folder was otherwise not counted on the folder's suggestion and got an adopted workstream beside the one working there.

Notes for review:

  • The new workstream takes the suggestion's path, not the path in the request. A relative path is still 409.
  • The reconciler keys the folders of a pass by resolved path (folderSet.key), each path resolved once per pass. A workstream adopted for a folder keeps the path first reported, so a session under /var/… on macOS is not adopted at /private/var/….
  • One workstream owns a folder's sessions: the first that is not adopted. An adopted workstream in a folder that another one works in is dropped, and its sessions go to that one. This goes beyond the issue. Matching by resolved path lets two workstreams name the same folder, which matching by name never had to consider.
  • The fake provider finds a project's sessions by their paths or with symlinks resolved, so a project added again by a path through a symlink finds the sessions it left running. It resolves afresh on each discovery, on a copy of its session folders with its lock released. During a full e2e run, with about 155 session folders left by other projects, a discovery took 2.7 ms at the median and 9 ms at most on my machine.
  • The store's rule that a folder holds one workstream still compares paths by name (domain.SameFolder).
  • The Enclave provider matches a container's folders to the project's with symlinks resolved too (ownsContainerIn), remembering each resolution until the next inventory check.
  • The provider and API test helpers now use the worktree's path as git lists it, as the e2e helper already does. The new tests go through a symlink of their own, so they cover this on the Linux CI runners as well.
  • workstream-note.spec.ts now polls for the note action. A created workstream gets its actions with a reconcile pass after it appears, and the spec read them at once. That race is on main too, but the fake's slower discovery made it show in full e2e runs.

Changelog

- A session running in a folder that HomeShell knows by another path, such as one through a
  symlink, shows on that folder's workstream or untracked worktree, not on a second workstream.
- Enclave sessions show in a project that was added by a path through a symlink.
- The API adds an untracked worktree that is named by a path through a symlink.

Checklist

  • Tests added: unit and e2e, or a regression test for a bug fix (see AGENTS.md)
    • Unit tests cover the add, the reconciler's matching and folder ownership, and the fake provider's discovery.
    • The e2e API specs add a worktree through a symlink, refuse a relative path, and add a project back through a symlink.
    • The workstream note spec no longer depends on when the reconcile pass after a create finishes.
  • Docs updated per the trigger table in AGENTS.md
    • docs/API.md and docs/ARCHITECTURE.md

Git lists a worktree at its real path, so adding an untracked worktree
by a path through a symlink, such as one under /var on macOS, was
refused as not an untracked worktree of the project. Match the path
against the suggestions with symlinks resolved, as the survey already
does, and keep the suggestion's path on the workstream. A relative
path is refused as before.

The reconciler matched a session to a workstream or a suggestion by
cleaned path as well. A session reported by another path to a folder
was not counted on the folder's suggestion, and got an adopted
workstream beside the one working there.

- The reconciler keys the folders of a pass by their resolved paths. A
  workstream adopted for a folder keeps the path first reported.
- One workstream owns a folder's sessions: the first that is no
  adopted one. An adopted workstream in a folder another works in is
  dropped, and its sessions go to that one.
- The fake provider finds a project's sessions by their paths or with
  symlinks resolved, so a project added again by a path through a
  symlink finds the sessions it left running. It resolves on a copy of
  its session folders, with its lock released.
- The provider and API test helpers use the worktree's path as git
  lists it, as the e2e helper already does. New tests go through a
  symlink, so they cover this on Linux as well.
- The workstream note e2e spec polls for the note action. A created
  workstream gets its actions with a reconcile pass after it appears,
  and the spec read them at once. The fake's discovery takes a few
  milliseconds longer now, which made that race show.

Fixes eclipse-enclave#27

Signed-off-by: Christian W. Damus <cdamus@eclipsesource.com>

@EclipseSourceAI EclipseSourceAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note

Autonomous AI review. May contain mistakes.

Useful comment? React 👍. Disagree? React 👎 to reject it for follow-up reviews. A reply explaining why helps too.

This agent never approves PRs. A maintainer must sign off.

Only a maintainer can re-request a review from this agent.

Powered by Eclipse Enclave via review-guard-mcp

Fixes #27. Git lists worktrees at their real path, so adding an untracked worktree through a symlinked path got a 409. Now addUntrackedWorktree matches the requested path against the suggestions with symlinks resolved (folderSet). The new workstream takes the suggestion's path, and a relative path is still refused.

The reconciler now groups sessions by resolved path instead of the cleaned path (folderSet.key, replacing cleanDir). It also picks one owner per folder (folderOwners / yieldsFolder): an adopted workstream in a folder that another workstream works in is dropped, and the owner takes its sessions.

What to look at

  • Reconciler: the core change is the ownership logic in reconcile.go. The new unit tests cover it well: matching across a symlink in both directions, one adoption for two paths to the same folder, and an adopted workstream giving way to the owner. I found no correctness bugs in the pass.
  • Fake provider vs. real providers: the fake now finds sessions through symlinks, and the new project-remove.spec.ts e2e case depends on that. The Enclave provider still decides which project owns a session by comparing path strings, so the real provider doesn't behave that way. A maintainer should decide whether Enclave gets the same treatment or whether the fake and the changelog note should be narrowed (see inline comments).
  • Paths still compared as strings: the store's folder checks (workingDirTakenLocked, handOverTakenSuggestions) still compare paths as strings, as the description says. That stays consistent here only because the new workstream takes the suggestion's path.

Not verified

  • No Go toolchain was available, so I couldn't run the unit tests.
  • I skipped a browser check: the change is in the daemon and API, and the e2e API specs cover it.

Comment thread daemon/internal/provider/fake/fake.go Resolved
Enclave reports a container's folders by their real paths, and git
lists a worktree by its real path, but the Enclave provider matched
them to a project's and its workstreams' folders by name. A project
added by a path through a symlink, as under /tmp or /var on macOS,
did not own its containers, so a CLI session in one of its untracked
worktrees was never counted on the suggestion. The fake provider
already found sessions through symlinks, so the e2e suite covered
behaviour the Enclave provider lacked.

ownsContainerIn and ownsDirIn now compare folders as they are first,
then with symlinks resolved. Each resolution is remembered until the
next inventory check, as the ownership check runs on every watch tick,
some of the time with the bridges' lock held.

The Enclave spec of a CLI session in an untracked worktree runs with
the project added by its path and through a symlink, so it covers
this on Linux as well.

Signed-off-by: Christian W. Damus <cdamus@eclipsesource.com>

@EclipseSourceAI EclipseSourceAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Note

Autonomous AI review. May contain mistakes.

Useful comment? React 👍. Disagree? React 👎 to reject it for follow-up reviews. A reply explaining why helps too.

This agent never approves PRs. A maintainer must sign off.

Only a maintainer can re-request a review from this agent.

Powered by Eclipse Enclave via review-guard-mcp

Follow-up review of commit 737f0a0, which was pushed since my last review.

This commit makes Enclave's ownsContainerIn/ownsDirIn resolve symlinks too (new folderPaths cache, invalidated each inventory pass), closing the gap between the fake provider and the real Enclave provider. I checked the new unit tests (TestContainerOwnershipThroughASymlink, TestFolderPathsForgetASymlinkRetargeted, TestFolderPathsSame) and the updated enclave-cli-sessions.spec.ts, which now runs the untracked-worktree case both directly and through a symlink. Both match what the reply on my earlier threads described, and docs/ARCHITECTURE.md got a matching "Ownership" section. No Go toolchain was available again, so I couldn't execute the suite, but the logic and test coverage read correctly by inspection.

No new issues found in this commit. Nothing else changed since my last review.

These previous comments can be resolved as they are now handled:

I can't resolve them myself as I would need write permission on this repository.

@fismif
fismif self-requested a review November 30, 2026 08:14

@fismif fismif left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, approving. Thanks!

Verified locally: Go unit tests (also with -race, 3 runs), lint, and the API e2e specs all pass. The new tests fail against main's code, so they do cover #27.

Non-blocking nits:

  • folderPaths.same holds its lock while resolving symlinks on disk, and some callers already hold the bridges' lock. A hung mount would stall every ownership check behind it.
  • The store still compares folders by name (domain.SameFolder). If two non-adopted workstreams ever named one folder by different paths, the second would quietly get no sessions. I couldn't find a way to reach this through the API, so a follow-up is fine.

@fismif

fismif commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Hi @cdamus - this would need a little conflict resolution before merging. Whenever you have time. I can't do that myself unfortunately.

# Conflicts:
#	webapp/apps/web-e2e/src/api/enclave-cli-sessions.spec.ts
The stub that stands in for Enclave in the OpenIDE test recorded $PWD,
which Go sets to the command's directory as it was named. The test
compares that with the temp dir's path with symlinks resolved, so it
failed on macOS, where the temp dir is under /var, a symlink to
/private/var. The stub now records `pwd -P`.

Signed-off-by: Christian W. Damus <cdamus@eclipsesource.com>
@cdamus

cdamus commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @fismif I've pushed a merge to resolve the conflicts.

When I ran the tests locally, I got the same kind of test failure again in a new TheiaIDE test that had been merged to main in the meantime, so because it's the same Mac-specific problem as we're fixing here, I fixed it in a new commit. Hope that's OK.

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.

Adding an untracked worktree refuses a path that reaches it through a symlink

3 participants