Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(cable): a board that greeted as a dial is never judged foreign again (#1596)

0xdiego2525344cf6d16f
diff --git a/cli/src/cable/cableFleet.spec.ts b/cli/src/cable/cableFleet.spec.ts
index f3873109e..84e0461d0 100644
--- a/cli/src/cable/cableFleet.spec.ts
+++ b/cli/src/cable/cableFleet.spec.ts
@@ -509,6 +509,21 @@ describe('a board that is not a dial', () => {
} finally { await second.fleet.stop() }
})
+ it('remembers a board that greeted as a dial, so a later silent probe never marks it foreign', async () => {
+ const file = join(mkdtempSync(join(tmpdir(), 'fleet-verdicts-')), 'dial-ports.json')
+ const s = scenario({ file })
+ try {
+ s.fleet.start()
+ await vi.waitFor(() => expect(s.f.ports.map(p => p.path)).toContain('/dev/tim'))
+ await s.f.greet(s.f.ports.filter(p => p.path === '/dev/tim'))
+ await vi.waitFor(() => expect(s.fleet.isConnected).toBe(true))
+ } finally { await s.fleet.stop() }
+ const dial = { ...device('/dev/tim', 'AA:01'), session: '201' }
+ const verdicts = new DialVerdicts(file)
+ verdicts.markForeign(dial)
+ expect(verdicts.isForeign(dial)).toBe(false)
+ })
+
it('is never opened while another program has it, and only then once that program is done', async () => {
let busy = true
const s = scenario({ inUse: async path => path === '/dev/other' && busy })
diff --git a/cli/src/cable/cableFleet.ts b/cli/src/cable/cableFleet.ts
index 328875a26..3d3c13ad2 100644
--- a/cli/src/cable/cableFleet.ts
+++ b/cli/src/cable/cableFleet.ts
@@ -191,6 +191,7 @@ export class CableFleet {
if (this.stopped) return
const entry: Entry = { port, attached: false, status: { attached: false }, session: undefined!, faults: [] }
const attached = () => {
+ this.verdicts.markDial(port)
if (entry.attached) return
const first = ![...this.entries.values()].some(e => e.attached)
entry.attached = true
diff --git a/cli/src/cable/dialPortVerdicts.spec.ts b/cli/src/cable/dialPortVerdicts.spec.ts
index c625f5f3d..a173c4625 100644
--- a/cli/src/cable/dialPortVerdicts.spec.ts
+++ b/cli/src/cable/dialPortVerdicts.spec.ts
@@ -55,4 +55,18 @@ describe('verdicts on USB boards', () => {
verdicts.markForeign(board('1'))
expect(JSON.parse(readFileSync(file, 'utf8'))).toHaveProperty('AA:01')
})
+
+ it('never judges foreign a board that once greeted as a dial, across restarts and attachments', () => {
+ // A Harness Pro rebooting while the daemon restarted stayed silent past the probe, was marked foreign
+ // and left on its "Harness" screen for hours (a user's logs, 10-15, 10-16 and 10-22).
+ const file = join(mkdtempSync(join(tmpdir(), 'verdicts-')), 'dial-ports.json')
+ new DialVerdicts(file).markDial(board('1'))
+ const next = new DialVerdicts(file)
+ next.markForeign(board('2'))
+ expect(next.isForeign(board('2'))).toBe(false)
+ expect(new DialVerdicts(file).isForeign(board('3'))).toBe(false)
+ // Another board is still judged on its own.
+ next.markForeign(board('2', 'BB:02'))
+ expect(next.isForeign(board('2', 'BB:02'))).toBe(true)
+ })
})
diff --git a/cli/src/cable/dialPortVerdicts.ts b/cli/src/cable/dialPortVerdicts.ts
index e46fe8498..0facadcc0 100644
--- a/cli/src/cable/dialPortVerdicts.ts
+++ b/cli/src/cable/dialPortVerdicts.ts
@@ -6,7 +6,8 @@
// cost another probe each time. It stops holding when the board is unplugged (a new attachment,
// DialPort.session), when someone worked on it and let go (the fleet clears it: a flash is exactly how a
// board becomes a dial, and a reset over USB-Serial/JTAG does NOT change the attachment, measured), or
-// when it gets old.
+// when it gets old. A board that once greeted as a dial is remembered as one and never judged foreign
+// again: a dial rebooting while the daemon restarts is silent too, and a verdict then strands it.
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs'
import { dirname } from 'node:path'
import type { DialPort } from './serial.js'
@@ -17,7 +18,7 @@ const KNOWN_FOR_MS = 6 * 60 * 60_000
/** A verdict about a port with no attachment identity is only a pause, since nothing says when it changes. */
const UNKNOWN_FOR_MS = 10 * 60_000
-interface Verdict { session?: string; at: number }
+interface Verdict { session?: string; at: number; dial?: true }
const keyOf = (port: DialPort) => (port.serialNumber ?? port.path).toUpperCase()
@@ -30,7 +31,7 @@ export class DialVerdicts {
const raw = JSON.parse(readFileSync(file, 'utf8')) as Record<string, unknown>
for (const [key, value] of Object.entries(raw)) {
const v = value as Partial<Verdict> | null
- if (v && typeof v.at === 'number') this.foreign.set(key, { at: v.at, ...(typeof v.session === 'string' ? { session: v.session } : {}) })
+ if (v && typeof v.at === 'number') this.foreign.set(key, { at: v.at, ...(typeof v.session === 'string' ? { session: v.session } : {}), ...(v.dial === true ? { dial: true as const } : {}) })
}
} catch { /* unreadable: start with no opinions, and rewrite it on the next verdict */ }
}
@@ -38,7 +39,7 @@ export class DialVerdicts {
/** Was this very attachment of this board already found not to be a dial? */
isForeign(port: DialPort): boolean {
const verdict = this.foreign.get(keyOf(port))
- if (!verdict) return false
+ if (!verdict || verdict.dial) return false
const age = this.now() - verdict.at
if (verdict.session === undefined || port.session === undefined) return age < UNKNOWN_FOR_MS
return verdict.session === port.session && age < KNOWN_FOR_MS
@@ -46,10 +47,19 @@ export class DialVerdicts {
/** Forget the verdict: somebody worked on this board since it was made. */
clear(port: DialPort): void {
+ if (this.foreign.get(keyOf(port))?.dial) return
if (this.foreign.delete(keyOf(port))) this.save()
}
+ /** This board greeted as a dial: it is one, whatever a later silence looks like. */
+ markDial(port: DialPort): void {
+ if (this.foreign.get(keyOf(port))?.dial) return
+ this.foreign.set(keyOf(port), { at: this.now(), dial: true })
+ this.save()
+ }
+
markForeign(port: DialPort): void {
+ if (this.foreign.get(keyOf(port))?.dial) return
this.foreign.set(keyOf(port), { at: this.now(), ...(port.session ? { session: port.session } : {}) })
this.save()
}