Clean up Galaxy model management integration

Co-authored-by: AngusBell97 <124716116+AngusBell97@users.noreply.github.com>
This commit is contained in:
firestar5683
2026-09-13 15:30:44 -05:00
parent 8ccaacb919
commit 01ae511879
7 changed files with 2 additions and 23 deletions
-2
View File
@@ -55,8 +55,6 @@ class ModelSizes:
self.sizes = {}
def size(self, path, declared):
# Short TTL avoids repeated directory scans on status polls, not stale sizes
# across completed downloads. Bad metadata is treated as unknown by helper.
key = (str(path), repr(declared))
with self.lock:
cached = self.sizes.get(key)
@@ -1,4 +1,3 @@
// Presentation only. No Params writes, telemetry collection or inferred mileage.
const FILTER_KEY = "galaxy.modelManager.hardwareFilter";
const FILTERS = new Set(["both", "gpu", "comma"]);
@@ -13,7 +12,7 @@ export function readHardwareFilter() {
export function saveHardwareFilter(value) {
const filter = FILTERS.has(value) ? value : "both";
try { localStorage.setItem(FILTER_KEY, filter); } catch { /* View still works without storage. */ }
try { localStorage.setItem(FILTER_KEY, filter); } catch {}
return filter;
}
@@ -38,7 +37,6 @@ function formatBytes(value) {
}
export function fileSizeText(model) {
// modelSize is an architecture class, never a byte count.
const installed = bytes(model?.fileSizeBytes);
const declared = bytes(model?.declaredSizeBytes);
const downloaded = bytes(model?.downloadedBytes);
@@ -225,7 +225,6 @@ async function fetchStatus() {
statusInFlight = generation;
try {
// Remount readback must follow settlement of an already sent selection.
if (selectionWrite) await selectionWrite.catch(() => {});
if (generation !== statusGeneration || !isModelRouteActive()) return;
const payload = await fetchJson("/api/models/status");
@@ -259,7 +258,6 @@ async function fetchStatus() {
state.error = "";
state.selectionUncertain = false;
// selected attributes cannot reset a select's dirty native value after a user edit.
queueMicrotask(() => {
if (generation !== statusGeneration || !isModelRouteActive()) return;
for (const profile of ["small", "big"]) {
@@ -436,11 +434,10 @@ async function runAction(action, modelKey = "") {
}
if (action === "select" || action === "select-small" || action === "select-big") {
// Empty Active Big explicitly disables that profile; other selections require a model.
if (!modelKey && action !== "select-big") return;
const profile = action === "select-small" ? "small" : action === "select-big" ? "big" : "";
state.selectionUncertain = true;
++statusGeneration; // Invalidate pre-write polls, including their finalisers.
++statusGeneration;
const payload = await setActiveModel(modelKey, profile);
if (generation !== viewGeneration || !isModelRouteActive()) return;
notify(payload.message || `Selected "${modelKey}".`);
@@ -469,7 +466,6 @@ async function runAction(action, modelKey = "") {
} catch (error) {
if (generation !== viewGeneration || !isModelRouteActive()) return;
notify(error?.message || String(error), "error");
// A failed response does not establish whether the server accepted the write.
await fetchStatus();
} finally {
if (generation === viewGeneration && isModelRouteActive()) state.actionBusy = false;
@@ -508,7 +504,6 @@ function bindDomHandlers() {
const modelKey = safeText(target.value, "");
const profile = target.id === "mm-active-big-model-select" ? "big" : "small";
if (!modelKey && profile !== "big") return;
// Native selects change before their event; display only verified state.
target.value = profile === "big" ? state.activeBigModel : state.activeSmallModel;
runAction(`select-${profile}`, modelKey).catch(() => {});
return;
@@ -640,13 +635,10 @@ function ensureModelView() {
++statusGeneration;
clearTimeout(pollingHandle);
pollingHandle = null;
// Arrow has no unmount hook. Observe this mount's removal, not just pathname:
// a quick leave-and-return must not revive an old write/readback continuation.
queueMicrotask(() => {
if (generation !== viewGeneration) return;
const observer = new MutationObserver(() => {
if (generation !== viewGeneration) { observer.disconnect(); return; }
// Arrow may replace the wrapper during an ordinary reactive render.
if (document.querySelector(".mm-wrapper") && isModelRouteActive()) return;
observer.disconnect();
if (generation !== viewGeneration) return;
@@ -1,4 +1,3 @@
/* Download status changes must not move the viewport to another card. */
.gx-model-manager { overflow-anchor: none; }
.gx-model-manager .gx-row .gx-field { min-width: 0; }
@@ -1,4 +1,3 @@
// Shared confirmation dialog for model downloads.
let activeDialog = null
let dialogId = 0
function installStyle() {
@@ -18,7 +17,6 @@ function installStyle() {
document.head.appendChild(style)
}
// Native modal provides inert background, Escape and focus restoration. No settings writes.
export function openGalaxyHelpDialog({ title, paragraphs = [], troubleshooting = [], confirmLabel = "Close", cancelLabel = "" }) {
installStyle()
activeDialog?.()
@@ -58,7 +56,6 @@ export function openGalaxyHelpDialog({ title, paragraphs = [], troubleshooting =
}
const cancel = () => finish(false)
const resize = () => {
// CSS zoom changes available CSS-pixel space independently of device scale.
let zoom = 1
for (let node = document.body; node; node = node.parentElement) zoom *= parseFloat(getComputedStyle(node).zoom) || 1
dialog.style.setProperty("--gx-help-height", `${Math.max(100, ((window.visualViewport?.height || innerHeight) - 24) / zoom)}px`)
@@ -13,7 +13,6 @@ function releasedTs(value) {
return Number.isNaN(n) ? 0 : n
}
// Survives SPA unmount: a new instance must read after a sent write settles.
let selectionWrite = null
export const ModelManager = {
@@ -172,7 +171,6 @@ export const ModelManager = {
confirmLabel: "Download anyway", cancelLabel: "Cancel",
})
if (!allowGpu || this.disposed) return
// The car can change state while a confirmation is open.
await this.refresh()
if (this.disposed || this.error || !this.actionAllowedOnroad(action) || this.status.downloading) {
if (!this.disposed) showSnackbar("Download not started. Check the device status and try again while parked.", "error")
@@ -226,7 +224,6 @@ export const ModelManager = {
} catch (e) {
if (this.disposed) return
showSnackbar(e?.message || String(e), "error")
// Reconcile a possibly accepted request before releasing the action lock.
await this.refresh()
} finally {
if (!this.disposed) this.busy = ""
@@ -4514,7 +4514,6 @@ def _build_troubleshoot_payload():
for section_definition in _TROUBLESHOOT_SECTION_DEFINITIONS
]
# Use the same category and parent metadata as Settings, rather than a second short list.
shown = {item['key'] for section in sections for item in section['items']}
registered = {key for key, *_ in starpilot_default_params}
for category in load_settings_catalog() or []:
@@ -6951,7 +6950,6 @@ def setup(app):
return jsonify({"error": "Cannot change active models while driving."}), 403
data = request.get_json(silent=True)
# An explicit empty model disables Active Big; malformed values must not.
if not isinstance(data, dict) or not isinstance(data.get("model"), str):
return jsonify({"error": "An explicit model string is required."}), 400
profile = str(data.get("profile") or "").strip().lower()