Repository navigation
Studio: keep project chat runs alive across view switches - #9129
Conversation
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
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". |
|
Confirmed this hits chat-page.tsx where ProjectLanding mounts its own ChatRuntimeProvider, so leaving the project view mid-response aborts the run while the single chat view survives the same navigation. Will get this reviewed. |
A staged composer attachment follows you into the next project (
|
mahiatlinux
left a comment
There was a problem hiding this comment.
Review posted as a comment above.
…nder, keep base alive under compare
|
Re-checked at this head: the composer no longer carries a staged attachment across a nonce change, and the outgoing thread id is now captured in render rather than an effect, so the Back-into-a-project guard actually fires. Looks right to me. |
|
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". |
|
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". |
Before/after evidence for #8908Two isolated Studio installs, one per side, each built from its own checkout with its own
Same scene on both sides, driven through the real UI: create a project, send from the project composer, then click another chat in the sidebar mid-response (an in-app row click, never a reload — a reload would abort the run on both sides and prove nothing), wait out the rest of the answer, and come back. The answer is a fixed 40-token stream that ends the moment its request is aborted, the way the backend does when the client disconnects. That makes the abort a number rather than a judgement call: both sides left at exactly token 5.
BEFORE the chat comes back holding Also in this round: rebased on current |
…ing was away Retaining the chat across a view switch is what this PR added; at the merge base leaving the project view unmounted the landing, so there was nothing to restore and the question could not arise. Nothing else clears the retained id. It is component state, so the sidebar's global delete does not reach it, and compare does not hold the chat as the store's active thread, so the reset inside deleteChatItems does not fire either. A chat deleted while compare was on screen therefore came back on exit: the landing rendered a conversation storage no longer has, with a composer pointed at it. Check the tombstone before restoring, and fall through to the existing rotate so the landing is left with a fresh thread to send into rather than a dangling id.
Retaining a chat across a view switch added three places that put a retained id back: ProjectLanding's resume effect, NonceThreadResumeRestore, and the remembered-nonce reopen. All three ask the runtime whether it still knows the thread. Studio deletes by tombstoning storage rather than calling runtime.threads.delete(), so after a delete the item and its remoteId both survive and all three still answer yes. Guarding only the landing (3741dc2) therefore fixed nothing on its own: the other two republish the same id. Both now check the tombstone as well, on remoteId, which is the id storage and the sidebar delete agree on. The reopen falls through to the existing clear, which is what a nonce owning nothing looks like.
createStudioDbAdapter files a materializing thread under the projectId its closure holds, and useRemoteThreadListRuntime hands the core a fresh adapter on every render through __internal_setOptions, so initialize() reads the provider's LATEST project. That used to be the same project the send was made in. Two things changed it. assistant-ui's BaseComposerRuntimeCore.send() empties the composer and then awaits every incomplete attachment through the adapter before calling handleSend, and Studio's PDF, DOCX and text adapters do their extraction there, so a document send reaches the runtime seconds after the click. And the shared provider survives a project switch, so that late send is still alive to land: before, switching projects unmounted the provider and it died with it. Together: send a document into a new project chat, switch projects while it converts, and the chat is created in, and persisted under, the project the user switched TO. The composer now stamps the send with its provider's project before send() starts awaiting, and initialize() files the thread under that. Per send rather than per thread creation, because switchToNewThread() reuses an untouched blank thread, so one local id can be the current new thread in two projects in a row. A claim of null wins too: it means the send was made from outside any project.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ff89e6aa82
ℹ️ 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".
| useEffect(() => { | ||
| if (compareRunning) return; | ||
| if (anyRunning && listedPairRef.current === pairId) return; | ||
| listedPairRef.current = pairId; | ||
| let isActive = true; | ||
| setThreadsSettled(false); | ||
| listStoredChatThreads({ pairId }) |
There was a problem hiding this comment.
Disable compare sends until the first thread list settles
When an existing compare is opened while the retained base chat is still running, this exception starts the initial asynchronous list with both compare panes mounted on blank local threads, but SharedComposer remains interactive. If the user sends before listStoredChatThreads resolves, the prompt starts on those blank threads; the callback then installs the stored IDs, causing ThreadAutoSwitch to move both panes away mid-run and potentially persist duplicate threads for the pair. The same pattern is repeated in GeneralCompareContent; gate the composer until the initial list settles or defer applying the listed IDs if a compare run began meanwhile.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The window is real, but it is not this PR's and the exception did not create it.
At the merge base 27ca0c9 the same effect already started listStoredChatThreads asynchronously with threadsSettled false, and SharedComposer was rendered on active alone there too, with no threadsSettled gate anywhere in either variant. So on main, every ordinary compare open has this exact window: panes mounted on blank local threads, composer live, ids installed when the read resolves. Opening compare from a running base chat was reachable on main as well (that is #8908 itself, which killed the base run but still opened compare), so even the entry path you describe is not new.
What the first-list exception changed is which situations reach a window that already existed, not what happens inside it. Duration is the same single IndexedDB read, and the consequence is the same: ThreadAutoSwitch is not paused for a compare pane either before or after this PR, so the mid-run switch would behave identically.
So I am leaving it here rather than widening the PR further. Gating the composer on threadsSettled looks like the right fix and I think it is worth its own issue, since it also wants a decision about what the composer should show while the pair's threads load, which is a UX question this PR has no basis to answer.
|
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". |
Comment-only. Collapses the longest explanations to the fact that is not recoverable from the code, and drops restatements of what the next line does.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c0847a45f
ℹ️ 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".
| return; | ||
| } | ||
| if (!activeThreadId) { | ||
| if (resumed && pendingNewThreadId) { |
There was a problem hiding this comment.
Restore project chats that materialize while compare is open
If the user sends from a project landing and opens Compare before the first history write publishes activeThreadId, pendingNewThreadId is still null when the landing is backgrounded. Both new publication paths deliberately stand down while backgrounded, so the run can materialize and finish without ever filling that state; on return this condition skips restoration even though the retained runtime's main thread now has a remote ID, leaving the completed conversation hidden behind the project overview. On resume, recover the materialized main thread from the retained runtime when pendingNewThreadId has not yet been observed, analogous to NonceThreadResumeRestore.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The window is real, but the restoration already happens; it just is not this condition that does it.
NonceThreadResumeRestore is enabled for the project landing too. The shared provider is handed newThreadNonce={projectNewThreadNonce} with no initialThreadId in project mode, so its enabled gate (base, no pairId, a nonce, no initialThreadId, not backgrounded) is satisfied, and it does exactly what you describe: on resume it reads mainThreadId off the retained runtime, requires a remoteId, and publishes it.
I did not want to take the effect ordering on trust, so I simulated it with both effects sliced verbatim and replayed with React's order (child before parent, then a re-render from the store write). On the resume commit: ProjectLanding runs first and skips, as you say; NonceThreadResumeRestore then publishes mainThreadId; the store write re-renders the landing, whose effect now sees a non-null activeThreadId that matches neither initialActiveThreadId (null, since openProjectLanding cleared it before the landing mounted) nor pendingNewThreadId, so it adopts and sets pendingNewThreadId. Result: activeThreadId and pendingNewThreadId both the materialized thread, and rotations: 0, so the rotate branch never fires and nothing is stranded.
So the landing does come back to the conversation. Leaving this as is rather than adding a second restore path that would race the first.
…h send paths The project claim fixed one field on one path. The root cause is broader: initialize() snapshots project, temporary status, model and creation time when the thread MATERIALIZES, which used to be the same tick as the send. It is not any more, because send() awaits document extraction and the shared provider survives the view switch, and navigating in between moves all of them: the adapter is rebuilt with the new project, and ChatPage's view effect clears incognito for anything that is not a fresh single chat. So a document sent from a Temporary Chat and followed by a project switch was created and persisted as a normal project chat, with the content the user had marked temporary. Same shape for the model the chat records. The claim now carries the whole creation snapshot, and the prompt queue stamps it too: that path calls initialize() on a fresh thread itself and never passes the composer, so a queued first prompt was filed wherever the user had moved to, and the run picked up that project's instructions and sources. ensureThreadRecord already took all four as snapshot parameters for exactly this reason; this is what lets the caller supply them from the send.
The creation claim fixed where the thread record is FILED. The run resolves its project separately: createOpenAIStreamAdapter captures activeProjectId before its first await and feeds it to rememberComposerProjectForRun, which decides the instructions, RAG sources and sandbox the response is generated with. Its comment already noted that a send survives navigation, and leaned on the fallback only being consulted while the thread's row is missing. That is exactly the window it is wrong in: initialize() returns without awaiting its row write, so a fresh document send reaches the run with no row and, by then, possibly another project on screen. The run now prefers the same send-time stamp, so history and generation agree. The claim is no longer consumed on read: its two readers, initialize() and the run adapter, have no ordering guarantee between them, and releasing on the first starved the second. Expiry bounds it instead, which is safe because a persisted row makes ensureThreadRecord early-return and a fresh thread always gets a fresh local id.
|
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". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 605941edae
ℹ️ 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".
| if (switchStateNow.attempt !== attempt) return; | ||
| if (switchStateNow.activeNonce !== nonce) return; | ||
| clearAttachments(); |
There was a problem hiding this comment.
Disable the composer while the new-thread switch is pending
When switchToNewThread() is delayed, the new-chat view already exposes an interactive composer while clearAfterSwitch remains armed. If the user attaches a file during that interval, it is added to the shared outgoing composer and this completion handler clears it along with the attachments that were intentionally being discarded, silently losing a file selected for the new chat. Gate the composer until this switch attempt lands, or clear only the attachment snapshot that existed when the switch began.
Useful? React with 👍 / 👎.

Fixes #8908. A chat started inside a project ran under ProjectLanding's own ChatRuntimeProvider; navigating to another chat mid-response unmounted it, aborting generation (the backend cancels on client disconnect), so the user returns to a truncated "Response stopped." while the identical navigation in a non-project chat lets the run finish, because the single-chat view already shares one provider across thread switches.
This hoists a single ChatRuntimeProvider above the project/single view switch (compare mode keeps its per-pane providers) and lifts the project's new-thread nonce to ChatPage so the shared provider and the project composer agree on it extending the app's existing keep-alive pattern rather than adding a new mechanism.