Skip to content
This repository was archived by the owner on Sep 30, 2026. It is now read-only.

Add live-session account-switch control surface (ADR 0031 Phase 1) - #22

Merged
yjuyjuy merged 5 commits into
masterfrom
fm/asw-jcode-control-surface
Aug 14, 2026
Merged

yjuyjuy merged 5 commits into
masterfrom
fm/asw-jcode-control-surface

Conversation

@yjuyjuy

@yjuyjuy yjuyjuy commented Aug 13, 2026

Copy link
Copy Markdown
Owner

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-axi switch verb will actuate.

What

  • Provider trait: account_label / set_account_label for a per-instance account pin, implemented on the Anthropic and OpenAI runtimes (honored on the credential-load and token-refresh paths) 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 so the next turn re-establishes context.
  • Protocol: ListSessions, SwitchSessionAccount, SwitchSessionAccountModel lightweight requests plus SessionList / SessionSwitchResult events (with SessionControlInfo / SessionSwitchOutcome).
  • Server: session_control handlers 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.
  • CLI: jcode session list and jcode session switch-account (--all, --model), both with --json for scripting.

Design notes

  • Additive and provider-general: Phase 1 exercises Claude account switching, but the surface supports account+model and cross-provider by design.
  • A switch never interrupts a turn in flight. When the agent lock is held, the switch is queued and applied on drain, taking effect on the session's next turn.
  • Scoped strictly to the control surface. Does not converge jcode on the shared usage cache (a separate later ticket).

Testing

Built test-first for the server/protocol layers.

  • session_control unit 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.
  • Protocol wire-roundtrip tests for the new requests/events (lock down the JSON shape the orchestrator depends on).
  • End-to-end script 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.

Chris Yuan 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
@yjuyjuy
yjuyjuy merged commit 447d4b7 into master Aug 14, 2026
10 of 11 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant