fix(notifications): only run waiting-reply foreground service while a reply is pending (#795)

The chat notification FGS — and its mandatory persistent 'Waiting for
Hermes replies' notification — was started on every ON_STOP of the chat
screen, even when nothing was in flight, and lingered at app startup.

Track a pending-reply flag on HermesWsClient (set when a prompt is
submitted and on any in-flight turn event, cleared on MessageComplete),
gate NotificationHelper.start() on it, and have the service retire
itself after delivering the reply notification in the background.
Replies sent from the notification re-arm the service for the
follow-up turn.

Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
M57andM57 authored and GitHub committed 2026-08-04 16:59:42 +03:00
1 parent 1870b375b1
commit 83ec590ed8
3 files changed
+71 -6

No files matched your search

@@ -92,6 +92,15 @@ open class NotificationReplyReceiver : BroadcastReceiver() {
val repliedNotification = buildReplyNotification(context)
val manager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
manager.notify(ChatNotificationService.PENDING_NOTIFICATION_ID, repliedNotification)
// The follow-up turn is now pending — keep the
// foreground service alive if it retired after the
// previous reply completed, so the next
// MessageComplete still notifies while backgrounded
// (issue #794). No-op when the app is foreground.
if (!NotificationHelper.isAppInForeground()) {
NotificationHelper.start(context)
}
}
}
} catch (e: Exception) {