This repository was archived by the owner on Sep 30, 2026. It is now read-only.
Repository navigation
Add live-session account-switch control surface (ADR 0031 Phase 1) - #22
Merged
Merged
Conversation
added 5 commits
August 13, 2026 17:15
Add a headless, subscription-free control surface that lets an external orchestrator switch a live jcode session's account (and optionally its model) without terminal injection. This is Phase 1 of the account-switch orchestrator. Account selection was process-global (a static runtime override plus the active label in auth.json), which only affects new sessions, so store-flipping could not switch a running session. This adds a per-instance account pin to the provider runtime, honored on the credential and token-refresh paths, so one live session can use a different account than its siblings. - Provider trait: account_label/set_account_label, implemented on the Anthropic and OpenAI runtimes and forwarded by MultiProvider to the active runtime. - Agent: set_account_label and switch_account_and_model (atomic account+model for the provider-crossing case), both resetting the provider session. - Protocol: ListSessions, SwitchSessionAccount, SwitchSessionAccountModel lightweight requests plus SessionList/SessionSwitchResult events. - Server: session_control handlers enumerate every live session, apply switches with drain semantics (applied immediately when idle, deferred to the next turn when a turn holds the agent lock, never interrupting it), and report per-session success/failure for one session or all sessions. - CLI: jcode session list and jcode session switch-account (--all, --model). - Tests: session_control unit tests, protocol wire-roundtrip tests, and an end-to-end script (scripts/asw_session_control_e2e.sh).
…l-surface # Conflicts: # scripts/code_size_budget.json # scripts/swallowed_error_budget.json # scripts/test_size_budget.json
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Adds a headless, subscription-free control surface that lets an external orchestrator switch a live jcode session's account (and optionally its model) without terminal injection. This is Phase 1 of the account-switch orchestrator (ADR 0031).
Why
Account selection was process-global (a static runtime override plus the active label in
auth.json), which only affects new sessions. Flipping the store could not switch a session that is already running, so per-session live switching did not exist. This adds the missing live-session control the later quota-axiswitchverb will actuate.What
account_label/set_account_labelfor a per-instance account pin, implemented on the Anthropic and OpenAI runtimes (honored on the credential-load and token-refresh paths) and forwarded byMultiProviderto the active runtime.set_account_labelandswitch_account_and_model(atomic account+model for the provider-crossing case), both resetting the provider session so the next turn re-establishes context.ListSessions,SwitchSessionAccount,SwitchSessionAccountModellightweight requests plusSessionList/SessionSwitchResultevents (withSessionControlInfo/SessionSwitchOutcome).session_controlhandlers enumerate every live session, apply switches with drain semantics (applied immediately when idle, deferred to the session's next turn when a turn holds the agent lock, never interrupting it), and report per-session success/failure for one session or all sessions.jcode session listandjcode session switch-account(--all,--model), both with--jsonfor scripting.Design notes
Testing
Built test-first for the server/protocol layers.
session_controlunit tests: list reports provider/account/model, per-session switch on an idle session, all-session switch, cross-provider account+model together, unknown-session failure, per-session failure reporting, and a deferred switch that applies after a busy turn drains. 10/10 pass.scripts/asw_session_control_e2e.sh: starts an isolated daemon, seeds two accounts, creates headless sessions, and drives the real CLI to list, switch one session, verify per-session isolation, switch all sessions, exercise account+model together, and confirm per-session failure reporting. Passes.Coverage gap: the end-to-end account+model (cross-provider) path is exercised for its control-plane result shape only; the hermetic test env has no real provider credentials, so it does not drive a live inference turn under the switched account. Live-inference verification is deferred to the environment that has real accounts.