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.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(remote): preserve IPv6 family in pairing origins (#2014)
Max4c382a8f7e0c
diff --git a/docs/plans/issue-1965-ipv6-pairing-origin.md b/docs/plans/issue-1965-ipv6-pairing-origin.mdnew file mode 100644index 000000000..93f9ce492--- /dev/null+++ b/docs/plans/issue-1965-ipv6-pairing-origin.md@@ -0,0 +1,71 @@+# IPv6 pairing origin family consistency++## Intent and boundary++Fix #1965: when Cloud widens a non-loopback IPv6 UI bind to `::`, every pairing-origin consumer must receive an IPv6 loopback URL that can reach that listener. The public signatures and configuration schema remain unchanged.++## Evidence++Audited `master@e8a7cb4a94e93b5413a977d70816b01560e3d156`: both `fd00::1` and `2001:db8::5` yield bind `::`, origin `127.0.0.1`. A disposable asyncio server confirmed IPv4 refusal and IPv6 loopback success. `_origin_host_for_pairing` owns the projection; inventory its direct and indirect consumers before changing it.++## Acceptance invariants++- With Cloud enabled, bind and pairing origin agree on reachable address family; non-loopback IPv6 hosts project to bracketed IPv6 loopback in URLs.+- Existing IPv4, loopback, wildcard, bracket normalization and localhost-resolution behavior is preserved unless a contradiction is demonstrated.+- All existing consumers of this shared projection inherit the correction, including tunnel configuration, health, expected origin and model service. Keep probe failures observable.+- Hermetic tests include a real disposable socket/HTTP connection through the produced origin to the produced bind, with clear platform capability handling; no live pairing or external user state.+- The relevant existing unit and auth/setup scenario tests pass; Ruff passes on all changed Python files. Update scenario metadata if this flow has a catalog case.++## Scope++Allowed: `vibe/remote_access.py`, `vibe/runtime.py` only if needed for shared family ownership, `tests/test_remote_access_vibe_cloud.py`, a focused new test module if isolation improves it, `tests/scenarios/auth_setup/catalog.yaml`, `tests/scenarios/auth_setup/test_auth_setup_scenarios.py`, and this plan. Read other consumers but ask the orchestrator before editing another production module. No UI files, schema change, service restart, deployment, dependency addition or broad refactor.++## Delivery++Smallest complete fix, focused validation, non-draft PR targeting `master`, `Fixes #1965`, exact-head Codex-bot pass, full expected CI and zero unresolved threads. Do not merge or close the issue before integration. Update this plan with verified evidence and residual manual checks.++## Implementation and verified evidence++- Base verified by explicit master fetch: `e8a7cb4a94e93b5413a977d70816b01560e3d156`.+- The shared projection now maps every parsed non-loopback IPv6 address to+ `[::1]`; the existing loopback-preservation and localhost-resolution branches+ are unchanged. No runtime bind, configuration, dependency or API change is needed.+- Consumer inventory at that base: `_origin_host_for_pairing` feeds+ `origin_service_for_pairing`, which feeds the pairing redeem payload (the+ backend configures cloudflared), `_local_ui_healthy`,+ `runtime_status_payload.expected_origin_service`, and+ `model_service._model_service_ui_origins`. All inherit the same correction.+- The audit's seven existing origin assertions describe IPv4, localhost,+ loopback or wildcard cases; none needs weakening or a changed expectation.+ Added family coverage includes private/global, bracketed, scoped and mapped+ IPv6 literals, plus unchanged IPv4 and hostname behavior.+- `AUTH-SETUP-907` starts a disposable aiohttp/asyncio HTTP listener on the+ actual effective bind and connects through the produced pairing and model+ service origins. It checks the real health consumer and reported origin,+ then verifies that a closed listener reports unhealthy. IPv6 cases require+ `IPV6_V6ONLY=1`, so dual-stack acceptance cannot hide a wrong IPv4 origin.+ Separate capability probing skips only unavailable OS IPv6 loopback support;+ errors in the generated bind or origin fail the test.+- Before the fix, focused coverage produced 10 failures and 11 passes,+ including connection failures in all three non-loopback IPv6 socket cases.+ After the fix, the full remote-access, auth/setup and model-service suites+ passed: **425 tests and 12 subtests**, with no skips.+- Mutation check: restoring only the old conditional made all three IPv6 HTTP+ cases fail with connection errors while the IPv4 control passed. Restoring+ the fix passed all four. Ruff passed on all three changed Python files.+- Hermetic boundaries: the existing autouse fixture redirects home, config,+ credential and SQLite state into test-owned directories. Pairing backend and+ connector lifecycle are stubbed; HTTP uses ephemeral local ports with proxy+ bypass. No live pairing, service restart or deployment was performed.++## Residual integration verification++The orchestrator may verify a real cloudflared tunnel after separately authorized+integration: pair an IPv6-configured local regression instance, confirm the+backend ingress uses `http://[::1]:<effective-port>`, then load the remote UI and+check health. This lane proves the local socket boundary and pairing payload;+it does not exercise external Cloud provisioning. Existing already-paired+backend ingress is not rewritten by this projection-only change.++Scope stayed within the assigned production module, existing tests/catalog and+this plan. No cross-lane interfaces or files changed.diff --git a/tests/scenarios/auth_setup/catalog.yaml b/tests/scenarios/auth_setup/catalog.yamlindex bd34caeac..77bf2f1c1 100644--- a/tests/scenarios/auth_setup/catalog.yaml+++ b/tests/scenarios/auth_setup/catalog.yaml@@ -310,4 +310,11 @@ scenarios:layer: scenariobackend: claudetest: tests/scenarios/auth_setup/test_auth_setup_scenarios.py::test_instance_manager_backend_credentials_round_trip+ - id: AUTH-SETUP-907+ name: Cloud pairing origin consumers reach the effective UI listener in its address family+ status: covered+ kind: historical_regression+ layer: scenario+ backend: web+ test: tests/scenarios/auth_setup/test_auth_setup_scenarios.py::test_cloud_pairing_origin_reaches_effective_ui_listenernext_priority: []diff --git a/tests/scenarios/auth_setup/test_auth_setup_scenarios.py b/tests/scenarios/auth_setup/test_auth_setup_scenarios.pyindex 8629bfeb3..a0c1c7e67 100644--- a/tests/scenarios/auth_setup/test_auth_setup_scenarios.py+++ b/tests/scenarios/auth_setup/test_auth_setup_scenarios.py@@ -1,7 +1,9 @@import asyncio+import errnoimport jsonimport osimport re+import socketimport sysimport tempfileimport time@@ -67,7 +69,7 @@ from vibe.claude_config import (materialize_claude_subprocess_env,read_claude_settings_env,)-from vibe import remote_access, show_identity, ui_server+from vibe import model_service, remote_access, runtime, show_identity, ui_serverfrom vibe.ui_server import appfrom vibe.model_hub_runtime.api_key_vendors import api_key_vendor_catalogfrom vibe.model_hub_runtime.adapter import (@@ -321,6 +323,69 @@ def _save_remote_web_auth_config() -> V2Config:return config[email protected]("setup_host", ["192.0.2.5", "fd00::1", "2001:db8::5", "[2001:db8::5]"])+async def test_cloud_pairing_origin_reaches_effective_ui_listener(monkeypatch, setup_host):+ """Scenario: AUTH-SETUP-907 — every origin consumer reaches the widened UI bind."""+ ipv6 = ":" in setup_host+ if ipv6:+ if not socket.has_ipv6:+ pytest.skip("Platform has no IPv6 support")+ # Probe OS capability separately: failures in the produced bind or URL+ # below must fail the scenario, never become capability skips.+ try:+ with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as probe:+ probe.bind(("::1", 0))+ except OSError as exc:+ if exc.errno in {errno.EAFNOSUPPORT, errno.EPROTONOSUPPORT, errno.EADDRNOTAVAIL}:+ pytest.skip(f"IPv6 loopback unavailable: {exc}")+ raise++ config = _save_remote_web_auth_config()+ config.ui.setup_host = setup_host+ config.save()+ monkeypatch.setenv("NO_PROXY", "*")+ monkeypatch.setenv("no_proxy", "*")+ monkeypatch.setattr(remote_access, "status", lambda cfg: {"running": True, "binary_found": True})+ monkeypatch.setattr(remote_access, "_observed_cloudflared_origin_service", lambda: None)+ requests_seen = []++ async def health(request):+ requests_seen.append(request.path)+ return web.json_response({"ok": True})++ local_ui = web.Application()+ local_ui.router.add_get("/health", health)+ runner = web.AppRunner(local_ui)+ await runner.setup()+ try:+ site = web.TCPSite(runner, host=runtime.effective_ui_bind_host(config), port=0)+ await site.start()+ listener = site._server.sockets[0]+ if ipv6:+ assert listener.family == socket.AF_INET6+ assert listener.getsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY) == 1+ monkeypatch.setenv("VIBE_UI_PORT", str(listener.getsockname()[1]))++ # Consume the persisted config and effective port just as pairing does.+ origin = remote_access.origin_service_for_pairing()+ async with httpx.AsyncClient(trust_env=False, timeout=2) as client:+ response = await client.get(f"{origin}/health")+ assert response.json() == {"ok": True}+ for model_origin in model_service._model_service_ui_origins(config):+ response = await client.get(f"{model_origin}/health")+ assert response.json() == {"ok": True}+ payload = await asyncio.to_thread(remote_access.runtime_status_payload, config)+ assert payload["expected_origin_service"] == origin+ assert payload["ui_healthy"] is True+ assert requests_seen == ["/health"] * 3+ finally:+ await runner.cleanup()++ # Closing the disposable listener must remain visible as an unhealthy UI.+ payload = await asyncio.to_thread(remote_access.runtime_status_payload, config)+ assert payload["ui_healthy"] is False++def test_remote_web_oauth_cold_launch_retry_is_single_owner(monkeypatch, tmp_path):"""Scenario: AUTH-SETUP-209"""monkeypatch.setenv("AVIBE_HOME", str(tmp_path))diff --git a/tests/test_remote_access_vibe_cloud.py b/tests/test_remote_access_vibe_cloud.pyindex 448c8dd57..be0bd487a 100644--- a/tests/test_remote_access_vibe_cloud.py+++ b/tests/test_remote_access_vibe_cloud.py@@ -718,9 +718,15 @@ def test_exchange_oauth_code_allows_30_seconds_of_clock_skew(assert exc_info.value.reason == expected_reason-def test_pair_redeems_key_and_starts_connector(monkeypatch, tmp_path) -> None:+ ("setup_host", "origin_host"),+ [("127.0.0.1", "127.0.0.1"), ("fd00::1", "[::1]"), ("[2001:db8::5]", "[::1]")],+)+def test_pair_redeems_key_and_starts_connector(monkeypatch, tmp_path, setup_host, origin_host) -> None:monkeypatch.setenv("AVIBE_HOME", str(tmp_path))+ monkeypatch.delenv("VIBE_UI_PORT", raising=False)config = _config()+ config.ui.setup_host = setup_hostconfig.remote_access.vibe_cloud.enabled = Falseconfig.remote_access.vibe_cloud.session_secret = ""config.save()@@ -728,7 +734,7 @@ def test_pair_redeems_key_and_starts_connector(monkeypatch, tmp_path) -> None:def fake_request(url: str, payload: dict, timeout: float = 20.0, **kwargs):assert url == "https://backend.test/api/v1/pairing/redeem"assert payload["pairing_key"] == "vrp_test"- assert payload["origin_service"] == "http://127.0.0.1:5123"+ assert payload["origin_service"] == f"http://{origin_host}:5123"assert kwargs["connection_target"].hostname == "backend.test"assert kwargs["connection_target"].connect_host == "93.184.216.34"return {@@ -1262,6 +1268,37 @@ def test_pair_origin_service_uses_ipv6_loopback_for_ipv6_wildcard(monkeypatch, tassert remote_access.origin_service_for_pairing() == "http://[::1]:15130"+ ("setup_host", "bind_host", "origin_host"),+ [+ ("", "127.0.0.1", "127.0.0.1"),+ ("ui.example.test", "0.0.0.0", "127.0.0.1"),+ ("192.168.2.3", "0.0.0.0", "127.0.0.1"),+ ("0.0.0.0", "0.0.0.0", "127.0.0.1"),+ ("127.0.0.2", "127.0.0.2", "127.0.0.2"),+ ("::1", "::1", "[::1]"),+ ("[::1]", "::1", "[::1]"),+ ("::", "::", "[::1]"),+ ("[::]", "::", "[::1]"),+ ("fd00::1", "::", "[::1]"),+ ("2001:db8::5", "::", "[::1]"),+ (" [2001:db8::5] ", "::", "[::1]"),+ ("fe80::1%eth0", "::", "[::1]"),+ ("::ffff:192.0.2.5", "::", "[::1]"),+ ],+)+def test_pairing_consumers_share_the_bind_address_family(monkeypatch, setup_host, bind_host, origin_host):+ monkeypatch.delenv("VIBE_UI_PORT", raising=False)+ config = _config()+ config.ui.setup_host = setup_host+ config.ui.setup_port = 15130+ origin = f"http://{origin_host}:15130"++ assert runtime.effective_ui_bind_host(config) == bind_host+ assert remote_access.origin_service_for_pairing(config) == origin+ assert model_service._model_service_ui_origins(config) == (origin,)++def test_ra_tq_007_runtime_status_payload_includes_tunnel_quality(monkeypatch, tmp_path) -> None:monkeypatch.setenv("AVIBE_HOME", str(tmp_path))config = _config()diff --git a/vibe/remote_access.py b/vibe/remote_access.pyindex fa62377da..822e50756 100644--- a/vibe/remote_access.py+++ b/vibe/remote_access.py@@ -4516,7 +4516,9 @@ def _origin_host_for_pairing(config: V2Config) -> str:if address.is_loopback:return f"[{address.compressed}]" if address.version == 6 else address.compressed- if address.is_unspecified and address.version == 6:+ # Cloud widens non-loopback IPv6 binds to ::. Its IPv6-only listener+ # requires an IPv6 loopback origin, including for specific interface IPs.+ if address.version == 6:return "[::1]"return "127.0.0.1"