Commit 0ade7ca
session: a session whose runner died can be reclaimed deliberately (#127)
Closes #19. A runner's claim is a compare-and-set, not a lease: it stops a
second runner from claiming a session and cannot notice one that died holding
it. The row stayed `running` with the dead `runner_pid` still on it -- so the
store knew who died and offered no way to act on it. Every later `run()` raised
`SessionBusy` forever, and the only remedy was a hand-written UPDATE, which
skips the lifecycle check and writes no transition row, corrupting the audit
trail the store exists to keep.
`SessionStore.release_dead_runner`, surfaced as `SessionManager.reclaim`.
**`failed`, not `interrupted`.** `interrupted` says a turn stopped somewhere it
can be picked up from; a runner that died left no such point. `failed` says the
turn did not settle, which is true, and is already resumable.
**Open holds survive.** `pending_approval` is left alone, so a session waiting
on a human is still waiting afterwards. Reclaiming a wedged session must not be
a way past an approval gate, and a test asserts the hold is still there.
**The liveness check runs inside `BEGIN IMMEDIATE`**, not before it, so two
operators reclaiming at once serialise on it. A check outside the write lock is
the same deferred-read race `_transaction`'s docstring already describes for
claiming.
Four refusals, each with a test: the session is not `running`; the pid is alive
(or belongs to another user, `PermissionError`, read as alive on purpose); the
pid is this process; a `running` row carries no `runner_pid` at all, which is
inconsistent in its own right and not something to paper over.
Pid reuse is not solved and is not pretended to be: a recycled pid reads as
alive, which is a refusal -- the safe direction. That is why nothing calls this
automatically. An automatic sweep would be a way for two live runners to fight
over one session, which is what the claim exists to prevent.
The crash is a real one in the tests: a child claims the session and `os._exit`s,
skipping every cleanup path, which is what a SIGKILL looks like from the store's
side. The alive-refusal test parks a real child on a file barrier rather than
inventing a pid, and the dead pid used elsewhere is spawned and reaped rather
than guessed -- a made-up number can belong to something, and the check under
test refuses a live pid.
The three honesty paragraphs this obsoletes are updated: `store.transition`'s
docstring, `session/runtime.py`'s limitations list, and the deep dive's. The
README no longer states it -- that sentence moved to the deep dive since the
issue was filed.
Verified: 2210 selected, 13 deselected, ruff clean.
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent 2e4b836 commit 0ade7ca
4 files changed
Lines changed: 301 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
253 | | - | |
| 253 | + | |
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | | - | |
| 257 | + | |
258 | 258 | | |
259 | 259 | | |
260 | 260 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
| |||
816 | 820 | | |
817 | 821 | | |
818 | 822 | | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
819 | 842 | | |
820 | 843 | | |
821 | 844 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
113 | 114 | | |
114 | 115 | | |
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 | + | |
116 | 141 | | |
117 | 142 | | |
118 | 143 | | |
| |||
417 | 442 | | |
418 | 443 | | |
419 | 444 | | |
420 | | - | |
421 | | - | |
| 445 | + | |
| 446 | + | |
422 | 447 | | |
423 | 448 | | |
424 | 449 | | |
| |||
461 | 486 | | |
462 | 487 | | |
463 | 488 | | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
464 | 576 | | |
465 | 577 | | |
466 | 578 | | |
| |||
0 commit comments