Skip to content

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

Find canary updates through the releases API, not the Atom feed

Petr Bauch40bf03efad8e
diff --git a/console/agents/risky-areas/updater.md b/console/agents/risky-areas/updater.md
index 5b2c7ee95..7536cacb4 100644
--- a/console/agents/risky-areas/updater.md
+++ b/console/agents/risky-areas/updater.md
@@ -3,6 +3,7 @@
## Main Files
- `src/main/core/updates/update-service.ts`
+- `src/main/core/updates/canary-feed.ts` — finds the newest canary release
- `src/main/core/updates/controller.ts`
- `src/main/core/updates/dev-harness.ts` — `SWITCHDASH_FAKE_UPDATE` replay
- `scripts/merge-mac-update-manifest.ts` — the merged macOS channel manifest
@@ -66,7 +67,7 @@ electron-builder suffixes the channel file per architecture on Linux only
There is no `latest-mac-x64.yml` to reach for, and giving one architecture its own
`channel` would not help either — `update-service.ts` calls `setFeedURL` with a bare
provider descriptor, so whatever channel the packaged `app-update.yml` carries is
-discarded at runtime.
+discarded at runtime (canary sets its own `channel` in that descriptor).
So the release workflow builds each architecture on a runner of that architecture,
neither job publishes a manifest, and `merge-mac-manifest` combines the two into one
@@ -97,7 +98,9 @@ constant named "channel" must be one.
The app does **not** override `autoUpdater.channel`; the GitHub provider resolves the channel naturally:
- **Stable** (`allowPrerelease=false`): resolves to `latest`, fetches `latest*.yml` from the newest non-prerelease GitHub release.
-- **Canary** (`allowPrerelease=true`): resolves the target release tag from the Atom feed by matching the semver prerelease identifier of the installed version (`canary`) against each entry. Once a `-canary.N` tag is found it fetches `canary*.yml` from that release, as defined by `channel: 'canary'` in `electron-builder.canary.config.ts`.
+- **Canary** does **not** use the GitHub provider. `canary-feed.ts` lists releases through the GitHub API, picks the newest published `v*-canary.*` tag, and `update-service.ts` points the **generic** provider at that release's download URL with `channel: 'canary'`, so it fetches `canary*.yml` (named by `channel: 'canary'` in `electron-builder.canary.config.ts`) and the installers from there.
+
+ Why not the GitHub provider: with `allowPrerelease` it finds a prerelease through `releases.atom`, which lists only the ten newest releases of the repo. The agents controller publishes a prerelease for every build on main, several a day, so canaries fall out of the feed within hours and the provider fails with `ERR_UPDATER_NO_PUBLISHED_VERSIONS`. Do not switch canary back to it while the repo publishes other prereleases.
- Canary publishes to GitHub as prereleases. `ALLOW_PRERELEASE` in `update-service.ts` is driven by `IS_CANARY` so canary clients accept prerelease versions automatically.
- The `publish-release` workflow job runs after all platform builds complete to flip the draft GitHub release to published. Until that job finishes the release remains a draft and is invisible to electron-updater clients.
diff --git a/console/apps/switch-console-desktop/src/main/core/updates/canary-feed.test.ts b/console/apps/switch-console-desktop/src/main/core/updates/canary-feed.test.ts
new file mode 100644
index 000000000..4acec6ad6
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/main/core/updates/canary-feed.test.ts
@@ -0,0 +1,73 @@
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { resolveCanaryFeedUrl } from './canary-feed';
+
+const DOWNLOAD = 'https://github.com/sandbox-quantum/switch/releases/download';
+
+function controllerBuilds(count: number) {
+ return Array.from({ length: count }, (_, i) => ({
+ tag_name: `switch-agent-controller-v0.31.1-dev.${i}.gabc1234`,
+ draft: false,
+ }));
+}
+
+function serve(pages: unknown[][]) {
+ const fetchMock = vi.fn(async (url: string) => {
+ const page = Number(new URL(url).searchParams.get('page'));
+ return new Response(JSON.stringify(pages[page - 1] ?? []), { status: 200 });
+ });
+ vi.stubGlobal('fetch', fetchMock);
+ return fetchMock;
+}
+
+afterEach(() => {
+ vi.unstubAllGlobals();
+});
+
+describe('resolveCanaryFeedUrl', () => {
+ it('finds a canary pushed off the first page by agents controller builds', async () => {
+ const fetchMock = serve([
+ controllerBuilds(100),
+ [
+ { tag_name: 'switch-console-v0.40.1', draft: false },
+ { tag_name: 'v0.41.0-canary.1', draft: false },
+ { tag_name: 'v0.40.0-canary.13', draft: false },
+ ],
+ ]);
+
+ await expect(resolveCanaryFeedUrl()).resolves.toBe(`${DOWNLOAD}/v0.41.0-canary.1`);
+ expect(fetchMock).toHaveBeenCalledTimes(2);
+ });
+
+ it('skips a draft, whose assets may still be uploading', async () => {
+ serve([
+ [
+ { tag_name: 'v0.41.0-canary.2', draft: true },
+ { tag_name: 'v0.41.0-canary.rc.1', draft: false },
+ ],
+ ]);
+
+ await expect(resolveCanaryFeedUrl()).resolves.toBe(`${DOWNLOAD}/v0.41.0-canary.rc.1`);
+ });
+
+ it('fails loudly when no canary is published', async () => {
+ serve([controllerBuilds(3)]);
+
+ await expect(resolveCanaryFeedUrl()).rejects.toThrow(/No published canary release/);
+ });
+
+ it('stops paging after a bounded number of pages', async () => {
+ const fetchMock = serve(Array.from({ length: 10 }, () => controllerBuilds(100)));
+
+ await expect(resolveCanaryFeedUrl()).rejects.toThrow(/No published canary release/);
+ expect(fetchMock).toHaveBeenCalledTimes(5);
+ });
+
+ it('surfaces a GitHub error rather than reporting no canary', async () => {
+ vi.stubGlobal(
+ 'fetch',
+ vi.fn(async () => new Response('rate limited', { status: 403 }))
+ );
+
+ await expect(resolveCanaryFeedUrl()).rejects.toThrow(/HTTP 403/);
+ });
+});
diff --git a/console/apps/switch-console-desktop/src/main/core/updates/canary-feed.ts b/console/apps/switch-console-desktop/src/main/core/updates/canary-feed.ts
new file mode 100644
index 000000000..4ded2300a
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/main/core/updates/canary-feed.ts
@@ -0,0 +1,48 @@
+import { RELEASE_REPO_NAME, RELEASE_REPO_OWNER } from '@shared/app-identity';
+
+const RELEASES_API_URL = `https://api.github.com/repos/${RELEASE_REPO_OWNER}/${RELEASE_REPO_NAME}/releases`;
+const RELEASES_DOWNLOAD_URL = `https://github.com/${RELEASE_REPO_OWNER}/${RELEASE_REPO_NAME}/releases/download`;
+const PAGE_SIZE = 100;
+/**
+ * How far back to look. The repo also publishes a prerelease for every agents
+ * controller build, several a day, so a canary can sit a few pages down.
+ */
+const MAX_PAGES = 5;
+
+/** Canary tags as .github/workflows/switch-console-release.yml accepts them. */
+const CANARY_TAG = /^v\d+\.\d+\.\d+-canary\.(\d+|rc\.\d+)$/;
+
+interface GitHubRelease {
+ tag_name: string;
+ draft: boolean;
+}
+
+/**
+ * The download URL of the newest published canary release, for electron-updater's
+ * generic provider to read `canary*.yml` and the installers from.
+ *
+ * electron-updater's own GitHub provider finds a prerelease through the releases
+ * Atom feed, which lists only the ten newest releases of the repo. The agents
+ * controller's per-build prereleases push every canary out of it within hours,
+ * and the provider then reports ERR_UPDATER_NO_PUBLISHED_VERSIONS. The releases
+ * API can page further back.
+ *
+ * GitHub lists releases newest first, so the first canary found is the latest.
+ */
+export async function resolveCanaryFeedUrl(): Promise<string> {
+ for (let page = 1; page <= MAX_PAGES; page++) {
+ const response = await fetch(`${RELEASES_API_URL}?per_page=${PAGE_SIZE}&page=${page}`, {
+ headers: { Accept: 'application/vnd.github+json', 'Cache-Control': 'no-cache' },
+ });
+ if (!response.ok) {
+ throw new Error(`Could not list canary releases: GitHub answered HTTP ${response.status}`);
+ }
+ const releases = (await response.json()) as GitHubRelease[];
+ const canary = releases.find((r) => !r.draft && CANARY_TAG.test(r.tag_name));
+ if (canary) return `${RELEASES_DOWNLOAD_URL}/${canary.tag_name}`;
+ if (releases.length < PAGE_SIZE) break;
+ }
+ throw new Error(
+ `No published canary release among the newest ${MAX_PAGES * PAGE_SIZE} releases of the repo`
+ );
+}
diff --git a/console/apps/switch-console-desktop/src/main/core/updates/update-service.ts b/console/apps/switch-console-desktop/src/main/core/updates/update-service.ts
index e28b18823..c7a188623 100644
--- a/console/apps/switch-console-desktop/src/main/core/updates/update-service.ts
+++ b/console/apps/switch-console-desktop/src/main/core/updates/update-service.ts
@@ -27,6 +27,7 @@ import {
updateProgressEvent,
} from '@shared/events/updateEvents';
import { switchConsoleReleaseApiUrl } from '@shared/urls';
+import { resolveCanaryFeedUrl } from './canary-feed';
import {
FAKE_UPDATE_VERSION_ENV_VAR,
FakeUpdateDriver,
@@ -292,11 +293,19 @@ class UpdateService implements IInitializable, IDisposable {
if (this.fake) return this.fake.check();
- autoUpdater.setFeedURL({
- provider: 'github',
- owner: RELEASE_REPO_OWNER,
- repo: RELEASE_REPO_NAME,
- });
+ if (IS_CANARY) {
+ autoUpdater.setFeedURL({
+ provider: 'generic',
+ url: await resolveCanaryFeedUrl(),
+ channel: 'canary',
+ });
+ } else {
+ autoUpdater.setFeedURL({
+ provider: 'github',
+ owner: RELEASE_REPO_OWNER,
+ repo: RELEASE_REPO_NAME,
+ });
+ }
log.info('Checking for updates...', {
channel: UPDATE_CHANNEL,
diff --git a/console/apps/switch-console-desktop/src/main/core/updates/utils.ts b/console/apps/switch-console-desktop/src/main/core/updates/utils.ts
index 42ef5465b..bbcb16db8 100644
--- a/console/apps/switch-console-desktop/src/main/core/updates/utils.ts
+++ b/console/apps/switch-console-desktop/src/main/core/updates/utils.ts
@@ -16,14 +16,17 @@ export function formatUpdaterError(error: unknown): string {
statusMessage?: string;
description?: string;
};
- const status = err.statusCode || err.code || err.status;
+ const status = err.statusCode || err.status;
const statusText = err.statusMessage || err.description;
if (status) {
const base = `Update request failed with HTTP ${status}`;
return statusText ? `${base}: ${stripMarkupAndTruncate(String(statusText))}` : base;
}
const message = error instanceof Error ? error.message : String(error ?? 'Unknown update error');
- return stripMarkupAndTruncate(message);
+ // electron-updater's own failures carry an ERR_UPDATER_* code, not an HTTP status.
+ return err.code
+ ? `${stripMarkupAndTruncate(message)} (${err.code})`
+ : stripMarkupAndTruncate(message);
}
export function sanitizeUpdaterLogArgs(args: unknown[]) {
diff --git a/console/apps/switch-console-desktop/src/shared/urls.test.ts b/console/apps/switch-console-desktop/src/shared/urls.test.ts
index 18cd0514c..b0bcda8ef 100644
--- a/console/apps/switch-console-desktop/src/shared/urls.test.ts
+++ b/console/apps/switch-console-desktop/src/shared/urls.test.ts
@@ -15,8 +15,9 @@ describe('switchConsoleReleaseTag', () => {
expect(switchConsoleReleaseTag('v0.18.2')).toBe('switch-console-v0.18.2');
});
- it('keeps a prerelease identifier intact', () => {
- expect(switchConsoleReleaseTag('0.19.0-canary.4')).toBe('switch-console-v0.19.0-canary.4');
+ it('tags a canary bare, as the release workflow does', () => {
+ expect(switchConsoleReleaseTag('0.19.0-canary.4')).toBe('v0.19.0-canary.4');
+ expect(switchConsoleReleaseTag('v0.19.0-canary.rc.1')).toBe('v0.19.0-canary.rc.1');
});
});
diff --git a/console/apps/switch-console-desktop/src/shared/urls.ts b/console/apps/switch-console-desktop/src/shared/urls.ts
index 1c6de1112..d4fab0b24 100644
--- a/console/apps/switch-console-desktop/src/shared/urls.ts
+++ b/console/apps/switch-console-desktop/src/shared/urls.ts
@@ -7,11 +7,13 @@ const SWITCH_CONSOLE_RELEASES_API_URL =
/**
* The desktop app shares its repo with switch-core, so its release tags are
- * namespaced `switch-console-v<version>` — see .github/workflows/switch-console-release.yml,
- * which only triggers on that prefix. A bare `v<version>` tag belongs to nothing.
+ * namespaced `switch-console-v<version>` — see .github/workflows/switch-console-release.yml.
+ * Canaries are the exception: they are tagged bare `v<version>`, because
+ * electron-updater skips any prerelease tag that is not plain semver.
*/
export function switchConsoleReleaseTag(version: string): string {
- return `switch-console-v${version.replace(/^v/, '')}`;
+ const bare = version.replace(/^v/, '');
+ return bare.includes('-canary.') ? `v${bare}` : `switch-console-v${bare}`;
}
/**