Repository navigation
feat(chat): faithful replay of durable runs — parts accumulator, catch-up watermark, card fidelity - #10910
feat(chat): faithful replay of durable runs — parts accumulator, catch-up watermark, card fidelity#10910CelesteHeartsong wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e48e4f4b84
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
This carries the whole of #10365 as well as the replay work, and it also flips UNSLOTH_STUDIO_DURABLE_TOOL_TURNS on by default in studio/backend/routes/chat_generation_runs.py so every tool-enabled turn leaves the legacy stream. Could you land #10365 first and rebase so this is the replay-only diff, and confirm the approval park timeout drop from 3600s to 300s in state/tool_approvals.py is intended? |
|
That test reads the generator source and asserts the partial-save path is not wrapped in a Worth deciding which side is right before changing either: if the accumulator genuinely needs the guard, the test is the thing to revisit, but the behaviour it is protecting (an immediate failure still shows as interrupted rather than vanishing) looks deliberate. The |
Yep yep, the plan was to land #10365 first (this PR was a split from that PR for just the replay section) I believe both of your issues are inherited form #10365 as well. state/tool_approvals.py and routes/chat_generation_runs.py are byte-identical between this branch and #10365, so once #10365 lands and I rebase, the DURABLE_TOOL_TURNS default flip and the park-timeout change both drop out of this diff — they'll have landed with #10365. On the 300s: yes, intended. It only applies to durable/parked runs (cancel_event.durable); the legacy path still uses the 3600s ceiling. A parked approval denying after ~300s (env-tunable via UNSLOTH_STUDIO_TOOL_APPROVAL_TIMEOUT_S) is the deliberate tradeoff — it feeds the rejection back to the model so an unattended agent adapts and keeps going instead of holding its slot for the full lease window. If you think 300s is too aggressive for "grab your phone," I'd rather set that number in #10365 where it's introduced. |
Agreed the behavior is the deliberate one — an immediate failure should read as interrupted rather than vanish. The guard was the bug, so I removed it in #10365 (6946ed1) and kept the test. This branch still carries the pre-fix guard (it branched before that commit), which is why this subtest fails here; once #10365 lands and I rebase onto main it picks up the fix and goes green with no change on this side. Happy to cherry-pick 6946ed1 onto this branch now if you'd rather see it red-free sooner than waiting on the merge. And noted on Core — thanks, that's the unsloth-zoo-main issue (unslothai/unsloth-zoo#1219), unrelated to this work. |
|
Cherry-picked 6946ed1 onto this branch (c82ba28) so the frontend reds clear without waiting on #10365's merge — a turn that fails before any text is still saved as interrupted passes now, and both source-pin suites are green (chat-continuation 94/94, stuck-generation-run 34/34). That should take Frontend build + bundle sanity and Frontend unit tests (Windows) to green; the only reds left will be the three Core checks from unsloth-zoo main (unslothai/unsloth-zoo#1219). The later rebase onto main will absorb this same change, so expect a trivial already-applied dedupe there. |
…ai#10365 conflicts) unslothai#10365 landed on main after this branch forked from the shared dev base, so its reviewed durable-turns code collided with the copy carried here. Resolved per file: - backend state/tool_approvals.py, tests/test_tool_approvals.py and tests/studio/test_desktop_reliability_frontend_contract.py: take main's reviewed version (this PR has no unique work in them). - core/inference/chat_generation_runs.py: take main's reviewed park/lease logic. - routes/chat_generation_runs.py, durable-gate.ts, durable-gate.test.ts and test_multi_chat_prompt_queue_contract.py: keep THIS PR's media-turns work - UNSLOTH_STUDIO_DURABLE_MEDIA_TURNS toggle (default on), media removed from the frontend gate, and the matching "media turns are durable" assertions. - chat-adapter.ts: keep shapeToolResult shaper + media-durable gate args; take main for import formatting and the partial-yield block (unslothai#10811 removed that guard); drop the duplicate local isMcpImageToolResult (imported from utils/tool-result-shape). - runtime-provider.tsx: keep this PR's self-consistent recovery impl. - generation-tool-recovery.test.ts: union the mock store stubs. REVIEW NOTE: main's media-refusal branch also detects input-audio / embedded-image / video inside messages[] (added after this branch forked); this branch's toggle-off refusal only checks top-level _MEDIA_FIELDS. Decide whether to fold those in. Follow-ups before landing: tsc -b + npm test; backend test_chat_generation_runs + test_tool_approvals; reconcile the shared replay files with unslothai#10910 (keep unslothai#10910's).
…ngine unslothai#10910 replaced createGenerationToolRecovery's arm/disarm lifecycle and the client-side parseThinkTags flag with createRecoveryReplay (frame-type reasoning split + toolConfirmations register/resolve). Update literal-think-when-thinking-off and seeded-approval-terminal-run to pin that new wiring instead of the removed call sites.
…ngine unslothai#10910 replaced createGenerationToolRecovery's arm/disarm lifecycle and the client-side parseThinkTags flag with createRecoveryReplay (frame-type reasoning split + toolConfirmations register/resolve). Update literal-think-when-thinking-off and seeded-approval-terminal-run to pin that new wiring instead of the removed call sites.
…h-up watermark, card fidelity Rebased onto main after unslothai#10365 landed, so this is the replay-only delta: no durable-gate, approval-timeout, or DURABLE_TOOL_TURNS changes. A reopened tab renders tool cards at their offsets, thought cards with their tags and seconds, a still-parked call with Approve/Deny, and a still-running call's streamed stdout; the catch-up watermark opens on where the generation is rather than re-typing from character zero.
18cb65a to
0fd68b0
Compare
|
Rebased onto current main, which now has #10365, so this PR is a single commit containing only the replay work. None of #10365's changes (state/tool_approvals.py, routes/chat_generation_runs.py, durable-gate.ts) are in this diff anymore. On the partial-save guard: it's removed from chat-adapter.ts, there's no if (partialContent.length > 0) wrapping the yield { content: partialContent, … incomplete: { … } }. Locally chat-continuation is green 110/110 including "a turn that fails before any text is still saved as interrupted", and the full frontend suite passes with 0 failures. Waiting on CI to confirm. |
|
Updated the description to remove stated dependency on #10406. This PR now contains aspects of the replay solution that are also being used in the other PR, but that functionality is more fitting to be worked on and completed in this PR. Once this PR is finished then we can wrap up this whole project with the durable media turns in #10406. |
|
Thanks for this work. Since this branch was cut, main has absorbed most of it: the catch-up publish gate landed in #12464, and seeded approval re-raise, tool-card offsets and result shaping live in Rebased as-is, this diff would remove main's terminal-run guard and pending check on seeded approvals, the The remaining piece, showing a still-running tool's stdout to a reopening tab, would be very welcome as a small focused PR on top of current main's recovery. Closing this one in favor of that. |
|
Thank you for getting the functionality merged in! I've noticed on main already that the main issue I was trying to resolve is fixed. (Phone going to sleep used to cancel running generations) |
TL;DR
Faithful replay of durable runs: a reopened tab renders tool cards at their offsets, thought cards with their tags and seconds, a still-parked call with its Approve/Deny buttons, and a still-running call's streamed stdout — instead of flattening everything to one string and re-parsing per publish. A catch-up watermark means you open on where the generation is, not on a re-type from character zero.
What
createRecoveryReplay): folds persisted frames into a part array one at a time, stamping each tool call with the offset it ran at. Text/reasoning runs extend in place; tool frames land on the card their id names. Publish is gated on achangedflag instead of firing per event.createdAt, and a mid-flight thought joined by a second tab is timed by both.tool_startat or below the follower's cursor — the seed itself re-raises it, keyed${scopeId}:${approvalId}exactly as live keyed it, and Approve/Deny renders in THIS tab.Depends on
Tests
chat-generation-replay-parts.test.ts— cards keyed by minted ids, offset placement, fuller-output preferencechat-generation-replay-durations.test.ts— seeded groups, frame-clock timinggeneration-recovery-catch-up.test.ts— single catch-up write, watermark never drags backwardsgeneration-tool-recovery.test.ts— parked approval re-raise, stdout visibilitydurable-gate.test.ts— gate truth table (carried from feat(chat): make agentic turns survive tab-close #10365)