@devries-cameron20 / t3code-1 / commits / 52df13ea93
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(mobile): preserve notification responses when navigation fails (#22084)

Co-authored-by: GPT-6.1 Sol <noreply@openai.com>

Victor Vogel committed Oct 31, 2026 at 03:40 UTC 52df13ea93718dc2c47dea708e9409d4865ac280
2 files changed +58 -4
apps/mobile/src/features/agent-awareness/notificationNavigation.test.ts
+50
@@ -105,6 +105,56 @@ describe("extractAgentNotificationDeepLink", () => {
105 });
106
107 describe("routeAgentNotificationResponseOnce", () => {
108 + it("retries a failed initial response and deduplicates it after navigation succeeds", async () => {
109 + vi.spyOn(console, "error").mockImplementation(() => undefined);
110 + const response = responseWithData({ deepLink: "/threads/env/thread" }) as NotificationResponse;
111 + const handledResponseIds = new Set<string>();
112 + const navigate = vi.fn().mockImplementationOnce(() => {
113 + throw new Error("navigation not ready");
114 + });
115 + const clearLastResponse = vi.fn(() => Promise.resolve());
116 + const consume = () =>
117 + consumeLastAgentNotificationResponse({
118 + getLastResponse: () => Promise.resolve(response),
119 + clearLastResponse,
120 + handleResponse: (response) =>
121 + routeAgentNotificationResponseOnce({ handledResponseIds, response, navigate }),
122 + });
123 +
124 + await consume();
125 + expect(handledResponseIds.size).toBe(0);
126 + expect(clearLastResponse).not.toHaveBeenCalled();
127 +
128 + await consume();
129 + expect(navigate).toHaveBeenCalledTimes(2);
130 + expect(navigate).toHaveBeenLastCalledWith("/threads/env/thread");
131 + expect(clearLastResponse).toHaveBeenCalledOnce();
132 +
133 + routeAgentNotificationResponseOnce({ handledResponseIds, response, navigate });
134 + expect(navigate).toHaveBeenCalledTimes(2);
135 + });
136 +
137 + it("discards malformed destination ids without leaving the response pending", async () => {
138 + const response = responseWithData({
139 + environmentId: "env",
140 + threadId: "\ud800",
141 + }) as NotificationResponse;
142 + const handledResponseIds = new Set<string>();
143 + const navigate = vi.fn();
144 + const clearLastResponse = vi.fn(() => Promise.resolve());
145 +
146 + await consumeLastAgentNotificationResponse({
147 + getLastResponse: () => Promise.resolve(response),
148 + clearLastResponse,
149 + handleResponse: (response) =>
150 + routeAgentNotificationResponseOnce({ handledResponseIds, response, navigate }),
151 + });
152 +
153 + expect(navigate).not.toHaveBeenCalled();
154 + expect(clearLastResponse).toHaveBeenCalledOnce();
155 + expect(handledResponseIds.has("notification-1")).toBe(true);
156 + });
157 +
158 it("does not navigate twice when the initial and listener responses refer to one notification", () => {
159 const handledResponseIds = new Set<string>();
160 const navigations: Array<string> = [];
apps/mobile/src/features/agent-awareness/notificationPayload.ts
+8 -4
@@ -41,7 +41,11 @@ function encodeThreadDeepLink(input: {
41 if (input.environmentId.length === 0 || input.threadId.length === 0) {
42 return null;
43 }
44 - return `/threads/${encodeURIComponent(input.environmentId)}/${encodeURIComponent(input.threadId)}`;
44 + try {
45 + return `/threads/${encodeURIComponent(input.environmentId)}/${encodeURIComponent(input.threadId)}`;
46 + } catch {
47 + return null;
48 + }
49 }
50
51 function normalizeThreadDeepLink(value: string): string | null {
@@ -104,11 +108,11 @@ export function routeAgentNotificationResponseOnce(input: {
108 if (responseId && input.handledResponseIds.has(responseId)) {
109 return;
110 }
107 - if (responseId) {
108 - input.handledResponseIds.add(responseId);
109 - }
111 const deepLink = extractAgentNotificationDeepLink(input.response);
112 if (deepLink) {
113 input.navigate(deepLink);
114 }
115 + if (responseId) {
116 + input.handledResponseIds.add(responseId);
117 + }
118 }