refactor: simplify session command dispatch#87
Open
ALX99 wants to merge 3 commits into
Open
Conversation
5cf571d to
dd748db
Compare
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.
Simplification
Inline the
new_session/switch_sessionbridge dispatch flow and remove the privatehandleSessionCommand()helper.Why the current design is overcomplicated
handleSessionCommand()had exactly one caller: the adjacentnew_session/switch_sessionbranch insideBridge.dispatch(). The helper did not provide a separate abstraction boundary, extension point, reuse point, or independently testable behavior. It also forced reviewers to jump between two private methods to understand one command dispatch path.The session command flow is small and depends directly on dispatch-local context: the parsed command, the originating client sender, runtime session replacement, cancellation handling, rebinding, and the final response. Keeping it inline makes the full branch behavior visible in one place.
Behavioral contract
The following behavior must remain unchanged:
new_sessionstill callsruntime.newSession().switch_sessionstill callsruntime.switchSession(cmd.path).{ type: "response", id, ok: false, error: "cancelled by extension" }.rebind()before responding success.{ type: "response", id, ok: true }.Before and after
Before:
Bridge.dispatch()groupednew_sessionandswitch_session, then delegated tothis.handleSessionCommand(cmd, replyTo).handleSessionCommand()immediately performed the runtime call, cancellation response,rebind(), and success response.After:
Bridge.dispatch()handles the groupednew_session/switch_sessionbranch directly.rebind(), and success response remain in the same order.handleSessionCommand()method is removed.Specific evidence:
pi-web/src/bridge.ts.new_sessionandswitch_session.pi-web/src/bridge.tsand is 1 commit ahead ofmasterwith no unrelated files changed.Validation
Static validation performed in this connector-limited run:
pi-web/src/bridge.tsbefore editing and verifiedhandleSessionCommand()had exactly one caller.master...refactor/simplify-session-command-dispatch: result is 1 commit ahead, 0 behind, with onlypi-web/src/bridge.tsmodified.rebind()ordering, and success response text/shape.Commands not run in this automation environment:
cd pi-web && npm run buildcd pi-web && npm run typecheckcd pi-web && npm testExisting tests expected to cover this behavior:
pi-web/tests/bridge.test.tscovers command dispatch, session rebinding, cancellation paths, response behavior, and client behavior.Risk assessment
Risk is low because this removes only a private single-caller helper and keeps the same code path, response payloads, runtime calls, and ordering. The behavior-sensitive part is session replacement: cancellation must avoid rebinding and success must rebind before returning success. Both branches are preserved exactly in the inlined flow.
Behavior-sensitive areas examined:
new_sessionvsswitch_sessionruntime call selection,rebind()ordering,handleCommand()try/catch,Scope
Intentionally not simplified:
Bridge.dispatch()branches, because they are behavior-dense and already readable.respond()and broadcast helpers, because they are reused side-effect boundaries.pi-web/src/web/bridge.ts) and open PR refactor: simplify agent discovery result handling #74 (subagent discovery), to avoid overlapping work.