Uh oh!
There was an error while loading. Please reload this page.
fix(session): stop prompt loop by assistant parent - #29480
Conversation
The following comment was made by an LLM, it may be inaccurate: I found several related PRs that address similar prompt loop exit condition issues: Potential Duplicates/Related PRs:
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). |
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