Skip to content

Leave no Pi extension timer armed after session_shutdown, and register the prompt handler previewSafe - #662

Merged
michael-denyer merged 7 commits into
mainfrom
pi-omo-shutdown-timer-preview-safe
Dec 4, 2026
Merged

michael-denyer merged 7 commits into
mainfrom
pi-omo-shutdown-timer-preview-safe

Conversation

@michael-denyer

@michael-denyer michael-denyer commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

On omo 5.1.92, the Pi extension left a timer armed after session_shutdown, and omo warned on stderr that it had closed it. omo --print-prompt-sizes exited 1 because the before_agent_start handler was not registered previewSafe, which also makes omo skip its prompt-cache prewarm.

What changed

  • In child.ts, PiChild clears its 30 s close timer when the child exits on its own. terminateGroup ends its grace early once the group's leader is gone. A 50 ms check of the leader covers every caller, including a restored orphan whose exit nothing reports. A caller whose run has an exit promise also passes it, which ends the grace at once if ours() no longer holds then. If the leader is still ours when the grace runs out, SIGKILL goes out as before.
  • hc-child.ts and orca-child.ts pass the run's exited to terminateGroup.
  • In t3-child.ts, end() clears its grace timer when the run ends, and a steer still waiting on that run stops waiting then.
  • In one-shot.ts, the 50 ms pending-message poll a print run keeps during its settle hold stops when the hold ends, in a finally, so a rejected wait for an agent stops it too.
  • In prompt.ts, the handler is registered with { previewSafe: true }. It reads the models sheet and the mandate, asks git for the project root, and returns what the turn gets. Pi 1.5.1 and 1.8.0 type on() with two arguments, so the call goes through a widened function type; Pi ignores the third argument at runtime.

Tests

tests/pi/timer-recorder.mjs counts timers the way omo's ExtensionHandleLedger does. A timer armed by code under plugins/pstack/pi counts until it fires or is cleared. Each test below failed on the code before its fix and passes now:

  • shutdown-timers.test.mjs: a foreground agent, a stopped agent, a print run's settle, a settle whose wait for an agent rejects, and a reaped orphan, checked 1 s into a 5 s grace.
  • orca-child.test.mjs, t3-child.test.mjs: a stopped run leaves no timer once it has exited.
  • child.test.mjs: a group still ours when its run's exit settles gets SIGKILL after the grace, and a leader still alive then ends the grace once it is gone.
  • prompt.test.mjs: a preview gets the same sections as the turn.

Checks

  • omo 5.1.92, engine senpi 2026.12.1-6, ran in a node:24 container with a stub model and no credentials. Main's Pi code has not changed since 7c6620d.

    Session main 7c6620d this branch at 53917f1
    plain -p, 20 runs 0 warnings 0 warnings
    foreground agent 1 timer 0
    stop_agent 1 timer 0
    --print-prompt-sizes exit 1, handler not previewSafe exit 0, extension:pstack 1440 bytes
  • bun test tests/ at 53917f1: 2950 pass, 0 fail, 300 skip.

  • bun tools/typecheck-pi.mjs: exit 0 against Pi 1.5.1 and 1.8.0.

  • PSTACK_PI_LIVE=1 bun test tests/pi/live.test.mjs on Pi 1.5.1 at 53917f1: 11 pass, 0 fail, 58 model calls.

  • Four reviews: one covered da4ae3e9, one covered c4083e17 and 9734b297, and one covered 12bb8411 and 53917f18. None found anything high or medium. 53917f18 handles two findings of the second review: a leader still exiting when its run's exit settled kept the full grace, and the SIGKILL test slept a fixed 100 ms waiting for a trap. c3aca9fe handles two of the third: the new leader-exit test's limit goes from 1 s to 2 s, and the changelog now says nothing observable changes on Pi. A fourth review covered c3aca9fe alone and found nothing to change in the code or tests.

  • c3aca9fe changes only that test limit and one changelog sentence, so the results above at 53917f1 hold for it. child.test.mjs passed 3 of 3 runs at it.

Rough edges

  • The herdr-core path has no local test. Its suite runs only on a live hc core with PSTACK_PI_HC_LIVE set. Its change is one line, and only the terminateGroup tests cover it.
  • A session that shuts down while a stopped process is still alive inside its grace leaves the grace timer and its 50 ms check armed, since the timer sends the SIGKILL. omo closes them and warns.
  • A restored orphan's stop now reports it gone once its own process exits, on Pi too, while other processes in its group may still be handling the SIGTERM. Before, the stop held the agent for the full 5 s grace.
  • The T3 change for a steer still in flight when a stopped run ends has no test; the path needs a non-abort failure from T3 Code during the stop.
  • No Orca test has a terminal that ignores SIGTERM. Only the terminateGroup test covers Orca's SIGKILL path.
  • The changelog fragment says nothing observable changes on Pi beyond the changes it names. One rare path on main was observable and is not named. If a print run's wait for an agent rejected, the 50 ms poll kept asking Pi for queued messages, and once Pi had disposed the session that call threw. A review reproduced the crash in a simulation, not in a real Pi session. This branch stops that poll.
  • omo's prompt-cache prewarm is off by default and was not observed. That it now runs is inferred from the same previewSafe rule.
  • The omo container covered the pi child process paths only. The hc, Orca, T3 and reap paths were not run on omo.

…rompt handler previewSafe

omo closes every timer an extension still holds after session_shutdown and warns about it, and it skips previews of the next system prompt while a before_agent_start handler is not registered previewSafe, which made omo --print-prompt-sizes exit 1.
terminateGroup clears its grace timer when the caller's exit settles and the process is no longer ours, and with no exit to wait on, as for a restored orphan, when a 50 ms poll finds the leader gone. hc and Orca pass their run's exit; T3's end() clears its grace timer and stops a waiting steer when the run ends. The timer recorder moves to tests/pi/timer-recorder.mjs so the Orca and T3 tests can use it.
…settles

terminateGroup now checks the leader every 50 ms in every case, so a process still exiting when its run's exit settles, as on the herdr-core error path, no longer keeps the grace timer for the full grace. The SIGKILL test waits for sh to set its trap instead of sleeping 100 ms.
@michael-denyer
michael-denyer merged commit fa8000a into main Dec 4, 2026
29 checks passed
@michael-denyer
michael-denyer deleted the pi-omo-shutdown-timer-preview-safe branch December 4, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant