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.
- Local
Worker - 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 itsctx_agentrole 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_appwithroleto 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 thanWORKER_CAPexist; past the cap the session maps to rolegeneral(of its host when that worker exists, else the firstgeneralworker, else the first worker).attachmakes 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_agentagent type, the process environment, thenmcp-client:<clientInfo.name>. - give_up
give_up_inon the book ofinstance_id, for an explicit retirement (lean-ctx cloud worker retire <wkr_…>). Refused when an active local session holds one ofids(Cloud would delete a worker that keeps posting), or when the agent registry cannot be read to tell;forceskips that check.- give_
up_ idle - Give up every worker idle for
idleor longer (idle_workers), under the book’s lock. No request: Cloud hears of them withsuper::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 inin_use, and last seen beforecutoff_ms(never seen: idle). Withsession_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;Nonewhen 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_idas pending retirement (Cloud retired it, or never knew it). - update_
book - Read-modify-write the book under its lock.