Expand description
Store for the agent-driven conversation-compaction directive (#1570 P1).
The MCP server cannot rewrite the client’s conversation — only the proxy
sees the messages. ctx_session(action="compact") therefore records a
directive; the proxy applies it to the requests of the app session that
armed it (cache-safe, live-suffix only). Restore is lossless by
construction: the client resends the full original history each turn, so
clearing the directive is enough.
One proxy carries many app sessions (the launching app’s
x-leanctx-session-id header, LEAN_CTX_SESSION_ID for the agent’s MCP
server). Every directive belongs to exactly one of them: it is stored
under that session, applied only to requests naming it, and a request
that names no valid session gets none (fail closed). The proxy also notes
each session it carries, so ctx_session compact can say honestly
whether a proxy would apply the directive at all.
Structs§
Functions§
- clear
- Drop the directive of
session— its next request carries the full original history again, so this alone is a complete, lossless restore. - create
- Create a new directive for
session. Fails when the session has no valid id, or when its previous one was created less thanMIN_INTERVAL_SECSago (rate limit — nothing is ever blocked, the agent simply keeps its current, already-compacted context). - is_
carried - Whether a proxy carried a request of
sessionwithin the carried window. - load_
active - The directive of
sessionwhen it exists and is younger thanTTL_SECS. - note_
carried - The proxy carried a request of
sessionnow. Best effort and throttled: a failed note only makes a latercompactreply say “no proxy”. - save