-
-
Notifications
You must be signed in to change notification settings - Fork 95
fix: avoid reversing chat history messages #384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
aa9be19
to
9d4f57a
Compare
WalkthroughAdjusted resend order in ChatHistoryHandler for PartialBlocking: last N messages are selected with Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller as Caller
participant CH as ChatHistoryHandler
participant Store as MessagesStore
participant Client as PlayerClient
Caller->>CH: resendMessages(status=PartialBlocking(N))
CH->>Store: retrieve messages
Note over CH,Store: Select last N via takeLast(N)
CH->>Client: send messages chronological (oldest → newest)
CH->>CH: set status to PartialBlocking(0)
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks (2 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Poem
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/interaction/ChatHistoryHandler.kt (2)
258-260
: Avoid allocation when there are no new messages.Short-circuit to skip the
toList()
copy whennewMessages == 0
.Apply this diff:
- messages.toList().takeLast(status.newMessages).forEach { it.send(player) } + if (status.newMessages > 0) { + messages.toList().takeLast(status.newMessages).forEach { it.send(player) } + }
258-260
: Add a regression test for resend ordering.Recommend a test that sets
PartialBlocking
, appends messages A,B,C, triggersresendMessages
, and asserts delivery order A→B→C for the last N.I can draft the test scaffold if you want.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/interaction/ChatHistoryHandler.kt
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (2)
engine/engine-paper/src/main/kotlin/com/typewritermc/engine/paper/interaction/ChatHistoryHandler.kt (2)
258-260
: Correct fix: resend last N in chronological order (no reversal).Using
toList().takeLast(status.newMessages)
preserves order and avoids the previous newest-first bug. Matches the PR goal and should prevent client disconnects tied to out-of-order resends.
258-260
: No additional.reversed().take(...)
usages found.A recursive grep across all
.kt
files returned no matches for.reversed().take(
. No further occurrences exist—no action needed.
9d4f57a
to
04c9891
Compare
This fixes an issue where chat messages were being sent in reverse order during partial blocking resends, causing Minecraft clients to disconnect. The problem was in the
resendMessages
method which was usingreversed().take()
instead oftakeLast()
to get recent messages, resulting in messages being delivered with incorrect sequential ordering.Summary by CodeRabbit