fix(session): use parentID instead of timestamp for loop exit condition#21334
fix(session): use parentID instead of timestamp for loop exit condition#21334YLRong wants to merge 1 commit into
Conversation
|
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
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
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