Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(core): desktop headless request strips viewerId and clearEnv (#925)

reviewc4938be5074c
diff --git a/src/core/headless-launch.test.ts b/src/core/headless-launch.test.ts
index af2f5ea6a..53f4ffe00 100644
--- a/src/core/headless-launch.test.ts
+++ b/src/core/headless-launch.test.ts
@@ -329,6 +329,33 @@ describe('desktopHeadlessRequest (#925)', () => {
expect(out.ptyOptions).toMatchObject(opts)
})
+ // A `viewerId` would subscribe `(0, viewer)` while `releaseHeadless` kills `(0, PRIMARY)`, leaving
+ // client 0 attached forever; `clearEnv` is a one-shot "Restart on subscription" flag that a
+ // headless start must never carry. Neither may cross the wire into this launcher.
+ it('removes viewerId and clearEnv, and keeps every other option as sent', () => {
+ const out = desktopHeadlessRequest({
+ ptyOptions: { ...opts, viewerId: 'modal-1', clearEnv: true, agentId: 'claude', requireRemote: true },
+ command: CMD
+ })
+ expect(out.ptyOptions.viewerId).toBeUndefined()
+ expect(out.ptyOptions.clearEnv).toBeUndefined()
+ expect(out.ptyOptions).toMatchObject({ ...opts, agentId: 'claude', requireRemote: true })
+ })
+
+ it('what reaches createHeadless carries no viewerId, so the release detaches the client it spawned', async () => {
+ const { deps } = harness()
+ const p = launchHeadless(
+ deps,
+ desktopHeadlessRequest({ ptyOptions: { ...opts, viewerId: 'modal-1', clearEnv: true }, command: CMD })
+ )
+ await vi.advanceTimersByTimeAsync(SETTLE_CAP_MS)
+ expect(await p).toEqual({ outcome: 'delivered', fresh: true })
+ const sent = (deps.createHeadless as ReturnType<typeof vi.fn>).mock.calls[0][0] as Record<string, unknown>
+ expect(sent.viewerId).toBeUndefined()
+ expect(sent.clearEnv).toBeUndefined()
+ expect(deps.releaseHeadless).toHaveBeenCalledWith('n1')
+ })
+
it('keeps requireRemote, so core still refuses to spawn a remote node locally', () => {
const out = desktopHeadlessRequest({
ptyOptions: { ...opts, sshRemote: ssh, requireRemote: true },
diff --git a/src/core/headless-launch.ts b/src/core/headless-launch.ts
index 659012587..fa975f5cb 100644
--- a/src/core/headless-launch.ts
+++ b/src/core/headless-launch.ts
@@ -40,8 +40,11 @@ export interface HeadlessLaunchDeps {
* `{ ptyOptions, command }`, and the desktop always releases its synthetic client, so it always
* requires a persistent backend. Whatever else the wire carries is overwritten here.
*
- * `sshRemote` is stripped: this path never spawns over a ControlMaster. `requireRemote` is KEPT as
- * sent. The primary fence is the renderer's: `startHeadless` refuses an SSH node before any claim
+ * `sshRemote` is stripped: this path never spawns over a ControlMaster. `viewerId` is stripped: a
+ * headless start is the connection's PRIMARY view, and `releaseHeadless` detaches `(0, PRIMARY)`,
+ * so a create under a viewer id would subscribe `(0, viewer)` and leave client 0 attached forever.
+ * `clearEnv` is stripped: it is a one-shot "Restart on subscription" recycle flag, never a launch
+ * option. `requireRemote` is KEPT as sent. The primary fence is the renderer's: `startHeadless` refuses an SSH node before any claim
* (`remote-unsupported`), so none should arrive here. `requireRemote` — which the renderer's
* `headlessPtyOptions` sets for an SSH-project node — is core's belt behind that fence: it makes
* `spawnNew` refuse (`unavailable:'ssh'` → `spawn-failed`), where clearing it with `sshRemote`
@@ -53,7 +56,7 @@ export function desktopHeadlessRequest(req: {
command: string
}): HeadlessLaunchRequest {
return {
- ptyOptions: { ...req.ptyOptions, sshRemote: undefined },
+ ptyOptions: { ...req.ptyOptions, sshRemote: undefined, viewerId: undefined, clearEnv: undefined },
command: String(req.command ?? ''),
release: true,
requirePersistent: true
diff --git a/src/main/index.ts b/src/main/index.ts
index 75b63d34e..1e7fd5640 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -1502,8 +1502,8 @@ app.whenReady().then(async () => {
// shared `registerIpc`, so a Server Edition browser cannot reach it (the server starts nodes
// through its own HeadlessNodeFactory). A relay peer does reach this table, and is refused
// host-side because the channel is in `HOST_ONLY_CHANNELS` (shared/host-control). All logic lives
- // in core/headless-launch: `desktopHeadlessRequest` strips `sshRemote` and forces release +
- // requirePersistent. The renderer refuses an SSH node before any claim (the primary fence); the
+ // in core/headless-launch: `desktopHeadlessRequest` strips `sshRemote`, `viewerId` and `clearEnv`
+ // and forces release + requirePersistent. The renderer refuses an SSH node before any claim (the primary fence); the
// `requireRemote` it sets for an SSH-project node is kept here, so core's `spawnNew` refusal
// stands behind that fence as a belt.
corePlatform.handle(