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-notify): a backward clock step expires the cached hostAuth session

review46aee381bccd
diff --git a/CLAUDE.md b/CLAUDE.md
index 89291cd13..c69cefde2 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -7866,7 +7866,8 @@ The invariants, each with its reason:
`POP_REFUSED_MESSAGE` (it names `team rotate-key`); the desktop shows ONE dialog with
`POP_REFUSED_MESSAGE_DESKTOP`, which must never name `team rotate-key` (Server Edition only).
- **Push uses a 15-minute `hostAuth` session from `/v1/push/host-auth`**, re-proven after 10
- minutes on the client's clock, one per stream (`core/push-notify.ts` `createHostAuthCache`). An
+ minutes on the client's clock (at once if that clock has stepped back since: a negative age is
+ expired), one per stream (`core/push-notify.ts` `createHostAuthCache`). An
old-backend verdict is cached 10 minutes; failed proofs back off 0/5/15/60 s (a hold further out
than 60 s is a backward clock step and is ignored); overlapping flushes share one proof; a proof
that throws is a failure, never a rejection. A batch that cannot be proven is DROPPED, never sent
diff --git a/docs/hosted-team-relay.md b/docs/hosted-team-relay.md
index 4199691a2..4989c9054 100644
--- a/docs/hosted-team-relay.md
+++ b/docs/hosted-team-relay.md
@@ -745,7 +745,9 @@ proves again.
- **Desktop host-mode push** (`src/core/push-notify.ts`). Push stops nothing: a batch that cannot
be proven is dropped, like a network error, and the phone still has the agent-status mirror.
- The `hostAuth` session is good for 15 minutes on the server, and the client proves again after
- 10 minutes on its own clock. notify and live-update each hold their own.
+ 10 minutes on its own clock, or at once if that clock has stepped back since (a cached session
+ or old-backend verdict with a negative age is expired). notify and live-update each hold their
+ own.
- A backend without the proof (challenge 404/405, or no host-auth route) is remembered for 10
minutes, so it costs one challenge per 10 minutes rather than one per batch.
- Failed proofs back off 0, 5, 15, then 60 s between attempts, since every attempt spends the
diff --git a/src/core/push-notify.test.ts b/src/core/push-notify.test.ts
index a5aaf5630..fac2994b9 100644
--- a/src/core/push-notify.test.ts
+++ b/src/core/push-notify.test.ts
@@ -2074,6 +2074,30 @@ describe('host-mode push proves possession of the host key (hostAuth session)',
h.stop()
})
+ it.each<[string, { challenge?: Route }, string | undefined, string | undefined]>([
+ ['session', {}, 'HA-1', 'HA-2'],
+ ['old-backend verdict', { challenge: () => bare(404) }, undefined, undefined]
+ ])(
+ 'a backward wall-clock step expires a cached %s: the next get() proves again',
+ async (_label, r, first, second) => {
+ // A negative age is no evidence of freshness. Read as "fresh", a clock stepped back an hour kept
+ // the same session for that hour PLUS the 10 minutes, past the server's 15-minute TTL.
+ route(r)
+ const cache = createHostAuthCache({
+ apiBase: 'https://api.nodeterm.dev',
+ fetchImpl: fetchMock as unknown as typeof fetch,
+ now: () => clock
+ })
+ clock = 60 * MIN
+ await expect(cache.get(PROVEN)).resolves.toBe(first)
+ expect(cache.onFile(PROVEN)).toBe(true)
+ clock = 0 // the wall clock steps back an hour
+ expect(cache.onFile(PROVEN)).toBe(false)
+ await expect(cache.get(PROVEN)).resolves.toBe(second)
+ expect(callsTo('/v1/relay/challenge')).toHaveLength(2)
+ }
+ )
+
it('a cached legacy verdict refused by a host latched elsewhere re-proves and re-posts in the SAME batch', async () => {
// The backend predated the proof when this sender asked, so it holds "legacy" for 10 minutes.
// Meanwhile the host latched through another path (the standing host's proven mint, or the
diff --git a/src/core/push-notify.ts b/src/core/push-notify.ts
index 60595eda1..2468cb9f3 100644
--- a/src/core/push-notify.ts
+++ b/src/core/push-notify.ts
@@ -318,7 +318,14 @@ export function createHostAuthCache(d: { apiBase: string; fetchImpl: typeof fetc
}
const keyOf = (id: PushHostIdentity): string => `${id.hostPublicKeyB64}\n${id.hostDeviceId}`
- const onFile = (key: string): boolean => !!cached && cached.key === key && d.now() - cached.at < HOST_AUTH_REPROVE_MS
+ // A NEGATIVE age is a wall clock that stepped back since the entry was cached, and is read as
+ // expired: taken as fresh, a step back of an hour would serve the same session (or old-backend
+ // verdict) for that hour plus the 10 minutes, past the server's 15-minute TTL.
+ const onFile = (key: string): boolean => {
+ if (!cached || cached.key !== key) return false
+ const age = d.now() - cached.at
+ return age >= 0 && age < HOST_AUTH_REPROVE_MS
+ }
return {
invalidate() {