@camstack/types 1.2.142 → 1.2.143
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/addon.js +1 -1
- package/dist/addon.mjs +1 -1
- package/dist/capabilities/device-manager.cap.d.ts +7 -0
- package/dist/capabilities/device-provider.cap.d.ts +30 -0
- package/dist/device/base-device-provider.d.ts +67 -1
- package/dist/device/device-restore-retry.d.ts +93 -0
- package/dist/device/index.d.ts +3 -1
- package/dist/generated/addon-api.d.ts +7 -0
- package/dist/generated/device-proxy.d.ts +2 -0
- package/dist/generated/method-access-map.d.ts +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +407 -25
- package/dist/index.mjs +405 -26
- package/dist/{sleep-Cwo3fRlv.mjs → sleep-B195W080.mjs} +1 -0
- package/dist/{sleep-BDmIj1HV.js → sleep-jdpPltQH.js} +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_event_category = require("./event-category-BaEgqJNv.js");
|
|
3
|
-
const require_sleep = require("./sleep-
|
|
3
|
+
const require_sleep = require("./sleep-jdpPltQH.js");
|
|
4
4
|
const require_canonical_hash = require("./canonical-hash-DNV8S5ET.js");
|
|
5
5
|
const require_enums = require("./enums.js");
|
|
6
6
|
const require_err_msg = require("./err-msg-COpsHMw2.js");
|
|
@@ -10117,6 +10117,35 @@ var deviceProviderCapability = {
|
|
|
10117
10117
|
name: zod.z.string(),
|
|
10118
10118
|
type: zod.z.string()
|
|
10119
10119
|
}))),
|
|
10120
|
+
/**
|
|
10121
|
+
* Tear down and reconstruct ONE device in place from its persisted rows —
|
|
10122
|
+
* touching no other device this provider owns.
|
|
10123
|
+
*
|
|
10124
|
+
* The primitive `deviceManager.migrateDevice` uses to flush the two
|
|
10125
|
+
* migrated numbers: after `swapIds` the runner's live instance still
|
|
10126
|
+
* carries the PRE-swap numeric id (baked into the object, its native-cap
|
|
10127
|
+
* registrations and its log tags), and a live object cannot be renumbered.
|
|
10128
|
+
* Before this method the only flush was restarting the whole owning addon
|
|
10129
|
+
* — which took every camera the provider owns down with it (28 devices
|
|
10130
|
+
* for one migrated camera, measured 2026-09-04, and the morning of the
|
|
10131
|
+
* same day ~27 devices' native caps did not come back on their own).
|
|
10132
|
+
*
|
|
10133
|
+
* Keyed by `stableId`, deliberately: the numeric id is exactly the thing
|
|
10134
|
+
* that changes. The reply carries the id the device answers on NOW.
|
|
10135
|
+
* Implemented once in `BaseDeviceProvider` — decommission the live
|
|
10136
|
+
* instance (if any), then re-create from the persisted row: the same
|
|
10137
|
+
* teardown/rehydrate pair every graceful shutdown + boot already uses.
|
|
10138
|
+
* An RPC, never an event: a dropped event would leave the runner writing
|
|
10139
|
+
* against the wrong camera (D8).
|
|
10140
|
+
*
|
|
10141
|
+
* Construction can dial hardware, and the migrated source is
|
|
10142
|
+
* characteristically dead — the timeout covers a full activate window
|
|
10143
|
+
* rather than the 60 s default.
|
|
10144
|
+
*/
|
|
10145
|
+
reloadDevice: require_sleep.method(zod.z.object({ stableId: zod.z.string() }), zod.z.object({ deviceId: zod.z.number() }), {
|
|
10146
|
+
kind: "mutation",
|
|
10147
|
+
timeoutMs: 3 * 6e4
|
|
10148
|
+
}),
|
|
10120
10149
|
supportsDiscovery: require_sleep.method(zod.z.object({}), zod.z.boolean()),
|
|
10121
10150
|
/**
|
|
10122
10151
|
* Run a network scan. `params` carries optional provider-specific scan
|
|
@@ -10511,13 +10540,21 @@ var deviceManagerCapability = {
|
|
|
10511
10540
|
* `sourceStillLive` names what stayed live; empty is the only value that
|
|
10512
10541
|
* means the old hardware is quiet. The migration proceeds either way —
|
|
10513
10542
|
* refusing would refuse the case this exists for.
|
|
10543
|
+
*
|
|
10544
|
+
* **Safe to retry.** A duplicate call while a migration involving either
|
|
10545
|
+
* device is in flight is REFUSED, never queued; a repeat of a swap that
|
|
10546
|
+
* already completed (matched against the `addonId`/`stableId` fingerprint
|
|
10547
|
+
* the swap left on the rows, within 15 min) is a no-op returning the
|
|
10548
|
+
* original report. A blind re-run can no longer silently undo the
|
|
10549
|
+
* migration it retried.
|
|
10514
10550
|
*/
|
|
10515
10551
|
migrateDevice: require_sleep.method(zod.z.object({
|
|
10516
10552
|
sourceId: zod.z.number(),
|
|
10517
10553
|
targetId: zod.z.number()
|
|
10518
10554
|
}), MigrateDeviceResultSchema, {
|
|
10519
10555
|
kind: "mutation",
|
|
10520
|
-
auth: "admin"
|
|
10556
|
+
auth: "admin",
|
|
10557
|
+
timeoutMs: 12 * 6e4
|
|
10521
10558
|
}),
|
|
10522
10559
|
/** Register a device in the DB + in-memory registry. Called by DeviceManagerApi.register(). */
|
|
10523
10560
|
registerDevice: require_sleep.method(DeviceRegisterPayloadSchema, zod.z.void(), { kind: "mutation" }),
|
|
@@ -36391,6 +36428,152 @@ var BaseDevice = class {
|
|
|
36391
36428
|
}
|
|
36392
36429
|
};
|
|
36393
36430
|
//#endregion
|
|
36431
|
+
//#region src/device/device-restore-retry.ts
|
|
36432
|
+
/**
|
|
36433
|
+
* Delays before retry rounds 1..N — the round count IS the bound.
|
|
36434
|
+
* 10 s catches "the hub was busy for a moment"; the full schedule
|
|
36435
|
+
* (10 + 30 + 90 s of waiting, plus up to one 60 s transport timeout
|
|
36436
|
+
* per attempt) covers a device-manager lock held for minutes — the
|
|
36437
|
+
* 2026-09-04 outage's migration hold was ~3.5 min.
|
|
36438
|
+
*/
|
|
36439
|
+
var DEVICE_RESTORE_RETRY_DELAYS_MS = [
|
|
36440
|
+
1e4,
|
|
36441
|
+
3e4,
|
|
36442
|
+
9e4
|
|
36443
|
+
];
|
|
36444
|
+
/** Lane width for retry rounds. See module docblock — retries are
|
|
36445
|
+
* evidence of congestion, so they never re-stampede full-width. */
|
|
36446
|
+
var DEVICE_RESTORE_RETRY_CONCURRENCY = 4;
|
|
36447
|
+
/** Abortable sleep — resolves early (never rejects) on abort. */
|
|
36448
|
+
function sleep$1(ms, signal) {
|
|
36449
|
+
return new Promise((resolve) => {
|
|
36450
|
+
if (signal.aborted) {
|
|
36451
|
+
resolve();
|
|
36452
|
+
return;
|
|
36453
|
+
}
|
|
36454
|
+
const onAbort = () => {
|
|
36455
|
+
clearTimeout(timer);
|
|
36456
|
+
resolve();
|
|
36457
|
+
};
|
|
36458
|
+
const timer = setTimeout(() => {
|
|
36459
|
+
signal.removeEventListener("abort", onAbort);
|
|
36460
|
+
resolve();
|
|
36461
|
+
}, ms);
|
|
36462
|
+
timer.unref?.();
|
|
36463
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
36464
|
+
});
|
|
36465
|
+
}
|
|
36466
|
+
/** Drain `items` through at most `width` concurrent lanes. `fn` must
|
|
36467
|
+
* not reject (callers wrap their own try/catch). */
|
|
36468
|
+
async function runWithConcurrency(items, width, fn) {
|
|
36469
|
+
const queue = [...items];
|
|
36470
|
+
const laneCount = Math.max(1, Math.min(width, queue.length));
|
|
36471
|
+
const lane = async () => {
|
|
36472
|
+
for (;;) {
|
|
36473
|
+
const item = queue.shift();
|
|
36474
|
+
if (item === void 0) return;
|
|
36475
|
+
await fn(item);
|
|
36476
|
+
}
|
|
36477
|
+
};
|
|
36478
|
+
await Promise.all(Array.from({ length: laneCount }, lane));
|
|
36479
|
+
}
|
|
36480
|
+
var DeviceRestoreRetryScheduler = class {
|
|
36481
|
+
#logger;
|
|
36482
|
+
#attempt;
|
|
36483
|
+
#onPermanentFailure;
|
|
36484
|
+
#delaysMs;
|
|
36485
|
+
#concurrency;
|
|
36486
|
+
#now;
|
|
36487
|
+
#abort = new AbortController();
|
|
36488
|
+
constructor(options) {
|
|
36489
|
+
this.#logger = options.logger;
|
|
36490
|
+
this.#attempt = options.attempt;
|
|
36491
|
+
this.#onPermanentFailure = options.onPermanentFailure;
|
|
36492
|
+
this.#delaysMs = options.delaysMs ?? DEVICE_RESTORE_RETRY_DELAYS_MS;
|
|
36493
|
+
this.#concurrency = options.concurrency ?? 4;
|
|
36494
|
+
this.#now = options.now ?? Date.now;
|
|
36495
|
+
}
|
|
36496
|
+
/** Stop retrying (shutdown). Pending entries are NOT marked
|
|
36497
|
+
* permanently failed — the next boot restores them from disk. */
|
|
36498
|
+
cancel() {
|
|
36499
|
+
this.#abort.abort();
|
|
36500
|
+
}
|
|
36501
|
+
/**
|
|
36502
|
+
* Run the bounded retry rounds. Resolves when every entry has either
|
|
36503
|
+
* restored, been marked permanently failed, or the scheduler was
|
|
36504
|
+
* cancelled. Never rejects.
|
|
36505
|
+
*/
|
|
36506
|
+
async run(initialFailures) {
|
|
36507
|
+
let pending = initialFailures.map((failure) => ({
|
|
36508
|
+
saved: failure.saved,
|
|
36509
|
+
lastError: failure.error,
|
|
36510
|
+
attempts: 1
|
|
36511
|
+
}));
|
|
36512
|
+
for (let round = 0; round < this.#delaysMs.length; round += 1) {
|
|
36513
|
+
if (pending.length === 0 || this.#abort.signal.aborted) break;
|
|
36514
|
+
await sleep$1(this.#delaysMs[round] ?? 0, this.#abort.signal);
|
|
36515
|
+
if (this.#abort.signal.aborted) break;
|
|
36516
|
+
pending = await this.#runRound(pending, round);
|
|
36517
|
+
}
|
|
36518
|
+
if (this.#abort.signal.aborted) return [];
|
|
36519
|
+
const terminal = pending.map((entry) => ({
|
|
36520
|
+
deviceId: entry.saved.id,
|
|
36521
|
+
stableId: entry.saved.stableId,
|
|
36522
|
+
type: String(entry.saved.type),
|
|
36523
|
+
attempts: entry.attempts,
|
|
36524
|
+
lastError: entry.lastError,
|
|
36525
|
+
failedAt: this.#now()
|
|
36526
|
+
}));
|
|
36527
|
+
for (const failure of terminal) this.#onPermanentFailure(failure);
|
|
36528
|
+
return terminal;
|
|
36529
|
+
}
|
|
36530
|
+
/** One retry round: parents first (phase 0), then hub-adopted
|
|
36531
|
+
* children (phase 1) — a child's attempt depends on its parent
|
|
36532
|
+
* having landed, exactly like the initial two-pass restore. */
|
|
36533
|
+
async #runRound(pending, round) {
|
|
36534
|
+
const next = [];
|
|
36535
|
+
const parents = pending.filter((entry) => entry.saved.parentDeviceId === null);
|
|
36536
|
+
const children = pending.filter((entry) => entry.saved.parentDeviceId !== null);
|
|
36537
|
+
for (const phase of [parents, children]) await runWithConcurrency(phase, this.#concurrency, async (entry) => {
|
|
36538
|
+
if (this.#abort.signal.aborted) {
|
|
36539
|
+
next.push(entry);
|
|
36540
|
+
return;
|
|
36541
|
+
}
|
|
36542
|
+
const attemptNo = entry.attempts + 1;
|
|
36543
|
+
try {
|
|
36544
|
+
await this.#attempt(entry.saved);
|
|
36545
|
+
this.#logger.info("Device restored on retry", {
|
|
36546
|
+
tags: {
|
|
36547
|
+
deviceId: entry.saved.id,
|
|
36548
|
+
stableId: entry.saved.stableId
|
|
36549
|
+
},
|
|
36550
|
+
meta: { attempt: attemptNo }
|
|
36551
|
+
});
|
|
36552
|
+
} catch (err) {
|
|
36553
|
+
const lastError = err instanceof Error ? err.message : String(err);
|
|
36554
|
+
const remainingRetries = this.#delaysMs.length - (round + 1);
|
|
36555
|
+
this.#logger.warn("Device restore retry failed", {
|
|
36556
|
+
tags: {
|
|
36557
|
+
deviceId: entry.saved.id,
|
|
36558
|
+
stableId: entry.saved.stableId
|
|
36559
|
+
},
|
|
36560
|
+
meta: {
|
|
36561
|
+
attempt: attemptNo,
|
|
36562
|
+
remainingRetries,
|
|
36563
|
+
error: lastError
|
|
36564
|
+
}
|
|
36565
|
+
});
|
|
36566
|
+
next.push({
|
|
36567
|
+
saved: entry.saved,
|
|
36568
|
+
lastError,
|
|
36569
|
+
attempts: attemptNo
|
|
36570
|
+
});
|
|
36571
|
+
}
|
|
36572
|
+
});
|
|
36573
|
+
return next;
|
|
36574
|
+
}
|
|
36575
|
+
};
|
|
36576
|
+
//#endregion
|
|
36394
36577
|
//#region src/device/base-device-provider.ts
|
|
36395
36578
|
/**
|
|
36396
36579
|
* Convert an IDevice to the flat DeviceSummary shape expected by the
|
|
@@ -36441,6 +36624,7 @@ var BaseDeviceProvider = class extends require_sleep.BaseAddon {
|
|
|
36441
36624
|
}];
|
|
36442
36625
|
}
|
|
36443
36626
|
async onShutdown() {
|
|
36627
|
+
this.cancelRestoreRetries();
|
|
36444
36628
|
const devices = await this.ctx.kernel.devices?.getAll() ?? [];
|
|
36445
36629
|
for (const device of devices) try {
|
|
36446
36630
|
await this.ctx.kernel.devices?.decommission(device.id);
|
|
@@ -36458,9 +36642,16 @@ var BaseDeviceProvider = class extends require_sleep.BaseAddon {
|
|
|
36458
36642
|
async start() {}
|
|
36459
36643
|
async stop() {}
|
|
36460
36644
|
async getStatus() {
|
|
36645
|
+
const all = await this.ctx.kernel.devices?.getAll() ?? [];
|
|
36646
|
+
const summary = this.restoreFailureSummary();
|
|
36647
|
+
if (summary === null) return {
|
|
36648
|
+
connected: true,
|
|
36649
|
+
deviceCount: all.length
|
|
36650
|
+
};
|
|
36461
36651
|
return {
|
|
36462
36652
|
connected: true,
|
|
36463
|
-
deviceCount:
|
|
36653
|
+
deviceCount: all.length,
|
|
36654
|
+
error: summary
|
|
36464
36655
|
};
|
|
36465
36656
|
}
|
|
36466
36657
|
async getDevices() {
|
|
@@ -36550,8 +36741,137 @@ var BaseDeviceProvider = class extends require_sleep.BaseAddon {
|
|
|
36550
36741
|
};
|
|
36551
36742
|
}
|
|
36552
36743
|
async restoreDevices(savedDevices) {
|
|
36553
|
-
await this.onRestoreDevices(savedDevices);
|
|
36554
|
-
if (savedDevices.length
|
|
36744
|
+
const report = await this.onRestoreDevices(savedDevices);
|
|
36745
|
+
if (savedDevices.length === 0) return;
|
|
36746
|
+
if (report && report.failedCount > 0) {
|
|
36747
|
+
this.ctx.logger.warn(`Restored ${report.restoredCount}/${savedDevices.length} ${this.providerName} device(s) — ${report.failedCount} failed, bounded retry scheduled`);
|
|
36748
|
+
return;
|
|
36749
|
+
}
|
|
36750
|
+
const restoredCount = report ? report.restoredCount : savedDevices.length;
|
|
36751
|
+
this.ctx.logger.info(`Restored ${restoredCount} ${this.providerName} device(s)`);
|
|
36752
|
+
}
|
|
36753
|
+
/** Retry schedule. Overridable (tests use millisecond delays). */
|
|
36754
|
+
restoreRetryDelaysMs = DEVICE_RESTORE_RETRY_DELAYS_MS;
|
|
36755
|
+
/** Retry lane width. See `device-restore-retry.ts` for why retries
|
|
36756
|
+
* never re-stampede full-width while the initial pass does (D167). */
|
|
36757
|
+
restoreRetryConcurrency = 4;
|
|
36758
|
+
_restoreRetryScheduler = null;
|
|
36759
|
+
_restoreRetryCompletion = null;
|
|
36760
|
+
_permanentRestoreFailures = /* @__PURE__ */ new Map();
|
|
36761
|
+
/** Settles when the background retry rounds finish (or `null` when
|
|
36762
|
+
* nothing failed). Exposed for tests and subclass diagnostics —
|
|
36763
|
+
* boot NEVER awaits this: the runner's post-init handshake goes out
|
|
36764
|
+
* with the devices that restored, and a late success is announced
|
|
36765
|
+
* through the `native-cap-change` → `updateCaps` path. */
|
|
36766
|
+
get restoreRetryCompletion() {
|
|
36767
|
+
return this._restoreRetryCompletion;
|
|
36768
|
+
}
|
|
36769
|
+
/** Devices that exhausted the retry bound this process lifetime. */
|
|
36770
|
+
get permanentRestoreFailures() {
|
|
36771
|
+
return [...this._permanentRestoreFailures.values()];
|
|
36772
|
+
}
|
|
36773
|
+
/** One-line operator-facing summary for `getStatus().error`, or
|
|
36774
|
+
* `null` when every device restored. */
|
|
36775
|
+
restoreFailureSummary() {
|
|
36776
|
+
if (this._permanentRestoreFailures.size === 0) return null;
|
|
36777
|
+
const ids = [...this._permanentRestoreFailures.keys()].join(", ");
|
|
36778
|
+
return `${this._permanentRestoreFailures.size} device(s) permanently failed restore (deviceIds: ${ids}) — restart the ${this.providerName} provider to retry`;
|
|
36779
|
+
}
|
|
36780
|
+
cancelRestoreRetries() {
|
|
36781
|
+
this._restoreRetryScheduler?.cancel();
|
|
36782
|
+
this._restoreRetryScheduler = null;
|
|
36783
|
+
}
|
|
36784
|
+
recordPermanentRestoreFailure(failure) {
|
|
36785
|
+
this._permanentRestoreFailures.set(failure.deviceId, failure);
|
|
36786
|
+
this.ctx.logger.error("Device restore permanently failed — its capabilities will not register until the provider restarts", {
|
|
36787
|
+
tags: {
|
|
36788
|
+
deviceId: failure.deviceId,
|
|
36789
|
+
stableId: failure.stableId
|
|
36790
|
+
},
|
|
36791
|
+
meta: {
|
|
36792
|
+
type: failure.type,
|
|
36793
|
+
attempts: failure.attempts,
|
|
36794
|
+
error: failure.lastError
|
|
36795
|
+
}
|
|
36796
|
+
});
|
|
36797
|
+
}
|
|
36798
|
+
scheduleRestoreRetries(failures, attempt) {
|
|
36799
|
+
const scheduler = new DeviceRestoreRetryScheduler({
|
|
36800
|
+
logger: this.ctx.logger,
|
|
36801
|
+
delaysMs: this.restoreRetryDelaysMs,
|
|
36802
|
+
concurrency: this.restoreRetryConcurrency,
|
|
36803
|
+
attempt,
|
|
36804
|
+
onPermanentFailure: (failure) => this.recordPermanentRestoreFailure(failure)
|
|
36805
|
+
});
|
|
36806
|
+
this._restoreRetryScheduler = scheduler;
|
|
36807
|
+
this._restoreRetryCompletion = scheduler.run(failures).then(() => void 0).catch((err) => {
|
|
36808
|
+
this.ctx.logger.error("Restore retry scheduler crashed", { meta: { error: err instanceof Error ? err.message : String(err) } });
|
|
36809
|
+
});
|
|
36810
|
+
}
|
|
36811
|
+
/**
|
|
36812
|
+
* Tear down and reconstruct ONE device from its persisted rows — the
|
|
36813
|
+
* `deviceProvider.reloadDevice` cap method. Persistence is never touched,
|
|
36814
|
+
* and no other device this provider owns is disturbed.
|
|
36815
|
+
*
|
|
36816
|
+
* Keyed by `stableId` because the caller's whole reason to be here is that
|
|
36817
|
+
* the NUMERIC id changed (`deviceManager.migrateDevice` swapped it): the
|
|
36818
|
+
* fresh instance resolves its id through `allocateDeviceId`, which returns
|
|
36819
|
+
* whatever number the row carries NOW. The teardown is `decommission` —
|
|
36820
|
+
* exactly what a graceful shutdown runs per device (fires `removeDevice()`,
|
|
36821
|
+
* unregisters native caps, drops the registry entry) — and the rebuild is
|
|
36822
|
+
* the boot restore's own `create()` path, including its pass 2: first-class
|
|
36823
|
+
* children (hub-adopted cameras under an NVR) are decommissioned with the
|
|
36824
|
+
* parent by the cascade and must be re-created explicitly, because only
|
|
36825
|
+
* accessory children come back through `getAccessoryChildren()`.
|
|
36826
|
+
*
|
|
36827
|
+
* Reloading an accessory child directly is refused (no device class) —
|
|
36828
|
+
* reload its parent instead.
|
|
36829
|
+
*/
|
|
36830
|
+
async reloadDevice(input) {
|
|
36831
|
+
const { stableId } = input;
|
|
36832
|
+
const devices = this.ctx.kernel.devices;
|
|
36833
|
+
if (!devices) throw new Error(`${this.providerName}: kernel.devices unavailable — cannot reload`);
|
|
36834
|
+
const live = (await devices.getAll()).find((d) => d.stableId === stableId);
|
|
36835
|
+
if (live) await devices.decommission(live.id);
|
|
36836
|
+
const { id } = await this.ctx.api.deviceManager.allocateDeviceId.mutate({
|
|
36837
|
+
addonId: this.addonId,
|
|
36838
|
+
stableId
|
|
36839
|
+
});
|
|
36840
|
+
const meta = await this.ctx.api.deviceManager.loadMeta.query({ deviceId: id });
|
|
36841
|
+
if (meta === null) throw new Error(`${this.providerName}: no persisted meta for "${stableId}" (id ${id}) — cannot reload`);
|
|
36842
|
+
const deviceType = Object.values(require_sleep.DeviceType).find((t) => t === meta.type);
|
|
36843
|
+
const Class = deviceType !== void 0 ? this.deviceClasses[deviceType] : void 0;
|
|
36844
|
+
if (!Class) throw new Error(`${this.providerName}: no device class for type "${meta.type}" — "${stableId}" is an accessory child; reload its parent instead`);
|
|
36845
|
+
await devices.create(stableId, Class, {}, meta.parentDeviceId ?? null);
|
|
36846
|
+
const rows = await this.ctx.api.deviceManager.listPersistedByAddon.query({ addonId: this.addonId });
|
|
36847
|
+
for (const row of rows) {
|
|
36848
|
+
if (row.parentDeviceId !== id) continue;
|
|
36849
|
+
const childType = Object.values(require_sleep.DeviceType).find((t) => t === row.type);
|
|
36850
|
+
const ChildClass = childType !== void 0 ? this.deviceClasses[childType] : void 0;
|
|
36851
|
+
if (!ChildClass) continue;
|
|
36852
|
+
try {
|
|
36853
|
+
await devices.create(row.stableId, ChildClass, {}, id);
|
|
36854
|
+
} catch (err) {
|
|
36855
|
+
this.ctx.logger.warn("reloadDevice: failed to re-create first-class child", {
|
|
36856
|
+
tags: {
|
|
36857
|
+
deviceId: row.id,
|
|
36858
|
+
stableId: row.stableId
|
|
36859
|
+
},
|
|
36860
|
+
meta: {
|
|
36861
|
+
parentDeviceId: id,
|
|
36862
|
+
error: err instanceof Error ? err.message : String(err)
|
|
36863
|
+
}
|
|
36864
|
+
});
|
|
36865
|
+
}
|
|
36866
|
+
}
|
|
36867
|
+
this.ctx.logger.info("device reloaded in place from persisted rows", {
|
|
36868
|
+
tags: { deviceId: id },
|
|
36869
|
+
meta: {
|
|
36870
|
+
stableId,
|
|
36871
|
+
type: meta.type
|
|
36872
|
+
}
|
|
36873
|
+
});
|
|
36874
|
+
return { deviceId: id };
|
|
36555
36875
|
}
|
|
36556
36876
|
/**
|
|
36557
36877
|
* Restore devices from persisted state. Two-pass:
|
|
@@ -36577,55 +36897,108 @@ var BaseDeviceProvider = class extends require_sleep.BaseAddon {
|
|
|
36577
36897
|
* accessory-spawn flow handles via the parent's
|
|
36578
36898
|
* `getAccessoryChildren()`. Override only when the default doesn't
|
|
36579
36899
|
* fit.
|
|
36900
|
+
*
|
|
36901
|
+
* A row that fails either pass is NOT terminal (D347): it is handed
|
|
36902
|
+
* to a bounded background retry (`DeviceRestoreRetryScheduler`).
|
|
36903
|
+
* Only after the bound is exhausted is the device marked permanently
|
|
36904
|
+
* failed — logged at ERROR with `tags.deviceId` and surfaced via
|
|
36905
|
+
* `getStatus().error`.
|
|
36580
36906
|
*/
|
|
36581
36907
|
async onRestoreDevices(savedDevices) {
|
|
36582
36908
|
const restored = /* @__PURE__ */ new Set();
|
|
36909
|
+
const failures = [];
|
|
36910
|
+
const attemptRestore = async (saved) => {
|
|
36911
|
+
if (restored.has(saved.id)) return;
|
|
36912
|
+
const Class = this.deviceClasses[saved.type];
|
|
36913
|
+
if (!Class) throw new Error(`no device class registered for type "${saved.type}"`);
|
|
36914
|
+
if (saved.parentDeviceId !== null && !restored.has(saved.parentDeviceId)) throw new Error(`parent device ${saved.parentDeviceId} not restored`);
|
|
36915
|
+
await this.ctx.kernel.devices.create(saved.stableId, Class, {}, saved.parentDeviceId);
|
|
36916
|
+
restored.add(saved.id);
|
|
36917
|
+
};
|
|
36583
36918
|
const topLevel = savedDevices.filter((saved) => saved.parentDeviceId === null);
|
|
36584
36919
|
const restoreOne = async (saved) => {
|
|
36585
|
-
|
|
36586
|
-
if (!Class) {
|
|
36920
|
+
if (!this.deviceClasses[saved.type]) {
|
|
36587
36921
|
this.ctx.logger.warn("No device class registered for restored type — skipping", {
|
|
36588
|
-
tags: {
|
|
36922
|
+
tags: {
|
|
36923
|
+
deviceId: saved.id,
|
|
36924
|
+
stableId: saved.stableId
|
|
36925
|
+
},
|
|
36589
36926
|
meta: { type: saved.type }
|
|
36590
36927
|
});
|
|
36591
36928
|
return;
|
|
36592
36929
|
}
|
|
36593
36930
|
try {
|
|
36594
|
-
await
|
|
36595
|
-
restored.add(saved.id);
|
|
36931
|
+
await attemptRestore(saved);
|
|
36596
36932
|
} catch (err) {
|
|
36597
|
-
|
|
36598
|
-
|
|
36933
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
36934
|
+
this.ctx.logger.warn("Failed to restore device — bounded retry scheduled", {
|
|
36935
|
+
tags: {
|
|
36936
|
+
deviceId: saved.id,
|
|
36937
|
+
stableId: saved.stableId
|
|
36938
|
+
},
|
|
36599
36939
|
meta: {
|
|
36600
36940
|
type: saved.type,
|
|
36601
|
-
|
|
36941
|
+
attempt: 1,
|
|
36942
|
+
error
|
|
36602
36943
|
}
|
|
36603
36944
|
});
|
|
36945
|
+
failures.push({
|
|
36946
|
+
saved,
|
|
36947
|
+
error
|
|
36948
|
+
});
|
|
36604
36949
|
}
|
|
36605
36950
|
};
|
|
36606
36951
|
await Promise.all(topLevel.map((saved) => restoreOne(saved)));
|
|
36952
|
+
const failedTopLevelIds = new Set(failures.map((failure) => failure.saved.id));
|
|
36607
36953
|
const childRows = savedDevices.filter((s) => s.parentDeviceId !== null);
|
|
36608
36954
|
for (const saved of childRows) {
|
|
36609
|
-
|
|
36610
|
-
if (!Class) continue;
|
|
36955
|
+
if (!this.deviceClasses[saved.type]) continue;
|
|
36611
36956
|
if (saved.parentDeviceId === null) continue;
|
|
36612
|
-
if (
|
|
36613
|
-
|
|
36614
|
-
|
|
36615
|
-
|
|
36616
|
-
|
|
36617
|
-
|
|
36957
|
+
if (restored.has(saved.parentDeviceId)) {
|
|
36958
|
+
try {
|
|
36959
|
+
await attemptRestore(saved);
|
|
36960
|
+
} catch (err) {
|
|
36961
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
36962
|
+
this.ctx.logger.warn("Failed to restore hub-adopted child — bounded retry scheduled", {
|
|
36963
|
+
tags: {
|
|
36964
|
+
deviceId: saved.id,
|
|
36965
|
+
stableId: saved.stableId,
|
|
36966
|
+
parentDeviceId: saved.parentDeviceId
|
|
36967
|
+
},
|
|
36968
|
+
meta: {
|
|
36969
|
+
type: saved.type,
|
|
36970
|
+
attempt: 1,
|
|
36971
|
+
error
|
|
36972
|
+
}
|
|
36973
|
+
});
|
|
36974
|
+
failures.push({
|
|
36975
|
+
saved,
|
|
36976
|
+
error
|
|
36977
|
+
});
|
|
36978
|
+
}
|
|
36979
|
+
continue;
|
|
36980
|
+
}
|
|
36981
|
+
if (failedTopLevelIds.has(saved.parentDeviceId)) {
|
|
36982
|
+
this.ctx.logger.warn("Hub-adopted child deferred — parent failed initial restore", {
|
|
36618
36983
|
tags: {
|
|
36984
|
+
deviceId: saved.id,
|
|
36619
36985
|
stableId: saved.stableId,
|
|
36620
36986
|
parentDeviceId: saved.parentDeviceId
|
|
36621
36987
|
},
|
|
36622
|
-
meta: {
|
|
36623
|
-
type: saved.type,
|
|
36624
|
-
error: err instanceof Error ? err.message : String(err)
|
|
36625
|
-
}
|
|
36988
|
+
meta: { type: saved.type }
|
|
36626
36989
|
});
|
|
36990
|
+
failures.push({
|
|
36991
|
+
saved,
|
|
36992
|
+
error: `parent device ${saved.parentDeviceId} not restored`
|
|
36993
|
+
});
|
|
36994
|
+
continue;
|
|
36627
36995
|
}
|
|
36628
36996
|
}
|
|
36997
|
+
if (failures.length > 0) this.scheduleRestoreRetries(failures, attemptRestore);
|
|
36998
|
+
return {
|
|
36999
|
+
restoredCount: restored.size,
|
|
37000
|
+
failedCount: failures.length
|
|
37001
|
+
};
|
|
36629
37002
|
}
|
|
36630
37003
|
/** Convert an IDevice to the flat DeviceSummary for the cap router. */
|
|
36631
37004
|
toSummary(device) {
|
|
@@ -41033,6 +41406,12 @@ var METHOD_ACCESS_MAP = Object.freeze({
|
|
|
41033
41406
|
addonId: null,
|
|
41034
41407
|
access: "view"
|
|
41035
41408
|
},
|
|
41409
|
+
"deviceProvider.reloadDevice": {
|
|
41410
|
+
capName: "device-provider",
|
|
41411
|
+
capScope: "system",
|
|
41412
|
+
addonId: null,
|
|
41413
|
+
access: "create"
|
|
41414
|
+
},
|
|
41036
41415
|
"deviceProvider.start": {
|
|
41037
41416
|
capName: "device-provider",
|
|
41038
41417
|
capScope: "system",
|
|
@@ -52779,6 +53158,8 @@ exports.DEVICE_BACKEND_TO_FORMAT = DEVICE_BACKEND_TO_FORMAT;
|
|
|
52779
53158
|
exports.DEVICE_CAP_NAMES = DEVICE_CAP_NAMES;
|
|
52780
53159
|
exports.DEVICE_CHILDREN_BATCH_MAX = DEVICE_CHILDREN_BATCH_MAX;
|
|
52781
53160
|
exports.DEVICE_PROFILES = DEVICE_PROFILES;
|
|
53161
|
+
exports.DEVICE_RESTORE_RETRY_CONCURRENCY = DEVICE_RESTORE_RETRY_CONCURRENCY;
|
|
53162
|
+
exports.DEVICE_RESTORE_RETRY_DELAYS_MS = DEVICE_RESTORE_RETRY_DELAYS_MS;
|
|
52782
53163
|
exports.DEVICE_SCOPED_CAPS = require_sleep.DEVICE_SCOPED_CAPS;
|
|
52783
53164
|
exports.DEVICE_SETTINGS_CONTRIBUTION_METHODS = require_sleep.DEVICE_SETTINGS_CONTRIBUTION_METHODS;
|
|
52784
53165
|
exports.DEVICE_STATE_READERS = DEVICE_STATE_READERS;
|
|
@@ -52808,6 +53189,7 @@ exports.DeviceExportUnexposeInputSchema = UnexposeInputSchema;
|
|
|
52808
53189
|
exports.DeviceFeature = require_sleep.DeviceFeature;
|
|
52809
53190
|
exports.DeviceInfoSchema = DeviceInfoSchema;
|
|
52810
53191
|
exports.DeviceNetworkStatsSchema = DeviceNetworkStatsSchema;
|
|
53192
|
+
exports.DeviceRestoreRetryScheduler = DeviceRestoreRetryScheduler;
|
|
52811
53193
|
exports.DeviceRole = require_sleep.DeviceRole;
|
|
52812
53194
|
exports.DeviceRuntimeState = DeviceRuntimeState;
|
|
52813
53195
|
exports.DeviceSelectorSchema = DeviceSelectorSchema;
|