H.Session.Server (H v0.3.0)

Copy Markdown View Source

Single mutation authority and durable coordinator for one H session.

Never blocks on LLM calls, tool execution, or slow SSE consumers. Groups ready mailbox mutations via drain-batch commits (H.Storage.commit/2), fences effect workers by {incarnation, task_id, attempt_id}, and broadcasts single-encoded ProcBin commit and ephemeral frames via H.PubSub.

Summary

Functions

abort_all(server, reason \\ "stopped")

@spec abort_all(GenServer.server(), String.t()) :: {:ok, map()} | {:error, term()}

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(server, reason \\ :shutdown)

@spec close(GenServer.server(), term()) :: :ok

execute_command(server, cmd)

@spec execute_command(GenServer.server(), map()) :: {:ok, map()} | {:error, term()}

export_branch(server, cid, at_entry_id \\ nil)

@spec export_branch(GenServer.server(), pos_integer(), nil | pos_integer()) ::
  {:ok, %{entries: [map()], agent: map()}} | {:error, term()}

get_detail(server)

@spec get_detail(GenServer.server()) :: {:ok, map()} | {:error, term()}

get_seq(server)

@spec get_seq(GenServer.server()) :: {:ok, non_neg_integer()}

get_submission_outcome(server, request_id)

@spec get_submission_outcome(GenServer.server(), String.t()) ::
  {:ok, map()} | {:error, :not_found}

get_tree(server)

@spec get_tree(GenServer.server()) :: {:ok, map()} | {:error, term()}

scan_entries(server, cid, query \\ %{})

@spec scan_entries(GenServer.server(), pos_integer(), map()) ::
  {:ok, %{items: [map()], next_cursor: nil | pos_integer()}} | {:error, term()}

seed_entries(server, entries, cid \\ 1)

@spec seed_entries(GenServer.server(), [map()], pos_integer()) ::
  {:ok, %{seeded: non_neg_integer(), seq: non_neg_integer()}} | {:error, term()}

snapshot_or_replay(server, cid, last_event_id)

@spec snapshot_or_replay(GenServer.server(), pos_integer(), nil | non_neg_integer()) ::
  {:ok,
   {:snapshot, non_neg_integer(), binary()}
   | {:replay, [{non_neg_integer(), binary()}]}}
  | {:error, term()}

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

verify_visible_entry(server, cid, entry_id)

@spec verify_visible_entry(GenServer.server(), pos_integer(), pos_integer()) ::
  {:ok, map()} | {:error, :not_found | :entry_not_visible}