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(pairing): revoke a legacy device's row too, and stop claiming it cannot exist

enes9fd4a41fb94f
diff --git a/src/main/pairing-revoke.test.ts b/src/main/pairing-revoke.test.ts
index 3c3133302..fd702dea2 100644
--- a/src/main/pairing-revoke.test.ts
+++ b/src/main/pairing-revoke.test.ts
@@ -192,15 +192,19 @@ describe('createPairingService().revokeDevice', () => {
expect(authKeys()).toBe(`${KEY_OTHER}\n`)
})
- it('skips the server when the device predates relayDeviceId (nothing we can name)', async () => {
+ // A device paired before `relayDeviceId` was recorded is the population this whole task exists
+ // to protect, and skipping it was a real leak: when the phone sent no id of its own, the mint
+ // keyed the row on OUR per-pairing id — the same value `revokeDevice` is called with — so the
+ // row can be named after all. (That id is a randomUUID per pairing, never this desktop's own
+ // `getDeviceId()`, which is not a key in relay_devices at all.)
+ it('falls back to our own id for a device paired before relayDeviceId was recorded', async () => {
seed(undefined)
const fetchMock = vi.fn(async () => ({ ok: true, status: 204 }))
vi.stubGlobal('fetch', fetchMock)
const service = createPairingService(relayDeps('TOKEN'))
- expect(await service.revokeDevice('dev-a')).toEqual({ local: true, server: 'skipped' })
- // Falling back to our own id would ask the backend about a row that cannot exist.
- expect(fetchMock).not.toHaveBeenCalled()
+ expect(await service.revokeDevice('dev-a')).toEqual({ local: true, server: 'ok' })
+ expect(fetchBody(fetchMock)).toEqual({ deviceId: 'dev-a', entitlement: 'TOKEN' })
expect(deviceIds()).toEqual([])
})
@@ -249,6 +253,9 @@ describe('createPairingService().revokeDevice', () => {
expect(fetchBody(fetchMock)).toEqual({ deviceId: 'phone-relay-1', entitlement: 'TOKEN' })
})
+ // The fallback above is licensed by there BEING a device — an id that names no pairing names no
+ // row either, and asking about it would be a request we cannot justify (and a 204 we would then
+ // report as 'ok').
it('skips the server for an id that is not in the registry', async () => {
const fetchMock = vi.fn()
vi.stubGlobal('fetch', fetchMock)
diff --git a/src/main/pairing-service.ts b/src/main/pairing-service.ts
index 9b319401c..a833953b5 100644
--- a/src/main/pairing-service.ts
+++ b/src/main/pairing-service.ts
@@ -131,7 +131,7 @@ const REVOKE_TIMEOUT_MS = 8000
* verify) or could not reach the server. The caller must NOT report a clean removal.
* - 'skipped' we did not ask, and that is a normal state: a free-tier desktop holds no
* entitlement to sign the request with (and has no Pro of ours on that phone to
- * reclaim), and a device paired before `relayDeviceId` existed has no row we can name.
+ * reclaim), or there is no device (and so no row) to name at all.
*
* `relayDeviceId` is phone-supplied, unvalidated text, so it rides the JSON body — never a URL.
*/
@@ -721,28 +721,48 @@ export function createPairingService(relayDeps?: PairingRelayDeps): PairingServi
// entitlement is what authorizes the server leg, not the local write's success, and a phone the
// user asked to remove should stop being minted Pro either way.
const revokeDevice = async (id: string): Promise<DeviceRevokeResult> => {
- const { local, relayId } = await serialize(async () => {
- const relayId = readDevices(await readAgentJson()).find((d) => d.id === id)?.relayDeviceId
+ const { local, relayId, found } = await serialize(async () => {
+ const entry = readDevices(await readAgentJson()).find((d) => d.id === id)
+ const relayId = entry?.relayDeviceId
+ const found = !!entry
try {
await removeAuthorizedKeysForDevice(id)
const obj = await readAgentJson()
const devices = removeDevice(readDevices(obj), id)
await writeAgentJson({ ...obj, devices })
- return { local: true, relayId }
+ return { local: true, relayId, found }
} catch (err) {
// Reported, not thrown: `local:false` is what the UI turns into "try again", and the
// server leg below is still worth running. The detail belongs in the log.
console.warn('[pairing] local revoke failed:', err)
- return { local: false, relayId }
+ return { local: false, relayId, found }
}
})
+ // A device paired before `relayDeviceId` was recorded still falls back to OUR id — which is
+ // not a guess. `id` is the per-pairing `randomUUID()` above, and when the phone sent no id of
+ // its own the mint sent exactly this value as the row's `deviceId` (see `phoneDeviceId`), so
+ // the row really is keyed on it. It is NOT this desktop's machine id (`getDeviceId()`), which
+ // is never a key in `relay_devices` — it lives only in the non-key `host_device_id` column,
+ // and /v1/relay/host-token writes no row at all — so this cannot reach the desktop's own
+ // registration. Nor can it reach a stranger's: the route authorizes by the row's licenseId /
+ // hostDeviceId and answers 403 otherwise, and 204 (no write) for a row carrying a
+ // 'free:'/'apple:' id — which is what keeps an Apple purchase bridged to this desktop safe.
+ //
+ // RESIDUAL LEAK, deliberately not closed here: a pre-Task-12 pairing where the phone DID send
+ // its own id (every iOS build since 2026-07-10 does) has a row keyed by a value we never
+ // recorded, and the backend's 204 reveals nothing — so this reports 'ok' having asked about a
+ // row that is not that phone's, and the phone keeps Pro. The desktop cannot name that row at
+ // all; re-pairing the phone records its id (the phone's id is stable and the mint upserts on
+ // it), after which a removal revokes for real. Closing it properly needs a
+ // server-side "devices for this host" read, which does not exist yet.
+ //
// Deliberately OUTSIDE the mutation chain: this is a network round trip, and holding the
// agent.json/authorized_keys queue open for it would stall a concurrent pairing POST behind
// an unreachable backend. No local state depends on the answer.
- const server = relayId
+ const server = found
? await revokeRelayDevice(
relayDeps?.apiBase ?? '',
- relayId,
+ relayId ?? id,
relayDeps?.getEntitlement() ?? null
)
: 'skipped'
diff --git a/src/renderer/components/settings/sections/PhoneSection.revoke.test.tsx b/src/renderer/components/settings/sections/PhoneSection.revoke.test.tsx
index 11f4d0fab..da9b53336 100644
--- a/src/renderer/components/settings/sections/PhoneSection.revoke.test.tsx
+++ b/src/renderer/components/settings/sections/PhoneSection.revoke.test.tsx
@@ -25,10 +25,16 @@ let root: Root
let host: HTMLElement
let revokeDevice: ReturnType<typeof vi.fn>
-/** The narrow slice of `window.nodeTerminal` this section touches on mount + revoke. */
+/**
+ * The narrow slice of `window.nodeTerminal` this section touches on mount + revoke. A successful
+ * local leg really does empty the list (the ordinary case: one paired phone), because that is what
+ * the note has to survive — it renders beside a list that no longer has a row.
+ */
function stubBridge(result: DeviceRevokeResult | Error): void {
+ let devices: PairedDevice[] = [DEVICE]
revokeDevice = vi.fn(async () => {
if (result instanceof Error) throw result
+ if (result.local) devices = []
return result
})
;(window as unknown as { nodeTerminal: unknown }).nodeTerminal = {
@@ -38,7 +44,7 @@ function stubBridge(result: DeviceRevokeResult | Error): void {
onDone: vi.fn(() => () => undefined),
probeSsh: vi.fn(async () => true),
openRemoteLoginSettings: vi.fn(),
- listDevices: vi.fn(async () => [DEVICE]),
+ listDevices: vi.fn(async () => devices),
revokeDevice
},
remoteHost: { setPhoneAccess: vi.fn() },
@@ -131,6 +137,32 @@ describe('PhoneSection revoke feedback', () => {
expect(text).not.toMatch(/Pro access/i)
})
+ // The ordinary case is ONE paired phone, so the successful local leg empties the list — and the
+ // warning has to outlive it. A note rendered inside the list's non-empty branch would vanish at
+ // exactly the moment it is needed.
+ it('keeps the server warning visible after the last device leaves the list', async () => {
+ stubBridge({ local: true, server: 'failed' })
+ mount()
+ await act(async () => undefined)
+
+ const text = await revokeFlow()
+ expect(text).toContain('No devices paired yet')
+ expect(text).toMatch(/Pro access/i)
+ })
+
+ it('reports BOTH legs when both fail', async () => {
+ stubBridge({ local: false, server: 'failed' })
+ mount()
+ await act(async () => undefined)
+
+ const text = await revokeFlow()
+ expect(text).toMatch(/Couldn’t remove/i)
+ expect(text).toMatch(/Pro access/i)
+ // The device is still on this machine, so the "Removed … from this machine" clause must not
+ // appear beside the failure that says it was not removed.
+ expect(text).not.toMatch(/Removed “/)
+ })
+
it('warns when the call itself never answered', async () => {
stubBridge(new Error('E_UNSUPPORTED'))
mount()
diff --git a/src/renderer/components/settings/sections/PhoneSection.tsx b/src/renderer/components/settings/sections/PhoneSection.tsx
index 4aff2a301..634d98e5b 100644
--- a/src/renderer/components/settings/sections/PhoneSection.tsx
+++ b/src/renderer/components/settings/sections/PhoneSection.tsx
@@ -86,17 +86,24 @@ export function PhoneSection({ isActive }: { isActive: boolean }): React.JSX.Ele
setRevokeNote('')
try {
const result = await window.nodeTerminal.pairing.revokeDevice(device.id)
+ // Additive, not exclusive: both legs can fail at once (an unwritable ~/.ssh while offline),
+ // and being told only half of that leaves the other half to be discovered by accident.
+ const notes: string[] = []
if (!result.local) {
- setRevokeNote(`Couldn’t remove “${device.name}” from this machine — try again.`)
- } else if (result.server === 'failed') {
- // Not "try again" on its own: the row is already gone from the list, so there is no button
- // left to press. Name the one thing that does re-run the server leg.
- setRevokeNote(
- `Removed “${device.name}” from this machine, but its Pro access couldn’t be revoked, ` +
- 'so that phone may keep Pro. Once this machine is back online, pair it and remove it ' +
- 'again to try again.'
+ notes.push(`Couldn’t remove “${device.name}” from this machine — try again.`)
+ }
+ if (result.server === 'failed') {
+ // Not a bare "try again": on a successful local removal the row is already gone from the
+ // list, so there is no button left to press. Name the one thing that does re-run the
+ // server leg — the phone sends the same stable device id every time it pairs, and the
+ // backend upserts the row on that id, so pairing again makes the next Revoke land.
+ notes.push(
+ (result.local ? `Removed “${device.name}” from this machine, but its` : 'Its') +
+ ' Pro access couldn’t be revoked, so that phone may keep Pro. Once this machine is' +
+ ' back online, pair it and remove it again to try again.'
)
}
+ setRevokeNote(notes.join(' '))
} catch {
// The call itself never got an answer (main is gone, or the surface doesn't support it).
setRevokeNote(`Couldn’t remove “${device.name}” — try again.`)
diff --git a/src/shared/types.ts b/src/shared/types.ts
index bec2458a2..49a96249f 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -2317,8 +2317,12 @@ export interface PairedDevice {
* The server leg of a device revoke — three states, because two cannot tell the truth apart.
* 'ok' = the backend confirmed; 'failed' = we asked and were refused or could not reach it;
* 'skipped' = we did not ask and that is fine (no entitlement to sign with — a free-tier desktop
- * has no Pro of ours on that phone to reclaim — or no relay device id to name). Only 'failed' is
- * a warning: reporting 'skipped' as a failure would tell a free user their phone's Pro is stuck.
+ * has no Pro of ours on that phone to reclaim — or no such device to name). Only 'failed' is a
+ * warning: reporting 'skipped' as a failure would tell a free user their phone's Pro is stuck.
+ *
+ * 'ok' is the backend's 204, which is idempotent and reveals nothing about WHICH row it applied
+ * to — see the residual-leak note on `revokeDevice` in main/pairing-service.ts before treating it
+ * as proof that a particular phone lost Pro.
*/
export type DeviceRevokeServerOutcome = 'ok' | 'failed' | 'skipped'