Skip to content

fix(session): use parentID instead of message ID ordering in prompt loop#17010

Open
ShenAC-SAC wants to merge 1 commit intoanomalyco:devfrom
ShenAC-SAC:codex/fix-web-session-loop
Open

fix(session): use parentID instead of message ID ordering in prompt loop#17010
ShenAC-SAC wants to merge 1 commit intoanomalyco:devfrom
ShenAC-SAC:codex/fix-web-session-loop

Conversation

@ShenAC-SAC
Copy link

@ShenAC-SAC ShenAC-SAC commented Mar 11, 2026

Issue for this PR

Closes #17012

Type of change

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

What does this PR do?

Fixes an infinite assistant loop in web sessions.

SessionPrompt.loop() was using message ID ordering to decide whether the latest finished assistant message belonged to the latest user message:

lastUser.id < lastAssistant.id

That is not reliable for web prompts, because the user messageID is generated in the browser while assistant message IDs are generated on the server.

This change replaces that check with:

lastAssistant.parentID === lastUser.id

This is the correct relationship because parentID directly links an assistant message to the user message it answers.

How did you verify your code works?

Added a regression test covering a web-style prompt flow where the user messageID is provided externally and does not sort safely against a later server-generated assistant message ID.

Also verified locally that prompt processing stops after the first finished assistant response instead of creating repeated assistant messages for the same user prompt.

Screenshots / recordings

N/A

Checklist

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

@github-actions
Copy link
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 github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Mar 11, 2026
@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Found a potential related PR:

PR #14307: fix: use parentID matching instead of ID ordering for prompt loop exit and message rendering
#14307

This appears to be addressing the same issue - replacing ID ordering with parentID matching for the prompt loop. This could be a duplicate or previous attempt at fixing the same problem.

@github-actions github-actions bot removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Mar 11, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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 sessions can loop indefinitely when user message IDs are generated on the client

1 participant