From 93bf5cdc88a33d1a347692dbda3dfda776e135ff Mon Sep 17 00:00:00 2001 From: Z User Date: Sat, 24 Oct 2026 01:07:37 +0000 Subject: [PATCH] fix(dashboard): start-llama diagnostics + comfy/queue no longer 500s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Two issues from user feedback ### Issue 1: Apply doesn't change model User reports: 'if I select a model in the panel, it shows as the new model but logs show the default model is still running'. Most likely cause: the user has an old model-worker image without the `--json` flag, OR the request body isn't including the new model name. The fix here is purely diagnostic — add logging so we can see what's happening: - `startLlama()` now logs to console: * `[startLlama] model: ` * `[startLlama] extraArgs: ` * `[startLlama] compose exit: ` * `[startLlama] compose output: ` - `/api/llama` POST logs: * `[/api/llama] action: config.model: ` * `[/api/llama] merged cfg.model: ` * `[/api/llama] startLlama result ok: ` - `handleStartLlama()` now includes the last 500 chars of compose logs in the toast message if start failed. Toast component renders multi-line messages as `
` so the logs are readable.

- Toast now uses `max-w-md` (was `max-w-sm`) and supports multi-line
  content with `whitespace-pre-wrap`.

After deploying, run `docker logs -f gpu-node-win-dashboard` while
clicking Start Llama — you'll see exactly what model name is being sent
and what docker compose outputs.

### Issue 2: /api/comfy/queue returns 500 every 5s

User reports: 'in logs I see problems with queue — 500 Internal Server
Error'. Even when not downloading anything.

Most likely cause: model-worker image on prod is old and doesn't support
`queue --json` flag (added in PR #5). When `modelWorkerExec('queue',
'--json')` fails with non-zero exit code, `getComfyQueue()` returns
`ok: false`, and the endpoint returns 500. Frontend polls every 5s, so
we get a flood of 500s.

Fixes:

- `/api/comfy/queue` no longer returns 500 on worker failure. Always
  returns 200 with `{ ok: false, queue: [], error:  }` —
  frontend shows empty queue, no error toast.

- `modelWorkerExec()` now logs failures to console.error with:
  * args being called
  * container name
  * exit code
  * stderr (truncated to 500 chars)

  This will show up in `docker logs gpu-node-win-dashboard` so we can
  see if it's a missing --json flag, container not running, etc.

## After deploying

```sh
git pull && sh build.sh
docker compose up -d --force-recreate dashboard model-worker
```

If model-worker is on old image (no --json support), the dashboard logs
will show:

  [modelWorkerExec] args=["queue","--json"] container=gpu-node-win-model-worker
  exitCode=1 stderr=Usage: ... worker.py queue [--watch] [--clear] ...

Recreate model-worker to pick up the new image:

  docker compose up -d --force-recreate model-worker

## Files changed

- dashboard/src/lib/docker.ts:
  * startLlama() now logs model + extraArgs + compose output
  * modelWorkerExec() now logs failures with exit code + stderr
- dashboard/src/app/api/llama/route.ts: logs action + model + result
- dashboard/src/app/api/comfy/queue/route.ts: returns 200 even on failure
- dashboard/src/app/page.tsx:
  * handleStartLlama includes compose logs in toast on failure
  * Toast component supports multi-line messages (renders as 
)
---
 dashboard/src/app/api/comfy/queue/route.ts | 20 ++++++++++++-----
 dashboard/src/app/api/llama/route.ts       |  4 ++++
 dashboard/src/app/page.tsx                 | 26 +++++++++++++++++++---
 dashboard/src/lib/docker.ts                | 26 +++++++++++++++++-----
 4 files changed, 62 insertions(+), 14 deletions(-)

diff --git a/dashboard/src/app/api/comfy/queue/route.ts b/dashboard/src/app/api/comfy/queue/route.ts
index 7c1fc29..fdab843 100644
--- a/dashboard/src/app/api/comfy/queue/route.ts
+++ b/dashboard/src/app/api/comfy/queue/route.ts
@@ -1,4 +1,4 @@
-import { NextRequest, NextResponse } from "next/server";
+import { NextResponse } from "next/server";
 import { getComfyQueue } from "@/lib/docker";
 
 export const dynamic = "force-dynamic";
@@ -6,12 +6,20 @@ export const runtime = "nodejs";
 
 /**
  * GET /api/comfy/queue
- * Returns current download queue via `docker exec model-worker python3 /app/worker.py queue`.
+ *
+ * Returns current download queue via `docker exec model-worker python3
+ * /app/worker.py queue --json`.
+ *
+ * Returns 200 even when model-worker is offline (queue is empty in that
+ * case) — frontend polls this every 5s, returning 500 on every poll when
+ * worker isn't running would spam the browser console.
  */
 export async function GET() {
   const result = await getComfyQueue();
-  return NextResponse.json(
-    { ok: result.ok, queue: result.queue, raw: result.raw, error: result.error },
-    { status: result.ok ? 200 : 500 }
-  );
+  return NextResponse.json({
+    ok: result.ok,
+    queue: result.queue,
+    raw: result.raw,
+    error: result.error,
+  });
 }
diff --git a/dashboard/src/app/api/llama/route.ts b/dashboard/src/app/api/llama/route.ts
index 94dbe67..d120e71 100644
--- a/dashboard/src/app/api/llama/route.ts
+++ b/dashboard/src/app/api/llama/route.ts
@@ -17,13 +17,17 @@ export async function POST(req: NextRequest) {
     config?: Partial;
   };
 
+  console.log("[/api/llama] action:", body.action, "config.model:", body.config?.model);
+
   if (body.action === "start") {
     const current = await loadConfig();
     const cfg: DashboardConfig = {
       ...current,
       ...(body.config || {}),
     } as DashboardConfig;
+    console.log("[/api/llama] merged cfg.model:", cfg.model);
     const result = await startLlama(cfg);
+    console.log("[/api/llama] startLlama result ok:", result.ok);
     return NextResponse.json(result, { status: result.ok ? 200 : 500 });
   }
 
diff --git a/dashboard/src/app/page.tsx b/dashboard/src/app/page.tsx
index 5a5aa05..2ee0127 100644
--- a/dashboard/src/app/page.tsx
+++ b/dashboard/src/app/page.tsx
@@ -452,6 +452,7 @@ export default function DashboardPage() {
 
   async function handleStartLlama() {
     await runAction("start-llama", async () => {
+      // Persist config first so reloads restore it.
       const res = await fetch("/api/config", {
         method: "PUT",
         headers: { "Content-Type": "application/json" },
@@ -463,7 +464,17 @@ export default function DashboardPage() {
         headers: { "Content-Type": "application/json" },
         body: JSON.stringify({ action: "start", config }),
       });
-      return await startRes.json();
+      const result = await startRes.json();
+      // If start failed, include compose logs in the message so the user can
+      // see what went wrong (common cause: model-worker still on old image
+      // without --json flag, or env not set, etc).
+      if (!result.ok && result.logs) {
+        return {
+          ok: false,
+          message: `${result.message}\n\n${result.logs.slice(-500)}`,
+        };
+      }
+      return result;
     });
   }
 
@@ -2125,10 +2136,13 @@ function Toast({
   toast: { type: "success" | "error" | "info"; message: string };
   onClose: () => void;
 }) {
+  // If message has multiple lines, render as pre-formatted text (so logs are
+  // readable); otherwise normal flow.
+  const isMultiLine = toast.message.includes("\n");
   return (
     
- {toast.message} + {isMultiLine ? ( +
+            {toast.message}
+          
+ ) : ( + {toast.message} + )}