From 9d33639c04edb3009f99bbdf80adc204c1187011 Mon Sep 17 00:00:00 2001 From: Hermenix Date: Sun, 11 Oct 2026 22:53:50 +0000 Subject: [PATCH] fix(sessions): `start --stream` answers with the daemon's stream, not the record's MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `start`'s reply was `Session.public()`, which reports what was *stored* -- and a `url` is never stored, because naming one is the daemon's (CONTRACT-sessions.md §3.5) and a URL on disk is a URL that lies the first time the listener moves. So a successful `start --stream` handed back a stream with a phrase and no URL, which no caller could tell from a stream that failed to open: the CLI printed WARNING: the session is running but its stream was not enabled: the broker reported no stream over a stream the daemon had attached a second earlier, and the MCP tool's summary said `stream: NOT enabled` for the same reason. `stream enable` was always right, because it answers with `_stream_public` -- only the one-call path was wrong. Found by checks/vm-stream.nix's last subtest, which is the only place `start --stream` runs against a real daemon. The unit test added beside it pins the seam rather than the symptom: the reply carries a `url`, the record does not, so anything answering from the record alone has to merge. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_011ZeH65zd6pFTgBSu52W9PE --- src/hhstreamd/manager.py | 19 ++++++++++++++++++- tests/sessions/unit/test_stream_verbs.py | 22 ++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/hhstreamd/manager.py b/src/hhstreamd/manager.py index d37a6f8..ce8c9fc 100644 --- a/src/hhstreamd/manager.py +++ b/src/hhstreamd/manager.py @@ -1018,6 +1018,9 @@ class SessionManager: if session.live: await self._read_back(session, app_id) stream_error: str | None = None + #: The daemon's view of the stream, which is the only place a `url` + #: exists. Locals and not attributes, for the reason below. + stream_public: dict[str, Any] | None = None if stream and session.live: # After the read-back, because that is what settles the container's # output, and a stream has to have one to publish @@ -1032,9 +1035,10 @@ class SessionManager: # be the wrong trade; the refusal is reported on the session's # `stream_error` and the caller can retry `stream.enable`. try: - await self.stream_enable( + enabled = await self.stream_enable( session.id, phrase=stream_phrase, fps=stream_fps ) + stream_public = enabled.get("stream") except ManagerError as exc: log.warning("could not enable %s's stream: %s", session.id, exc.reason) session.last_error = session.last_error or exc.reason @@ -1049,6 +1053,19 @@ class SessionManager: # a key that appears only on failure is a key every caller has to # remember to look for. record["stream_error"] = stream_error + if stream_public is not None: + # The daemon's view, not the record's. `Session.public()` + # reports what was stored, and a `url` is never stored -- + # naming one is the daemon's (§3.5), and a URL on disk is a URL + # that lies after the listener moves. So a successful + # `start --stream` that answered with `session.public()` alone + # handed back a stream with no URL, which a caller cannot tell + # from one that failed to open. + # + # MEASURED in checks/vm-stream.nix: the daemon attached, the + # broker recorded it, and the CLI printed "the session is + # running but its stream was not enabled". + record["stream"] = stream_public if session.state == State.EXITED: # The app exited during the settle: surface it rather than handing # back a healthy-looking id (DESIGN.md §7 #3). diff --git a/tests/sessions/unit/test_stream_verbs.py b/tests/sessions/unit/test_stream_verbs.py index ad70784..76484fd 100644 --- a/tests/sessions/unit/test_stream_verbs.py +++ b/tests/sessions/unit/test_stream_verbs.py @@ -217,6 +217,28 @@ def test_enabling_mints_a_phrase_the_daemon_accepts_and_publishes(harness): assert harness.daemon.outputs() == ["hh-foot-aaaaaa"] +def test_the_url_is_the_daemon_s_and_is_not_in_the_record(harness): + """So anything answering with the record alone must merge the reply in. + + REGRESSION. `start --stream` built its answer from `Session.public()`, + which reports what was *stored* -- and a `url` is never stored, because + naming one is the daemon's (CONTRACT-sessions.md §3.5). The result was a + successful start whose stream had no URL, which the CLI could not tell + from a stream that failed to open: it printed "the session is running but + its stream was not enabled" over a stream the daemon had just attached. + Found by checks/vm-stream.nix, which is also where the `start --stream` + path is proven end to end -- there is no launcher here. + """ + + harness.add() + reply = harness.run(harness.manager.stream_enable("foot-aaaaaa")) + + assert reply["stream"]["url"] + stored = harness.manager.registry.get("foot-aaaaaa").public(harness.clock.boottime()) + assert stored["stream"]["phrase"] == reply["stream"]["phrase"] + assert "url" not in stored["stream"] + + def test_the_phrase_is_in_the_record_so_it_survives_a_restart(harness): harness.add() first = harness.run(harness.manager.stream_enable("foot-aaaaaa"))["stream"]