fix: forking a long conversation breaks chat structure #4777
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.
ref: PR #4772 and issue #4761
I think I've found the culprit.
This issue is due to the forking doesn't copy over the
createdAt
attribute of the messages, so the message list queried might be our of order, hence a messed up tree.The main change is here:
https://github.com/xyqyear/LibreChat/blob/cb98456ba034a86857adaeaa564d2ac7f17cebc8/api/models/Message.js#L80-L86
If
timestamps
is true, then mongoose will overridecreatedAt
with the current time, which is the default iftimestamps
is set to true for the schema.Testing
I've modified exiting tests and the api tests passed.
However, this PR should not be merged right away and should be further investigated to make sure importing doesn't break since importing use the same mechanics.
The current behavior for importing I believe is to just use the default
createdAt
time that mongoose auto inserts. So imports a conversations with more than 16 messages should be having the same issue (needs testing).