Skip to content

fix(sessionizer): focus existing workspace instead of duplicating - #27

Draft
pperanich wants to merge 2 commits into
andrewchng:mainfrom
pperanich:fix/dedupe-project-workspace
Draft

fix(sessionizer): focus existing workspace instead of duplicating#27
pperanich wants to merge 2 commits into
andrewchng:mainfrom
pperanich:fix/dedupe-project-workspace

Conversation

@pperanich

@pperanich pperanich commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

In the sessionizer flow, dismissing the workspace picker (Esc) and then selecting a project that already has an open workspace created a second workspace for the same cwd. The worktree flow already guards against this via findRepoWorkspaceId; this brings the project flow in line.

Change

  • Reuse the workspace list already fetched for the first picker (no extra herdr workspace list call)
  • If a non-worktree workspace's cwd matches the picked project (paths compared via normalizePath), focus it and log, instead of create + layout
  • Worktree workspaces are excluded from the match so a plain project workspace can still be created alongside a worktree checkout of the same repo, mirroring the worktree flow's semantics

Layout is intentionally not reapplied on focus, consistent with the existing "existing workspaces are only focused" behavior documented in the README.

Testing

  • bun run typecheck and bun test (135 pass; 2 new cases: focus-instead-of-create, and worktree-only match still creates)

Picking a project through the Esc path created a second workspace even
when one with the same cwd was already open. Reuse the workspace list
fetched for the first picker and focus the match; worktree workspaces
are excluded so a plain project workspace can still be created next to
them, matching the worktree flow's findRepoWorkspaceId.
@pperanich
pperanich marked this pull request as draft July 20, 2026 02:13
@pperanich

Copy link
Copy Markdown
Contributor Author

Converting to draft after deeper verification: this guard cannot fire on current herdr.

I stood up a headless herdr server (0.7.4), created a workspace with workspace create --cwd, and inspected workspace list, workspace get, and api snapshot: the workspace objects carry no cwd field. I then checked herdr's source to be sure it wasn't a CLI formatting gap: WorkspaceInfo in src/api/schema/workspaces.rs has no path field for plain workspaces (worktree workspaces get checkout_path/repo_root); identity_cwd exists internally but is never serialized. Pane cwd/foreground_cwd are exposed but track the live process (a cd in the pane moves both, symlink-resolved), so they aren't a stable identity either.

Two consequences:

  1. This PR's findProjectWorkspace compiles and its tests pass, but workspace.cwd is always undefined at runtime, so it silently falls through to the old create-duplicate behavior.
  2. The existing findRepoWorkspaceId in src/worktree/flow.ts has the same issue: repoWorkspaceId is always undefined on 0.7.4, so worktree calls always take the --cwd project fallback.

The clean fix is upstream: herdr serializing identity_cwd on WorkspaceInfo, at which point this PR works as written (and findRepoWorkspaceId starts working too). Label-based matching would work today but breaks on same-basename repos and renames, so I didn't ship it.

Happy to either park this until herdr exposes the field, or rework it if you'd prefer a different matching key.

herdr is proposed to expose the workspace creation directory as
workspace.path; match on that first and keep cwd as a legacy fallback.
the display helper prefers path for the same reason.
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.

1 participant