Repository navigation
Conversation
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4e936f379a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const request = queuedMessageRequestsRef.current.then(() => | ||
| mutate({ queuedMessageId: id, req }), | ||
| ); | ||
| queuedMessageRequestsRef.current = request.catch(() => undefined); |
There was a problem hiding this comment.
Abort saves when the begin marker fails
If a user submits the optimistic editor before {editing: true} settles and that begin request is rejected, this recovery converts the failed queue tail into a fulfilled promise, so the queued save still executes afterward. This is unsafe when a stale client tries to edit a row after another client has paused the chat: the begin is rejected by coderd/x/chatd/chatstate/transitions.go:905-907, but the subsequent request can still overwrite the row because content is updated independently at lines 908-927. Preserve the begin failure for dependent save/end operations instead of allowing them to proceed.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Partially valid. The mechanics are as described, but the trace is not: Enter leaves edit mode synchronously (clearInputForEdit) before the begin settles, so no resync happens; the save then applies the text the user typed, which is the intended content. Making dependents abort would either poison the chain for the rest of the session or double-toast and re-enter edit mode, so ordering stays as is. The ordering itself is now expressed with a React Query mutation scope (3cf5df7), see below.$\n\n> 🤖 Reply by Coder Agents on behalf of @mafredri.
| ], | ||
| { queuedEditOverride: { id: 9, editing: true } }, | ||
| ); | ||
| expect(screen.getByText("Editing")).toBeInTheDocument(); |
There was a problem hiding this comment.
Move visual-state assertions out of Vitest
The new override test asserts only rendered presence and absence with toBeInTheDocument, rather than an interaction's callback, request, or state outcome. These visual branches should be captured by a Storybook state, while Vitest should exercise observable behavior such as invoking Edit or Cancel with the expected row; the frontend contract explicitly prohibits these DOM-presence assertions.
AGENTS.md reference: site/AGENTS.md:L7-L7
Useful? React with 👍 / 👎.
| patchQueuedMessage( | ||
| id, | ||
| { editing: true }, | ||
| "Failed to edit queued message.", | ||
| ).catch(() => setFailedQueuedEditBeginID(id)); |
There was a problem hiding this comment.
Associate begin failures with an edit attempt
When requests are slow, a user can select row A, row B, and then row A again before A's first begin settles because onEdit now returns immediately. If the first A request fails, this callback records only A's row ID, so the render logic treats the newer A attempt as failed and cancels its composer even though its own begin is still queued and may succeed, leaving the server editing A while the local UI has exited edit mode. Track an attempt token or request identity so an obsolete failure cannot cancel a later edit of the same row.
Useful? React with 👍 / 👎.
| it("lets the local edit state override the row's marker", () => { | ||
| renderList( | ||
| [ | ||
| { ...MockChatQueuedMessage, id: 9 }, | ||
| { ...MockChatQueuedMessage, id: 10 }, | ||
| ], | ||
| { queuedEditOverride: { id: 9, editing: true } }, | ||
| ); | ||
| expect(screen.getByText("Editing")).toBeInTheDocument(); | ||
| expect(screen.getByText("Waiting")).toBeInTheDocument(); | ||
| expect( | ||
| screen.getByRole("button", { name: "Cancel edit" }), | ||
| ).toBeInTheDocument(); | ||
| cleanup(); | ||
|
|
||
| renderList([{ ...MockEditingChatQueuedMessage, id: 9 }], { | ||
| queuedEditOverride: { id: 9, editing: false }, | ||
| }); | ||
| expect(screen.queryByText("Editing")).not.toBeInTheDocument(); | ||
| expect( | ||
| screen.queryByRole("button", { name: "Cancel edit" }), | ||
| ).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("hides the Enter hint on the head while Enter saves an edit", () => { | ||
| renderList([{ ...MockChatQueuedMessage, id: 9 }]); | ||
| expect(screen.getByText("to send")).toBeInTheDocument(); | ||
| cleanup(); | ||
|
|
||
| renderList([{ ...MockChatQueuedMessage, id: 9 }], { | ||
| enterSendsHead: false, | ||
| }); | ||
| expect(screen.queryByText("to send")).not.toBeInTheDocument(); | ||
| }); | ||
|
|
There was a problem hiding this comment.
violations of frontend rules
| // begin it follows. A 404 means the row was sent or removed. Drop it | ||
| // locally; a queue_update for it may never arrive. Every failure is | ||
| // reported here, so callers only decide whether to continue. | ||
| const queuedMessageRequestsRef = useRef<Promise<unknown>>(Promise.resolve()); |
There was a problem hiding this comment.
Gone. The intent was ordering: Edit opens the composer before the begin PATCH settles, so a quick Escape or Enter must not reach the server before the begin. React Query already has this: mutations sharing a scope.id run serially and a failed one does not block the next (mutationCache.canRun/runNext). editChatQueuedMessage now sets scope: { id: \chat-queued-messages-${chatId}` }andpatchQueuedMessage` is plain async/await again (3cf5df7).$\n\n> 🤖 Reply by Coder Agents on behalf of @mafredri.
| const request = queuedMessageRequestsRef.current.then(() => | ||
| mutate({ queuedMessageId: id, req }), | ||
| ); | ||
| queuedMessageRequestsRef.current = request.catch(() => undefined); |
| // The begin request settles after the click's render, so its failure | ||
| // goes through state. The composer then follows the row the server | ||
| // has under edit, if any. | ||
| const [failedQueuedEditBeginID, setFailedQueuedEditBeginID] = useState< | ||
| number | null | ||
| >(null); | ||
| const queuedEditBeginFailed = | ||
| failedQueuedEditBeginID !== null && | ||
| failedQueuedEditBeginID === queuedEditTargetID; | ||
| if (failedQueuedEditBeginID !== null) { | ||
| setFailedQueuedEditBeginID(null); | ||
| } | ||
| const serverEditRow = useChatSelector(store, (s) => | ||
| s.queuedMessages.find((row) => row.editing_since), | ||
| ); | ||
| if (queuedEdit.lost === "ended") { | ||
| editing.leaveEdit(); | ||
| } else if (queuedEditBeginFailed && serverEditRow) { | ||
| const { text, fileBlocks } = getEditableContentPayload( | ||
| serverEditRow.content, | ||
| ); | ||
| editing.handleBeginEdit( | ||
| { kind: "queued", id: serverEditRow.id }, | ||
| text, | ||
| fileBlocks, | ||
| ); | ||
| } else if (queuedEdit.lost === "never_began" || queuedEditBeginFailed) { | ||
| editing.handleCancelEdit(); | ||
| } | ||
|
|
||
| const endQueuedEditBeforeLeaving = async (): Promise<boolean> => { | ||
| if (queuedEditTargetID === null) { | ||
| return true; | ||
| } | ||
| try { | ||
| await handleEndQueuedMessageEdit(queuedEditTargetID); | ||
| return true; | ||
| } catch { | ||
| return false; | ||
| // Rows show the local edit state before the server confirms it. The | ||
| // composer target covers a begin; an end is tracked until the row's | ||
| // marker clears or the request fails. | ||
| const [endingQueuedEditID, setEndingQueuedEditID] = useState<number | null>( | ||
| null, | ||
| ); | ||
| const endingQueuedEditRow = useChatSelector(store, (s) => | ||
| s.queuedMessages.find((row) => row.id === endingQueuedEditID), | ||
| ); | ||
| if (endingQueuedEditID !== null && !endingQueuedEditRow?.editing_since) { | ||
| setEndingQueuedEditID(null); | ||
| } | ||
| let queuedEditOverride: QueuedEditOverride | undefined; | ||
| if (queuedEditTargetID !== null) { | ||
| queuedEditOverride = { id: queuedEditTargetID, editing: true }; | ||
| } else if (endingQueuedEditID !== null) { | ||
| queuedEditOverride = { id: endingQueuedEditID, editing: false }; | ||
| } | ||
|
|
||
| const endQueuedMessageEdit = (id: number) => { | ||
| setEndingQueuedEditID(id); | ||
| return patchQueuedMessage( | ||
| id, | ||
| { editing: false }, | ||
| "Failed to stop editing the queued message.", | ||
| ).catch((error: unknown) => { | ||
| setEndingQueuedEditID((current) => (current === id ? null : current)); | ||
| throw error; | ||
| }); | ||
| }; | ||
|
|
||
| // Failures are reported by patchQueuedMessage; the row keeps offering | ||
| // Cancel edit while its marker remains. | ||
| const handleEndQueuedMessageEdit = (id: number) => { | ||
| if (id === queuedEditTargetID) { | ||
| editing.handleCancelEdit(); |
There was a problem hiding this comment.
this component has far too much junk in it. far too much logic is living in it. we really need to organise this code better
There was a problem hiding this comment.
Agreed. The queued-edit orchestration (begin/end/save, lost-edit tracking, restore, override) is a self-contained unit that belongs in its own hook next to useConversationEditingState, with the page only wiring props. I'd rather do that as one move after this stack lands than mid-review; say if you want it in this PR instead.$\n\n> 🤖 Reply by Coder Agents on behalf of @mafredri.
There was a problem hiding this comment.
Done, and earlier than promised: the queued-edit orchestration now lives in hooks/useQueuedMessageEdit.ts with its own tests (12), and the page only wires requests and props. This PR is folded into #29555 so the eager design is reviewed once rather than as a rewrite of an intermediate one; closing this PR.$\n\n> 🤖 Reply by Coder Agents on behalf of @mafredri.
60bb342 to
4c2cc30
Compare
4e936f3 to
af52e29
Compare
4c2cc30 to
1b8fceb
Compare
af52e29 to
95d193a
Compare
1b8fceb to
d4de206
Compare
95d193a to
3cf5df7
Compare
d4de206 to
17cd798
Compare
3cf5df7 to
4a9c0e5
Compare
Edit state carries an EditingTarget with a kind instead of a bare history message ID, so a second target kind can be added without touching every consumer again. The edit model override and the editable payload extraction move into reusable helpers, and the queued row actions share one button and one action runner. No behavior changes.
The backend now pauses a chat when its queue head is under edit and marks the row with editing_since. The frontend treats paused as a finished turn (chime, buffered part discard, archive hint), queues instead of sending while paused, and never promotes a head that is under edit. Queued rows show Editing and Waiting badges from the marker; the row actions to begin or end an edit come next. Queued rows are compared structurally because a marker or content change no longer changes the row's identity.
A queued row gets Edit and Cancel edit actions. Edit marks the row on the server and loads it into the composer; Save patches the content and clears the marker; Cancel clears the marker, which while paused sends the row unchanged. Each step waits for the server before the composer changes mode, so a failed request leaves the user where they were. The page owns the server calls. A 404 means the row was already sent or removed, so it is dropped locally. If another client ends the edit, the composer leaves edit mode and keeps the typed text as the draft. A chat that loads with a row under edit reopens that edit.
Edit opens the composer at once and sends the begin marker behind it, so the click feels the same as editing a history message. The rows show the local edit state through queuedEditOverride until the server's marker catches up. Marker requests run on their own mutation and in order, so an end or save cannot overtake the begin it follows. If the begin fails, the composer follows whichever row the server has under edit, or leaves edit mode. The lost-edit tracker now tells a row that was sent before its edit began apart from one whose edit was ended by another client, because only the latter should keep the typed text as the draft.
17cd798 to
b608b0b
Compare
4a9c0e5 to
eb7138b
Compare
f938d82 to
c14a860
Compare
Edit now opens the composer at once and sends the begin marker behind it, so the click feels like editing a history message. Rows show the local edit state through
queuedEditOverrideuntil the server's marker catches up. Marker requests never mark the composer pending and run in order, so an end or save cannot overtake its begin. If the begin fails, the composer follows whichever row the server has under edit, or leaves edit mode.Review notes: the lost-edit tracker distinguishes a row sent before its edit began (
never_began, cancel) from one whose edit another client ended (ended, keep the typed text). Earlier marker-based list tests become override-based, since the list now renders from the override.Part of the CODAGT-971 frontend stack: 4 of 4.