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.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(relay): a key-proof refusal stops hosting only on the second in a row; desktop dialog drops rotate-key
review598e08165c15
diff --git a/src/core/relay/host-token.ts b/src/core/relay/host-token.tsindex 448e72e3e..c46e96dad 100644--- a/src/core/relay/host-token.ts+++ b/src/core/relay/host-token.ts@@ -7,11 +7,13 @@// longer mint this host's tokens. Only a challenge answered 404/405 means "this backend predates the// proof" and gets the legacy two-field mint; any other challenge failure is transient.//-// The desktop copy distinguishes only two outcomes: a terminal key-proof refusal (`{ refused }` —+// The desktop copy distinguishes only two outcomes: a key-proof refusal (`{ refused }` —// `pop_invalid`, or `pop_required` on a proven mint), which stops phone access and tells the human-// once, and `null` for every other failure, which backs off and retries. This one says WHICH failure-// it was, because the scheduler reacts differently to each: a 429 waits at least a minute, a 402/403-// stops minting, anything else backs off and retries. Both copies share one rule: a 403 is+// once when it is the second in a row, and `null` for every other failure, which backs off and+// retries. This one says WHICH failure it was, because the scheduler reacts differently to each: a+// 429 waits at least a minute, a 402/403 stops minting (a key-proof refusal only on the second in a+// row — hosted-scheduler.ts counts), anything else backs off and retries. Both copies stay stateless+// and count their refusals in the caller. Both share one more rule: a 403 is// deliberately NOT terminal when it is a `pop_required` answer to a mint sent WITHOUT a proof because// the challenge said 404/405. A reverse proxy answers 404 while the backend redeploys, and the// unproven mint that follows can land on the fresh backend, which requires a proof from a host itdiff --git a/src/core/relay/hosted-scheduler.test.ts b/src/core/relay/hosted-scheduler.test.tsindex 0d119357c..af087bbd1 100644--- a/src/core/relay/hosted-scheduler.test.ts+++ b/src/core/relay/hosted-scheduler.test.ts@@ -413,11 +413,81 @@ describe('hosted scheduler', () => {// --- relay proof of possession (relay-pop.ts) ---- it('a PoP refusal stops with backend-refused and the proof message', async () => {- const h = harness([{ ok: false, kind: 'refused', status: 403, reason: 'pop_required' }])+ const popRefused = (reason: 'pop_required' | 'pop_invalid' = 'pop_invalid'): MintResult =>+ ({ ok: false, kind: 'refused', status: 403, reason })++ it.each(['pop_required', 'pop_invalid'] as const)(+ 'two %s refusals in a row stop with backend-refused and the proof message; the first backs off',+ async (reason) => {+ const h = harness([popRefused(reason), popRefused(reason)])+ h.s.start(); await flush()+ // The first is transient (a POP_SECRET rotation mid challenge→mint looks exactly like this).+ expect(h.s.status()).toMatchObject({ state: 'running', lastError: 'network (403)' })+ expect(h.timers).toHaveLength(1) // the backoff owns the next mint (a fresh challenge)+ await h.advance(1000)+ expect(h.mintCalls()).toBe(2)+ expect(h.s.status()).toMatchObject({ state: 'backend-refused', lastError: POP_REFUSED_MESSAGE })+ expect(h.timers).toHaveLength(0)+ }+ )++ it('one PoP refusal then a successful mint: hosting keeps running', async () => {+ const h = harness([popRefused(), ok()])h.s.start(); await flush()- expect(h.s.status()).toMatchObject({ state: 'backend-refused', lastError: POP_REFUSED_MESSAGE })- expect(h.timers).toHaveLength(0)+ await h.advance(1000)+ expect(h.s.status()).toMatchObject({ state: 'running', idle: 1 })+ expect(h.opened).toHaveLength(1)+ })++ it('a successful mint resets the count: refusal, success, refusal is still transient', async () => {+ const h = harness([popRefused(), ok(), popRefused(), popRefused()])+ h.s.start(); await flush()+ await h.advance(1000) // retry → success+ expect(h.opened).toHaveLength(1)+ h.opened[0].ev.onBridged(); await flush() // bridged → a replacement is minted, and refused+ expect(h.mintCalls()).toBe(3)+ expect(h.s.status().state).toBe('running') // the first refusal since the success+ await h.advance(1000)+ expect(h.mintCalls()).toBe(4)+ expect(h.s.status().state).toBe('backend-refused') // the second in a row+ })++ it('start() resets the count: a refusal before a stop does not make the next one terminal', async () => {+ const h = harness([popRefused(), popRefused()])+ h.s.start(); await flush()+ expect(h.s.status().state).toBe('running')+ h.s.stop()+ h.s.start(); await flush()+ expect(h.mintCalls()).toBe(2)+ expect(h.s.status().state).toBe('running') // the first refusal of THIS run+ })++ it('a POP_SECRET rotated between the challenge and the mint: the real mint backs off, re-challenges and proves', async () => {+ // Backend A issues the challenge, backend B (the new secret) verifies the mint: an honest host+ // earns pop_invalid once. Stopping there would stop every host mid-mint at the rotation.+ const keys = nacl.box.keyPair()+ const pub = Buffer.from(keys.publicKey).toString('base64')+ const oldSecret = createTestPopServer('old-secret-'.padEnd(40, 'o'))+ const newSecret = createTestPopServer('new-secret-'.padEnd(40, 'n'))+ let issuer = oldSecret+ const json = (status: number, body: unknown) => new Response(JSON.stringify(body), { status })+ const f = (async (u: string, init: RequestInit) => {+ const body = JSON.parse(String(init.body)) as Record<string, unknown>+ if (u.endsWith('/v1/relay/challenge')) {+ const c = issuer.issue(pub, 'host-token')+ issuer = newSecret // the rotation lands right after the first challenge+ return json(200, c)+ }+ const proven = newSecret.verify({ hostPublicKeyB64: pub, purpose: 'host-token', subject: String(body.deviceId ?? ''), popChallenge: body.popChallenge, popProof: body.popProof })+ return proven ? json(200, { pairingToken: 'T', hostId: 'H', exp: 0 }) : json(403, { error: 'pop_invalid' })+ }) as typeof fetch+ const mint = () => mintHostToken({ apiBase: 'https://api', deviceId: 'd', hostPublicKeyB64: pub, hostSecretKey: keys.secretKey, fetch: f })+ const h = harness([mint, mint])+ h.s.start(); await flush()+ expect(h.s.status().state).toBe('running')+ await h.advance(1000); await flush()+ expect(h.opened).toHaveLength(1)+ expect(h.s.status().state).toBe('running')})it('a pop_required answer to an unproven mint (challenge 404 mid-redeploy) backs off and proves on the retry', async () => {diff --git a/src/core/relay/hosted-scheduler.ts b/src/core/relay/hosted-scheduler.tsindex a2d4c061c..f1b9ac75d 100644--- a/src/core/relay/hosted-scheduler.ts+++ b/src/core/relay/hosted-scheduler.ts@@ -15,6 +15,10 @@// - a 429 waits at least 60 s (longer if Retry-After says so); a 402/403 stops minting (a refused// key proof names itself in `lastError`; a 403 host-token.ts judges transient arrives as// `network` and backs off);+// - a key-proof refusal stops minting only on the SECOND in a row: a POP_SECRET rotation, or a+// secret mismatch between backend instances, inside ONE challenge→mint pair refuses an honest+// host once. The first is backed off like a transient 403 (the retry fetches a fresh challenge);+// a successful mint or start() resets the count;// - while a backoff timer is armed it owns the next mint: nothing else may mint early.// Everything the injected deps can throw is caught: a scheduler that swallowed an exception would sit// in 'running' with no listener and no timer, i.e. hosting silently dead until a restart.@@ -79,6 +83,8 @@ export function createHostedScheduler(deps: SchedulerDeps, now: () => number) {let opening = falselet attempt = 0let retry: unknown = null+ /** Key-proof refusals since the last successful mint or start(); the second in a row is terminal. */+ let popRefusals = 0const mints: number[] = []const live = new Set<Entry>()@@ -182,7 +188,13 @@ export function createHostedScheduler(deps: SchedulerDeps, now: () => number) {r = { ok: false, kind: 'network' }threw = `mint failed: ${errorText(err)}`}- if (r.ok) mints.push(now()) // counted even if we were stopped meanwhile: the backend counted it+ if (r.ok) {+ mints.push(now()) // counted even if we were stopped meanwhile: the backend counted it+ popRefusals = 0+ } else if (r.kind === 'refused' && r.reason && ++popRefusals < 2) {+ // The first key-proof refusal in a row is transient (see the header): back off, re-challenge.+ r = { ok: false, kind: 'network', status: 403 }+ }if (state !== 'running') returnif (!r.ok) {// A key-proof refusal says what to do about it (update, or `team rotate-key`); `refused (403)` would not.@@ -258,6 +270,7 @@ export function createHostedScheduler(deps: SchedulerDeps, now: () => number) {if (state === 'running') returnstate = 'running'attempt = 0+ popRefusals = 0emit()void top()},diff --git a/src/core/relay/relay-pop.ts b/src/core/relay/relay-pop.tsindex 74ca17d46..33858be8e 100644--- a/src/core/relay/relay-pop.ts+++ b/src/core/relay/relay-pop.ts@@ -9,6 +9,9 @@ export type PopPurpose = 'host-token' | 'push'export type PopRefusal = 'pop_required' | 'pop_invalid'export const POP_REFUSED_MESSAGE ="The relay refused this host's key proof — update nodeterm, or run `team rotate-key` if the key was replaced."+/** The desktop phone relay's copy: `team rotate-key` exists only in the Server Edition. */+export const POP_REFUSED_MESSAGE_DESKTOP =+ "The relay refused this computer's key proof — update nodeterm; if it persists after updating, contact support."const PROOF_LABEL = 'nodeterm/relay-pop/v1'const hmac = (key: Buffer | Uint8Array, data: string): Buffer => createHmac('sha256', key).update(data).digest()diff --git a/src/main/remote/standing-host.test.ts b/src/main/remote/standing-host.test.tsindex b157f0815..2f492ff21 100644--- a/src/main/remote/standing-host.test.ts+++ b/src/main/remote/standing-host.test.ts@@ -16,7 +16,7 @@ import { presenceHub } from '../../core/presence/hub'import type { ApprovedDevices } from './approved-devices-core'import type { HostSession, HostSessionOptions } from './host-service'import { createTestPopServer } from '../../core/relay/relay-pop.test-server'-import { POP_REFUSED_MESSAGE } from '../../core/relay/relay-pop'+import { POP_REFUSED_MESSAGE_DESKTOP } from '../../core/relay/relay-pop'// The host's key pair: a REAL X25519 pair, so the standing host can compute a key proof that the// test pop server (a mirror of the backend's verify) accepts or refuses on the real bytes.@@ -676,8 +676,16 @@ describe('standing host: host key proof-of-possession on the host-token mint', (}})+ /** A host-token route answering the listed replies in order, then the last one forever. */+ const hostTokenSeq =+ (...replies: Array<number | string>): Route =>+ (init) => {+ const next = replies.length > 1 ? replies.shift()! : replies[0]+ return next === 200 ? hostTokenOk(init) : res(403, { error: next })+ }+it.each(['pop_required', 'pop_invalid'])(- 'a %s refusal of a PROVEN mint stops hosting, says so once, and never re-mints',+ 'two %s refusals of PROVEN mints in a row stop hosting, say so once, and never re-mint',async (error) => {vi.useFakeTimers()const pop = createTestPopServer()@@ -686,41 +694,160 @@ describe('standing host: host key proof-of-possession on the host-token mint', (host.setEnabled(true)for (let i = 0; i < 5; i++) await settle()+ // The first refusal is transient (a POP_SECRET rotation mid challenge→mint looks exactly like+ // this): no dialog, and the backoff asks for a FRESH challenge.expect(mintCalls()).toHaveLength(1)expect(mintBody()).toHaveProperty('popProof')+ expect(errorBoxes).toHaveLength(0)+ await vi.advanceTimersByTimeAsync(1000)+ expect(challengeCalls()).toHaveLength(2)+ expect(mintCalls()).toHaveLength(2)++ // The second in a row is terminal.expect(sessions).toHaveLength(0)expect(errorBoxes).toHaveLength(1)- expect(errorBoxes[0].body).toContain(POP_REFUSED_MESSAGE)+ expect(errorBoxes[0].body).toContain(POP_REFUSED_MESSAGE_DESKTOP)+ // `team rotate-key` exists only in the Server Edition: the desktop must not advise it.+ expect(errorBoxes[0].body).not.toContain('rotate-key')// Terminal: no reconnect timer is left armed.await vi.advanceTimersByTimeAsync(60_000)- expect(mintCalls()).toHaveLength(1)- expect(challengeCalls()).toHaveLength(1)+ expect(mintCalls()).toHaveLength(2)+ expect(challengeCalls()).toHaveLength(2)expect(errorBoxes).toHaveLength(1)host.stop()})- it('a refusal on the replacement mint while a phone is bridged tears hosting down (stop)', async () => {- // The realistic moment for a refusal: a phone bridges, the pool mints a replacement listener,- // and THAT mint is refused. Stopping must cut the live session, withdraw the advertisement and- // leave nothing that re-mints — a late socket close must not raise a second dialog.+ it('one refusal then a successful mint: no dialog, the host keeps running', async () => {+ vi.useFakeTimers()+ const pop = createTestPopServer()+ routeFetch({ challenge: challengeFrom(pop), hostToken: hostTokenSeq('pop_invalid', 200) })+ const host = makeHost()+ host.setEnabled(true)+ for (let i = 0; i < 5; i++) await settle()+ expect(sessions).toHaveLength(0)+ await vi.advanceTimersByTimeAsync(1000)+ expect(mintCalls()).toHaveLength(2)+ expect(sessions).toHaveLength(1) // a listener is registered: hosting runs+ expect(errorBoxes).toHaveLength(0)+ expect(advertisementsRemoved).toBe(0)+ host.stop()+ })++ it('a successful mint resets the count: refusal, success, refusal is still transient', async () => {vi.useFakeTimers()const pop = createTestPopServer()- let mints = 0routeFetch({challenge: challengeFrom(pop),- hostToken: (init) => (++mints === 1 ? hostTokenOk(init) : res(403, { error: 'pop_invalid' }))+ hostToken: hostTokenSeq('pop_invalid', 200, 'pop_invalid', 'pop_invalid')})const host = makeHost()host.setEnabled(true)for (let i = 0; i < 5; i++) await settle()+ await vi.advanceTimersByTimeAsync(1000) // retry → successexpect(sessions).toHaveLength(1)sessions[0].opts.onPeerReady(sessions[0].session) // bridged → the pool mints a replacementfor (let i = 0; i < 5; i++) await settle()+ expect(mintCalls()).toHaveLength(3) // refused: the FIRST since the success, so transient+ expect(errorBoxes).toHaveLength(0)+ expect(sessions[0].closed).toBe(0) // the phone keeps its session++ await vi.advanceTimersByTimeAsync(2000) // the backoff's next step+ expect(mintCalls()).toHaveLength(4) // the second in a row: terminal+ expect(errorBoxes).toHaveLength(1)+ expect(sessions[0].closed).toBe(1)+ host.stop()+ })++ it('start() resets the count: a refusal before a restart does not make the next one terminal', async () => {+ vi.useFakeTimers()+ const pop = createTestPopServer()+ routeFetch({ challenge: challengeFrom(pop), hostToken: () => res(403, { error: 'pop_invalid' }) })+ const host = makeHost()+ host.setEnabled(true)+ for (let i = 0; i < 5; i++) await settle()+ expect(mintCalls()).toHaveLength(1)+ host.setEnabled(false)+ host.setEnabled(true)+ for (let i = 0; i < 5; i++) await settle()expect(mintCalls()).toHaveLength(2)+ expect(errorBoxes).toHaveLength(0) // the first refusal of THIS run+ host.stop()+ })++ it('turning access off while a mint is in flight: a refusal that lands afterwards raises nothing', async () => {+ vi.useFakeTimers()+ const pop = createTestPopServer()+ let answer: ((r: FakeRes) => void) | null = null+ let n = 0+ routeFetch({+ challenge: challengeFrom(pop),+ hostToken: () =>+ ++n === 1+ ? res(403, { error: 'pop_invalid' })+ : new Promise<FakeRes>((resolve) => {+ answer = resolve+ })+ })+ const host = makeHost()+ host.setEnabled(true)+ for (let i = 0; i < 5; i++) await settle()+ await vi.advanceTimersByTimeAsync(1000) // the retry: the SECOND mint is now in flight+ expect(mintCalls()).toHaveLength(2)+ expect(answer).not.toBeNull()++ host.setEnabled(false) // the human turns phone access off+ answer!(res(403, { error: 'pop_invalid' })) // …and the refusal lands afterwards+ for (let i = 0; i < 5; i++) await settle()+ expect(errorBoxes).toEqual([])+ await vi.advanceTimersByTimeAsync(60_000)+ expect(mintCalls()).toHaveLength(2)+ })++ it('the refusal kind is logged; the dialog text stays fixed', async () => {+ vi.useFakeTimers()+ const logged = vi.spyOn(console, 'error').mockImplementation(() => {})+ try {+ const pop = createTestPopServer()+ routeFetch({ challenge: challengeFrom(pop), hostToken: () => res(403, { error: 'pop_invalid' }) })+ const host = makeHost()+ host.setEnabled(true)+ for (let i = 0; i < 5; i++) await settle()+ await vi.advanceTimersByTimeAsync(1000)+ expect(errorBoxes).toHaveLength(1)+ expect(errorBoxes[0].body).not.toContain('pop_invalid')+ expect(logged.mock.calls.flat().join(' ')).toContain('pop_invalid')+ host.stop()+ } finally {+ logged.mockRestore()+ }+ })++ it('refusals on the replacement mint while a phone is bridged: the first is transient, the second tears hosting down (stop)', async () => {+ // The realistic moment for a refusal: a phone bridges, the pool mints a replacement listener,+ // and THAT mint is refused. The first refusal leaves the phone's session alone; the second in a+ // row must cut it, withdraw the advertisement and leave nothing that re-mints — a late socket+ // close must not raise a second dialog.+ vi.useFakeTimers()+ const pop = createTestPopServer()+ routeFetch({ challenge: challengeFrom(pop), hostToken: hostTokenSeq(200, 'pop_invalid') })+ const host = makeHost()+ host.setEnabled(true)+ for (let i = 0; i < 5; i++) await settle()+ expect(sessions).toHaveLength(1)++ sessions[0].opts.onPeerReady(sessions[0].session) // bridged → the pool mints a replacement+ for (let i = 0; i < 5; i++) await settle()+ expect(mintCalls()).toHaveLength(2)+ expect(errorBoxes).toHaveLength(0)+ expect(sessions[0].closed).toBe(0)+ expect(phones()).toBe(1)++ await vi.advanceTimersByTimeAsync(1000) // the backoff re-challenges and is refused again+ expect(mintCalls()).toHaveLength(3)expect(errorBoxes).toHaveLength(1)- expect(errorBoxes[0].body).toContain(POP_REFUSED_MESSAGE)+ expect(errorBoxes[0].body).toContain(POP_REFUSED_MESSAGE_DESKTOP)expect(sessions[0].closed).toBe(1) // the bridged phone session is cutexpect(phones()).toBe(0)expect(advertisementsRemoved).toBe(1) // phones stop minting against a host that is gone@@ -728,21 +855,24 @@ describe('standing host: host key proof-of-possession on the host-token mint', (sessions[0].opts.onClose() // a late transport close of the cut sessionfor (let i = 0; i < 5; i++) await settle()await vi.advanceTimersByTimeAsync(60_000)- expect(mintCalls()).toHaveLength(2)+ expect(mintCalls()).toHaveLength(3)expect(errorBoxes).toHaveLength(1)host.stop()})- it('a pop_invalid refusal is terminal even for an unproven (legacy) mint', async () => {+ it('pop_invalid is terminal even for unproven (legacy) mints — on the second in a row', async () => {vi.useFakeTimers()routeFetch({ hostToken: () => res(403, { error: 'pop_invalid' }) })const host = makeHost()host.setEnabled(true)for (let i = 0; i < 5; i++) await settle()expect(mintBody()).not.toHaveProperty('popProof')+ expect(errorBoxes).toHaveLength(0)+ await vi.advanceTimersByTimeAsync(1000)+ expect(mintCalls()).toHaveLength(2)expect(errorBoxes).toHaveLength(1)await vi.advanceTimersByTimeAsync(60_000)- expect(mintCalls()).toHaveLength(1)+ expect(mintCalls()).toHaveLength(2)host.stop()})diff --git a/src/main/remote/standing-host.ts b/src/main/remote/standing-host.tsindex 16888fd10..fa9728c32 100644--- a/src/main/remote/standing-host.ts+++ b/src/main/remote/standing-host.ts@@ -43,7 +43,7 @@ import { phonePins } from './approved-devices'import { registerPeerSessionKiller } from './peer-revoke'import { createPhoneApprovals } from '../../core/phone-approval'import {- POP_REFUSED_MESSAGE,+ POP_REFUSED_MESSAGE_DESKTOP,computePopProof,fetchPopChallenge,popRefusalOf,@@ -95,9 +95,10 @@ export function tokenTtlMs(exp: number, serverDate: string | null, localNowMs: n* other challenge failure is transient and mints NOTHING: to a host the backend has seen prove* before, an unproven mint is a 403, which would stop hosting over a blip.*- * Returns `{ refused }` for a terminal key-proof refusal (the caller stops hosting and says so) and- * null for every other failure (the caller backs off and retries). One 403 is deliberately NOT- * terminal: `pop_required` for a mint sent WITHOUT a proof because the challenge said 404/405. A+ * Returns `{ refused }` for a key-proof refusal and null for every other failure (the caller backs+ * off and retries). This function stays stateless: the caller counts refusals and stops hosting+ * only on the second in a row (see `popRefusals` in initStandingHost). One 403 is not a refusal at+ * all: `pop_required` for a mint sent WITHOUT a proof because the challenge said 404/405. A* reverse proxy answers 404 while the backend redeploys, and the unproven mint that follows can land* on the fresh backend; stopping there would end hosting for good over a redeploy, so it backs off* and the next attempt asks for a challenge again.@@ -204,20 +205,21 @@ function reportKeyLocked(err: Error): void {}/**- * The relay refused this host's key proof (`pop_invalid`, or `pop_required` on a proven mint). It- * will refuse every retry the same way, so hosting stops and the human is told, once, how to- * recover — instead of phone access going quietly dead, or a retry loop spending the host's mints.+ * The relay refused this host's key proof twice in a row, each time on a fresh challenge+ * (`pop_invalid`, or `pop_required` on a proven mint). It will keep refusing, so hosting stops and+ * the human is told, once, what to do — instead of phone access going quietly dead, or a retry+ * loop spending the host's mints. The kind goes to the log only; the dialog text is fixed.*/-function reportPopRefused(): void {+function reportPopRefused(kind: PopRefusal): void {try {dialog.showErrorBox('Remote access stopped',- `${POP_REFUSED_MESSAGE}\n\nPhone access is off until then. Turn it back on in Settings → Phone.`+ `${POP_REFUSED_MESSAGE_DESKTOP}\n\nPhone access is off until then. Turn it back on in Settings → Phone.`)} catch {// No dialog available (headless / very early boot): the console line is the fallback.}- console.error('[standing-host] the relay refused this host key proof')+ console.error(`[standing-host] the relay refused this host key proof twice in a row (${kind})`)}export interface StandingHost {@@ -266,6 +268,11 @@ export function initStandingHost(const pool = new Set<Pooled>()let reconnectTimer: ReturnType<typeof setTimeout> | null = nulllet reconnectAttempt = 0+ // Key-proof refusals since the last successful mint or start(). Only the SECOND in a row is+ // terminal: a POP_SECRET rotation, or a secret mismatch between backend instances, inside one+ // challenge→mint pair refuses an honest host once, and stopping there would leave every host that+ // was mid-mint at that moment off until someone turned phone access back on by hand.+ let popRefusals = 0function send(channel: string, ...args: unknown[]): void {if (!win.isDestroyed()) win.webContents.send(channel, ...args)@@ -403,15 +410,22 @@ export function initStandingHost(const token = await mintHostToken(entitlement, keys)if (!running) returnif (token && 'refused' in token) {- // Terminal: every retry would be refused the same way. stop() clears any armed reconnect.- stop()- reportPopRefused()+ popRefusals += 1+ if (popRefusals >= 2) {+ // Terminal: every retry would be refused the same way. stop() clears any armed reconnect.+ stop()+ reportPopRefused(token.refused)+ return+ }+ console.warn(`[standing-host] the relay refused this host key proof (${token.refused}); retrying with a fresh challenge`)+ scheduleReconnect()return}if (!token) {scheduleReconnect()return}+ popRefusals = 0 // a successful mint: the key proof is accepted// NOT `reconnectAttempt = 0` here. A mint proves only that the API answered — the relay is a// different host, and when it is unreachable from this machine (relay log, 2026-09-27: a host// on the fixed build, API fine, relay WS failing for 2½ minutes) every mint succeeds, every@@ -506,6 +520,7 @@ export function initStandingHost(if (running) returnrunning = truereconnectAttempt = 0+ popRefusals = 0ensurePool()}diff --git a/src/main/window-raise.guard.test.ts b/src/main/window-raise.guard.test.tsindex 88293d3dc..4416e6f83 100644--- a/src/main/window-raise.guard.test.ts+++ b/src/main/window-raise.guard.test.ts@@ -94,9 +94,10 @@ const ALLOWED = new Map<string, { calls: number; why: string }>(['not a silent raise); the honest fix routes it to a non-modal in-app surface and needs a ' +'macOS check that a sheet on a background window does not activate. The SECOND call is ' +'the same class: an app-modal showErrorBox (reportPopRefused) when the relay refuses this ' +- "host's key proof (pop_invalid, or pop_required on a proven mint), raised from a re-mint " +- 'on the refresh/reconnect timer. It is terminal and rare (a downgrade after the host ' +- 'latched, or a replaced key), and phone access silently stopping would be worse. Both ' ++ "host's key proof on two consecutive mints, each on a fresh challenge (pop_invalid, or " ++ 'pop_required on a proven mint), raised from a re-mint on the refresh/reconnect timer. ' ++ 'This build always proves when the backend asks, so it means a backend fault or a client ' ++ 'bug: terminal and rare, and phone access silently stopping would be worse. Both ' +"belong to one fix: route standing-host's dialogs to a non-modal in-app surface. The two " +'call sites stay separate on purpose (one shared helper would hide a raise from this ' +'count). Listed so they cannot be forgotten, and so the count still fails if a THIRD ' +