Repository navigation
Commit ea4362c
fix(session): make PTY start + end routes async; pin uvicorn loop=asyncio
Three coordinated fixes that the per-agent Playwright matrix surfaced
(the unit-test stubs were swallowing all three):
1. POST /api/session/start is now async def. The previous sync handler
ran on the thread-pool worker, so ``asyncio.run(active.acquire(...))``
spun up a fresh event loop in a non-main thread. Python's signal
module disallows installing signal handlers off the main thread —
``loop.add_signal_handler(SIGCHLD, ...)`` (from PTYTransport's
SIGCHLD reaper) raised ``set_wakeup_fd only works in main thread``.
Running on the FastAPI loop (main thread) fixes it.
2. POST /api/session/end is now async def and ``await
active.release()`` before the legacy tmux cleanup. Without this,
ending a PTY session cleared session_state.json but left
active._active holding the transport, so the next start got
409 "already active" even though the UI had clearly ended.
3. ``studyloop web`` now runs uvicorn with ``loop="asyncio"`` (not
the default uvloop). uvloop reserves SIGCHLD for its own
subprocess watcher and refuses ``loop.add_signal_handler`` calls
with ``cannot add a signal handler for SIGCHLD: it is used by
the event loop``. The asyncio loop allows it; cost is a small
perf delta irrelevant for a localhost single-user dashboard.
These fixes were hidden from the §1.5b unit suite because those
tests stub _build_pty_transport with a StubTransport, which never
touches ``pty.fork()`` or SIGCHLD. The per-agent matrix hits the
real path (with STUDYLOOP_TEST_AGENT_CMD='echo ready; exec cat'
stubbing only the agent binary) and exposed all three.
Main suite 2001 passed; per-agent matrix 15/15 green across claude,
codex, gemini, kiro, opencode.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 06ed6dd commit ea4362c
2 files changed
Lines changed: 37 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
427 | 427 | | |
428 | 428 | | |
429 | 429 | | |
430 | | - | |
| 430 | + | |
431 | 431 | | |
432 | 432 | | |
433 | 433 | | |
| |||
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
442 | 447 | | |
443 | 448 | | |
444 | 449 | | |
445 | | - | |
| 450 | + | |
446 | 451 | | |
447 | 452 | | |
448 | 453 | | |
449 | | - | |
| 454 | + | |
450 | 455 | | |
451 | 456 | | |
452 | 457 | | |
453 | 458 | | |
454 | 459 | | |
455 | | - | |
| 460 | + | |
456 | 461 | | |
457 | 462 | | |
458 | | - | |
459 | 463 | | |
460 | 464 | | |
461 | 465 | | |
| |||
578 | 582 | | |
579 | 583 | | |
580 | 584 | | |
581 | | - | |
| 585 | + | |
582 | 586 | | |
583 | 587 | | |
584 | 588 | | |
| |||
1000 | 1004 | | |
1001 | 1005 | | |
1002 | 1006 | | |
1003 | | - | |
1004 | | - | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
1005 | 1017 | | |
1006 | 1018 | | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
1007 | 1023 | | |
1008 | 1024 | | |
1009 | 1025 | | |
| |||
0 commit comments