Skip to content

Commit c6047c2

Browse files
committed
fix(mobile): return failure when title generation fails
1 parent 72e2532 commit c6047c2

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎apps/mobile/src/features/home/useThreadListActions.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ProviderInstanceId,
88
RunId,
99
ThreadId,
10+
type ThreadTitleRegenerationOutcome,
1011
} from "@t3tools/contracts";
1112
import * as Cause from "effect/Cause";
1213
import { AsyncResult } from "effect/reactivity";
@@ -18,6 +19,7 @@ const state = vi.hoisted(() => ({
1819
dropBusy: false,
1920
holdingRows: false,
2021
failedAction: null as string | null,
22+
titleOutcome: null as ThreadTitleRegenerationOutcome | null,
2123
archivedRefreshes: [] as string[],
2224
scopes: new Map<string, Set<string>>(),
2325
shells: [] as EnvironmentThreadShell[],
@@ -156,7 +158,7 @@ vi.mock("../../state/threads", () => ({
156158
if (action === state.failedAction)
157159
return AsyncResult.failure(Cause.fail(new Error("Server rejected action")));
158160
state.afterRequest?.();
159-
return AsyncResult.success(undefined);
161+
return AsyncResult.success(action === "regenerateTitle" ? state.titleOutcome : undefined);
160162
},
161163
]),
162164
),
@@ -193,6 +195,7 @@ const mutationCases = [
193195
beforeEach(() => {
194196
state.connectedEnvironmentIds = [primaryEnvironmentId, otherEnvironmentId];
195197
state.failedAction = null;
198+
state.titleOutcome = null;
196199
state.archivedRefreshes = [];
197200
state.pendingOrder = null;
198201
state.dropBusy = false;
@@ -215,6 +218,16 @@ afterEach(() => {
215218
vi.unstubAllEnvs();
216219
});
217220

221+
it("reports a failed title generation as unsuccessful and allows another request", async () => {
222+
const actions = useThreadListActions();
223+
const thread = makeThread();
224+
state.titleOutcome = { status: "failed", message: "Model unavailable" };
225+
expect(await actions.regenerateThreadTitle(thread)).toBe(false);
226+
227+
state.titleOutcome = { status: "renamed" };
228+
expect(await actions.regenerateThreadTitle(thread)).toBe(true);
229+
});
230+
218231
describe("thread list operation permissions", () => {
219232
it.each(mutationCases)(
220233
"%s rejects a retained callback after its environment loses permission",

‎apps/mobile/src/features/home/useThreadListActions.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ export function useThreadListActions(): {
551551
"Could not regenerate title",
552552
result.value.message ?? "The thread title could not be regenerated.",
553553
);
554+
return false;
554555
} else if (result.value?.status === "unchanged") {
555556
Dialog.alert("Title kept", "The current title already fits this thread.");
556557
}

0 commit comments

Comments
 (0)