Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions loopx/chat_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1881,8 +1881,11 @@ def serve_chat(
raise ValueError("loopx chat requires a loopback --host such as 127.0.0.1")
resolved_assets = (assets_dir or default_chat_assets_dir()).expanduser().resolve()
if assets_dir is None:
from .presentation.chat_bundle import validate_bundle
validate_bundle(resolved_assets, source_root=Path(__file__).resolve().parents[1])
from .presentation.chat_bundle import runtime_source_root, validate_bundle
validate_bundle(
resolved_assets,
source_root=runtime_source_root(Path(__file__).resolve().parents[1]),
)
if not (resolved_assets / "index.html").is_file():
raise FileNotFoundError("LoopX Chat web assets are unavailable; reinstall LoopX or rebuild the chat bundle")
resolved_registry_path = registry_path or (Path.home() / ".loopx" / "registry.json")
Expand Down
7 changes: 5 additions & 2 deletions loopx/dashboard_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,11 @@ def launch_dashboard(
)

if assets_dir is None:
from .presentation.chat_bundle import validate_bundle
validate_bundle(default_packaged_assets_dir(), source_root=Path(__file__).resolve().parents[1])
from .presentation.chat_bundle import runtime_source_root, validate_bundle
validate_bundle(
default_packaged_assets_dir(),
source_root=runtime_source_root(Path(__file__).resolve().parents[1]),
)

existing_chat = _probe_existing_chat(
host,
Expand Down
2 changes: 1 addition & 1 deletion loopx/hosts/managed_service_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
_OBSERVER_LABEL = "com.loopx.codex-native-accounts"
_OBSERVER_MODULE = "loopx_codex_provider_routing.native"
_RUNTIME_BINDING = {"schema_version": "loopx_managed_runtime_binding_v1"}
_SERVICE_READINESS_TIMEOUT_SECONDS = 45.0
_SERVICE_READINESS_TIMEOUT_SECONDS = 90.0


def _literal_arguments(command: str) -> list[str]:
Expand Down
21 changes: 21 additions & 0 deletions loopx/presentation/chat_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,27 @@ def source_inputs(root: Path) -> dict[str, str]:
}


def runtime_source_root(root: Path) -> Path | None:
"""Return the frontend source root when live source-freshness checks apply.

Immutable installed releases carry a `release.json` manifest with a
non-empty `release_id` and no `.git` checkout marker; they already passed
build-time source verification and skip redundant 700+ file source hashing
at server startup while keeping full served-bundle digest checks.
"""
resolved = root.expanduser().resolve()
if (resolved / ".git").exists():
return resolved
try:
manifest = json.loads((resolved / "release.json").read_text(encoding="utf-8"))
except (OSError, json.JSONDecodeError):
return resolved
release_id = manifest.get("release_id") if isinstance(manifest, dict) else None
if isinstance(release_id, str) and release_id.strip():
return None
return resolved


def safe_relative(value: str) -> bool:
if not isinstance(value, str):
return False
Expand Down
7 changes: 5 additions & 2 deletions loopx/presentation/runtime_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ..capabilities.explore.result_log import explore_history_rows
from ..control_plane.status.goal_source import GoalSource, GoalSourceReader, SourceScopeError
from ..status_server import cors_response_headers, is_loopback_host, is_loopback_origin, parse_strict_json_object
from .chat_bundle import validate_bundle
from .chat_bundle import runtime_source_root, validate_bundle
from .research_analysis_api import RESEARCH_ANALYSIS_PATH, ResearchAnalysisRequestMixin


Expand Down Expand Up @@ -253,7 +253,10 @@ def main():
assets = (args.assets_dir or Path(__file__).resolve().parents[1] / "web" / "chat").expanduser().resolve()
if args.assets_dir is None:
try:
validate_bundle(assets, source_root=Path(__file__).resolve().parents[2])
validate_bundle(
assets,
source_root=runtime_source_root(Path(__file__).resolve().parents[2]),
)
except RuntimeError as exc:
parser.error(str(exc))
if not (assets / "index.html").is_file():
Expand Down
53 changes: 52 additions & 1 deletion tests/presentation/test_chat_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import zipfile

import pytest
from loopx.presentation.chat_bundle import MANIFEST, validate_bundle
from loopx.presentation.chat_bundle import MANIFEST, runtime_source_root, validate_bundle

spec = importlib.util.spec_from_file_location(
"chat_builder", Path(__file__).resolve().parents[2] / "scripts/chat_bundle.py"
Expand Down Expand Up @@ -405,3 +405,54 @@ def test_provider_contract_update_invalidates_packaged_frontend(source, tmp_path
contract.write_text("changed contract", encoding="utf-8")
with pytest.raises(RuntimeError, match="source changed"):
validate_bundle(builder.OUTPUT, source_root=tmp_path)


def test_runtime_source_root_skips_source_scan_only_for_immutable_installed_release(
source, tmp_path, monkeypatch,
):
builder.build(None)
(tmp_path / "release.json").write_text(
'{"release_id": "20261120T000000Z"}\n',
encoding="utf-8",
)

assert runtime_source_root(tmp_path) is None

def fail_source_inputs(_root):
raise AssertionError("installed releases must not re-hash source inputs")

monkeypatch.setattr("loopx.presentation.chat_bundle.source_inputs", fail_source_inputs)
manifest = validate_bundle(builder.OUTPUT, source_root=runtime_source_root(tmp_path))
assert manifest["schema_version"] == "loopx_chat_bundle_v1"

# Served asset integrity checks remain active even when source scanning is skipped.
index = builder.OUTPUT / "index.html"
index.write_text("tampered", encoding="utf-8")
with pytest.raises(RuntimeError, match="bundle file changed: index.html"):
validate_bundle(builder.OUTPUT, source_root=runtime_source_root(tmp_path))


@pytest.mark.parametrize("git_kind", ["dir", "file"])
def test_runtime_source_root_retains_checkout_verification_when_git_present(tmp_path, git_kind):
(tmp_path / "release.json").write_text(
'{"release_id": "20261120T000000Z"}\n',
encoding="utf-8",
)
git_marker = tmp_path / ".git"
if git_kind == "dir":
git_marker.mkdir()
else:
git_marker.write_text("gitdir: /tmp/worktree\n", encoding="utf-8")

assert runtime_source_root(tmp_path) == tmp_path.resolve()


@pytest.mark.parametrize(
"release_json",
[None, "{invalid json", "[]", "{}", '{"release_id": ""}', '{"release_id": " "}'],
)
def test_runtime_source_root_fails_closed_without_valid_release_manifest(tmp_path, release_json):
if release_json is not None:
(tmp_path / "release.json").write_text(release_json, encoding="utf-8")

assert runtime_source_root(tmp_path) == tmp_path.resolve()
8 changes: 4 additions & 4 deletions tests/test_managed_service_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ def fail_once(*args):



def test_verify_services_allows_production_startup_past_legacy_15s_cutoff_and_enforces_45s_deadline(
def test_verify_services_allows_production_startup_past_legacy_cutoff_and_enforces_90s_deadline(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch,
) -> None:
import io
Expand All @@ -757,7 +757,7 @@ def __exit__(self, *args):

class _FakeOpener:
def open(self, url: str, timeout: float = 0.5):
if clock[0] < 22.0:
if clock[0] < 60.0:
raise ConnectionRefusedError("starting up")
if url.endswith("/?readiness=1"):
payload = {
Expand All @@ -784,7 +784,7 @@ def open(self, url: str, timeout: float = 0.5):
)

managed_runtime._verify_services(services, identity)
assert clock[0] == 22.0
assert clock[0] == 60.0

clock[0] = 0.0

Expand All @@ -795,4 +795,4 @@ def open(self, url: str, timeout: float = 0.5):
monkeypatch.setattr(managed_runtime.urllib.request, "build_opener", lambda *_: _NeverReadyOpener())
with pytest.raises(RuntimeError, match="service_runtime_alignment_failed"):
managed_runtime._verify_services(services, identity)
assert clock[0] == 45.0
assert clock[0] == 90.0
Loading