fix(chat): isolate pending flows and cancel stale requests

This commit is contained in:
2026-07-17 19:22:01 +08:00
parent 2fc312b5c7
commit 8bb1e21886
27 changed files with 501 additions and 92 deletions
+20
View File
@@ -0,0 +1,20 @@
import { describe, expect, it } from "vitest";
import { isAbortError } from "@/utils/abort";
import { Result } from "@/utils/result";
describe("isAbortError", () => {
it("recognizes cancellation after Result normalizes the error", async () => {
const result = await Result.wrap(async () => {
throw new DOMException("This operation was aborted", "AbortError");
});
expect(Result.isErr(result) && isAbortError(result.error)).toBe(true);
});
it("does not treat request timeouts as actor cancellation", () => {
expect(isAbortError(new DOMException("Timed out", "TimeoutError"))).toBe(
false,
);
});
});
+6
View File
@@ -0,0 +1,6 @@
export function isAbortError(error: unknown): boolean {
if (!(error instanceof Error)) return false;
if (error.name === "AbortError") return true;
const cause = error.cause;
return cause !== error && isAbortError(cause);
}