Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat: let a failed installer queue a CoS agent to investigate it (#5981)

[._.]/ Adam Eivy0f04aff6f2ec
diff --git a/client/src/components/imageGen/Flux2InstallModal.jsx b/client/src/components/imageGen/Flux2InstallModal.jsx
index 97beb53360..9d7c159fa5 100644
--- a/client/src/components/imageGen/Flux2InstallModal.jsx
+++ b/client/src/components/imageGen/Flux2InstallModal.jsx
@@ -13,6 +13,7 @@
import { useEffect, useState } from 'react';
import { CheckCircle2, Loader2, AlertCircle, Download, X } from 'lucide-react';
import { useInstallStream } from '../../hooks/useInstallStream';
+import InstallErrorFooter from '../install/InstallErrorFooter';
import Modal from '../ui/Modal';
const STAGES = [
@@ -197,27 +198,33 @@ export default function Flux2InstallModal({ open, onClose, onComplete }) {
</button>
</div>
</>
+ ) : error ? (
+ <InstallErrorFooter
+ message="⚠️ Installer hit an error — see logs above."
+ label="FLUX.2 Runtime"
+ stage={currentStage}
+ error={error}
+ logs={logs}
+ surface="client/src/components/imageGen/Flux2InstallModal.jsx"
+ onClose={handleClose}
+ />
) : (
<>
<span className="text-xs text-gray-400">
{done
? '✅ FLUX.2 is ready. You can close this window.'
- : error
- ? '⚠️ Installer hit an error — see logs above.'
- : 'Downloading torch + diffusers from PyPI/git. ~3-10 minutes on first run.'}
+ : 'Downloading torch + diffusers from PyPI/git. ~3-10 minutes on first run.'}
</span>
<button
onClick={handleClose}
- disabled={!done && !error && !currentStage}
+ disabled={!done && !currentStage}
className={`px-3 py-1.5 rounded-lg text-xs font-medium transition-colors ${
done
? 'bg-port-success text-white hover:bg-port-success/80'
- : error
- ? 'bg-port-border text-white hover:bg-port-border/70'
- : 'bg-port-border text-gray-300 hover:bg-port-border/70 disabled:opacity-50'
+ : 'bg-port-border text-gray-300 hover:bg-port-border/70 disabled:opacity-50'
}`}
>
- {done ? 'Done' : error ? 'Close' : 'Cancel'}
+ {done ? 'Done' : 'Cancel'}
</button>
</>
)}
diff --git a/client/src/components/install/InstallErrorFooter.jsx b/client/src/components/install/InstallErrorFooter.jsx
new file mode 100644
index 0000000000..ce9fd7f371
--- /dev/null
+++ b/client/src/components/install/InstallErrorFooter.jsx
@@ -0,0 +1,46 @@
+/**
+ * Shared modal footer for a failed install (#5981).
+ *
+ * `Flux2InstallModal` and `RuntimeInstallModal` each hand-rolled the same
+ * "message + Close" error footer, so adding the agent-investigation action to
+ * both would have made a third copy of the same row. Both render this instead
+ * whenever `useInstallStream` reports an `error`.
+ *
+ * Returns the footer row's CONTENT (message on the left, actions on the right)
+ * so each modal keeps its own footer container and spacing.
+ */
+
+import QueueInstallInvestigationButton from './QueueInstallInvestigationButton';
+
+export default function InstallErrorFooter({
+ message,
+ label,
+ stage,
+ error,
+ logs,
+ surface,
+ onClose,
+ closeLabel = 'Close',
+}) {
+ return (
+ <>
+ <span className="text-xs text-gray-400">{message}</span>
+ <div className="flex items-center gap-2">
+ <QueueInstallInvestigationButton
+ label={label}
+ stage={stage}
+ error={error}
+ logs={logs}
+ surface={surface}
+ />
+ <button
+ type="button"
+ onClick={onClose}
+ className="px-3 py-1.5 rounded-lg text-xs font-medium transition-colors bg-port-border text-white hover:bg-port-border/70"
+ >
+ {closeLabel}
+ </button>
+ </div>
+ </>
+ );
+}
diff --git a/client/src/components/install/QueueInstallInvestigationButton.jsx b/client/src/components/install/QueueInstallInvestigationButton.jsx
new file mode 100644
index 0000000000..3ce8e6f04f
--- /dev/null
+++ b/client/src/components/install/QueueInstallInvestigationButton.jsx
@@ -0,0 +1,54 @@
+/**
+ * "Queue agent to investigate" action for an installer failure (#5981).
+ *
+ * An install error used to be a dead end — Close was the only affordance — even
+ * though PortOS already owns an autonomous-agent queue. This button hands the
+ * failure straight to that queue: it builds a reproducible task from the
+ * installer name, the failing stage, the error and the streamed log tail, and
+ * posts it via `addCosTask` with no `app`, which targets PortOS itself (the
+ * installer code lives in this repo).
+ *
+ * Rendered by `InstallErrorFooter` (both install modals) and directly by
+ * `LocalSetupPanel`, which draws its own error region.
+ */
+
+import { useState } from 'react';
+import { Bot, Check } from 'lucide-react';
+import { useAsyncAction } from '../../hooks/useAsyncAction';
+import { buildInstallFailureTask } from '../../lib/installFailureTask';
+import { addCosTask } from '../../services/api';
+import toast from '../ui/Toast';
+
+export default function QueueInstallInvestigationButton({
+ label,
+ stage,
+ error,
+ logs,
+ surface,
+ className = '',
+}) {
+ const [queued, setQueued] = useState(false);
+ // `useAsyncAction` owns the failure toast, so the request itself is silent —
+ // otherwise the user gets two toasts for one failed queue.
+ const [queueTask, queueing] = useAsyncAction(async () => {
+ const task = buildInstallFailureTask({ label, stage, error, logs, surface });
+ await addCosTask({ ...task, useWorktree: true, openPR: true }, { silent: true });
+ setQueued(true);
+ toast.success('Queued an agent to investigate this failure');
+ }, { errorMessage: 'Failed to queue the investigation task' });
+
+ return (
+ <button
+ type="button"
+ onClick={queueTask}
+ disabled={queueing || queued}
+ title={queued
+ ? 'An agent task for this failure is already queued'
+ : 'Queue a PortOS agent task to investigate this install failure'}
+ className={`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium transition-colors bg-port-accent text-white hover:bg-port-accent/80 disabled:opacity-50 disabled:hover:bg-port-accent ${className}`}
+ >
+ {queued ? <Check size={14} /> : <Bot size={14} />}
+ {queued ? 'Agent queued' : queueing ? 'Queueing…' : 'Queue agent to investigate'}
+ </button>
+ );
+}
diff --git a/client/src/components/install/RuntimeInstallModal.jsx b/client/src/components/install/RuntimeInstallModal.jsx
index 7f47578753..e60eb440e7 100644
--- a/client/src/components/install/RuntimeInstallModal.jsx
+++ b/client/src/components/install/RuntimeInstallModal.jsx
@@ -11,6 +11,7 @@ import { useEffect, useState } from 'react';
import { CheckCircle2, Loader2, AlertCircle, Download, X } from 'lucide-react';
import { useInstallStream } from '../../hooks/useInstallStream';
import Modal from '../ui/Modal';
+import InstallErrorFooter from './InstallErrorFooter';
const MAX_LOG_LINES = 1000;
@@ -40,7 +41,7 @@ export default function RuntimeInstallModal({
const [confirmingCancel, setConfirmingCancel] = useState(false);
const query = new URLSearchParams({ runtime: runtime ?? '', ...(params || {}) });
const url = open && runtime ? `${installUrlBase}?${query}` : null;
- const { logs, done, error, streamStarted, logsEndRef, close } = useInstallStream(
+ const { logs, currentStage, done, error, streamStarted, logsEndRef, close } = useInstallStream(
url,
{ enabled: open && !!runtime, onComplete, maxLogLines: MAX_LOG_LINES, flushMs, method: streamMethod },
);
@@ -134,26 +135,32 @@ export default function RuntimeInstallModal({
</button>
</div>
</>
+ ) : error ? (
+ <InstallErrorFooter
+ message="Installer hit an error - see logs above."
+ label={label || runtime}
+ stage={currentStage}
+ error={error}
+ logs={logs}
+ surface="client/src/components/install/RuntimeInstallModal.jsx"
+ onClose={handleClose}
+ />
) : (
<>
<span className="text-xs text-gray-400">
{done
? `${label || runtime} is ready. You can close this window.`
- : error
- ? 'Installer hit an error - see logs above.'
- : description}
+ : description}
</span>
<button
onClick={handleClose}
className={`px-3 py-1.5 rounded-lg text-xs font-medium transition-colors ${
done
? 'bg-port-success text-white hover:bg-port-success/80'
- : error
- ? 'bg-port-border text-white hover:bg-port-border/70'
- : 'bg-port-border text-gray-300 hover:bg-port-border/70'
+ : 'bg-port-border text-gray-300 hover:bg-port-border/70'
}`}
>
- {done ? 'Done' : error ? 'Close' : 'Cancel'}
+ {done ? 'Done' : 'Cancel'}
</button>
</>
)}
diff --git a/client/src/components/install/RuntimeInstallModal.test.jsx b/client/src/components/install/RuntimeInstallModal.test.jsx
new file mode 100644
index 0000000000..a27c2e6215
--- /dev/null
+++ b/client/src/components/install/RuntimeInstallModal.test.jsx
@@ -0,0 +1,100 @@
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { render, screen, fireEvent, waitFor } from '@testing-library/react';
+
+// The SSE stream itself is covered by useInstallStream's own suite; this file
+// pins the failure-footer contract every installer surface shares (#5981).
+vi.mock('../../hooks/useInstallStream', () => ({
+ useInstallStream: vi.fn(),
+}));
+vi.mock('../../services/api', () => ({
+ addCosTask: vi.fn(),
+}));
+vi.mock('../ui/Toast', () => ({
+ default: Object.assign(vi.fn(), {
+ success: vi.fn(), error: vi.fn(), warning: vi.fn(), info: vi.fn(),
+ }),
+}));
+
+import { useInstallStream } from '../../hooks/useInstallStream';
+import { addCosTask } from '../../services/api';
+import toast from '../ui/Toast';
+import RuntimeInstallModal from './RuntimeInstallModal';
+
+const streamState = (overrides = {}) => ({
+ logs: [],
+ currentStage: null,
+ done: false,
+ error: null,
+ streamStarted: true,
+ logsEndRef: { current: null },
+ close: vi.fn(),
+ ...overrides,
+});
+
+const renderFailed = ({ onClose = vi.fn(), ...overrides } = {}) => {
+ useInstallStream.mockReturnValue(streamState({
+ error: 'setup.sh exited 1',
+ currentStage: 'clone',
+ logs: [{ kind: 'log', text: 'cloning repo' }, { kind: 'error', text: 'fatal: could not build' }],
+ ...overrides,
+ }));
+ render(<RuntimeInstallModal open runtime="trellis2" label="TRELLIS.2" onClose={onClose} />);
+ return onClose;
+};
+
+beforeEach(() => {
+ vi.clearAllMocks();
+});
+
+describe('RuntimeInstallModal failure footer', () => {
+ it('offers no investigation action while the install is still running', () => {
+ useInstallStream.mockReturnValue(streamState());
+ render(<RuntimeInstallModal open runtime="trellis2" label="TRELLIS.2" onClose={vi.fn()} />);
+ expect(screen.queryByRole('button', { name: /queue agent to investigate/i })).toBeNull();
+ });
+
+ it('queues a CoS task carrying the failing stage, error and log tail, targeting PortOS itself', async () => {
+ addCosTask.mockResolvedValue({ id: 'task-1' });
+ renderFailed();
+
+ fireEvent.click(screen.getByRole('button', { name: /queue agent to investigate/i }));
+
+ await waitFor(() => expect(addCosTask).toHaveBeenCalledTimes(1));
+ const [task, options] = addCosTask.mock.calls[0];
+ expect(task.description).toBe('Fix TRELLIS.2 installer failure at the clone stage');
+ expect(task.prompt).toContain('Failing stage: clone');
+ expect(task.prompt).toContain('setup.sh exited 1');
+ expect(task.prompt).toContain('fatal: could not build');
+ // No `app` — the installer code lives in PortOS, which is the server default.
+ expect(task.app).toBeUndefined();
+ expect(task).toMatchObject({ useWorktree: true, openPR: true });
+ // useAsyncAction owns the failure toast, so the request must not toast too.
+ expect(options).toMatchObject({ silent: true });
+
+ // Queued state: labelled and disabled so a second click can't double-queue.
+ const queued = await screen.findByRole('button', { name: /agent queued/i });
+ expect(queued.disabled).toBe(true);
+ expect(toast.success).toHaveBeenCalled();
+ });
+
+ it('toasts and stays clickable when queueing fails', async () => {
+ addCosTask.mockRejectedValue(new Error('CoS queue unavailable'));
+ renderFailed();
+
+ fireEvent.click(screen.getByRole('button', { name: /queue agent to investigate/i }));
+
+ await waitFor(() => expect(toast.error).toHaveBeenCalledWith('CoS queue unavailable'));
+ const button = screen.getByRole('button', { name: /queue agent to investigate/i });
+ expect(button.disabled).toBe(false);
+ expect(toast.success).not.toHaveBeenCalled();
+ });
+
+ it('keeps Close working alongside the new action', () => {
+ const onClose = renderFailed();
+ expect(screen.getByRole('button', { name: /queue agent to investigate/i })).toBeTruthy();
+ fireEvent.click(screen.getByRole('button', { name: /^close$/i }));
+ // A failed install is not "running", so Close dismisses without the
+ // cancel-confirmation prompt.
+ expect(onClose).toHaveBeenCalledTimes(1);
+ });
+});
diff --git a/client/src/components/settings/LocalSetupPanel.jsx b/client/src/components/settings/LocalSetupPanel.jsx
index d6bd328384..93d9280572 100644
--- a/client/src/components/settings/LocalSetupPanel.jsx
+++ b/client/src/components/settings/LocalSetupPanel.jsx
@@ -6,6 +6,7 @@ import BrailleSpinner from '../BrailleSpinner';
import { usePrevious } from '../../hooks/usePrevious.js';
import { useInstallStream } from '../../hooks/useInstallStream.js';
import useMounted from '../../hooks/useMounted.js';
+import QueueInstallInvestigationButton from '../install/QueueInstallInvestigationButton';
import { checkImageGenSetup, detectImageGenPython, createImageGenVenv } from '../../services/api';
export default function LocalSetupPanel({ pythonPath, onPythonPathChange, onPackagesChanged }) {
@@ -83,6 +84,7 @@ export default function LocalSetupPanel({ pythonPath, onPythonPathChange, onPack
// handling, unmount teardown, and auto-scroll.
const {
logs: installLog,
+ currentStage: installStage,
done: installDone,
error: installError,
streamStarted: installStarted,
@@ -277,6 +279,18 @@ export default function LocalSetupPanel({ pythonPath, onPythonPathChange, onPack
<div ref={logsEndRef} />
</pre>
)}
+ {installError && (
+ <div className="mt-2 flex flex-wrap items-center gap-2">
+ <span className="text-xs text-port-error">Install failed — see the log above.</span>
+ <QueueInstallInvestigationButton
+ label="PortOS local Python packages"
+ stage={installStage}
+ error={installError}
+ logs={installLog}
+ surface="client/src/components/settings/LocalSetupPanel.jsx"
+ />
+ </div>
+ )}
</>
)}
</div>
diff --git a/client/src/lib/README.md b/client/src/lib/README.md
index b8f3b22a27..82d12e9982 100644
--- a/client/src/lib/README.md
+++ b/client/src/lib/README.md
@@ -221,3 +221,4 @@ grep -i "what you want to do" client/src/lib/README.md
| `qrCode.js` | Deterministic SVG QR code generator for scoped mobile session join links (#5383). |
| `riggingReasons.js` | Client mirror of the character-rigging readiness reason labels in `server/services/rigging/readiness.js`: `RIGGING_UNAVAILABLE_REASONS` (reason code -> user-facing label), `RIGGING_REASON_FALLBACK`, and `riggingReasonLabel(code, fallback?)`. Render these anywhere a `GET /api/rigging/readiness` reason is shown; never re-declare the codes. Parity + code coverage enforced by `server/services/rigging/unavailableReasons.parity.test.js`. |
| `usdzExport.js` | AR Quick Look (USDZ) export for the 3D viewer (#5756): `exportSceneToUsdz(scene, { maxTextureSize })` lazy-loads three's `USDZExporter` and serializes the already-decoded scene to bytes, `countSceneTriangles(object3d)` measures an object graph against `AR_TRIANGLE_BUDGET`, and `supportsArQuickLook()` feature-detects the `<a rel="ar">` handoff (Safari on iOS/iPadOS only — never sniff the user agent) so a desktop is offered a download instead of a button that does nothing. `AR_MAX_TEXTURE_SIZE` bounds the file: USDZ stores every texel raw, with no Draco/meshopt equivalent. |
+| `installFailureTask.js` | Build the CoS task payload behind the installer-failure "Queue agent to investigate" button (#5981): `buildInstallFailureTask({ label, stage, error, logs, surface })` → `{ description, prompt }` carrying the installer name, failing stage, error text and a bounded log tail, and `installLogTail(logs)` (the `useInstallStream` `{ kind, text }` entries rendered as text, capped at `INSTALL_FAILURE_LOG_TAIL_LINES` / `INSTALL_FAILURE_LOG_TAIL_CHARS` so a 1000-line pip stream cannot push a huge body through `POST /api/cos/tasks`). Shared by both install modals and `LocalSetupPanel` so every surface queues the same reproducible context. |
diff --git a/client/src/lib/index.js b/client/src/lib/index.js
index 1ce9586c91..59de4bc9e0 100644
--- a/client/src/lib/index.js
+++ b/client/src/lib/index.js
@@ -45,6 +45,7 @@ export * from './imageTo3dReasons.js';
export * from './imageTo3dTargetFixture.js';
export * from './imageTo3dRenderOptions.js';
export * from './importerDeepLink.js';
+export * from './installFailureTask.js';
export * from './letteringDensity.js';
export * from './issueLength.js';
export * from './musicDuration.js';
diff --git a/client/src/lib/installFailureTask.js b/client/src/lib/installFailureTask.js
new file mode 100644
index 0000000000..8f6bb44468
--- /dev/null
+++ b/client/src/lib/installFailureTask.js
@@ -0,0 +1,81 @@
+/**
+ * Build the CoS task payload for the "Queue agent to investigate" action on an
+ * installer failure (#5981).
+ *
+ * Every installer failure surface (`Flux2InstallModal`, `RuntimeInstallModal`
+ * and its six call sites, `LocalSetupPanel`) reaches this one builder so the
+ * queued task always carries the same reproducible context: which installer
+ * failed, the stage it died on, the error text, and the tail of the streamed
+ * install log — enough for an agent to work the failure without the user
+ * re-typing anything.
+ *
+ * Pure: no React, no network. The caller hands the result straight to
+ * `addCosTask`.
+ */
+
+// Keep the log tail large enough to hold a pip/bash traceback but small enough
+// that a chatty 1000-line install stream can't push a multi-hundred-KB body
+// through `POST /api/cos/tasks`.
+export const INSTALL_FAILURE_LOG_TAIL_LINES = 80;
+export const INSTALL_FAILURE_LOG_TAIL_CHARS = 6000;
+
+const TRUNCATION_NOTE = '… (earlier log lines omitted)';
+
+/**
+ * Render the tail of a `useInstallStream` log array as plain text.
+ * Accepts the hook's `{ kind, text }` entries as well as bare strings.
+ * @param {Array<{ text?: string }|string>} logs
+ * @returns {string} '' when there is nothing to show.
+ */
+export function installLogTail(logs) {
+ if (!Array.isArray(logs)) return '';
+ const lines = logs
+ .map(entry => (typeof entry === 'string' ? entry : entry?.text))
+ .filter(text => typeof text === 'string' && text.trim() !== '');
+ if (lines.length === 0) return '';
+ const truncatedByLine = lines.length > INSTALL_FAILURE_LOG_TAIL_LINES;
+ let tail = lines.slice(-INSTALL_FAILURE_LOG_TAIL_LINES).join('\n');
+ let truncatedByChar = false;
+ if (tail.length > INSTALL_FAILURE_LOG_TAIL_CHARS) {
+ tail = tail.slice(-INSTALL_FAILURE_LOG_TAIL_CHARS);
+ truncatedByChar = true;
+ }
+ return truncatedByLine || truncatedByChar ? `${TRUNCATION_NOTE}\n${tail}` : tail;
+}
+
+const cleanLabel = (value) => (typeof value === 'string' ? value.trim() : '');
+
+/**
+ * @param {object} input
+ * @param {string} [input.label] - human name of the thing being installed ("FLUX.2 Runtime", "TRELLIS.2").
+ * @param {string} [input.stage] - `currentStage` from `useInstallStream`, when the surface tracks stages.
+ * @param {string} [input.error] - the hook's `error` string.
+ * @param {Array} [input.logs] - the hook's `logs` array.
+ * @param {string} [input.surface] - repo path of the UI that failed, so the agent starts in the right file.
+ * @returns {{ description: string, prompt: string }} ready for `addCosTask`.
+ */
+export function buildInstallFailureTask({ label, stage, error, logs, surface } = {}) {
+ const name = cleanLabel(label) || 'PortOS';
+ const failedStage = cleanLabel(stage);
+ const message = cleanLabel(error) || 'Installer failed with no error message.';
+ const description = failedStage
+ ? `Fix ${name} installer failure at the ${failedStage} stage`
+ : `Fix ${name} installer failure`;
+
+ const tail = installLogTail(logs);
+ const sections = [
+ `The ${name} installer failed in the PortOS UI. Investigate the root cause and fix it.`,
+ '',
+ `Installer: ${name}`,
+ `Failing stage: ${failedStage || '(not reported)'}`,
+ `Error: ${message}`,
+ ];
+ if (cleanLabel(surface)) sections.push(`Reported from: ${cleanLabel(surface)}`);
+ if (tail) sections.push('', 'Install log tail:', '```', tail, '```');
+ sections.push(
+ '',
+ 'Reproduce the failure, find why the install step fails on this machine, and fix the installer (script, dependency pin, or error handling) so it succeeds or reports an actionable message.',
+ );
+
+ return { description, prompt: sections.join('\n') };
+}
diff --git a/client/src/lib/installFailureTask.test.js b/client/src/lib/installFailureTask.test.js
new file mode 100644
index 0000000000..f9aaebf33e
--- /dev/null
+++ b/client/src/lib/installFailureTask.test.js
@@ -0,0 +1,79 @@
+import { describe, it, expect } from 'vitest';
+import {
+ buildInstallFailureTask,
+ installLogTail,
+ INSTALL_FAILURE_LOG_TAIL_LINES,
+ INSTALL_FAILURE_LOG_TAIL_CHARS,
+} from './installFailureTask.js';
+
+describe('installLogTail', () => {
+ it('renders the hook log entries as text and keeps a short log whole', () => {
+ const tail = installLogTail([
+ { kind: 'stage', text: 'venv' },
+ { kind: 'log', text: 'creating venv' },
+ { kind: 'error', text: 'boom' },
+ ]);
+ expect(tail).toBe('venv\ncreating venv\nboom');
+ expect(tail).not.toMatch(/omitted/);
+ });
+
+ it('drops empty entries and non-arrays rather than emitting blank lines', () => {
+ expect(installLogTail([{ text: 'a' }, { text: ' ' }, {}, 'b'])).toBe('a\nb');
+ expect(installLogTail(null)).toBe('');
+ expect(installLogTail([])).toBe('');
+ });
+
+ it('keeps only the tail of a long log and says it truncated', () => {
+ const logs = Array.from({ length: INSTALL_FAILURE_LOG_TAIL_LINES + 40 }, (_, i) => ({ text: `line ${i}` }));
+ const tail = installLogTail(logs);
+ const lines = tail.split('\n');
+ // One extra line for the truncation note.
+ expect(lines).toHaveLength(INSTALL_FAILURE_LOG_TAIL_LINES + 1);
+ expect(lines[0]).toMatch(/omitted/);
+ // The LAST lines survive — the traceback is at the end of a failed install.
+ expect(tail).toContain(`line ${INSTALL_FAILURE_LOG_TAIL_LINES + 39}`);
+ expect(tail).not.toContain('line 0\n');
+ });
+
+ it('bounds the payload by characters too, so a few very long lines cannot blow up the body', () => {
+ const logs = [{ text: 'x'.repeat(INSTALL_FAILURE_LOG_TAIL_CHARS * 2) }];
+ const tail = installLogTail(logs);
+ expect(tail.length).toBeLessThanOrEqual(INSTALL_FAILURE_LOG_TAIL_CHARS + 64);
+ expect(tail).toMatch(/omitted/);
+ });
+});
+
+describe('buildInstallFailureTask', () => {
+ it('names the installer and the failing stage in the description', () => {
+ const { description } = buildInstallFailureTask({ label: 'FLUX.2 Runtime', stage: 'venv' });
+ expect(description).toBe('Fix FLUX.2 Runtime installer failure at the venv stage');
+ });
+
+ it('omits the stage clause when the surface reports no stage', () => {
+ const { description } = buildInstallFailureTask({ label: 'TRELLIS.2', stage: '' });
+ expect(description).toBe('Fix TRELLIS.2 installer failure');
+ });
+
+ it('carries the stage, error, surface and log tail into the agent prompt', () => {
+ const { prompt } = buildInstallFailureTask({
+ label: 'TRELLIS.2',
+ stage: 'clone',
+ error: 'git exited 128',
+ logs: [{ text: 'cloning repo' }, { text: 'fatal: repository not found' }],
+ surface: 'client/src/components/install/RuntimeInstallModal.jsx',
+ });
+ expect(prompt).toContain('Installer: TRELLIS.2');
+ expect(prompt).toContain('Failing stage: clone');
+ expect(prompt).toContain('Error: git exited 128');
+ expect(prompt).toContain('Reported from: client/src/components/install/RuntimeInstallModal.jsx');
+ expect(prompt).toContain('fatal: repository not found');
+ });
+
+ it('still produces a usable task when the stream failed with no message or logs', () => {
+ const { description, prompt } = buildInstallFailureTask({});
+ expect(description).toBe('Fix PortOS installer failure');
+ expect(prompt).toContain('Failing stage: (not reported)');
+ expect(prompt).toContain('Installer failed with no error message.');
+ expect(prompt).not.toContain('Install log tail:');
+ });
+});