Commit aaf26a8
authored
🤖 fix: prevent background process name collisions (#1070)
## Problem
Background processes are stored in a `Map<processId, BackgroundProcess>`
in `BackgroundProcessManager`. The `processId` was set directly from
`displayName`, and it's also used to compute the output directory:
```typescript
const processId = config.displayName;
// ...
const outputDir = `${bgOutputDir}/${workspaceId}/${processId}`;
```
When a new process is spawned in the background with a display name that
was previously used:
1. It gets the **same `outputDir`** as the old process
2. The old `exit_code` file still exists in that directory (written by
shell trap on exit)
3. When `refreshRunningStatuses()` checks the new process, it reads the
**stale `exit_code` file**
4. The new process is immediately marked as `"exited"` even though it
just started
5. The banner filters to `status === "running"` → **process doesn't
appear**
Additionally, the map entry itself gets overwritten, losing tracking of
any previous process with that name.
## Fix
Append incrementing suffix `(1)`, `(2)`, etc. when a collision is
detected:
```typescript
let processId = config.displayName;
let suffix = 1;
while (this.processes.has(processId)) {
processId = `${config.displayName} (${suffix})`;
suffix++;
}
```
This ensures each process gets a unique `outputDir`, so no stale
`exit_code` files interfere.
The original `displayName` is preserved separately on the
`BackgroundProcess` object for UI display - the banner shows clean names
like "Dev Server" while the agent receives unique IDs like "Dev Server
(1)" to reference specific processes.
_Generated with `mux`_1 parent 34895ca commit aaf26a8
1 file changed
+7
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
173 | | - | |
174 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
175 | 180 | | |
176 | 181 | | |
177 | 182 | | |
| |||
0 commit comments