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(live-links): widening owner changes wait for the write; input deadline from hand-over

reviewede5b10ed27b
diff --git a/src/core/pty-manager.control-input.test.ts b/src/core/pty-manager.control-input.test.ts
index 8bffeafe1..af1f98610 100644
--- a/src/core/pty-manager.control-input.test.ts
+++ b/src/core/pty-manager.control-input.test.ts
@@ -425,6 +425,30 @@ describe('controlInput — bounded on every route', () => {
})
}
+ // The deadline runs from the HAND-OVER: a chunk that waited 15 s behind a slow step has 5 s left,
+ // not a fresh 20 — its caller gives up 20 s after handing it over, whatever the chain did meanwhile.
+ it('a chunk queued behind a slow step for 15 s gets at most 5 s more', async () => {
+ let releaseFirst!: (v: boolean) => void
+ let n = 0
+ const sendText = vi.fn(
+ (): Promise<boolean> => (++n === 1 ? new Promise<boolean>((r) => (releaseFirst = r)) : new Promise<boolean>(() => {}))
+ )
+ const { mgr } = await manager({ nativeWindowsPane: { sendText }, tmuxBacked: false, persistKey: undefined })
+ vi.useFakeTimers()
+ const first = mgr.controlInput('sess-1', { kind: 'paste', text: 'a' })
+ let second: boolean | null = null
+ void mgr.controlInput('sess-1', { kind: 'paste', text: 'b' }).then((v) => (second = v))
+ await vi.advanceTimersByTimeAsync(15_000)
+ releaseFirst(true)
+ expect(await first).toBe(true)
+ await vi.advanceTimersByTimeAsync(0)
+ expect(sendText).toHaveBeenCalledTimes(2) // 'b' started, with 5 s left
+ await vi.advanceTimersByTimeAsync(PANE_INPUT_DEADLINE_MS - 15_000 - 1)
+ expect(second).toBeNull()
+ await vi.advanceTimersByTimeAsync(1)
+ expect(second).toBe(false)
+ })
+
it('a chunk that could not START before the deadline is dropped undelivered: its caller gave up on it', async () => {
const sendText = vi.fn((): Promise<boolean> => new Promise(() => {}))
const { mgr } = await manager({ nativeWindowsPane: { sendText }, tmuxBacked: false, persistKey: undefined })
diff --git a/src/core/pty-manager.ts b/src/core/pty-manager.ts
index e812e1e14..f462c0086 100644
--- a/src/core/pty-manager.ts
+++ b/src/core/pty-manager.ts
@@ -4989,23 +4989,24 @@ export class PtyManager {
* inside each step (it can be gone by then → false), and the tmux name is resolved from it, never
* from the caller. A false is never retried here (a timed-out delivery may well have run).
*
- * BOUNDED on every route (PANE_INPUT_DEADLINE_MS, the link host's own deadline). The tmux and SSH
- * routes are bounded already (`runWithStdin`: PROC_TIMEOUT_MS), the session host's request by its
- * own timeout once connected — but its reconnect can wait on a host that is still starting, and a
- * step that never settled would hold every later chunk behind it, to land long after the link host
- * told its controller it was dropped. So a step answers false at the deadline (a late delivery may
- * still land, as with any timed-out one), and a chunk that could not even START by its deadline is
- * dropped undelivered: whoever handed it over has given up on it.
+ * BOUNDED on every route, by a deadline PANE_INPUT_DEADLINE_MS after the chunk was HANDED OVER —
+ * the link host's own deadline, which runs from the same moment. The tmux and SSH routes are bounded
+ * already (`runWithStdin`: PROC_TIMEOUT_MS), the session host's request by its own timeout once
+ * connected — but its reconnect can wait on a host that is still starting, and a step that never
+ * settled would hold every later chunk behind it, to land long after the link host told its
+ * controller it was dropped. So a step gets only what is LEFT of its chunk's deadline (a chunk that
+ * waited 15 s behind a slow one has 5 s), answers false when it runs out (a late delivery may still
+ * land, as with any timed-out one), and a chunk with nothing left when its turn comes is dropped
+ * undelivered: whoever handed it over has given up on it.
*/
controlInput(sessionId: string, chunk: ControlInputChunk): Promise<boolean> {
const handedAt = Date.now()
const prev = this.controlInputChains.get(sessionId) ?? Promise.resolve(true)
const step = prev
- .then(() =>
- Date.now() - handedAt >= PANE_INPUT_DEADLINE_MS
- ? false
- : settleWithin(this.deliverControlInput(sessionId, chunk), PANE_INPUT_DEADLINE_MS)
- )
+ .then(() => {
+ const left = PANE_INPUT_DEADLINE_MS - (Date.now() - handedAt)
+ return left <= 0 ? false : settleWithin(this.deliverControlInput(sessionId, chunk), left)
+ })
.catch(() => false)
this.controlInputChains.set(sessionId, step)
void step.then(() => {
diff --git a/src/core/watch-link/pane-input.ts b/src/core/watch-link/pane-input.ts
index 66f12b8f3..bb8ef3ae3 100644
--- a/src/core/watch-link/pane-input.ts
+++ b/src/core/watch-link/pane-input.ts
@@ -102,11 +102,12 @@ export type WatcherInputRoute = 'tmux' | 'ssh' | 'write' | 'none'
export const WATCHER_INPUT_ROUTES = ['tmux', 'ssh', 'write', 'none'] as const satisfies readonly WatcherInputRoute[]
/**
- * How long one chunk of a controller's input may take, from the moment it is handed over: the link
+ * How long one chunk of a controller's input may take, from the moment it is HANDED OVER: the link
* host gives up on it then (INPUT_DELIVERY_TIMEOUT_MS is this value) and tells its controller it was
- * dropped, and `PtyManager.controlInput` answers false at the same deadline and moves the session's
- * chain on — so a delivery that never answers cannot hold every later chunk behind it, and a chunk
- * that could not even START by then is never delivered at all.
+ * dropped, and `PtyManager.controlInput` answers false at the same instant — a chunk that waited
+ * behind a slow one gets only what is left — and moves the session's chain on. So a delivery that
+ * never answers cannot hold every later chunk behind it, and a chunk with nothing left when its turn
+ * comes is never delivered at all.
*/
export const PANE_INPUT_DEADLINE_MS = 20_000
diff --git a/src/core/watch-link/service.test.ts b/src/core/watch-link/service.test.ts
index eac048cf1..3d05620cc 100644
--- a/src/core/watch-link/service.test.ts
+++ b/src/core/watch-link/service.test.ts
@@ -1079,8 +1079,9 @@ describe('createWatchLinkService — creating a Control link', () => {
throw new Error(`scrypt said no about ${pw}`)
}
})
- const r = await t.s.create(ctlReq())
- expect(r.ok).toBe(false)
+ // `unsupported`: the one kind whose desktop copy names no cause ("can't be created here right now");
+ // `network` would say nodeterm's service could not be reached, which is not what happened.
+ expect(await t.s.create(ctlReq())).toEqual({ ok: false, error: 'unsupported' })
expect(t.calls).toEqual([])
expect(t.hosts.made).toEqual([])
expect(allLogged([warn])).not.toContain(PW)
@@ -1274,7 +1275,7 @@ describe('createWatchLinkService — the owner controls a Control link', () => {
h.hooks.length = 0
h.deps.onControlLocked() // its own write fails too: the lock holds
expect(await t.s.allowControl(id)).toBe(false)
- expect(h.hooks).toEqual(['allowControl', 'controlChanged'])
+ expect(h.hooks).toEqual([]) // a widening the write refused never reached the host
expect(t.s.list()[0].control).toEqual({ enabled: true, locked: true })
const c = h.record.control!
expect(allLogged([warn])).not.toMatch(
@@ -1297,6 +1298,140 @@ describe('createWatchLinkService — the owner controls a Control link', () => {
})
})
+// A change that NARROWS access (typing off, a new password) reaches the host at once, before the write.
+// One that WIDENS it (typing on, allow again) reaches it only once the write landed: a viewer must never
+// unlock and type during a write the owner is then told failed.
+describe('createWatchLinkService — owner changes, by direction', () => {
+ async function heldWrites(o: { hashPassword?: Opts['hashPassword'] } = {}) {
+ let held: ReturnType<typeof deferred<SaveOutcome>> | null = null
+ // What each write carried, copied AT CALL TIME (the store snapshots then; the record objects in
+ // `f.saves` are the live ones and would show later changes).
+ const written: (WatchLinkRecord['control'] | undefined)[] = []
+ const f = fakeStore({
+ save: (recs) => {
+ written.push(recs[0]?.control ? { ...recs[0].control } : undefined)
+ return held ? held.promise : Promise.resolve('saved')
+ }
+ })
+ const t = service({ store: f.store, hashPassword: o.hashPassword ?? fastHash })
+ const r = await t.s.create(ctlReq())
+ if (!r.ok) throw new Error(r.error)
+ const h = t.hosts.made[0]
+ return {
+ t, f, h, written, id: r.link.linkId,
+ hold: () => (held = deferred<SaveOutcome>()),
+ release: (o: SaveOutcome) => {
+ const d = held!
+ held = null
+ d.resolve(o)
+ }
+ }
+ }
+
+ it('typing OFF reaches the host before the write lands', async () => {
+ const x = await heldWrites()
+ x.hold()
+ const off = x.t.s.setControl(x.id, false)
+ await flush()
+ expect(x.h.record.control?.enabled).toBe(false)
+ expect(x.h.hooks).toEqual(['controlChanged'])
+ x.release('saved')
+ expect(await off).toBe(true)
+ })
+
+ it('typing ON waits for the write: the record the host reads stays off throughout, and a failed write never turns it on', async () => {
+ const x = await heldWrites()
+ expect(await x.t.s.setControl(x.id, false)).toBe(true)
+ x.h.hooks.length = 0
+ x.hold()
+ const on = x.t.s.setControl(x.id, true)
+ await flush()
+ // What an unlock checks (the host reads the record live): still off while the write is in flight.
+ expect(x.h.record.control?.enabled).toBe(false)
+ expect(x.h.hooks).toEqual([])
+ expect(x.t.s.list()[0].control).toEqual({ enabled: false, locked: false })
+ // …and yet the write carries the change.
+ expect(x.written.at(-1)?.enabled).toBe(true)
+ x.release('failed')
+ expect(await on).toBe(false)
+ expect(x.h.record.control?.enabled).toBe(false)
+ expect(x.h.hooks).toEqual([])
+ expect(x.written.at(-1)?.enabled).toBe(false) // the list as it is, queued behind
+ })
+
+ it('typing ON that lands: applied, then the host is told', async () => {
+ const x = await heldWrites()
+ expect(await x.t.s.setControl(x.id, false)).toBe(true)
+ x.h.hooks.length = 0
+ x.hold()
+ const on = x.t.s.setControl(x.id, true)
+ await flush()
+ expect(x.h.hooks).toEqual([])
+ x.release('saved')
+ expect(await on).toBe(true)
+ expect(x.h.record.control?.enabled).toBe(true)
+ expect(x.h.hooks).toEqual(['controlChanged'])
+ expect(x.t.s.list()[0].control).toEqual({ enabled: true, locked: false })
+ })
+
+ it('allowControl waits for the write too: still locked throughout, and a failed write never unlocks it', async () => {
+ const x = await heldWrites()
+ x.h.deps.onControlLocked()
+ await flush()
+ x.hold()
+ const allow = x.t.s.allowControl(x.id)
+ await flush()
+ expect(x.h.record.control?.locked).toBe(true)
+ expect(x.h.hooks).toEqual([])
+ x.release('failed')
+ expect(await allow).toBe(false)
+ expect(x.h.record.control?.locked).toBe(true)
+ expect(x.h.hooks).toEqual([])
+ x.hold()
+ const again = x.t.s.allowControl(x.id)
+ await flush()
+ expect(x.h.record.control?.locked).toBe(true)
+ x.release('saved')
+ expect(await again).toBe(true)
+ expect(x.h.record.control?.locked).toBe(false)
+ expect(x.h.hooks).toEqual(['allowControl'])
+ })
+
+ it('typing ON then OFF while the ON is still being written: OFF wins, and the disk ends off', async () => {
+ const x = await heldWrites()
+ expect(await x.t.s.setControl(x.id, false)).toBe(true)
+ x.h.hooks.length = 0
+ x.hold()
+ const on = x.t.s.setControl(x.id, true)
+ await flush()
+ expect(await x.t.s.setControl(x.id, false)).toBe(true) // the later click
+ x.release('saved')
+ expect(await on).toBe(true) // written, then replaced by the later change
+ expect(x.h.record.control?.enabled).toBe(false)
+ expect(x.h.hooks).toEqual([])
+ await vi.waitFor(() => expect(x.written.at(-1)?.enabled).toBe(false))
+ })
+
+ it('a write issued while a widening is in flight cannot leave the disk behind memory', async () => {
+ const x = await heldWrites()
+ expect(await x.t.s.setControl(x.id, false)).toBe(true)
+ x.hold()
+ const on = x.t.s.setControl(x.id, true)
+ await flush()
+ const n = x.written.length
+ // A lock writes the LIVE record (still off) behind the write that carries ON — and touches
+ // another field, so the ON keeps its turn and is applied once its write lands.
+ x.h.deps.onControlLocked()
+ expect(x.written.length).toBe(n + 1)
+ expect(x.written.at(-1)).toMatchObject({ enabled: false, locked: true })
+ x.release('saved')
+ expect(await on).toBe(true)
+ expect(x.h.record.control).toMatchObject({ enabled: true, locked: true })
+ // The last write is the record as memory holds it, not the lock's older snapshot.
+ await vi.waitFor(() => expect(x.written.at(-1)).toEqual({ ...x.h.record.control }))
+ })
+})
+
describe('createWatchLinkService — one bound on scrypt', () => {
it('a FIFO gate: a third task waits for a slot, slots go in arrival order, a failure frees its slot', async () => {
const gate = createFifoGate(2)
@@ -1367,6 +1502,46 @@ describe('createWatchLinkService — one bound on scrypt', () => {
})
})
+describe('createWatchLinkService — a password check queued behind a new password', () => {
+ it('reads the NEW hash when it runs: the old password fails, the new one opens', async () => {
+ const holds = new Map<string, ReturnType<typeof deferred<boolean>>>()
+ const seen: { pw: string; hash: string }[] = []
+ const t = service({
+ verifyPassword: (pw, h) => {
+ seen.push({ pw, hash: h.hash })
+ if (pw.startsWith('hold-')) {
+ const d = deferred<boolean>()
+ holds.set(pw, d)
+ return d.promise
+ }
+ return verifyControlPassword(pw, h)
+ }
+ })
+ for (const nodeId of ['n1', 'n2', 'n1']) expect((await t.s.create(ctlReq({ nodeId }))).ok).toBe(true)
+ const [a, b, c] = t.hosts.made
+ const oldHash = a.record.control!.hash
+ // Both slots busy; then the new password's hash, then two checks on link A, queue in that order.
+ const busy = [b.deps.verifyPassword('hold-b'), c.deps.verifyPassword('hold-c')]
+ await flush()
+ const changed = t.s.setPassword(a.record.linkId, NEW_PW)
+ const oldTry = a.deps.verifyPassword(PW)
+ const newTry = a.deps.verifyPassword(NEW_PW)
+ await flush()
+ expect(seen.map((x) => x.pw)).toEqual(['hold-b', 'hold-c'])
+ // One slot frees: the hash runs in it while the other stays busy, so both checks are still queued
+ // when the new password lands; the first takes the hash's slot after it.
+ holds.get('hold-b')!.resolve(false)
+ expect(await changed).toBe(true)
+ expect(await oldTry).toBe(false)
+ holds.get('hold-c')!.resolve(false)
+ expect(await newTry).toBe(true)
+ const newHash = a.record.control!.hash
+ expect(newHash).not.toBe(oldHash)
+ expect(seen.filter((x) => x.pw === PW || x.pw === NEW_PW).map((x) => x.hash)).toEqual([newHash, newHash])
+ await Promise.all(busy)
+ })
+})
+
describe('createWatchLinkService — controlSupport', () => {
it("answers the shell's check; anything else, a throw, an unsafe id or no check at all is unknown", () => {
const answers: Record<string, unknown> = { n1: 'ok', n2: 'unsupported', n3: 'maybe' }
diff --git a/src/core/watch-link/service.ts b/src/core/watch-link/service.ts
index 27cbf8915..578ba284c 100644
--- a/src/core/watch-link/service.ts
+++ b/src/core/watch-link/service.ts
@@ -40,11 +40,14 @@
// through ONE FIFO gate of SCRYPT_SLOTS (each run is ~32 MiB and ~80 ms on libuv's 4-thread pool, and
// unlock attempts arrive from strangers): a run waits for a slot, it is never refused. The lock the
// link host asks for (`onControlLocked`) is set on the record synchronously — the host reads the record
-// live — and is never undone by a failed write. The owner's changes (typing on/off, a new password,
-// allow again) reach the host at once (turning typing off or replacing a leaked password must not wait
-// on the disk), are then written, and are undone in memory and at the host when the write fails or does
-// not answer within PERSIST_TIMEOUT_MS: the owner is answered false, never told a change was kept that
-// the next launch would not have.
+// live — and is never undone by a failed write. The owner's changes go by DIRECTION. One that NARROWS
+// access (typing off, a new password) reaches the record and the host at once — a leaked password or
+// an unwanted typist must not wait on the disk — and is undone when its write fails or does not answer
+// within PERSIST_TIMEOUT_MS. One that WIDENS it (typing on, allow again) is written first, from a copy
+// of the record, and reaches the record and the host only once that write landed: nobody can unlock
+// and type during a write the owner is then told failed. Either way a failed write answers false: the
+// owner is never told a change was kept that the next launch would not have. A later change to the
+// same field supersedes an earlier one still being written (its undo or its late apply is skipped).
//
// AN UNLIMITED LINK (`ttlSeconds` 0) has `expiresAt: null`: no expiry timer, no expiry check on a host
// change, never pruned for time at launch. It ends like any link otherwise, and when its owner's Pro
@@ -426,10 +429,12 @@ export function createWatchLinkService(deps: WatchLinkServiceDeps): WatchLinkSer
}
/** Write the current records. Called, not awaited, wherever the owner must not wait on the disk;
- * the store snapshots at call time and serializes its writes, so disk order is call order. */
- function persist(): Promise<boolean> {
+ * the store snapshots at call time and serializes its writes, so disk order is call order.
+ * `instead` is written in place of the record with its id (a change not yet applied in memory). */
+ function persist(instead?: WatchLinkRecord): Promise<boolean> {
if (storeLatched) return Promise.resolve(true) // memory-only this run: nothing is written
- const p = deps.store.save([...records.values(), ...writing.values()]).then(
+ const list = [...records.values(), ...writing.values()].map((x) => (instead && x.linkId === instead.linkId ? instead : x))
+ const p = deps.store.save(list).then(
(outcome) => {
sealRefused = outcome === 'memory-only'
return outcome !== 'failed'
@@ -567,6 +572,7 @@ export function createWatchLinkService(deps: WatchLinkServiceDeps): WatchLinkSer
// SYNCHRONOUSLY, before any I/O: the host's lock rests on this flag (it reads the record live
// and never writes it). Never undone: a lock whose write fails still holds until quit.
if (r.control) r.control.locked = true
+ takeTurn(r, 'locked') // an "allow again" still being written must not land over it
if (records.get(r.linkId) === r) {
void persist().then((saved) => {
if (!saved) warn("a Control link's lock could not be saved; it holds until nodeterm quits")
@@ -695,30 +701,82 @@ export function createWatchLinkService(deps: WatchLinkServiceDeps): WatchLinkSer
}
}
+ /** Each owner change (and a lock) takes a TURN on the field it touches; an earlier change to the
+ * same field still being written sees it lost its turn and neither undoes nor applies anything. */
+ type ControlField = 'enabled' | 'locked' | 'password'
+ const turns = new WeakMap<WatchLinkRecord, Record<ControlField, number>>()
+ function takeTurn(r: WatchLinkRecord, f: ControlField): number {
+ const t = turns.get(r) ?? { enabled: 0, locked: 0, password: 0 }
+ turns.set(r, t)
+ return ++t[f]
+ }
+ const hasTurn = (r: WatchLinkRecord, f: ControlField, n: number): boolean => turns.get(r)?.[f] === n
+
/**
- * An owner's change to a Control link. Applied in memory and told to the host AT ONCE (typing off or
- * a replaced password must not wait on the disk), then written. A write that fails, or does not
- * answer within PERSIST_TIMEOUT_MS, undoes the change (`undo` restores only what is still this
- * change's own value), tells the host again, queues the corrected list behind the write, and answers
- * false: the owner is never told a change was kept that the next launch would not have.
+ * An owner's change that NARROWS access (typing off, a new password): applied in memory and told to
+ * the host AT ONCE, then written. A write that fails, or does not answer within PERSIST_TIMEOUT_MS,
+ * undoes the change — only while it still holds the field's turn, and `undo` restores only what is
+ * still this change's own value — tells the host again, queues the corrected list behind the write,
+ * and answers false.
*/
- async function changeControl(
+ async function narrowControl(
r: ControlRecord,
+ field: ControlField,
o: { apply(): void; undo(): void; host(h: LinkHost): void; undoHost(h: LinkHost): void }
): Promise<boolean> {
+ const turn = takeTurn(r, field)
o.apply()
tellHost(r.linkId, o.host)
emitState()
const written = await within(persist(), persistTimeoutMs)
if (written === true) return true
- o.undo()
- tellHost(r.linkId, o.undoHost)
+ if (hasTurn(r, field, turn)) {
+ o.undo()
+ tellHost(r.linkId, o.undoHost)
+ }
if (records.get(r.linkId) === r) void persist()
emitState()
warn("an owner's change to a Control link could not be saved; it was undone")
return false
}
+ /**
+ * An owner's change that WIDENS access (typing on, allow again): written FIRST, from a copy of the
+ * record — the record the host reads is untouched, so nobody can unlock during the write — and
+ * applied to the record and told to the host only once that write landed. A write that fails or does
+ * not answer changes nothing in memory (the list as it is is queued behind it) and answers false. A
+ * later change to the same field wins: this one is then not applied, and the list as memory holds it
+ * is written again over this write's copy.
+ */
+ async function widenControl(
+ r: ControlRecord,
+ field: ControlField,
+ o: { change(c: WatchLinkControlRecord): void; host(h: LinkHost): void }
+ ): Promise<boolean> {
+ const turn = takeTurn(r, field)
+ const next = { ...r.control }
+ o.change(next)
+ const write = persist({ ...r, control: next })
+ const written = await within(write, persistTimeoutMs)
+ const live = liveControl(r.linkId) === r
+ if (written !== true) {
+ if (live) void persist()
+ warn("an owner's change to a Control link could not be saved; nothing changed")
+ return false
+ }
+ if (!live) return false
+ if (!hasTurn(r, field, turn)) {
+ void persist() // this write's copy is on disk; memory says what the later change made of it
+ return true
+ }
+ o.change(r.control)
+ // A write issued meanwhile snapshotted the record before this change, and lands after this one.
+ if (lastWrite !== write) void persist()
+ tellHost(r.linkId, o.host)
+ emitState()
+ return true
+ }
+
return {
init,
@@ -751,8 +809,10 @@ export function createWatchLinkService(deps: WatchLinkServiceDeps): WatchLinkSer
try {
h = await scrypt(() => hashPassword(parsed.password as string))
} catch (err) {
+ // `unsupported` ("can't be created here right now"): the one error that names no cause —
+ // `network` would say nodeterm's service could not be reached, which is not what happened.
warn(`hashing a control password failed (${errorName(err)}); nothing was created`)
- return fail('network')
+ return fail('unsupported')
}
parsed.password = null
control = { enabled: true, locked: false, salt: h.salt, hash: h.hash }
@@ -903,14 +963,26 @@ export function createWatchLinkService(deps: WatchLinkServiceDeps): WatchLinkSer
const r = liveControl(linkId)
if (!r || typeof enabled !== 'boolean') return false
const c = r.control
- if (c.enabled === enabled) return true
- const before = c.enabled
- return changeControl(r, {
+ if (c.enabled === enabled) {
+ // Nothing to change here — but it is still the owner's latest word on this field: an earlier
+ // change still being written must not land over it.
+ takeTurn(r, 'enabled')
+ return true
+ }
+ if (enabled) {
+ return widenControl(r, 'enabled', {
+ change: (x) => {
+ x.enabled = true
+ },
+ host: (h) => h.controlChanged()
+ })
+ }
+ return narrowControl(r, 'enabled', {
apply: () => {
- c.enabled = enabled
+ c.enabled = false
},
undo: () => {
- if (c.enabled === enabled) c.enabled = before
+ if (c.enabled === false) c.enabled = true
},
host: (h) => h.controlChanged(),
undoHost: (h) => h.controlChanged()
@@ -931,7 +1003,7 @@ export function createWatchLinkService(deps: WatchLinkServiceDeps): WatchLinkSer
if (!r) return false
const c = r.control
const before = { salt: c.salt, hash: c.hash }
- return changeControl(r, {
+ return narrowControl(r, 'password', {
apply: () => {
c.salt = h.salt
c.hash = h.hash
@@ -951,18 +1023,15 @@ export function createWatchLinkService(deps: WatchLinkServiceDeps): WatchLinkSer
async allowControl(linkId) {
const r = liveControl(linkId)
if (!r) return false
- const c = r.control
- if (!c.locked) return true
- return changeControl(r, {
- apply: () => {
- c.locked = false
- },
- // Locking again is always safe (and a lock that arrived meanwhile is the same state).
- undo: () => {
- c.locked = true
+ if (!r.control.locked) {
+ takeTurn(r, 'locked')
+ return true
+ }
+ return widenControl(r, 'locked', {
+ change: (x) => {
+ x.locked = false
},
- host: (h) => h.allowControl(),
- undoHost: (h) => h.controlChanged()
+ host: (h) => h.allowControl()
})
},
diff --git a/src/shared/watch-link-types.ts b/src/shared/watch-link-types.ts
index 895cbe7ca..f5f5e162f 100644
--- a/src/shared/watch-link-types.ts
+++ b/src/shared/watch-link-types.ts
@@ -48,7 +48,9 @@ export interface CreateWatchLinkRequest {
* - `unsupported` — this surface cannot create links: the Server Edition until it has a license
* layer ("Live links need a Pro license on this server — not available in the Server Edition
* yet", never an Upgrade button — R43), a relay tab ("Live links are created on the machine that
- * runs this terminal"), a client that is not the machine's owner, or an app that is quitting.
+ * runs this terminal"), a client that is not the machine's owner, or an app that is quitting. Also
+ * a Control link whose password this machine could not hash (scrypt failed; nothing was created
+ * anywhere): the desktop copy names no cause, and every other kind names one that is not it.
* - `ttl-unsupported` — the API refused an Unlimited link (an older server): pick an end time.
* - `control-unsupported` — a Control link on a terminal that cannot take typed input safely (a
* Zellij session, whose key bindings would reach every session).