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): offer firmware per DIAL, not per version

0xdiego2555a7cebc71d1
diff --git a/cli/src/cable/cableSession.spec.ts b/cli/src/cable/cableSession.spec.ts
index a407177da..8e0bf2867 100644
--- a/cli/src/cable/cableSession.spec.ts
+++ b/cli/src/cable/cableSession.spec.ts
@@ -228,6 +228,36 @@ describe('cable session', () => {
await session.stop()
})
+ it('offers the image to a SECOND dial, even after a first one took it', async () => {
+ // Found in the field: one dial updated, was unplugged, and a second still on the old image was plugged
+ // into the same daemon and never offered anything. `offered` held bare version strings, so it was a
+ // statement about the IMAGE rather than about the board — the second dial was refused because that
+ // version had been offered to someone else, and nothing in the log said so.
+ const image = Buffer.alloc(2048, 9)
+ const host = makeHost({
+ firmwareFor: async () => ({ version: '9.9.9', image, sha256: 'x'.repeat(64) }),
+ })
+ const { session, port } = await connect(host)
+
+ port.say({ t: 'hello', product: 'harness', fw: '0.0.1', proto: 2, mac: 'aa:bb' })
+ await settle()
+ expect(port.types().filter((t) => t === 'fw.offer')).toHaveLength(1)
+
+ // The first dial takes it and reboots. Without this the transfer is still in flight and the guard
+ // that refuses a SECOND concurrent offer would be what answers below — a different rule, and the
+ // wrong one to be testing here.
+ port.say({ t: 'fw.done' })
+ await settle()
+
+ // A different board, same daemon, same port — the port does not close when a dial reboots, which is
+ // why the session's memory of what it has offered outlives the dial it offered to.
+ port.sent.length = 0
+ port.say({ t: 'hello', product: 'harness', fw: '0.0.1', proto: 2, mac: 'cc:dd' })
+ await settle()
+ expect(port.types().filter((t) => t === 'fw.offer')).toHaveLength(1)
+ await session.stop()
+ })
+
it('does not wedge forever when opening the port hangs', async () => {
// The `opening` guard keeps two opens from racing on one tty — a race that once left five read loops
// shredding a single byte stream. But a guard released only when the attempt FINISHES is a guard held
diff --git a/cli/src/cable/cableSession.ts b/cli/src/cable/cableSession.ts
index 6d1138a80..a9f8ec9f9 100644
--- a/cli/src/cable/cableSession.ts
+++ b/cli/src/cable/cableSession.ts
@@ -243,6 +243,7 @@ export class CableSession {
/** A firmware transfer in flight, and the versions already tried this session. */
private transfer: FirmwareTransfer | null = null
+ /** `<mac>:<version>` already offered on this port. The durable, cross-port guard is `mayOffer`. */
private offered = new Set<string>()
/** Voice capture in flight: PCM chunks as they arrive, plus what `voice.begin` said about them. */
@@ -410,6 +411,15 @@ export class CableSession {
// A new port is a new dial until proven otherwise; tell it everything.
this.lastAgentsKey = ''
this.lastMachinesKey = ''
+ // INCLUDING which images it has been offered. `offered` holds bare version strings and named no dial,
+ // so without this it outlived the session its comment claims it belongs to and became per-DAEMON:
+ // offer 0.0.42 to one dial, unplug it, plug in a second still on 0.0.41, and the second is refused
+ // because the version — not the board — had already been offered. It sat there on the old image with
+ // nothing in the log to say why.
+ //
+ // Clearing it does NOT reopen the flash loop this guards against. That is `mayOffer`'s job, and it is
+ // keyed by MAC and outlives the port precisely so this one does not have to.
+ this.offered.clear()
this.lastRx = Date.now()
this.host.log(`cable: open on ${opened.path}`)
}
@@ -672,9 +682,16 @@ export class CableSession {
private async maybeOfferFirmware(runningVersion: string): Promise<void> {
if (!this.host.firmwareFor || this.transfer || !runningVersion) return
const candidate = await this.host.firmwareFor(runningVersion).catch(() => null)
- if (!candidate || this.offered.has(candidate.version)) return
- if (!this.mayOffer(this.greetedMac ?? 'unknown', candidate.version)) return
- this.offered.add(candidate.version)
+ // Keyed by DIAL as well as version. Holding bare version strings made this a statement about the
+ // image rather than about the board: offer 0.0.42 to one dial, swap in a second still on 0.0.41, and
+ // the second was refused because that version had been offered — to someone else. It then sat on the
+ // old image with nothing in the log to say why, which is how it was found.
+ if (!candidate) return
+ const mac = this.greetedMac ?? 'unknown'
+ const offerKey = `${mac}:${candidate.version}`
+ if (this.offered.has(offerKey)) return
+ if (!this.mayOffer(mac, candidate.version)) return
+ this.offered.add(offerKey)
this.host.log(`cable: offering firmware ${candidate.version} (${candidate.image.length} B)`)
this.transfer = new FirmwareTransfer(