Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions gui/src/components/use-main-device-reauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ export function useMainDeviceReauth(apiBase: string, onCompleted: () => void) {
const dto = await res.json().catch(() => ({})) as FlowDto;
if (!isCurrent() || flowRef.current !== flowId) return;
if (!res.ok) {
if (res.status === 404 && dto.code === "unknown_flow") {
stopPolling();
flowRef.current = null;
setState({ phase: "failed", code: "request_failed" });
return;
}
// Ownership continues from the Cancel click, including while DELETE
// is unresolved. Never offer a replacement POST during that window,
// and keep the existing poll cadence so a later terminal status remains observable.
Expand Down
11 changes: 11 additions & 0 deletions gui/tests/main-device-reauth-ownership.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,17 @@ for (const failure of ["network", "http", "nonterminal"] as const) {
});
}

test("unknown flow status stops polling after a failed cancellation", async () => {
await mount();
await beginFlow("A");
await invoke(() => hook.cancel());
await reply(take("DELETE", "A"), { code: "unavailable" }, 503);
await act(async () => { for (const wake of sleepers.splice(0)) wake(); });
await reply(take("GET", "A"), { code: "unknown_flow" }, 404);
expect(hook.state).toEqual({ phase: "failed", code: "request_failed" });
expect(sleepers).toHaveLength(0);
});

test("two successful cancellation replies complete the same flow only once", async () => {
await mount();
await beginFlow("A");
Expand Down
Loading