[PR #4229] [MERGED] Chat completes the server's custom chat completions #5502

Closed
opened 2026-11-03 05:13:01 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4229
Author: @d3grando
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @levzzz5154

Base: main ← Head: fix-3518-custom-chat-completions


📝 Commits (1)

  • e9eda29 Complete chat with the server's custom chat completions

📊 Changes

9 files changed (+184 additions, -7 deletions)

View changed files

📝 crates/horizon-client-core/src/registries.rs (+52 -0)
📝 crates/horizon-client-render/src/chat.rs (+3 -1)
📝 crates/horizon-client-render/src/chat_tests.rs (+52 -0)
📝 crates/horizon-client/src/game/chat.rs (+1 -0)
📝 crates/horizon-client/src/game/remote.rs (+28 -1)
📝 crates/horizon-command/src/args.rs (+3 -1)
📝 crates/horizon-command/src/lib.rs (+1 -1)
📝 crates/horizon-protocol/src/packets/play.rs (+41 -0)
📝 tools/port_map/client-002.tsv (+3 -3)

📄 Description

🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando personally.

What and why

Proxies and plugins send extra chat completions with ClientboundCustomChatCompletionsPacket (Paper's Player#addCustomChatCompletions, Velocity's player names from other backend servers, chat tags). In vanilla, Tab in chat offers them next to the online players. In Horizon, Tab in chat offered only the player list.

Root cause: CUSTOM_CHAT_COMPLETIONS (23) was only a constant in ids.rs. Horizon never decoded the packet, kept no completion set, and the chat path of CommandSuggestions.updateCommandInfo completed from registries.players only.

The fix:

  • horizon-protocol: decodes CustomChatCompletions: the action as a VarInt (Action.STREAM_CODEC, ByteBufCodecs.idMapper), then a list of UTF-8 strings.
  • horizon-client-core: Registries::custom_completions holds ClientSuggestionProvider.customCompletionSuggestions. modify_custom_completions ports modifyCustomCompletions (ADD, REMOVE, SET). As in vanilla, an action id out of range counts as ADD (ByIdMap.continuous with OutOfBoundsStrategy.ZERO). Registries::custom_tab_suggestions ports getCustomTabSuggestions: the player names plus the custom completions, each one once.
  • remote.rs: each connection keeps its own set and updates it from the packet (handleCustomChatCompletions). The set is emptied on a reconfiguration, because vanilla builds a new ClientPacketListener there, and with it a new ClientSuggestionProvider. Opening chat copies the set into the registries the chat screen reads, so leaving the server clears it too.
  • chat.rs: chat that is not a command now completes from custom_tab_suggestions(). Commands are unchanged: entity arguments still use only the online players (getOnlinePlayerNames).
  • Port map: handleCustomChatCompletions, getCustomTabSuggestions and modifyCustomCompletions in tools/port_map/client-002.tsv now point at the ports.

Part of #3518. The port map lists these methods as missing, but they aren't rows in the issue's list.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Read with javap from the 26.3 client.jar:

  • ClientboundCustomChatCompletionsPacket.STREAM_CODEC (Action.STREAM_CODEC, then ByteBufCodecs.STRING_UTF8.apply(ByteBufCodecs.list())). Action.BY_ID is ByIdMap.continuous(..., OutOfBoundsStrategy.ZERO), so an unknown id is ADD.
  • ClientPacketListener.handleCustomChatCompletions: suggestionsProvider.modifyCustomCompletions(action, entries).
  • ClientSuggestionProvider.modifyCustomCompletions (ADD addAll, REMOVE remove per entry, SET clear + addAll on a HashSet) and getCustomTabSuggestions: the online player names alone when the set is empty, otherwise a HashSet of both.
  • CommandSuggestions.updateCommandInfo: chat that is not a command suggests getSuggestionsProvider().getCustomTabSuggestions() for the last word.
  • ClientPacketListener.<init> creates a new ClientSuggestionProvider, and ClientConfigurationPacketListenerImpl.handleConfigurationFinished creates a new ClientPacketListener, so the set starts empty after a reconfiguration.

Vanilla's own server never sends this packet, so no parity harness can produce one. The checks are:

  • packets::play::tests::custom_chat_completions_are_an_action_and_a_string_list: the wire bytes, a round trip, and a truncated payload.
  • chat::tests::chat_completes_the_servers_custom_completions_with_the_players: ADD, REMOVE, SET and an out-of-range action id; Tab in chat completes the custom entries and still completes the players; SET replaces the custom entries.
  • An end-to-end run against a vanilla 26.3 dedicated server behind a small proxy. The proxy acts as a plugin and sends the packet once play has started.

Self-check

tools/pr_ready.py doesn't run on Windows (it needs SIGHUP), so I ran the steps by hand. tools/port_ledger.py map-check needs a ledger built from the decompiled sources, which this machine doesn't have.

cargo fmt --all -- --check                                              # ok
cargo clippy -p horizon-protocol --all-targets -- -D warnings           # ok
cargo clippy -p horizon-client-core --all-targets -- -D warnings        # ok
cargo clippy -p horizon-command --all-targets -- -D warnings            # ok
cargo clippy -p horizon-client-render --all-targets -- -D warnings      # ok
cargo clippy -p horizon-client --all-targets -- -D warnings             # ok
cargo test -p horizon-protocol --lib                                    # 111 passed
cargo test -p horizon-client-render --lib chat::tests                   # 13 passed
cargo test -p horizon-command --lib suggest                             # 3 passed
cargo test -p horizon-client --bin horizon-client chat                  # 4 passed

Before and after (only the code reverted, the tests kept):

# chat.rs back on registries.players:
cargo test -p horizon-client-render --lib chat_completes_the_servers
  panicked at chat_tests.rs:287: left: "hi no", right: "hi Notch"     # FAILED
# without the Clientbound::CustomChatCompletions variant:
cargo test -p horizon-protocol --lib custom_chat_completions
  error[E0599]: no variant ... named `CustomChatCompletions` found for enum `Clientbound`   # fails to build
# with the fix:
cargo test -p horizon-client-render --lib chat_completes_the_servers   # 1 passed
cargo test -p horizon-protocol --lib custom_chat_completions           # 1 passed

In game (Windows, --profile fast builds of main and of this branch): I joined a vanilla 26.3 dedicated server through a proxy that injects CustomChatCompletions. The proxy sent SET Notch_lobby2, NoxBuilder, #trade. Then I opened chat, typed hi No and pressed Tab.

  • main: no list appears, and Tab does nothing (decode_errors 0; the packet is dropped as unknown).
  • this branch: the list shows Notch_lobby2 and NoxBuilder. A second Tab gives hi Notch_lobby2, and the server logs <Guest> hi Notch_lobby2. After the proxy sent REMOVE Notch_lobby2, the same keys gave hi NoxBuilder.

The reconfiguration reset (the set emptied on Event::Reconfigured) was not run in game: it needs a proxy that moves the player to another server.

Screenshots

before: typing hi No and pressing Tab in chat suggests nothing

after: the names the server sent (ClientboundCustomChatCompletionsPacket) are suggested

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/4229 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix-3518-custom-chat-completions` --- ### 📝 Commits (1) - [`e9eda29`](https://github.com/horizon-rust/horizon/commit/e9eda298fd0f4ee3d5c9be88e0adbc6613596dfd) Complete chat with the server's custom chat completions ### 📊 Changes **9 files changed** (+184 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-core/src/registries.rs` (+52 -0) 📝 `crates/horizon-client-render/src/chat.rs` (+3 -1) 📝 `crates/horizon-client-render/src/chat_tests.rs` (+52 -0) 📝 `crates/horizon-client/src/game/chat.rs` (+1 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+28 -1) 📝 `crates/horizon-command/src/args.rs` (+3 -1) 📝 `crates/horizon-command/src/lib.rs` (+1 -1) 📝 `crates/horizon-protocol/src/packets/play.rs` (+41 -0) 📝 `tools/port_map/client-002.tsv` (+3 -3) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando personally. ## What and why Proxies and plugins send extra chat completions with `ClientboundCustomChatCompletionsPacket` (Paper's `Player#addCustomChatCompletions`, Velocity's player names from other backend servers, chat tags). In vanilla, Tab in chat offers them next to the online players. In Horizon, Tab in chat offered only the player list. Root cause: `CUSTOM_CHAT_COMPLETIONS` (23) was only a constant in `ids.rs`. Horizon never decoded the packet, kept no completion set, and the chat path of `CommandSuggestions.updateCommandInfo` completed from `registries.players` only. The fix: - **horizon-protocol:** decodes `CustomChatCompletions`: the action as a VarInt (`Action.STREAM_CODEC`, `ByteBufCodecs.idMapper`), then a list of UTF-8 strings. - **horizon-client-core:** `Registries::custom_completions` holds `ClientSuggestionProvider.customCompletionSuggestions`. `modify_custom_completions` ports `modifyCustomCompletions` (ADD, REMOVE, SET). As in vanilla, an action id out of range counts as ADD (`ByIdMap.continuous` with `OutOfBoundsStrategy.ZERO`). `Registries::custom_tab_suggestions` ports `getCustomTabSuggestions`: the player names plus the custom completions, each one once. - **remote.rs:** each connection keeps its own set and updates it from the packet (`handleCustomChatCompletions`). The set is emptied on a reconfiguration, because vanilla builds a new `ClientPacketListener` there, and with it a new `ClientSuggestionProvider`. Opening chat copies the set into the registries the chat screen reads, so leaving the server clears it too. - **chat.rs:** chat that is not a command now completes from `custom_tab_suggestions()`. Commands are unchanged: entity arguments still use only the online players (`getOnlinePlayerNames`). - **Port map:** `handleCustomChatCompletions`, `getCustomTabSuggestions` and `modifyCustomCompletions` in `tools/port_map/client-002.tsv` now point at the ports. Part of #3518. The port map lists these methods as `missing`, but they aren't rows in the issue's list. ## Kind - [x] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Read with javap from the 26.3 client.jar: - `ClientboundCustomChatCompletionsPacket.STREAM_CODEC` (`Action.STREAM_CODEC`, then `ByteBufCodecs.STRING_UTF8.apply(ByteBufCodecs.list())`). `Action.BY_ID` is `ByIdMap.continuous(..., OutOfBoundsStrategy.ZERO)`, so an unknown id is `ADD`. - `ClientPacketListener.handleCustomChatCompletions`: `suggestionsProvider.modifyCustomCompletions(action, entries)`. - `ClientSuggestionProvider.modifyCustomCompletions` (ADD `addAll`, REMOVE `remove` per entry, SET `clear` + `addAll` on a `HashSet`) and `getCustomTabSuggestions`: the online player names alone when the set is empty, otherwise a `HashSet` of both. - `CommandSuggestions.updateCommandInfo`: chat that is not a command suggests `getSuggestionsProvider().getCustomTabSuggestions()` for the last word. - `ClientPacketListener.<init>` creates a new `ClientSuggestionProvider`, and `ClientConfigurationPacketListenerImpl.handleConfigurationFinished` creates a new `ClientPacketListener`, so the set starts empty after a reconfiguration. Vanilla's own server never sends this packet, so no parity harness can produce one. The checks are: - `packets::play::tests::custom_chat_completions_are_an_action_and_a_string_list`: the wire bytes, a round trip, and a truncated payload. - `chat::tests::chat_completes_the_servers_custom_completions_with_the_players`: ADD, REMOVE, SET and an out-of-range action id; Tab in chat completes the custom entries and still completes the players; SET replaces the custom entries. - An end-to-end run against a vanilla 26.3 dedicated server behind a small proxy. The proxy acts as a plugin and sends the packet once play has started. ## Self-check `tools/pr_ready.py` doesn't run on Windows (it needs SIGHUP), so I ran the steps by hand. `tools/port_ledger.py map-check` needs a ledger built from the decompiled sources, which this machine doesn't have. ``` cargo fmt --all -- --check # ok cargo clippy -p horizon-protocol --all-targets -- -D warnings # ok cargo clippy -p horizon-client-core --all-targets -- -D warnings # ok cargo clippy -p horizon-command --all-targets -- -D warnings # ok cargo clippy -p horizon-client-render --all-targets -- -D warnings # ok cargo clippy -p horizon-client --all-targets -- -D warnings # ok cargo test -p horizon-protocol --lib # 111 passed cargo test -p horizon-client-render --lib chat::tests # 13 passed cargo test -p horizon-command --lib suggest # 3 passed cargo test -p horizon-client --bin horizon-client chat # 4 passed ``` Before and after (only the code reverted, the tests kept): ``` # chat.rs back on registries.players: cargo test -p horizon-client-render --lib chat_completes_the_servers panicked at chat_tests.rs:287: left: "hi no", right: "hi Notch" # FAILED # without the Clientbound::CustomChatCompletions variant: cargo test -p horizon-protocol --lib custom_chat_completions error[E0599]: no variant ... named `CustomChatCompletions` found for enum `Clientbound` # fails to build # with the fix: cargo test -p horizon-client-render --lib chat_completes_the_servers # 1 passed cargo test -p horizon-protocol --lib custom_chat_completions # 1 passed ``` In game (Windows, `--profile fast` builds of main and of this branch): I joined a vanilla 26.3 dedicated server through a proxy that injects `CustomChatCompletions`. The proxy sent SET `Notch_lobby2`, `NoxBuilder`, `#trade`. Then I opened chat, typed `hi No` and pressed Tab. - main: no list appears, and Tab does nothing (`decode_errors` 0; the packet is dropped as unknown). - this branch: the list shows `Notch_lobby2` and `NoxBuilder`. A second Tab gives `hi Notch_lobby2`, and the server logs `<Guest> hi Notch_lobby2`. After the proxy sent REMOVE `Notch_lobby2`, the same keys gave `hi NoxBuilder`. The reconfiguration reset (the set emptied on `Event::Reconfigured`) was not run in game: it needs a proxy that moves the player to another server. ## Screenshots ![before: typing hi No and pressing Tab in chat suggests nothing](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/3518-custom-chat-completions-1.png) ![after: the names the server sent (ClientboundCustomChatCompletionsPacket) are suggested](https://raw.githubusercontent.com/d3grando/horizon/pr-assets/3518-custom-chat-completions-2.png) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:13:01 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#5502
No description provided.