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: 7 additions & 0 deletions .changes/planning/fix-surface-header-live-waiter-5c2e91a7.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 6 additions & 2 deletions plugins/planning/surface/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,7 @@ def user_settings(self):

def signature(self):
user = self.user_settings()
listener = self.listener()
return (
mtime(self.questions),
mtime(self.responses),
Expand All @@ -1043,8 +1044,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):
Expand Down
22 changes: 22 additions & 0 deletions plugins/planning/surface/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
4 changes: 3 additions & 1 deletion plugins/planning/surface/tests/ui_c.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,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));
Expand Down
Loading