Skip to main content

Module log_ctx

Module log_ctx 

Source
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"), or None if 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 f with the given session id set on the current thread, restoring the previous value afterwards (RAII-style and panic-safe).