fix(diagnostics): deep-review round 2 — a send that claims, not one that blocks

The send no longer holds the session's row lock while it talks to the tracker:
it claims the session, gives the lock back, and checkpoints each step. A Stop
is never held behind a send, while a draft, a screenshot or a second send are
refused at once instead of queueing. The claim ages out, so a request that
died mid-send does not strand the session.

What the composer says is what happened: an attachment that went is no longer
named as one that did not (the missing body edit is its own line), and the
issue's screenshot count comes from the server when the list cannot be read,
so a failed read no longer blocks saving the draft. The zip is fetched as a
request, so its pace is a message and not a saved error page. Screenshots of a
finished report can be removed again; only one still being sent is held.

A recording's log elevation can no longer outlive it. The step prompt keeps
the keyboard (the page's keys stay quiet) and traps Tab itself. An image
pasted into a dialog opened over the composer stays that dialog's.
This commit is contained in:
2026-09-20 00:51:12 +02:00
parent 134ec9a68e
commit 3f983e6d76
17 changed files with 347 additions and 126 deletions
+38 -33
View File
@@ -128,10 +128,10 @@ function ComposerBody({
queryKey: qk.debugScreenshots(session.id),
queryFn: () => api.debugScreenshots(session.id),
});
// Until the screenshots are known, the body cannot say how many there are: nothing is saved or
// sent from it before then (a failed read must not become "no screenshots" in the issue).
const shotsReady = shotsQ.data !== undefined;
const shots = shotsQ.data?.items ?? [];
// How many the ISSUE will carry. From the list while it is loaded, else from the session itself
// (the server's own count) — a failed read must not quietly become "no screenshots".
const shotCount = shotsQ.data ? shots.length : session.screenshots;
const excluded = useMemo(() => new Set(form.excluded), [form.excluded]);
const kept = (source: Source) =>
@@ -155,7 +155,7 @@ function ComposerBody({
const body = renderIssue(
form,
env,
{ client: kept("web"), server: kept("server"), screenshots: shots.length },
{ client: kept("web"), server: kept("server"), screenshots: shotCount },
text,
);
@@ -213,14 +213,14 @@ function ComposerBody({
const saveRef = useRef(save.mutate);
saveRef.current = save.mutate;
useEffect(() => {
if (locked || !unsaved || !shotsReady) return;
if (locked || !unsaved) return;
const timer = window.setTimeout(() => saveRef.current(), SAVE_DELAY_MS);
return () => window.clearTimeout(timer);
}, [body, form.title, locked, unsaved, shotsReady]);
}, [body, form.title, locked, unsaved]);
// Closed before the typing paused: save what is still waiting, now.
const flushRef = useRef(() => {});
flushRef.current = () => {
if (unsaved && !locked && shotsReady) save.mutate();
if (unsaved && !locked) save.mutate();
};
useEffect(() => () => flushRef.current(), []);
@@ -233,10 +233,14 @@ function ComposerBody({
});
const addRef = useRef(addShot.mutate);
addRef.current = addShot.mutate;
const root = useRef<HTMLDivElement>(null);
useEffect(() => {
if (locked) return;
// Only an image paste is taken over: text pasted into the title or a step goes where it was typed.
// And only OUR dialog's: something opened over the composer (the command palette) keeps its own.
const onPaste = (e: ClipboardEvent) => {
const dialog = e.target instanceof Element ? e.target.closest('[aria-modal="true"]') : null;
if (dialog && !dialog.contains(root.current)) return;
const images = [...(e.clipboardData?.files ?? [])].filter(isImage);
if (!images.length) return;
e.preventDefault();
@@ -248,19 +252,21 @@ function ComposerBody({
const [mode, setMode] = useState<"edit" | "preview">("edit");
// The export is built from the SAVED draft: save what is on screen first.
const exportZip = async () => {
if (!sent) {
try {
await save.mutateAsync();
} catch {
return; // the save's own message says why
}
}
const a = document.createElement("a");
a.href = api.debugExportUrl(session.id);
a.download = "";
a.click();
};
const exportZip = useMutation({
mutationFn: async () => {
if (!sent) await save.mutateAsync();
return api.debugExport(session.id);
},
meta: { failTitle: "recorder.composer.exportFailed" },
onSuccess: ({ blob, name }) => {
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = name;
a.click();
URL.revokeObjectURL(url);
},
});
const started = new Date(session.started_at);
const minutes = Math.max(
@@ -271,7 +277,7 @@ function ComposerBody({
);
return (
<div className="flex flex-col gap-4">
<div ref={root} className="flex flex-col gap-4">
<p className="text-sm text-muted">
{t("recorder.composer.meta", {
start: started.toLocaleString(i18n.language),
@@ -279,9 +285,13 @@ function ComposerBody({
level: t(`settings.diagnostics.levels.${session.level}`),
})}
</p>
{sent && pending.length > 0 && (
{sent && (pending.length > 0 || session.images_pending) && (
<div className="flex flex-wrap items-center justify-between gap-2 rounded-xl border border-warn/40 bg-warn/10 px-3 py-2 text-sm">
<span>{t("recorder.composer.partial", { files: pending.join(", ") })}</span>
<span>
{pending.length > 0
? t("recorder.composer.partial", { files: pending.join(", ") })
: t("recorder.composer.partialImages")}
</span>
<Button
variant="outline"
size="sm"
@@ -384,19 +394,14 @@ function ComposerBody({
</Button>
<Button
variant="outline"
loading={save.isPending}
disabled={!shotsReady || send.isPending}
onClick={() => void exportZip()}
loading={save.isPending || exportZip.isPending}
disabled={send.isPending}
onClick={() => exportZip.mutate()}
>
{t("recorder.composer.export")}
</Button>
{target && !sent && (
<Button
variant="primary"
loading={send.isPending}
disabled={!shotsReady}
onClick={() => send.mutate()}
>
<Button variant="primary" loading={send.isPending} onClick={() => send.mutate()}>
{t("recorder.composer.send")}
</Button>
)}
@@ -647,7 +652,7 @@ function Attachments({
)}
</div>
))}
{!readOnly && shotsQ.data && (
{!readOnly && (
<div
onDragOver={(e) => e.preventDefault()}
onDrop={onDrop}