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:
@@ -701,3 +701,19 @@ func (m *chatManager) TurnRunning(sessionID string) bool {
|
||||
reporter, ok := adapter.(chatTurnReporter)
|
||||
return ok && reporter.TurnRunning(sessionID)
|
||||
}
|
||||
|
||||
// ProbeTurn asks the session's own harness whether a turn is in flight. It is
|
||||
// the server-start probe (chat_unattended.go): a harness that can be asked
|
||||
// (OpenCode, Codex) is asked; otherwise its in-memory state is used, which for
|
||||
// Claude Code (a child of this server) is empty after a restart.
|
||||
func (m *chatManager) ProbeTurn(ctx context.Context, sessionID string) (bool, error) {
|
||||
adapter, err := m.brokerFor(ctx, sessionID)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if prober, ok := adapter.(chatTurnProber); ok {
|
||||
return prober.ProbeTurn(ctx, sessionID)
|
||||
}
|
||||
reporter, ok := adapter.(chatTurnReporter)
|
||||
return ok && reporter.TurnRunning(sessionID), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user