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(push): route a granted send under the grant of the event's OWN host (issue #435)

enes2088165010af
diff --git a/src/core/push-grants.ts b/src/core/push-grants.ts
index e9d594584..7490f65a4 100644
--- a/src/core/push-grants.ts
+++ b/src/core/push-grants.ts
@@ -25,6 +25,12 @@ export interface PushGrant {
grant: string
/** The phone's connection UUID, if the file carried one. */
connectionId?: string
+ /** The SSH host (`user@host`, `sshHostKey`) this grant was swept FROM, when it lives on a remote
+ * host rather than in this machine's own `~/.nodeterm/push-grants` (then absent). A grant
+ * authorizes pushes about the host it was dropped on and nothing else: the phone signs it for
+ * that host's connectionId, which is also the scope its per-host mute is keyed by — so the
+ * senders route a node's events to the grants of the node's OWN host (issue #435). */
+ host?: string
}
/** The slice of `fs` the loader needs — injectable so tests drive it without touching disk. */
diff --git a/src/core/push-notify.test.ts b/src/core/push-notify.test.ts
index 9886c9b0d..ec887c0df 100644
--- a/src/core/push-notify.test.ts
+++ b/src/core/push-notify.test.ts
@@ -617,10 +617,16 @@ describe('createPushNotify', () => {
h.stop()
})
- // The one overlap the desktop CAN see: the same phone dropped a grant on this Mac AND on an SSH
- // host it reaches (src/main's allPushGrants concatenates both lists), so the same deviceId shows
- // up twice with different tokens. First occurrence wins — main puts the local grants first.
- it('OVERLAP: two grants for the same deviceId collapse to ONE POST (first wins)', async () => {
+ // A grant authorizes pushes about the HOST it was dropped on — nothing else. src/main's
+ // allPushGrants concatenates this machine's grants with a sweep of every connected SSH host, so
+ // one phone that reached three hosts contributes three grants, each signed for a DIFFERENT
+ // connectionId (the phone's own saved-connection UUID for that host — exactly the scope its
+ // per-host mute is keyed by). Collapsing them per deviceId and posting every event under the
+ // survivor sent host B's events under host A's grant: the backend then consulted A's mute for
+ // B's event, and a host the user had turned OFF kept ringing the phone (issue #435, field
+ // report). Events are routed to the grants swept from THEIR host; a node with no host
+ // attribution (a local node, or the Server Edition) goes to this machine's own grants.
+ it('PER-HOST: an event routes ONLY to the grants swept from the host its node lives on', async () => {
const em = makeEmitter()
const h = createPushNotify(
baseDeps({
@@ -628,7 +634,68 @@ describe('createPushNotify', () => {
getHostIdentity: () => null,
getGrants: () => [
{ deviceId: 'dev-A', grant: 'tok-local' },
- { deviceId: 'dev-A', grant: 'tok-remote' },
+ { deviceId: 'dev-A', grant: 'tok-h1', host: 'u@h1' },
+ { deviceId: 'dev-A', grant: 'tok-h2', host: 'u@h2' },
+ { deviceId: 'dev-B', grant: 'tok-h2-B', host: 'u@h2' }
+ ],
+ grantHostFor: (nodeId) => ({ a: 'u@h1', b: 'u@h2' })[nodeId],
+ hostLabel: () => 'niova'
+ })
+ )
+ em.emit(iev({ nodeId: 'a', title: 'A' }))
+ em.emit(iev({ nodeId: 'b', title: 'B' }))
+ em.emit(iev({ nodeId: 'c', title: 'C' })) // no attribution → local
+ await vi.advanceTimersByTimeAsync(2000)
+ const sent = fetchMock.mock.calls.map((c) => [
+ c[1].headers.authorization,
+ JSON.parse(c[1].body).events.map((e: { title: string }) => e.title)
+ ])
+ expect(sent).toEqual(
+ expect.arrayContaining([
+ ['Bearer tok-h1', ['A']],
+ ['Bearer tok-h2', ['B']],
+ ['Bearer tok-h2-B', ['B']],
+ ['Bearer tok-local', ['C']]
+ ])
+ )
+ expect(sent).toHaveLength(4)
+ h.stop()
+ })
+
+ it('PER-HOST: a phone holding grants on two hosts gets ONE push per event, under the right host', async () => {
+ const em = makeEmitter()
+ const h = createPushNotify(
+ baseDeps({
+ subscribe: em.subscribe,
+ getHostIdentity: () => null,
+ getGrants: () => [
+ { deviceId: 'dev-A', grant: 'tok-h1', host: 'u@h1' },
+ { deviceId: 'dev-A', grant: 'tok-h2', host: 'u@h2' }
+ ],
+ grantHostFor: () => 'u@h2',
+ hostLabel: () => 'niova'
+ })
+ )
+ em.emit(iev({ nodeId: 'a', title: 'A' }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(fetchMock).toHaveBeenCalledTimes(1)
+ expect(fetchMock.mock.calls[0][1].headers.authorization).toBe('Bearer tok-h2')
+ h.stop()
+ })
+
+ // Without any host attribution (the Server Edition: one machine, its own grant dir) every
+ // grant is local and every event is local — the pre-existing fan-out, unchanged. Two files
+ // for one device cannot exist in one dir (the filename IS the deviceId), so the within-host
+ // first-wins dedupe is defensive only.
+ it('no grantHostFor (Server Edition): every event goes to every local grant, first-wins per device', async () => {
+ const em = makeEmitter()
+ const h = createPushNotify(
+ baseDeps({
+ subscribe: em.subscribe,
+ getHostIdentity: () => null,
+ getGrants: () => [
+ { deviceId: 'dev-A', grant: 'tok-A' },
+ { deviceId: 'dev-A', grant: 'tok-A-dup' },
{ deviceId: 'dev-B', grant: 'tok-B' }
],
hostLabel: () => 'niova'
@@ -636,14 +703,33 @@ describe('createPushNotify', () => {
)
em.emit(iev({ nodeId: 'a', title: 'A' }))
await vi.advanceTimersByTimeAsync(2000)
- expect(fetchMock).toHaveBeenCalledTimes(2)
expect(fetchMock.mock.calls.map((c) => c[1].headers.authorization)).toEqual([
- 'Bearer tok-local',
+ 'Bearer tok-A',
'Bearer tok-B'
])
h.stop()
})
+ // A remote node's event must NEVER fall back to this machine's grants: a grant dropped here
+ // authorizes pushes about this machine only, and a phone that only reaches host h1 has no
+ // connection to open a "local" event with anyway.
+ it('PER-HOST: a remote node with no grant on its host is dropped from the granted leg', async () => {
+ const em = makeEmitter()
+ const h = createPushNotify(
+ baseDeps({
+ subscribe: em.subscribe,
+ getHostIdentity: () => null,
+ getGrants: () => [{ deviceId: 'dev-A', grant: 'tok-local' }],
+ grantHostFor: () => 'u@h1',
+ hostLabel: () => 'niova'
+ })
+ )
+ em.emit(iev({ nodeId: 'a', title: 'A' }))
+ await vi.advanceTimersByTimeAsync(2000)
+ expect(fetchMock).not.toHaveBeenCalled()
+ h.stop()
+ })
+
it('NEITHER (no paired phone, no grants) → inert', async () => {
const em = makeEmitter()
const h = createPushNotify(
@@ -1447,19 +1533,29 @@ describe('createLiveUpdatePush', () => {
h.stop()
})
- it('OVERLAP: two grants for the same deviceId collapse to ONE POST (first wins)', async () => {
+ // Same per-host routing as notify (issue #435): a Live Activity update about a node on host h2
+ // goes ONLY under h2's grant — never under another host's, whose connectionId names a host the
+ // phone may have muted, and whose card the phone would then attribute to the wrong connection.
+ it('PER-HOST: an update routes ONLY to the grants swept from the host its node lives on', async () => {
const { h, st } = wire({
getHostIdentity: () => null,
getGrants: () => [
{ deviceId: 'dev-A', grant: 'tok-local' },
- { deviceId: 'dev-A', grant: 'tok-remote' }
+ { deviceId: 'dev-A', grant: 'tok-h1', host: 'u@h1' },
+ { deviceId: 'dev-A', grant: 'tok-h2', host: 'u@h2' }
],
+ grantHostFor: (nodeId) => ({ a: 'u@h2' })[nodeId],
hostLabel: () => 'niova'
})
st.emit({ nodeId: 'a', event: 'start', state: 'working', ts: 1 })
+ st.emit({ nodeId: 'c', event: 'start', state: 'working', ts: 2 }) // unattributed → local
await vi.advanceTimersByTimeAsync(1000)
- expect(fetchMock).toHaveBeenCalledTimes(1)
- expect(fetchMock.mock.calls[0][1].headers.authorization).toBe('Bearer tok-local')
+ const sent = fetchMock.mock.calls.map((c) => [
+ c[1].headers.authorization,
+ JSON.parse(c[1].body).updates.map((u: { nodeId: string }) => u.nodeId)
+ ])
+ expect(sent).toEqual(expect.arrayContaining([['Bearer tok-h2', ['a']], ['Bearer tok-local', ['c']]]))
+ expect(sent).toHaveLength(2)
h.stop()
})
diff --git a/src/core/push-notify.ts b/src/core/push-notify.ts
index 0af726a10..fe983c78f 100644
--- a/src/core/push-notify.ts
+++ b/src/core/push-notify.ts
@@ -86,26 +86,53 @@ interface SendTarget {
}
/**
- * One POST per DEVICE, not per grant FILE.
+ * One POST per (host, device), not per grant FILE.
*
* `src/main`'s `allPushGrants` concatenates this machine's `~/.nodeterm/push-grants` with a sweep of
- * every connected SSH host, and one phone that reached two of them dropped a DIFFERENT token on
- * each — so the same `deviceId` can appear twice in the merged list and would earn that phone two
- * notifications for one event. (`remote-push-grants`'s cache dedupes only within its own half.)
- * First occurrence wins, which is why main puts the local grants first; a 401/403 on the survivor
- * marks it dead and the next send promotes the other, the same self-healing the remote cache does.
+ * every connected SSH host, so one phone that reached several of them appears several times — once
+ * per host, with a DIFFERENT token each time. Those are not duplicates: each token is signed for
+ * the phone's connectionId for THAT host, which is also the scope its per-host mute is keyed by.
+ * This used to collapse them per deviceId ("first occurrence wins") and post every event under the
+ * survivor, so host B's events went out under host A's grant and the backend consulted A's mute for
+ * a B event — a host the user had turned OFF kept ringing the phone (issue #435). Events are now
+ * routed per host (`grantsFor` / `groupByGrantHost`); within one host a device has exactly one file
+ * (the filename is the deviceId), so the first-wins here is defensive only.
*/
-function dedupeGrantsByDevice(grants: readonly PushGrant[]): PushGrant[] {
+function dedupeGrants(grants: readonly PushGrant[]): PushGrant[] {
const seen = new Set<string>()
const out: PushGrant[] = []
for (const g of grants) {
- if (seen.has(g.deviceId)) continue
- seen.add(g.deviceId)
+ const key = `${g.host ?? ''}\u0000${g.deviceId}`
+ if (seen.has(key)) continue
+ seen.add(key)
out.push(g)
}
return out
}
+/** The grants that may carry an event about `host` (undefined = a node on THIS machine): exactly
+ * the ones swept from that host. A grant dropped here never carries a remote node's event, and a
+ * remote host's grant never carries another host's — the phone signed each for one host. */
+function grantsFor(grants: readonly PushGrant[], host: string | undefined): PushGrant[] {
+ return grants.filter((g) => (g.host ?? undefined) === host)
+}
+
+/** Bucket a batch by the host each item's node lives on. Without a `hostOf` resolver (the Server
+ * Edition: one machine, its own grant dir) everything is local — one bucket, the legacy fan-out. */
+function groupByGrantHost<T extends { nodeId: string }>(
+ items: readonly T[],
+ hostOf: ((nodeId: string) => string | undefined) | undefined
+): Map<string | undefined, T[]> {
+ const out = new Map<string | undefined, T[]>()
+ for (const it of items) {
+ const host = hostOf ? hostOf(it.nodeId) : undefined
+ const bucket = out.get(host)
+ if (bucket) bucket.push(it)
+ else out.set(host, [it])
+ }
+ return out
+}
+
/**
* The single targeting rule, shared by BOTH senders (`createPushNotify` and `createLiveUpdatePush`
* each had their own copy of it, and a copy is a thing that drifts). The per-sender gates — the
@@ -134,6 +161,12 @@ function dedupeGrantsByDevice(grants: readonly PushGrant[]): PushGrant[] {
* knowable — either the backend does it (it sees the relay device row AND the grant's deviceId, so
* it is the only party holding both halves) or the desktop starts persisting the phone's deviceId
* beside its pinned pubkey at pair time. Both are protocol changes, not a filter we can add here.
+ *
+ * **The grants are the whole list, tagged by host — the SPLIT happens at send time.** The relay leg
+ * carries every event under this machine's identity (the backend has no other host identity to
+ * check a per-host mute against — see the known gap in the PR). The granted leg is per host: each
+ * event goes only under the grants swept from the host its node lives on (`grantHostFor`), because
+ * a grant is signed for that one host's connectionId and the phone's mute is keyed by exactly that.
*/
function resolveSendTarget(
getHostIdentity: () => PushHostIdentity | null,
@@ -142,7 +175,7 @@ function resolveSendTarget(
const id = getHostIdentity()
// The paired-phone gate is host-mode only — a grant IS the phone's opt-in.
const host = id && id.hasPairedPhone ? id : null
- const grants = dedupeGrantsByDevice(getGrants?.() ?? [])
+ const grants = dedupeGrants(getGrants?.() ?? [])
if (!host && grants.length === 0) return null
return { host, grants }
}
@@ -189,6 +222,13 @@ export interface PushNotifyDeps {
getGrants?: () => PushGrant[]
/** Mark a grant dead after a 401/403 (dropped until its file changes). Paired with `getGrants`. */
markGrantDead?: (grant: string) => void
+ /** The SSH host (`sshHostKey`, `user@host`) a node's project lives on, or undefined for a node on
+ * THIS machine. Drives the granted leg's per-host routing: an event goes only under the grants
+ * swept from its node's host (`PushGrant.host`), never under another host's — each grant is
+ * signed for one host's connectionId, the scope the phone's per-host mute is keyed by (issue
+ * #435). Absent (the Server Edition) ⇒ every node is local and every grant is local: the legacy
+ * fan-out. In production this is `workspaceStore.sshProjectIdForNode` → the project's host key. */
+ grantHostFor?: (nodeId: string) => string | undefined
/** `os.hostname()`, passed in to keep core pure — the granted-mode `hostLabel` (a granted send
* carries no host identity, so this is the only host label the backend sees). */
hostLabel?: () => string
@@ -375,17 +415,21 @@ export function createPushNotify(deps: PushNotifyDeps): PushNotifyHandle {
})
}
// …and the grants, in the SAME flush (see resolveSendTarget: a paired phone must not silence
- // the SSH-only ones). One POST per live grant, Bearer-authorized, NO host identity fields —
- // just `hostLabel` (os.hostname(), injected). A 401/403 marks that grant dead.
+ // the SSH-only ones). PER HOST: each event goes only under the grants swept from the host its
+ // node lives on — a grant is signed for that one host's connectionId, which is what the phone's
+ // per-host mute is keyed by (issue #435). One POST per live grant, Bearer-authorized, NO host
+ // identity fields — just `hostLabel` (os.hostname(), injected). A 401/403 marks that grant dead.
const label = deps.hostLabel?.()
- for (const g of target.grants) {
- const res = await postJson(
- fetchImpl,
- url,
- { ...(label ? { hostLabel: label } : {}), events },
- g.grant
- )
- if (res && (res.status === 401 || res.status === 403)) deps.markGrantDead?.(g.grant)
+ for (const [host, group] of groupByGrantHost(events, deps.grantHostFor)) {
+ for (const g of grantsFor(target.grants, host)) {
+ const res = await postJson(
+ fetchImpl,
+ url,
+ { ...(label ? { hostLabel: label } : {}), events: group },
+ g.grant
+ )
+ if (res && (res.status === 401 || res.status === 403)) deps.markGrantDead?.(g.grant)
+ }
}
}
@@ -490,6 +534,9 @@ export interface LiveUpdateDeps {
getGrants?: () => PushGrant[]
/** Mark a grant dead after a 401/403 (dropped until its file changes). Paired with `getGrants`. */
markGrantDead?: (grant: string) => void
+ /** See the identical field on `PushNotifyDeps`: the node → SSH host resolver behind the granted
+ * leg's per-host routing. Absent ⇒ every node and every grant is local. */
+ grantHostFor?: (nodeId: string) => string | undefined
/** `os.hostname()`, passed in to keep core pure — the granted-mode `hostLabel`. */
hostLabel?: () => string
/** The `settings.mobilePushEnabled` master switch. */
@@ -713,17 +760,20 @@ export function createLiveUpdatePush(deps: LiveUpdateDeps): LiveUpdateHandle {
updates
})
}
- // …and the grants, in the SAME flush (see resolveSendTarget). One POST per live grant,
+ // …and the grants, in the SAME flush (see resolveSendTarget), PER HOST exactly like notify:
+ // an update goes only under the grants swept from its node's host. One POST per live grant,
// Bearer-authorized, NO host identity fields.
const label = deps.hostLabel?.()
- for (const g of target.grants) {
- const res = await postJson(
- fetchImpl,
- url,
- { ...(label ? { hostLabel: label } : {}), updates },
- g.grant
- )
- if (res && (res.status === 401 || res.status === 403)) deps.markGrantDead?.(g.grant)
+ for (const [host, group] of groupByGrantHost(updates, deps.grantHostFor)) {
+ for (const g of grantsFor(target.grants, host)) {
+ const res = await postJson(
+ fetchImpl,
+ url,
+ { ...(label ? { hostLabel: label } : {}), updates: group },
+ g.grant
+ )
+ if (res && (res.status === 401 || res.status === 403)) deps.markGrantDead?.(g.grant)
+ }
}
}
diff --git a/src/core/remote-push-grants.test.ts b/src/core/remote-push-grants.test.ts
index 60ba6123e..755f36f7a 100644
--- a/src/core/remote-push-grants.test.ts
+++ b/src/core/remote-push-grants.test.ts
@@ -13,6 +13,14 @@ const grantFile = (grant: string, connectionId?: string): string =>
JSON.stringify({ v: 1, grant, ...(connectionId ? { connectionId } : {}) })
describe('parseRemoteGrants', () => {
+ it('tags every grant with the host it was swept from, and leaves it untagged without one', () => {
+ const line = `phone\t${grantFile('tok', 'conn-1')}`
+ expect(parseRemoteGrants(line, 'u@host1')).toEqual([
+ { deviceId: 'phone', grant: 'tok', connectionId: 'conn-1', host: 'u@host1' }
+ ])
+ expect(parseRemoteGrants(line)).toEqual([{ deviceId: 'phone', grant: 'tok', connectionId: 'conn-1' }])
+ })
+
it('parses `<deviceId>\\t<json>` lines', () => {
const out = parseRemoteGrants(
`dev-a\t${grantFile('tok-a', 'conn-a')}\ndev-b\t${grantFile('tok-b')}\n`
@@ -47,27 +55,40 @@ describe('createRemoteGrantsCache', () => {
expect(createRemoteGrantsCache().get()).toEqual([])
})
- it('keeps ONE grant per device id — two hosts holding the same phone must not double-push', () => {
+ // One phone that reaches two hosts drops a DIFFERENT grant on each, each signed for that host's
+ // connectionId — the scope the phone's per-host mute is keyed by. Both must survive, tagged with
+ // their host, so push-notify can route a host's events under that host's grant (issue #435).
+ // Collapsing them per device here sent host 2's events under host 1's grant.
+ it('keeps every host\u2019s grant for one phone, each tagged with the host it came from', () => {
const c = createRemoteGrantsCache()
c.set([
- { deviceId: 'phone', grant: 'tok-host1' },
- { deviceId: 'phone', grant: 'tok-host2' },
- { deviceId: 'other', grant: 'tok-other' }
+ ...parseRemoteGrants(`phone\t${grantFile('tok-host1', 'conn-1')}`, 'u@host1'),
+ ...parseRemoteGrants(`phone\t${grantFile('tok-host2', 'conn-2')}\nother\t${grantFile('tok-other')}`, 'u@host2')
])
expect(c.get()).toEqual([
- { deviceId: 'phone', grant: 'tok-host1' },
- { deviceId: 'other', grant: 'tok-other' }
+ { deviceId: 'phone', grant: 'tok-host1', connectionId: 'conn-1', host: 'u@host1' },
+ { deviceId: 'phone', grant: 'tok-host2', connectionId: 'conn-2', host: 'u@host2' },
+ { deviceId: 'other', grant: 'tok-other', host: 'u@host2' }
+ ])
+ })
+
+ it('dedupes only WITHIN a host: the same device listed twice for one host keeps the first', () => {
+ const c = createRemoteGrantsCache()
+ c.set([
+ { deviceId: 'phone', grant: 'tok-a', host: 'u@host1' },
+ { deviceId: 'phone', grant: 'tok-b', host: 'u@host1' }
])
+ expect(c.get()).toEqual([{ deviceId: 'phone', grant: 'tok-a', host: 'u@host1' }])
})
- it('a 401 on the chosen token promotes the OTHER host’s grant for the same device', () => {
+ it('a 401 on one host\u2019s token drops that grant and leaves the other host\u2019s standing', () => {
const c = createRemoteGrantsCache()
c.set([
- { deviceId: 'phone', grant: 'tok-host1' },
- { deviceId: 'phone', grant: 'tok-host2' }
+ { deviceId: 'phone', grant: 'tok-host1', host: 'u@host1' },
+ { deviceId: 'phone', grant: 'tok-host2', host: 'u@host2' }
])
c.markDead('tok-host1')
- expect(c.get()).toEqual([{ deviceId: 'phone', grant: 'tok-host2' }])
+ expect(c.get()).toEqual([{ deviceId: 'phone', grant: 'tok-host2', host: 'u@host2' }])
})
it('a dead mark survives later sweeps while the token is still there', () => {
diff --git a/src/core/remote-push-grants.ts b/src/core/remote-push-grants.ts
index e13081662..b00f1c92e 100644
--- a/src/core/remote-push-grants.ts
+++ b/src/core/remote-push-grants.ts
@@ -44,8 +44,11 @@ const DEVICE_ID_MAX = 128
/**
* Parse the sweep's stdout into grants. Every malformed line is skipped silently: a partial write,
* a non-JSON file someone dropped in the directory, a schema-version bump, a truncated giant.
+ *
+ * `host` is the `sshHostKey` of the machine the listing came from; every grant is tagged with it so
+ * the senders can route a node's events to the grants of the node's own host (`PushGrant.host`).
*/
-export function parseRemoteGrants(stdout: string): PushGrant[] {
+export function parseRemoteGrants(stdout: string, host?: string): PushGrant[] {
const out: PushGrant[] = []
for (const line of stdout.split('\n')) {
const tab = line.indexOf('\t')
@@ -65,15 +68,16 @@ export function parseRemoteGrants(stdout: string): PushGrant[] {
out.push({
deviceId,
grant: rec.grant,
- ...(typeof rec.connectionId === 'string' ? { connectionId: rec.connectionId } : {})
+ ...(typeof rec.connectionId === 'string' ? { connectionId: rec.connectionId } : {}),
+ ...(host ? { host } : {})
})
}
return out
}
export interface RemoteGrantsCache {
- /** The live remote grants: dead-marked tokens dropped, then ONE per device id. Sync, so it can
- * sit behind `push-notify`'s `getGrants`. */
+ /** The live remote grants: dead-marked tokens dropped, then ONE per (host, device id). Sync, so
+ * it can sit behind `push-notify`'s `getGrants`. */
get(): PushGrant[]
/** Replace the cache with a completed sweep's result (all hosts). */
set(grants: readonly PushGrant[]): void
@@ -85,10 +89,16 @@ export interface RemoteGrantsCache {
/**
* The cache `src/main` refreshes on a timer and `push-notify` reads synchronously.
*
- * Device-id dedupe happens at READ time, after the dead filter, deliberately: one phone paired to
- * two hosts drops a different token on each, and pushing both would double every notification.
- * Picking the survivor after the dead filter means a 401 on the first host's (stale) token
- * promotes the other host's on the very next send — self-healing, no extra round-trip.
+ * Dedupe is per (host, device id), at READ time after the dead filter. It used to be per device id
+ * alone — one phone that reached two hosts dropped a different token on each, and "pushing both
+ * would double every notification". That was true only because every event was posted under every
+ * grant. Each of those tokens is signed for a DIFFERENT connectionId (the phone's saved connection
+ * for THAT host — the scope its per-host mute is keyed by), so collapsing them sent host 2's events
+ * under host 1's grant, and the backend consulted host 1's mute for a host 2 event: a host the user
+ * had turned OFF kept ringing (issue #435). Both grants now survive, tagged with their host, and
+ * `push-notify` routes each node's events to its own host's grant — one push per event, under the
+ * right identity. Within one host a device has exactly one file (the filename is the deviceId), so
+ * the per-host first-wins is defensive only.
*/
export function createRemoteGrantsCache(): RemoteGrantsCache {
let all: PushGrant[] = []
@@ -100,8 +110,9 @@ export function createRemoteGrantsCache(): RemoteGrantsCache {
const out: PushGrant[] = []
for (const g of all) {
if (dead.has(g.grant)) continue
- if (seen.has(g.deviceId)) continue
- seen.add(g.deviceId)
+ const key = `${g.host ?? ''}\u0000${g.deviceId}`
+ if (seen.has(key)) continue
+ seen.add(key)
out.push(g)
}
return out
diff --git a/src/main/index.ts b/src/main/index.ts
index 834844701..d21e7bfe6 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -2071,11 +2071,25 @@ app.whenReady().then(async () => {
// by a timer below; `get()` is sync so it can sit behind `getGrants`. See
// core/remote-push-grants.ts.
const remoteGrants = createRemoteGrantsCache()
- /** Local grants first (this machine's own phone), then the hosts'. ORDER MATTERS: one phone that
- * reached both this Mac and an SSH host dropped a different token on each, and push-notify's
- * `dedupeGrantsByDevice` keeps the FIRST occurrence per deviceId — so the local token, the one
- * that needs no host round-trip to stay fresh, is the survivor. */
+ /** This machine's own grants (untagged) plus every connected host's (tagged `host`). They are NOT
+ * collapsed per phone any more: one phone that reached both this Mac and an SSH host dropped a
+ * different token on each, each signed for its connectionId for THAT host, and push-notify routes
+ * a node's events to the grants of the node's own host (`grantHostFor` below). Collapsing them
+ * sent a remote host's events under another host's grant, past the phone's per-host mute
+ * (issue #435). */
const allPushGrants = (): PushGrant[] => [...pushGrants.get(), ...remoteGrants.get()]
+ /** The SSH host a node lives on, for the granted leg's per-host routing — or undefined for a
+ * local node. Resolved from the project's INDEX entry (`projectTargetInfo`), not the live
+ * connection: a remote node whose host is momentarily disconnected must still not fall back to
+ * "local" and ride out under this Mac's own grant. An ssh project with no resolvable host key
+ * gets a key that matches no grant, so its events are dropped from the granted leg rather than
+ * misattributed (the relay leg still carries them). */
+ const pushGrantHostFor = (nodeId: string): string | undefined => {
+ const projectId = workspaceStore.sshProjectIdForNode(nodeId)
+ if (!projectId) return undefined
+ const ssh = workspaceStore.projectTargetInfo(projectId)?.ssh
+ return ssh ? sshHostKey(ssh.server) : `ssh:${projectId}`
+ }
/** A 401/403 could be on either side's token; neither accessor knows the other's. */
const markPushGrantDead = (grant: string): void => {
pushGrants.markDead(grant)
@@ -2163,6 +2177,7 @@ app.whenReady().then(async () => {
// block comment above). resolveTarget keeps a single sender: host wins when paired.
getGrants: allPushGrants,
markGrantDead: markPushGrantDead,
+ grantHostFor: pushGrantHostFor,
hostLabel: () => hostname(),
mobilePushEnabled: () => settingsStore.get().mobilePushEnabled !== false,
mobilePushNeedsYou: () => settingsStore.get().mobilePushNeedsYou !== false,
@@ -2199,6 +2214,7 @@ app.whenReady().then(async () => {
: null,
getGrants: allPushGrants,
markGrantDead: markPushGrantDead,
+ grantHostFor: pushGrantHostFor,
hostLabel: () => hostname(),
mobilePushEnabled: () => settingsStore.get().mobilePushEnabled !== false,
mobileLiveActivities: () => settingsStore.get().mobileLiveActivities !== false,
diff --git a/src/main/remote-ssh/ssh-project.ts b/src/main/remote-ssh/ssh-project.ts
index c81536f1a..952aa10ec 100644
--- a/src/main/remote-ssh/ssh-project.ts
+++ b/src/main/remote-ssh/ssh-project.ts
@@ -1743,7 +1743,9 @@ export class SshProjectManager {
const { code, stdout } = await this.r.run(
childArgs(c.conn, c.controlPath, REMOTE_GRANT_SCAN_CMD)
)
- if (code === 0 && stdout) out.push(...parseRemoteGrants(stdout))
+ // Tagged with the host it came from: a grant authorizes pushes about THAT host only, and
+ // push-notify routes a node's events to its own host's grants (PushGrant.host).
+ if (code === 0 && stdout) out.push(...parseRemoteGrants(stdout, hk))
} catch {
// best-effort per host — a failed read just keeps the previous sweep's grants
}