Skip to content

feat(workspace): spawn per-project workspace host processes#4647

Merged
gregpriday merged 5 commits intodevelopfrom
feature/issue-4642-spawn-per-project-workspace
Mar 30, 2026
Merged

feat(workspace): spawn per-project workspace host processes#4647
gregpriday merged 5 commits intodevelopfrom
feature/issue-4642-spawn-per-project-workspace

Conversation

@gregpriday
Copy link
Copy Markdown
Collaborator

Summary

  • Replaces the singleton WorkspaceService utility process with one process per active project, eliminating cross-project state contamination at the OS level
  • Introduces WorkspaceHostProcess to manage the lifecycle of per-project workspace hosts (spawn, health-check, restart on crash, teardown)
  • Transforms WorkspaceClient from a message router with 16 guard mechanisms into a clean process lifecycle manager — the renderer IPC contract is unchanged

Resolves #4642

Changes

  • electron/services/WorkspaceHostProcess.ts — new class managing a single workspace utility process with MessagePort-based IPC, heartbeat monitoring, and restart backoff
  • electron/services/WorkspaceClient.ts — rewritten to maintain a Map<projectPath, WorkspaceHostProcess> with ref-counting for windows sharing a project; all the windowScopes/generation-counter guard layers removed
  • electron/workspace-host/WorkspaceService.ts — removed per-scope filtering code; service now owns exactly one project
  • electron/window/windowServices.ts — updated to call WorkspaceClient.attachWindow / detachWindow on project open/close
  • electron/ipc/handlers/worktree.ts, copyTree.ts, artifacts.ts — minor updates to route through the new per-project client API
  • electron/__tests__/WorkspaceClient.resilience.test.ts — test suite updated to cover per-project process lifecycle, crash recovery, and ref-counting

Testing

  • Full unit test suite passes (npm run check)
  • Resilience tests cover: clean spawn, crash recovery with backoff, ref-counting when two windows share a project, graceful shutdown
  • Renderer IPC contract unchanged — existing E2E tests continue to apply without modification

- Extract WorkspaceHostProcess class for per-host lifecycle management
- Rewrite WorkspaceClient as multi-process manager with Map<path, ProcessEntry>
- Add refcounting with 5s grace period cleanup on zero-refcount
- Route getAllStatesAsync by windowId to correct per-project host
- Remove scope guards from WorkspaceService (now per-process isolated)
- Update IPC handlers to pass windowId for per-project routing
- Rewrite resilience tests for new multi-process architecture
- Fix poisoned entry on init failure: clean up failed entries and retry
- Replace blind first-available fallback with worktree path reverse map
- Only fall back to single-host case to avoid cross-project routing
- Propagate real errors from deleteWorktree instead of swallowing
- Skip WORKTREE_ACTIVATED emission when all hosts reject setActive
- Add tests for worktree path routing and setActive rejection
- Remove unused worktree-removed no-op loop (TS6133)
- Change let to const for workspaceReady (prefer-const)
- Fix useless assignment warning by renaming entry variables
- Suppress no-explicit-any in test file and pendingRequests type
- All checks pass: typecheck, lint ratchet (402, -1 from baseline), format
- CI test failure: worktree.rateLimit.test.ts missing BrowserWindow in electron mock
- Handlers now use BrowserWindow.fromWebContents for windowId routing
@gregpriday gregpriday force-pushed the feature/issue-4642-spawn-per-project-workspace branch from 64fa271 to 949918a Compare March 30, 2026 17:16
@gregpriday gregpriday merged commit f179ff0 into develop Mar 30, 2026
4 checks passed
@gregpriday gregpriday deleted the feature/issue-4642-spawn-per-project-workspace branch March 30, 2026 17:20
@gregpriday
Copy link
Copy Markdown
Collaborator Author

gregpriday commented Apr 7, 2026

The old workspace host's events leaked into the new project during the 5-second grace period. Scope filtering was needed on the transition boundary. Fixed in #4670.

Regression audit for training data.

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.

Spawn per-project workspace host processes

1 participant