Skip to content

Commit a9a4151

Browse files
radroidclaude
authored andcommitted
fix(web): keep the queue's reorder controls usable, and leave a dispatch trail (#35)
Two defects found by an adversarial review of the previous two commits, both introduced by them, both reproduced in Chromium before being fixed. Twenty candidate findings were raised; eighteen were refuted on inspection. 1. Tapping Edit could delete the message. Every `Button` carries a `pointer-coarse:after:min-w-11` invisible 44px hit area that is NOT pointer-events-none, so the four adjacent icon buttons overlapped on touch: the right third of Edit hit-tested to Remove. Measured on the shipped stylesheet — Edit's visible box spans x=[52,76] but only [42,68) resolves to Edit, and a probe 3px inside its right edge returns "Remove queued message". Fixed with `*:pointer-coarse:after:min-w-auto`, the same antidote the `Group` primitive applies to adjacent buttons, plus a wider gap on coarse pointers so the now-exact targets stay apart. Minimum height is left alone; nothing is adjacent vertically. 2. Every reorder click destroyed keyboard focus. `busy` flips synchronously — React commits the sync lane in a microtask queued before the mutation's — so `disabled={busy || !canMoveUp}` disabled the very button the user had just activated, and a disabled element loses focus to <body>. That is worse than it sounds: the action cluster is only revealed on `:focus-within`, so it also vanished, and the next move required tabbing from the top of the document. `busy` is now guarded inside the handler instead of on the control, matching upstream's own reorder buttons in `ProviderModelsSection.tsx:311`, and focus is explicitly restored after the move commits — falling back to the opposite arrow when the pressed one has reached the end of its travel. Both fixes are behavioural, not cosmetic, and neither is covered by a unit test because both live in DOM focus and hit-testing behaviour that jsdom does not model. They were verified by direct browser reproduction instead. Also adds the diagnostics the review showed were missing. A reorder that failed rejected unhandled, so a click that quietly did nothing left no trace; it now warns. And each composer submit records which way it went — queue, send, or steer — with the connection phase, turn phase, queue depth and provider that produced that decision. That matters because a steer refused by the adapter is invisible to the client: `providerService.sendTurn` is forked in ProviderCommandReactor, so the command has already succeeded by the time the adapter declines. Both follow the `[thread-outbox]` prefix and structured-field shape the module's four existing log sites already use, so one console filter catches the lot. Seam impact: `ChatView.tsx` +168/-1 → +181/-1 (risk 10140 → 10920) for the breadcrumb; row and header totals updated. Everything else is fork-owned. Verified: 80 tests green, typecheck and lint clean. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent 25dcb8d commit a9a4151

4 files changed

Lines changed: 158 additions & 42 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ import { registerFaviconProjectForThread } from "~/browserFaviconStore";
185185
import { resolveComposerSendLabel } from "~/outbox/composerSendLabel.logic";
186186
import { enqueueThreadOutboxMessage, useThreadOutboxQueue } from "~/outbox/threadOutbox";
187187
import { canSteerActiveThread } from "~/outbox/composerSteering.logic";
188+
import { logComposerDispatch } from "~/outbox/outboxDiagnostics";
188189
import { ThreadOutboxQueueList } from "./chat/ThreadOutboxQueueList";
189190
import { getProviderModelCapabilities, resolveSelectableProvider } from "../providerModels";
190191
import { NO_PROVIDER_MODEL_SELECTION } from "../providerInstances";
@@ -5073,6 +5074,18 @@ function ChatViewContent(props: ChatViewProps) {
50735074
}),
50745075
);
50755076
};
5077+
// One breadcrumb per submit: whether it queued, sent, or steered into a
5078+
// running turn, plus every input to that decision. A refused steer is
5079+
// invisible on the client, so this is the only client-side evidence.
5080+
logComposerDispatch({
5081+
queued: composerQueueMode,
5082+
steerable: composerCanSteerActiveThread,
5083+
phase,
5084+
queueCount: outboxQueue.length,
5085+
connection: activeEnvironmentConnectionPhase,
5086+
provider: selectedProvider,
5087+
threadId: activeThread?.id ?? null,
5088+
});
50765089
// Queue mode routes the submit through the thread outbox instead of the
50775090
// immediate-send path (which is gated on an idle, connected thread).
50785091
//

‎apps/web/src/components/chat/ThreadOutboxQueueList.tsx‎

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
useThreadOutboxQueue,
1212
} from "~/outbox/threadOutbox";
1313
import type { QueuedThreadMessage } from "~/outbox/threadOutbox.logic";
14+
import { logOutboxMutationFailure } from "~/outbox/outboxDiagnostics";
1415
import { cn } from "~/lib/utils";
1516
import { Button } from "../ui/button";
1617
import { Textarea } from "../ui/textarea";
@@ -82,6 +83,8 @@ function QueuedMessageRow({
8283
const [draft, setDraft] = useState(message.text);
8384
const [busy, setBusy] = useState(false);
8485
const messageIdRef = useRef<MessageId>(message.messageId);
86+
const moveUpRef = useRef<HTMLButtonElement | null>(null);
87+
const moveDownRef = useRef<HTMLButtonElement | null>(null);
8588

8689
// Keep the local draft aligned with external updates while not editing.
8790
useEffect(() => {
@@ -137,14 +140,45 @@ function QueuedMessageRow({
137140

138141
const move = useCallback(
139142
async (direction: "up" | "down") => {
143+
// Guarded here rather than by disabling the button: `busy` flips
144+
// synchronously, so disabling would take effect on the very control the
145+
// user just activated, and a disabled element loses focus to <body>.
146+
if (busy) {
147+
return;
148+
}
149+
// Only restore focus when the press came from this control, so a mouse
150+
// click does not pull a focus ring onto the row.
151+
const pressed = (direction === "up" ? moveUpRef : moveDownRef).current;
152+
const hadFocus = pressed !== null && document.activeElement === pressed;
140153
setBusy(true);
141154
try {
142155
await moveThreadOutboxMessage(message, direction);
156+
} catch (error) {
157+
// A rejected reorder means the new order never reached storage, so the
158+
// queue silently stays as it was. Without this the promise rejects
159+
// unhandled and the only symptom is a click that appears to do nothing.
160+
logOutboxMutationFailure(
161+
"reorder",
162+
{ direction, messageId: message.messageId, threadId: message.threadId },
163+
error,
164+
);
143165
} finally {
144166
setBusy(false);
167+
if (hadFocus) {
168+
// Once the move commits, this button may sit at the end of its travel
169+
// and be disabled, or its row may have been re-inserted into the DOM.
170+
// Both blur to <body>, which does not just lose the caret — the whole
171+
// action cluster is only revealed on :focus-within, so it disappears
172+
// and the next move needs a Tab from the top of the document.
173+
requestAnimationFrame(() => {
174+
const same = (direction === "up" ? moveUpRef : moveDownRef).current;
175+
const other = (direction === "up" ? moveDownRef : moveUpRef).current;
176+
(same !== null && !same.disabled ? same : other)?.focus();
177+
});
178+
}
145179
}
146180
},
147-
[message],
181+
[busy, message],
148182
);
149183

150184
if (isEditing) {
@@ -201,21 +235,33 @@ function QueuedMessageRow({
201235
not something to read in full. Editing shows the whole text. */}
202236
<p className="min-w-0 flex-1 truncate text-foreground/80">{message.text}</p>
203237
{/* Revealed on hover, on keyboard focus anywhere in the row, and always on
204-
touch devices, which have no hover state to reveal them. */}
205-
<div className="flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 pointer-coarse:opacity-100">
238+
touch devices, which have no hover state to reveal them.
239+
240+
`*:pointer-coarse:after:min-w-auto` is load-bearing, and is the same
241+
antidote the `Group` primitive applies. Every Button carries a
242+
`pointer-coarse:after:min-w-11` invisible 44px hit area that is *not*
243+
pointer-events-none, so four adjacent icon buttons overlap on touch:
244+
without this, the right third of Edit hit-tests to Remove, and a tap
245+
meant to edit deletes the message instead. Neutralising the minimum
246+
width makes the hit area match the visible button; the extra gap keeps
247+
the now-smaller targets apart. Minimum height is left alone — nothing
248+
is adjacent vertically. */}
249+
<div className="*:pointer-coarse:after:min-w-auto flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 pointer-coarse:gap-1.5 pointer-coarse:opacity-100">
206250
<Button
207251
aria-label={`Move queued message ${position} up`}
208-
disabled={busy || !canMoveUp}
252+
disabled={!canMoveUp}
209253
onClick={() => void move("up")}
254+
ref={moveUpRef}
210255
size="icon-xs"
211256
variant="ghost"
212257
>
213258
<ArrowUpIcon className="size-3.5" />
214259
</Button>
215260
<Button
216261
aria-label={`Move queued message ${position} down`}
217-
disabled={busy || !canMoveDown}
262+
disabled={!canMoveDown}
218263
onClick={() => void move("down")}
264+
ref={moveDownRef}
219265
size="icon-xs"
220266
variant="ghost"
221267
>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
2+
import type { ProviderDriverKind, ThreadId } from "@t3tools/contracts";
3+
4+
/**
5+
* Greppable breadcrumbs for the composer's send-vs-queue behaviour.
6+
*
7+
* This path has two failure modes that leave no other trace:
8+
*
9+
* - A message queues when the user expected it to go out now (or the reverse).
10+
* The decision depends on connection phase, queue depth, turn phase and the
11+
* provider's steering support, none of which are visible after the fact.
12+
* - A steer is accepted by the command layer and then refused by the adapter.
13+
* `providerService.sendTurn` is forked in ProviderCommandReactor, so the
14+
* client's command has already succeeded; nothing on the client knows.
15+
*
16+
* Matches the `[thread-outbox]` prefix and structured-field shape the rest of
17+
* the module already uses (threadOutboxStorage, threadOutboxManager,
18+
* useThreadOutboxDrain), so one filter catches every outbox log line.
19+
*/
20+
21+
const PREFIX = "[thread-outbox]";
22+
23+
export interface ComposerDispatchDiagnostics {
24+
readonly queued: boolean;
25+
readonly steerable: boolean;
26+
readonly phase: string;
27+
readonly queueCount: number;
28+
readonly connection: EnvironmentConnectionPhase;
29+
readonly provider: ProviderDriverKind | null;
30+
readonly threadId: ThreadId | null;
31+
}
32+
33+
/**
34+
* One line per composer submit, recording which way it went and every input to
35+
* that decision. `steer` is the case worth grepping for: it is the only one
36+
* that hands a message to a turn that is already running.
37+
*/
38+
export function logComposerDispatch(input: ComposerDispatchDiagnostics): void {
39+
const decision = input.queued ? "queue" : input.steerable ? "steer" : "send";
40+
console.info(`${PREFIX} composer dispatch: ${decision}`, {
41+
decision,
42+
phase: input.phase,
43+
connection: input.connection,
44+
provider: input.provider,
45+
queueCount: input.queueCount,
46+
threadId: input.threadId,
47+
});
48+
}
49+
50+
/** A queue mutation that failed after the user asked for it. */
51+
export function logOutboxMutationFailure(
52+
operation: "reorder",
53+
fields: Readonly<Record<string, unknown>>,
54+
error: unknown,
55+
): void {
56+
console.warn(`${PREFIX} ${operation} failed`, { ...fields, error });
57+
}

0 commit comments

Comments
 (0)