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:
@@ -1863,3 +1863,25 @@ func decodeChatSession(data []byte) (protocol.ChatSession, error) {
|
||||
}
|
||||
return chatSessionFields(record), nil
|
||||
}
|
||||
|
||||
// ProbeTurn reports whether OpenCode is running a turn for the session, read
|
||||
// from the same /api/session/active list Stream polls. The server uses it once
|
||||
// at start to resume observing turns a previous process left running. A failed
|
||||
// read is an error, never "idle".
|
||||
func (c *Chat) ProbeTurn(ctx context.Context, id string) (bool, error) {
|
||||
if !sessionID.MatchString(id) {
|
||||
return false, fmt.Errorf("invalid OpenCode session id")
|
||||
}
|
||||
data, err := c.call(ctx, "get", "/api/session/active", nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
var response struct {
|
||||
Data *map[string]json.RawMessage `json:"data"`
|
||||
}
|
||||
if err := json.Unmarshal(data, &response); err != nil || response.Data == nil {
|
||||
return false, fmt.Errorf("invalid OpenCode active-session readback")
|
||||
}
|
||||
_, active := (*response.Data)[id]
|
||||
return active, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user