The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tui): Ink /rollback refuses on the shared gateway; parity table says so
Teknium1d691d84d823
diff --git a/scripts/gen_gateway_command_parity.py b/scripts/gen_gateway_command_parity.pyindex 51b485d45e5..79b8d799f5e 100755--- a/scripts/gen_gateway_command_parity.py+++ b/scripts/gen_gateway_command_parity.py@@ -124,14 +124,25 @@ def ink_cell(cmd, gateway, ink, served):return _rpc_cell(methods, served) if methods else "local"+def _sidecar_live_session_methods():+ """Sidecar RPCs that resolve their ``session_id`` in the sidecar's own session map+ (``@_rpc(..., live_session=True)``), which never holds a shared-gateway session."""+ text = "".join(p.read_text(encoding="utf-8-sig") for p in sorted((ROOT / "tui_gateway").glob("*.py")))+ return set(re.findall(r'_rpc\(\s*"([\w.]+)"[^)]*\blive_session=True', text))++def _rpc_cell(methods, served):"""An RPC the authority does not serve: session-namespace verbs answer -32601 (the client's- "out of sync" error); any other method reaches the legacy sidecar (``tui_gateway/ws.py``)."""+ "out of sync" error); any other method reaches the legacy sidecar (``tui_gateway/ws.py``),+ where a live-session handler answers 4001 for every shared-gateway session."""from tui_gateway.ws_legacy_fallback import _SESSION_FALLBACK_ALLOWED, _SESSION_NAMESPACESbroken = sorted(m for m in methods - servedif m.startswith(_SESSION_NAMESPACES) and m not in _SESSION_FALLBACK_ALLOWED)if broken:return "**broken**: " + ", ".join(broken) + " (-32601)"+ unbound = sorted((methods - served) & _sidecar_live_session_methods())+ if unbound:+ return "**broken**: " + ", ".join(unbound) + " (4001 session not found)"legacy = sorted(methods - served)return ", ".join(sorted(methods & served)) + ("; " if methods & served and legacy else "") + ("sidecar: " + ", ".join(legacy) if legacy else "")diff --git a/tests/hermes_cli/test_gateway_command_parity_live_session.py b/tests/hermes_cli/test_gateway_command_parity_live_session.pynew file mode 100644index 00000000000..9dccc819d51--- /dev/null+++ b/tests/hermes_cli/test_gateway_command_parity_live_session.py@@ -0,0 +1,20 @@+"""A sidecar live-session RPC (``@_rpc(..., live_session=True)``) resolves ``session_id`` in the+sidecar's own session map, which never holds a shared-gateway session: the parity table must+not list a client that calls one as served by the sidecar."""+import importlib.util+from pathlib import Path++ROOT = Path(__file__).resolve().parents[2]+++def test_sidecar_live_session_rpc_is_reported_broken_on_the_shared_gateway():+ spec = importlib.util.spec_from_file_location("gen_gateway_command_parity",+ ROOT / "scripts" / "gen_gateway_command_parity.py")+ gen = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(gen)++ cell = gen._rpc_cell({"rollback.list", "rollback.diff"}, set())++ assert cell.startswith("**broken**"), cell+ assert "rollback.diff" in cell and "rollback.list" in cell+ assert "sidecar:" not in celldiff --git a/ui-tui/src/__tests__/canonicalRollbackRefusal.test.ts b/ui-tui/src/__tests__/canonicalRollbackRefusal.test.tsnew file mode 100644index 00000000000..33d6fbb17af--- /dev/null+++ b/ui-tui/src/__tests__/canonicalRollbackRefusal.test.ts@@ -0,0 +1,52 @@+import { beforeEach, expect, it, vi } from 'vitest'++import { createSlashHandler } from '../app/createSlashHandler.js'+import { patchUiState, resetUiState } from '../app/uiStore.js'++const flush = () => new Promise(resolve => setImmediate(resolve))++beforeEach(() => {+ resetUiState()+ patchUiState({ sid: 'owner' })+})++// The rollback.* handlers are sidecar live-session RPCs: on the shared gateway they look the+// owner's session id up in the sidecar's own map and always answer "session not found".+it('/rollback says it is not available on the shared gateway instead of "session not found"', async () => {+ const request = vi.fn(async (method: string) => {+ if (method.startsWith('rollback.')) {+ throw new Error('session not found')+ }++ return {}+ })++ const sys = vi.fn()++ const slash = createSlashHandler({+ composer: { enqueue: vi.fn() },+ gateway: { gw: { isCanonical: true, request }, rpc: request },+ local: { getHistoryItems: () => [], getLastUserMsg: () => '', maybeWarn: vi.fn() },+ session: { resumeById: vi.fn() },+ slashFlightRef: { current: 0 },+ transcript: {+ page: vi.fn(),+ panel: vi.fn(),+ send: vi.fn(),+ setHistoryItems: vi.fn(),+ sys,+ trimLastExchange: (x: unknown[]) => x+ }+ } as any)++ for (const cmd of ['/rollback', '/rollback diff abc123', '/rollback abc123 src/a.py']) {+ slash(cmd)+ }++ await flush()++ expect(request.mock.calls.map(([method]) => method).filter(method => method.startsWith('rollback.'))).toEqual([])+ expect(sys.mock.calls.map(([text]) => String(text))).toEqual(+ Array(3).fill('/rollback is not available on the shared gateway yet')+ )+})diff --git a/ui-tui/src/app/slash/commands/ops.ts b/ui-tui/src/app/slash/commands/ops.tsindex 2289f678341..2e6c2ca8c00 100644--- a/ui-tui/src/app/slash/commands/ops.ts+++ b/ui-tui/src/app/slash/commands/ops.ts@@ -253,6 +253,12 @@ export const opsCommands: SlashCommand[] = [return ctx.transcript.sys(t('slashCmd.ops.rollback.noSession'))}+ // Checkpoints live in the legacy sidecar's per-session map, which never holds a+ // shared-gateway session; the owner serves no rollback verb yet.+ if (ctx.gateway.gw?.isCanonical) {+ return ctx.transcript.sys(t('canonical.controls.notAvailable', 'rollback'))+ }+const trimmed = arg.trim()const [first = '', ...rest] = trimmed.split(/\s+/).filter(Boolean)const lower = first.toLowerCase()diff --git a/website/docs/developer-guide/gateway-command-parity.md b/website/docs/developer-guide/gateway-command-parity.mdindex 517e130596a..0d16d5d73b8 100644--- a/website/docs/developer-guide/gateway-command-parity.md+++ b/website/docs/developer-guide/gateway-command-parity.md@@ -97,7 +97,7 @@ policy; `client-local (cli_only)` commands are terminal/UI features of a client.| `/resume` | refused | refused: not available yet | local | picker: session | refused | switches the messaging chat's session; local clients resume by id || `/retry` | refused | session.mutate rewind + resubmit | canonical route | slash.exec: refused | refused | || `/review` | refused | refused: not available yet | slash.exec: refused | slash.exec: refused | refused | |-| `/rollback` | refused | refused: not available yet | sidecar: rollback.diff, rollback.list, rollback.restore | slash.exec: refused | refused | restores filesystem checkpoints |+| `/rollback` | refused | refused: not available yet | refused: not available yet | slash.exec: refused | refused | restores filesystem checkpoints || `/save` | refused | refused: not available yet | refused: not available yet | slash.exec: refused | refused | writes an export file on the gateway host || `/sessions` | refused | refused: not available yet | local | picker: session | refused | messaging origin-scoped listing (`/sessions all` needs a messaging admin) || `/sethome` (/set-home) | refused | refused: not available yet | slash.exec: refused | unavailable: terminal | refused | messaging-only |