Skip to content

The agent that grows with you

fix: propagate logging session context after daemon-pool compress_context

kshitijk4poorbcbaaa402037
diff --git a/run_agent.py b/run_agent.py
index b7c8df67006..ad99cec2468 100644
--- a/run_agent.py
+++ b/run_agent.py
@@ -7192,7 +7192,7 @@ class AIAgent:
"session, or check auxiliary.compression."
)
- return run_compress_context_with_progress_timeout(
+ result = run_compress_context_with_progress_timeout(
worker=_run,
messages=messages,
system_prompt_fallback=_fallback_prompt,
@@ -7200,24 +7200,22 @@ class AIAgent:
total_ceiling_seconds=total_ceiling,
on_timeout=_on_timeout,
)
- self._active_compression_commit_fence = active_fence
+ # compress_context ran on a daemon pool worker thread; the session
+ # id rotation updated hermes_logging._session_context (a
+ # threading.local) on the WORKER thread, not this one. Propagate
+ # the current session_id back so subsequent log lines on this
+ # thread carry the rotated id (#34089).
try:
- return compress_context(
- self, messages, system_message,
- approx_tokens=approx_tokens, task_id=task_id, focus_topic=focus_topic,
- force=force,
- defer_context_engine_notification=defer_context_engine_notification,
- commit_fence=active_fence,
- )
- finally:
- if previous_fence is missing_fence:
- vars(self).pop("_active_compression_commit_fence", None)
- else:
- self._active_compression_commit_fence = previous_fence
- # Restore whatever the caller had, so a compaction never leaks its
- # tag into the surrounding scope.
- if token is not None:
- reset_conversation_context(token)
+ from hermes_logging import set_session_context
+ set_session_context(self.session_id)
+ except Exception:
+ pass
+ return result
+ finally:
+ # Restore whatever the caller had, so a compaction never leaks its
+ # tag into the surrounding scope.
+ if token is not None:
+ reset_conversation_context(token)
def _set_tool_guardrail_halt(self, decision: ToolGuardrailDecision) -> None:
"""Record the first guardrail decision that should stop this turn."""