From 8ebfdb0e0f064f41e3c23edb55afe3cdae36ddef Mon Sep 17 00:00:00 2001 From: Daniel Pittman <7246312+daniel-pittman@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:28:16 -0700 Subject: [PATCH] Board: moving a session that is not running no longer crashes, and the move shows Pressing m on a session known only from its status file (not running, so it has no live record, and its row sits on Needs you) and choosing a group crashed the app: the move looked up the session's working folder and session id in the live records with a plain index, which raised KeyError. The move now reads the live record, else the Needs-you row's record, so it rewrites the same pins a live move wrote, by name and by session id. Without either, it pins the session by name and its folder gives no group (Other). Such a session also stayed under Other after the move: the board's group map held only sessions with a live row, so the overrides were never consulted for it. Sessions with no live row now fall back to the overrides, matched by name and by the session id the Needs-you row carries. That row now takes the session id from the status file when the record has none, since a pin written while the session ran is keyed by it. Co-Authored-By: Claude Opus 5.5 --- fleetwatch/app.py | 12 +++++++++--- fleetwatch/data.py | 5 ++++- fleetwatch/views.py | 10 +++++++--- tests/test_gone_rows.py | 43 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/fleetwatch/app.py b/fleetwatch/app.py index 93fdb04..730ccf6 100644 --- a/fleetwatch/app.py +++ b/fleetwatch/app.py @@ -185,7 +185,8 @@ def derive(self, holds): self.helpers.setdefault(data.clean(r["name"]), r) self.grouping = views.Grouping( {x["name"]: self.groups.of(x["name"], x["r"]["cwd"], x["r"]["sessionId"]) for x in self.view["rows"]}, - self.groups.names()) + self.groups.names(), fallback=lambda name: self.groups.of( + name, (self.gone.get(name) or {}).get("cwd"), (self.gone.get(name) or {}).get("sessionId"))) bad = len(index_health.problem_rows(self.indexes.rows, now)) self.header = views.header_text(self.view, self.counts, now, self.warnings, False, bad, len(self.watches)) self.header_mid = views.header_text(self.view, self.counts, now, self.warnings, False, bad, @@ -1482,13 +1483,18 @@ def action_regroup(self): names = snap.groups.names() current = snap.grouping.of(name) + # A session that is not running has no live record; its Needs-you row + # carries the folder and session id when its status file names them, so + # the move updates the same pins a live move wrote. With neither, the + # session is pinned by name alone and its paths give no group (Other). + rec = snap.records.get(name) or snap.gone.get(name) or {} + def chosen(group): if group is None: return try: config.set_override(config.groups_path(), name, group, - snap.groups.by_path(snap.records[name]["cwd"]), - snap.records[name]["sessionId"]) + snap.groups.by_path(rec.get("cwd")), rec.get("sessionId")) except (OSError, ValueError) as exc: self.say("could not save the group: %s" % (data.clean(exc)[:70] or type(exc).__name__)) return diff --git a/fleetwatch/data.py b/fleetwatch/data.py index 0d47b8b..e893bbe 100644 --- a/fleetwatch/data.py +++ b/fleetwatch/data.py @@ -571,9 +571,12 @@ def gone_row(r, name, now): """A Needs-you row for a session with no live row, so its due items stay visible.""" sf = r["status"] or {} upd = to_epoch(sf.get("updated")) + # A file-only record carries no session id; the status file names it, and a + # group pin written while the session ran is keyed by it. + sid = r.get("sessionId") or (sf.get("sessionId") if isinstance(sf.get("sessionId"), str) else None) return { "r": {"name": r["name"], "status": None, "children": [], "live": False, "state": "gone", - "cwd": r.get("cwd"), "sessionId": r.get("sessionId"), "last": r.get("last")}, + "cwd": r.get("cwd"), "sessionId": sid, "last": r.get("last")}, "name": name, "persona": clean(sf["persona"]) if sf.get("persona") else None, "stuck": None, "helper_stuck": [], "qs": [], "working": False, "busy_helpers": 0, "quiet": None, "updated": upd if upd is not None else r.get("last"), "renamed_from": None, diff --git a/fleetwatch/views.py b/fleetwatch/views.py index b1160fd..221c2ab 100644 --- a/fleetwatch/views.py +++ b/fleetwatch/views.py @@ -59,11 +59,15 @@ def sort_label(tab, current): class Grouping: """Which group each top-level session is in, and the order groups are shown.""" - def __init__(self, by_name, order): - self.by_name, self.order = dict(by_name), list(order) + def __init__(self, by_name, order, fallback=None): + self.by_name, self.order, self.fallback = dict(by_name), list(order), fallback def of(self, name): - return self.by_name.get(name, OTHER) + # A session with no live row (only a status file) has no folder to match; + # `fallback` still applies the overrides pinned to its name. + if name in self.by_name: + return self.by_name[name] + return self.fallback(name) if self.fallback else OTHER def present(self, names): seen = {self.of(n) for n in names} diff --git a/tests/test_gone_rows.py b/tests/test_gone_rows.py index c25d29f..4b05254 100644 --- a/tests/test_gone_rows.py +++ b/tests/test_gone_rows.py @@ -85,6 +85,49 @@ async def body(app, pilot): self.assertEqual(len(calls), 1) self.assertIn("resume %s --here" % s, calls[0][0]) + def test_m_moves_a_session_that_is_not_running(self): + # Its only row is on Needs you and it has no live record. The move updates + # the pins a live move wrote (by name and by session id), the grouped board + # shows it in the chosen group, and moving it back to Other removes both. + from fleetwatch import config + s, _ = self.transcript("Gone Session") + self.gone(sessionId=s) + path = config.groups_path() + config.load_groups() # writes the default file + config.set_override(path, "Gone Session", "Work", session_id=s) # a pin from when it ran + + async def body(app, pilot): + await pilot.press("G") + await pilot.pause(0.1) + app.current.move_to("needs:Gone Session") + self.assertNotIn("Gone Session", app.snapshot.records) + await pilot.press("m") + await pilot.pause(0.2) + self.assertEqual(type(app.screen).__name__, "GroupPicker") + picker = app.screen.query_one("#choices") + picker.highlighted = app.screen.names.index("Personal") + await pilot.press("enter") + await self.settle(pilot, lambda: "moved Gone Session to Personal" in (app.status_text or "")) + groups, _w = config.load_groups(create=False) + self.assertEqual(groups.overrides.get("Gone Session"), "Personal") + self.assertEqual(groups.override_ids.get(s), "Personal") + await self.settle(pilot, lambda: app.snapshot.grouping.of("Gone Session") == "Personal") + await self.settle(pilot, lambda: "needs:Gone Session" in app.current._order) + order = app.current._order + heads = [k for k in order[:order.index("needs:Gone Session")] if k.startswith("grp:")] + self.assertTrue(heads and heads[-1].endswith(":Personal"), heads) + app.current.move_to("needs:Gone Session") + await pilot.press("m") + await pilot.pause(0.2) + picker = app.screen.query_one("#choices") + picker.highlighted = app.screen.names.index("Other") + await pilot.press("enter") + await self.settle(pilot, lambda: "moved Gone Session to Other" in (app.status_text or "")) + groups, _w = config.load_groups(create=False) + self.assertNotIn("Gone Session", groups.overrides) + self.assertNotIn(s, groups.override_ids) + self.drive_needs(body) + def test_escape_calls_nothing(self): s, _ = self.transcript("Gone Session") self.gone(sessionId=s)