fix: preserve delivery failures across channel boundaries

This commit is contained in:
chengyongru authored and chengyongru committed 2026-11-09 11:41:57 +08:00
1 parent f62dfe0ee8
commit d789e1bfc7
10 files changed
+616 -68

No files matched your search

+16 -8
View File
@@ -100,6 +100,7 @@ export function UpdateFlowProvider({ client, token, enabled, canSettleHandoff =
};
const refresh = async (manual = false) => {
const feedback = manual ? new Promise(resolve => setTimeout(resolve, 600)) : Promise.resolve();
let readingReview = false;
try {
// API tokens belong to a gateway process. Let the client's authenticated
// reconnect replace them before reading the new process's update journal.
@@ -116,9 +117,11 @@ export function UpdateFlowProvider({ client, token, enabled, canSettleHandoff =
setRecovery(next.recovery_command);
try { sessionStorage.setItem(RECOVERY_KEY, JSON.stringify({ id: next.id, command: next.recovery_command, automatic: next.automatic_recovery === true })); } catch { /* Still available until reload. */ }
}
setOffline(false);
setDelayed(false);
missingSince = 0;
if (next.recorded_phase !== "ready" || next.execution_confirmation_id) {
setOffline(false);
setDelayed(false);
missingSince = 0;
}
setError("");
if (next.recorded_phase === "ready" && approved.current === next.id) {
await execute(next.id);
@@ -129,10 +132,14 @@ export function UpdateFlowProvider({ client, token, enabled, canSettleHandoff =
&& !(next.service_restored && next.running_version !== next.previous_version)) return;
// A refresh can recover files already staged, but not installation consent.
if (next.recorded_phase === "ready" && !next.execution_confirmation_id) {
try {
const restored = await readUpdateReview(token, next.id);
if (active) setReview(restored);
} catch { if (active) setError(t("updates.reviewFailed")); }
readingReview = true;
const restored = await readUpdateReview(token, next.id);
if (active) {
setReview(restored);
setOffline(false);
setDelayed(false);
missingSince = 0;
}
}
} catch (reason) {
if (!active) return;
@@ -142,9 +149,10 @@ export function UpdateFlowProvider({ client, token, enabled, canSettleHandoff =
approved.current = null;
setOffline(false);
setDelayed(false);
setError(t("updates.statusFailed"));
setError(t(readingReview ? "updates.reviewFailed" : "updates.statusFailed"));
return;
}
if (readingReview) setError(t("updates.reviewFailed"));
reconnecting();
} finally {
if (manual) {
+44
View File
@@ -370,6 +370,50 @@ describe("Real update consent and recovery", () => {
fireEvent.click(screen.getByRole("button", { name: "Update & restart" }));
await waitFor(() => expect(api.executeUpdate).toHaveBeenCalledOnce());
});
it("stops polling a forbidden restored review and allows a manual retry", async () => {
vi.useFakeTimers();
sessionStorage.setItem("nanobot.pending-update.v1", id);
vi.mocked(api.readUpdateReview).mockRejectedValueOnce(new api.ApiError(403, "Forbidden"));
render(view());
await act(async () => {});
expect(screen.getByText(/Could not verify this update/)).toBeVisible();
await act(async () => { await vi.advanceTimersByTimeAsync(4500); });
expect(api.readUpdateReview).toHaveBeenCalledTimes(1);
expect(api.readUpdateJob).toHaveBeenCalledTimes(1);
fireEvent.click(screen.getByRole("button", { name: "Check again" }));
await act(async () => { await vi.advanceTimersByTimeAsync(600); });
expect(api.readUpdateReview).toHaveBeenCalledTimes(2);
expect(screen.getByRole("button", { name: "Update & restart" })).toBeEnabled();
expect(api.executeUpdate).not.toHaveBeenCalled();
});
it("retries a transient restored review failure and recovers without consent", async () => {
vi.useFakeTimers();
sessionStorage.setItem("nanobot.pending-update.v1", id);
vi.mocked(api.readUpdateReview).mockRejectedValueOnce(new Error("offline"));
render(view());
await act(async () => {});
expect(api.readUpdateReview).toHaveBeenCalledTimes(1);
await act(async () => { await vi.advanceTimersByTimeAsync(1500); });
expect(api.readUpdateReview).toHaveBeenCalledTimes(2);
expect(screen.getByRole("button", { name: "Update & restart" })).toBeEnabled();
expect(api.executeUpdate).not.toHaveBeenCalled();
});
it("offers a manual check and delayed recovery after repeated review failures", async () => {
vi.useFakeTimers();
sessionStorage.setItem("nanobot.pending-update.v1", id);
sessionStorage.setItem("nanobot.pending-update-recovery.v1", JSON.stringify({ id, command: "recover safely" }));
vi.mocked(api.readUpdateReview).mockRejectedValue(new Error("offline"));
render(view());
await act(async () => {});
expect(screen.getByRole("button", { name: "Check again" })).toBeEnabled();
await act(async () => { await vi.advanceTimersByTimeAsync(123_000); });
expect(screen.getByDisplayValue("recover safely")).toBeVisible();
vi.mocked(api.readUpdateReview).mockResolvedValue(review);
fireEvent.click(screen.getByRole("button", { name: "Check again" }));
await act(async () => { await vi.advanceTimersByTimeAsync(600); });
expect(screen.getByRole("button", { name: "Update & restart" })).toBeEnabled();
expect(api.executeUpdate).not.toHaveBeenCalled();
});
it("waits for the restored review before enabling confirmation", async () => {
sessionStorage.setItem("nanobot.pending-update.v1", id);
let resolveReview!: (value: api.UpdateReviewResponse) => void;