From 3f6e239cc52dd1d44f2fced9b1bb630be24b2716 Mon Sep 17 00:00:00 2001 From: Danny Date: Fri, 13 Nov 2026 18:18:57 -0800 Subject: [PATCH] ModelManager: Cleanup --- .../galaxy/tests/test_model_laboratory.mjs | 2 +- .../starpilot/galaxy/tests/test_models.mjs | 24 +--- .../starpilot/galaxy/web/css/settings.css | 14 +- openpilot/starpilot/galaxy/web/js/models.js | 120 +++++++++--------- openpilot/starpilot/models/manager.py | 6 +- .../starpilot/models/tests/test_manager.py | 10 +- 6 files changed, 86 insertions(+), 90 deletions(-) diff --git a/openpilot/starpilot/galaxy/tests/test_model_laboratory.mjs b/openpilot/starpilot/galaxy/tests/test_model_laboratory.mjs index 2f688c9401..b11507f5a4 100644 --- a/openpilot/starpilot/galaxy/tests/test_model_laboratory.mjs +++ b/openpilot/starpilot/galaxy/tests/test_model_laboratory.mjs @@ -97,5 +97,5 @@ assert.match(template,/lab\.runtime\.error/) console.log('Model Laboratory contracts passed') assert.match(template,/steers · \{\{ labModelLabel\(labConfig\.longitudinalModel\) \}\} paces/) assert.match(template,/The pair takes effect the next time the driving model starts/) -assert.match(template,/labRow\(m\)\?\.small \|\| labRow\(m\)\?\.modelLabEligible/) +assert.match(template,/row\?\.small \|\| row\?\.modelLabEligible/) assert.match(template,/Pair lateral judgment from one model with longitudinal judgment from another\./) diff --git a/openpilot/starpilot/galaxy/tests/test_models.mjs b/openpilot/starpilot/galaxy/tests/test_models.mjs index ffcc3a78d1..3751e7d22f 100644 --- a/openpilot/starpilot/galaxy/tests/test_models.mjs +++ b/openpilot/starpilot/galaxy/tests/test_models.mjs @@ -388,25 +388,7 @@ for (const label of ["Polaris R3 A ⚠️🧪", "Polaris R3 B ⚠️🧪", "Pola } assert.deepEqual(ModelsPage.methods.polarisTitleParts({value: "spz_polaris_r3a"}), ["spz_polaris_r3a", ""]) - // Laboratory overrides normal selections until the next model start. -const labConfig = { enabled: true, lateralModel: 'small', longitudinalModel: 'big' } -const labView = { ...managerPayload, laboratory: labConfig, capabilities: { ...managerPayload.capabilities, configureLaboratory: true } } -assert.equal(modelActionAllowed(labView, 'disable-laboratory'), true) -assert.equal(modelActionAllowed({ ...labView, isOnroad: true }, 'disable-laboratory'), false) -assert.equal(modelActionAllowed({ ...labView, downloading: true }, 'disable-laboratory'), false) -assert.equal(modelActionAllowed({ ...labView, laboratory: { ...labConfig, enabled: false } }, 'disable-laboratory'), false) -const labManager = managerFixture() -labManager.manager.start() -await labManager.reply(0, labView) -const disabledLab = labManager.manager.action('disable-laboratory') -assert.equal(labManager.requests[1].url, './api/models/laboratory') -assert.deepEqual(JSON.parse(labManager.requests[1].options.body), { ...labConfig, enabled: false }) -await labManager.reply(1, { message: 'Model Laboratory configuration saved' }) -await labManager.reply(2, { ...labView, laboratory: { ...labConfig, enabled: false } }) -await disabledLab -assert.equal(labManager.manager.data.laboratory.enabled, false) -labManager.manager.stop() const pairData = { catalog: [{ id: 'small', name: 'Small model' }, { id: 'big', name: 'Big model' }], laboratory: { active: true, lateralModel: 'small', longitudinalModel: 'big' } } const pairPage = { selectionUncertain: false, status: {}, runtime: { status: 'ready', data: pairData } } @@ -414,6 +396,12 @@ assert.equal(ModelsPage.computed.runningModelLabel.call(pairPage), 'Small model/ assert.equal(ModelsPage.computed.runningModelLabel.call({ ...pairPage, runtime: { status: 'stale', data: pairData } }), 'Status unavailable') assert.equal(ModelsPage.computed.runningModelLabel.call({ ...pairPage, runtime: { status: 'ready', data: { ...pairData, laboratory: { ...pairData.laboratory, active: false } } } }), 'Laboratory output unavailable') assert.match(ModelsPage.template, /fallback choices/) +const pendingStart = data => ModelsPage.computed.pendingNextStart.call({ runtime: { status: 'ready', data } }) +assert.equal(pendingStart({ ...pairData, pendingNextStart: false }), false) +assert.equal(pendingStart({ ...pairData, pendingNextStart: true }), true) +assert.equal(pendingStart({ ...pairData, laboratory: { ...pairData.laboratory, pendingNextStart: true } }), true) +assert.equal(ModelsPage.computed.pendingNextStart.call({ runtime: { status: 'stale', data: { pendingNextStart: true } } }), false) +assert.equal(ModelsPage.template.match(/v-if="pendingNextStart"> · saved changes pending next start/g).length, 2) // Merged page: search, row list, Single model / Model pair mode switcher, and pair saving. { diff --git a/openpilot/starpilot/galaxy/web/css/settings.css b/openpilot/starpilot/galaxy/web/css/settings.css index 420f5a50db..ad75ffca5b 100644 --- a/openpilot/starpilot/galaxy/web/css/settings.css +++ b/openpilot/starpilot/galaxy/web/css/settings.css @@ -316,11 +316,11 @@ input[type="range"].gx-slider:active::-moz-range-thumb { .gx-model-reason { margin: var(--sp-3) 0; color: var(--text-muted); font-size: var(--fs-sm); } .gx-model-card__reason { margin: 0; } -/* Models page: mobile-first Material Design 3 layout */ +/* Models page */ .gx-model-manager { --panel-padding: var(--sp-4); gap: var(--sp-3); } .gx-model-manager .gx-btn, .gx-model-card__progress { min-height: var(--touch-target); padding: 6px var(--sp-4); } -/* Mode selector: Material 3 segmented pill */ +/* Single / pair mode switch */ .gx-tabs.gx-model-mode { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: var(--radius-full); border: 1px solid var(--glass-border); background: var(--surface-container-high); } .gx-model-mode > button { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2); min-height: 40px; border: 0; border-radius: var(--radius-full); @@ -328,7 +328,7 @@ input[type="range"].gx-slider:active::-moz-range-thumb { .gx-model-mode > button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); box-shadow: 0 4px 12px var(--primary-glow); } .gx-model-mode > button:disabled { opacity: .5; cursor: not-allowed; } -/* Driving & Laboratory controls: stacked on mobile, side-by-side on wider viewports */ +/* Driving and Laboratory controls */ .gx-model-driving__body, .gx-model-laboratory { display: grid; gap: var(--sp-3); } .gx-model-driving__summary { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-2); } .gx-model-summary-item { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: 8px 12px; border-radius: var(--radius-md); border: 1px solid var(--outline); background: var(--surface-container-high); min-width: 0; } @@ -344,7 +344,7 @@ input[type="range"].gx-slider:active::-moz-range-thumb { .gx-model-driving .gx-model-reason { margin: 0; } .gx-model-driving__random-hint { color: var(--text-muted); font-weight: normal; margin-left: var(--sp-1); } -/* Library toolbar: mobile-first search, hardware tabs, sort, and filter chips */ +/* Library toolbar */ .gx-model-toolbar { display: grid; gap: var(--sp-3); } .gx-model-searchbar { display: flex; align-items: center; flex-wrap: wrap; gap: var(--sp-2); min-width: 0; } .gx-model-search-wrap { position: relative; flex: 1 1 200px; min-width: 0; display: flex; align-items: center; } @@ -364,7 +364,7 @@ input[type="range"].gx-slider:active::-moz-range-thumb { .gx-model-filters { flex: 1 1 auto; align-items: center; } .gx-model-filters .gx-chip { display: inline-flex; align-items: center; gap: var(--sp-1); min-height: 40px; padding-inline: var(--sp-3); } -/* Tags: green eGPU, blue Small, orange Pairable, purple Active Small / Big */ +/* Model tags */ .gx-model-tag { display: inline-flex; align-items: center; gap: 4px; padding: 0 8px; border: 1px solid; border-radius: var(--radius-full); font-size: .72rem; font-weight: 700; line-height: 1.6; white-space: nowrap; } .gx-model-tag i { font-size: .9em; } .gx-model-tag--egpu { color: #6ee7a0; background: rgba(110, 231, 160, .12); border-color: rgba(110, 231, 160, .4); } @@ -376,7 +376,7 @@ input[type="range"].gx-slider:active::-moz-range-thumb { [data-theme="light"] .gx-model-tag--small { color: #1d4ed8; background: rgba(29, 78, 216, .08); border-color: rgba(29, 78, 216, .35); } [data-theme="light"] .gx-model-tag--pair { color: #c2410c; background: rgba(194, 65, 12, .08); border-color: rgba(194, 65, 12, .35); } -/* Row-based model list: mobile-first 2-row column grid, single horizontal multi-column row on tablet/desktop */ +/* Model list rows */ .gx-model-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--outline); } .gx-model-item { display: grid; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--outline); transition: background-color var(--motion-fast); } .gx-model-item:first-child { border-top: 0; } @@ -415,7 +415,7 @@ input[type="range"].gx-slider:active::-moz-range-thumb { .gx-model-card__progress-fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--secondary), var(--primary)); opacity: .6; transition: width .3s ease; } .gx-model-card__progress-label { position: relative; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } -/* Model Pair mode rows: 3-row card layout with full model names, compact 3rd-row pills, borderless cloud & gradient dash running around the cloud outline */ +/* Model pair rows */ .gx-model-item__row--pair { align-items: center; gap: 4px 10px; } .gx-model-item__row--pair .gx-model-item__main { display: contents; } .gx-model-item__row--pair .gx-model-item__title { grid-column: 2; grid-row: 1; min-height: 24px; line-height: 1.3; } diff --git a/openpilot/starpilot/galaxy/web/js/models.js b/openpilot/starpilot/galaxy/web/js/models.js index 89499c77db..04ee92289c 100644 --- a/openpilot/starpilot/galaxy/web/js/models.js +++ b/openpilot/starpilot/galaxy/web/js/models.js @@ -175,7 +175,7 @@ export function formatEta(seconds, short = false) { const PHASES = { catalog: "Checking the model catalog", verifying: "Verifying download", installing: "Installing model" } -// One shape for the progress panel; old backends only send a text line, so a percent in it still draws a bar. +// Progress panel shape; a percent in a text-only progress line still draws a bar. export function describeProgress(data, models = []) { const detail = data?.downloadProgress const label = value => models.find(m => m.value === value)?.label || "" @@ -204,10 +204,10 @@ export function describeProgress(data, models = []) { const actionPaths = { "select-small": "active", "select-big": "active", favorite: "preferences", unfavorite: "preferences", "enable-randomizer": "preferences", "disable-randomizer": "preferences", exclude: "preferences", include: "preferences", - download: "download", downloadAll: "download_all", cancel: "cancel", delete: "delete", refresh: "refresh_manifest", jetlink: "jetlink", "disable-laboratory": "laboratory" } + download: "download", downloadAll: "download_all", cancel: "cancel", delete: "delete", refresh: "refresh_manifest", jetlink: "jetlink" } const actionCapabilities = { "select-small": "select", "select-big": "select", favorite: "favorites", unfavorite: "favorites", "enable-randomizer": "randomizer", "disable-randomizer": "randomizer", exclude: "exclusions", include: "exclusions", - download: "download", downloadAll: "downloadAll", cancel: "cancel", delete: "delete", refresh: "refresh", jetlink: "jetlink", "disable-laboratory": "configureLaboratory" } + download: "download", downloadAll: "downloadAll", cancel: "cancel", delete: "delete", refresh: "refresh", jetlink: "jetlink" } export function fitsModelProfile(model, profile) { return Array.isArray(model?.profiles) ? model.profiles.includes(profile) : profile === "big" ? model?.requiresGpu === true : model?.requiresGpu === false @@ -216,7 +216,6 @@ export function fitsModelProfile(model, profile) { export function modelActionAllowed(data, action, model = null) { if (!data || data.capabilities?.[actionCapabilities[action]] !== true) return false if (data.isOnroad !== false && !["favorite", "unfavorite", "cancel", "select-small", "select-big"].includes(action)) return false - if (action === "disable-laboratory") return data.laboratory?.enabled === true && !data.downloading if (action === "jetlink") return data.jetlink !== undefined if (["select-small", "select-big"].includes(action)) { if (action === "select-big" && data.jetlinkBig && data.isOnroad !== false) return false @@ -348,7 +347,6 @@ export class ModelManagerFeed { const data = this.data const key = model?.value || "" let payload = action === "jetlink" ? extra : {} - if (action === "disable-laboratory") payload = { ...data.laboratory, enabled: false } if (action.startsWith("select-")) payload = { profile: action === "select-big" ? "big" : "small", model: key } else if (["favorite", "unfavorite"].includes(action)) { const userFavorites = data.models.filter(m => m.userFavorite && m.value !== key).map(m => m.value) @@ -361,7 +359,7 @@ export class ModelManagerFeed { } else if (["enable-randomizer", "disable-randomizer"].includes(action)) payload = { randomizer: action === "enable-randomizer" } else if (["download", "delete"].includes(action)) payload = { model: key } if (["download", "downloadAll"].includes(action)) payload.allowGpuWithoutGpu = extra.allowGpuWithoutGpu === true - if (typeof data.view === "string" && action !== "disable-laboratory") payload.view = data.view + if (typeof data.view === "string") payload.view = data.view this.saving = true this.data = null const result = await this.requestJson(actionPaths[action], payload) @@ -374,8 +372,7 @@ export class ModelManagerFeed { } } -// Model Laboratory: pairs one model's lateral output with another's longitudinal output, using eGPU (Chestnut) variants. -// It reads the same catalog and download job as the manager, through ./api/models/laboratory. +// Model Laboratory: one model steers, another paces, via ./api/models/laboratory. export const laboratoryModels = data => data?.models || [] export const laboratoryReady = data => laboratoryModels(data).filter(m => m.modelLabEligible === true && m.modelLabArtifactAvailable === true && m.modelLabArtifactInstalled === true) @@ -531,8 +528,11 @@ export const ModelsPage = { if (!model.loadedId) return model.health === "loading" ? "Loading…" : "Identity unverified" return model.catalog.find(item => item.id === model.loadedId)?.name || model.loadedId }, + pendingNextStart() { + const data = this.runtime.status === "ready" ? this.runtime.data : null + return data?.pendingNextStart === true || data?.laboratory?.pendingNextStart === true + }, laboratoryEnabled() { return !this.selectionUncertain && this.status.laboratory?.enabled === true }, - laboratoryRunning() { return this.runtime.status === "ready" && !!this.runtime.data?.laboratory?.lateralModel }, installedSmallModels() { return this.models.filter(m => (m.value === this.activeSmallModel || m.selectable) && fitsModelProfile(m, "small")) }, installedBigModels() { return this.models.filter(m => (m.value === this.activeBigModel || m.selectable) && fitsModelProfile(m, "big")) }, // the manager words it: under Jetlink, the Jetlink app's choice @@ -588,7 +588,6 @@ export const ModelsPage = { }, jetlinkOpen() { return !!this.status.jetlink && this.status.jetlink.mode !== "off" }, driveMode() { return this.pairView ?? (this.lab?.configuration.enabled ? "pair" : "single") }, - showLabVariants() { return this.driveMode === "pair" || this.pairableFilter }, labRows() { return new Map(laboratoryModels(this.lab).map(m => [m.value, m])) }, labReady() { return laboratoryReady(this.lab) }, labCandidates() { return this.labReady.filter(m => m.value !== this.labConfig.lateralModel) }, @@ -660,6 +659,7 @@ export const ModelsPage = { isPairable(model) { return this.labRow(model)?.modelLabArtifactAvailable === true }, labStatusLabel: laboratoryStatusLabel, labReason(model) { const row = this.labRow(model); return row && LAB_REASON_STATES.has(row.modelLabStatus) ? row.modelLabReason : "" }, + pairKind(row) { return row.small ? "eGPU variant" : "Big model" }, labDownloadLabel(m) { return m.small ? (m.modelLabChestnut === false ? "Download Small model" : "Download pair variants") : "Download Big model" }, labModelLabel(id) { return this.lab?.models.find(m => m.value === id)?.label || id || "Not selected" }, labActionAvailable(action, model = null) { return laboratoryActionAllowed(this.lab, action, model, this.labConfig) }, @@ -837,8 +837,8 @@ export const ModelsPage = { const result = await (["enable-randomizer", "disable-randomizer", "include", "exclude"].includes(action) ? reportSave(perform) : perform()) if (!this.disposed && result) { this.trackingProgress = ["download", "downloadAll", "refresh"].includes(action) - this.message = (action === "disable-laboratory" ? "Laboratory is off for the next start. Choose your Small and Big models below." : "") || (this.trackingProgress && this.status.progress) || result.message || - (action === "disable-laboratory" ? "Laboratory is off for the next start. Choose your Small and Big models below." : action.startsWith("select-") ? "Selection saved for the next onroad cycle." : "Saved.") + this.message = (this.trackingProgress && this.status.progress) || result.message || + (action.startsWith("select-") ? "Selection saved for the next onroad cycle." : "Saved.") if (["download", "downloadAll", "cancel", "delete", "refresh"].includes(action)) this.laboratory?.load() } } finally { if (!this.disposed) { this.pendingChoice = null; this.busy = "" } } @@ -893,7 +893,7 @@ export const ModelsPage = { Model Randomizer tries a different model each drive - Running now: {{ runningModelLabel }} + Running now: {{ runningModelLabel }}

A different verified model is chosen each start. {{ status.gpuAvailable && activeBigModel ? 'Big GPU' : 'Small on-device' }} models are used. {{ (status.blacklistedModels || []).length }} excluded. Favorites only mark your preferred models.

{{ gpuNote }}

@@ -906,7 +906,7 @@ export const ModelsPage = { {{ lab ? (lab.chestnutReady ? 'Chestnut ready' : 'Chestnut required') : 'Waiting for device status' }} {{ labRuntimeState }} - Running now: {{ runningModelLabel }} + Running now: {{ runningModelLabel }} {{ labError }} {{ lab.configurationError }} @@ -1067,55 +1067,57 @@ export const ModelsPage = { -
-
- -
-
-
- {{ labRow(m).small ? 'eGPU variant' : 'Big model' }} +
diff --git a/openpilot/starpilot/models/manager.py b/openpilot/starpilot/models/manager.py index 5d9a3b7a95..c043ad6c38 100644 --- a/openpilot/starpilot/models/manager.py +++ b/openpilot/starpilot/models/manager.py @@ -434,7 +434,8 @@ class ModelManager: self.downloading = model job["model"] = model if detail is not None: - job["detail"] = {**(job.get("detail") if isinstance(job.get("detail"), dict) else {}), **detail} + previous = job.get("detail") + job["detail"] = {**(previous if isinstance(previous, dict) else {}), **detail} atomic_json(self.root / ".download-job.json", job) def _check_cancelled(self) -> None: @@ -453,7 +454,8 @@ class ModelManager: try: job = self._read_job() if job.get("jobId") == self.job_id: - detail = job.get("detail") if isinstance(job.get("detail"), dict) else {} + previous = job.get("detail") + detail = previous if isinstance(previous, dict) else {} if failed and self.progress != "Download cancelled" and job.get("operation") != "refresh_manifest": detail = {**detail, "phase": "failed", "failed": True, "error": self.progress[:300], "rate": 0, "finishedAt": time.monotonic()} else: diff --git a/openpilot/starpilot/models/tests/test_manager.py b/openpilot/starpilot/models/tests/test_manager.py index 465bcfcf0d..53d27fc848 100644 --- a/openpilot/starpilot/models/tests/test_manager.py +++ b/openpilot/starpilot/models/tests/test_manager.py @@ -202,8 +202,10 @@ class ModelManagerTest(unittest.TestCase): row.update({key: self.row[key] for key in ('artifact_format', 'artifact_sha256', 'artifact_size', 'artifact_chunk_count')}) seen = self.record_progress() self.manager.action('download_all', {}) - self.manager.worker.join(10) - self.assertFalse(self.manager.worker.is_alive()) + worker = self.manager.worker + assert worker is not None + worker.join(10) + self.assertFalse(worker.is_alive()) starts = [(detail['index'], detail['count']) for detail in seen if 'index' in detail] count = starts[0][1] self.assertGreater(count, 1) @@ -242,7 +244,9 @@ class ModelManagerTest(unittest.TestCase): self.manager.opener = offline self.manager.action('refresh_manifest', {}) - self.manager.worker.join(3) + worker = self.manager.worker + assert worker is not None + worker.join(3) self.assertIsNone(self.manager.snapshot()['downloadProgress']) def test_insufficient_storage_preserves_installed_model_and_selection(self):