Keep observing chats with an in-flight turn after the last client leaves

Chat attention notifications (questions, approvals, finished replies) come
from a session's event stream, which the hub only read while a room existed;
detach destroyed the room when the last client left, so a turn that finished
or asked with the app closed notified nobody.

A room whose last client leaves now stays observing, unattended, while its
turn is in flight or it holds an unanswered question/approval, and is torn
down when the turn ends (or after 6h for a stuck turn); at most 16 such rooms.
At server start, recently used open sessions whose harness reports a running
turn (OpenCode /api/session/active, Codex thread/turns/list) are observed
again so their reply still notifies. Settings, dedupe and app_notifications
recording are unchanged.
This commit is contained in:
2026-11-02 16:07:42 +00:00
parent 467f3eafa7
commit 80022ea41a
13 changed files with 820 additions and 25 deletions
+4 -1
View File
@@ -58,6 +58,9 @@ type chatHub struct {
// operation ids, so a client retry is acknowledged instead of re-sent.
recentOps map[string]struct{}
recentOpOrder []string
// unattended holds the unattended-observation timings (chat_unattended.go),
// fixed when the hub is built.
unattended chatUnattendedTimings
}
// chatPart is the retained form of one part. Text and reasoning deltas append to
@@ -121,7 +124,7 @@ type chatResolution struct {
}
func newChatHub() *chatHub {
return &chatHub{turns: map[string]*chatTurn{}, rooms: map[string]*chatRoom{}, baseCtx: context.Background(), now: time.Now}
return &chatHub{turns: map[string]*chatTurn{}, rooms: map[string]*chatRoom{}, baseCtx: context.Background(), now: time.Now, unattended: currentChatUnattendedTimings()}
}
// nextUserMessageID mints a stable id for one echoed user turn.