Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

refactor(mobile): single localized send-failure message, tested per locale (MUL-9761) (#11107)

Jiayuan Zhang20f560e11a76
diff --git a/apps/mobile/app/(app)/[workspace]/(tabs)/chat.tsx b/apps/mobile/app/(app)/[workspace]/(tabs)/chat.tsx
index be20778762..0b89ac48a0 100644
--- a/apps/mobile/app/(app)/[workspace]/(tabs)/chat.tsx
+++ b/apps/mobile/app/(app)/[workspace]/(tabs)/chat.tsx
@@ -85,9 +85,7 @@ import {
} from "@/data/realtime/chat-ws-updaters";
import { useWorkspaceAgentAvailability } from "@/lib/workspace-agent-availability";
import { queuedChatMessages } from "@/lib/chat-queued-messages";
-import {
- dispatchReasonCode,
-} from "@/lib/dispatch-reason";
+import { sendFailureMessage } from "@/lib/dispatch-reason";
import { useT } from "@/lib/i18n";
import { useAgentPresence } from "@/lib/use-agent-presence";
import { Header } from "@/components/ui/header";
@@ -105,20 +103,6 @@ import { isAgentRuntimeBound } from "@/lib/is-agent-runtime-bound";
export default function ChatTab() {
const qc = useQueryClient();
const { t } = useT("chat");
- const sendFailureMessage = useCallback((err: unknown) => {
- switch (dispatchReasonCode(err)) {
- case "invocation_not_allowed":
- return t("failure.invocation_not_allowed");
- case "agent_runtime_required":
- return t("failure.agent_runtime_required");
- case "runtime_access_denied":
- return t("failure.runtime_access_denied", {
- detail: t("failure.runtime_access_recovery"),
- });
- default:
- return t("failure.default");
- }
- }, [t]);
const wsId = useWorkspaceStore((s) => s.currentWorkspaceId);
const wsSlug = useWorkspaceStore((s) => s.currentWorkspaceSlug);
const userId = useAuthStore((s) => s.user?.id);
@@ -328,7 +312,7 @@ export default function ChatTab() {
// Session create runs the same invoke gate as a send, so a permission
// change refuses here too — and this is the only layer that sees the
// reason code (MUL-6380).
- Alert.alert(t("alerts.not_sent"), sendFailureMessage(err));
+ Alert.alert(t("alerts.not_sent"), sendFailureMessage(err, t));
throw err;
}
if (!sessionId) return;
@@ -401,7 +385,7 @@ export default function ChatTab() {
// The composer restores the draft on a thrown rejection but says nothing
// about it, so a revoked-permission 403 used to read as a silent no-op
// (MUL-6380). Name the cause here: only this layer sees the error body.
- Alert.alert(t("alerts.not_sent"), sendFailureMessage(err));
+ Alert.alert(t("alerts.not_sent"), sendFailureMessage(err, t));
throw err;
}
},
@@ -413,7 +397,6 @@ export default function ChatTab() {
runtimeBound,
ensureSession,
qc,
- sendFailureMessage,
t,
promoteNewDraft,
clearDraft,
diff --git a/apps/mobile/lib/dispatch-reason.test.ts b/apps/mobile/lib/dispatch-reason.test.ts
index 895659c0f8..8c014dcd2a 100644
--- a/apps/mobile/lib/dispatch-reason.test.ts
+++ b/apps/mobile/lib/dispatch-reason.test.ts
@@ -1,6 +1,8 @@
// @vitest-environment node
import { describe, expect, it } from "vitest";
import { dispatchReasonCode, sendFailureMessage } from "./dispatch-reason";
+import { i18n } from "./i18n/singleton";
+import type { SupportedLocale } from "./i18n/types";
// Shaped like `apps/mobile/data/api.ts:ApiError` — a thrown Error carrying the
// parsed response body. Built inline rather than imported because `@/data/api`
@@ -31,34 +33,48 @@ describe("dispatchReasonCode", () => {
});
describe("sendFailureMessage", () => {
+ const send = (locale: SupportedLocale, err: unknown) =>
+ sendFailureMessage(err, i18n.getFixedT(locale, "chat"));
+
// The point of the helper: a revoked permission must not read as a transient
// failure the user should retry (MUL-6380).
it("names revoked permission instead of suggesting a retry", () => {
- const message = sendFailureMessage(
- apiError({ reason_code: "invocation_not_allowed" }),
+ const err = apiError({ reason_code: "invocation_not_allowed" });
+ expect(send("en", err)).toBe(
+ "You no longer have permission to run this agent, so the message was not sent.",
);
- expect(message).toMatch(/no longer have permission/i);
- expect(message).not.toMatch(/try again/i);
+ expect(send("zh-Hans", err)).toBe("你已无权运行该智能体,消息未发送。");
+ expect(send("zh-Hant", err)).toBe("你已無權執行該 AI 代理,訊息未傳送。");
});
it("names the runtime for agent_runtime_required", () => {
- expect(
- sendFailureMessage(apiError({ reason_code: "agent_runtime_required" })),
- ).toMatch(/runtime/i);
+ const err = apiError({ reason_code: "agent_runtime_required" });
+ expect(send("en", err)).toBe(
+ "Bind a runtime to this agent before sending a message.",
+ );
+ expect(send("zh-Hans", err)).toBe("发送消息前,请先为该智能体绑定运行时。");
+ expect(send("zh-Hant", err)).toBe("傳送訊息前,請先為該 AI 代理繫結執行時。");
});
// PUCK-89: a private-runtime owner mismatch never resolves by retrying. The
// message must name the real fixes instead of the generic retry advice.
it("gives runtime_access_denied actionable copy, not a retry", () => {
- const message = sendFailureMessage(
- apiError({ reason_code: "runtime_access_denied" }),
+ const err = apiError({ reason_code: "runtime_access_denied" });
+ expect(send("en", err)).toBe(
+ "Message not sent — This agent can't run on its private runtime. Make the runtime public, or rebind/copy the agent to a runtime its owner can use.",
+ );
+ expect(send("zh-Hans", err)).toBe(
+ "消息未发送:该智能体无法在其私有运行时上运行。请将该运行时设为公开,或将智能体重新绑定/复制到其所有者可用的运行时。",
+ );
+ expect(send("zh-Hant", err)).toBe(
+ "訊息未傳送:該 AI 代理無法在其私有執行時上執行。請將該執行時設為公開,或將 AI 代理重新繫結/複製到其所有者可用的執行時。",
);
- expect(message).toMatch(/private runtime/i);
- expect(message).toMatch(/public|rebind/i);
- expect(message).not.toMatch(/try again/i);
});
it("falls back to a retryable message for anything else", () => {
- expect(sendFailureMessage(new Error("timeout"))).toMatch(/try again/i);
+ const err = new Error("timeout");
+ expect(send("en", err)).toBe("Your message could not be sent. Please try again.");
+ expect(send("zh-Hans", err)).toBe("消息无法发送,请重试。");
+ expect(send("zh-Hant", err)).toBe("訊息無法傳送,請重試。");
});
});
diff --git a/apps/mobile/lib/dispatch-reason.ts b/apps/mobile/lib/dispatch-reason.ts
index 267d6b789c..0f974bca0d 100644
--- a/apps/mobile/lib/dispatch-reason.ts
+++ b/apps/mobile/lib/dispatch-reason.ts
@@ -1,5 +1,3 @@
-import { RUNTIME_ACCESS_DENIED_RECOVERY_COPY } from "./runtime-access-copy";
-
/**
* Mobile-owned mirror of `packages/core/api/client.ts:dispatchReasonCode`.
*
@@ -19,23 +17,29 @@ export function dispatchReasonCode(err: unknown): string | undefined {
}
/**
- * User-facing sentence for a refused send. `invocation_not_allowed` is the
- * revoked-permission case (MUL-4525): the session was created while the user
- * could run the agent and the server now refuses, so it must not read as a
- * transient failure the user should retry.
+ * User-facing sentence for a refused send, from the `chat` namespace's
+ * `failure.*` keys. `invocation_not_allowed` is the revoked-permission case
+ * (MUL-4525): the session was created while the user could run the agent and
+ * the server now refuses, so it must not read as a transient failure the user
+ * should retry.
*/
-export function sendFailureMessage(err: unknown): string {
+export function sendFailureMessage(
+ err: unknown,
+ t: (key: string, options?: Record<string, unknown>) => string,
+): string {
switch (dispatchReasonCode(err)) {
case "invocation_not_allowed":
- return "You no longer have permission to run this agent, so the message was not sent.";
+ return t("failure.invocation_not_allowed");
case "agent_runtime_required":
- return "Bind a runtime to this agent before sending a message.";
+ return t("failure.agent_runtime_required");
case "runtime_access_denied":
// The agent's owner cannot execute it on the selected private runtime.
// Retrying never fixes this — the fix is making that runtime public or
// rebinding/copying the agent to a runtime its owner can use.
- return `Message not sent — ${RUNTIME_ACCESS_DENIED_RECOVERY_COPY}`;
+ return t("failure.runtime_access_denied", {
+ detail: t("failure.runtime_access_recovery"),
+ });
default:
- return "Your message could not be sent. Please try again.";
+ return t("failure.default");
}
}
diff --git a/apps/mobile/lib/runtime-access-copy.ts b/apps/mobile/lib/runtime-access-copy.ts
deleted file mode 100644
index d74e646c9d..0000000000
--- a/apps/mobile/lib/runtime-access-copy.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-// Shared copy for the persisted and admission-time runtime ownership failure.
-// Keep this in one mobile-owned module because mobile cannot import the web
-// locale bundles.
-export const RUNTIME_ACCESS_DENIED_RECOVERY_COPY =
- "This agent can't run on its private runtime. Make the runtime public, or rebind/copy the agent to a runtime its owner can use.";