fix(session): use parentID instead of timestamp for loop exit condition#21334
Open
YLRong wants to merge 1 commit intoanomalyco:devfrom
Open
fix(session): use parentID instead of timestamp for loop exit condition#21334YLRong wants to merge 1 commit intoanomalyco:devfrom
YLRong wants to merge 1 commit intoanomalyco:devfrom
Conversation
Contributor
|
The following comment was made by an LLM, it may be inaccurate: I found potentially related PRs that address similar issues:
These PRs appear to be addressing the same or very similar issues with the prompt loop exit condition and clock skew. You should verify if PR #14307 is a previous attempt at the same fix or if there's overlap in scope. |
e91f050 to
f5dc565
Compare
Replace timestamp-based comparison with parentID check to prevent duplicate assistant responses caused by clock skew between client and server. When client and server have different system times, the ID-based comparison lastUser.id < lastAssistant.id fails, causing the prompt loop to continue and generate a second assistant response. This fix uses the explicit parentID relationship to determine if the assistant message is a response to the last user message, which is immune to clock skew issues. For backward compatibility, the timestamp comparison is kept as a fallback for messages that may not have parentID set. Fixes anomalyco#14935
This was referenced Apr 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #14935
Type of change
What does this PR do?
Fixes duplicate assistant responses caused by clock skew between client and server systems.
Problem: When client and server have different system times (clock skew), the prompt loop's exit condition
lastUser.id < lastAssistant.idfails because message IDs are timestamp-based. This causes the loop to continue and generate a second assistant response for the same user message.Solution: Replace timestamp-based comparison with explicit
parentIDrelationship check. The assistant message'sparentIDfield already stores the ID of the user message it responds to, making this a more reliable indicator than timestamp comparison.The change adds:
lastAssistant.parentID === lastUser.idThis fix is needed because the timestamp-based approach assumes client and server clocks are synchronized, which is not always true in real-world deployments.
How did you verify your code works?
Tested with OpenChamber 1.9.3 + OpenCode 1.3.17:
The fix uses existing fields (parentID) that are already populated correctly, so no migration is needed.
Screenshots / recordings
N/A - This is a backend logic fix
Checklist