Files
multica/server
Jiayuan Zhang ead32a8e50 fix(terminal): Phase 4 review round 2 — Desktop token first-frame auth, opened-frame rollback (MUL-2295)
Two fixes for Emacs Round 2 findings:

1. Desktop TerminalPanel now sends `{type:"auth", payload:{token}}` as
   the first WS frame in token mode and waits for `auth_ack`. Previously
   it transitioned straight to "connected" without authing, so the
   server's 10s first-frame deadline closed the connection and the
   terminal never opened. Cookie-mode apps still skip the handshake.
   Exposes ApiClient.getToken() so the panel can snapshot the bearer
   without reaching into auth-store internals.

2. terminalBridge.handleOpen no longer treats `terminal.opened` as a
   droppable control frame. sendFrame now returns bool; if the ack
   can't be enqueued the bridge rolls the half-open session back
   (cancel ctx, drop the route, sess.Close) so the spawned PTY doesn't
   orphan until the idle sweep — which also pinned the GC active-env
   mark for that window.

Regression coverage:
- TestTerminalBridge_OpenedEnqueueFailureClosesSession: drop-only
  sender, spawn must happen exactly once, manager and bridge route map
  must drain to zero.
- packages/views/issues/components/terminal-panel.test.tsx: asserts
  the auth frame is sent in token mode and NOT sent in cookie mode.

Co-authored-by: multica-agent <github@multica.ai>
2026-05-16 19:27:51 +08:00
..