You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🤖 fix: persist runtimeConfig when forking local workspaces (#1863)
## Summary
Fix local workspace fork creating corrupt worktree workspaces by
persisting `runtimeConfig` in `config.addWorkspace()`, then simplify the
codebase by removing redundant inline fallbacks.
## Background
PR #1721 (commit 4238ff4) added fork support for local (project-dir)
workspaces. The `LocalRuntime.forkWorkspace()` was correctly implemented
to return the project path, and `workspaceService.fork()` correctly
assembled the `FrontendWorkspaceMetadata` with `runtimeConfig:
forkedRuntimeConfig`.
However, when `config.addWorkspace()` stored the forked workspace entry,
it **discarded the runtimeConfig field**:
```typescript
const workspaceEntry: Workspace = {
path: workspacePath,
id: metadata.id,
name: metadata.name,
createdAt: metadata.createdAt,
// runtimeConfig was missing!
};
```
On subsequent config loads, `getAllWorkspaceMetadata()` would see no
`runtimeConfig` and apply `DEFAULT_RUNTIME_CONFIG` (type: "worktree"
with srcBaseDir), causing the forked workspace to be treated as a
worktree runtime. This created "corrupt worktree" errors because
WorktreeRuntime operations would fail on directories that were never set
up as git worktrees.
## Implementation
### Commit 1: Fix runtimeConfig persistence
One-line fix: include `runtimeConfig: metadata.runtimeConfig` in the
workspace entry when calling `addWorkspace()`.
### Commit 2: Remove redundant fallbacks
The config layer already guarantees every `WorkspaceMetadata` has a
`runtimeConfig` (via `DEFAULT_RUNTIME_CONFIG` applied in
`getAllWorkspaceMetadata()`). This commit removes 13 inline `?? { type:
"local", srcBaseDir }` fallbacks across 5 service files that were:
- **Redundant**: The metadata type already includes runtimeConfig
- **Inconsistent**: Inline fallbacks used `type: "local"` while the
canonical default is `type: "worktree"`
- **Bug-masking**: Silently substituting values instead of surfacing
issues
Files cleaned up:
- `workspaceService.ts` (5 locations)
- `agentSession.ts` (5 locations)
- `aiService.ts`, `terminalService.ts`,
`workspaceMcpOverridesService.ts` (1 each)
### Commit 3: Fix namedWorkspacePath persistence (Codex review feedback)
`config.addWorkspace()` was hardcoding worktree-style paths
(`~/.mux/src/...`) even for local workspaces. After app restart, this
caused Open-in-Editor and path display to use the wrong directory.
Fix: use `namedWorkspacePath` from the metadata if provided (which is
computed runtime-aware by `Runtime.getWorkspacePath()`), falling back to
worktree-style path only for legacy callers.
## Validation
- Integration tests for fork persistence:
- Creates local workspace → forks → verifies runtimeConfig survives
reload
- Verifies `namedWorkspacePath` is the project path (not
`~/.mux/src/...`) after reload
- `make typecheck` passes
- `make static-check` passes
- `TEST_INTEGRATION=1 bun x jest tests/ipc/forkWorkspace.test.ts` - all
9 tests pass
---
_Generated with `mux` · Model: `anthropic:claude-sonnet-4-20250514`_
<!-- mux-attribution: model=anthropic:claude-sonnet-4-20250514 -->
0 commit comments