pig/obs/session
JSONL session writer — records SessionEvents to a file for replay.
OTP actor that receives SessionEvents and appends them as JSONL lines. Two modes:
record()— fire-and-forget, never blocks the agent.record_sync()— synchronous call, blocks until written. For testing.
Types
Replay error type for session reconstruction.
pub type ReplayError {
FileError(String)
ParseError(String)
}
Constructors
-
FileError(String) -
ParseError(String)
Opaque handle to the session writer actor.
pub opaque type SessionWriter
Values
pub fn decode_message() -> decode.Decoder(message.Message)
Decode a Message from JSON.
pub fn decode_tool_call() -> decode.Decoder(message.ToolCall)
Decode a ToolCall from JSON.
pub fn format_event(event: events.SessionEvent) -> String
Format a SessionEvent as a JSON string (pure function, no side effects).
pub fn record(
writer: SessionWriter,
event: events.SessionEvent,
) -> Nil
Record a session event. Fire-and-forget: does not block.
pub fn record_sync(
writer: SessionWriter,
event: events.SessionEvent,
) -> Nil
Record a session event synchronously. Blocks until the event is written to disk. Use this in tests for deterministic assertions.
pub fn replay(
path: String,
) -> Result(List(message.Message), ReplayError)
Replay a JSONL session file and reconstruct the message history.
Strategy: find the last InferenceCompleted event. Its input_messages + message give the complete history. For partial sessions (crash mid-loop), also include Tool messages from ToolExecuted events after the last inference.
pub fn start(
path: String,
) -> Result(SessionWriter, actor.StartError)
Start a new session writer actor that appends events to the given file.
pub fn start_consumer(
path: String,
) -> Result(
process.Subject(events.SessionEvent),
actor.StartError,
)
Start a session consumer actor that accepts SessionEvent directly. Used by the dispatcher to fan out events. Returns the Subject for registration. This is the consumer version of the actor — it receives SessionEvent directly, not WriterMessage wrappers. Fire-and-forget: does not block.
pub fn supervised(
path: String,
name: process.Name(events.SessionEvent),
) -> supervision.ChildSpecification(Nil)
Create a supervised session consumer actor for use in a supervision tree. The supervised actor’s message type is SessionEvent directly (not WriterMessage).