Skip to content

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

Go

fix(feedback): validate response and pass error kind (#4633)

Ryan Yu03828015cae2
diff --git a/apps/desktop/src/renderer/src/components/route-error-page.test.tsx b/apps/desktop/src/renderer/src/components/route-error-page.test.tsx
index cb231fd1bf..83b58b12ee 100644
--- a/apps/desktop/src/renderer/src/components/route-error-page.test.tsx
+++ b/apps/desktop/src/renderer/src/components/route-error-page.test.tsx
@@ -79,11 +79,12 @@ describe("DesktopRouteErrorPage", () => {
"feedback",
expect.objectContaining({
initialMessage: expect.stringContaining("kind: desktop_route_error"),
+ kind: "bug",
}),
);
});
- it("documents the structured kind/context follow-up debt in the report template", () => {
+ it("documents the structured context follow-up debt in the report template", () => {
const report = formatRouteErrorReport({
error: new Error("bad route"),
url: "app://desktop/acme/issues",
@@ -93,6 +94,6 @@ describe("DesktopRouteErrorPage", () => {
expect(report).toContain("kind: desktop_route_error");
expect(report).toContain("trigger: route-errorElement");
- expect(report).toContain("TODO: promote kind/context to structured feedback fields");
+ expect(report).toContain("TODO: promote error context to structured feedback fields");
});
});
\ No newline at end of file
diff --git a/apps/desktop/src/renderer/src/components/route-error-page.tsx b/apps/desktop/src/renderer/src/components/route-error-page.tsx
index d9bb75b600..ab37076afc 100644
--- a/apps/desktop/src/renderer/src/components/route-error-page.tsx
+++ b/apps/desktop/src/renderer/src/components/route-error-page.tsx
@@ -38,7 +38,7 @@ export function formatRouteErrorReport({
normalized.stack ?? "<no stack>",
"```",
"",
- "TODO: promote kind/context to structured feedback fields once the feedback API supports them.",
+ "TODO: promote error context to structured feedback fields once the feedback API supports them.",
].join("\n");
}
@@ -106,6 +106,7 @@ export function DesktopRouteErrorPage() {
onClick={() =>
useModalStore.getState().open("feedback", {
initialMessage: report,
+ kind: "bug",
})
}
>
diff --git a/packages/core/api/client.test.ts b/packages/core/api/client.test.ts
index cf0f047b43..8d46f62404 100644
--- a/packages/core/api/client.test.ts
+++ b/packages/core/api/client.test.ts
@@ -152,6 +152,59 @@ describe("ApiClient", () => {
expect(headers["X-Client-OS"]).toBeUndefined();
});
+ it("posts feedback kind and parses the response through the schema", async () => {
+ const fetchMock = vi.fn().mockResolvedValue(
+ new Response(JSON.stringify({ id: "feedback-1", created_at: "2026-06-26T00:00:00Z" }), {
+ status: 201,
+ headers: { "Content-Type": "application/json" },
+ }),
+ );
+ vi.stubGlobal("fetch", fetchMock);
+
+ const client = new ApiClient("https://api.example.test");
+ const response = await client.createFeedback({
+ message: "Desktop route crashed",
+ url: "app://desktop/acme/issues",
+ workspace_id: "ws-1",
+ kind: "bug",
+ });
+
+ expect(response).toEqual({
+ id: "feedback-1",
+ created_at: "2026-06-26T00:00:00Z",
+ });
+ expect(fetchMock).toHaveBeenCalledWith(
+ "https://api.example.test/api/feedback",
+ expect.objectContaining({
+ method: "POST",
+ body: JSON.stringify({
+ message: "Desktop route crashed",
+ url: "app://desktop/acme/issues",
+ workspace_id: "ws-1",
+ kind: "bug",
+ }),
+ }),
+ );
+ });
+
+ it("falls back to an empty feedback response when the server shape drifts", async () => {
+ vi.stubGlobal(
+ "fetch",
+ vi.fn().mockResolvedValue(
+ new Response(JSON.stringify({ id: 42, created_at: "2026-06-26T00:00:00Z" }), {
+ status: 201,
+ headers: { "Content-Type": "application/json" },
+ }),
+ ),
+ );
+
+ const client = new ApiClient("https://api.example.test");
+ await expect(client.createFeedback({ message: "hello" })).resolves.toEqual({
+ id: "",
+ created_at: "",
+ });
+ });
+
it("uses the expected HTTP contract for comment trigger preview and suppress", async () => {
const fetchMock = vi.fn()
.mockResolvedValueOnce(
diff --git a/packages/core/api/client.ts b/packages/core/api/client.ts
index d02858c8ae..4cac2ce370 100644
--- a/packages/core/api/client.ts
+++ b/packages/core/api/client.ts
@@ -131,6 +131,7 @@ import type {
CreateBillingPortalSessionResponse,
} from "../types";
import type { OnboardingCompletionPath } from "../onboarding/types";
+import type { CreateFeedbackResponse, FeedbackKind } from "../feedback/types";
import type {
CloudRuntimeNode,
CreateCloudRuntimeNodeRequest,
@@ -211,6 +212,8 @@ import {
EMPTY_BILLING_CHECKOUT_SESSION_STATUS,
EMPTY_CREATE_BILLING_PORTAL_SESSION_RESPONSE,
EMPTY_CANCEL_TASK_RESPONSE,
+ CreateFeedbackResponseSchema,
+ EMPTY_CREATE_FEEDBACK_RESPONSE,
InboxUnreadSummarySchema,
EMPTY_INBOX_UNREAD_SUMMARY,
} from "./schemas";
@@ -616,11 +619,15 @@ export class ApiClient {
message: string;
url?: string;
workspace_id?: string;
- }): Promise<{ id: string; created_at: string }> {
- return this.fetch("/api/feedback", {
+ kind?: FeedbackKind;
+ }): Promise<CreateFeedbackResponse> {
+ const raw = await this.fetch<unknown>("/api/feedback", {
method: "POST",
body: JSON.stringify(data),
});
+ return parseWithFallback(raw, CreateFeedbackResponseSchema, EMPTY_CREATE_FEEDBACK_RESPONSE, {
+ endpoint: "POST /api/feedback",
+ });
}
async updateIssue(id: string, data: UpdateIssueRequest): Promise<Issue> {
diff --git a/packages/core/api/schemas.test.ts b/packages/core/api/schemas.test.ts
index cda1e69025..c7ac0dc932 100644
--- a/packages/core/api/schemas.test.ts
+++ b/packages/core/api/schemas.test.ts
@@ -4,7 +4,9 @@ import {
DashboardAgentRunTimeListSchema,
DashboardUsageByAgentListSchema,
DashboardUsageDailyListSchema,
+ CreateFeedbackResponseSchema,
DuplicateIssueErrorBodySchema,
+ EMPTY_CREATE_FEEDBACK_RESPONSE,
EMPTY_INBOX_UNREAD_SUMMARY,
EMPTY_USER,
InboxUnreadSummarySchema,
@@ -186,6 +188,38 @@ describe("TimelineEntriesSchema", () => {
});
});
+describe("CreateFeedbackResponseSchema", () => {
+ const ENDPOINT = { endpoint: "POST /api/feedback" };
+
+ it("parses a well-formed response and preserves extra fields", () => {
+ const parsed = parseWithFallback(
+ { id: "feedback-1", created_at: "2026-06-26T00:00:00Z", future_field: true },
+ CreateFeedbackResponseSchema,
+ EMPTY_CREATE_FEEDBACK_RESPONSE,
+ ENDPOINT,
+ );
+ expect(parsed).toMatchObject({
+ id: "feedback-1",
+ created_at: "2026-06-26T00:00:00Z",
+ future_field: true,
+ });
+ });
+
+ it("returns the empty fallback for malformed feedback responses", () => {
+ expect(
+ parseWithFallback(
+ { id: 123, created_at: "2026-06-26T00:00:00Z" },
+ CreateFeedbackResponseSchema,
+ EMPTY_CREATE_FEEDBACK_RESPONSE,
+ ENDPOINT,
+ ),
+ ).toBe(EMPTY_CREATE_FEEDBACK_RESPONSE);
+ expect(
+ parseWithFallback(null, CreateFeedbackResponseSchema, EMPTY_CREATE_FEEDBACK_RESPONSE, ENDPOINT),
+ ).toBe(EMPTY_CREATE_FEEDBACK_RESPONSE);
+ });
+});
+
// The duplicate-issue branch in create-issue.tsx feeds ApiError.body
// (typed as `unknown`) through this schema. Any future server drift that
// loses the contract MUST fail the parse so the UI falls back to a normal
diff --git a/packages/core/api/schemas.ts b/packages/core/api/schemas.ts
index 3532adb682..6792626363 100644
--- a/packages/core/api/schemas.ts
+++ b/packages/core/api/schemas.ts
@@ -26,6 +26,7 @@ import type {
WebhookDelivery,
} from "../types";
import type { CloudRuntimeNode } from "../runtimes/cloud-runtime";
+import type { CreateFeedbackResponse } from "../feedback/types";
export interface AppConfigResponse {
cdn_domain: string;
@@ -194,6 +195,16 @@ export const EMPTY_APP_CONFIG: AppConfigResponse = {
workspace_creation_disabled: false,
};
+export const CreateFeedbackResponseSchema = z.object({
+ id: z.string(),
+ created_at: z.string(),
+}).loose();
+
+export const EMPTY_CREATE_FEEDBACK_RESPONSE: CreateFeedbackResponse = {
+ id: "",
+ created_at: "",
+};
+
export const CommentSchema = z.object({
id: z.string(),
issue_id: z.string(),
diff --git a/packages/core/feedback/index.ts b/packages/core/feedback/index.ts
index 105523c16b..2596ba47ac 100644
--- a/packages/core/feedback/index.ts
+++ b/packages/core/feedback/index.ts
@@ -1,2 +1,4 @@
export * from "./mutations";
+export { FEEDBACK_KINDS } from "./types";
+export type { CreateFeedbackResponse, FeedbackKind } from "./types";
export { useFeedbackDraftStore } from "./draft-store";
diff --git a/packages/core/feedback/mutations.ts b/packages/core/feedback/mutations.ts
index 8d23eb0e8c..93e7ad76f6 100644
--- a/packages/core/feedback/mutations.ts
+++ b/packages/core/feedback/mutations.ts
@@ -1,10 +1,12 @@
import { useMutation } from "@tanstack/react-query";
import { api } from "../api";
+import type { FeedbackKind } from "./types";
export interface CreateFeedbackInput {
message: string;
url?: string;
workspace_id?: string;
+ kind?: FeedbackKind;
}
export function useCreateFeedback() {
diff --git a/packages/core/feedback/types.ts b/packages/core/feedback/types.ts
new file mode 100644
index 0000000000..e336ad6576
--- /dev/null
+++ b/packages/core/feedback/types.ts
@@ -0,0 +1,8 @@
+export const FEEDBACK_KINDS = ["bug", "feature", "general", "praise"] as const;
+
+export type FeedbackKind = (typeof FEEDBACK_KINDS)[number];
+
+export interface CreateFeedbackResponse {
+ id: string;
+ created_at: string;
+}
diff --git a/packages/views/modals/feedback.test.tsx b/packages/views/modals/feedback.test.tsx
index 4a46799f80..79b3845ba3 100644
--- a/packages/views/modals/feedback.test.tsx
+++ b/packages/views/modals/feedback.test.tsx
@@ -43,6 +43,7 @@ vi.mock("@multica/core/platform", () => ({
enterKey: "enter",
}));
vi.mock("@multica/core/feedback", () => ({
+ FEEDBACK_KINDS: ["bug", "feature", "general", "praise"] as const,
useCreateFeedback: () => ({ isPending: false, mutateAsync: vi.fn() }),
useFeedbackDraftStore: (selector: any) =>
selector({ draft: { message: storedDraftMessage }, setDraft: vi.fn(), clearDraft: vi.fn() }),
diff --git a/packages/views/modals/feedback.tsx b/packages/views/modals/feedback.tsx
index 091d06f1a3..028cf3954f 100644
--- a/packages/views/modals/feedback.tsx
+++ b/packages/views/modals/feedback.tsx
@@ -16,7 +16,12 @@ import {
useFileDropZone,
FileDropOverlay,
} from "../editor";
-import { useCreateFeedback, useFeedbackDraftStore } from "@multica/core/feedback";
+import {
+ useCreateFeedback,
+ useFeedbackDraftStore,
+ FEEDBACK_KINDS,
+ type FeedbackKind,
+} from "@multica/core/feedback";
import { useCurrentWorkspace } from "@multica/core/paths";
import { useFileUpload } from "@multica/core/hooks/use-file-upload";
import { api } from "@multica/core/api";
@@ -26,6 +31,8 @@ import { formatShortcut, modKey, enterKey } from "@multica/core/platform";
const MAX_MESSAGE_LEN = 10000;
+const FEEDBACK_KIND_SET = new Set<FeedbackKind>(FEEDBACK_KINDS);
+
function composeFeedbackInitialMessage(draftMessage: string, incomingInitialMessage: string) {
const draft = draftMessage.trim();
const incoming = incomingInitialMessage.trim();
@@ -57,6 +64,9 @@ export function FeedbackModal({
const editorRef = useRef<ContentEditorRef>(null);
const incomingInitialMessage =
initialMessage ?? (typeof data?.initialMessage === "string" ? data.initialMessage : "");
+ const kind = typeof data?.kind === "string" && FEEDBACK_KIND_SET.has(data.kind as FeedbackKind)
+ ? (data.kind as FeedbackKind)
+ : undefined;
const seededMessage = composeFeedbackInitialMessage(draft.message, incomingInitialMessage);
const [message, setMessage] = useState(seededMessage);
const { isDragOver, dropZoneProps } = useFileDropZone({
@@ -99,6 +109,7 @@ export function FeedbackModal({
message: latest,
url: typeof window !== "undefined" ? window.location.href : undefined,
workspace_id: workspace?.id,
+ kind,
});
clearDraft();
toast.success(t(($) => $.feedback.toast_sent));