Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

perf(release): reuse warmed Rust and Cua Driver caches in desktop release builds (#3018)

Call Whited813384dcd8c
diff --git a/.github/workflows/desktop-package.yml b/.github/workflows/desktop-package.yml
index ead098648..c68b7faa0 100644
--- a/.github/workflows/desktop-package.yml
+++ b/.github/workflows/desktop-package.yml
@@ -4,7 +4,22 @@ name: desktop-self-contained-package
# without the complete Apple credential set; manual builds sign when the whole
# set is configured and stay ad-hoc when none of it is. Apple and updater keys
# come only from desktop-updater.
+#
+# Only reruns of the same tag can read a tag's caches, so release builds
+# restore caches but never save them. The unsigned cache warm-up (a master push
+# that changes a Rust cache input, and a daily run) builds every target without
+# signing or uploading anything; release builds restore its default-branch
+# caches.
on:
+ push:
+ branches: [master]
+ paths:
+ - desktop/Cargo.lock
+ - desktop/cua-driver/**
+ - desktop/scripts/prepare-cua-driver.py
+ - .github/workflows/desktop-package.yml
+ schedule:
+ - cron: "41 18 * * *"
workflow_dispatch:
inputs:
version:
@@ -41,6 +56,10 @@ jobs:
name: ${{ matrix.target }}
runs-on: ${{ matrix.os }}
environment: desktop-updater
+ env:
+ # Never a release: a release build always carries its tag.
+ DESKTOP_CACHE_WARMUP: ${{ !inputs.release_tag && (github.event_name == 'push' || github.event_name == 'schedule') }}
+ DESKTOP_VERSION: ${{ inputs.version || '0.0.0' }}
strategy:
fail-fast: false
matrix:
@@ -77,15 +96,37 @@ jobs:
cache-dependency-glob: uv.lock
prune-cache: true
- - uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
+ # Cargo artifacts and a prepared Cua Driver are reused only from the same
+ # compiler and Apple SDK; a toolchain change starts a new cache entry.
+ - name: Resolve build cache identity
+ id: toolchain
+ shell: bash
+ run: |
+ set -euo pipefail
+ fingerprint() {
+ python -c 'import hashlib, sys; print(hashlib.sha256(sys.stdin.buffer.read()).hexdigest()[:16])'
+ }
+ echo "rustc=$(rustc -vV | fingerprint)" >> "$GITHUB_OUTPUT"
+ if [ "$RUNNER_OS" = macOS ]; then
+ echo "apple=$({ xcodebuild -version; xcrun --sdk macosx --show-sdk-build-version; } | fingerprint)" >> "$GITHUB_OUTPUT"
+ fi
+
+ # Dependencies only: bundles and final binaries are rebuilt every time.
+ # The warm-up restores its exact key only, so each entry starts clean.
+ - name: Restore Rust build cache
+ id: rust-cache
+ uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
~/.cargo/registry/index
~/.cargo/registry/cache
~/.cargo/git/db
- desktop/target
- key: ${{ runner.os }}-${{ matrix.target }}-desktop-package-${{ hashFiles('desktop/Cargo.lock') }}
- restore-keys: ${{ runner.os }}-${{ matrix.target }}-desktop-package-
+ desktop/target/release/.fingerprint
+ desktop/target/release/build
+ desktop/target/release/deps
+ desktop/target/cua-driver-patched
+ key: ${{ runner.os }}-${{ matrix.target }}-desktop-package-${{ steps.toolchain.outputs.rustc }}-${{ hashFiles('desktop/Cargo.lock', 'desktop/cua-driver/sources.json') }}
+ restore-keys: ${{ env.DESKTOP_CACHE_WARMUP != 'true' && format('{0}-{1}-desktop-package-{2}-', runner.os, matrix.target, steps.toolchain.outputs.rustc) || '' }}
- name: Build Workbench
working-directory: ui
@@ -102,7 +143,7 @@ jobs:
- name: Prepare package version
shell: bash
env:
- AVIBE_DESKTOP_VERSION: ${{ inputs.version }}
+ AVIBE_DESKTOP_VERSION: ${{ env.DESKTOP_VERSION }}
RELEASE_TAG: ${{ inputs.release_tag }}
SOURCE_SHA: ${{ inputs.source_sha }}
run: |
@@ -128,8 +169,9 @@ jobs:
# build fails here on a missing or partial credential set; a manual build
# accepts the complete set or none of it. Only identity, keychain, and
# notary key locations leave this step, under names Tauri never reads.
+ # The cache warm-up alone skips it and stays ad-hoc.
- name: Import Apple signing identity
- if: runner.os == 'macOS'
+ if: runner.os == 'macOS' && env.DESKTOP_CACHE_WARMUP != 'true'
env:
RELEASE_TAG: ${{ inputs.release_tag }}
APPLE_CERTIFICATE: ${{ secrets.APPLE_CERTIFICATE }}
@@ -156,11 +198,33 @@ jobs:
python -m pip install --disable-pip-version-check
--only-binary=:all: "PyYAML==6.0.3"
+ # The pinned helper's inputs never change between releases. A restored
+ # helper is kept only when its provenance names exactly these inputs and
+ # it passes the checks a fresh build passes; otherwise it is rebuilt.
+ - name: Restore prepared Cua Driver
+ id: cua-driver-cache
+ if: runner.os == 'macOS'
+ uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
+ with:
+ path: |
+ desktop/src-tauri/binaries/cua-driver-${{ matrix.target }}
+ desktop/src-tauri/binaries/cua-driver-${{ matrix.target }}.provenance.json
+ key: cua-driver-${{ matrix.target }}-${{ steps.toolchain.outputs.apple }}-${{ hashFiles('desktop/cua-driver/**', 'desktop/scripts/prepare-cua-driver.py') }}
+
- name: Prepare pinned Cua Driver sidecar
if: runner.os == 'macOS'
run: >
python desktop/scripts/prepare-cua-driver.py
- --target "${{ matrix.target }}"
+ --target "${{ matrix.target }}" --reuse-verified
+
+ - name: Save prepared Cua Driver
+ if: runner.os == 'macOS' && !inputs.release_tag && steps.cua-driver-cache.outputs.cache-hit != 'true'
+ uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
+ with:
+ path: |
+ desktop/src-tauri/binaries/cua-driver-${{ matrix.target }}
+ desktop/src-tauri/binaries/cua-driver-${{ matrix.target }}.provenance.json
+ key: ${{ steps.cua-driver-cache.outputs.cache-primary-key }}
- name: Clean prior bundle output
shell: bash
@@ -183,6 +247,20 @@ jobs:
--features bundled-runtime
--config tauri.release.conf.json
+ - name: Save Rust build cache
+ if: ${{ !inputs.release_tag && steps.rust-cache.outputs.cache-hit != 'true' }}
+ uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
+ with:
+ path: |
+ ~/.cargo/registry/index
+ ~/.cargo/registry/cache
+ ~/.cargo/git/db
+ desktop/target/release/.fingerprint
+ desktop/target/release/build
+ desktop/target/release/deps
+ desktop/target/cua-driver-patched
+ key: ${{ steps.rust-cache.outputs.cache-primary-key }}
+
# The .app inside the DMG. A signed build signs the Cua Driver helper and
# then the app with the Team's Developer ID, pins both code identities,
# and notarizes and staples the app. The smoke test, the DMG, and the
@@ -298,7 +376,7 @@ jobs:
run: >
sh scripts/create-macos-dmg.sh
target/release/bundle/macos/Avibe.app
- "target/release/bundle/dmg/Avibe_${{ inputs.version }}_${{ matrix.target }}.dmg"
+ "target/release/bundle/dmg/Avibe_${{ env.DESKTOP_VERSION }}_${{ matrix.target }}.dmg"
# The DMG carries the stapled app; it is signed, notarized, and stapled
# itself, then the shipped shapes are checked the way Gatekeeper sees a
@@ -310,7 +388,7 @@ jobs:
shell: bash
run: |
set -eu
- dmg="target/release/bundle/dmg/Avibe_${{ inputs.version }}_${{ matrix.target }}.dmg"
+ dmg="target/release/bundle/dmg/Avibe_${{ env.DESKTOP_VERSION }}_${{ matrix.target }}.dmg"
python scripts/macos_signing.py sign-dmg "$dmg"
python scripts/macos_signing.py notarize "$dmg"
python scripts/macos_signing.py verify-release \
@@ -328,7 +406,7 @@ jobs:
- name: Record artifact hashes
shell: bash
env:
- AVIBE_DESKTOP_VERSION: ${{ inputs.version }}
+ AVIBE_DESKTOP_VERSION: ${{ env.DESKTOP_VERSION }}
RELEASE_TAG: ${{ inputs.release_tag }}
TARGET: ${{ matrix.target }}
RUNNER_OS: ${{ runner.os }}
@@ -371,8 +449,9 @@ jobs:
--target "$TARGET" --app desktop/target/release/bundle/macos/Avibe.app
- uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6
+ if: env.DESKTOP_CACHE_WARMUP != 'true'
with:
- name: avibe-desktop-${{ inputs.version }}-${{ matrix.target }}
+ name: avibe-desktop-${{ env.DESKTOP_VERSION }}-${{ matrix.target }}
path: desktop-package/
if-no-files-found: error
retention-days: 14
diff --git a/desktop/README.md b/desktop/README.md
index 33d99ebf5..2a9e35aac 100644
--- a/desktop/README.md
+++ b/desktop/README.md
@@ -551,7 +551,13 @@ Security → Microphone. `tests/notarization_preflight.rs` pins both facts.
sign. `.github/workflows/desktop-package.yml` builds architecture-specific,
self-contained DMG and NSIS artifacts, both manually and as the reusable TEST
build unit for `.github/workflows/release_ai.yml`. Its signing policy is
-described above. Native packaging and a real
+described above. Release builds restore the Rust dependency cache and the
+prepared Cua Driver but never save caches, because only reruns of the same tag
+could read them. The workflow's unsigned cache warm-up on `master` (daily, and on
+pushes that change a Rust cache input) is the writer they read from; it signs and
+uploads nothing. A restored Cua Driver is kept only when its provenance names the
+pinned inputs and it passes the checks a fresh build passes; otherwise it is
+rebuilt. Native packaging and a real
installation on each supported architecture remain separate acceptance gates
from unit/contract tests.
diff --git a/desktop/scripts/prepare-cua-driver.py b/desktop/scripts/prepare-cua-driver.py
index 114b61201..54fc9873d 100644
--- a/desktop/scripts/prepare-cua-driver.py
+++ b/desktop/scripts/prepare-cua-driver.py
@@ -229,11 +229,15 @@ def build_driver(manifest: dict, source_root: Path, target: str) -> Path:
built = target_dir / target / "release" / "cua-driver"
if not built.is_file():
raise ValueError("patched Cua Driver build did not produce the expected binary")
- info = run(["lipo", "-info", str(built)])
+ verify_architecture(built, target)
+ return built
+
+
+def verify_architecture(binary: Path, target: str) -> None:
+ info = run(["lipo", "-info", str(binary)])
arch = TARGET_ARCH[target]
if arch not in info or "Non-fat file" not in info:
raise ValueError(f"patched Cua Driver has the wrong architecture: {info}")
- return built
def verify_built_contract(binary: Path) -> None:
@@ -259,21 +263,84 @@ def sign_adhoc(binary: Path) -> None:
unsigned. The packaging workflow still re-signs the helper from the inside out.
"""
subprocess.run(["codesign", "--force", "--sign", "-", str(binary)], check=True)
+ verify_code_signature(binary)
+
+
+def verify_code_signature(binary: Path) -> None:
subprocess.run(["codesign", "--verify", "--strict", str(binary)], check=True)
+def provenance_record(
+ manifest: dict, target: str, *, patch_sha256: str, binary_sha256: str
+) -> dict:
+ driver = manifest["driver"]
+ return {
+ "schema_version": 2,
+ "version": driver["version"],
+ "tag": driver["tag"],
+ "source_commit": driver["source_commit"],
+ "target": target,
+ "arch": TARGET_ARCH[target],
+ "source_archive": driver["source"]["archive"],
+ "source_archive_sha256": driver["source"]["sha256"],
+ "patch_variant": driver["patch"]["variant"],
+ "patch_file": driver["patch"]["file"],
+ "patch_sha256": patch_sha256,
+ "tool_snapshot_sha256": digest(TOOL_SNAPSHOT),
+ "prepared_binary_sha256": binary_sha256,
+ "build_origin": "repository_patch_built",
+ }
+
+
+def reuse_verified(manifest: dict, target: str, output: Path) -> bool:
+ """Accept an already prepared helper only when it passes a fresh build's checks.
+
+ The helper and its provenance must describe exactly the pinned source, patch,
+ snapshot, and target, and the binary must hash to the recorded value. It then
+ passes the same architecture, code-signature, and tool-contract checks as a
+ helper built here. Anything else is rebuilt from source.
+ """
+ provenance_path = output.with_name(f"{output.name}.provenance.json")
+ if any(path.is_symlink() or not path.is_file() for path in (output, provenance_path)):
+ return False
+ try:
+ recorded = json.loads(provenance_path.read_text(encoding="utf-8"))
+ except (OSError, UnicodeError, json.JSONDecodeError):
+ return False
+ patch = ROOT / "cua-driver" / manifest["driver"]["patch"]["file"]
+ expected = provenance_record(
+ manifest,
+ target,
+ patch_sha256=digest(patch),
+ binary_sha256=digest(output),
+ )
+ if recorded != expected:
+ return False
+ try:
+ verify_architecture(output, target)
+ verify_code_signature(output)
+ verify_built_contract(output)
+ except (OSError, ValueError, subprocess.CalledProcessError) as exc:
+ print(f"::warning::Rebuilding the Cua Driver; the prepared helper failed verification: {exc}")
+ return False
+ print(f"Reusing the verified prepared Cua Driver {expected['prepared_binary_sha256']}")
+ return True
+
+
def prepare(
target: str,
*,
source_archive: Path | None = None,
output_dir: Path | None = None,
+ reuse: bool = False,
) -> Path:
manifest = load_manifest()
- arch = TARGET_ARCH[target]
driver = manifest["driver"]
destination = (output_dir or ROOT / "src-tauri" / "binaries").resolve()
destination.mkdir(parents=True, exist_ok=True)
output = destination / f"cua-driver-{target}"
+ if reuse and reuse_verified(manifest, target, output):
+ return output
with tempfile.TemporaryDirectory(prefix="avibe-cua-driver-") as temporary:
work = Path(temporary)
@@ -289,22 +356,12 @@ def prepare(
shutil.copyfile(prepared, temporary_output)
temporary_output.chmod(0o755)
os.replace(temporary_output, output)
- provenance = {
- "schema_version": 2,
- "version": driver["version"],
- "tag": driver["tag"],
- "source_commit": driver["source_commit"],
- "target": target,
- "arch": arch,
- "source_archive": driver["source"]["archive"],
- "source_archive_sha256": driver["source"]["sha256"],
- "patch_variant": driver["patch"]["variant"],
- "patch_file": driver["patch"]["file"],
- "patch_sha256": digest(patch),
- "tool_snapshot_sha256": digest(TOOL_SNAPSHOT),
- "prepared_binary_sha256": digest(output),
- "build_origin": "repository_patch_built",
- }
+ provenance = provenance_record(
+ manifest,
+ target,
+ patch_sha256=digest(patch),
+ binary_sha256=digest(output),
+ )
provenance_output = output.with_name(f"{output.name}.provenance.json")
temporary_provenance = destination / f".{provenance_output.name}.{os.getpid()}.tmp"
temporary_provenance.write_text(
@@ -321,6 +378,11 @@ def main() -> None:
parser.add_argument("--target", choices=TARGET_ARCH)
parser.add_argument("--source-archive", type=Path)
parser.add_argument("--output-dir", type=Path)
+ parser.add_argument(
+ "--reuse-verified",
+ action="store_true",
+ help="keep an existing helper whose provenance and checks match the pinned inputs",
+ )
args = parser.parse_args()
if args.check_manifest:
load_manifest()
@@ -332,6 +394,7 @@ def main() -> None:
args.target,
source_archive=args.source_archive,
output_dir=args.output_dir,
+ reuse=args.reuse_verified,
)
print(output)
diff --git a/tests/test_cua_driver_packaging.py b/tests/test_cua_driver_packaging.py
index cbdd5e149..9e4f796fe 100644
--- a/tests/test_cua_driver_packaging.py
+++ b/tests/test_cua_driver_packaging.py
@@ -161,6 +161,91 @@ def test_prepared_helper_is_a_signed_code_object(
)
+ "case",
+ ["match", "binary-changed", "other-target", "other-patch", "contract-fails", "missing-provenance"],
+)
+def test_restored_helper_is_reused_only_when_it_passes_a_fresh_builds_checks(
+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path, case: str
+) -> None:
+ """A cached helper ships only as the exact pinned build; anything else is rebuilt."""
+
+ target = "x86_64-apple-darwin"
+ manifest = _SCRIPT["load_manifest"]()
+ patch = Path("desktop/cua-driver") / manifest["driver"]["patch"]["file"]
+ binaries = tmp_path / "binaries"
+ binaries.mkdir()
+ restored = binaries / f"cua-driver-{target}"
+ restored.write_bytes(b"restored helper")
+ provenance = _SCRIPT["provenance_record"](
+ manifest,
+ "aarch64-apple-darwin" if case == "other-target" else target,
+ patch_sha256="0" * 64 if case == "other-patch" else _SCRIPT["digest"](patch),
+ binary_sha256=_SCRIPT["digest"](restored),
+ )
+ if case != "missing-provenance":
+ restored.with_name(f"{restored.name}.provenance.json").write_text(
+ json.dumps(provenance, indent=2, sort_keys=True) + "\n"
+ )
+ if case == "binary-changed":
+ restored.write_bytes(b"tampered helper")
+
+ built = tmp_path / "build" / "cua-driver"
+ built.parent.mkdir()
+ built.write_bytes(b"rebuilt helper")
+ checked: list[tuple[str, bytes]] = []
+ builds: list[str] = []
+
+ def check(name: str):
+ def run(binary: Path, *_args: object) -> None:
+ checked.append((name, binary.read_bytes()))
+ if case == "contract-fails" and name == "contract" and binary == restored:
+ raise ValueError("patched Cua Driver reports an unexpected version")
+
+ return run
+
+ script = _SCRIPT["prepare"].__globals__
+ monkeypatch.setitem(script, "verify_architecture", check("architecture"))
+ monkeypatch.setitem(script, "verify_code_signature", check("signature"))
+ monkeypatch.setitem(script, "verify_built_contract", check("contract"))
+ monkeypatch.setitem(script, "sign_adhoc", check("sign"))
+ monkeypatch.setitem(script, "extract_driver_source", lambda *_args: tmp_path / "source")
+ monkeypatch.setitem(script, "apply_driver_patch", lambda *_args: patch.resolve())
+
+ def build(*_args: object) -> Path:
+ builds.append(target)
+ return built
+
+ monkeypatch.setitem(script, "build_driver", build)
+
+ output = _SCRIPT["prepare"](
+ target,
+ source_archive=tmp_path / "source.tar.gz",
+ output_dir=binaries,
+ reuse=True,
+ )
+
+ assert output == restored.resolve()
+ if case == "match":
+ assert builds == []
+ assert output.read_bytes() == b"restored helper"
+ assert checked == [
+ ("architecture", b"restored helper"),
+ ("signature", b"restored helper"),
+ ("contract", b"restored helper"),
+ ]
+ else:
+ assert builds == [target]
+ assert output.read_bytes() == b"rebuilt helper"
+ assert ("contract", b"rebuilt helper") in checked
+ # The release verifier accepts whichever helper was kept.
+ desktop_release.driver_provenance(
+ target,
+ output,
+ output.with_name(f"{output.name}.provenance.json"),
+ )
+
+
def test_source_extraction_is_scoped_to_the_driver_subtree(tmp_path: Path) -> None:
archive = tmp_path / "source.tar.gz"
root = "cua-fixture"
diff --git a/tests/test_desktop_release.py b/tests/test_desktop_release.py
index 4a7f91c40..152492fd9 100644
--- a/tests/test_desktop_release.py
+++ b/tests/test_desktop_release.py
@@ -513,8 +513,10 @@ def test_manual_record_names_the_layers_it_produced(tmp_path, profile, layers):
def test_workflow_signs_every_macos_layer_before_recording():
package = workflow("desktop-package.yml")
triggers = package.get("on", package.get(True))
- assert set(triggers) == {"workflow_dispatch", "workflow_call"}
+ assert set(triggers) == {"workflow_dispatch", "workflow_call", "push", "schedule"}
assert "secrets" not in triggers["workflow_call"]
+ # Only the default branch warms caches; tag pushes reach this build only through release_ai.
+ assert triggers["push"]["branches"] == ["master"] and "tags" not in triggers["push"]
jobs = workflow("release_ai.yml")["jobs"]
caller = jobs["desktop-packages"]
assert caller["uses"] == "./.github/workflows/desktop-package.yml"
@@ -540,9 +542,18 @@ def test_workflow_signs_every_macos_layer_before_recording():
"Sign and verify final updater artifacts",
]
assert [steps.index(step(name)) for name in order] == sorted(steps.index(step(name)) for name in order)
- # Every macOS build imports: a tag build fails there without the complete set.
+ # Every macOS build but the unsigned cache warm-up imports: a tag build fails
+ # there without the complete set, and a build carrying a tag is never a warm-up.
+ warmup = build["env"]["DESKTOP_CACHE_WARMUP"]
+ assert warmup.startswith("${{ !inputs.release_tag && (")
identity = step("Import Apple signing identity")
- assert identity["if"] == "runner.os == 'macOS'"
+ assert identity["if"] == "runner.os == 'macOS' && env.DESKTOP_CACHE_WARMUP != 'true'"
+ # Only reruns of the same tag could read a cache a release build saved.
+ caches = [item for item in steps if str(item.get("uses", "")).startswith("actions/cache")]
+ assert {item["uses"].split("@")[0] for item in caches} == {"actions/cache/restore", "actions/cache/save"}
+ for item in caches:
+ if item["uses"].startswith("actions/cache/save@"):
+ assert "!inputs.release_tag" in item["if"], item["name"]
assert identity["env"]["RELEASE_TAG"] == "${{ inputs.release_tag }}"
assert "import-identity" in identity["run"]
prepared_driver = step("Verify prepared Cua Driver provenance")
@@ -563,6 +574,7 @@ def test_workflow_signs_every_macos_layer_before_recording():
assert f"macos_signing.py {command}" in dmg["run"]
assert "NotSigned" in step("Verify unsigned Windows installer")["run"]
assert steps[-2]["uses"] == "actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f"
+ assert steps[-2]["if"] == "env.DESKTOP_CACHE_WARMUP != 'true'"
assert steps[-1]["name"] == "Remove Apple signing material"
assert steps[-1]["if"] == "always() && runner.os == 'macOS'"
workflow_text = (ROOT / ".github/workflows/desktop-package.yml").read_text(encoding="utf-8")