Skip to main content

Module attach

Module attach 

Source
Expand description

Which worker a session belongs to (SPEC-ENGINE §3.6): host app detection, role normalisation, the 32-worker cap and the local book of durable workers. Sessions (mcp-<pid>-<uuid>) are only a detail of the worker they attach to.

Structs§

Attachment
The worker a session attaches to.
LocalWorker
A durable worker of this instance as the engine remembers it.

Constants§

WORKER_CAP
Durable workers one instance may have (workspace ids).

Functions§

agent_worker_key
The (host_app, role) of the worker a local presence speaks as: the host app from its transport or agent type, and its ctx_agent role made per session when the launching app named one (super::session_role). Two sessions of one role on one instance are two agents on Cloud; a subagent in the same session with the same role is the same agent.
attach
Attach a session of host_app with role to a durable worker of the enrolled instance, adding it to the book when new. A full book (32, as Cloud allows per instance) gives up the longest-unused worker no active session holds, so a new role gets its own worker instead of sharing another one’s.
attach_in
Pure attachment rule over the known workers: an existing (host, role) is reused; a new one is added while fewer than WORKER_CAP exist; past the cap the session maps to role general (of its host when that worker exists, else the first general worker, else the first worker). attach makes room first, so this fallback only happens when every worker is in use.
detect_host_app
Host app of a session, from the hints in order of trust: the MCP handshake’s identified host, the ctx_agent agent type, the process environment, then mcp-client:<clientInfo.name>.
give_up
give_up_in on the book of instance_id, for an explicit retirement (lean-ctx cloud worker retire <wkr_…>). Refused when an active local session holds one of ids (Cloud would delete a worker that keeps posting), or when the agent registry cannot be read to tell; force skips that check.
give_up_idle
Give up every worker idle for idle or longer (idle_workers), under the book’s lock. No request: Cloud hears of them with super::register::retire_evicted (the sync, the next registration). Fails closed: when the agent registry cannot be read, nothing is given up (which workers live sessions hold is unknown).
host_display
Display name of a host app in default worker names.
idle_workers
The workers that may retire (owner 09.11.: workers that are not active do not count and are switched off): not the connector’s own (host CAPTURE_HOST), held by no active session in in_use, and last seen before cutoff_ms (never seen: idle). With session_only, only the workers recorded as one app session’s (LocalWorker::per_session), which end with it.
known
The worker of (host_app, role) if the book has one, without adding or stamping anything (for sessions that have ended).
last_seen_ms
When a session last attached to worker (ms), else when it was registered; None when neither is known (a book from before either).
list
Every durable worker of the enrolled instance.
retired
Workers evicted from the book that Cloud still counts.
retirement_done
Forget worker_id as pending retirement (Cloud retired it, or never knew it).
update_book
Read-modify-write the book under its lock.