fix: wait for an in-progress reply before sending after a reload - #59
Open
asasemahmed wants to merge 1 commit into
Open
asasemahmed wants to merge 1 commit into
asasemahmed wants to merge 1 commit into
Conversation
Reloading the app while a reply is still running, then sending a message, fails with "Thread <uuid> is locked" and a Retry button. The chat marks the conversation loaded as soon as replayed messages arrive, while connectAgent is still attached to the running reply, so the next turn is sent while the server still holds the thread lock. - Keep new turns queued until connectAgent returns. It returns once the thread is idle, so the earlier reply finishes streaming first and queued messages then send automatically. - If a turn is still refused with agent_thread_locked (for example, another device is running the thread), keep the message unsent and on hold instead of showing the raw lock error. The server rejected it before running it, so no work was done. - runConversationTurn now reports the first, specific failure code; CopilotKit follows a lock with a generic agent_run_failed.
Contributor
|
Needs a rebase before merge. It conflicts with #54 in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Reloading the app while a reply is still running, then sending a message, fails with:
A Retry response button appears next to it, and retrying would ask for the earlier reply again.
The cause:
hydrate()marks the conversation loaded as soon as replayed messages arrive, whileconnectAgentis still attached to the running reply. The next turn is therefore sent while the server still holds the thread lock. CopilotKit reports the refusal asagent_thread_locked, then again asagent_run_failed.Now:
connectAgentreturns. In connect mode it returns once the thread is idle. So after a reload, the earlier reply finishes streaming in first, and queued messages then send automatically. The history still shows immediately, and the composer stays usable.agent_thread_locked(for example, another device is running the thread), the message goes back first in the queue and the queue is put on hold, instead of showing the raw lock error. The existing Send queued messages control resumes it. The server refused the turn before running it, so no work was done.runConversationTurnreports the first, specific failure code.ConversationTurnErrorcarries that code.Verification
tests/conversation-sdk.test.tsuses the realCopilotKitCore: a run refused withAgentThreadLockedErrorrejects with codeagent_thread_locked. It failed beforerunConversationTurnkept the first report.apps/mobile/test/conversation-queue.test.ts: a refused message is restored first in line, once.pnpm typecheckpasses. Biome reports no issues for the changed files.pnpm test: 172 passed, 1 failed. The failure isDocker subprocess uses literal argv…, which fails on Windows with or without this change.AGENT_BACKEND=modeland Rich Threads:main: "Thread … is locked" and Retry response.Integration limits
Tested on web. The change is in shared chat state handling, and native layout is unchanged.