Commit Graph

6 Commits

Author SHA1 Message Date
kshitijk4poor
065ea31ad3 fix(cli): classify the /resume target with one session.resume
The switch asked the gateway twice about a refused target. The receipt-owner
lookup (_gateway_owned_id, 639bcdf4) attached first and swallowed every error;
_open_switched_session then attached again, because a refused id is never
cached, and only that second answer stopped the switch. The two calls had to
stay in that order, and the first one hid the refusal.

_gateway_open now makes the one attach and returns (owner_id, refusal):
refusal is the reason code when the owner answers RESUME_GONE (not_found,
permission_denied, profile_mismatch), else None (off the gateway store, a
transient refusal such as session_busy, or no answer). The switch uses it
directly; _gateway_owned_id keeps its signature as the owner half for the
startup compression-chain path. _open_switched_session goes away with its
stale docstring and the handler comment that described a pre-first-turn gap
_gateway_owned_id already closes on main.

The switch tests now run on a real GatewaySessionStore with a gateway double.
The previous ones used a MagicMock store, which is not a GatewaySessionStore,
so they skipped the gateway path and their "subscribes before the first turn"
case was red on main for that reason alone. The refused-target cases
(not_found, permission_denied, profile_mismatch) are red on main (the switch
lands on the target) and assert a single session.resume; the openable case
is a guard and passes on main.
2026-10-20 14:58:52 +05:30
kshitijk4poor
198175f197 refactor(cli): hoist the gateway_client import in the switch helper
_open_switched_session imported GatewayClientError/GatewayRPCError inside
the function, though the module already imports gateway_connection at the
top (which itself imports gateway_client), so there is no cycle to dodge.
Move the import to module top and drop the trailing "return None" that
followed a try whose every branch already returns.

No behaviour change.
2026-10-20 14:58:52 +05:30
kshitijk4poor
6513b97f11 refactor(cli): keep the session.resume refusal sets in one place
gateway_connection already had _GONE (not_found, permission_denied,
profile_mismatch) for the reconnect resume. This branch then added
RESUME_REFUSALS in gateway_session_store and _SWITCH_REFUSALS in
cli_session_switch, which rebuilt the same three-member set. That made
three hand-kept copies of one session.resume vocabulary.

Both sets now live in gateway_connection: RESUME_REFUSALS (startup resume,
still exactly not_found + permission_denied) and the public
RESUME_GONE = RESUME_REFUSALS | {"profile_mismatch"} (reconnect and the
/resume switch). Behaviour is unchanged.
2026-10-20 14:58:52 +05:30
kshitijk4poor
fde167f6e5 refactor(cli): open the /resume target once and fix the switch comments
The refusal check ran twice on the same target_id before any state change
(once on the already-on arm, once on the switch path). Run it once, after the
Kanban guard and above the already-on check; behaviour is identical.

Comments: the memory-provider block in _sync_agent_to_session merged three
old comments and described reset=True and /new while the code passes
reset=False; replace it with one accurate line. Trim the reason-code list
over _SWITCH_REFUSALS (it would go stale) to one sentence, and say why the
agent setter's second attach costs nothing (attach caches per session id).
2026-10-20 14:58:52 +05:30
kshitijk4poor
586c578cb4 fix(cli): refuse a /resume switch the gateway answers with not_found
The switch aborted only on permission_denied / profile_mismatch, so a
session.resume answered with not_found still committed the switch, printed
"Resumed ...", and the first prompt was refused (permission_denied) because
nothing was subscribed: the original symptom. Startup resume
(GatewaySessionStore.open_session) already treats {not_found,
permission_denied} as "don't adopt".

Name that set once as RESUME_REFUSALS next to attach() and build the switch
set from it (plus profile_mismatch, which session.resume can raise via
SessionAuthority.authorize and restore_local_session), so the two callers
cannot drift. The refusal copy stays gateway.resume.switch_failed.
2026-10-20 14:58:52 +05:30
Daniel V. Baecker
e0561116c6 fix(cli): subscribe the session a /resume or /sessions switch lands on
The gateway holds the write side of a session and refuses prompt.submit
with permission_denied for any session this viewer's connection never
resumed (gateway/session_controls.py: submit). Startup resume and the
agent's session_id setter both reach GatewaySessionStore.attach; a
/resume or /sessions <n> typed before the first turn reached neither,
because _sync_agent_to_session only repoints an agent that already
exists. The first prompt after the switch was refused, and the CLI
reported it as a failed model request ("Run /model to switch"), which
names the wrong subsystem.

Open the switched-to session before the switch commits, so the first
turn is admitted. Only an ownership refusal from the owner
(permission_denied, profile_mismatch) stops the switch, with the
resume.switch_failed copy the gateway already shares and every catalog
translates; a transient or ownership-free answer (session_busy,
runtime_coordination_required, storage_unavailable, unknown_execution,
admission_conflict, not_found) and a transport failure (unavailable,
disconnected, timeout) both proceed, because the switch's reads are
local by design. The already-on branch opens the session too: a launch
whose attach was refused lands there without a subscription.

The switch plumbing moves to cli_session_switch.py, a topical sibling:
the mixin is over the FILE_LINES ratchet, so it may only go down, and the
two moved functions are byte-identical to the ones they replace. The
mixin shrinks by the 34 lines they occupied instead of growing.

Tests: tests/hermes_cli/test_cli_resume_command.py (six cases) and the
new tests/hermes_cli/test_cli_resume_switch_guards.py (nine). Nine of
them fail on the base: both switch spellings without an agent, the
refusal abort, the already-on arm, the numbered picker, and the refusal-
copy check. Eight neighbouring suites stay green (98 tests). python
scripts/check: 12 checks ok.
2026-10-20 14:58:52 +05:30