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(transcripts): never read a remote node's transcript from this machine

review0c5fc5fb23dc
diff --git a/src/core/transcript-ipc.test.ts b/src/core/transcript-ipc.test.ts
index 56ccf7535..893d485f1 100644
--- a/src/core/transcript-ipc.test.ts
+++ b/src/core/transcript-ipc.test.ts
@@ -446,7 +446,8 @@ describe('registerTranscriptIpc — paged chat reads', () => {
messages: [],
found: false,
olderCursor: null,
- unmatchedResults: []
+ unmatchedResults: [],
+ unreadable: true
})
})
@@ -483,7 +484,8 @@ describe('registerTranscriptIpc — paged chat reads', () => {
messages: [],
found: false,
olderCursor: null,
- unmatchedResults: []
+ unmatchedResults: [],
+ unreadable: true
})
})
@@ -496,3 +498,29 @@ describe('registerTranscriptIpc — paged chat reads', () => {
})
})
})
+
+describe('readChatTranscript — remoteOnly (a node the host KNOWS is remote)', () => {
+ it('never takes the local leg when the remote leg cannot resolve it (unmounted SSH node)', async () => {
+ writeTranscript(lines(assistantLine('the LOCAL machine')))
+ const pathFor = vi.fn(() => undefined)
+ for (const readRemotePage of [async () => null, undefined]) {
+ const res = await readChatTranscript(
+ { sessionId: SID, cwd: CWD, nodeId: 'nt-1', agentId: 'claude', remoteOnly: true },
+ {},
+ { pathFor, ...(readRemotePage ? { readRemotePage } : {}) }
+ )
+ expect(res).toEqual({ messages: [], found: false, olderCursor: null, unmatchedResults: [], unreadable: true })
+ }
+ expect(pathFor).not.toHaveBeenCalled()
+ })
+ it('a remote grok node is not read from this machine either', async () => {
+ const res = await readChatTranscript({ sessionId: SID, nodeId: 'nt-1', agentId: 'grok', remoteOnly: true }, {}, {})
+ expect(res).toMatchObject({ found: false, unreadable: true, messages: [] })
+ })
+ it('without remoteOnly a null remote leg still means "local session" (unchanged)', async () => {
+ writeTranscript(lines(assistantLine('local')))
+ const res = await readChatTranscript({ sessionId: SID, cwd: CWD, nodeId: 'nt-1' }, {}, { readRemotePage: async () => null })
+ expect(res.found).toBe(true)
+ expect(res.unreadable).toBeUndefined()
+ })
+})
diff --git a/src/core/transcript-ipc.ts b/src/core/transcript-ipc.ts
index d4e4fca3b..28cc7c8ed 100644
--- a/src/core/transcript-ipc.ts
+++ b/src/core/transcript-ipc.ts
@@ -36,6 +36,9 @@ export interface TranscriptQuery {
cwd: string | undefined
accountId: string | undefined
nodeId: string | undefined
+ /** The caller KNOWS this node is remote (from its own records, not from a live pty): the local
+ * resolver must never run, even when the remote leg cannot resolve the node. */
+ remoteOnly?: boolean
}
export interface TranscriptIpcDeps {
@@ -104,7 +107,7 @@ async function parseGrowingWindow(
if (!noCompleteLine || w.start === 0 || maxBytes >= CHAT_PAGE_MAX_BYTES) return { found: true, ...parsed }
maxBytes = Math.min(CHAT_PAGE_MAX_BYTES, maxBytes * CHAT_PAGE_GROWTH)
const next = await read({ before: page.before, maxBytes })
- if (!next) return notFoundPage()
+ if (!next) return unreadablePage()
w = next
}
}
@@ -116,6 +119,10 @@ const notFoundPage = (): ChatTranscriptResult => ({
unmatchedResults: []
})
+/** Not found BECAUSE it could not be read — the host did not answer, or a remote node has no
+ * reachable master. Distinct from "no transcript exists" for a caller that must say so. */
+const unreadablePage = (): ChatTranscriptResult => ({ ...notFoundPage(), unreadable: true })
+
/**
* A paged chat read (`chat:read-transcript` with its trailing `page` argument). Kept apart from the
* legacy branch so the unpaged result stays byte-for-byte what it was.
@@ -136,7 +143,7 @@ async function readChatPage(
if (readRemotePage) {
const remote = await readRemotePage(q, page)
if (remote !== null) {
- if (!remote.ok) return notFoundPage()
+ if (!remote.ok) return unreadablePage()
// A growth re-read that suddenly says "not remote" (null) is a failed read too — never a
// reason to go read THIS machine's disk halfway through a remote page.
return parseGrowingWindow(page, remote, async (p) => {
@@ -145,6 +152,10 @@ async function readChatPage(
})
}
}
+ // A node its caller KNOWS is remote (an SSH project's node, whether or not a pty is attached):
+ // "the remote leg could not resolve it" is a failed read, never "take THIS machine's disk" —
+ // that would answer from the wrong machine, or adopt a local transcript sharing its cwd.
+ if (q.remoteOnly) return unreadablePage()
const p = await resolveTranscript(q, deps.pathFor)
if (!p) return notFoundPage()
const w = await readChatWindow(p, page)
@@ -178,6 +189,9 @@ export interface ChatReadQuery {
accountId?: string
nodeId?: string
agentId?: string
+ /** See `TranscriptQuery.remoteOnly`. Honoured on the PAGED read (the only one the phone uses) and
+ * by grok's local-only reader; the legacy unpaged read ignores it. */
+ remoteOnly?: boolean
}
/**
@@ -191,7 +205,7 @@ export async function readChatTranscript(
rawPage: unknown,
deps: TranscriptIpcDeps
): Promise<ChatTranscriptResult> {
- const { sessionId, cwd, accountId, nodeId, agentId } = q
+ const { sessionId, cwd, accountId, nodeId, agentId, remoteOnly } = q
// Validated FIRST: it arrived over IPC / the WS bridge, and `before` reaches a remote shell
// line. `null` = no page asked for = the legacy read below, byte for byte.
const page = normalizeChatPage(rawPage)
@@ -201,6 +215,8 @@ export async function readChatTranscript(
// conversation. The remote leg is claude-only too (its reader tails claude's file), so a grok
// node is served locally or not at all rather than being handed the wrong host's claude log.
if (agentId === 'grok') {
+ // Grok is read locally only — a remote grok node's history is on the host.
+ if (remoteOnly) return page ? unreadablePage() : { messages: [], found: false }
const gp = sessionId ? await locateGrok(sessionId) : undefined
// Grok does NOT page: its history is small and its reader has no byte-offset keys, so a
// paged request gets the whole (capped) read with `olderCursor: null` — "nothing older to
@@ -212,7 +228,7 @@ export async function readChatTranscript(
? { messages: [], found: false, ...paging }
: { messages: chatMessagesFromGrok(buf), found: true, ...paging }
}
- if (page) return readChatPage({ sessionId, cwd, accountId, nodeId }, page, deps)
+ if (page) return readChatPage({ sessionId, cwd, accountId, nodeId, ...(remoteOnly ? { remoteOnly } : {}) }, page, deps)
const remote = deps.readRemote ? await deps.readRemote({ sessionId, cwd, accountId, nodeId }) : null
// A resolved-but-unreadable remote file is NOT "no conversation yet" — the read failed
// (master down, transcript gone), and the panel must be able to say so.
diff --git a/src/main/remote-transcript-page.test.ts b/src/main/remote-transcript-page.test.ts
index 767f7efed..54ebc3b6c 100644
--- a/src/main/remote-transcript-page.test.ts
+++ b/src/main/remote-transcript-page.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it, vi } from 'vitest'
-import { createReadRemotePage, forgetLocatedRef, rememberHookRef, type RemoteTranscriptRefCache } from './remote-transcript-page'
+import { createReadRemotePage, forgetLocatedRef, rememberHookRef, remoteTargetForNode, type RemoteTranscriptRefCache } from './remote-transcript-page'
import type { RemoteFileRef } from './remote-ssh/remote-file'
const ref = (path: string): RemoteFileRef => ({
@@ -76,3 +76,20 @@ describe('createReadRemotePage — the desktop remote leg of a paged chat read',
expect(c.located.has('sid')).toBe(false)
})
})
+
+describe('remoteTargetForNode (which master a remote transcript read goes over)', () => {
+ const live = { conn: { host: 'live' } as RemoteFileRef['conn'], controlPath: '/live' }
+ const proj = { conn: { host: 'proj' } as RemoteFileRef['conn'], controlPath: '/proj' }
+ it('the live pty session wins when there is one', () => {
+ expect(remoteTargetForNode('n', { live: () => live, projectIdFor: () => 'p', refForProject: () => proj })).toBe(live)
+ })
+ it('an UNMOUNTED SSH node resolves through its PROJECT\'s master', () => {
+ const refForProject = vi.fn(() => proj)
+ expect(remoteTargetForNode('n', { live: () => undefined, projectIdFor: () => 'p', refForProject })).toEqual(proj)
+ expect(refForProject).toHaveBeenCalledWith('p')
+ })
+ it('a local node (no project) or a disconnected project resolves nothing', () => {
+ expect(remoteTargetForNode('n', { live: () => undefined, projectIdFor: () => undefined, refForProject: () => proj })).toBeUndefined()
+ expect(remoteTargetForNode('n', { live: () => undefined, projectIdFor: () => 'p', refForProject: () => undefined })).toBeUndefined()
+ })
+})
diff --git a/src/main/remote-transcript-page.ts b/src/main/remote-transcript-page.ts
index 27579bd76..5ca43dbae 100644
--- a/src/main/remote-transcript-page.ts
+++ b/src/main/remote-transcript-page.ts
@@ -47,3 +47,21 @@ export function createReadRemotePage(deps: {
}
}
}
+
+/** Which ControlMaster a remote transcript read for `nodeId` goes over: the node's LIVE pty session
+ * when there is one (the exact master it spawned over), else its SSH PROJECT's master — an idle
+ * tab, or any node after a desktop restart, has no attached pty, and resolving only through the pty
+ * made such a node read as "not remote". `undefined` = a local node, or a project with no master. */
+export function remoteTargetForNode<T extends { conn: unknown; controlPath: string }>(
+ nodeId: string,
+ deps: {
+ live(nodeId: string): T | undefined
+ projectIdFor(nodeId: string): string | undefined
+ refForProject(projectId: string): T | undefined
+ }
+): T | undefined {
+ const live = deps.live(nodeId)
+ if (live) return live
+ const projectId = deps.projectIdFor(nodeId)
+ return projectId ? deps.refForProject(projectId) : undefined
+}
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 5e23be23b..f7c955e82 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -2887,6 +2887,10 @@ export interface ChatTranscriptResult {
model?: string
/** PAGED claude reads only: the newest assistant record's top-level `effort` in the window. */
effort?: string
+ /** PAGED reads only, with `found: false`: the transcript could not be READ (a remote host that did
+ * not answer, a growth re-read that failed, a remote node with no reachable master) — as opposed
+ * to "no transcript exists". Absent on every other result. */
+ unreadable?: true
}
/**