Add session IDs, forking, ephemeral sessions and auto-resume

Merged
SA
2mo ago
+1770-106

A relay that stores sessions names each one in ChildEvent.session_id, set on its first reply to Configure or Load whatever that reply's kind, so a load of a suspended session still carries it. Configure.persistence asks the relay to store a session or not, and Load.fork copies a stored session under a new ID instead of claiming it. Children ignore all three, so PROTOCOL_VERSION does not move.

monty-pool exposes Persistence, ReplConfig::persistence, Checkout::session_id and restore(.., fork, ..). With PoolConfig::auto_resume (default on) a checkout whose relay drains a named session redials, reclaims it by ID and re-sends the request the relay did not run, returning the original Shutdown if the reclaimed session does not match.

pydantic_monty adds checkout(ephemeral=), AsyncMontyWebsocket(auto_resume=), fork= on the async loads and AsyncMontySession.session_id.

Claude-Session: https://claude.ai/code/session_015K5gKCYXr4yxxoKyb6fC19


Summary by cubic

Adds session IDs, forking, ephemeral sessions, and auto-resume for relays that store sessions.

Session storage

  • Storing relays name each session in ChildEvent.session_id and honor Configure.persistence; loading an ID always starts a fresh session under a new ID, so forking is Dump then two Loads. Children ignore all three, so PROTOCOL_VERSION stays at 5; a relay without a store refuses Dump/Load with Error and names nothing on shutdown.
  • monty-pool exposes Persistence, ReplConfig::persistence, and Checkout::session_id. With PoolConfig::auto_resume (default on) a checkout whose relay answers with Shutdown redials, loads the named state into a new session, re-announces the same suspension, and re-sends the request the relay didn't run, returning the original Shutdown if nothing was named or the reload fails. The resumed session keeps its own budget — only the suspension and sleep totals reset for the re-announcement — and takes its ID from the Load reply. The turn hot path stays a single async layer with the resume as a boxed tail branch and an untouched result, so auto-resume adds no per-turn cost.
  • pydantic_monty adds checkout(ephemeral=), AsyncMontyWebsocket(auto_resume=), and AsyncMontySession.session_id, reported even when adopted mid-turn; monty.pool.session.resumed records each attempt's outcome.
  • A Load the worker refuses with Error keeps the session's prior ID so its parked state stays resumable; an over-budget aborted re-announcement keeps the new session's ID instead.
  • Datatest now allows 15s (up from 4s) before calling a test hung, since a debug CI timeout exceeded the old limit.