refactor(pkg-r): remove dead else branch in mod_server#223
Merged
Conversation
Since #207 introduced create_session_client(), QueryChat$server() always passes a closure to mod_server — the else branch that handled a pre-built Chat object was unreachable. Remove it and add check_function(client) to match Python's mod_server, which raises TypeError for non-callable clients.
Contributor
There was a problem hiding this comment.
Pull request overview
Removes unreachable logic in the R Shiny module server (mod_server()) by enforcing that client must be a function (consistent with the post-#207 architecture where QueryChat$server() always passes a closure that creates a session-scoped chat client).
Changes:
- Replace
if (is_function(client)) ... else ...withcheck_function(client)and a direct invocation. - Eliminate dead code that cloned a
Chatinstance and manually registered a fixed subset of tools.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Removes an unreachable
elsebranch inmod_server()that was left behind after #207 refactored client creation.Before #207,
mod_server()accepted either a function (client factory) or a pre-builtChatobject. Theelsebranch handled the latter case by cloning the Chat and manually registering tools.After #207,
QueryChat$server()always wrapsprivate$create_session_client()in a closure and passes that asclient— somod_server()always receives a function. Theelsebranch became dead code.This is a problem because the
elsebranch:update,query, andresettools (ignoring thetoolsparameter)This PR replaces the
if/elsewithcheck_function(client)+ a direct call, matching the Pythonmod_serverwhich raisesTypeErrorfor non-callable clients.Test plan
git logthat no code path passes a non-functionclienttomod_server()since feat: Allow deferred chat client initialization #207