Skip to content

fix(session): use parent link for prompt loop exit#29038

Open
BestSithInEU wants to merge 1 commit into
anomalyco:devfrom
BestSithInEU:fix/session-prompt-loop-parent
Open

fix(session): use parent link for prompt loop exit#29038
BestSithInEU wants to merge 1 commit into
anomalyco:devfrom
BestSithInEU:fix/session-prompt-loop-parent

Conversation

@BestSithInEU
Copy link
Copy Markdown

@BestSithInEU BestSithInEU commented May 23, 2026

Issue for this PR

Fixes #26220

Type of change

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

What does this PR do?

The prompt loop exit check used lastUser.id < lastAssistant.id to 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:

lastAssistant.parentID === lastUser.id

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 parentID approach, but rebases it onto current dev where prompt-effect.test.ts no longer exists, and adds focused tests against the current code.

How did you verify your code works?

  • bun test test/session/prompt-loop.test.ts
    • 6 pass, 0 fail
  • bun run typecheck
    • passed
  • PATH=/usr/bin:/bin bun test test/tool/write.test.ts --timeout 15000 -t "restores BOM after formatter strips it"
    • 1 pass, 0 fail
  • git push git@github.com:BestSithInEU/opencode.git fix/session-prompt-loop-parent
    • pre-push bun turbo typecheck: 15 successful, 15 total

I also attempted the full bun test --timeout 30000, but it did not complete in this environment because the unrelated write formatter test hung when node resolved through the local mise shim. Bypassing the shim made that isolated test pass.

Screenshots / recordings

N/A

Checklist

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

@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

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:

  1. PR fix(session): use parentID instead of timestamp for loop exit condition #21365 - fix(session): use parentID instead of timestamp for loop exit condition

    • This appears to be a previous attempt at the same fix, using parentID logic instead of timestamp comparison
  2. PR fix(session): use transcript position instead of lexical ID compare in prompt loop #24379 - fix(session): use transcript position instead of lexical ID compare in prompt loop

    • Related fix for the prompt loop exit condition, using a different approach
  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

    • Another related fix attempting to improve the loop exit condition

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.

@BestSithInEU
Copy link
Copy Markdown
Author

I noticed the related prior work flagged by the bot: #21365, #24379, #24544, and #28637.

This PR is closest to #21365: it keeps the parentID approach, but rebases it onto current dev where prompt-effect.test.ts no longer exists, extracts the predicate for focused coverage, and includes current passing validation.

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.

Bug: OpenCode enters infinite loop after tool calls complete (Zen/big-pickle)

1 participant