Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

release-extension: feed offers the newest signed release and swaps in safely

shukieshah3457c7181e94
diff --git a/.github/workflows/release-extension.yml b/.github/workflows/release-extension.yml
index db2bf83f..aac3ad3a 100644
--- a/.github/workflows/release-extension.yml
+++ b/.github/workflows/release-extension.yml
@@ -17,15 +17,18 @@ name: Release Browser Extension
# No `environment: release`. That environment exists to gate the Apple signing
# secrets, which these jobs do not use, so putting them behind the same approval
# would add friction without protecting anything. Same reasoning as the
-# windows-package job in release.yml. The one secret here, the Chrome signing
-# key, lives in its own `extension-signing` environment, which admits only
-# `ext-v*` tags and is entered only by the `sign` job.
+# windows-package job in release.yml. The Chrome signing key lives in its own
+# `extension-signing` environment, which admits only `ext-v*` tags and is
+# entered only by the `sign` job; the `firefox` job reads the AMO_JWT_ISSUER and
+# AMO_JWT_SECRET repository secrets.
#
# The jobs that run `npm ci` hold a read-only token: a dependency's lifecycle
# script runs with whatever token the job has, and a write token would let it
# overwrite release assets and their .sha256 files. They hand their archives
-# over as workflow artifacts, and only `release` and `attach-firefox`, which
-# never check out or install anything, get `contents: write` (#904).
+# over as workflow artifacts. Only `release` and `attach-firefox`, which never
+# check out or install anything, and `feed`, which checks out only
+# browser-extension/tools and runs it with plain Node, get `contents: write`
+# (#904).
#
# Chrome: besides the zip (load unpacked, for development), the `sign` job signs
# the same bytes as a CRX3 file with the key that fixes the extension ID
@@ -343,11 +346,13 @@ jobs:
--repo "$REPO" --clobber
fi
- # Points the update feed at this release's CRX. The feed is updates.xml on a
- # fixed `ext-updates` release, so its URL never changes: it is the manifest's
- # update_url and the URL fleets put in policy. It runs after the CRX is
- # published and downloadable, and refuses to offer a lower version than the
- # feed already does, so re-running an old tag cannot roll fleets back.
+ # Points the update feed at the newest published signed build. The feed is
+ # updates.xml on a fixed `ext-updates` release, so its URL never changes: it
+ # is the manifest's update_url and the URL fleets put in policy. It runs after
+ # this release's CRX is published, offers the highest ext-v* release with a
+ # signed CRX rather than only this run's version, and refuses to offer a lower
+ # version than the feed already does, so neither a feed job GitHub cancelled
+ # nor a re-run of an older tag can leave fleets behind.
feed:
needs: [build, sign, release]
runs-on: ubuntu-latest
@@ -363,7 +368,6 @@ jobs:
REPO: ${{ github.repository }}
TAG: ${{ github.ref_name }}
VERSION: ${{ needs.build.outputs.version }}
- CRX: ${{ needs.sign.outputs.crx }}
EXTENSION_ID: ${{ needs.sign.outputs.id }}
FEED_TAG: ext-updates
GH_TOKEN: ${{ github.token }}
@@ -387,12 +391,24 @@ jobs:
exit 1
fi
+ # Offer the newest published release with a signed build, not only
+ # this run's version. GitHub keeps one waiting job per concurrency
+ # group and cancels the others, so a newer tag's feed job may never
+ # run; whichever job runs last still leaves the feed right.
+ gh api --paginate "repos/${REPO}/releases?per_page=100" \
+ --jq '.[] | {tag: .tag_name, draft: .draft, assets: [.assets[].name]}' > releases.ndjson
+ offered="$(node "$tools/pack-crx.mjs" newest --releases releases.ndjson)"
+ if [ "$offered" != "$VERSION" ]; then
+ echo "::notice title=Feed offers a newer release::ext-v${offered} is newer than this run's ${VERSION}, so the feed offers it."
+ fi
+
# Fetch the CRX the way Chrome will, through its public download URL,
# and check it is the signed build before pointing anyone at it.
- codebase="https://github.com/${REPO}/releases/download/${TAG}/${CRX}"
- curl -fsSL --retry 5 --retry-all-errors -o "$CRX" "$codebase"
- node "$tools/pack-crx.mjs" verify --crx "$CRX"
- sha256="$(shasum -a 256 "$CRX" | cut -d' ' -f1)"
+ crx="agent-beacon-browser-extension-${offered}-chrome.crx"
+ codebase="https://github.com/${REPO}/releases/download/ext-v${offered}/${crx}"
+ curl -fsSL --retry 5 --retry-all-errors -o "$crx" "$codebase"
+ node "$tools/pack-crx.mjs" verify --crx "$crx"
+ sha256="$(shasum -a 256 "$crx" | cut -d' ' -f1)"
# Created once, never "Latest" (the CLI keeps that label) and marked
# pre-release so it is not mistaken for a version.
@@ -404,16 +420,27 @@ jobs:
fi
# Only a feed release without updates.xml means "no feed yet". Any
- # other failure to read the current feed fails the job, because
- # skipping the comparison below could roll fleets back.
+ # other failure to read the current feed fails the job.
rm -f current.xml
feed_assets="$(gh release view "$FEED_TAG" --repo "$REPO" --json assets --jq '.assets[].name')"
if printf '%s\n' "$feed_assets" | grep -qxF updates.xml; then
gh release download "$FEED_TAG" --repo "$REPO" --pattern updates.xml --output current.xml
fi
- node "$tools/pack-crx.mjs" feed --id "$EXTENSION_ID" --version "$VERSION" \
- --codebase "$codebase" --sha256 "$sha256" --out updates.xml --current current.xml
- gh release upload "$FEED_TAG" updates.xml --repo "$REPO" --clobber
+ node "$tools/pack-crx.mjs" feed --id "$EXTENSION_ID" --version "$offered" \
+ --codebase "$codebase" --sha256 "$sha256" --out updates.xml.new --current current.xml
+
+ # Upload under a temporary name, then swap it in, so a failed upload
+ # leaves the live feed in place. `--clobber` would delete it first.
+ asset_id() {
+ gh api "repos/${REPO}/releases/tags/${FEED_TAG}" --jq ".assets[] | select(.name == \"$1\") | .id"
+ }
+ stale="$(asset_id updates.xml.new)"
+ if [ -n "$stale" ]; then gh api -X DELETE "repos/${REPO}/releases/assets/${stale}"; fi
+ gh release upload "$FEED_TAG" updates.xml.new --repo "$REPO"
+ new_id="$(asset_id updates.xml.new)"
+ old_id="$(asset_id updates.xml)"
+ if [ -n "$old_id" ]; then gh api -X DELETE "repos/${REPO}/releases/assets/${old_id}"; fi
+ gh api -X PATCH "repos/${REPO}/releases/assets/${new_id}" -f name=updates.xml >/dev/null
# Read it back through the URL installed copies poll, parsing the
# version the feed offers for this extension (a plain grep would also
@@ -423,13 +450,13 @@ jobs:
import { feedVersion } from "./browser-extension/tools/pack-crx.mjs";
let xml = ""; for await (const chunk of process.stdin) xml += chunk;
console.log(feedVersion(xml, process.argv[1]) ?? "");' "$EXTENSION_ID" || true)"
- if [ "$live" = "$VERSION" ]; then
- echo "feed now offers ${VERSION}: $update_url"
+ if [ "$live" = "$offered" ]; then
+ echo "feed now offers ${offered}: $update_url"
exit 0
fi
sleep 10
done
- echo "the feed at $update_url does not offer ${VERSION}"
+ echo "the feed at $update_url does not offer ${offered}"
exit 1
firefox:
diff --git a/CLAUDE.md b/CLAUDE.md
index ff026292..9a6d0ea9 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -670,9 +670,14 @@ missing key fails the release. The key fixes the extension ID that every fleet's
policy names, so it is never rotated; a copy is kept in the company password
manager, and losing it means a new extension ID and a policy change for every fleet.
-The `feed` job (one concurrency group across all tags) then downloads the CRX from its public release URL, verifies it,
-and replaces `updates.xml` on the fixed `ext-updates` release (created on first
-use, `--latest=false --prerelease`). That file's URL is `CHROME_UPDATE_URL`, the
+The `feed` job (one concurrency group across all tags) then picks the highest
+published `ext-v*` release that has a signed CRX and its checksum (`pack-crx.mjs
+newest`), not only its own version, because GitHub keeps one waiting job per
+concurrency group and cancels the rest. It downloads that CRX from its public
+release URL, verifies it, and swaps a new `updates.xml` in on the fixed
+`ext-updates` release (created on first use, `--latest=false --prerelease`),
+uploading it as `updates.xml.new` and renaming it so a failed upload leaves the
+live feed in place. That file's URL is `CHROME_UPDATE_URL`, the
manifest's `update_url` and the URL fleets put in policy, so it must never move
without first shipping a version whose `update_url` names the new place. The job
refuses to offer a lower version than the feed already does, so re-running an old
diff --git a/browser-extension/test/unit/pack-crx.test.ts b/browser-extension/test/unit/pack-crx.test.ts
index 80b72df6..c6df3f06 100644
--- a/browser-extension/test/unit/pack-crx.test.ts
+++ b/browser-extension/test/unit/pack-crx.test.ts
@@ -7,7 +7,16 @@ import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
-import { compareVersions, crxIdFromPublicKey, feedVersion, feedXml, packCrx, readCrx } from '../../tools/pack-crx.mjs';
+import {
+ compareVersions,
+ crxAssetName,
+ crxIdFromPublicKey,
+ feedVersion,
+ feedXml,
+ newestSignedVersion,
+ packCrx,
+ readCrx,
+} from '../../tools/pack-crx.mjs';
const tool = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', '..', 'tools', 'pack-crx.mjs');
const rsaPem = () =>
@@ -88,6 +97,23 @@ describe('update feed', () => {
expect(() => feedXml({ ...ok, sha256: 'A'.repeat(64) })).toThrow('SHA-256');
});
+ it('offers the newest published release that carries a signed build', () => {
+ const signed = (v: string) => [crxAssetName(v), `${crxAssetName(v)}.sha256`, `agent-beacon-browser-extension-${v}-chrome.zip`];
+ expect(
+ newestSignedVersion([
+ { tag: 'ext-v0.2.0', assets: signed('0.2.0') },
+ { tag: 'ext-v0.10.0', assets: signed('0.10.0') },
+ { tag: 'ext-v0.9.0', assets: signed('0.9.0') },
+ { tag: 'ext-v0.11.0', draft: true, assets: signed('0.11.0') }, // not published
+ { tag: 'ext-v0.12.0', assets: [crxAssetName('0.12.0')] }, // CRX without its checksum
+ { tag: 'ext-v0.1.1', assets: ['agent-beacon-browser-extension-0.1.1-chrome.zip'] }, // before signing
+ { tag: 'v1.3.60', assets: signed('1.3.60') }, // a CLI release
+ { tag: 'ext-updates', assets: ['updates.xml'] },
+ ]),
+ ).toBe('0.10.0');
+ expect(newestSignedVersion([{ tag: 'ext-v0.1.1', assets: [] }])).toBeUndefined();
+ });
+
it('compares dotted versions numerically', () => {
expect(compareVersions('0.10.0', '0.9.9')).toBeGreaterThan(0);
expect(compareVersions('1.0', '1.0.0')).toBe(0);
diff --git a/browser-extension/tools/pack-crx.d.mts b/browser-extension/tools/pack-crx.d.mts
index a1b640ed..98880abc 100644
--- a/browser-extension/tools/pack-crx.d.mts
+++ b/browser-extension/tools/pack-crx.d.mts
@@ -7,3 +7,7 @@ export declare function readCrx(crx: Buffer): { id: string; zip: Buffer };
export declare function feedXml(feed: { id: string; version: string; codebase: string; sha256: string }): string;
export declare function feedVersion(xml: string, id: string): string | undefined;
export declare function compareVersions(a: string, b: string): number;
+export declare function crxAssetName(version: string): string;
+export declare function newestSignedVersion(
+ releases: { tag?: string; draft?: boolean; assets?: string[] }[],
+): string | undefined;
diff --git a/browser-extension/tools/pack-crx.mjs b/browser-extension/tools/pack-crx.mjs
index 099839f4..a23133b2 100644
--- a/browser-extension/tools/pack-crx.mjs
+++ b/browser-extension/tools/pack-crx.mjs
@@ -144,6 +144,30 @@ export function feedVersion(xml, id) {
return app ? /\bversion=['"]([^'"]+)['"]/.exec(app[1])?.[1] : undefined;
}
+/** The signed build's asset name on an `ext-v<version>` release. */
+export function crxAssetName(version) {
+ return `agent-beacon-browser-extension-${version}-chrome.crx`;
+}
+
+/**
+ * The highest version among published `ext-v*` releases that carry a signed CRX and its checksum,
+ * or undefined. The feed offers this rather than whichever release ran last, so a feed job that
+ * never ran, or a re-run of an older tag, cannot leave fleets on an older version.
+ * @param {{ tag?: string, draft?: boolean, assets?: string[] }[]} releases
+ */
+export function newestSignedVersion(releases) {
+ let newest;
+ for (const release of releases) {
+ if (release.draft || !release.tag?.startsWith('ext-v')) continue;
+ const version = release.tag.slice('ext-v'.length);
+ if (!VERSION_PATTERN.test(version)) continue;
+ const crx = crxAssetName(version);
+ if (!release.assets?.includes(crx) || !release.assets.includes(`${crx}.sha256`)) continue;
+ if (newest === undefined || compareVersions(version, newest) > 0) newest = version;
+ }
+ return newest;
+}
+
/** Compare dotted Chrome versions numerically: negative, zero or positive. */
export function compareVersions(a, b) {
const pa = a.split('.').map(Number);
@@ -218,10 +242,12 @@ const USAGE = `usage:
pack-crx.mjs pack --zip <archive.zip> --key-env <VAR> | --key <key.pem> --out <file.crx> [--expect-id <id>]
pack-crx.mjs verify --crx <file.crx> [--zip <archive.zip>] [--expect-id <id>]
pack-crx.mjs feed --id <id> --version <v> --codebase <url> --sha256 <hex> --out <updates.xml> [--current <updates.xml>]
+ pack-crx.mjs newest --releases <releases.ndjson>
--expect-id defaults to CHROME_EXTENSION_ID in targets.mjs. pack prints the extension ID.
feed refuses to write a version lower than the one in --current, so re-running an old release
-cannot roll installed extensions back.`;
+cannot roll installed extensions back. newest prints the highest ext-v* version whose release has a
+signed CRX and its checksum, from one {"tag", "draft", "assets"} object per line.`;
function parseArgs(argv) {
const opts = {};
@@ -275,6 +301,13 @@ function main(argv) {
process.stdout.write(xml);
return;
}
+ case 'newest': {
+ const lines = fs.readFileSync(need(opts, 'releases'), 'utf8').split('\n').filter((line) => line.trim());
+ const version = newestSignedVersion(lines.map((line) => JSON.parse(line)));
+ if (!version) throw new Error('no published ext-v* release has a signed CRX and its checksum');
+ console.log(version);
+ return;
+ }
default:
throw new Error(USAGE);
}