Repository navigation
Commit 1e89efa
authored
fix: tear down session interactions and background processes on close (#711)
## Summary
Follow up #710 with the session-close interaction and background-process
cleanup changes from the protocol review. Applies to ACP v1 and v2;
`session/delete` uses the same teardown path.
- Give session-scoped permission requests and elicitations a shared
cancellation owner, including idle/background interactions and
registered child sessions. Preserve caller cancellation and leave
request-scoped login interactions alone.
- Cancel pending interactions before waiting for runtime teardown and
reject new interactions while the owning session is closing.
- Stop Codex background processes before unsubscribe and before
responding to close, independently of AIR async-task display support.
Codex's unsubscribe only detaches the subscriber; delayed unload is not
a cleanup barrier.
- Share background-terminal pagination with the existing task tracker.
Read every page before terminating processes, and detect repeated
cursors.
- Clean up child processes only for ownership established by native
events/readbacks. Do not wait on unrelated metadata reads during close
or act on foreign ownership.
- Preserve the local session and subscriptions when process cleanup
fails, so close can be retried. A false termination result is checked
against the current process list rather than assumed to mean success.
- Make already-closed/unknown close requests succeed without unnecessary
Codex calls, and publish terminal task state only after successful
cleanup.
## Validation
- `npm run typecheck` — passed, including examples.
- `npm test` — 2,282 passed, 39 skipped.
- `npm run test:integration` — all 19 tests passed across 8 files.
- `npm run build` and `git diff --check` — passed.
- A new real-Codex integration test starts a long-lived shell process,
confirms it is alive, closes the session without AIR async-task support,
and confirms the OS process has exited when close responds.
- Real Codex smoke: `npm run codex-test -- -p "Reply with exactly OK. Do
not use tools or modify any files." -o summary` — completed with
`end_turn`.
- Opt-in E2E suite was not run.
## Remaining follow-ups
This is not a claim of complete v2 lifecycle conformance. The general
post-close notification fence, resume snapshots/metadata, setup response
ordering, and active-resume environment replacement remain separate
changes. Active-resume replacement also needs the spec decision about
in-flight operations using removed roots or MCP servers. No internal
review Markdown file is included.1 parent 6f96fbe commit 1e89efa
23 files changed
Lines changed: 567 additions & 55 deletions
File tree
- src
- __tests__
- CodexACPAgent
- data
- integration
- async-tasks
- subagents
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
| 11 | + | |
| 12 | + | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
36 | | - | |
| 40 | + | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
43 | 47 | | |
44 | | - | |
| 48 | + | |
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
51 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
52 | 91 | | |
53 | 92 | | |
54 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| |||
854 | 856 | | |
855 | 857 | | |
856 | 858 | | |
| 859 | + | |
| 860 | + | |
857 | 861 | | |
858 | 862 | | |
859 | 863 | | |
| |||
974 | 978 | | |
975 | 979 | | |
976 | 980 | | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
977 | 992 | | |
978 | | - | |
979 | | - | |
980 | | - | |
981 | | - | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
982 | 1010 | | |
983 | 1011 | | |
984 | 1012 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
112 | | - | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| |||
488 | 488 | | |
489 | 489 | | |
490 | 490 | | |
491 | | - | |
| 491 | + | |
492 | 492 | | |
493 | 493 | | |
494 | 494 | | |
| |||
594 | 594 | | |
595 | 595 | | |
596 | 596 | | |
| 597 | + | |
597 | 598 | | |
598 | 599 | | |
599 | 600 | | |
600 | | - | |
601 | | - | |
| 601 | + | |
| 602 | + | |
602 | 603 | | |
603 | 604 | | |
604 | 605 | | |
605 | 606 | | |
606 | 607 | | |
607 | 608 | | |
608 | | - | |
609 | | - | |
| 609 | + | |
| 610 | + | |
610 | 611 | | |
611 | 612 | | |
612 | 613 | | |
| |||
659 | 660 | | |
660 | 661 | | |
661 | 662 | | |
662 | | - | |
| 663 | + | |
663 | 664 | | |
664 | 665 | | |
665 | 666 | | |
| |||
677 | 678 | | |
678 | 679 | | |
679 | 680 | | |
680 | | - | |
| 681 | + | |
681 | 682 | | |
682 | 683 | | |
683 | 684 | | |
| |||
781 | 782 | | |
782 | 783 | | |
783 | 784 | | |
784 | | - | |
| 785 | + | |
785 | 786 | | |
786 | 787 | | |
787 | 788 | | |
| |||
843 | 844 | | |
844 | 845 | | |
845 | 846 | | |
846 | | - | |
| 847 | + | |
847 | 848 | | |
848 | 849 | | |
849 | 850 | | |
| |||
1361 | 1362 | | |
1362 | 1363 | | |
1363 | 1364 | | |
1364 | | - | |
| 1365 | + | |
1365 | 1366 | | |
1366 | 1367 | | |
1367 | 1368 | | |
| |||
1995 | 1996 | | |
1996 | 1997 | | |
1997 | 1998 | | |
1998 | | - | |
| 1999 | + | |
| 2000 | + | |
1999 | 2001 | | |
2000 | 2002 | | |
2001 | 2003 | | |
2002 | 2004 | | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
2003 | 2009 | | |
2004 | 2010 | | |
2005 | 2011 | | |
2006 | 2012 | | |
2007 | | - | |
2008 | | - | |
2009 | 2013 | | |
2010 | 2014 | | |
2011 | 2015 | | |
| |||
2023 | 2027 | | |
2024 | 2028 | | |
2025 | 2029 | | |
| 2030 | + | |
| 2031 | + | |
| 2032 | + | |
| 2033 | + | |
| 2034 | + | |
2026 | 2035 | | |
2027 | 2036 | | |
2028 | 2037 | | |
2029 | | - | |
| 2038 | + | |
2030 | 2039 | | |
2031 | 2040 | | |
2032 | 2041 | | |
| |||
2041 | 2050 | | |
2042 | 2051 | | |
2043 | 2052 | | |
| 2053 | + | |
2044 | 2054 | | |
2045 | 2055 | | |
2046 | 2056 | | |
| |||
3483 | 3493 | | |
3484 | 3494 | | |
3485 | 3495 | | |
3486 | | - | |
| 3496 | + | |
3487 | 3497 | | |
3488 | 3498 | | |
3489 | 3499 | | |
| |||
5480 | 5490 | | |
5481 | 5491 | | |
5482 | 5492 | | |
5483 | | - | |
| 5493 | + | |
5484 | 5494 | | |
5485 | 5495 | | |
5486 | 5496 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
| 105 | + | |
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| |||
838 | 839 | | |
839 | 840 | | |
840 | 841 | | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
841 | 856 | | |
842 | 857 | | |
843 | 858 | | |
| |||
0 commit comments