Expand description
Thread-local session context for log lines.
AFT runs a single-threaded request loop. Each incoming request carries a
session_id that identifies the OpenCode/Pi session. By storing it in a
thread-local we can automatically prepend [ses_xxx] to every slog_*
log macro call without threading the session id through every function
signature.
Background threads spawned during request handling (search-index pre-warm,
semantic-index build) must capture the session id before spawning and
re-install it on the new thread via set_session or with_session.
Functions§
- current_
session - Return the current session id (e.g.
"abcd1234"), orNoneif no session is set. - session_
prefix - Return the current session id prefix string, e.g.
"[ses_abcd1234] ", or an empty string if no session id has ever been observed on this thread. - set_
session - Set the current thread-local session id.
- with_
session - Run
fwith the given session id set on the current thread, restoring the previous value afterwards (RAII-style and panic-safe).