Notify: an agent's notify reaches every connected app

The notify tool now records a chat_notify app notification with its own
id per call (no dedupe of repeated words) and the tool's priority, so
every subscribed client gets it and a reconnecting client replays it.
ntfy delivery is unchanged; the tool result names where it went.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-12-02 15:44:39 +00:00
parent 3e817a189b
commit c8541f29b7
11 changed files with 195 additions and 47 deletions
+23 -5
View File
@@ -33,9 +33,9 @@ func newChatToolFixture(t *testing.T) *chatToolFixture {
f.hub.shown = store
f.service = newChatToolService(store, store, f.hub, store)
f.service.home = func() (string, error) { return f.home, nil }
f.service.notify = func(_ context.Context, sessionID, title, message string) (bool, string) {
f.notified = append(f.notified, sessionID+": "+title)
return true, ""
f.service.notify = func(_ context.Context, sessionID string, notice chatToolNotice) chatToolDelivery {
f.notified = append(f.notified, sessionID+": "+notice.Title)
return chatToolDelivery{App: true, Phone: true}
}
return f
}
@@ -229,7 +229,8 @@ func TestNotifyIsRateLimitedPerChat(t *testing.T) {
now := time.Unix(1_800_000_000, 0)
f.service.now = func() time.Time { return now }
for i := range 5 {
if r := f.call(a, "notify", `{"title":"Done","message":"Build finished","priority":"high"}`); r.IsError {
if r := f.call(a, "notify", `{"title":"Done","message":"Build finished","priority":"high"}`); r.IsError ||
r.Text != "Delivered to the operator's Pipelines apps and phone notifications." {
t.Fatalf("notification %d: %v", i, r)
}
}
@@ -254,7 +255,9 @@ func TestNotifyIsRateLimitedPerChat(t *testing.T) {
t.Fatalf("items = %+v", got)
}
f.service.notify = func(context.Context, string, string, string) (bool, string) { return false, "ntfy is not configured" }
f.service.notify = func(context.Context, string, chatToolNotice) chatToolDelivery {
return chatToolDelivery{Detail: "ntfy is not configured"}
}
r := f.call(b, "notify", `{"title":"Fails","message":"x"}`)
if !r.IsError || !strings.Contains(r.Text, "ntfy is not configured") {
t.Fatalf("an undelivered notification is reported: %v", r)
@@ -262,6 +265,21 @@ func TestNotifyIsRateLimitedPerChat(t *testing.T) {
if last := f.items(t, "ses_n2"); len(last) != 2 || last[1].Delivered || last[1].Detail != "ntfy is not configured" {
t.Fatalf("the undelivered entry is recorded: %+v", last)
}
// Apps only (ntfy off): the agent is told where it went.
f.service.notify = func(_ context.Context, _ string, notice chatToolNotice) chatToolDelivery {
if !strings.HasPrefix(notice.ID, "shown_") || notice.Priority != "low" {
t.Errorf("notice = %+v", notice)
}
return chatToolDelivery{App: true, Detail: "phone notifications (ntfy) are turned off"}
}
r = f.call(b, "notify", `{"title":"Apps","message":"x","priority":"low"}`)
if r.IsError || r.Text != "Delivered to the operator's Pipelines apps; phone notifications (ntfy) are turned off." {
t.Fatalf("apps-only result: %v", r)
}
if last := f.items(t, "ses_n2"); len(last) != 3 || !last[2].Delivered || !strings.HasPrefix(last[2].ID, "shown_") {
t.Fatalf("the apps-only entry is recorded: %+v", last)
}
}
func TestInstanceTokenCallsNeedOneMatchingRunningToolCall(t *testing.T) {