Repository navigation
π§βπ« refactor: Share Stream Frame Placement Rules - #18194
Conversation
24cc4a7 to
57700ea
Compare
|
@codex review |
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. |
|
Codex Review: Didn't find any major issues. Delightful! 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". |
850e9b1 to
eabef10
Compare
dad1dfb to
c99adae
Compare
1c64a9b to
9763a87
Compare
9763a87 to
518b90d
Compare
518b90d to
4a81f11
Compare
4a81f11 to
d3961c1
Compare
|
Codex Review: Didn't find any major issues. Bravo. 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 stream carries frames that are not token deltas but still write to the response: an injected steer, an activity label, a reasoning title, a pause for approval or a question, a pending MCP OAuth prompt. Main chat places them through
ResponsePatcher, and the decision of where each one lands (which message, which content index, how an edit's retained prefix shifts it, whether more of the target has yet to be drawn) was written inline in the patcher, mixed with things only the hooks session needs: frame retries, flushing queued token writes, re-syncing the step handler's copy. The part transforms themselves reached the patcher through a host member,ResumableParts, even though all but one already lived in this package and the app only handed them back.That shape means a second consumer cannot place these frames without copying the patcher. The
Chatclass is that second consumer: its event applier (#18190) leaves these frames unapplied for exactly this reason.This separates the two.
core/parts/place.tsholds one pure function per frame, each answering where the frame lands and whether it is settled, andResponsePatcherkeeps only the session's own concerns around them. Behavior is unchanged.Sixth in a stack, on #18193. The
Chatapplier calls the same functions in the next PR.How it works
Every placement has one signature and one result:
settled: falsereplaces three differently worded retry conditions: a tool approval whose sibling calls are not all drawn, a question whose part was not written, a reasoning title whose reasoning part does not exist yet. What a caller does about it is its own business: the patcher asks for another frame, as before.What stays in the patcher is what belongs to the hooks session:
ResumablePartsis removed fromResumableHost: the patcher imports the transforms. The one transform that still lived in the app,applyReasoningLabelwithfindReasoningLabelMessageIndex, moves tocore/parts/reasoningLabels.tswith its test;~/utilsre-exports both, so app imports are unchanged.Type of change
Testing
Tested environments/configuration:
Unit level. No behavior change is intended, so the evidence is main chat's existing suites passing on the new code.
Automated tests:
packages/chat/src/core/__tests__/place.spec.ts(15 cases): each placement with no prefix, with a retained prefix, under a placeholder id, with the response absent, replayed, and unsettled; the phase start that moves back only when the generation's first part merged into the prefix; the OAuth prompt's two step events.patches.spec.ts: the three cases that stubbed the host's part functions now assert the message the patcher wrote, with the real transforms.reasoningLabels.spec.tsmoved from the client with its subject.packages/chat:npx jest src/core src/react/stream(73 suites, 1700 tests);npx tsc --noEmit.client, against the rebuilt package:useResumableSSE.spec.ts,useResumeOnLoad.spec.tsxandChat/__tests__/transport.spec.tsx(245 tests), which drive real steers, labels and pauses through the patcher.npm run static-checks -- --against origin/dev.Screenshots / recordings
No user-facing change.
Risk / compatibility
This is main chat's placement path. The logic moved rather than changed: the same target lookup, the same prefix arithmetic, the same no-op identity (
changedismessage !== messages[index]), the same retry conditions expressed assettled.ResumableHostloses thepartsmember, which is a breaking change for any other host of the package; the app is the only one.