Commit 3c711f3
Fix spinner/Esc interrupt when MCP startup completes mid-turn (#8661)
## **Problem**
Codex’s TUI uses a single “task running” indicator (spinner + Esc interrupt hint)
to communicate “the UI is busy”. In practice, “busy” can mean two different
things: an agent turn is running, or MCP servers are still starting up. Without a
clear contract, those lifecycles can interfere: startup completion can clear the
spinner while a turn is still in progress, or the UI can appear idle while MCP is
still booting. This is user-visible confusion during the most important moments
(startup and the first turn), so it was worth making the contract explicit and
guarding it.
## **Mental model**
`ChatWidget` is the UI-side adapter for the `codex_core::protocol` event stream.
It receives `EventMsg` events and updates two major UI surfaces: the transcript
(history/streaming cells) and the bottom pane (composer + status indicator).
The key concept after this change is that the bottom pane’s “task running”
indicator is treated as **derived UI-busy state**, not “agent is running”. It is
considered active while either:
- an agent turn is in progress (`TurnStarted` → completion/abort), or
- MCP startup is in progress (`McpStartupUpdate` → `McpStartupComplete`).
Those lifecycles are tracked independently, and the bottom-pane indicator is
defined as their union.
## **Non-goals**
- This does not introduce separate UI indicators for “turn busy” vs “MCP busy”.
- This does not change MCP startup behavior, ordering guarantees, or core
protocol semantics.
- This does not rework unrelated status/header rendering or transcript layout.
## **Tradeoffs**
- The “one flag represents multiple lifecycles” approach remains lossy: it
preserves correct “busy vs idle” semantics but cannot express *which* kind of
busy is happening without further UI changes.
- The design keeps complexity low by keeping a single derived boolean, rather
than adding a more expressive bottom-pane state machine. That’s chosen because
it matches existing UX and minimizes churn while fixing the confusion.
## **Architecture**
- `codex-core` owns the actual lifecycles and emits `codex_core::protocol`
events.
- `ChatWidget` owns the UI interpretation of those lifecycles. It is responsible
for keeping the bottom pane’s derived “busy” state consistent with the event
stream, and for updating the status header when MCP progress updates arrive.
- The bottom pane remains a dumb renderer of the single “task running” flag; it
does not learn about MCP or agent turns directly.
## **Observability**
- When working: the spinner/Esc hint stays visible during MCP startup and does
not disappear mid-turn when `McpStartupComplete` arrives; startup status
headers can update without clearing “busy” for an active turn.
- When broken: you’ll see the spinner/hint flicker off while output is still
streaming, or the UI appears idle while MCP startup status is still changing.
## **Tests**
- Adds/strengthens a regression test that asserts MCP startup completion does
not clear the “task running” indicator for an active turn (in both `tui` and
`tui2` variants).
- These tests prove the **contract** (“busy is the union of turn + startup”) at
the UI boundary; they do not attempt to validate MCP startup ordering,
real-world startup timing, or backend integration behavior.
Fixes #7017
Signed-off-by: 2mawi2 <2mawi2@users.noreply.github.com>
Co-authored-by: 2mawi2 <2mawi2@users.noreply.github.com>
Co-authored-by: Josh McKinney <joshka@openai.com>1 parent 141d2b5 commit 3c711f3
File tree
4 files changed
+158
-14
lines changed- codex-rs
- tui2/src
- chatwidget
- tui/src
- chatwidget
4 files changed
+158
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
| |||
330 | 335 | | |
331 | 336 | | |
332 | 337 | | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
333 | 344 | | |
334 | 345 | | |
335 | 346 | | |
| |||
364 | 375 | | |
365 | 376 | | |
366 | 377 | | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
367 | 388 | | |
368 | 389 | | |
369 | 390 | | |
| |||
457 | 478 | | |
458 | 479 | | |
459 | 480 | | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
460 | 489 | | |
461 | 490 | | |
462 | 491 | | |
| |||
613 | 642 | | |
614 | 643 | | |
615 | 644 | | |
| 645 | + | |
616 | 646 | | |
617 | | - | |
| 647 | + | |
618 | 648 | | |
619 | 649 | | |
620 | 650 | | |
| |||
628 | 658 | | |
629 | 659 | | |
630 | 660 | | |
631 | | - | |
| 661 | + | |
| 662 | + | |
632 | 663 | | |
633 | 664 | | |
634 | 665 | | |
| |||
755 | 786 | | |
756 | 787 | | |
757 | 788 | | |
758 | | - | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
759 | 793 | | |
760 | 794 | | |
761 | 795 | | |
762 | 796 | | |
763 | | - | |
| 797 | + | |
| 798 | + | |
764 | 799 | | |
765 | 800 | | |
766 | 801 | | |
| |||
789 | 824 | | |
790 | 825 | | |
791 | 826 | | |
792 | | - | |
| 827 | + | |
793 | 828 | | |
794 | 829 | | |
795 | 830 | | |
| |||
845 | 880 | | |
846 | 881 | | |
847 | 882 | | |
848 | | - | |
| 883 | + | |
849 | 884 | | |
850 | 885 | | |
851 | 886 | | |
| |||
1522 | 1557 | | |
1523 | 1558 | | |
1524 | 1559 | | |
| 1560 | + | |
1525 | 1561 | | |
1526 | 1562 | | |
1527 | 1563 | | |
| |||
1612 | 1648 | | |
1613 | 1649 | | |
1614 | 1650 | | |
| 1651 | + | |
1615 | 1652 | | |
1616 | 1653 | | |
1617 | 1654 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
1 | 7 | | |
2 | 8 | | |
3 | 9 | | |
| |||
30 | 36 | | |
31 | 37 | | |
32 | 38 | | |
| 39 | + | |
33 | 40 | | |
34 | 41 | | |
35 | 42 | | |
| |||
409 | 416 | | |
410 | 417 | | |
411 | 418 | | |
| 419 | + | |
412 | 420 | | |
413 | 421 | | |
414 | 422 | | |
| |||
2953 | 2961 | | |
2954 | 2962 | | |
2955 | 2963 | | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
| 2969 | + | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
| 2984 | + | |
| 2985 | + | |
| 2986 | + | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
2956 | 2990 | | |
2957 | 2991 | | |
2958 | 2992 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
| |||
298 | 303 | | |
299 | 304 | | |
300 | 305 | | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
301 | 312 | | |
302 | 313 | | |
303 | 314 | | |
| |||
331 | 342 | | |
332 | 343 | | |
333 | 344 | | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
334 | 355 | | |
335 | 356 | | |
336 | 357 | | |
| |||
423 | 444 | | |
424 | 445 | | |
425 | 446 | | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
426 | 455 | | |
427 | 456 | | |
428 | 457 | | |
| |||
579 | 608 | | |
580 | 609 | | |
581 | 610 | | |
| 611 | + | |
582 | 612 | | |
583 | | - | |
| 613 | + | |
584 | 614 | | |
585 | 615 | | |
586 | 616 | | |
| |||
593 | 623 | | |
594 | 624 | | |
595 | 625 | | |
596 | | - | |
| 626 | + | |
| 627 | + | |
597 | 628 | | |
598 | 629 | | |
599 | 630 | | |
| |||
720 | 751 | | |
721 | 752 | | |
722 | 753 | | |
723 | | - | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
724 | 758 | | |
725 | 759 | | |
726 | 760 | | |
727 | 761 | | |
728 | | - | |
| 762 | + | |
| 763 | + | |
729 | 764 | | |
730 | 765 | | |
731 | 766 | | |
| |||
754 | 789 | | |
755 | 790 | | |
756 | 791 | | |
757 | | - | |
| 792 | + | |
758 | 793 | | |
759 | 794 | | |
760 | 795 | | |
| |||
810 | 845 | | |
811 | 846 | | |
812 | 847 | | |
813 | | - | |
| 848 | + | |
814 | 849 | | |
815 | 850 | | |
816 | 851 | | |
| |||
1381 | 1416 | | |
1382 | 1417 | | |
1383 | 1418 | | |
| 1419 | + | |
1384 | 1420 | | |
1385 | 1421 | | |
1386 | 1422 | | |
| |||
1469 | 1505 | | |
1470 | 1506 | | |
1471 | 1507 | | |
| 1508 | + | |
1472 | 1509 | | |
1473 | 1510 | | |
1474 | 1511 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
1 | 7 | | |
2 | 8 | | |
3 | 9 | | |
| |||
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
| 38 | + | |
32 | 39 | | |
33 | 40 | | |
34 | 41 | | |
| |||
397 | 404 | | |
398 | 405 | | |
399 | 406 | | |
| 407 | + | |
400 | 408 | | |
401 | 409 | | |
402 | 410 | | |
| |||
2520 | 2528 | | |
2521 | 2529 | | |
2522 | 2530 | | |
| 2531 | + | |
| 2532 | + | |
| 2533 | + | |
| 2534 | + | |
| 2535 | + | |
| 2536 | + | |
| 2537 | + | |
| 2538 | + | |
| 2539 | + | |
| 2540 | + | |
| 2541 | + | |
| 2542 | + | |
| 2543 | + | |
| 2544 | + | |
| 2545 | + | |
| 2546 | + | |
| 2547 | + | |
| 2548 | + | |
| 2549 | + | |
| 2550 | + | |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
| 2554 | + | |
| 2555 | + | |
| 2556 | + | |
| 2557 | + | |
| 2558 | + | |
2523 | 2559 | | |
2524 | 2560 | | |
2525 | 2561 | | |
| |||
0 commit comments