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(windows): session-host watch probe falls through instead of refusing a live Zellij join

reviewbfe36908871c
diff --git a/docs/live-links.md b/docs/live-links.md
index de0736e65..1456c27fa 100644
--- a/docs/live-links.md
+++ b/docs/live-links.md
@@ -923,7 +923,9 @@ carry it to teammates and the canvas authority would write it into the git-share
session, so an owner opening the node gets its own typing attachment. A host from an older build
lacks the feature: refused (`join-only`), never an ordinary attach that would cast the viewer's size.
The create dialog's note follows `tmuxStatus().persistence.watchJoin` (the CONNECTED host's answer).
- Control typing needs the node open (a watch attachment has no typing path).
+ Control typing needs the node open WHEN THE VIEWER JOINS: a viewer that joined through `watch-attach`
+ keeps that read-only attachment (its input route is decided at join, `none`) even after the owner
+ opens the node, until it rejoins (the session ends, or the link reconnects).
- **Desktop where local terminals are neither tmux nor such a session host** (tmux switched off or
missing; the Zellij backend; an older host): there is no watcher client of its own, so a viewer can
co-attach only to a terminal this app has OPEN (mounted, or parked) — after a restart, for a background project or an
@@ -1018,7 +1020,8 @@ Found while building it:
`#{client_session}` and treating a switch as a lifecycle event is a possible follow-up.
- **Any machine whose local terminals are neither tmux nor a `watch-attach` session host:** a link to a
terminal that is not open in the app cannot be watched until it is (Surfaces, above). Said, never
- silent. On the session host, Control typing still needs the node open.
+ silent. On the session host, Control typing still needs the node open at the moment the viewer joins (a
+ viewer already riding a `watch-attach` attachment is not upgraded when the owner opens the node).
- **A tmux < 3.2 host cannot be watched** (fail closed, "waiting").
- **After a run whose index was missing, unreadable or corrupt, node-gone waits for the next launch**
(R44/R54): a link to a node deleted in that run lives until its expiry (≤ 24 h) — an Unlimited link
diff --git a/docs/windows-session-host.md b/docs/windows-session-host.md
index 7e67a8040..b03de0a46 100644
--- a/docs/windows-session-host.md
+++ b/docs/windows-session-host.md
@@ -692,9 +692,11 @@ you chose and why") rather than an oversight.
by default (no OSC 7 / 9;9), so a plain Windows shell's relative file links still resolve against
the launch cwd only; agent CLIs and shell integrations that emit OSC 7 / 9;9 / 633 work. No prompt
hook is installed for them (it would rewrite the user's prompt); an opt-in one is a follow-up.
-- **Control typing into a session-host node needs the node open** in this app: a viewer of a node
- nobody holds rides a read-only `watch-attach` attachment, which has no typing path (the host
- refuses its writes, and keys must not be retyped as a framed `sendKeys` paste).
+- **Control typing into a session-host node needs the node open when the viewer joins**: a viewer
+ of a node nobody holds rides a read-only `watch-attach` attachment, which has no typing path (the
+ host refuses its writes, and keys must not be retyped as a framed `sendKeys` paste). The input
+ route is decided at join, so that viewer stays read-only after the owner opens the node, until it
+ rejoins.
- **No equivalent of `paneOwner` / `bracketPasteRequested` / a standalone `paneCursor` query** —
see the protocol table's "Not implemented" note. Nothing in this app currently calls these for a
session-host-backed node (they are gated behind `this.tmuxPath` being set), so nothing is
diff --git a/src/core/pty-manager.ts b/src/core/pty-manager.ts
index ee9f9afdf..2d985f69a 100644
--- a/src/core/pty-manager.ts
+++ b/src/core/pty-manager.ts
@@ -2663,9 +2663,12 @@ export class PtyManager {
this.hostBackendEligible()
) {
const live = await sessionHostHasSession(sessionName(options.persistKey)).catch(() => false)
- if (!live || !(await sessionHostSupportsWatch().catch(() => false)))
- return { sessionId: '', fresh: false, unavailable: 'join-only' }
- options = { ...options, [SESSION_HOST_WATCH]: true } as SessionHostWatchOptions
+ // Not proven ⇒ NO early return: fall through to the existing join-only decision, where the
+ // session-host placeholder `fresh = true` still refuses. On Windows that is the same refusal;
+ // on a POSIX machine without tmux it keeps the Zellij branch below reachable, so a viewer of a
+ // node that lives in a LIVE Zellij session is not refused just because the host lacks it.
+ if (live && (await sessionHostSupportsWatch().catch(() => false)))
+ options = { ...options, [SESSION_HOST_WATCH]: true } as SessionHostWatchOptions
}
const sessionHostWatch = isSessionHostWatch(options)
let fresh = options.sshRemote
@@ -5289,7 +5292,8 @@ export class PtyManager {
if (s.sshRemote) return s.tmuxBacked ? 'ssh' : 'none'
// A read-only session-host attachment (`watch-attach`, the node not held here) has no typing
// path: the host refuses writes from it, and its keys must not be retyped as a framed paste.
- // Control typing reaches a session-host node while the node is open in this app.
+ // Control typing reaches a session-host node only for a viewer that joined while the node was
+ // open in this app (the route is read once, at join: this viewer is not upgraded later).
if (s.sessionHost && s.watcherClient) return 'none'
if (s.sessionHost || s.nativeWindowsPane) return 'write'
if (s.tmuxBacked) return this.tmuxPath ? 'tmux' : 'none'
diff --git a/src/core/pty-session-host-watch-zellij.test.ts b/src/core/pty-session-host-watch-zellij.test.ts
new file mode 100644
index 000000000..9f857e896
--- /dev/null
+++ b/src/core/pty-session-host-watch-zellij.test.ts
@@ -0,0 +1,101 @@
+// A POSIX machine with NO tmux: the session host is eligible, but a node may live in Zellij instead.
+// A join-only create (hosted-relay viewer) whose session the host does NOT have must fall through to
+// the existing join decision — which reaches a LIVE Zellij session — rather than being refused by the
+// session-host watch probe before Zellij is ever asked (review of the win-10-live-links package).
+import fs from 'fs'
+import path from 'path'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { initPlatform, resetPlatformForTests } from './platform'
+import { fakePlatform } from './platform-fake'
+import { DEFAULT_SETTINGS, type Settings } from '../shared/types'
+import { testTmpDir } from './test-tmp'
+
+const h = vi.hoisted(() => ({
+ spawns: [] as Array<{ file: string; args: string[] }>,
+ hasSession: vi.fn(async (_name: string): Promise<boolean> => false),
+ supportsWatch: vi.fn(async (): Promise<boolean> => true),
+ watch: vi.fn()
+}))
+
+vi.mock('./session-host-backend', async () => ({
+ ...(await import('./__fixtures__/no-session-host')).noSessionHost(),
+ sessionHostSupported: () => true,
+ sessionHostHasSession: h.hasSession,
+ sessionHostSupportsWatch: h.supportsWatch,
+ watchExistingSessionHostPty: h.watch
+}))
+vi.mock('./pty-devices', async (importOriginal) => ({
+ ...(await importOriginal<typeof import('./pty-devices')>()),
+ readPtyDevices: () => ({ ceiling: 511, inUse: 8 })
+}))
+vi.mock('node-pty', () => ({
+ spawn: (file: string, args: string[]) => {
+ h.spawns.push({ file, args })
+ return {
+ onData: () => ({ dispose() {} }),
+ onExit: () => ({ dispose() {} }),
+ write: () => {},
+ resize: () => {},
+ pause: () => {},
+ resume: () => {},
+ kill: () => {},
+ pid: 4321
+ }
+ }
+}))
+
+let dir: string
+let userData: string
+let savedSockDir: string | undefined
+
+beforeEach(() => {
+ h.spawns.length = 0
+ h.hasSession.mockReset().mockResolvedValue(false)
+ h.supportsWatch.mockReset().mockResolvedValue(true)
+ h.watch.mockReset()
+ dir = testTmpDir('shzfold-')
+ userData = path.join(dir, 'ud')
+ fs.mkdirSync(userData)
+ savedSockDir = process.env.ZELLIJ_SOCKET_DIR
+ process.env.ZELLIJ_SOCKET_DIR = path.join(dir, 's')
+ initPlatform(fakePlatform({ userDataDir: userData }))
+})
+afterEach(() => {
+ if (savedSockDir === undefined) delete process.env.ZELLIJ_SOCKET_DIR
+ else process.env.ZELLIJ_SOCKET_DIR = savedSockDir
+ resetPlatformForTests()
+})
+
+function liveZellij(): string {
+ const file = path.join(dir, 'zellij-live')
+ fs.writeFileSync(
+ file,
+ '#!/bin/sh\n' +
+ 'case "$1" in list-sessions) echo "nt-z1 [Created 1s ago]"; exit 0;; esac\n' +
+ 'case "$*" in *list-panes*) echo \'[{"id":0,"is_plugin":false,"is_focused":true}]\'; exit 0;; esac\n' +
+ 'exit 0\n',
+ { mode: 0o755 }
+ )
+ return file
+}
+
+describe('session-host watch probe on a POSIX machine without tmux', () => {
+ it.skipIf(process.platform === 'win32')(
+ 'a viewer of a LIVE Zellij node the host does not have is not refused by the host probe',
+ async () => {
+ const bin = liveZellij()
+ const { PtyManager } = await import('./pty-manager')
+ const m = new PtyManager({ zellijBin: bin })
+ ;(m as unknown as { getSettings: () => Settings }).getSettings = () => ({
+ ...DEFAULT_SETTINGS,
+ sessionBackend: 'zellij'
+ })
+ ;(m as unknown as { tmuxPath: string | null }).tmuxPath = null
+ const r = await m.createHeadless({ cols: 80, rows: 24, persistKey: 'z1', joinOnly: true, sizeVote: false })
+ expect(h.hasSession).toHaveBeenCalled()
+ expect(h.watch).not.toHaveBeenCalled()
+ expect(r.unavailable).toBeUndefined()
+ expect(h.spawns.at(-1)?.file).toBe(bin)
+ }
+ )
+})