Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

fix(switchdash): a failed update is not a broken dependency (CHOO-1809)

Louis Amaudruzbc3c21a15411
diff --git a/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/host-setup-runner.test.ts b/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/host-setup-runner.test.ts
index 11ab0f9ed..e693f90e9 100644
--- a/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/host-setup-runner.test.ts
+++ b/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/host-setup-runner.test.ts
@@ -625,7 +625,14 @@ describe('updating one step', () => {
expect(updateOrder).toEqual([]);
});
- it('reports the updater failing, and does not claim the new version', async () => {
+ /**
+ * A failed update is not a broken dependency.
+ *
+ * Marking the step `failed` while its last observation was still `satisfied`
+ * rendered a red badge reading "Ready" — the label names the observation. The
+ * state has to come from looking, not from the updater's exit code.
+ */
+ it('stays installed when the update failed but the thing is still there', async () => {
const { runner } = makeRunner({
checks: { claude: [{ outcome: 'satisfied', version: '2.1.0' }] },
installs: {},
@@ -634,11 +641,40 @@ describe('updating one step', () => {
const result = await runner.updateStep(plan([installed()]), 'claude');
- expect(stateOf(result, 'claude')).toBe('failed');
- expect(result.steps[0]!.error).toBe('network unreachable');
+ expect(stateOf(result, 'claude')).toBe('satisfied');
expect(result.steps[0]!.version).toBe('2.1.0');
});
+ it('still reports why the update failed', async () => {
+ const { runner } = makeRunner({
+ checks: { claude: [{ outcome: 'satisfied', version: '2.1.0' }] },
+ installs: {},
+ updates: { claude: { ok: false, error: 'network unreachable' } },
+ });
+
+ const result = await runner.updateStep(plan([installed()]), 'claude');
+
+ expect(result.steps[0]!.error).toBe('network unreachable');
+ });
+
+ it('fails when a failed update took the thing with it', async () => {
+ // Codex updates by removing and re-adding. A remove that succeeded and an
+ // add that did not leaves nothing installed, and assuming otherwise would
+ // report a working agent that is not there.
+ const { runner } = makeRunner({
+ checks: { claude: [{ outcome: 'missing' }] },
+ installs: {},
+ updates: {
+ claude: { ok: false, error: 'the plugin was removed but could not be reinstalled' },
+ },
+ });
+
+ const result = await runner.updateStep(plan([installed()]), 'claude');
+
+ expect(stateOf(result, 'claude')).toBe('failed');
+ expect(result.steps[0]!.error).toContain('could not be reinstalled');
+ });
+
it('fails when the thing is gone after updating', async () => {
// A remove-then-add that removed and did not add leaves nothing installed.
// An exit code saying otherwise is a claim; the probe is the observation.
diff --git a/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/host-setup-runner.ts b/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/host-setup-runner.ts
index eb21e45e4..e98ebf367 100644
--- a/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/host-setup-runner.ts
+++ b/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/host-setup-runner.ts
@@ -255,12 +255,21 @@ export class HostSetupRunner {
const result = await this.deps.update(findStep(next, stepId));
if (!result.ok) {
- next = await this.patchStep(next, stepId, {
- state: 'failed',
- error: result.error,
- output: result.output ?? null,
- });
- return await this.settle(next);
+ // Look before judging, even on failure. A failed update usually leaves
+ // what was there working — but not always: the remove-then-add some
+ // CLIs need can remove and then fail to add. Assuming either way gets
+ // it wrong half the time, so the state comes from a fresh probe and
+ // only the *error* comes from the updater.
+ const looking = await this.patchStep(next, stepId, { state: 'checking', error: null });
+ const observed = await this.observe(looking, stepId);
+ const still = findStep(observed, stepId);
+ return await this.settle(
+ await this.patchStep(observed, stepId, {
+ state: still.outcome === 'satisfied' ? 'satisfied' : 'failed',
+ error: result.error,
+ output: result.output ?? null,
+ })
+ );
}
const verifying = await this.patchStep(next, stepId, { state: 'checking' });
diff --git a/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/step-outcomes.test.ts b/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/step-outcomes.test.ts
index ffb7cd981..98c554a83 100644
--- a/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/step-outcomes.test.ts
+++ b/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/step-outcomes.test.ts
@@ -228,3 +228,64 @@ describe('describeInstallFailure — the install command could not run', () => {
expect(message).toContain('package manager lock');
});
});
+
+/**
+ * npm refusing to write to a root-owned global prefix (CHOO-1809).
+ *
+ * npm's own report is a stack trace through arborist ending in advice to "run
+ * the command again as root" — addressed to a user who is not the one running
+ * it. Passed through, that is what the row shows.
+ */
+describe('describeInstallFailure — npm cannot write the global prefix', () => {
+ // Trimmed from a real transcript, after ANSI stripping and condensing.
+ const eacces = [
+ 'npm error code EACCES',
+ 'npm error syscall mkdir',
+ 'npm error path /usr/lib/node_modules/@openai',
+ 'npm error errno -13',
+ "npm error Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/@openai'",
+ 'npm error at async mkdir (node:internal/fs/promises:858:10)',
+ 'npm error The operation was rejected by your operating system.',
+ 'npm error the command again as root/Administrator.',
+ ].join('\n');
+
+ it('names the directory that could not be written', () => {
+ const message = describeInstallFailure(
+ 'Codex',
+ 'User does not have sufficient permissions.',
+ eacces
+ );
+
+ expect(message).toContain('/usr/lib/node_modules');
+ });
+
+ it('does not capture npm’s surrounding quote as part of the path', () => {
+ const message = describeInstallFailure('Codex', 'Install command failed.', eacces);
+
+ expect(message).not.toContain("@openai'");
+ });
+
+ it('says switchdash will not escalate on its own', () => {
+ // The user should know why we did not just sudo it, rather than assuming
+ // the install is broken.
+ const message = describeInstallFailure('Codex', 'Install command failed.', eacces);
+
+ expect(message).toContain('does not run installs as root');
+ });
+
+ it('reports the host as untouched, because the write never happened', () => {
+ const message = describeInstallFailure('Codex', 'Install command failed.', eacces);
+
+ expect(message).toContain('Nothing was changed');
+ });
+
+ it('leaves an unrelated permission failure to the generic message', () => {
+ const message = describeInstallFailure(
+ 'Git',
+ 'Permission denied.',
+ 'cannot open /etc/apt/sources.list'
+ );
+
+ expect(message).toBe('Permission denied.');
+ });
+});
diff --git a/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/step-outcomes.ts b/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/step-outcomes.ts
index 42330f903..7ccf2cafe 100644
--- a/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/step-outcomes.ts
+++ b/dash/apps/switchdash-desktop/src/main/core/remote-hosts/setup/step-outcomes.ts
@@ -79,6 +79,10 @@ const TOOLCHAIN_HINTS: Record<string, string> = {
npm: 'npm ships with Node.js — a Node install that reports a version but has no npm is usually a partial one (on Debian/Ubuntu the distro splits `nodejs` and `npm` into separate packages). Re-installing Node.js from the Node.js step generally fixes it.',
};
+/** npm refusing to write into a global prefix the SSH user does not own. */
+const NPM_GLOBAL_EACCES =
+ /EACCES[\s\S]*?(?:mkdir|open|access)[\s\S]*?(\/[^\s'"]*node_modules[^\s'"]*)/i;
+
/**
* Explain why an install failed, in terms the user can act on.
*
@@ -104,6 +108,16 @@ export function describeInstallFailure(
return `Could not install ${name}: another process${holder} on the host holds the package manager lock. That is usually the system's own automatic updates, which clear within a few minutes — but it can also be an earlier install left stuck, which will not clear on its own. If retrying keeps failing with the same pid, check that process on the host.`;
}
+ // npm's own EACCES report is thorough and completely unactionable from here:
+ // a stack trace through arborist, then advice to "try running the command
+ // again as root" addressed to a user who is not the one running it. What
+ // matters is which directory, and that switchdash does not silently escalate
+ // to sudo on someone's host.
+ const eaccesPath = NPM_GLOBAL_EACCES.exec(output ?? '')?.[1];
+ if (eaccesPath) {
+ return `Could not install ${name}: the SSH user cannot write to \`${eaccesPath}\`, which is where this host's npm installs global packages. switchdash does not run installs as root on its own. Either make npm's global prefix writable by this user (\`npm config set prefix\` pointing somewhere it owns, with that bin directory on PATH), or install this agent on the host manually with sudo and re-check. Nothing was changed on the host.`;
+ }
+
// The install never started: the tool that runs it is not there. Left raw,
// this reaches the user as a screen of login banner ending in
// "npm: command not found", which reads as the agent being broken rather
diff --git a/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/setup/setup-detail-sheet.tsx b/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/setup/setup-detail-sheet.tsx
index 5215b9073..7f745287a 100644
--- a/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/setup/setup-detail-sheet.tsx
+++ b/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/setup/setup-detail-sheet.tsx
@@ -139,10 +139,14 @@ function ObservationCard({
</p>
)}
- {step.state === 'failed' && step.error && (
- <p className="text-destructive text-xs">{step.error}</p>
- )}
- {step.state === 'failed' && step.output && <FailureOutput output={step.output} />}
+ {/*
+ Not gated on `failed`. An update that fails over something still
+ installed leaves the step satisfied — correctly, it works — but the
+ attempt did fail, and hiding the reason leaves a row that silently
+ refuses to move off "Update available" with nothing to explain why.
+ */}
+ {step.error && <p className="text-destructive text-xs">{step.error}</p>}
+ {step.output && <FailureOutput output={step.output} />}
</div>
);
}
diff --git a/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/setup/step-presentation.test.ts b/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/setup/step-presentation.test.ts
index 5139c0497..fbfc33e2a 100644
--- a/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/setup/step-presentation.test.ts
+++ b/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/setup/step-presentation.test.ts
@@ -359,3 +359,29 @@ describe('stepBadge — an update in flight', () => {
});
});
});
+
+/**
+ * A red badge reading "Ready" (CHOO-1809).
+ *
+ * The failed label names the last observation, which is right for an install
+ * ("Not installed") and self-contradictory for an action that failed over
+ * something present.
+ */
+describe('stepBadge — a failed action over something that is installed', () => {
+ it('never labels a failed step Ready', () => {
+ const badge = stepBadge(step({ state: 'failed', outcome: 'satisfied', version: '0.146.0' }));
+
+ expect(badge.label).not.toBe('Ready');
+ expect(badge.tone).toBe('danger');
+ });
+
+ it('says what actually happened instead', () => {
+ expect(stepBadge(step({ state: 'failed', outcome: 'satisfied' })).label).toBe(
+ 'Last action failed'
+ );
+ });
+
+ it('still names the observation when it is the useful thing to say', () => {
+ expect(stepBadge(step({ state: 'failed', outcome: 'missing' })).label).toBe('Not installed');
+ });
+});
diff --git a/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/setup/step-presentation.ts b/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/setup/step-presentation.ts
index 5c8cd0566..1b95af804 100644
--- a/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/setup/step-presentation.ts
+++ b/dash/apps/switchdash-desktop/src/renderer/features/remote-hosts/setup/step-presentation.ts
@@ -171,7 +171,14 @@ export function stepBadge(step: HostSetupStep): BadgeSpec {
case 'updating':
return { tone: 'info', label: 'Updating…' };
case 'failed':
- return { tone: 'danger', label: outcomeLabel(step.outcome) };
+ // The label normally names the last observation, which for a failed
+ // install is the useful thing to say ("Not installed"). It must not be
+ // said when that observation was `satisfied`: a failed action over
+ // something that is present rendered a red badge reading "Ready", which
+ // is two contradictions in three words.
+ return step.outcome === 'satisfied'
+ ? { tone: 'danger', label: 'Last action failed' }
+ : { tone: 'danger', label: outcomeLabel(step.outcome) };
case 'skipped':
return { tone: 'neutral', label: 'Skipped' };
case 'pending':