jeevesagent.runtime.journaled
=============================

.. py:module:: jeevesagent.runtime.journaled

.. autoapi-nested-parse::

   Journal-based durable runtime.

   Wraps a :class:`JournalStore` with the :class:`Runtime` protocol. The
   contract: every ``step()`` and ``stream_step()`` call inside an open
   ``session(session_id)`` context records its result. On a subsequent
   call with the same ``(session_id, step_name)``, the cached result is
   returned without re-executing the underlying function.

   Session tracking uses :class:`contextvars.ContextVar`. anyio's
   structured concurrency propagates contextvars to spawned tasks, so
   parallel tool dispatches under ``_dispatch_tools`` still see the right
   session id without explicit threading.

   When ``step()`` is called outside any open session, the journal is
   bypassed and the function runs directly — the runtime degrades
   gracefully into the same behavior as :class:`InProcRuntime`.



Classes
-------

.. autoapisummary::

   jeevesagent.runtime.journaled.JournaledRuntime
   jeevesagent.runtime.journaled.JournaledSession


Module Contents
---------------

.. py:class:: JournaledRuntime(store: jeevesagent.runtime.journal.JournalStore | None = None)

   Runtime that journals every step's result for replay.

   Pass any :class:`JournalStore` (in-memory for tests, sqlite for
   durable single-process use, future Postgres/DBOS adapters for
   multi-process / multi-host).


   .. py:method:: session(session_id: str) -> collections.abc.AsyncIterator[JournaledSession]
      :async:



   .. py:method:: signal(session_id: str, name: str, payload: Any) -> None
      :async:



   .. py:method:: step(name: str, fn: collections.abc.Callable[Ellipsis, collections.abc.Awaitable[Any]], *args: Any, idempotency_key: str | None = None, **kwargs: Any) -> Any
      :async:



   .. py:method:: stream_step(name: str, fn: collections.abc.Callable[Ellipsis, collections.abc.AsyncIterator[Any]], *args: Any, **kwargs: Any) -> collections.abc.AsyncIterator[Any]


   .. py:attribute:: name
      :value: 'journaled'



   .. py:property:: store
      :type: jeevesagent.runtime.journal.JournalStore



.. py:class:: JournaledSession(session_id: str)

   The handle yielded by :meth:`JournaledRuntime.session`.


   .. py:method:: deliver(name: str, payload: Any) -> None
      :async:



   .. py:attribute:: id


