refactor(assistant): split run_session_turn into sibling API and CLI runners - #223
Merged
Merged
Conversation
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.
Why
engine::run_session_turnwas ~630 lines that ran the whole API turn inline (stream consumption, tool execution, context-limit recovery, persistence) while delegating CLI providers tolocal_agent. The two runners were not at the same level.What
Pure refactor, no intended behaviour change.
engine::run_session_turn(now 37 lines) loads the session and connection once, validates (including a missingagent_workspace_id), resolves the workspace root once, then dispatches with a plainiftoapi_turn::run_session_turnorlocal_agent::run_session_turn. No trait. Callers are unchanged.assistant/api_turn.rsholds the API loop, split intoprepare_api_request,try_context_limit_recovery,consume_api_stream,finalize_api_message,execute_api_tool_callsandApiTurnState. The orchestrator is about 130 lines.assistant/turn_common.rsholds the helpers both runners use: trigger marker, empty-content rule, image preservation, and cleanup of unanswered input.Tests
Characterisation tests, each checked by mutation:
Known gap: there are no runner-level tests for these cases:
The blocker is that
AssistantDepsrequiresAppHandle<Wry>, while Tauri'smock_appgivesMockRuntime. A follow-up PR will add a runtime seam.Review
Two independent review rounds. Round 1 found a double workspace-root lookup, an unused adapter-injection seam, visibility that was too wide, and a stale comment; all were fixed. Round 2 returned
production_quality, with a function-by-function mapping againstmain.Manual test requested
API-provider chat with tool calls, plus a cancel partway through a reply.