Chat list: spinner and background-task badge from server activity on every row

The list applies chat_activity pushes and each row's activity by seq, so
every listed chat shows a running turn, not only the chat open here. An
idle chat with running background tasks wears a quiet badge with tooltip and
semantics "Background tasks running (N)". Older servers keep the old
behaviour. List rows that never changed carry the server's current seq so
they order after snapshots kept from an earlier server process.
This commit is contained in:
2026-11-03 19:53:52 +00:00
parent 1b98877d88
commit 45c933c176
9 changed files with 560 additions and 73 deletions
+11 -2
View File
@@ -81,7 +81,10 @@ func (h *chatHub) nextActivitySeqLocked() int64 {
}
// activitySnapshot returns the current summary of each session in ids, each
// with the sequence of its last recorded change (0 when it never changed).
// with the sequence of its last recorded change. A session that has not
// changed since this server started carries the current sequence instead, so
// it still orders after anything a client kept from a previous server process
// and before any later push.
func (h *chatHub) activitySnapshot(ids []string) map[string]protocol.ChatActivity {
out := make(map[string]protocol.ChatActivity, len(ids))
if h == nil {
@@ -89,9 +92,15 @@ func (h *chatHub) activitySnapshot(ids []string) map[string]protocol.ChatActivit
}
h.mu.Lock()
defer h.mu.Unlock()
if h.activitySeq == 0 {
h.activitySeq = time.Now().UnixMicro()
}
for _, id := range ids {
activity := h.chatActivityLocked(id)
activity.Seq = h.activity[id].Seq
activity.Seq = h.activitySeq
if recorded, ok := h.activity[id]; ok {
activity.Seq = recorded.Seq
}
out[id] = activity
}
return out
+6 -3
View File
@@ -65,13 +65,16 @@ func TestChatActivityReachesEveryConnection(t *testing.T) {
viewer := dialChatConn(t, server.ctx, server.srv)
list := dialChatConn(t, server.ctx, server.srv)
if got := listActivity(t, server.ctx, list); got == nil || got.TurnRunning || got.BackgroundTasks != 0 {
t.Fatalf("idle row activity = %+v, want an empty summary", got)
// A session that never changed still carries a sequence (this server's
// current one), so it orders after anything kept from an earlier process.
initial := listActivity(t, server.ctx, list)
if initial == nil || initial.TurnRunning || initial.BackgroundTasks != 0 || initial.Seq == 0 {
t.Fatalf("idle row activity = %+v, want an empty summary with a sequence", initial)
}
sendPrompt(t, server.ctx, viewer, "p1", "build it", "op-1")
started := readActivity(t, server.ctx, list)
if started.SessionID != "ses_1" || !started.TurnRunning || started.BackgroundTasks != 0 || started.Seq == 0 {
if started.SessionID != "ses_1" || !started.TurnRunning || started.BackgroundTasks != 0 || started.Seq <= initial.Seq {
t.Fatalf("turn start push = %+v", started)
}
broker.push(stepFrameFor(protocol.ChatStepStarted, "turn_1"))