Skip to content

The agent that grows with you

fix(webapp): report an unbuilt Webapp as unavailable and say how to build it

emozilla43a978390c13
diff --git a/gateway/webapp_listener.py b/gateway/webapp_listener.py
index 3ac857eaf67..f343ee93923 100644
--- a/gateway/webapp_listener.py
+++ b/gateway/webapp_listener.py
@@ -187,6 +187,24 @@ def _one_use_links_work() -> bool:
return sys.platform != "darwin"
+#: How every missing-bundle reason starts; ``hermes webapp --status`` asks for no restart after it.
+NOT_BUILT = "The Webapp is not built"
+
+
+def bundle_missing_reason(dist) -> str | None:
+ """Why the Webapp cannot be served from *dist*, or None once its bundle is built. The listener
+ serves a bundle the moment it appears, so building it needs no gateway restart."""
+ if (Path(dist) / "index.html").is_file():
+ return None
+ return f"{NOT_BUILT} ({Path(dist) / 'index.html'} is missing). Run hermes webapp to build it."
+
+
+def _bundle_missing(web) -> str | None:
+ """:func:`bundle_missing_reason` for the bundle the mounted Webapp serves, or None."""
+ dist = getattr(getattr(getattr(web, "app", None), "state", None), "web_dist", None)
+ return None if dist is None else bundle_missing_reason(dist)
+
+
def register_control_verbs(runner, home) -> None:
"""The private control-socket verbs ``hermes webapp`` uses; only an authenticated same-user peer
reaches them. ``webapp-launch`` returns a one-use launch link, so the credential crosses neither
@@ -209,7 +227,12 @@ def register_control_verbs(runner, home) -> None:
return status, web
def webapp_status(_params, _peer):
- return dict(runner.webapp_status)
+ # Serving only while the bundle is built; the listener serves one as soon as it appears.
+ status = dict(runner.webapp_status)
+ missing = _bundle_missing(getattr(getattr(getattr(runner, "session_api", None), "app", None), "web", None))
+ if status["state"] == "serving" and missing:
+ return {"state": "unavailable", "url": None, "reason": missing}
+ return status
def webapp_launch(params, _peer):
from urllib.parse import urlencode
@@ -221,6 +244,9 @@ def register_control_verbs(runner, home) -> None:
raise ValueError("profile must be a profile name")
query = f"?profile={profile}" if profile else "" # the page opens on that profile
status, web = serving()
+ missing = _bundle_missing(web)
+ if missing:
+ raise RuntimeError(f"The Webapp is unavailable: {missing}")
from hermes_cli.web_server_surface import private_launch
if not private_launch(web.app.state):
# Behind the dashboard's sign-in the page asks for it; a launch link opens only a private Webapp.
diff --git a/hermes_cli/web_server_dashboard.py b/hermes_cli/web_server_dashboard.py
index 0fdfdb95241..0d35c6b20ed 100644
--- a/hermes_cli/web_server_dashboard.py
+++ b/hermes_cli/web_server_dashboard.py
@@ -170,8 +170,12 @@ def mount_spa(application: FastAPI):
try:
html = (web_dist() / "index.html").read_text(encoding="utf-8-sig")
except OSError:
- # Partial build / wiped dist / permissions: same JSON 404 as a fully-missing dist.
- return JSONResponse({"error": "Frontend not built. Run: cd web && npm run build"}, status_code=404)
+ # Partial build / wiped dist / permissions: same JSON 404 as a fully-missing dist. The
+ # Webapp's bundle is built by `hermes webapp`, not by the dashboard's web project.
+ webapp = getattr(application.state, "ui_surface", "dashboard") == "webapp"
+ missing = ("The Webapp is not built. Run: hermes webapp" if webapp
+ else "Frontend not built. Run: cd web && npm run build")
+ return JSONResponse({"error": missing}, status_code=404)
chat_js = "true" if _DASHBOARD_EMBEDDED_CHAT_ENABLED else "false"
gated = bool(getattr(application.state, "auth_required", False))
surface = getattr(application.state, "ui_surface", "dashboard")
diff --git a/hermes_cli/webapp_launcher.py b/hermes_cli/webapp_launcher.py
index 1b1681f0ade..bc77185df0c 100644
--- a/hermes_cli/webapp_launcher.py
+++ b/hermes_cli/webapp_launcher.py
@@ -101,7 +101,9 @@ def _status(target: Path) -> int:
print(f"The Webapp is off. Set webapp.enabled: true in {target / 'config.yaml'}, then run {RESTART_COMMAND}.")
else:
print(f"Unavailable: {status['reason']}")
- print(RETRY_AFTER_FIX)
+ from gateway.webapp_listener import NOT_BUILT
+ if not str(status["reason"]).startswith(NOT_BUILT): # a build is served without a restart
+ print(RETRY_AFTER_FIX)
return 0
diff --git a/tests/gateway/test_webapp_bundle.py b/tests/gateway/test_webapp_bundle.py
new file mode 100644
index 00000000000..46f35434124
--- /dev/null
+++ b/tests/gateway/test_webapp_bundle.py
@@ -0,0 +1,57 @@
+"""A Webapp whose bundle is not built is reported unavailable, with how to build it.
+
+The gateway serves the Webapp from its built bundle (``apps/desktop/dist-webapp``). Until that bundle
+has its ``index.html`` the gateway reports the Webapp unavailable, says to run ``hermes webapp`` (which
+builds it), mints no launch link and answers ``/`` with that instruction rather than the dashboard's
+build command. The listener picks the bundle up as soon as it is built, without a restart. The live
+case runs a real gateway listener in a child process (``fixtures/webapp_fallback_peer.py``).
+"""
+import pytest
+
+from gateway import webapp_listener
+from hermes_cli import webapp_launcher as launcher
+from tests.gateway.fixtures.webapp_fallback_peer import free_port, run
+
+
[email protected](scope="module")
+def unbuilt(tmp_path_factory):
+ return run(tmp_path_factory.mktemp("unbuilt"), {"webapp": {"enabled": True, "port": free_port()},
+ "built": False})
+
+
+def test_an_unbuilt_webapp_is_unavailable_and_says_how_to_build_it(unbuilt):
+ assert unbuilt["start_error"] is None, unbuilt.get("start_traceback")
+ status = unbuilt["status"]
+ assert (status["state"], status["url"]) == ("unavailable", None)
+ assert "hermes webapp" in status["reason"] and "index.html" in status["reason"]
+
+
+def test_an_unbuilt_webapp_mints_no_launch_link(unbuilt):
+ assert "hermes webapp" in unbuilt["launch"]["refused"]
+
+
+def test_an_unbuilt_webapp_page_names_the_webapps_build(unbuilt):
+ assert unbuilt["index"]["status"] == 404
+ assert "hermes webapp" in unbuilt["index"]["body"]
+ assert "npm run build" not in unbuilt["index"]["body"]
+
+
+def test_the_webapp_is_served_once_built_without_a_restart(unbuilt):
+ assert unbuilt["status_once_built"]["state"] == "serving"
+ assert unbuilt["index_once_built"] == {"status": 200, "is_webapp": True}
+
+
+def test_the_launcher_reports_an_unbuilt_webapp_without_asking_for_a_restart(monkeypatch, tmp_path, capsys):
+ # Building it is enough: the running gateway serves the bundle once it exists.
+ reason = webapp_listener.bundle_missing_reason(tmp_path / "dist-webapp")
+ answer = {"ok": True, "result": {"state": "unavailable", "url": None, "reason": reason}}
+ monkeypatch.setattr(launcher, "_control", lambda home, verb, params=None: answer)
+ assert launcher._status(tmp_path) == 0
+ out = capsys.readouterr().out
+ assert reason in out
+ assert launcher.RESTART_COMMAND not in out
+
+
+def test_a_built_webapp_has_no_missing_bundle_reason(tmp_path):
+ (tmp_path / "index.html").write_text("<!doctype html>", encoding="utf-8")
+ assert webapp_listener.bundle_missing_reason(tmp_path) is None
diff --git a/website/docs/user-guide/desktop.md b/website/docs/user-guide/desktop.md
index 6ad3b9fd760..d485615eac5 100644
--- a/website/docs/user-guide/desktop.md
+++ b/website/docs/user-guide/desktop.md
@@ -76,7 +76,8 @@ a sign-in provider. Prefer an SSH tunnel, Tailscale or another trusted VPN.
`hermes webapp --status` shows whether the gateway serves the Webapp. When it cannot (the port is
taken, or a wildcard host has no sign-in provider), the gateway still serves native clients and the
status says why. The gateway reads these settings when it starts, so restart it after fixing the cause
-(`hermes gateway restart`).
+(`hermes gateway restart`). When the Webapp's bundle has not been built yet, the status says so instead:
+`hermes webapp` builds it, and the running gateway serves it without a restart.
Browser-selected files are staged under the active profile before they enter the normal attachment
flow, with a **16 MiB** limit per file. Host files download through the browser's download manager, and