Skip to main content

Module m4a_wake

Module m4a_wake 

Source
Expand description

Letter wake for live sessions the node adopted (/m4a/adopt).

The old standalone mailbox daemon woke a session itself: its listener held the account’s push socket and pressed the turn on the provider’s leader. The node owns the accounts now, so it runs that listener in-process, one thread per adopted account (mail4agent’s library: open the account store, sync/push, new inbound letters). The store dedups by event and never hands over the account’s own messages; each letter goes to a per-session queue whose one worker pushes it into the live session through the leader (grok: ACP session/load + session/prompt, gate4agent_wake::grok_leader), with the session id and cwd recorded at adoption, so at most one push runs into a session at a time.

Adoptions persist in <accounts root>/adopted.json (no secret: provider, session id, cwd, nick, account ref, store root), so a node restart restarts the listeners. Nothing here embeds a host, key or name.

Structs§

Adoption
One adopted live session.
SpawnedWake
A wake signal for a session this node spawned: who wrote and which event. No letter text; the session reads the letter itself through m4a.

Constants§

ADOPTED_FILE
WEB_SESSION
Provider id of a web session woken by its routine webhook (no local process, no leader).

Functions§

grok_session_cwd
Working directory of a grok session from the provider’s own index (active_sessions.json rows {"session_id","cwd"}), falling back to the session file’s cwd field.
is_watched
Whether a listener of this account is currently wanted (started and not replaced).
leader_for
Leader endpoint of provider (grok only for now).
letter_prompt
The prompt a woken session gets: headers, how to answer, then the letter verbatim.
load_adoptions
restore
Restarts the listeners of every saved adoption (node start). Returns how many started.
restore_from_env
Node start: restore when the node has m4a accounts configured; says why not otherwise.
save_adoption
Inserts or replaces the adoption of (provider, session).
set_spawned_sink
Where wake signals of spawned sessions go (the node’s wake handle). Set once at start.
sole_adoption
The provider session an attach with no session of its own belongs to: the only adoption of that provider. Several adoptions are ambiguous (None).
unwatch
Stops the listener of an account (session ended).
watch
Starts (or restarts) the in-process mailbox listener of a.
watch_spawned
Starts the mailbox listener of an account this node assigned at spawn: it keeps the account open (sync, push, auto-join of invites by the m4a auto-join policy) and turns each new letter into a wake signal for that session.
watch_web_sessions
Starts the mailbox listener of every routine in policy that names its own m4a account (routines.<nick>.mailbox): the node is that web session’s courier, each new letter goes out as one routine POST. Returns how many started.