Skip to content

Commit 434df33

Browse files
fix(mobile): a new task rescans its project's models after reconnecting
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ba64f05 commit 434df33

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎apps/mobile/src/features/threads/use-project-models-refresh.test.tsx‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ afterEach(() => {
5959
});
6060

6161
describe("useProjectModelsRefresh", () => {
62-
it("asks again after a failed request once the environment reconnects", async () => {
62+
it("asks again whenever the environment reconnects", async () => {
6363
harness.respond = () => AsyncResult.failure(Cause.fail(new Error("socket closed")));
6464
await render({ ...project, connected: true });
6565
await render({ ...project, connected: false });
@@ -69,8 +69,13 @@ describe("useProjectModelsRefresh", () => {
6969
await render({ ...project, connected: true });
7070
expect(harness.calls).toHaveLength(2);
7171

72-
await render({ ...project, connected: false });
7372
await render({ ...project, connected: true });
7473
expect(harness.calls).toHaveLength(2);
74+
75+
// A restarted server has dropped the project's catalog, so a successful
76+
// request does not outlive the connection.
77+
await render({ ...project, connected: false });
78+
await render({ ...project, connected: true });
79+
expect(harness.calls).toHaveLength(3);
7580
});
7681
});

‎apps/mobile/src/features/threads/use-project-models-refresh.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { useAtomCommand } from "../../state/use-atom-command";
88
/**
99
* The composer scans its project once a thread exists; a new task needs the
1010
* project's catalog before that. Each project is requested once per
11-
* environment, since the server reuses scans inside its TTL. A failed request
12-
* is forgotten, so the next connection asks again.
11+
* connection: the server reuses scans inside its TTL, but a restarted server
12+
* has none. A failed request is forgotten, so a later render asks again.
1313
*/
1414
export function useProjectModelsRefresh(input: {
1515
readonly environmentId: EnvironmentId | null;
@@ -23,7 +23,11 @@ export function useProjectModelsRefresh(input: {
2323
});
2424
const requestedKeyRef = useRef<string | null>(null);
2525
useEffect(() => {
26-
if (!connected || !environmentId || !cwd || !instanceId) return;
26+
if (!connected) {
27+
requestedKeyRef.current = null;
28+
return;
29+
}
30+
if (!environmentId || !cwd || !instanceId) return;
2731
const key = JSON.stringify([environmentId, cwd]);
2832
if (requestedKeyRef.current === key) return;
2933
requestedKeyRef.current = key;

0 commit comments

Comments
 (0)