From 1c320ac69063315b22a9865005d75d34aaab0957 Mon Sep 17 00:00:00 2001 From: Kyle Sexton <153232337+kyle-sexton@users.noreply.github.com> Date: Tue, 27 Oct 2026 13:12:53 -0400 Subject: [PATCH] fix(planning): push a state frame when a surface watcher starts or stops waiting The event stream sends a frame only when Hub.signature() changes, and the signature held the listener state and lease presence but not whether a watcher waits. A wait inside the 10 s listen grace changed neither, so the open page kept reading Claude is working while a watcher waited, until an unrelated file write sent a frame. ui_c.6 passed only when its background handle landed inside the 5 s Live window. The signature now includes waiters > 0. ui_c.6's release check waits for the bridge to report reading before checking the pill, since the pill now reads working from the lease before the release. Co-Authored-By: Claude Opus 5.5 --- ...fix-surface-header-live-waiter-5c2e91a7.md | 7 ++++++ plugins/planning/surface/server.py | 8 +++++-- plugins/planning/surface/test_server.py | 22 +++++++++++++++++++ plugins/planning/surface/tests/ui_c.js | 4 +++- 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 .changes/planning/fix-surface-header-live-waiter-5c2e91a7.md diff --git a/.changes/planning/fix-surface-header-live-waiter-5c2e91a7.md b/.changes/planning/fix-surface-header-live-waiter-5c2e91a7.md new file mode 100644 index 00000000000..1e53a4cd393 --- /dev/null +++ b/.changes/planning/fix-surface-header-live-waiter-5c2e91a7.md @@ -0,0 +1,7 @@ +--- +bump: patch +--- + +### Fixed + +- Interview surface: the header now turns Live as soon as a watcher starts waiting, and leaves Live when the wait ends, even within 10 seconds of the previous wait. Before, the open page heard of a new wait only when some other change came along, so it could read Claude is working while a watcher was waiting. diff --git a/plugins/planning/surface/server.py b/plugins/planning/surface/server.py index 4451eed779b..83bdd8c82a4 100644 --- a/plugins/planning/surface/server.py +++ b/plugins/planning/surface/server.py @@ -1014,6 +1014,7 @@ def user_settings(self): def signature(self): user = self.user_settings() + listener = self.listener() return ( mtime(self.questions), mtime(self.responses), @@ -1023,8 +1024,11 @@ def signature(self): mtime(self.dir / SESSION_JSON), mtime(self.layers.repo_file) if self.layers.repo_file else 0, mtime(Path(user)) if user else 0, - self.listener()["state"], - self.lease_view() is not None, + listener["state"], + # The header reads Live only while a watcher waits, and a wait inside the listen + # grace leaves state and lease unchanged. + listener["waiters"] > 0, + listener["lease"] is not None, ) def watched(self): diff --git a/plugins/planning/surface/test_server.py b/plugins/planning/surface/test_server.py index 9efce104355..915825d454f 100644 --- a/plugins/planning/surface/test_server.py +++ b/plugins/planning/surface/test_server.py @@ -1539,6 +1539,28 @@ def test_a_failed_read_is_marked_stale_until_a_read_succeeds(self): self.assertFalse(hub.read_state()[1]) +class TestSignatureWaiter(unittest.TestCase): + """A waiter arriving or leaving inside the listen grace, lease held, still changes the + signature, so the open page gets the frame that turns its header Live or back to working.""" + + def test_a_waiter_inside_the_grace_changes_the_signature(self): + import server + + tmp = Path(tempfile.mkdtemp(prefix="iv-sig-")) + self.addCleanup(shutil.rmtree, tmp, True) + hub = server.Hub(0, tmp) + with hub.cond: + hub.claim("w1") + hub.lease["inflight"] -= 1 + hub.last_wait = time.time() + before = hub.signature() + hub.waiters = 1 + self.assertEqual(hub.listener()["state"], "listening") + self.assertNotEqual(hub.signature(), before) + hub.waiters = 0 + self.assertEqual(hub.signature(), before) + + class TestEventStreamCap(ServerCase): """At most MAX_STREAMS event streams at once: one more is 503 until a stream closes.""" diff --git a/plugins/planning/surface/tests/ui_c.js b/plugins/planning/surface/tests/ui_c.js index 8a754772136..6e29bc23bcd 100644 --- a/plugins/planning/surface/tests/ui_c.js +++ b/plugins/planning/surface/tests/ui_c.js @@ -619,7 +619,9 @@ async page => { ok("a handle-only apply clears the chip on the open page, no reload", gone && await page.evaluate(() => window.__marker === "same page"), await chip()); // Lease released, no waiter, D1 handled: once the 10 s listen grace ends the bridge reports the session reading (D1 was delivered under 180 s ago), and the header still shows the working state. const rel = await page.request.post(base + "api/lease", {headers: {"Content-Type": "application/json", "X-Interview-Token": await token()}, data: {action: "release"}}); - const reading = await page.waitForFunction(() => document.getElementById("pill").className === "pill working", null, {timeout: 20000, polling: 200}).then(() => true).catch(() => false); + // The pill already reads working from the lease, so wait for the bridge's reading state first. + for (const end = Date.now() + 20000; Date.now() < end && (await state()).listener.state !== "reading";) await page.waitForTimeout(200); + const reading = await page.waitForFunction(() => document.getElementById("pill").className === "pill working", null, {timeout: 5000, polling: 200}).then(() => true).catch(() => false); const pr = await page.evaluate(() => ({text: document.getElementById("pill").textContent, title: document.getElementById("pill").title})); const st = await state(); ok("reading with no lease and no waiter: the header reads Claude is working, not Live or Not listening", rel.ok() && reading && st.listener.state === "reading" && !st.listener.lease && st.listener.waiters === 0 && pr.text === "Claude is working" && /no watcher is waiting/.test(pr.title), JSON.stringify(pr) + " " + JSON.stringify(st.listener));