Skip to content
Merged
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
4 changes: 2 additions & 2 deletions frontend/dist/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -31742,10 +31742,10 @@ function gP(e, i, a) {
try {
const A = await vP(e, b.current);
if (!g.current) return !1;
if (A?.status === 401 && a(), A?.ok && A.data?.message_id)
if (A?.status === 401 && a(), A?.ok && typeof A.data?.message_id == "string" && A.data.message_id.length > 0)
return b.current = null, p("idle"), y(null), await C(), !0;
const E = A?.data?.output?.failure_kind;
return A?.status === 0 || A?.status === 503 || E === "outcome_unknown" ? (p("uncertain"), y(null), !1) : (b.current = null, p("error"), A?.status === 409 || E === "conflict" ? y("conflict") : E === "invalid_context" ? y("context") : A?.status === 401 || A?.status === 403 || A?.status === 404 || E === "unavailable" ? (y("unavailable"), (A?.status === 403 || A?.status === 404) && l(null)) : y("failed"), !1);
return !A || A.status === 0 || A.status >= 500 || A.ok || E === "outcome_unknown" ? (p("uncertain"), y(null), !1) : (b.current = null, p("error"), A?.status === 409 || E === "conflict" ? y("conflict") : E === "invalid_context" ? y("context") : A?.status === 401 || A?.status === 403 || A?.status === 404 || E === "unavailable" ? (y("unavailable"), (A?.status === 403 || A?.status === 404) && l(null)) : y("failed"), !1);
} catch {
return g.current && (p("uncertain"), y(null)), !1;
}
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/runtime-v2/state/useWindowCollaboration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,18 @@ export function useWindowCollaboration(client: RuntimeV2Client, windowKey: strin
const response = await postWindowCollaboration(client, pending.current);
if (!alive.current) return false;
if (response?.status === 401) onUnauthorized();
if (response?.ok && response.data?.message_id) {
if (response?.ok && typeof response.data?.message_id === "string" && response.data.message_id.length > 0) {
pending.current = null;
setSendState("idle");
setSendError(null);
await refresh();
return true;
}
const failureKind = response?.data?.output?.failure_kind;
const uncertain = response?.status === 0 || response?.status === 503 || failureKind === "outcome_unknown";
// A gateway error or missing receipt does not prove the write was rejected.
// Retain the exact payload/key so an explicit retry can deduplicate it.
const uncertain = !response || response.status === 0 || response.status >= 500
|| response.ok || failureKind === "outcome_unknown";
if (uncertain) {
setSendState("uncertain");
setSendError(null);
Expand Down
13 changes: 11 additions & 2 deletions frontend/test-v2/window-collaboration.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,20 @@ describe("Window collaboration", () => {
view.unmount();
});

it("retains the exact uncertain payload across retries and context changes", async () => {
it.each([
{ ok: false, status: 0, data: null },
{ ok: false, status: 500, data: null },
{ ok: false, status: 502, data: null },
{ ok: false, status: 503, data: null },
{ ok: false, status: 504, data: null },
{ ok: true, status: 200, data: null },
{ ok: true, status: 200, data: { message_id: 123 } },
null,
])("retains the exact uncertain payload across retries and context changes: %j", async response => {
const writes: unknown[] = [];
const post = vi.fn(async (path: string, payload: unknown) => {
if (path === "window-collaboration") return { ok: true, status: 200, data: transcript };
writes.push(payload); return { ok: false, status: 503, data: null };
writes.push(payload); return response;
});
const client = { post } as unknown as RuntimeV2Client;
const onUnauthorized = vi.fn();
Expand Down
Loading