Commit c923e30
authored
fix(pool): force-evict hung sessions so zombie slots cannot exhaust the pool (#1300)
* refactor(pool): extract idle and eviction classification helpers
Pure helpers for cleanup_idle stale detection and get_or_create eviction
candidate selection, with characterization tests for current behavior.
* feat(pool): add lock-free session activity tracking
SessionActivity exposes last-active and in-flight state without the
connection mutex; pool state mirrors activity handles alongside cancel handles.
* fix(pool): force-evict hung sessions past hard-timeout grace
cleanup_idle detects in-flight sessions stuck beyond
prompt_hard_timeout_secs + hung_grace_secs and evicts them lock-free.
* test(pool): cover hung classification and eviction bookkeeping
Extract classify_hung and apply_hung_eviction helpers with unit tests;
add SessionActivity touch/in-flight tests.
* docs(config): document pool.hung_grace_secs
Document the hung-session grace period and apply rustfmt to touched acp files.
* fix(pool)!: make hung eviction reset-like and harden cancel path
Hung sessions are purged from suspended/persisted (not suspended for
resume): the old streaming task may still own an in-flight turn, so
resuming the same session id is unsafe. Eviction uses the connection
handle captured at classification time via remove_if_same_handle, and
session/cancel is sent from a detached 5s-timeout task outside the
state lock. SessionActivity gains Release/Acquire ordering, a
saturating age() helper, and a test-only last_active setter.
* feat(pool): wire hung threshold from config into SessionPool::new
SessionPool::new now takes hung_threshold_secs; main.rs passes
prompt_hard_timeout_secs + hung_grace_secs and the builder setter is
removed. Document hung_grace_secs in config.toml.example.
* fix(pool): never await existing connection mutex under the creating gate
Awaiting a hung connection's mutex in get_or_create while holding the
per-thread creating gate would permanently jam all future messages for
that thread. try_lock and treat lock-held as busy/alive (F1).
* fix(pool): use monotonic clock for session activity timestamps
A wall-clock step (NTP, manual change) could make an active session
look hours stale and trigger a false hung eviction. Track activity as
milliseconds since a process-boot Instant instead of SystemTime (F2).
* fix(pool): self-heal stale in_flight flag during cleanup sweep
If cleanup_idle can try_lock the connection, no turn is streaming, so a
true in_flight flag means the turn aborted without prompt_done. Reset it
to prevent a future false hung classification (F3).
* fix(pool): kill hung agent process group after eviction
The hung task never unwinds, so AcpConnection::Drop never fires and the
ACP child would leak forever. Track child pgids lock-free in PoolState
and, after the 5s session/cancel attempt, SIGTERM then SIGKILL the
process group from the detached task (F4). Also enrich the eviction
warn with session id, age_secs and threshold_secs (F7).
* fix(acp): bound stdin writes in send_raw with a 10s timeout
A hung agent can stop draining stdin; an unbounded write_all would then
block the caller (and any mutex it holds) forever (F5).
* fix(pool): keep the creating gate when purging a hung session
The creating gate is concurrency control, not session state: removing
it while a holder still owns the old gate Arc lets a concurrent
get_or_create mint a fresh gate and run two creations for the same key (F6).
* test(dispatch): derive hung threshold from config defaults
Replace the magic 30*60+120 literal with the actual serde default fns
so the test constant cannot drift from config defaults (F8).1 parent db98646 commit c923e30
7 files changed
Lines changed: 488 additions & 31 deletions
File tree
- crates/openab-core/src
- acp
- docs
- src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
183 | 186 | | |
184 | 187 | | |
185 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
107 | 107 | | |
108 | 108 | | |
109 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 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 | + | |
110 | 172 | | |
111 | 173 | | |
112 | 174 | | |
| |||
119 | 181 | | |
120 | 182 | | |
121 | 183 | | |
| 184 | + | |
122 | 185 | | |
123 | 186 | | |
124 | 187 | | |
| |||
371 | 434 | | |
372 | 435 | | |
373 | 436 | | |
374 | | - | |
| 437 | + | |
| 438 | + | |
375 | 439 | | |
376 | 440 | | |
377 | 441 | | |
| |||
399 | 463 | | |
400 | 464 | | |
401 | 465 | | |
| 466 | + | |
| 467 | + | |
402 | 468 | | |
403 | 469 | | |
404 | 470 | | |
| |||
410 | 476 | | |
411 | 477 | | |
412 | 478 | | |
| 479 | + | |
413 | 480 | | |
414 | 481 | | |
415 | 482 | | |
| |||
422 | 489 | | |
423 | 490 | | |
424 | 491 | | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
429 | 503 | | |
430 | 504 | | |
431 | 505 | | |
| |||
572 | 646 | | |
573 | 647 | | |
574 | 648 | | |
| 649 | + | |
| 650 | + | |
575 | 651 | | |
576 | 652 | | |
577 | 653 | | |
| |||
606 | 682 | | |
607 | 683 | | |
608 | 684 | | |
| 685 | + | |
| 686 | + | |
609 | 687 | | |
610 | 688 | | |
611 | 689 | | |
| |||
634 | 712 | | |
635 | 713 | | |
636 | 714 | | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
637 | 724 | | |
638 | 725 | | |
639 | 726 | | |
| |||
872 | 959 | | |
873 | 960 | | |
874 | 961 | | |
875 | | - | |
876 | | - | |
877 | | - | |
878 | | - | |
879 | | - | |
880 | | - | |
881 | | - | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
882 | 966 | | |
883 | 967 | | |
884 | 968 | | |
| |||
934 | 1018 | | |
935 | 1019 | | |
936 | 1020 | | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
937 | 1050 | | |
0 commit comments