Files
alan 1b98877d88 Chat list activity: turn running and background tasks on every row, pushed to every connection
chat_sessions rows carry activity (turn_running, background_tasks, seq) from
the hub's own state, and chat_activity is pushed to every connection when a
session's turn starts or ends or its running background-task count changes.
A room whose last viewer left stays observed while background tasks run,
bounded by the unattended limits; a Claude Code process exit ends its tasks.
2026-11-03 19:45:43 +00:00

33 lines
897 B
Go

package server
import (
"context"
"encoding/json"
"github.com/coder/websocket"
"github.com/coder/websocket/wsjson"
"git.a-wan.net/alan/pipelines/internal/protocol"
)
// readTestFrame reads the next websocket frame into v like wsjson.Read, but
// skips chat_activity pushes. Those reach every connection whenever any
// chat's turn or background-task count changes, so tests that read one
// connection's replies in order would otherwise see them interleaved. Tests of
// chat_activity itself read the raw stream.
func readTestFrame(ctx context.Context, conn *websocket.Conn, v any) error {
for {
var raw json.RawMessage
if err := wsjson.Read(ctx, conn, &raw); err != nil {
return err
}
var head struct {
Type string `json:"type"`
}
if json.Unmarshal(raw, &head) == nil && head.Type == protocol.ChatActivityChanged {
continue
}
return json.Unmarshal(raw, v)
}
}