Repository navigation
feat: edit queued chat messages - #29555
Conversation
This comment has been minimized.
This comment has been minimized.
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: 60bb342e91
ℹ️ 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: TypesGen.EditChatQueuedMessageRequest = { | ||
| content, | ||
| model_config_id: editSelectedModelConfigID, | ||
| reasoning_effort: editReasoningEffort, |
There was a problem hiding this comment.
Preserve the queued row's model on content-only edits
When a queued row was created with a different model from the chat's current picker value, saving a text-only edit passes that picker value to resolveEditModelConfigID, which treats the mismatch as a user-requested model change. This silently rewrites model_config_id even though the user never touched the selector, which is especially likely when multiple queued messages were created with different models. Track whether the selector changed during this edit, as is already done for reasoning effort, or initialize it from the queued row before including an override.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Partially valid: the rewrite is real, but it is the existing history-edit behavior on main (resolveEditModelConfigID is a verbatim extraction, and no model dirty flag exists anywhere). Fixing only queued rows would create exactly the divergence this warns about, so it is tracked for both paths in https://linear.app/codercom/issue/CODAGT-1075 rather than in this stack.
🤖 Reply by Coder Agents on behalf of @mafredri.
| queuedEditRestoredRef.current = true; | ||
| const row = chatQueuedMessages.find((message) => message.editing_since); | ||
| if (!row || isViewerNotOwner) { |
There was a problem hiding this comment.
Wait for fresh queue data before consuming restoration
When React Query has cached messages from before another client began editing, this effect runs immediately with that stale queue, permanently sets queuedEditRestoredRef, and then ignores the authoritative background-refetch result containing editing_since. Revisiting such a chat therefore fails to reopen its server-side edit as intended. Only mark restoration complete after the current mount has received authoritative queue data, or reconsider the marker when the query data timestamp advances.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid for the code this was posted on. The head has no one-time restore: deriveComposerTarget in useQueuedMessageEdit.ts derives the composer target on every render, and a composer in "follow" (untouched) targets the row the store marks. When a refetch or queue_update brings editing_since after cached data, the composer opens that row.
🤖 Reply by Coder Agents on behalf of @mafredri.
| // Leaves edit mode with the composer text kept as the draft. | ||
| const leaveEdit = () => { | ||
| setEditingTarget(null); | ||
| setEditingFileBlocks([]); | ||
| }; |
There was a problem hiding this comment.
Persist text when an external update ends editing
When another client ends or moves the queued edit, leaveEdit makes the current editor text look like the new draft but never writes its text or serialized state to draft storage. If the user reloads or navigates away before typing another character, the retained text is lost and the pre-edit draft is restored instead. Persist the current editor state when leaving, and clear the obsolete draftBeforeEdit, so the visually retained content is actually treated as the draft.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid. When the server stops marking the row and the edit was modified, loadTargetIntoEditor in useConversationEditingState.ts keeps the text as a new-message draft and writes it to draft storage. A change counts as modified when the text or the editor state, such as a file-reference chip, differs from what was loaded. The "when the server ends the edit" table in useConversationEditingState.test.ts asserts the stored draft. Keeping the draft from before the edit as well is still open (CRF-8).
🤖 Reply by Coder Agents on behalf of @mafredri.
| {onEdit && ( | ||
| <QueuedMessageActionButton | ||
| label="Edit" |
There was a problem hiding this comment.
Reveal queued actions when they receive keyboard focus
For every non-head row, this new Edit control is rendered inside the existing opacity-0 action container until pointer hover, but tabbing to the button does not update hoveredID; keyboard users therefore focus and activate an invisible edit control. Reveal the action group with focus-within or remove hidden controls from the tab order until they are displayed.
AGENTS.md reference: site/AGENTS.md:L61-L65
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid; Send now and Remove had the same gap on main. The actions container in QueuedMessagesList.tsx has focus-within:opacity-100, as AttachmentPreview does, so an action that receives keyboard focus is visible.
🤖 Reply by Coder Agents on behalf of @mafredri.
| expect(editBehind).toBeDisabled(); | ||
| await user.hover(editBehind); | ||
| expect( | ||
| await screen.findByText("Finish the current edit first."), | ||
| ).toBeInTheDocument(); |
There was a problem hiding this comment.
Move tooltip rendering assertions to Storybook
This behavior test asserts the tooltip's rendered presence with toBeInTheDocument, although FE1 explicitly reserves rendered visual states for Pixel-backed stories and requires Vitest assertions to target non-visual outcomes. Drive the disabled-tooltip state in the existing paused story and keep this test focused on whether the edit callback is or is not invoked.
AGENTS.md reference: site/AGENTS.md:L5-L7
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid. Edit on a row behind a paused head is aria-disabled and stays focusable, and its tooltip gives the reason. QueuedMessagesList.test.tsx focuses it, checks toHaveAccessibleDescription("Finish the current edit first."), and checks that a click does not call onEdit; the PausedEditBehindHead story hovers it for the screenshot.
🤖 Reply by Coder Agents on behalf of @mafredri.
| export const trackQueuedEditTarget = ( | ||
| targetID: number | null, | ||
| row: TypesGen.ChatQueuedMessage | undefined, | ||
| seenID: number | null, | ||
| ): { seenID: number | null; lost: boolean } => { |
There was a problem hiding this comment.
Do we need to be able to handle | null and | undefined on every single parameter?
There was a problem hiding this comment.
The helper this was posted on is not in the current head. The functions this stack adds to chatQueueReconciliation.ts, runDeleteQueuedMessage and runEditQueuedMessage, take required parameters. The composer target is derived in deriveComposerTarget (useQueuedMessageEdit.ts) from the composer mode, the marked row ID (number | null, null when no row is marked), and the latest marker request.
🤖 Reply by Coder Agents on behalf of @mafredri.
| const queuedEditRestoredRef = useRef(false); | ||
| useEffect(() => { | ||
| if ( | ||
| queuedEditRestoredRef.current || | ||
| chat === undefined || | ||
| chatQueuedMessages === undefined | ||
| ) { | ||
| return; | ||
| } | ||
| queuedEditRestoredRef.current = true; | ||
| const row = chatQueuedMessages.find((message) => message.editing_since); | ||
| if (!row || isViewerNotOwner) { | ||
| return; | ||
| } | ||
| const { text, fileBlocks } = getEditableContentPayload(row.content); | ||
| isEditReasoningEffortDirtyRef.current = false; | ||
| editing.handleBeginEdit({ kind: "queued", id: row.id }, text, fileBlocks); | ||
| }, [chat, chatQueuedMessages, isViewerNotOwner, editing]); |
There was a problem hiding this comment.
I have no idea what is happening here. My immediate thought is to say something is wrong here (although I could be wrong). Could you have an agent confirm that this is definitely valid?
There was a problem hiding this comment.
That effect is not in the current head. Edit mode is restored by derivation: while the composer is in "follow" (the user has not typed or chosen anything), deriveComposerTarget in useQueuedMessageEdit.ts targets the row the store marks for the chat owner, and the layout effect in useConversationEditingState.ts loads that row into the editor when the target changes. That covers a reload, a chat switch, and a row marked from another tab. The first keystroke leaves "follow", so a later marker does not replace typed text.
🤖 Reply by Coder Agents on behalf of @mafredri.
| // under edit opens the composer on it. A marker that arrives later | ||
| // from another client does not, as that would replace what the user | ||
| // is typing here. | ||
| const queuedEditRestoredRef = useRef(false); |
There was a problem hiding this comment.
do we need this as a ref?
There was a problem hiding this comment.
The ref is gone. The composer target is derived on every render from the store marker, the composer mode, and the marker request (deriveComposerTarget in useQueuedMessageEdit.ts), so no once-per-mount flag is needed. The first keystroke moves the composer out of "follow" (handleContentChange in useConversationEditingState.ts), so a marker that arrives later from another tab does not replace typed text.
🤖 Reply by Coder Agents on behalf of @mafredri.
4c2cc30 to
1b8fceb
Compare
1b8fceb to
d4de206
Compare
d4de206 to
17cd798
Compare
17cd798 to
b608b0b
Compare
b608b0b to
f938d82
Compare
f938d82 to
c14a860
Compare
c14a860 to
471bf40
Compare
29272f9 to
fca5a0c
Compare
Loading a row into the composer remounts the Lexical editor, and two of its updates reached handleContentChange after the hook had reset its refs for the new editor. The outgoing editor commits once more when its root detaches, before the listener is removed, and an editor superseded within the same commit chain seeded from a passive effect after the parent's next load. Either one overwrote inputValueRef and the serialized state, so the new editor's seed looked like user input. An untouched edit then counted as modified: it kept the row's text as a draft instead of following another client's edit or giving the pre-edit draft back. ContentChangePlugin now ignores updates of an editor without a root and registers in a layout effect; ValueSyncPlugin seeds synchronously in a layout effect, so each editor reports its seed in the commit that mounts it. The queued edit tests for a server-side end or move now run against the real editor.
An edit counted as modified from the first change after it loaded, and a composer in follow mode switched to draft on its first keystroke. Neither flag went back, so typing and deleting the text again left the composer holding the old row as a draft when another client moved the edit, or never following another client's edit at all. The composer now compares the editor with the content last loaded into it, by text and file-reference chips, when the marked row changes. A changed editor keeps its content as before; an unchanged one follows. Follow mode no longer switches on keystrokes, so the composer only leaves it when a row change finds the editor changed. The file-reference cases now run against the real editor, which also covers a stored draft that loses one of its chips.
The move tests reached the first row through Edit, so nothing checked that a composer following the marked row keeps its changed text when the marker moves. Two rows now open the first row by following the marker: typed text is kept, and text deleted again follows the next row. Every row starts from a stored draft so the composer is unchanged when the first marker arrives.
A send clears the editor, and the composer must then count as unchanged. The test starts from a stored draft, so without the reset the empty editor would differ from the draft and not follow.
When a marker arrived at a changed composer in follow mode, one commit reported the marked row as the editing target before the load effect declined it. That commit unmounted the row's focused Edit button, dropping focus to the page, and dropped the slash commands, which can close an open "/" menu for good. The hook now reports the target the editor holds. A load still runs in a layout effect, so the edit chrome appears before paint.
…ory edits Opening an edit loaded only the row's text, so a queued row's or past message's skill chips were missing from the composer and a save dropped them. The editor now loads the serialized state getEditableContentPayload builds from the content, and the modified check compares skill chips in document order alongside file references. ValueSyncPlugin keeps restoring a serialized state with a deferred update, as main does, because a discrete commit there makes chip decorators flushSync inside the effect; only the plain-text seed is discrete.
Opening an edit of a history message or a queued row built the editor state from text and skill chips only, so file-reference parts never reached the composer and saving sent the content without them. serializeMessageDraft now rebuilds FileReferenceNodes in document order, and getEditableContentPayload builds the state whenever the content has a skill or file-reference part. The composer already sends file references from the editor, so a loaded chip round-trips and a removed one is dropped.
QueuedMessagesList keys the row under edit on queuedMessageUnderEditID and never reads editing_since, so the Cancel edit test now uses an unmarked row and absorbs the separate pending-begin case. buildEditModelOverrides tests repeated resolveEditModelConfigID and the submitChatTurn edit test. The edit test now covers both dirty states, so the function no longer needs an export for testing. The file-reference-only reopen case is the only one without a skill chip, which is what makes getEditableContentPayload build editor state for file references. Its name now says so.
…remounts Text typed into a queued edit lived only in the editor, so a reload or a switch to another chat and back loaded the row's server content over it. The edit's editor state is now stored per row next to the new-message draft and loaded instead of the row's content. It still counts as typed, so a marker that leaves keeps it as a new-message draft. The stored state goes away when the edit is saved, cancelled or loses its row.
…emoving its row Remove on the row the composer edited deleted the row while the editor still held its text, so the typed text stayed behind as a new-message draft and the draft from before the edit was lost. Remove now closes the edit first, as Cancel edit does.
…ending its row Send now on the row the composer edited promoted the row while the editor still held its unsaved text, which then stayed behind as a new-message draft. Send now now closes the edit first, like Remove, so the server sends the row's saved content and the draft from before the edit comes back.
The model picker shows the chat's model, not the queued row's, so a queued save sent the picker's model whenever it differed from the row's and changed the row's model without the user picking one. A queued save now sends model_config_id only when the picker changed during this edit, tracked like the reasoning effort. History edits keep their rules: they also fall back to a usable model when the message's model is no longer available.
…used Edit When the server refused to begin an edit (409 or another non-404 error), the target went away and the editor switched the composer to follow mode, so it opened the row as soon as another client began editing it. The composer now returns to the mode it had before Edit, unless a later choice replaced it, and the editor keeps a draft mode it finds when the target goes away.
…s the row On a paused chat, cancelling the queued edit sends the row unchanged, which the row action already says. The composer's cancel button now says the same. History edits keep "Cancel editing", since cancelling one sends nothing.
react-query reports a settled request to the page on its notify scheduler, separately from rejecting the request's promise. The refused-Edit restore only worked because the default scheduler runs after the promise's handlers. When the page saw the failure first, the editor closed the target, switched the composer to follow, and later opened another client's edit of the row. The Edit's choice now stays the composer's target until the begin's own handlers have applied the outcome, so the editor sees the restored mode whichever order react-query uses.
DanielleMaywood
left a comment
There was a problem hiding this comment.
This review was performed by ai-review, an automated review bot.
10 inline findings and 1 below.
whole PR
SCOPE-1: This PR changes 4772 lines in 33 files (limit 1000). Split it into smaller PRs.
Remedy: split
Coverage
Coverage: 32 of 34 files reviewed, 1 unsupported, 1 deleted; 35 rules.
Candidates: 880 found, 743 outside changed lines, 6 already discussed, 131 evaluated.
Findings: 11 (40 sites, 8 pre-existing sites), 0 over budget, 0 failed.
Model: deepseek/deepseek-v4.1-flash; 103 questions, 78 answered, 25 abstained (truncated 25), 0 cached; 0 uncalibrated findings held back; 90900 input and 98508 output tokens.
Experiments: 4 run, 0 passed, 4 vetoed, 0 unverified, 0 skipped for time.
vetoed: TYPE-1 site/src/pages/AgentsPage/components/QueuedMessagesList.tsx:128: 3 new type errors, first src/pages/AgentsPage/components/AgentChatInput.tsx: TS2345 Argument of type 'number
vetoed: TYPE-1 site/src/pages/AgentsPage/hooks/useQueuedMessageEdit.ts:33: 1 new type error, first src/pages/AgentsPage/hooks/useQueuedMessageEdit.ts: TS2345 Argument of type 'number
vetoed: TYPE-1 site/src/pages/AgentsPage/hooks/useQueuedMessageEdit.ts:56: 4 new type errors, first src/pages/AgentsPage/hooks/useConversationEditingState.test.tsx: TS2345 Argument of type 'number
vetoed: TYPE-1 site/src/pages/AgentsPage/utils/draftStorage.ts:116: 6 new type errors, first src/pages/AgentsPage/hooks/useConversationEditingState.test.tsx: TS2345 Argument of type 'string
| store={store} | ||
| initialMessages={chatMessagesList ?? []} | ||
| editing={{ ...editing, handleBeginHistoryEdit }} | ||
| editing={{ ...editing, handleBeginHistoryEdit, handleCancelEdit }} |
There was a problem hiding this comment.
READ-1: Nested ternary. Use early returns, an if/else, or a lookup instead.
Remedy: split
There was a problem hiding this comment.
Not changing it here: this ternary is on main unchanged; the PR only touches a prop inside it.
🤖 Reply by Coder Agents on behalf of @mafredri.
|
|
||
| // Behavioral: clicking edit fires onEditUserMessage with the | ||
| // correct message ID and text. | ||
| // message ID. |
There was a problem hiding this comment.
TEST-1 (pre-existing, non-blocking): Story UserMessageCopyButton asserts in its play function. Stories are covered by visual regression; keep play to state setup and move behaviour assertions to a Vitest test.
Remedy: move
There was a problem hiding this comment.
Pre-existing story, outside this PR's change. Leaving it.
🤖 Reply by Coder Agents on behalf of @mafredri.
| "cursor-not-allowed text-content-disabled hover:bg-transparent hover:text-content-disabled", | ||
| )} | ||
| > | ||
| <Spinner className="h-3.5 w-3.5" loading={busy}> |
There was a problem hiding this comment.
STYLE-1 (pre-existing, non-blocking): Use size-3.5 instead of w-3.5 h-3.5.
Remedy: simplify
There was a problem hiding this comment.
Pre-existing line, outside this PR's change. Leaving it.
🤖 Reply by Coder Agents on behalf of @mafredri.
| const [selectedModel, setSelectedModel] = useState(""); | ||
| const [selectedReasoningEffort, setSelectedReasoningEffort] = useState(""); | ||
| const isEditReasoningEffortDirtyRef = useRef(false); | ||
| const isEditModelDirtyRef = useRef(false); |
There was a problem hiding this comment.
READ-2 (pre-existing, non-blocking): 21 lines and 12 statements with no blank line between them. Separate the logical steps with blank lines.
Remedy: split
Same at 5 other sites:
site/src/pages/AgentsPage/AgentChatPage/AgentChatPage.tsx:336: 59 lines and 15 statements with no blank line between them. Separate the logical steps with blank lines.site/src/pages/AgentsPage/AgentChatPage/AgentChatPage.tsx:525: 38 lines and 8 statements with no blank line between them. Separate the logical steps with blank lines.site/src/pages/AgentsPage/components/AgentChatInput.tsx:1159: 81 lines and 11 statements with no blank line between them. Separate the logical steps with blank lines.site/src/pages/AgentsPage/components/AgentChatInput.tsx:1358: 45 lines and 10 statements with no blank line between them. Separate the logical steps with blank lines.site/src/pages/AgentsPage/components/ChatConversation/submitChatTurn.ts:385: 53 lines and 12 statements with no blank line between them. Separate the logical steps with blank lines.
There was a problem hiding this comment.
All six sites are pre-existing code this PR does not change. Leaving them.
🤖 Reply by Coder Agents on behalf of @mafredri.
There was a problem hiding this comment.
I'm concerned with how we're adding an extra 135 lines to this already bloated page. Not going to block with this but thoughts on trying to pull some logic into children components?
There was a problem hiding this comment.
Agreed the page is too big. The queued-edit code here can't move into children on its own: the composer target, save pending state and queued save all feed the editing state and send path that #31476 keeps in the page. Shrinking the page means moving the whole composer, which is your #30638's "composer as a node" step. I'd rather do that after this lands than add it to a 4.7k-line PR; happy to take it on or build on #30638.
🤖 Reply by Coder Agents on behalf of @mafredri.
| export const isQueuedMessageUnderEdit = ( | ||
| message: ChatQueuedMessage, | ||
| queuedMessageUnderEditID: number | null, | ||
| ): boolean => message.id === queuedMessageUnderEditID; |
There was a problem hiding this comment.
I mean.. it gave a descriptive name to the check 😂, definitely couldn't have been a variable!
There was a problem hiding this comment.
It was a one-line ID comparison left over from when it also read editing_since. Inlined at its three call sites and removed.
🤖 Reply by Coder Agents on behalf of @mafredri.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: be28da4661
ℹ️ 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".
| store.setQueuedMessages( | ||
| store.getSnapshot().queuedMessages.map((row) => { | ||
| if (row.id === id) { | ||
| return { ...row, editing_since: editingSince }; | ||
| } |
There was a problem hiding this comment.
Skip stale marker writes after queue updates
When another client moves the edit after this request commits but before editQueuedMessage resolves locally, its authoritative queue_update can already have marked a different row in the store. This unconditional post-await write then marks the older requested row again and clears the newer marker, leaving this client following a row the server no longer considers under edit with no later event guaranteed to repair it. Capture and check the queue convergence fence before applying this optimistic marker.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Real, but not changing it here. queue_update has no version, so the client cannot tell whether a snapshot that arrived during the request is newer or older than its own write. Skipping the write-back on any such update would fix this case but drop the write-back that corrects a stale snapshot read before the begin committed. Both need a queue version; I added this sequence to CODAGT-1503, which the PR's Limitations already link.
🤖 Reply by Coder Agents on behalf of @mafredri.
| closeQueuedEditOf(id); | ||
| return requestDeleteQueuedMessage(id); | ||
| }; | ||
| const handlePromoteQueuedMessage = (id: number) => { | ||
| closeQueuedEditOf(id); |
There was a problem hiding this comment.
Restore the queued edit when an action fails
When the user has unsaved changes in a queued edit and Delete or Send now fails due to a network, conflict, or server error, closeQueuedEditOf has already restored the old draft and removed the persisted queued-edit state. Although the reconciliation path restores the queued row, nothing restores the user's edited content, so the failed action causes permanent input loss. Close the edit only after success or retain a rollback snapshot.
AGENTS.md reference: site/AGENTS.md:L11-L11
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this. Remove and Send now discard the typed text on purpose: the user chose to drop the edit. If the request fails, the row comes back with its saved content and the user can retry the action.
🤖 Reply by Coder Agents on behalf of @mafredri.
There was a problem hiding this comment.
This round re-reviews queued-message editing at be28da4 (rebased, 30 fix commits): 1 P1, 4 P2, 10 P3, 11 P4 and 1 Nit are open, six of them re-raised from round 1.
The fixes the panel checked hold, including cancel routing, chips on edit, the transcript refetch and the dirty-ref reset; the disputes on silent draft conversion, the 404 toast, the delete refetch and the two naming nits are closed. Three PR Limitations have no ticket: the content-loss cases, the confirmation dialog, and Escape on a modified edit; this needs a human decision.
The chip fix for edits (898dd11) changes editing of sent messages on main and does not depend on the queued-edit flow, so it can ship as its own PR; if it stays, the description needs the addition the messageParsing.ts comment asks for.
Out of scope (needs a ticket or explicit acceptance by a human):
site/src/api/queries/chats.ts:2767:deleteChatQueuedMessage.onSuccessawaitsinvalidateChatMessages, so each queued-row delete refetches every loaded transcript page in sequence and stays pending until they all return.coderd/exp_chats.go:3166:patchChatQueuedMessagereturns 404 for a failed authorization check, a missing chat and a missing row with no machine-readable code, so a client can tell them apart only by matching message text.site/src/pages/AgentsPage/hooks/useConversationEditingState.test.tsx:576: the comment moved from the deleted test file describes a past change ("now") instead of the behavior.
Notes:
- A refused Edit on another row returns the composer to the row it was editing, but that row's typed text was deleted at the switch, so the composer shows the row's stored content; this is the row-switch case in Limitations.
🤖 This review was automatically generated with Coder Agents.
| isOwner && | ||
| serverMarkedID !== null | ||
| ) { | ||
| editing.handleCancelEdit({ kind: "queued", id: serverMarkedID }); |
There was a problem hiding this comment.
P3 [CRF-46] The page's handleCancelEdit branch that switches a cancelled history edit to the server-marked queued row has no test. (Netero)
Replacing this line with editing.handleCancelEdit(); leaves AgentChatPage.test.tsx, useConversationEditingState.test.tsx, useQueuedMessageEdit.test.ts and submitChatTurn.test.ts green (252 passed), because the hook test at useConversationEditingState.test.tsx:1617 passes the target to the hook directly. If the branch regresses, the marked row does not reopen in this tab after a history cancel. Add an AgentChatPage.test.tsx case that begins a history edit while a queued row is marked, cancels, and expects the composer to hold the queued row's text.
🤖
There was a problem hiding this comment.
Not changing this in this PR; it is approved, and the remaining changes are limited to user-facing defects.
🤖 Reply by Coder Agents on behalf of @mafredri.
| model_config_id: isEditModelDirtyRef.current | ||
| ? effectiveSelectedModel || undefined | ||
| : undefined, | ||
| reasoning_effort: isEditReasoningEffortDirtyRef.current |
There was a problem hiding this comment.
P4 [CRF-47] The queued save's dirty reasoning-effort branch has no test. (Netero)
Replacing lines 375 to 377 with reasoning_effort: undefined leaves the same 252 tests green; submitChatTurn.test.ts:311 covers only the clean case, and the dirty-effort table at line 367 runs only for history edits. Add the queued target to that table, or add a { current: true } case to the test at line 311.
🤖
There was a problem hiding this comment.
Not changing this in this PR; it is approved, and the remaining changes are limited to user-facing defects.
🤖 Reply by Coder Agents on behalf of @mafredri.
| * resolveEditModelConfigID picks one, the effort unless the user changed | ||
| * it for this edit. | ||
| */ | ||
| const buildEditModelOverrides = ({ |
There was a problem hiding this comment.
P4 [CRF-48] buildEditModelOverrides has one caller since ac386e9 moved the queued branch off it. (Netero)
7321374 extracted it so both branches shared the model and effort logic; it now wraps one resolveEditModelConfigID call and one ternary for the history branch at line 391. Inline it back into the history branch, which also removes its doc comment at line 93.
🤖
There was a problem hiding this comment.
Not changing this in this PR; it is approved, and the remaining changes are limited to user-facing defects.
🤖 Reply by Coder Agents on behalf of @mafredri.
|
|
||
| // Closes the composer's edit of the row and discards its typed text; the | ||
| // server acts on the row's saved content. | ||
| const closeQueuedEditOf = (id: number) => { |
There was a problem hiding this comment.
P3 [CRF-49] closeQueuedEditOf discards the composer's edit before Send now or Remove runs, so when that request fails the row comes back still under edit and the rewrite is gone. (Hisoka, Kite)
On failure, runPromoteQueuedMessage and runDeleteQueuedMessage restore the queue snapshot, which still has the row's editing_since, so the server edit and the pause remain while the composer is in "draft". Reproduced with a temporary page test (type, Edit, type " edit", Send now with the promote rejecting): {"composer":"draft","editing":1,"edit":1,"cancelEditing":1,"storage":[]}. Fix: close the composer's edit only after the request resolves, as runEditQueuedMessage applies its store write only after success.
🤖
There was a problem hiding this comment.
Intended, same as Send now: the user gave up the edit. If the request fails, the row comes back with its saved content and the action can be retried.
🤖 Reply by Coder Agents on behalf of @mafredri.
| finalizeSuccessfulSend(target); | ||
| if (sendTarget?.kind === "queued") { | ||
| removeQueuedEdit(sendTarget); | ||
| // Saving puts the row back in the queue, and on a paused chat's |
There was a problem hiding this comment.
P4 [CRF-61] The save-tail comment says "Saving puts the row back in the queue", but the row never leaves the queue; a save clears editing_since. (Gon)
No code removes the row from queuedMessages during an edit, so the comment describes a step that does not happen. Rewrite: "Saving ends the edit, and on a paused chat's head it sends the row. The saved text is not a new message, so the pre-edit draft comes back unless another edit opened during the save."
🤖
There was a problem hiding this comment.
Not changing this in this PR; it is approved, and the remaining changes are limited to user-facing defects.
🤖 Reply by Coder Agents on behalf of @mafredri.
| readOnlyNotice?: string; | ||
| isChatPaused?: boolean; | ||
| // Editing state, owned by the parent. | ||
| // Editing state, owned by the parent. The kind selects the banner text. |
There was a problem hiding this comment.
P4 [CRF-62] The editingKind prop comment says the kind selects the banner text, but it also selects the cancel label and whether the edit holds the Stop slot. (Gon)
editingHoldsStop (line 1369) is true only for history edits, so a queued edit gives up Stop while a turn streams, which the comment does not tell the reader. Rewrite: "The kind selects the banner text, the cancel label, and whether the edit holds the Stop slot."
🤖
There was a problem hiding this comment.
Not changing this in this PR; it is approved, and the remaining changes are limited to user-facing defects.
🤖 Reply by Coder Agents on behalf of @mafredri.
| // layout. | ||
| Object.defineProperty(Range.prototype, "getBoundingClientRect", { | ||
| configurable: true, | ||
| value: () => new DOMRect(0, 0, 1, 16), |
There was a problem hiding this comment.
P4 [CRF-63] The Lexical jsdom shim new DOMRect(0, 0, 1, 16) and the type paste helper are copied between useConversationEditingState.test.tsx and AgentChatPage.test.tsx. (Gon)
Both copies are new in this PR (AgentChatPage.test.tsx:56, :119; here and at line 384), so a change to one leaves the two Lexical setups different. Move the shim and the helper into one shared test helper module, with 16 as a named line height.
🤖
There was a problem hiding this comment.
Not changing this in this PR; it is approved, and the remaining changes are limited to user-facing defects.
🤖 Reply by Coder Agents on behalf of @mafredri.
|
|
||
| const loaded = loadedTarget?.target; | ||
| if (loaded?.kind === "queued") { | ||
| if (isEditorChanged() && (content.trim() || hasFileReferences)) { |
There was a problem hiding this comment.
P4 [CRF-64] The queued-edit localStorage write in handleContentChange repeats writeDraft with a different key. (Zoro)
Both do the same non-empty check, setItem in a try with a quota catch, and removeItem otherwise (writeDraft at lines 142 to 156). Pass the key to writeDraft, then call writeDraft(queuedEditStorageKey(loaded.id), ...) when isEditorChanged() and removeQueuedEdit(loaded) otherwise.
🤖
There was a problem hiding this comment.
Not changing this in this PR; it is approved, and the remaining changes are limited to user-facing defects.
🤖 Reply by Coder Agents on behalf of @mafredri.
|
|
||
| type SerializedNode = { type?: string; children?: SerializedNode[] }; | ||
|
|
||
| const chipNodeTypes: ReadonlySet<string> = new Set([ |
There was a problem hiding this comment.
P4 [CRF-65] chipNodeTypes is a second list of the chip node types; isChipNode in fileReferenceDisplay.ts:9-12 already lists the same two. (Zoro)
FileReferenceNode.getType() returns the same "file-reference" string the serialized state uses, so both lists describe one set, and a third chip type added to only one of them makes isEditorChanged miss changes to it. Export chipNodeTypes from one module and make isChipNode (node) => chipNodeTypes.has(node.getType()).
🤖
There was a problem hiding this comment.
Not changing this in this PR; it is approved, and the remaining changes are limited to user-facing defects.
🤖 Reply by Coder Agents on behalf of @mafredri.
… was typed against A tab following another tab's queued edit loaded that tab's saved typed text and counted it as its own change, so when the edit ended it kept the text as a new-message draft and overwrote the shared draft. Saved text could also load over a row another client had saved since. The saved edit now records the row content it was typed against and loads only while the row still has it. Text loaded from the saved edit and not changed in this tab counts as unchanged when the edit ends.
|
Reply to the review summary:
|
Queued rows gain Edit and Cancel edit actions. Edit opens the composer at once and marks the row on the server (
editing_since). Save patches the content and clears the marker; Cancel only clears the marker. On a paused chat, Save sends the edited head and Cancel sends it unchanged. A chat that loads with a row under edit reopens it in the composer. While the chat is paused, Edit on other rows is unavailable, and hovering or focusing it shows why. The row the composer edits shows Cancel edit instead of Edit. While a turn streams, a history edit keeps Stop in the send slot and a queued edit shows Save Edit.The composer target is derived on every render from the row the store marks, the composer mode the user chose in this session (
"follow","draft", or a history or queued row), and the state of the latest marker request. In"follow", the composer edits the marked row, so a reload or chat switch restores edit mode in the same render the store gets the row, and every tab shows the same edit. A queued mode holds while the server marks that row or the request to begin its edit is in flight, and closes when the server no longer marks it. The page shows edit mode only for the row the editor holds, and never for an edit the server does not have.When the marked row changes, a modified input (text or file-reference chips that differ from what was last loaded into the editor) stays as a new-message draft and no edit opens. An unmodified input, including text typed and deleted again, gets back the draft from before the edit, captured once per edit session, and the composer follows the marked row.
Text typed in a queued edit is saved in local storage per row, like a new-message draft, so a reload or chat switch brings it back. It is saved with the row content it was typed against and loads only while the row still has that content. Text a tab loaded from the saved edit and did not change counts as unchanged when the edit ends, so a tab that followed another tab's edit gets its own draft back.
Editing a sent message also keeps its skill and file-reference chips now.
For review:
deriveComposerTargetandderiveQueuedMessageUnderEditIDinuseQueuedMessageEdit.tsare pure functions with table tests. The hook holds one piece of state,unappliedEdit, which keeps a refused Edit's row as the target until the refusal restores the earlier composer mode.useConversationEditingStateowns the editor text and the pre-edit draft and loads the editor in one layout effect. The page ownscomposerModeand thesaveQueuedMessageandsetQueuedMessageEditingrequests, whose store updates are inrunEditQueuedMessage(chatQueueReconciliation.ts). A successful request that setseditingwrites the marker into the store without waiting forqueue_update, and a 404 drops the row. Marker requests share a mutation scope with save, so an end or save never runs before its begin, but use a separate mutation instance, so they do not mark the composer pending.Limitations:
queue_updatehas no version, so the client cannot order it against its own writes. A queue snapshot the stream read before an edit began can arrive after the begin returned; the composer treats it as the edit ending and keeps typed text as a new-message draft until Edit reopens the row (CODAGT-1503).Linear: https://linear.app/codercom/issue/CODAGT-971
Part of the CODAGT-971 frontend stack: 3 of 3.