fix(session): use parent link for prompt loop exit#29038
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Based on my search, I found several related PRs that address similar session prompt loop logic: Potential Related PRs:
These PRs are all addressing the same underlying issue (prompt loop exit logic) that your PR tackles. However, since your PR (29038) is the current one and the others appear to be closed/merged from earlier attempts, they're historical rather than true duplicates. Your PR appears to be the most recent and targeted fix for this issue. |
|
I noticed the related prior work flagged by the bot: #21365, #24379, #24544, and #28637. This PR is closest to #21365: it keeps the |
Issue for this PR
Fixes #26220
Type of change
What does this PR do?
The prompt loop exit check used
lastUser.id < lastAssistant.idto decide whether the latest assistant response belonged to the latest user turn. That relies on message ID ordering.This changes the check to use the actual message relationship instead:
Assistant messages already record the user message they reply to, so this is a more direct way to decide whether the loop can exit.
I also extracted the predicate into
shouldExitPromptLoop()so the edge cases can be tested directly.Prior related attempts include #21365, #24379, #24544, and #28637. This PR is closest to #21365: it keeps the
parentIDapproach, but rebases it onto currentdevwhereprompt-effect.test.tsno longer exists, and adds focused tests against the current code.How did you verify your code works?
bun test test/session/prompt-loop.test.tsbun run typecheckPATH=/usr/bin:/bin bun test test/tool/write.test.ts --timeout 15000 -t "restores BOM after formatter strips it"git push git@github.com:BestSithInEU/opencode.git fix/session-prompt-loop-parentbun turbo typecheck: 15 successful, 15 totalI also attempted the full
bun test --timeout 30000, but it did not complete in this environment because the unrelated write formatter test hung whennoderesolved through the local mise shim. Bypassing the shim made that isolated test pass.Screenshots / recordings
N/A
Checklist