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.

feat(upgrade): converge Memory from a preview release's own wheels (#1806)

rkrkrkk4abec39ace8e
diff --git a/docs/plans/preview-install-convergence.md b/docs/plans/preview-install-convergence.md
new file mode 100644
index 000000000..5fa3cdbd9
--- /dev/null
+++ b/docs/plans/preview-install-convergence.md
@@ -0,0 +1,164 @@
+# Preview Install Convergence
+
+> Status: implemented (scenario MEMORY-INDEP-027)
+>
+> Scope: a `gh-v*` preview install or preview-to-preview upgrade is one
+> copyable `uv tool install` command for the core wheel; the Memory companion
+> converges automatically afterward. No CLI surface changes. The official
+> `v*` / PyPI publication and upgrade contract is untouched.
+>
+> Replaces the earlier `memory-preview-bundle` and `preview-upgrade` drafts.
+> Deliberately dropped from those drafts: bundle manifest asset, digest
+> pipeline, GitHub API discovery, new CLI flags, and Web UI channel control.
+
+## Problem
+
+A `gh-v*` release attaches the `avibe-os` and `avibe-memory` wheels as GitHub
+Release assets and publishes nothing to PyPI. Installing a preview therefore
+means assembling `uv tool install <core-url> --with <memory-url> --force` from
+two long asset URLs, and the operator must remember the Memory wheel even when
+Memory is already installed. Installing only the core is worse than
+inconvenient: the post-ready Memory package repair treats the rc version as
+published, pins `avibe-memory==<rc>` against PyPI where it does not exist, and
+burns its bounded three-attempt budget on installs that can never succeed.
+
+## Design
+
+The single user action, for first install and for every preview-to-preview
+upgrade, is the one command printed in the `gh-v*` release notes:
+
+```bash
+uv tool install https://github.com/avibe-bot/avibe/releases/download/<tag>/avibe_os-<version>-py3-none-any.whl --force
+```
+
+`uv tool install --force` rebuilds the tool environment from that single spec,
+so the previously installed `avibe-memory` is dropped — intentionally. After
+the service restarts and reaches readiness, the **existing** reconciler
+(`reconcile_memory_package_on_startup` → `_prepare_memory_package_job`)
+observes that Memory is required and the companion is missing or
+version-mismatched, and repairs it. The only change is where the repair points
+its package specs when the running version is a preview.
+
+### Origin-aware repair specs
+
+**The version string cannot decide this.** `publish.yml` triggers on `v*` and
+accepts official `vX.Y.ZrcN` tags, publishing both packages to PyPI. Such a
+build carries a version indistinguishable from a `gh-v*` build of the same
+number, so treating every clean prerelease as GitHub-only would point the
+official one at a `gh-vX.Y.ZrcN` tag that was never created — reproducing the
+exact 404-and-burn-the-budget failure this plan exists to fix, one version
+class over.
+
+The installer already recorded the answer. PEP 610 requires a
+`direct_url.json` in the installed `.dist-info` whenever a distribution came
+from somewhere other than an index, so:
+
+- **no record** → resolved by name from an index → keep today's exact PyPI
+ pins. This covers every PyPI install, official prereleases included.
+- **record naming a release asset of this repository** → repair from that same
+ release: the core spec is the recorded URL itself, and the memory spec is its
+ sibling in the same release directory.
+- **any other record** (a local file, another repository, a directory or VCS
+ install) → keep index pins, i.e. today's behavior.
+
+No GitHub API call is made, and no tag is derived from a convention: the pair
+comes from the release the running copy demonstrably came from. The recorded
+URL must name the exact running version, so a stale or mismatched record cannot
+drive the repair to a different pair. Dev and local versions keep today's
+refusal (`memory_package_unpublished_build`).
+
+The released artifacts' reciprocal exact pins (`avibe-os==X ⇄ avibe-memory==X`
+in published METADATA) remain the pairing integrity gate — uv fails resolution
+if the pair does not match.
+
+### Plan builder extension
+
+`build_upgrade_plan` gains two optional parameters honored only in
+exact-version mode: `core_spec` and `memory_spec`. When set, they replace the
+`avibe-os==<version>` / `avibe-memory==<version>` pins in the install and
+preflight commands. Defaults are `None`, and every existing call site passes
+neither, so all current plans — stable CLI upgrade, stable Web upgrade, stable
+repair — are byte-identical to today. Exact-version semantics (install into
+the current tool dir, `--force`, no `--upgrade`, service-scope restart) are
+unchanged.
+
+### Surfaces that benefit without changes
+
+- the automatic startup reconciler;
+- the manual "install memory-package" job on the Web UI Dependencies page
+ (same `_prepare_memory_package_job` implementation);
+- the bounded three-attempt budget, shared upgrade lock, integrity
+ verification, and `memory-package-repair` service restart, all reused as-is.
+
+## Behavior
+
+| Situation | Result |
+| --- | --- |
+| preview core installed, Memory enabled or previously installed | repair installs the exact-version wheel pair from the GitHub release, then service restart |
+| preview core installed, Memory disabled and absent | reconciler skips; zero download, zero install |
+| preview release or asset missing (404), network failure | structured `memory_package_install_failed`; attempt budget consumed; stays repairable from the Dependencies page |
+| dev / local / source build | refused before any network access, as today |
+| installed from an index (any version, official `vX.Y.ZrcN` included) | exact PyPI pins, byte-identical to today |
+| preview → newer preview | same single `uv tool install` command from the new tag's notes |
+| preview → stable | ordinary `vibe upgrade` once PyPI has a newer official version; the stable path carries Memory automatically |
+
+## Official upgrade path — invariants
+
+This change must not alter any official `v*` behavior:
+
+1. `vibe upgrade` (CLI) and Web `do_upgrade` never pass the new parameters;
+ their plans are unchanged for every input.
+2. The repair branch is selected by publication channel, not version shape: an
+ install with no PEP 610 origin record came from an index and keeps today's
+ exact PyPI pins. This is what makes an official `vX.Y.ZrcN` PyPI prerelease
+ safe, and it is the reason the selector is not `is_prerelease`.
+3. `publish.yml`, PyPI ordering (Memory before core), and release asset
+ contracts are untouched.
+4. Regression tests assert the stable plan shapes byte-for-byte (extending the
+ existing exact-plan contract test in `tests/test_upgrade_flow.py`).
+
+## Failure and security bounds
+
+- Fixed repository, HTTPS only, derived URLs; no redirect-following logic of
+ our own — uv performs the download inside the existing install step.
+- All failures surface through the existing structured repair results; no new
+ failure lifecycle, no rollback, no reservation, no quarantine.
+- Error output follows the existing truncation and never adds credentials or
+ URLs beyond what the install command already contains.
+
+## Testing
+
+- URL/tag derivation unit tests: rc/a/b versions, normalization, dev/local
+ refusal, stable versions bypass;
+- plan-shape tests: `core_spec`/`memory_spec` rendering in uv and pip exact
+ plans and their preflights; omitted parameters produce today's commands
+ byte-for-byte;
+- repair tests: prerelease running version produces derived URL specs;
+ attempt budget, lock, and restart behavior unchanged; 404-style install
+ failure yields the existing structured result;
+- reconciler tests: required+missing converges, disabled skips, mismatch at a
+ preview version converges to the running version's pair.
+
+## Delivery
+
+One PR: derivation helper + `core_spec`/`memory_spec` + preview branch in
+`_prepare_memory_package_job` + tests. No publish workflow asset changes.
+
+### As shipped
+
+- `release_asset_specs` in `vibe/upgrade.py` reads the PEP 610 origin and
+ returns the pair, and `build_upgrade_plan` renders `memory_spec` as the PEP
+ 508 direct reference `avibe-memory @ <url>` so every installer still reads it
+ as a named distribution rather than an anonymous artifact.
+- The first draft keyed this on `is_prerelease`. Codex review of PR #1806
+ caught that `publish.yml` publishes official `vX.Y.ZrcN` tags to PyPI, so the
+ basis moved from version shape to recorded install origin — which is the
+ thing actually being asked about, and cannot be wrong about a channel.
+- Sources without an exact `version` raise `ValueError` instead of being
+ ignored. A forward upgrade resolves the newest release and has no known pair
+ to name, so a silently dropped spec would read as applied — this is a
+ decision beyond the original draft, and the invariant-1 tests assert it.
+- The optional `gh-v*` release-notes template line is **not** in this PR. The
+ notes are produced by the shared `release_ai.yml` generator, which also
+ writes official `v*` notes, so changing it would put invariant 3 at risk for
+ a text-only convenience. It stays a separate workflow-side change.
diff --git a/tests/scenarios/memory_independence/catalog.yaml b/tests/scenarios/memory_independence/catalog.yaml
index 1f5b201f0..1c7470ff7 100644
--- a/tests/scenarios/memory_independence/catalog.yaml
+++ b/tests/scenarios/memory_independence/catalog.yaml
@@ -158,3 +158,9 @@ scenarios:
kind: compatibility
layer: scenario
test: tests/e2e/test_upgrade_command.py::test_memory_indep_026_upgrade_command_bridges_released_3_0_13_generation
+ - id: MEMORY-INDEP-027
+ name: A core-only preview install converges to the Memory companion published by its own release
+ status: covered
+ kind: compatibility
+ layer: scenario
+ test: tests/test_local_deps.py::test_memory_indep_027_preview_repair_installs_the_release_that_published_it
diff --git a/tests/scenarios/memory_independence/test_memory_independence_catalog.py b/tests/scenarios/memory_independence/test_memory_independence_catalog.py
index a1024936d..fca842f1d 100644
--- a/tests/scenarios/memory_independence/test_memory_independence_catalog.py
+++ b/tests/scenarios/memory_independence/test_memory_independence_catalog.py
@@ -44,6 +44,22 @@ def test_memory_indep_021_catalog_points_to_executable_import_fence() -> None:
assert "test_memory_indep_021_status_import_fence" in test_source
+def test_memory_indep_027_catalog_points_to_preview_release_convergence() -> None:
+ catalog = yaml.safe_load(
+ (ROOT / "tests/scenarios/memory_independence/catalog.yaml").read_text()
+ )
+ scenario = next(
+ item for item in catalog["scenarios"] if item["id"] == "MEMORY-INDEP-027"
+ )
+
+ assert scenario["status"] == "covered"
+ assert scenario["test"].endswith(
+ "test_memory_indep_027_preview_repair_installs_the_release_that_published_it"
+ )
+ test_source = (ROOT / "tests/test_local_deps.py").read_text()
+ assert "test_memory_indep_027_preview_repair_installs_the_release_that_published_it" in test_source
+
+
def test_memory_indep_026_catalog_points_to_released_first_hop_upgrade() -> None:
catalog = yaml.safe_load(
(ROOT / "tests/scenarios/memory_independence/catalog.yaml").read_text()
diff --git a/tests/test_local_deps.py b/tests/test_local_deps.py
index 33f86497b..9a8e37e60 100644
--- a/tests/test_local_deps.py
+++ b/tests/test_local_deps.py
@@ -2400,7 +2400,36 @@ def test_memory_package_server_admission_rejects_nonrepairable_rows(
}
-def test_memory_package_dependency_job_uses_existing_pinned_plan(monkeypatch) -> None:
+#: One running version, published two ways. `publish.yml` accepts official
+#: `vX.Y.ZrcN` tags and publishes them to PyPI, while a `gh-v*` build of the
+#: identical version is on no index at all — so the version string cannot pick
+#: the repair sources and only the recorded install origin can. Both rows use
+#: the same version deliberately.
+REPAIR_VERSION = "3.0.14rc8"
+RELEASE_CORE_URL = f"https://github.com/avibe-bot/avibe/releases/download/gh-v{REPAIR_VERSION}/avibe_os-{REPAIR_VERSION}-py3-none-any.whl"
+RELEASE_MEMORY_URL = (
+ f"https://github.com/avibe-bot/avibe/releases/download/gh-v{REPAIR_VERSION}/"
+ f"avibe_memory-{REPAIR_VERSION}-py3-none-any.whl"
+)
+INSTALL_ORIGIN_SOURCES = {
+ "index install": (None, None, None),
+ "release asset install": (RELEASE_CORE_URL, RELEASE_CORE_URL, RELEASE_MEMORY_URL),
+}
+
+
+ ("origin", "core_spec", "memory_spec"),
+ list(INSTALL_ORIGIN_SOURCES.values()),
+ ids=list(INSTALL_ORIGIN_SOURCES),
+)
+def test_memory_package_dependency_job_targets_the_running_version_wherever_it_came_from(
+ monkeypatch,
+ origin: str | None,
+ core_spec: str | None,
+ memory_spec: str | None,
+) -> None:
+ current_version = REPAIR_VERSION
+ monkeypatch.setattr("vibe.upgrade._recorded_install_origin", lambda _package: origin)
plan = SimpleNamespace(
command=["repair"],
activation=None,
@@ -2410,7 +2439,7 @@ def test_memory_package_dependency_job_uses_existing_pinned_plan(monkeypatch) ->
calls: dict[str, object] = {}
lock_events: list[str] = []
monkeypatch.setattr(api, "_memory_package_repair_rejection", lambda **_kwargs: None)
- monkeypatch.setattr(api, "_published_running_version", lambda: "3.0.14")
+ monkeypatch.setattr(api, "_published_running_version", lambda: current_version)
monkeypatch.setattr(api, "get_running_vibe_path", lambda: "/bin/vibe")
monkeypatch.setattr(api, "get_safe_cwd", lambda: "/safe")
monkeypatch.setattr(api, "restart_is_pending", lambda: False)
@@ -2456,11 +2485,13 @@ def test_memory_package_dependency_job_uses_existing_pinned_plan(monkeypatch) ->
assert result["ok"] is True
assert result["message"] == "memory_package_ready"
assert calls["plan"] == {
- "version": "3.0.14",
+ "version": current_version,
"package_name": api.PACKAGE_NAME,
"memory_package": True,
- "memory_version": "3.0.14",
+ "memory_version": current_version,
"vibe_path": "/bin/vibe",
+ "core_spec": core_spec,
+ "memory_spec": memory_spec,
}
assert calls["execute"] == (
plan,
@@ -2482,12 +2513,70 @@ def test_memory_package_dependency_job_uses_existing_pinned_plan(monkeypatch) ->
assert result["restart"] == {"job_id": "restart"}
assert lock_events == ["entered", "build", "execute", "restart", "exited"]
record_result.assert_called_once_with(
- "3.0.14",
+ current_version,
result="restart_scheduled",
reason=None,
)
+def test_memory_indep_027_preview_repair_installs_the_release_that_published_it(
+ monkeypatch,
+) -> None:
+ """MEMORY-INDEP-027: a core-only preview install converges from its own release.
+
+ A `gh-v*` release publishes the wheel pair as release assets and nothing to
+ an index, so this builds the real plan rather than a recorded call: what
+ matters is the command an installer would actually run.
+ """
+
+ current_version = REPAIR_VERSION
+ calls: dict[str, object] = {}
+ monkeypatch.setattr("vibe.upgrade._recorded_install_origin", lambda _package: RELEASE_CORE_URL)
+ monkeypatch.setattr(api, "_memory_package_repair_rejection", lambda **_kwargs: None)
+ monkeypatch.setattr(api, "_published_running_version", lambda: current_version)
+ monkeypatch.setattr(api, "get_running_vibe_path", lambda: "/bin/vibe")
+ monkeypatch.setattr(api, "get_safe_cwd", lambda: "/safe")
+ monkeypatch.setattr(api, "restart_is_pending", lambda: False)
+ monkeypatch.setattr(api, "_memory_package_restart_retry_required", lambda _version: False)
+ monkeypatch.setattr(api, "_record_memory_package_repair_result", Mock())
+ monkeypatch.setattr(api, "atomic_upgrade_lock", nullcontext)
+ monkeypatch.setattr(api, "schedule_restart", lambda **_kwargs: {"job_id": "restart"})
+ monkeypatch.setattr(
+ api,
+ "verify_python_environment",
+ lambda _python: SimpleNamespace(ok=True, detail="ok"),
+ )
+ # Resolve to the pip installer so the plan is built from this interpreter
+ # without consulting any uv tool environment on the host.
+ monkeypatch.setattr("vibe.upgrade.find_uv_binary", lambda **_kwargs: None)
+
+ def execute_plan(plan, **_kwargs):
+ calls["plan"] = plan
+ return subprocess.CompletedProcess(plan.command, 0, stdout="installed", stderr="")
+
+ monkeypatch.setattr(api, "execute_upgrade_plan", execute_plan)
+
+ result = api._prepare_memory_package_job(automatic=True)
+
+ assert result["ok"] is True
+ assert result["restarting"] is True
+ plan = calls["plan"]
+ release = f"https://github.com/avibe-bot/avibe/releases/download/gh-v{current_version}/"
+ commands = [
+ command
+ for command in (plan.command, plan.preflight_command, plan.preflight_fallback_command)
+ if command
+ ]
+ assert len(commands) >= 2, "the repair resolves the pair before it installs it"
+ for command in commands:
+ assert f"{release}avibe_os-{current_version}-py3-none-any.whl" in command
+ assert f"avibe-memory @ {release}avibe_memory-{current_version}-py3-none-any.whl" in command
+ # An index pin here is the bug: PyPI never served this version, so the
+ # install fails and spends one of the bounded repair attempts.
+ assert f"{api.PACKAGE_NAME}=={current_version}" not in command
+ assert f"{api.MEMORY_PACKAGE_NAME}=={current_version}" not in command
+
+
def test_memory_package_dependency_job_fails_closed_when_restart_cannot_be_scheduled(
monkeypatch,
tmp_path,
diff --git a/tests/test_upgrade_flow.py b/tests/test_upgrade_flow.py
index 3c8a67ca5..8a9bcb7da 100644
--- a/tests/test_upgrade_flow.py
+++ b/tests/test_upgrade_flow.py
@@ -2,6 +2,7 @@ from __future__ import annotations
import ast
from contextlib import nullcontext
+import json
import os
import stat
import subprocess
@@ -16,10 +17,12 @@ import pytest
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from vibe import api, cli, runtime
+from vibe import upgrade as vibe_upgrade
from vibe.runtime import ServiceLauncher
from vibe.upgrade import (
AtomicActivation,
MemoryRequirementUnreadableError,
+ PIP_DOWNLOAD_DEST_PLACEHOLDER,
UpgradePlan,
build_upgrade_plan,
configured_memory_enabled,
@@ -35,6 +38,7 @@ from vibe.upgrade import (
get_running_vibe_path,
get_safe_cwd,
pinned_package_spec,
+ release_asset_specs,
execute_upgrade_plan,
restart_is_pending,
)
@@ -951,6 +955,266 @@ def test_an_exact_plan_never_asks_for_an_upgrade_and_always_forces_the_install(m
assert FORCES_THE_INSTALL[plan.method] in plan.command
+def test_an_exact_memory_plan_names_both_index_pins_when_no_source_is_given(monkeypatch):
+ # The repair reaches an index by default. A caller that names no install
+ # source gets exactly the pins it got before install sources existed.
+ monkeypatch.setattr("vibe.upgrade.os.path.exists", lambda path: True)
+ monkeypatch.setattr("vibe.upgrade.os.access", lambda path, mode: True)
+
+ uv_plan = build_upgrade_plan(
+ python_executable="/tmp/.local/share/uv/tools/avibe-os/bin/python",
+ uv_path="/usr/local/bin/uv",
+ vibe_path="/custom/bin/vibe",
+ base_env={"PATH": "/usr/bin"},
+ version="3.0.10",
+ package_name="avibe-os",
+ memory_package=True,
+ memory_version="3.0.10",
+ )
+ assert uv_plan.command == [
+ "/usr/local/bin/uv",
+ "tool",
+ "install",
+ "avibe-os==3.0.10",
+ "--with",
+ "avibe-memory==3.0.10",
+ "--force",
+ ]
+ assert uv_plan.preflight_command == [
+ "/usr/local/bin/uv",
+ "pip",
+ "install",
+ "--dry-run",
+ "--python",
+ "/tmp/.local/share/uv/tools/avibe-os/bin/python",
+ "avibe-os==3.0.10",
+ "avibe-memory==3.0.10",
+ ]
+
+ pip_plan = build_upgrade_plan(
+ python_executable="/usr/bin/python3",
+ uv_path=None,
+ base_env={"PATH": "/usr/bin"},
+ version="3.0.10",
+ package_name="avibe-os",
+ memory_package=True,
+ memory_version="3.0.10",
+ )
+ assert pip_plan.command == [
+ "/usr/bin/python3",
+ "-m",
+ "pip",
+ "install",
+ "--force-reinstall",
+ "avibe-os==3.0.10",
+ "avibe-memory==3.0.10",
+ ]
+ assert pip_plan.preflight_command == [
+ "/usr/bin/python3",
+ "-m",
+ "pip",
+ "download",
+ "--dest",
+ PIP_DOWNLOAD_DEST_PLACEHOLDER,
+ "--no-deps",
+ "avibe-os==3.0.10",
+ "avibe-memory==3.0.10",
+ ]
+
+
+PREVIEW_VERSION = "3.0.16rc1"
+PREVIEW_CORE_URL = (
+ "https://github.com/avibe-bot/avibe/releases/download/gh-v3.0.16rc1/avibe_os-3.0.16rc1-py3-none-any.whl"
+)
+PREVIEW_MEMORY_URL = (
+ "https://github.com/avibe-bot/avibe/releases/download/gh-v3.0.16rc1/avibe_memory-3.0.16rc1-py3-none-any.whl"
+)
+
+
+def _installed_from(monkeypatch, origin: str | None) -> None:
+ """Record where the installer says this copy of core came from."""
+
+ monkeypatch.setattr("vibe.upgrade._recorded_install_origin", lambda _package: origin)
+
+
+def test_the_companion_comes_from_the_release_core_was_installed_from(monkeypatch):
+ _installed_from(monkeypatch, PREVIEW_CORE_URL)
+
+ assert release_asset_specs(PREVIEW_VERSION) == (PREVIEW_CORE_URL, PREVIEW_MEMORY_URL)
+
+
+def test_an_official_prerelease_on_pypi_keeps_its_index_pins(monkeypatch):
+ # `publish.yml` accepts official `vX.Y.ZrcN` tags and publishes them to
+ # PyPI. Such a build carries a version indistinguishable from a `gh-v*`
+ # one, so only its origin can say that `gh-v3.0.16rc1` was never created.
+ _installed_from(monkeypatch, None)
+
+ assert release_asset_specs(PREVIEW_VERSION) is None
+
+
+ "spelling",
+ ["3.0.16rc1", "3.0.16RC1", "3.0.16-rc-1", "v3.0.16rc1", "3.0.16.rc.1"],
+)
+def test_one_normalization_matches_the_origin_and_names_the_companion(monkeypatch, spelling):
+ # The recorded URL spells the version the way a wheel filename does, so the
+ # match against the running version must normalize both the same way.
+ _installed_from(monkeypatch, PREVIEW_CORE_URL)
+
+ assert release_asset_specs(spelling) == (PREVIEW_CORE_URL, PREVIEW_MEMORY_URL)
+
+
+ ("origin", "version"),
+ [
+ # An index install records no origin at all: it is repairable by name.
+ (None, PREVIEW_VERSION),
+ ("", PREVIEW_VERSION),
+ # Somewhere that is not a release asset of this repository.
+ ("https://example.com/gh-v3.0.16rc1/avibe_os-3.0.16rc1-py3-none-any.whl", PREVIEW_VERSION),
+ ("https://github.com/other/repo/releases/download/gh-v3.0.16rc1/avibe_os-3.0.16rc1-py3-none-any.whl", PREVIEW_VERSION),
+ ("file:///tmp/avibe_os-3.0.16rc1-py3-none-any.whl", PREVIEW_VERSION),
+ ("https://github.com/avibe-bot/avibe/releases/download/avibe_os-3.0.16rc1-py3-none-any.whl", PREVIEW_VERSION),
+ (
+ "https://github.com/avibe-bot/avibe/releases/download/gh-v3.0.16rc1/nested/avibe_os-3.0.16rc1-py3-none-any.whl",
+ PREVIEW_VERSION,
+ ),
+ (
+ "https://github.com/avibe-bot/avibe/releases/download/../gh-v3.0.16rc1/avibe_os-3.0.16rc1-py3-none-any.whl",
+ PREVIEW_VERSION,
+ ),
+ # The recorded asset names a different distribution or version than the
+ # one being repaired, so it cannot say where this pair lives.
+ (PREVIEW_MEMORY_URL, PREVIEW_VERSION),
+ (PREVIEW_CORE_URL, "3.0.16rc2"),
+ (PREVIEW_CORE_URL, "3.0.16"),
+ (PREVIEW_CORE_URL, ""),
+ (PREVIEW_CORE_URL, "not-a-version"),
+ ],
+)
+def test_an_origin_that_cannot_name_this_pair_keeps_index_pins(monkeypatch, origin, version):
+ _installed_from(monkeypatch, origin)
+
+ assert release_asset_specs(version) is None
+
+
+def test_a_missing_or_unreadable_origin_record_reads_as_an_index_install(monkeypatch):
+ class _Distribution:
+ def __init__(self, recorded):
+ self._recorded = recorded
+
+ def read_text(self, _name):
+ return self._recorded
+
+ recorded_values = [None, "", "not json", "[]", "{}", '{"url": 7}']
+ for recorded in recorded_values:
+ monkeypatch.setattr(
+ "importlib.metadata.distribution",
+ lambda _name, recorded=recorded: _Distribution(recorded),
+ )
+ assert vibe_upgrade._recorded_install_origin("avibe-os") is None, recorded
+
+ def _raise(_name):
+ raise RuntimeError("metadata is unreadable")
+
+ monkeypatch.setattr("importlib.metadata.distribution", _raise)
+ assert vibe_upgrade._recorded_install_origin("avibe-os") is None
+
+
+def test_a_recorded_origin_is_read_from_the_installers_own_pep_610_record(monkeypatch):
+ class _Distribution:
+ def read_text(self, name):
+ assert name == "direct_url.json"
+ return json.dumps({"url": PREVIEW_CORE_URL, "archive_info": {}})
+
+ monkeypatch.setattr("importlib.metadata.distribution", lambda _name: _Distribution())
+
+ assert vibe_upgrade._recorded_install_origin("avibe-os") == PREVIEW_CORE_URL
+
+
+def test_an_exact_plan_installs_the_named_sources_instead_of_index_pins(monkeypatch):
+ monkeypatch.setattr("vibe.upgrade.os.path.exists", lambda path: True)
+ monkeypatch.setattr("vibe.upgrade.os.access", lambda path, mode: True)
+
+ shared = {
+ "base_env": {"PATH": "/usr/bin"},
+ "version": PREVIEW_VERSION,
+ "package_name": "avibe-os",
+ "memory_package": True,
+ "memory_version": PREVIEW_VERSION,
+ "core_spec": PREVIEW_CORE_URL,
+ "memory_spec": PREVIEW_MEMORY_URL,
+ }
+ uv_plan = build_upgrade_plan(
+ python_executable="/tmp/.local/share/uv/tools/avibe-os/bin/python",
+ uv_path="/usr/local/bin/uv",
+ vibe_path="/custom/bin/vibe",
+ **shared,
+ )
+ assert uv_plan.command == [
+ "/usr/local/bin/uv",
+ "tool",
+ "install",
+ PREVIEW_CORE_URL,
+ "--with",
+ f"avibe-memory @ {PREVIEW_MEMORY_URL}",
+ "--force",
+ ]
+ pip_plan = build_upgrade_plan(python_executable="/usr/bin/python3", uv_path=None, **shared)
+ assert pip_plan.command == [
+ "/usr/bin/python3",
+ "-m",
+ "pip",
+ "install",
+ "--force-reinstall",
+ PREVIEW_CORE_URL,
+ f"avibe-memory @ {PREVIEW_MEMORY_URL}",
+ ]
+
+ # Every command an installer runs has to reach the release. A pin left in
+ # any one of them resolves against an index that never served this version,
+ # which is the failure the sources exist to remove.
+ for plan in (uv_plan, pip_plan):
+ commands = [
+ command
+ for command in (plan.command, plan.preflight_command, plan.preflight_fallback_command)
+ if command
+ ]
+ assert len(commands) >= 2, "an exact Memory plan resolves before it installs"
+ for command in commands:
+ assert PREVIEW_CORE_URL in command
+ assert f"avibe-memory @ {PREVIEW_MEMORY_URL}" in command
+ assert f"avibe-os=={PREVIEW_VERSION}" not in command
+ assert f"avibe-memory=={PREVIEW_VERSION}" not in command
+ assert "--upgrade" not in plan.command
+ assert FORCES_THE_INSTALL[plan.method] in plan.command
+
+
+def test_a_forward_upgrade_keeps_index_pins_and_admits_no_install_source(monkeypatch):
+ # A forward upgrade resolves whichever release is newest, so there is no
+ # known release to name. Ignoring a source here would report an install
+ # from the release that never happened.
+ monkeypatch.setattr("vibe.upgrade.find_uv_binary", lambda **kwargs: None)
+ forward = {
+ "python_executable": "/usr/bin/python3",
+ "base_env": {"PATH": "/usr/bin"},
+ "memory_enabled": True,
+ "package_spec": "avibe-os==3.1.0",
+ }
+
+ plan = build_upgrade_plan(**forward)
+ assert "avibe-os[memory]==3.1.0" in plan.command
+ assert "avibe-memory==3.1.0" in plan.command
+
+ for sources in (
+ {"core_spec": PREVIEW_CORE_URL},
+ {"memory_spec": PREVIEW_MEMORY_URL},
+ {"core_spec": PREVIEW_CORE_URL, "memory_spec": PREVIEW_MEMORY_URL},
+ ):
+ with pytest.raises(ValueError):
+ build_upgrade_plan(**forward, **sources)
+
+
def _metadata_records(monkeypatch, distribution: str, version: str) -> None:
"""One distribution provides `vibe`, and its metadata records `version`."""
diff --git a/vibe/api.py b/vibe/api.py
index f8d3317bb..744bbf8fa 100644
--- a/vibe/api.py
+++ b/vibe/api.py
@@ -81,6 +81,7 @@ from vibe.upgrade import (
get_running_vibe_path,
get_safe_cwd,
launcher_is_current_process,
+ release_asset_specs,
restart_is_pending,
should_skip_show_runtime_prepare,
UPGRADE_INSTALL_TIMEOUT_SECONDS,
@@ -9511,12 +9512,21 @@ def _prepare_memory_package_job(*, automatic: bool = False) -> dict:
if restart_only:
result = {"ok": True}
else:
+ # A GitHub-only release publishes its pair as release assets and
+ # nothing to an index, so pinning it by name would resolve
+ # against a PyPI that never served this version and spend an
+ # attempt on an install that cannot succeed. This asks where
+ # core actually came from; an index install answers `None` and
+ # keeps its pins.
+ asset_specs = release_asset_specs(current_version)
plan = build_upgrade_plan(
version=current_version,
package_name=PACKAGE_NAME,
memory_package=True,
memory_version=current_version,
vibe_path=current_vibe_path,
+ core_spec=asset_specs[0] if asset_specs else None,
+ memory_spec=asset_specs[1] if asset_specs else None,
)
if plan.preflight_error:
return {
diff --git a/vibe/upgrade.py b/vibe/upgrade.py
index 2c2e220de..2b52d99e9 100644
--- a/vibe/upgrade.py
+++ b/vibe/upgrade.py
@@ -25,6 +25,7 @@ from packaging.requirements import InvalidRequirement, Requirement
from packaging.utils import (
InvalidSdistFilename,
InvalidWheelFilename,
+ canonicalize_name,
parse_sdist_filename,
parse_wheel_filename,
)
@@ -54,6 +55,13 @@ LEGACY_PACKAGE_NAME = LEGACY_CORE_PACKAGE_NAME
MEMORY_PACKAGE_NAME = SHAPE_MEMORY_PACKAGE_NAME
MEMORY_EXTRA_NAME = "memory"
PIP_DOWNLOAD_DEST_PLACEHOLDER = "{avibe-pip-download-destination}"
+# A GitHub-only pre-release publishes its wheels as release assets and nothing
+# to PyPI, so an install taken from one can only be repaired from that same
+# release. Which release that is comes from the installer's own PEP 610 record,
+# never from the version string: `publish.yml` accepts official `vX.Y.ZrcN`
+# tags and publishes them to PyPI, so a pre-release version says nothing about
+# where its wheels live.
+RELEASE_DOWNLOAD_BASE_URL = "https://github.com/avibe-bot/avibe/releases/download"
DEFAULT_UPDATE_METADATA_URL = f"https://pypi.org/pypi/{PACKAGE_NAME}/json"
CURRENT_VIBE_EXECUTABLE_ENV = "VIBE_CURRENT_EXECUTABLE"
SHOW_RUNTIME_SKIP_ENV = "VIBE_INSTALL_SKIP_SHOW_RUNTIME"
@@ -1269,6 +1277,84 @@ def _memory_target_version(package_spec: str, target_version: str | None) -> str
return _published_version(str(version))
+def _wheel_distribution(package_name: str) -> str:
+ """Spell one distribution name the way a wheel filename does."""
+
+ return canonicalize_name(package_name).replace("-", "_")
+
+
+def _recorded_install_origin(package_name: str) -> str | None:
+ """The URL an installed distribution was taken from, per PEP 610.
+
+ Installers write `direct_url.json` only when the distribution came from
+ somewhere other than an index, so its absence is itself the answer: this
+ copy was resolved by name and can be repaired the same way.
+ """
+
+ try:
+ from importlib.metadata import PackageNotFoundError, distribution
+
+ recorded = distribution(package_name).read_text("direct_url.json")
+ except PackageNotFoundError:
+ return None
+ except Exception:
+ logger.warning("Could not read %s install origin; assuming an index install", package_name, exc_info=True)
+ return None
+ if not recorded:
+ return None
+ try:
+ url = json.loads(recorded).get("url")
+ except (ValueError, AttributeError):
+ return None
+ return url if isinstance(url, str) else None
+
+
+def release_asset_specs(version: str) -> tuple[str, str] | None:
+ """The wheel pair this install came from, or `None` if an index serves it.
+
+ A version string cannot answer this. `publish.yml` accepts official
+ `vX.Y.ZrcN` tags and publishes them to PyPI, so a pre-release may well be
+ on an index, while a `gh-v*` build carrying the identical version is on no
+ index at all. Treating every pre-release as GitHub-only would point the
+ official one at a tag that was never created.
+
+ The installer already recorded the answer. When core came from a release
+ asset of this repository, the pair is repaired from that same release —
+ the one it demonstrably came from, rather than one derived from a naming
+ convention. Every other origin, an index install included, returns `None`
+ and keeps its index pins.
+
+ The recorded URL must name this exact running version, so a stale or
+ mismatched record cannot drive the repair to a different pair.
+ """
+
+ origin = _recorded_install_origin(PACKAGE_NAME)
+ if not origin:
+ return None
+ try:
+ normalized = str(Version(version))
+ except InvalidVersion:
+ return None
+ prefix = f"{RELEASE_DOWNLOAD_BASE_URL}/"
+ if not origin.startswith(prefix):
+ return None
+ # Exactly one tag segment and one filename: anything else is not an asset of
+ # this repository's releases, whatever it may resemble.
+ segments = origin[len(prefix) :].split("/")
+ if len(segments) != 2:
+ return None
+ tag, asset = segments
+ if not tag or tag in {".", ".."}:
+ return None
+ if asset != f"{_wheel_distribution(PACKAGE_NAME)}-{normalized}-py3-none-any.whl":
+ return None
+ # One release directory, so the companion cannot come from another release.
+ return (
+ origin,
+ f"{prefix}{tag}/{_wheel_distribution(MEMORY_PACKAGE_NAME)}-{normalized}-py3-none-any.whl",
+ )
+
+
def pinned_package_spec(
version: str,
*,
@@ -1303,14 +1389,27 @@ def build_upgrade_plan(
memory_package: bool | None = None,
memory_version: str | None = None,
package_spec: str | None = None,
+ core_spec: str | None = None,
+ memory_spec: str | None = None,
) -> UpgradePlan:
"""How to install avibe: the newest release, or `version` exactly.
Exact-version plans support the explicit Memory package install action. They
replace the ordinary upgrade request and force the installer so the matching
optional distribution is applied even when core is already satisfied.
+
+ `core_spec` and `memory_spec` name where to fetch that exact pair when it
+ was never published to an index — a preview release's own wheel URLs. They
+ replace the two pins and change nothing else, so the resulting plan is the
+ same operation against a different source. A forward upgrade resolves the
+ newest release rather than a known one and has no such source to name, so
+ passing either without `version` is rejected instead of ignored: a spec that
+ silently does nothing would read as applied.
"""
+ if (core_spec or memory_spec) and not version:
+ raise ValueError("Explicit install sources require an exact target version")
+
executable = python_executable or sys.executable
# A caller targeting another interpreter (for example a test-owned venv)
# can provide an explicit package-shape measurement. Only infer from this
@@ -1323,9 +1422,12 @@ def build_upgrade_plan(
else bool(memory_enabled or memory_package_installed())
)
package_spec = (
- pinned_package_spec(
- version,
- package_name=package_name or PACKAGE_NAME,
+ (
+ core_spec
+ or pinned_package_spec(
+ version,
+ package_name=package_name or PACKAGE_NAME,
+ )
)
if version
else (package_spec or get_upgrade_package_spec())
@@ -1338,7 +1440,14 @@ def build_upgrade_plan(
if not version and include_memory and f"[{MEMORY_EXTRA_NAME}]" not in package_spec:
package_spec = _with_memory_extra(package_spec)
memory_target = memory_version if version else target_version
- pinned_memory_spec = f"{MEMORY_PACKAGE_NAME}=={memory_target}" if include_memory and memory_target else None
+ # The URL form stays a named requirement so every installer still reads it
+ # as "this distribution, from here" rather than as an anonymous artifact.
+ pinned_memory_spec = None
+ if include_memory:
+ if memory_spec:
+ pinned_memory_spec = f"{MEMORY_PACKAGE_NAME} @ {memory_spec}"
+ elif memory_target:
+ pinned_memory_spec = f"{MEMORY_PACKAGE_NAME}=={memory_target}"
if is_uv_tool_install(executable) and uv_binary:
env = dict(base_env or os.environ)