Skip to main content

Module agent_session_runtime

Module agent_session_runtime 

Source
Expand description

AgentSessionRuntime — owns the current AgentSession and drives the new / switch / fork / import replacement pipeline.

Ports coding-agent/src/core/agent-session-runtime.ts. The runtime is single-owner: each replacement operation (under a serializing async mutex) creates the replacement session, tears down the current one, atomically swaps, and rebinds listeners on the new session.

Replacement order (matches TS regression 2860: withSession runs AFTER rebind on the NEW session):

  1. emit_before_switch / emit_before_fork (cancellable).
  2. Build the new session manager.
  3. Call the factory → new session + services + diagnostics.
  4. teardown_current: typed session_shutdown{reason, targetSessionFile} emit, then before_session_invalidate, then session.dispose().
  5. apply(result): swap session + services + diagnostics.
  6. finish_session_replacement: rebind_session(new_session) then optional with_session(ctx). The mode’s rebind calls bind_extensions on the new session, which emits the stored session_start{new|resume|fork} after the old host received its session_shutdown in step 4.

Re-exports§

pub use crate::core::session_transfer::SessionImportFileNotFoundError as SessionImportFileNotFound;

Structs§

AgentSessionRuntime
Owns the current AgentSession plus cwd-bound services, and drives the replacement pipeline for new / switch / fork / import.
AgentSessionRuntimeServices
Cwd-bound service handles the runtime needs to drive replacements.
CreateAgentSessionRuntimeOptions
Inputs to CreateAgentSessionRuntimeFactory::create.
CreateAgentSessionRuntimeResult
Result returned by CreateAgentSessionRuntimeFactory::create.
ForkOutcome
Outcome of fork.
NewSessionOptions
Options for AgentSessionRuntime::new_session.
SwitchOutcome
Outcome of new_session / switch_session / import_from_jsonl.
SwitchSessionOptions
Options for AgentSessionRuntime::switch_session.

Enums§

AgentSessionRuntimeError
Errors from runtime operations.
ForkPosition
Options for AgentSessionRuntime::fork.

Traits§

CreateAgentSessionRuntimeFactory
Factory that builds a fresh session + services from a session manager.

Functions§

create_agent_session_runtime
Create the initial runtime from a factory and initial session manager.

Type Aliases§

BeforeSessionInvalidateCallback
Synchronous callback invoked after session_shutdown handlers finish but before the old session is invalidated (host UI teardown that must not yield to the event loop).
RebindSessionCallback
Async callback invoked on the new session after teardown + apply, before with_session. Re-binds listeners / event subscriptions.