Skip to content

Studio: stop a recovered chat crashing on a duplicate tool call key - #12442

Merged
danielhanchen merged 3 commits into
mainfrom
studio-recovery-duplicate-tool-key
Oct 1, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
studio-recovery-duplicate-tool-key

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Reopening a chat whose tool turn was being recovered could crash the thread view with:

Something went wrong!
Duplicate key toolCallId-<call id>:<run id>:<seq> in tapResources

Recovery mints a tool card id as <backend id>:<run id>:<seq> when it replays a tool_start above the stored cursor. It only looked for an existing card among cards still waiting on a result. If the saved message already held that very card, finished, past its stored cursor, recovery minted it again with the same id, and assistant-ui refuses to render two parts with one key. The same gap also let a card the live stream saved (stamped generationToolCallId = <run id>:<seq>) be recovered as a second, duplicate card.

A single recovery cannot mint one run:seq twice (apply drops any seq it already applied), so the crash needs the card to be in the saved content already. The fix reuses that card: before minting, recovery now looks for a carried tool card with the same minted id or the same generationToolCallId. Matching on the exact run:seq keeps reused backend ids in later rounds on separate cards.

Reported in #12435 (and earlier in #10288).

Changes

  • studio/frontend/src/features/chat/utils/generation-tool-recovery.ts: reuse a carried card for a replayed tool_start instead of minting a duplicate.
  • studio/frontend/tests/generation-tool-recovery.test.ts: two regression tests, one for a finished recovered card saved past the cursor, one for a finished live card saved past the cursor.

Testing

  • New tests on main: both fail. The first produces ['call_0:run:4897', 'call_0:run:4897'], the exact key shape in the report; the second produces ['call_0:live-uuid', 'call_0:run:4897'].
  • With the fix: node --experimental-strip-types --test tests/generation-*.test.ts tests/chat-generation-*.test.ts tests/stuck-generation-run.test.ts gives 156 passed, 0 failed.
  • tsc -p tsconfig.app.json --noEmit clean; no new biome diagnostics on the changed lines.

Before / after

A real Studio build of each side, Chromium, with a thread seeded directly in studio.db (no model needed): a completed durable run whose events are text, read_file start, read_file end, text, and an assistant message saved with the finished recovered card one event past its stored cursor. Opening the thread starts recovery.

  • Before (merge base 16c112906): the thread crashes to "Something went wrong!" with Duplicate key toolCallId-call_0:<run id>:3 in tapResources in the page error.
  • After (38ee7d9ec): one read_file card and the full reply.

Before: Something went wrong. After: the recovered thread renders with one read_file card

@danielhanchen danielhanchen self-assigned this Oct 1, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T14:20:04.658261Z 38ee7d9 Manual request
🔒 Security Review ⚠️ Failed 2026-10-01T14:15:48.828777Z 5bdf6e2 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-01T14:15:45.970762Z 5bdf6e2 PR opened
🔒 Security Review 🔄 Running since 2026-10-01T14:15:45.123441Z 5bdf6e2 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 38ee7d9ec3

ℹ️ 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".

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant