Commit bf49903
feat(session): wire PTYTransport into /session/ws (§1.5)
/api/session/ws now runs the new transport stack — no more
agent_session_manager, no legacy {type:"start"} frame. The route binds
the already-acquired active.ActiveSession to the WS and pumps transport
events both ways under asyncio.TaskGroup + except*.
Why: §1.5 of the agent-session-transport plan. Closes the wiring gap
that left session/transport.py, session/transports/pty.py, and
session/active.py fully implemented but unreachable from the web UI
since PR-B-1..B-4.
Route contract (authoritative for frontend §1.7):
- Preconditions: active session must already be acquired. WS closes
1008 pre-accept when current() is None.
- Origin guard: localhost/127.0.0.1 any port by default, extend via
STUDYLOOP_ALLOWED_ORIGINS env var (plan Blocker B1).
- Session-id match: ?study_session_id must equal active.study_session_id
or close 1008 (pattern from terminal_proxy.py:134).
- Inbound JSON: input/resize/stop control frames.
- Outbound: binary for OutputBytes, text JSON for lifecycle events.
- finally: always await active.release() — guarantees a clean
singleton on disconnect.
Scope cuts (deferred to §1.5b, separate PR):
- POST /session/start still runs legacy tmux+ttyd flow. Re-pointing
it at active.acquire(config, PTYTransport) is the remaining §1.5
work; user deferred because it needs Playwright-driven iteration.
- Frontend WS feature flag (§1.9) becomes a browser concern rather
than server concern — the WS route no longer serves ttyd at all;
iframe path stays behind /terminal/ in terminal_proxy.py.
Legacy test cleanup: 2 stale tests removed from test_web_live_session.py
(test_live_session_websocket_streams_events_and_accepts_input and
test_live_session_websocket_rejects_acp_until_handshake_is_implemented)
— they exercised the now-replaced protocol. test_session_runtime.py's
unit tests of the legacy manager still pass; session_runtime/ stays
on disk until §1.5b also lands.
Tests: 1980 passed, 145 deselected. +8 new in test_web_session_ws.py
(origin guard, session-id mismatch, no-active-session rejection,
Started/Output/Stopped pump, input/resize/stop inbound frames,
release-on-disconnect). Ruff clean, format clean.
Plan: docs/plans/2026-05-09-refactor-agent-session-transport-plan.md
Amendment #5 appended with the full route contract for §1.7 frontend.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 0b5a638 commit bf49903
4 files changed
Lines changed: 518 additions & 136 deletions
File tree
- docs/plans
- packages/studyloop
- src/studyloop/web/routes
- tests
Lines changed: 88 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
123 | 211 | | |
124 | 212 | | |
125 | 213 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
576 | 576 | | |
577 | 577 | | |
578 | 578 | | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
579 | 618 | | |
580 | 619 | | |
581 | | - | |
582 | | - | |
583 | | - | |
584 | | - | |
585 | | - | |
586 | | - | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
587 | 641 | | |
588 | | - | |
589 | | - | |
590 | | - | |
591 | | - | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
592 | 650 | | |
593 | | - | |
594 | | - | |
595 | | - | |
| 651 | + | |
596 | 652 | | |
597 | | - | |
598 | | - | |
599 | | - | |
600 | | - | |
601 | | - | |
602 | | - | |
603 | | - | |
604 | | - | |
605 | | - | |
606 | | - | |
607 | | - | |
608 | | - | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
614 | | - | |
615 | | - | |
616 | | - | |
617 | | - | |
618 | | - | |
619 | | - | |
620 | | - | |
621 | | - | |
622 | | - | |
623 | | - | |
624 | | - | |
625 | | - | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
626 | 694 | | |
627 | | - | |
628 | | - | |
629 | | - | |
630 | | - | |
631 | | - | |
632 | | - | |
633 | | - | |
634 | | - | |
635 | | - | |
636 | | - | |
637 | | - | |
638 | | - | |
639 | | - | |
640 | | - | |
641 | | - | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
642 | 699 | | |
643 | | - | |
| 700 | + | |
644 | 701 | | |
645 | | - | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
646 | 736 | | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
647 | 741 | | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
| 742 | + | |
652 | 743 | | |
653 | 744 | | |
654 | 745 | | |
| |||
0 commit comments