Skip to content

refactor(pkg-r): remove dead else branch in mod_server#223

Merged
cpsievert merged 1 commit intomainfrom
refactor/remove-mod-server-dead-code
Apr 28, 2026
Merged

refactor(pkg-r): remove dead else branch in mod_server#223
cpsievert merged 1 commit intomainfrom
refactor/remove-mod-server-dead-code

Conversation

@cpsievert
Copy link
Copy Markdown
Contributor

Summary

Removes an unreachable else branch in mod_server() that was left behind after #207 refactored client creation.

Before #207, mod_server() accepted either a function (client factory) or a pre-built Chat object. The else branch handled the latter case by cloning the Chat and manually registering tools.

After #207, QueryChat$server() always wraps private$create_session_client() in a closure and passes that as client — so mod_server() always receives a function. The else branch became dead code.

This is a problem because the else branch:

  • Hardcodes registering only update, query, and reset tools (ignoring the tools parameter)
  • Would silently do the wrong thing if somehow reached

This PR replaces the if/else with check_function(client) + a direct call, matching the Python mod_server which raises TypeError for non-callable clients.

Test plan

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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ... with check_function(client) and a direct invocation.
  • Eliminate dead code that cloned a Chat instance and manually registered a fixed subset of tools.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cpsievert cpsievert merged commit a49697f into main Apr 28, 2026
14 checks passed
@cpsievert cpsievert deleted the refactor/remove-mod-server-dead-code branch April 28, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants