Repository navigation
🔷 feat: Declare Turn Shapes in Created Frames - #18401
Conversation
Codex Review Summary: ✅ CompletedThis 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: 5e1b13e1ed
ℹ️ 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".
| : messages.find( | ||
| (message) => !message.isCreatedByUser && message.messageId === turn.responseMessageId, | ||
| ); | ||
| if (named != null && turn?.editedContent != null) { |
There was a problem hiding this comment.
Carry the source reply identity separately for edited reruns
When observing an edited assistant reply, this lookup searches for the new generation ID rather than the saved reply being edited. The request controller allocates a fresh preallocatedResponseMessageId for edits, and BaseClient.setMessageOptions() replaces the original response ID before invoking onStart, so turn.responseMessageId does not identify a row already in the observer's list. Consequently, the edited-content branch is skipped and the observer streams without applying the edit or setting the retained-prefix offset. Carry the original edited reply ID separately from the new response ID and use it to locate the retained content; the added test currently masks this by using the same ID for both.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid. Fixed in 0c623d6. An edited rerun is stored under a fresh id, so responseMessageId cannot name the reply it starts from. The frame now carries that reply separately as turn.sourceMessageId (the request's responseMessageId, stated for a continued and for an edited turn), and the applier looks up the retained content by it. The test no longer uses one id for both: reruns an edited reply from its own parts under the new id the server stores it at edits resp-0 into a reply stored as resp-1, and fails against the previous code. turn.spec.ts covers the server side of the split.
| isRegenerate: false, | ||
| isEdited: true, | ||
| isContinued: true, | ||
| messages: messages.filter((message) => message !== named), | ||
| initialResponse: restarted, |
There was a problem hiding this comment.
Seed continued replies from the cleared response, not the list tail
When the continued reply is not the last assistant row in the cached conversation—for example, the list also contains a later sibling answer—removing named leaves that other answer at the tail. With isRegenerate: false, reduceStep() explicitly seeds the first run step from the last assistant message instead of initialResponse, so the cleared restarted content is ignored and streamed continuation text is appended to the unrelated answer's content under the continued reply's ID. Ensure continuation steps seed from the explicitly restarted response regardless of stored branch order, and cover a list containing a sibling after the continued reply.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid. Fixed in 0c623d6, and the cause was wider than the continued case: main chat's own created handler puts the turn's placeholder at the end of the list, which is why the reducer can build the first step on the last row; the applier removed the reply and left some other answer last. For a continued and for an edited turn, the reply the turn starts from now goes to the end of the list in its starting state (emptied for a plain continue, its parts with the edit in place for an edit), as main chat's placeholder does. Pinned by continues the reply it was told to, not the answer that happens to be last in the list and by the edited case, both with a sibling answer after the reply; both fail against the previous code.
|
@codex review Head 0c623d65f6. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0c623d65f6
ℹ️ 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".
| @@ -215,13 +275,13 @@ function createdSubmission(data: ChatCreatedFrame, messages: TMessage[]): EventS | |||
| initialResponse: { text: '', isCreatedByUser: false } as TMessage, | |||
| userMessage, | |||
| }); | |||
| /** The server's word on the turn's shape, where it gives one; else what the list implies. */ | |||
| const regenerated = turn != null ? turn.isRegenerate === true || anchored : anchored || answered; | |||
There was a problem hiding this comment.
Seed plain turns from their identified response, not the list tail
When an observer's cached list already contains the user message and an earlier assistant child, such as an abandoned response from a preempted attempt, a plain turn naming a fresh response now forces isRegenerate to false despite answered being true. Unlike the edited/continued branch, this path does not put the selected or empty response at the end of the list. Consequently, reduceStep() seeds the new response from the last assistant row rather than initialResponse, and incoming deltas append to the abandoned answer's content under the new response ID until a sync or final frame corrects it. Ensure plain turns also seed from the explicitly selected response independently of cached branch order.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Valid, and the same cause as the continued case, so it is fixed as the rule rather than as a third branch. In c6f6915 every turn that is not regenerate-shaped has its reply put last in the list at created: the edited and continued turns did since 0c623d6, and a plain turn now does too, moving the reply the list already holds or appending the empty one. That is what main chat's own created handler does with its placeholder, and it is why the step reducer may build the first step on the last row. Pinned by builds a plain turn on its own reply, not on an abandoned one under the same message, which fails against the previous code. A regenerate-shaped turn is unchanged: its first step is seeded from the submission, not from the list.
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…ies It as Its Sender Does
…ild on It, Not the List's Tail
c6f6915 to
f6e4273
Compare
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Summary
A
createdframe names the message a turn starts from, and that is all it says. The client that started the turn knows what kind of turn it is; one that only watches it (aChatfollowing a conversation throughcreateEventApplier) does not. Four kinds of turn name a message the conversation already holds: a regeneration, a compaction, a continued reply and an edited reply. The applier inferred what it could from the list, and two cases cannot be inferred at all: a continued or an edited reply names an existing user turn and an existing reply, exactly as a regeneration does. An observer drew either one as a second answer beside the first until the final frame corrected it.With this, the server states the turn's shape in the frame, and the applier takes it at its word.
Second of the steps toward a chat a reader can open and drive beside the main one. On #18398. No user-facing change: nothing observes a main-chat turn through the applier yet.
How it works
Server:
describeCreatedTurn(packages/api/src/agents/turn.ts) builds it from what the request already says, and both places that emit acreatedframe for a generation pass it: the resumable controller (api/server/controllers/agents/request.js, one call in the existing emit) and a background subagent's own stream.Applier (
createdSubmission), when the frame carriesturn:editedContent+editPrefixLengthisContinued, messages without the replyisRegenerate,compactFor both, the reply the turn starts from goes to the end of the list in its starting state. Main chat's own
createdhandler puts the turn's placeholder there, and the step reducer builds the first step on the last row; in a list that holds other branches the last row is otherwise some other answer.The edit is applied by
withEditedPart, lifted out of the client's turn builder so both use one rule (stamps off, the part replaced on a copy, a thought's generated title dropped).A frame without
turn, from a server that predates it, is read as before, by what the list implies.Type of change
Testing
Tested environments/configuration:
Unit level. Not exercised in a browser or against a running server: nothing reads the new field on a main-chat turn yet, and main chat's own stream session ignores it.
Automated tests:
packages/api/src/agents/turn.spec.ts(new, 7): a plain turn names only its reply; a regeneration; a compaction stated as regenerate-shaped too; a continued turn's source; an edited rerun's source beside its new id; no source for a turn that starts from no reply; a missing reply id left out.request.resumeMetadata.spec.js: a plain turn'screatedframe carriesturnwith the reply's id.packages/chat/src/core/__tests__/apply.spec.ts, new "a turn whose shape the server states" (5): a continued reply drawn again from empty under its own id; the same with another answer after it in the list; an edited reply rerun from its own parts under the new id, with a sibling after it and the saved row untouched; a regeneration taken at the server's word where the list holds no earlier answer; a frame withoutturnread as before. All but the last fail with the field ignored.packages/chat:npx jest(3928 tests),npx tsc --noEmit;packages/api:npx tsc --noEmitshows nothing in the files touched.npm run static-checks -- --against origin/dev.apisuites cannot load here (the installed agents SDK is older thandevrequires), so CI is the check forrequest.jsand the two controller specs whose hand-written@librechat/apimocks gained the helper.Risk / compatibility
/apichange is one call in an existing object literal; the rule lives inpackages/api.