Skip to content

fix(session): stop prompt loop by assistant parent#29480

Closed
YOMXXX wants to merge 1 commit into
anomalyco:devfrom
YOMXXX:fix/session-stop-parent-check
Closed

fix(session): stop prompt loop by assistant parent#29480
YOMXXX wants to merge 1 commit into
anomalyco:devfrom
YOMXXX:fix/session-stop-parent-check

Conversation

@YOMXXX
Copy link
Copy Markdown

@YOMXXX YOMXXX commented May 27, 2026

Issue for this PR

Closes #29478

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

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.

Screenshots / recordings

N/A - backend/session loop fix.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions
Copy link
Copy Markdown
Contributor

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:

  1. PR fix(session): use parent link for prompt loop exit #29038 - fix(session): use parent link for prompt loop exit

  2. PR fix(session): order prompt loop by message creation #29035 - fix(session): order prompt loop by message creation

  3. PR fix(session): use server timestamps instead of IDs in runLoop exit condition #28637 - fix(session): use server timestamps instead of IDs in runLoop exit condition

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).

@thdxr thdxr closed this May 27, 2026
@anomalyco anomalyco deleted a comment from YOMXXX May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web can persist duplicate final answers when client message IDs sort after assistant IDs

2 participants