Repository navigation
fix(server): deliver Claude push notifications through T3 #26137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
watashiwaaniket
wants to merge
20
commits into
pingdotgg:main
Choose a base branch
from
watashiwaaniket:fix/claude-push-notifications
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,416
−84
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a5430a7
fix(server): deliver Claude push notifications through T3
watashiwaaniket f48fe54
fix(server): keep Claude alerts on one shared path
watashiwaaniket 8d52d31
fix(server): deliver Claude alerts on the instance clients read
watashiwaaniket d79bc68
fix(server): keep a successful Claude push result
watashiwaaniket 244dbde
Merge remote-tracking branch 'github/main' into maria/pr-26137
maria-rcks 970166e
fix(server): confirm Claude phone alert acceptance
maria-rcks ef10b14
fix(server): describe rejected Claude alerts accurately
maria-rcks 5cdf998
fix(web): initialize Claude alert settings after the runtime
maria-rcks 71ce4bf
Merge remote-tracking branch 'github/main' into maria/pr-26137
maria-rcks 29d4fdd
fix(relay): align Claude alerts with delivery contracts
maria-rcks 5ae550d
chore: merge main into Claude notification fix
maria-rcks ae959b9
fix(web): keep Claude alert delivery on available channels
maria-rcks 442f6e4
fix: preserve notification behavior after main merge
maria-rcks 6a67537
fix(web): serialize Claude alert subscriptions
maria-rcks 88accbe
Merge remote-tracking branch 'upstream/main' into fix/claude-push-not…
watashiwaaniket 3fecd3a
fix(server): keep Claude push hooks beside device subagent hooks
watashiwaaniket e5ef9b2
Merge remote-tracking branch 'github/main' into takeover/26137
maria-rcks 9912d82
fix(relay): adapt alert signature verification to current main
maria-rcks 7b3fad8
fix(server): provide relay signing service
maria-rcks a770fcf
Merge remote-tracking branch 'github/main' into fix/claude-push-notif…
maria-rcks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { describe, expect, it } from "@effect/vitest"; | ||
| import { type AgentAlert, ThreadId } from "@t3tools/contracts"; | ||
| import * as Deferred from "effect/Deferred"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Queue from "effect/Queue"; | ||
| import * as Stream from "effect/Stream"; | ||
|
|
||
| import * as AgentAlerts from "./AgentAlerts.ts"; | ||
|
|
||
| const alert = { | ||
| threadId: ThreadId.make("thread-1"), | ||
| body: "fleet.lock stuck", | ||
| } satisfies AgentAlert; | ||
|
|
||
| describe("AgentAlerts", () => { | ||
| it.effect("reports no channel when nobody is listening", () => | ||
| Effect.gen(function* () { | ||
| const alerts = yield* AgentAlerts.AgentAlerts; | ||
| expect(yield* alerts.offer(alert)).toEqual({ local: false, phone: false }); | ||
| yield* alerts.registerPhone({ | ||
| publish: () => Effect.succeed(false), | ||
| }); | ||
| expect(yield* alerts.offer(alert)).toEqual({ local: false, phone: false }); | ||
| }).pipe(Effect.provide(AgentAlerts.layer)), | ||
| ); | ||
|
|
||
| it.effect("delivers to a connected client and a registered phone", () => | ||
| Effect.gen(function* () { | ||
| const alerts = yield* AgentAlerts.AgentAlerts; | ||
| const received = yield* Queue.unbounded<AgentAlert>(); | ||
| const published = yield* Deferred.make<AgentAlert>(); | ||
| yield* alerts.stream.pipe( | ||
| Stream.runForEach((item) => Queue.offer(received, item)), | ||
| Effect.forkScoped({ startImmediately: true }), | ||
| ); | ||
| yield* alerts.registerPhone({ | ||
| publish: (item) => Deferred.succeed(published, item).pipe(Effect.as(true)), | ||
| }); | ||
| expect(yield* alerts.offer(alert)).toEqual({ local: true, phone: true }); | ||
| expect(yield* Queue.take(received)).toEqual(alert); | ||
| yield* alerts.registerPhone({ publish: () => Effect.die("relay unavailable") }); | ||
| expect(yield* alerts.offer(alert)).toEqual({ local: true, phone: false }); | ||
| expect(yield* Queue.take(received)).toEqual(alert); | ||
| expect(yield* Deferred.await(published)).toEqual(alert); | ||
| }).pipe(Effect.provide(AgentAlerts.layer), Effect.scoped), | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import type { AgentAlert } from "@t3tools/contracts"; | ||
| import * as Context from "effect/Context"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Layer from "effect/Layer"; | ||
| import * as PubSub from "effect/PubSub"; | ||
| import * as Ref from "effect/Ref"; | ||
| import * as Stream from "effect/Stream"; | ||
|
|
||
| import type { ClaudePushChannels } from "../orchestration-v2/Adapters/claudePushNotification.ts"; | ||
|
|
||
| export interface AgentAlertPhoneDelivery { | ||
| readonly publish: (alert: AgentAlert) => Effect.Effect<boolean>; | ||
| } | ||
|
|
||
| export class AgentAlerts extends Context.Service< | ||
| AgentAlerts, | ||
| { | ||
| readonly offer: (alert: AgentAlert) => Effect.Effect<ClaudePushChannels>; | ||
| readonly stream: Stream.Stream<AgentAlert>; | ||
| readonly registerPhone: (delivery: AgentAlertPhoneDelivery) => Effect.Effect<void>; | ||
| } | ||
| >()("t3/notifications/AgentAlerts") {} | ||
|
|
||
| const make = Effect.gen(function* () { | ||
| const subscribers = yield* Ref.make(0); | ||
| const alerts = yield* PubSub.unbounded<AgentAlert>(); | ||
| const phone = yield* Ref.make<AgentAlertPhoneDelivery | null>(null); | ||
|
|
||
| const stream = Stream.unwrap( | ||
| Effect.gen(function* () { | ||
| // Subscribe first. Counting before the subscription exists tells Claude the | ||
| // alert was sent in a window where publish has nobody to deliver to. | ||
| const subscription = yield* PubSub.subscribe(alerts); | ||
| yield* Ref.update(subscribers, (count) => count + 1); | ||
| yield* Effect.addFinalizer(() => | ||
| Ref.update(subscribers, (count) => (count > 0 ? count - 1 : 0)), | ||
| ); | ||
| return Stream.fromSubscription(subscription); | ||
| }), | ||
| ); | ||
|
|
||
| const offer: AgentAlerts["Service"]["offer"] = Effect.fn("AgentAlerts.offer")(function* (alert) { | ||
| const delivery = yield* Ref.get(phone); | ||
| const local = (yield* Ref.get(subscribers)) > 0; | ||
| if (local) yield* PubSub.publish(alerts, alert); | ||
| const phoneAccepted = | ||
| delivery === null | ||
| ? false | ||
| : yield* delivery | ||
| .publish(alert) | ||
| .pipe( | ||
| Effect.catchCause((cause) => | ||
| Effect.logWarning("agent alert phone delivery failed", { cause }).pipe( | ||
| Effect.as(false), | ||
| ), | ||
| ), | ||
| ); | ||
| return { local, phone: phoneAccepted }; | ||
| }); | ||
|
|
||
| return AgentAlerts.of({ | ||
| offer, | ||
| stream, | ||
| registerPhone: Effect.fn("AgentAlerts.registerPhone")((delivery) => Ref.set(phone, delivery)), | ||
| }); | ||
| }); | ||
|
|
||
| export const layer = Layer.effect(AgentAlerts, make); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
apps/server/src/orchestration-v2/Adapters/claudePushNotification.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| import { describe, it } from "@effect/vitest"; | ||
| import * as NodeAssert from "node:assert/strict"; | ||
|
|
||
| import { | ||
| claudePushNotificationHooks, | ||
| claudePushNotificationOutput, | ||
| readClaudePushNotificationMessage, | ||
| } from "./claudePushNotification.ts"; | ||
|
|
||
| describe("claudePushNotification", () => { | ||
| it("keeps a one-line message and caps it at 200 characters", () => { | ||
| NodeAssert.equal( | ||
| readClaudePushNotificationMessage({ message: " fleet.lock stuck " }), | ||
| "fleet.lock stuck", | ||
| ); | ||
| NodeAssert.equal(readClaudePushNotificationMessage({ message: "line\n\nbreak" }), "line break"); | ||
| NodeAssert.equal(readClaudePushNotificationMessage({ message: " " }), null); | ||
| NodeAssert.equal(readClaudePushNotificationMessage({}), null); | ||
| const long = "x".repeat(240); | ||
| const read = readClaudePushNotificationMessage({ message: long }); | ||
| NodeAssert.equal(read?.length, 200); | ||
| NodeAssert.equal(read?.endsWith("…"), true); | ||
| }); | ||
|
|
||
| it("does not tell the agent the terminal is active when T3 cannot deliver", () => { | ||
| NodeAssert.deepEqual( | ||
| claudePushNotificationOutput({ channels: { local: false, phone: false } }), | ||
| { | ||
| hookSpecificOutput: { | ||
| hookEventName: "PostToolUse", | ||
| updatedToolOutput: { | ||
| message: "Not sent. No T3 client or phone accepted the notification.", | ||
| pushSent: false, | ||
| localSent: false, | ||
| disabledReason: "no_transport", | ||
| }, | ||
| }, | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| it("rewrites a user_present result when a T3 channel can deliver", async () => { | ||
| const hooks = claudePushNotificationHooks({ | ||
| offer: async () => ({ local: true, phone: false }), | ||
| }); | ||
| const hook = hooks.PostToolUse[0]?.hooks[0]; | ||
| NodeAssert.ok(hook); | ||
| const result = await hook( | ||
| { | ||
| hook_event_name: "PostToolUse", | ||
| tool_name: "PushNotification", | ||
| tool_input: { message: "fleet.lock stuck", status: "proactive" }, | ||
| tool_response: { | ||
| message: "Not sent — this terminal is active.", | ||
| pushSent: false, | ||
| localSent: false, | ||
| disabledReason: "user_present", | ||
| }, | ||
| tool_use_id: "tool-1", | ||
| session_id: "session-1", | ||
| transcript_path: "", | ||
| cwd: "/workspace", | ||
| }, | ||
| "tool-1", | ||
| { signal: new AbortController().signal }, | ||
| ); | ||
| NodeAssert.deepEqual(result, { | ||
| hookSpecificOutput: { | ||
| hookEventName: "PostToolUse", | ||
| updatedToolOutput: { | ||
| message: "Sent through T3.", | ||
| pushSent: false, | ||
| localSent: true, | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it("leaves a push Claude already resolved unchanged", async () => { | ||
| const offered: Array<string> = []; | ||
| const hooks = claudePushNotificationHooks({ | ||
| offer: async (message) => { | ||
| offered.push(message); | ||
| return { local: true, phone: true }; | ||
| }, | ||
| }); | ||
| const hook = hooks.PostToolUse[0]?.hooks[0]; | ||
| NodeAssert.ok(hook); | ||
| const call = (toolResponse: unknown) => | ||
| hook( | ||
| { | ||
| hook_event_name: "PostToolUse", | ||
| tool_name: "PushNotification", | ||
| tool_input: { message: "fleet.lock stuck", status: "proactive" }, | ||
| tool_response: toolResponse, | ||
| tool_use_id: "tool-1", | ||
| session_id: "session-1", | ||
| transcript_path: "", | ||
| cwd: "/workspace", | ||
| }, | ||
| "tool-1", | ||
| { signal: new AbortController().signal }, | ||
| ); | ||
| for (const toolResponse of [ | ||
| { message: "Sent", pushSent: true, localSent: true }, | ||
| { message: "Notifications are off.", pushSent: false, disabledReason: "config_off" }, | ||
| { message: "No push transport.", pushSent: false, disabledReason: "no_transport" }, | ||
| ]) { | ||
| NodeAssert.deepEqual(await call(toolResponse), {}); | ||
| } | ||
| NodeAssert.deepEqual(offered, []); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.