Skip to content

fix: load services for worktree projects after directory is created#88

Open
JanTvrdik wants to merge 1 commit intocontember:mainfrom
JanTvrdik:fix/worktree-services
Open

fix: load services for worktree projects after directory is created#88
JanTvrdik wants to merge 1 commit intocontember:mainfrom
JanTvrdik:fix/worktree-services

Conversation

@JanTvrdik
Copy link
Copy Markdown
Contributor

Summary

  • When creating a worktree with deferred hooks, the project is registered in the workspace before the directory exists on disk. The service loading observer would run immediately, find no okena.yaml or docker-compose.yml (directory doesn't exist yet), and mark the project as "known" — never retrying once the directory was ready.
  • Skip service loading for projects whose directory doesn't exist yet, so they get picked up on the next workspace notification after fire_worktree_hooks runs and the directory is available.
  • Same class of issue as Improve monorepo & worktree interaction #33 and Close worktree fails for monorepos #60 (worktree path handling).

Test plan

  • Manual: add a project with docker-compose.yml, create a worktree from it, verify Services section appears in the sidebar for the worktree project
  • Manual: restart the app with an existing worktree project that has services — verify services load on startup
  • Manual: verify non-worktree projects still load services normally

Co-Authored-By: Claude Code

When a worktree is created with deferred hooks, the project is registered
in the workspace before the directory exists on disk. The service loading
observer would attempt to load services (finding nothing since the directory
doesn't exist yet) and mark the project as known, never retrying once the
directory was ready.

Skip service loading for projects whose directory doesn't exist yet, so
they get picked up on the next workspace notification after the worktree
directory is created and fire_worktree_hooks runs.

Co-Authored-By: Claude Code
Copilot AI review requested due to automatic review settings March 27, 2026 16:13
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes service discovery for deferred worktree projects by avoiding “one-shot” service loading before the worktree directory exists on disk, ensuring services are loaded once the directory becomes available.

Changes:

  • Skip service loading for projects whose directory does not yet exist (deferred worktrees) during initial load and workspace-change observation.
  • Track known_project_ids based on successfully-attempted loads/unloads (insert on load, remove on unload) instead of blindly replacing with current_ids.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +298 to 309
// Load services for new projects (or deferred worktrees whose directory now exists)
for (id, path, saved_terminals) in &local_projects {
if !known.contains(id) {
// Skip projects whose directory doesn't exist yet (deferred worktrees).
if !std::path::Path::new(path).exists() {
continue;
}
service_manager.update(cx, |sm, cx| {
sm.load_project_services(id, path, saved_terminals, cx);
});
known.insert(id.clone());
}
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

This workspace→service loading observer logic is now diverging from the nearly-identical implementation in src/app/headless.rs. To avoid inconsistent behavior between GUI and headless modes (and future drift), consider either applying the same deferred-directory Path::exists() handling there as well, or extracting the shared project-service sync logic into a helper used by both call sites.

Copilot uses AI. Check for mistakes.
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