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.

harden(dino): rate-limit malformed dino casts; exempt only the genuine null stop (dino Task 1 review)

enes619ec2bceaaf
diff --git a/src/core/presence/hub.test.ts b/src/core/presence/hub.test.ts
index c4c9fdd81..373785b44 100644
--- a/src/core/presence/hub.test.ts
+++ b/src/core/presence/hub.test.ts
@@ -458,7 +458,14 @@ describe('PresenceHub dino (live spectator cast)', () => {
}
expect(diffs().length - before).toBe(budget.burst) // the bucket, not one cast more
- // A stop is an edge (a dropped one leaves a frozen ghost) → exempt, lands even when drained.
+ // A MALFORMED non-null cast is NOT an exempt stop — it spends a token like any snapshot, so a
+ // garbage flood is bounded by the same bucket (which is now drained → this drops, no diff).
+ const afterFlood = diffs().length
+ for (let i = 0; i < 50; i++) fake.senderListeners[IPC.presenceDino](1, { garbage: i })
+ expect(diffs().length).toBe(afterFlood) // all dropped by the rate limiter, not exempted
+
+ // A genuine stop (null) is an edge (a dropped one leaves a frozen ghost) → exempt, lands even
+ // when the bucket is drained.
fake.senderListeners[IPC.presenceDino](1, null)
expect(hub.peers()[0].dino).toBeNull()
expect(diffs().at(-1)).toEqual({ op: 'update', clientId: 1, patch: { dino: null } })
diff --git a/src/core/presence/hub.ts b/src/core/presence/hub.ts
index 6e41956ca..28671e194 100644
--- a/src/core/presence/hub.ts
+++ b/src/core/presence/hub.ts
@@ -84,8 +84,11 @@ function isClearingCast(channel: string, payload: unknown): boolean {
if (channel === IPC.presenceChat) return typeof payload !== 'string'
if (channel === IPC.presenceFocus) return typeof payload !== 'string' || payload === ''
// A dino "stop" (the authority quit / closed the node) is an EDGE — nothing supersedes it, and a
- // dropped one leaves a frozen ghost game on every spectator. Mirror setDino's own null rule.
- if (channel === IPC.presenceDino) return sanitizeDinoPayload(payload) === null
+ // dropped one leaves a frozen ghost game on every spectator, so the genuine stop (`null`) is
+ // exempt. A MALFORMED non-null cast is NOT a stop — it goes through the rate bucket (so a garbage
+ // flood is bounded), and setDino sanitizes it to null (a no-op if the peer wasn't playing). Cheap
+ // `== null` here, not a full sanitize, so the common exempt path allocates nothing.
+ if (channel === IPC.presenceDino) return payload == null
return false
}