From e37cfe13d9405c0a0656af9f0365a4e356f9daf1 Mon Sep 17 00:00:00 2001 From: repeat98 Date: Mon, 30 Nov 2026 20:02:27 +0100 Subject: [PATCH] Fix: a trial reports itself running or rolled back only once a USB function has reconnected A USB Audio trial takes the unit off USB a second after it starts and after it ends. The procedure's soak started at once and lost its link 0.8 s in, and the Part put-back after it found the unit away (0.4.2 on a development twin, 27 November 2026; again 0.4.3 on a 0.8.5 twin, 30 November 2026). trial() now waits, at most 40 s, until the base's USB function (request 41) is settled on what the modules ask for; the serve gives a try or remove those 40 s too. Written on 27 November (cbcd00b70) after #2306 had merged, so it never reached main. Co-Authored-By: Claude Opus 5.5 --- .../2026-11-30-trial-waits-usb-function.md | 1 + scripts/device.mjs | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 changelog/2026-11-30-trial-waits-usb-function.md diff --git a/changelog/2026-11-30-trial-waits-usb-function.md b/changelog/2026-11-30-trial-waits-usb-function.md new file mode 100644 index 0000000000..9a3c0722b0 --- /dev/null +++ b/changelog/2026-11-30-trial-waits-usb-function.md @@ -0,0 +1 @@ +Module tests on the Octatrack: a USB Audio trial now reports itself running, or rolled back, only once the Octatrack is back on USB, so the soak and the readings after it no longer lose the unit to its reconnect. diff --git a/scripts/device.mjs b/scripts/device.mjs index df87052e12..51b9dc712f 100644 --- a/scripts/device.mjs +++ b/scripts/device.mjs @@ -680,6 +680,7 @@ async function trial(session, pkg) { const original = session.status const baseline = ((await transport.capabilities())?.features ?? 0) & RuntimeFeature.moduleSets ? await transport.setIdentity() : undefined await stopping(() => session.stage(pkg, { signal: interrupt.signal })); await session.activate(); await session.startTrial() + await usbSettled() console.log(`trial: ${pkg.sha256.slice(0, 16)}… running`) for (let second = 1; second <= seconds && !interrupt.signal.aborted; second++) { await wait(1000) @@ -718,8 +719,25 @@ async function trial(session, pkg) { } const left = Date.now(), status = await session.leaveUploadMode() console.log(`left upload mode in ${Date.now() - left} ms`) // the card-set save runs first, in the same task + await usbSettled() return status } +/** A package with a USB function (USB Audio) takes the unit off USB a second or so after its trial starts or ends, and + * up to UF_PATIENCE later while it plays (usb_function.c): wait until the base's USB function (request 41) has settled on + * what the modules ask for, so the next reading or soak does not meet the reconnect. 40 s at most; a base without USB + * functions answers at once. */ +async function usbSettled() { + const start = Date.now(), took = () => ((Date.now() - start) / 1000).toFixed(1) + ' s' + for (; Date.now() - start < 40000; await wait(500)) { + const reply = await unit.controlTransferIn({ requestType: 'vendor', recipient: 'interface', request: 41, value: 0, index }, 8).catch(() => undefined) + if (!reply) continue // away: the reconnect is under way + if (reply.status !== 'ok' || reply.data?.byteLength !== 8) return // no ot_usb_functions + // live: the configuration the host read holds a module's function; table: a module asks for one (set as the trial publishes) + const [state, live, table] = new Uint8Array(reply.data.buffer, reply.data.byteOffset, 3) + if (state === 0 && !live === !table) { if (Date.now() - start > 1000) console.log('USB function settled after ' + took()); return } + } + console.log('USB function not settled after ' + took()) +} /** After a RAM boot or flash: wait until the unit has gone away and come back far enough to answer HELLO, and has started again. * `before` is the log read before arming (readLog): the unit is back only on a larger boot number, so a USB drop of the same @@ -790,7 +808,8 @@ if (command === 'serve') { line += d if (!line.includes('\n')) return const request = line.slice(0, line.indexOf('\n')), waits = [...request.matchAll(/\bw(\d+)\b/g)].reduce((sum, m) => sum + Number(m[1]), 0) - const limit = 20000 + waits // 20 s beyond the waits the sequence asks for: a hung request answers at once + // 20 s beyond the waits the sequence asks for: a hung request answers at once. A try or remove also waits for its USB function (usbSettled). + const limit = 20000 + waits + (/^(?:try|remove)\b/.test(request) ? 40000 : 0) serial(() => { const work = capture(request, Date.now() + limit) Promise.race([work, wait(limit).then(() => `error: no answer from the unit within ${Math.round(limit / 1000)} s\n`)]).then(reply => c.end(reply))