You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SessionPrompt.run used lastUser.id < lastAssistant.id to decide whether a finished assistant message should stop the prompt loop. Web clients can submit their own user message IDs, and those IDs can sort after the server-created assistant ID even when the assistant is the final answer for that user message.
This switches the stop condition to the actual turn relationship: lastAssistant.parentID === lastUser.id. The loop now exits when the latest finished assistant answers the latest user message, independent of client/server ID ordering.
The regression test seeds a Web-style user ID that sorts after its assistant ID and verifies the loop returns that finished assistant without making another LLM request.
How did you verify your code works?
PATH="$HOME/.bun/bin:$PATH" bun test test/session/prompt.test.ts -t "loop exits when a client user id sorts after its assistant id"
Red before the fix: expected the seeded assistant ID, received a new assistant ID from an extra LLM call.
Green after the fix: 1 pass, 0 fail.
PATH="$HOME/.bun/bin:$PATH" bun test test/session/prompt.test.ts
55 pass, 0 fail.
PATH="$HOME/.bun/bin:$PATH" bun typecheck from packages/opencode.
PATH="$HOME/.bun/bin:$PATH" bun x prettier --check src/session/prompt.ts test/session/prompt.test.ts.
git diff --check.
PATH="$HOME/.bun/bin:$PATH" .husky/pre-push currently fails in unrelated @opencode-ai/console-support typecheck because local dependencies/generated console-core modules are missing (@solidjs/*, solid-js/jsx-runtime, vite, @opencode-ai/console-core/*). The touched opencode package typecheck completed separately and passed.
Also addresses runLoop exit condition issues with ID/timestamp ordering
Note: PR #29038 appears to be the closest duplicate, as it directly addresses using the parent link for prompt loop exit—which is exactly what PR #29480 implements. You may want to verify which PR was created first and whether they're addressing the same underlying issue (#29478).
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
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.
Issue for this PR
Closes #29478
Type of change
What does this PR do?
SessionPrompt.runusedlastUser.id < lastAssistant.idto decide whether a finished assistant message should stop the prompt loop. Web clients can submit their own user message IDs, and those IDs can sort after the server-created assistant ID even when the assistant is the final answer for that user message.This switches the stop condition to the actual turn relationship:
lastAssistant.parentID === lastUser.id. The loop now exits when the latest finished assistant answers the latest user message, independent of client/server ID ordering.The regression test seeds a Web-style user ID that sorts after its assistant ID and verifies the loop returns that finished assistant without making another LLM request.
How did you verify your code works?
PATH="$HOME/.bun/bin:$PATH" bun test test/session/prompt.test.ts -t "loop exits when a client user id sorts after its assistant id"PATH="$HOME/.bun/bin:$PATH" bun test test/session/prompt.test.tsPATH="$HOME/.bun/bin:$PATH" bun typecheckfrompackages/opencode.PATH="$HOME/.bun/bin:$PATH" bun x prettier --check src/session/prompt.ts test/session/prompt.test.ts.git diff --check.PATH="$HOME/.bun/bin:$PATH" .husky/pre-pushcurrently fails in unrelated@opencode-ai/console-supporttypecheck because local dependencies/generated console-core modules are missing (@solidjs/*,solid-js/jsx-runtime,vite,@opencode-ai/console-core/*). The touchedopencodepackage typecheck completed separately and passed.Screenshots / recordings
N/A - backend/session loop fix.
Checklist