Commit bce78aa
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 96cb851 commit bce78aa
3 files changed
Lines changed: 430 additions & 136 deletions
File tree
- packages/studyloop
- src/studyloop/web/routes
- tests
| 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 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
2 | 9 | | |
3 | 10 | | |
4 | 11 | | |
5 | 12 | | |
6 | 13 | | |
7 | 14 | | |
8 | 15 | | |
9 | | - | |
10 | 16 | | |
11 | 17 | | |
12 | 18 | | |
13 | | - | |
14 | 19 | | |
15 | 20 | | |
16 | 21 | | |
17 | 22 | | |
18 | 23 | | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | 24 | | |
57 | 25 | | |
58 | 26 | | |
| |||
83 | 51 | | |
84 | 52 | | |
85 | 53 | | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
0 commit comments