The best way to control Claude Code, Codex and more from any computer or phone
fix(composer): bound long path search requests on web and mobile (#30714)
Co-authored-by: maria-rcks <maria@kuuro.net>
Johan Vaz committed
Nov 9, 2026 at 22:35 UTC
cddfc8db210b7abd05083e401c11fc5038a9d53f
4 files changed
+57
-11
apps/mobile/src/state/queries.debounce.test.tsx
+21
-7
@@ -75,19 +75,28 @@ const target = {
75
query: "src",
76
};
77
78
-it("keeps the original search deadline when rerenders have equivalent targets", () => {
78
+it.each([
79
+ { query: "src", expected: "src" },
80
+ { query: "a".repeat(256), expected: "a".repeat(256) },
81
+ {
82
+ query: ["a".repeat(86), "b".repeat(86), "c".repeat(86), "unique.ts"].join("/"),
83
+ expected: ["a".repeat(86), "b".repeat(86), "c".repeat(82)].join("/"),
84
+ },
85
+ { query: `${"a".repeat(255)}😀/boundary.ts`, expected: "a".repeat(255) },
86
+ { query: `${"a".repeat(254)}😀/boundary.ts`, expected: `${"a".repeat(254)}😀` },
87
+])("keeps the search deadline and bounds the request for query: $query", ({ query, expected }) => {
88
using harness = setup();
89
harness.render({ ...target, query: null });
81
- harness.render({ ...target, query: " src " });
90
+ harness.render({ ...target, query: ` ${query} ` });
91
act(() => vi.advanceTimersByTime(100));
83
- harness.render(target);
92
+ harness.render({ ...target, query });
93
act(() => vi.advanceTimersByTime(99));
94
expect(mocks.searchEntries).not.toHaveBeenCalled();
95
96
act(() => vi.advanceTimersByTime(1));
97
expect(mocks.searchEntries).toHaveBeenCalledExactlyOnceWith({
98
environmentId: target.environmentId,
90
- input: { cwd: target.cwd, query: target.query, limit: 20 },
99
+ input: { cwd: target.cwd, query: expected, limit: 20 },
100
});
101
});
102
@@ -95,10 +104,15 @@ it.each([
104
{ field: "environment", changed: { ...target, environmentId: EnvironmentId.make("other") } },
105
{ field: "project directory", changed: { ...target, cwd: "/other" } },
106
{ field: "query", changed: { ...target, query: "test" } },
98
-])("restarts the search deadline when the $field changes", ({ changed }) => {
107
+ {
108
+ field: "query suffix beyond the request limit",
109
+ initial: { ...target, query: `${"src/".repeat(65)}first.ts` },
110
+ changed: { ...target, query: `${"src/".repeat(65)}other.ts` },
111
+ },
112
+])("restarts the search deadline when the $field changes", ({ initial = target, changed }) => {
113
using harness = setup();
114
harness.render({ ...target, query: null });
101
- harness.render(target);
115
+ harness.render(initial);
116
act(() => vi.advanceTimersByTime(100));
117
harness.render(changed);
118
@@ -110,7 +124,7 @@ it.each([
124
act(() => vi.advanceTimersByTime(1));
125
expect(mocks.searchEntries).toHaveBeenCalledExactlyOnceWith({
126
environmentId: changed.environmentId,
113
- input: { cwd: changed.cwd, query: changed.query, limit: 20 },
127
+ input: { cwd: changed.cwd, query: changed.query.slice(0, 256), limit: 20 },
128
});
129
});
130
apps/mobile/src/state/queries.ts
+1
-1
@@ -417,7 +417,7 @@ export function useComposerPathSearch(target: ComposerPathSearchTarget) {
417
environmentId: debouncedTarget.environmentId,
418
input: {
419
cwd: debouncedTarget.cwd,
420
- query: debouncedTarget.query,
420
+ query: debouncedTarget.query.slice(0, 256).replace(/[\uD800-\uDBFF]$/, ""),
421
limit: COMPOSER_PATH_SEARCH_LIMIT,
422
},
423
}
apps/web/src/state/queries.filesystem.test.ts
+34
-2
@@ -8,6 +8,7 @@ const state = vi.hoisted(() => ({
8
phase: "connected" as "connected" | "offline",
9
sessionAtom: {},
10
searchAtom: {},
11
+ searchRequests: vi.fn(),
12
contentAtom: {},
13
contentRequests: vi.fn(),
14
contentError: null as string | null,
@@ -34,7 +35,12 @@ vi.mock("./presentation", () => ({
35
}),
36
}));
37
vi.mock("./projects", () => ({
37
- projectEnvironment: { searchEntries: () => state.searchAtom },
38
+ projectEnvironment: {
39
+ searchEntries: (target: unknown) => {
40
+ state.searchRequests(target);
41
+ return state.searchAtom;
42
+ },
43
+ },
44
projectContentSearch: (target: unknown) => {
45
state.contentRequests(target);
46
return state.contentAtom;
@@ -67,7 +73,7 @@ vi.mock("./query", () => ({
73
}),
74
}));
75
70
-import { useProjectContentSearch } from "./queries";
76
+import { useComposerPathSearch, useProjectContentSearch } from "./queries";
77
78
const target = {
79
environmentId: EnvironmentId.make("test-environment"),
@@ -80,6 +86,7 @@ beforeEach(() => {
86
state.sessionError = null;
87
state.sessionWaiting = false;
88
state.phase = "connected";
89
+ state.searchRequests.mockClear();
90
state.contentRequests.mockClear();
91
state.contentError = null;
92
});
@@ -92,6 +99,31 @@ const contentTarget = {
99
useRegex: false,
100
};
101
102
+it.each([
103
+ { query: "src", expected: "src" },
104
+ { query: "a".repeat(256), expected: "a".repeat(256) },
105
+ {
106
+ query: ["a".repeat(86), "b".repeat(86), "c".repeat(86), "unique.ts"].join("/"),
107
+ expected: ["a".repeat(86), "b".repeat(86), "c".repeat(82)].join("/"),
108
+ },
109
+ { query: `${"a".repeat(255)}😀/boundary.ts`, expected: "a".repeat(255) },
110
+ { query: `${"a".repeat(254)}😀/boundary.ts`, expected: `${"a".repeat(254)}😀` },
111
+])(
112
+ "bounds the path search request while preserving query identity: $query",
113
+ ({ query, expected }) => {
114
+ state.session = { authenticated: true, scopes: [AuthFilesystemReadScope] };
115
+ const result = useComposerPathSearch({ ...target, query: ` ${query} ` });
116
+
117
+ expect(state.searchRequests).toHaveBeenCalledExactlyOnceWith({
118
+ environmentId: target.environmentId,
119
+ input: { cwd: target.cwd, query: expected, limit: 80 },
120
+ });
121
+ expect(result.searchedTarget).toMatchObject({ ...target, query });
122
+ expect(result.searchedQuery).toBe(query);
123
+ expect(result.isPending).toBe(false);
124
+ },
125
+);
126
+
127
it("shows content-search denial before typing and never issues an unauthorized request", () => {
128
state.session = { authenticated: true, scopes: [] };
129
for (const query of ["", contentTarget.query]) {
apps/web/src/state/queries.ts
+1
-1
@@ -313,7 +313,7 @@ export function useProjectPathSearch(
313
environmentId: debouncedTarget.environmentId,
314
input: {
315
cwd: debouncedTarget.cwd,
316
- query: debouncedTarget.query,
316
+ query: debouncedTarget.query.slice(0, 256).replace(/[\uD800-\uDBFF]$/, ""),
317
limit,
318
...(debouncedTarget.kind ? { kind: debouncedTarget.kind } : {}),
319
...(debouncedTarget.imageOnly ? { imageOnly: true } : {}),