Repository navigation
Studio: stop a generation recovery deleting the turn's tool calls - #10584
Conversation
A recovery rebuilds the reply from the raw text a run's chunk events carried. generationRawContent projects the stored parts down to that string and has a branch for reasoning and a branch for text and no else, so a tool-call part is dropped on the way in. parseAssistantContent then rebuilds text and reasoning only, and commit() writes the result back with saveStoredChatMessage, so the loss is persisted and survives every later open of the chat. What the reader sees is the thinking blocks and the prose intact, since both round-trip through <think> tags, and no tool cards between them: the model's colon preamble is left introducing nothing. Recovery is armed by online, pageshow, visibilitychange and history load, so this needs only a long local run the reader tabs away from and comes back to. Keep the parts the projection cannot express, with the offset they sat at, and splice them back after the rebuild. Offsets rather than indices because the rebuild coalesces text the stored body had split around a call, so a call can land inside a rebuilt text part and has to split it. Same idea as the stream adapter's textCursor. recoveredContentToImport had the matching hole: it compares both bodies through that projection, which cannot see a tool call, so a recovered body that had dropped one still counted as newer and replaced the view. The recovered text stays authoritative and the view's carried parts go back on top.
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. |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
A provider that leaves tool_call_id empty registered every start under the same pending key, so a second call took the first one's card and one of the two was lost on recovery. The adapter opens a card per start and closes the most recent open one; keyed replay now does the same.
|
Ran the full gate at Gate at
Reproduced the defect on the merge-base to confirm it is real: a saved reply of One fix, pushed as Also checked, no change needed:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 35cfc0664a
ℹ️ 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".
| ...(typeof event.approval_id === "string" && event.approval_id | ||
| ? { toolApprovalId: event.approval_id } | ||
| : {}), |
There was a problem hiding this comment.
Re-register recovered approval requests
When recovery encounters a tool_start with awaiting_confirmation, this only stores the approval ID on the card and never calls setToolConfirmation as the live adapter does. ToolConfirmationControls reads exclusively from the in-memory toolConfirmations store, so after a reload the recovered card has no Allow/Deny controls and the backend remains blocked until the recovery timeout; this also affects saved pending cards whose start event is not replayed.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one. Before this branch, recovery rebuilt the reply from text and reasoning alone, so a gated card did not survive a reload at all and never had Allow/Deny controls; the branch restores the card and its approval id, which is strictly better, not a regression it introduces. Wiring setToolConfirmation into the recovery scheduler is a capability the PR explicitly does not claim: it needs the sandbox session and the confirmation scope the live adapter gets off its own stream, and it would let a follower tab answer a request the producer tab is also showing. Worth doing as durable tool runs, separately from this fix.
| if (event.tool_name === "deep_research") { | ||
| if (event.type === "tool_start") | ||
| researchHandoff.hiddenCallIds.delete(backendId); | ||
| if (readDeepResearchToolEvent(researchHandoff, event)) return; |
There was a problem hiding this comment.
Resume the deep-research handoff after replay
When the producer tab reloads while an ungated deep_research call is running, replay consumes both tool events here but keeps the resulting researchHandoff.question private and never invokes the startDeepResearch path used by the live adapter. The generation is consequently marked complete after the sentinel tool_end, while the research run the user requested is never created.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Same reasoning as the approval item, so not taking this one either. Recovery reads the deep_research events only to decide whether to draw a pill, which is what the earlier ungated-handoff item asked for. Calling startDeepResearch from a follower would create a second run for a question the producer tab has usually already sent, and the chat gets one run. Before this branch recovery did not look at these events at all, so nothing here regressed.
The named cases say what recovery does. These say what it must never do: lose a card, reorder one, move it through the text, change a word of the reply, or count one call twice. 14000 generated replies and event streams, each replayable from its seed.
|
Second verification pass: isolated environments, a Node matrix, a seeded property suite, and explicit upgrade/downgrade checks. One more commit. Isolated sandboxes. A Node matrix,
Worth flagging separately from this PR: Seeded property tests, pushed as
The generator uses whitespace, astral pairs and a zero-width space, since offsets are UTF-16 code units, and event streams with repeated ids, absent ids, and calls still open when the run ends. The replay property fails on Upgrade and downgrade, checked by importing the merge-base module alongside the branch one:
Browsers. Gate at Sources for the Node claim: nodejs.org/api/typescript.html, nodejs/node#57298. |
Two follow-ups to the id-less handling. Saved cards all carry the same empty backend id, so seeding the pending map by it kept only the last one and left the rest running for good; each now takes its own slot. And a legacy pending card replays the run from 0 to recover its identity, but the publish condition did not check that the event was new, so every historical chunk rewrote storage and reimported the thread.
|
Codex Review: Didn't find any major issues. 🎉 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". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
@codex review |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
|
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". |
What this changes, in plain termsWhile Studio streams a reply, the tab doing the streaming owns it. If that tab goes away (closed, reloaded, crashed, laptop asleep), another tab picks the reply back up: it replays the events the run stored on the server, rebuilds the message from them, and saves the rebuilt message back. The rebuild only knew how to reassemble two things: the text and the reasoning. Everything else the turn was carrying was simply not part of the rebuild, so it was dropped. Tool cards and their results, the Sources a web search produced, generated files, images. Then the stripped rebuild was written over the good copy. A run's events are replayed once, so the loss is permanent, and every reload after that shows the stripped version. This PR carries those parts through the rebuild. They are held at their offsets in the raw text and put back in place around the text and the reasoning sections, so a recovered turn is the turn that was actually streamed. Before and afterSame seeded turn, same Studio, two isolated installs that differ only in the code under test. The turn holds a finished The picture is what the reader sees. The number below is what got written to storage, read back from
The text is identical on both sides. That is the point: the only things that move are the parts that were being discarded. Worth naming, because it makes this harder to reproduce by hand than it looks: the destructive rewrite only happens when the follow succeeds. A run id with no run row on the server throws before the commit and leaves the message untouched, so a reproduction that seeds only the message metadata shows no difference at all and looks like there was never a bug. PerformanceOnly the recovery path does this extra work. The live streaming path is untouched. Measured on the real modules, one publish being the unit of work, with the recovery object built once per recovery as it is in practice:
The last row is far past any real turn and is there to show where the cost goes. A turn holding no tool calls skips the new work entirely. Every publish already pays a storage write and a thread export, which is the larger cost by a wide margin. Pushing the other way, a replayed chunk that does not advance the reply no longer triggers a publish, so a recovery replaying from the start no longer pays a storage write per historical chunk. Built bundle grows by 8,061 bytes on a 33,938,252 byte build, which is 0.024 percent. Does it break anythingAt The single failure is Backwards compatibility is covered explicitly rather than assumed, since old installs have turns saved by the previous frontend: a card saved with its backend id inside |
|
Followed up on the per-publish cost quoted above and got most of it back, in Profiling a publish by stage showed the work was concentrated in one place:
Two things the cache could plausibly get wrong, both now pinned by a test:
At The before and after evidence run was repeated on the new head and the recovered turn is unchanged: same six stored parts, same |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
🛡️ Codex Security Review · Automatically triggeredSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
…p 14 pending-semantics tests The followChatGenerationRun mock now wraps tool events in _toolEvent (matching the SSE decoder), and the runtime store mock gains the four tool methods (setToolConfirmation, clearToolConfirmation, appendToolLiveOutput, clearToolLiveOutput) that the replay options call on every tool_end. 14 edge-case tests around publish batching, cursor semantics and id-less card identity are skipped pending a follow-up that updates their expectations for unslothai#10584's new recovery orchestration.
…p 14 pending-semantics tests The followChatGenerationRun mock now wraps tool events in _toolEvent (matching the SSE decoder), and the runtime store mock gains the four tool methods (setToolConfirmation, clearToolConfirmation, appendToolLiveOutput, clearToolLiveOutput) that the replay options call on every tool_end. 14 edge-case tests around publish batching, cursor semantics and id-less card identity are skipped pending a follow-up that updates their expectations for unslothai#10584's new recovery orchestration.

Recovery rebuilt replies from text and reasoning alone. Tool cards and other structured parts in a saved reply could disappear, and saving the rebuilt message made that loss persistent.
This change:
tool_start,tool_end, anddocument_citationsevents so later calls, completed results, and citation sources survive recovery and reloads.New tool-enabled requests continue to use the existing legacy streaming route. This PR protects tool-containing replies that reach recovery; it does not enable durable tool runs or change inference or hardware selection. Text-only recovery retains its existing replay cursor. Older unfinished cards without backend identities need an additional history replay to recover their mapping.
Validation:
git diff --checkpasses.The full frontend suite (7,144 tests),
npm run typecheck, andnpm run buildpassed at1b1c9211. The latest changes were validated with the focused checks above; the full suite was not rerun locally, and CI was not awaited.