fix(agent): redact private recovery and reconnect diagnostics
This commit is contained in:
1 parent
2640251076
commit
d37d7c07c0
6 files changed
+160
-14
No files matched your search
+14
-2
@@ -1458,6 +1458,10 @@ class AgentLoop:
|
||||
msg = deferred.pop(0)
|
||||
if not deferred:
|
||||
self._deferred_automation_turns.pop(session_key)
|
||||
session = self.sessions.get_cached(session_key)
|
||||
log_content = session is None or (
|
||||
session.policy.persist and session.policy.log_content
|
||||
)
|
||||
try:
|
||||
await self._dispatch_one(msg, pending)
|
||||
except asyncio.CancelledError as exc:
|
||||
@@ -1465,7 +1469,7 @@ class AgentLoop:
|
||||
coordinator.complete(msg, error=exc)
|
||||
raise
|
||||
except Exception:
|
||||
logger.exception(
|
||||
logger.opt(exception=log_content).error(
|
||||
"Session worker failed one message for {}; continuing FIFO",
|
||||
session_key,
|
||||
)
|
||||
@@ -1504,6 +1508,12 @@ class AgentLoop:
|
||||
) -> None:
|
||||
"""Process one root message while later inputs remain in its session inbox."""
|
||||
session_key = self._effective_session_key(msg)
|
||||
# The request context is reset before errors reach this boundary, and
|
||||
# discard may evict the session while a turn is still unwinding.
|
||||
session = self.sessions.get_cached(session_key)
|
||||
log_content = session is None or (
|
||||
session.policy.persist and session.policy.log_content
|
||||
)
|
||||
recovery_task_registered = False
|
||||
recovery_admission = self._recovery_admission
|
||||
current_task: asyncio.Task[Any] | None = None
|
||||
@@ -1588,7 +1598,9 @@ class AgentLoop:
|
||||
)
|
||||
raise
|
||||
except Exception as exc:
|
||||
logger.exception("Error processing message for session {}", session_key)
|
||||
logger.opt(exception=log_content).error(
|
||||
"Error processing message for session {}", session_key,
|
||||
)
|
||||
await delivery.fail(
|
||||
publish_completion=not turn_continuation.internal_continuation_pending(
|
||||
msg.metadata
|
||||
|
||||
@@ -23,6 +23,7 @@ from nanobot.agent.context_governance import (
|
||||
TranscriptBuilder,
|
||||
)
|
||||
from nanobot.agent.hook import AgentHook, AgentHookContext, AgentRunHookContext
|
||||
from nanobot.agent.tools.context import tool_log_content_allowed
|
||||
from nanobot.agent.tools.execution import execute_tool_calls
|
||||
from nanobot.agent.tools.registry import ToolRegistry
|
||||
from nanobot.events import NO_EVENTS, EventSink
|
||||
@@ -219,7 +220,7 @@ class AgentRunner:
|
||||
try:
|
||||
content = callback()
|
||||
except Exception:
|
||||
logger.exception("continuation_callback failed")
|
||||
logger.opt(exception=tool_log_content_allowed()).error("continuation_callback failed")
|
||||
return None
|
||||
if content is None or not content.strip():
|
||||
return None
|
||||
@@ -242,7 +243,7 @@ class AgentRunner:
|
||||
try:
|
||||
items = await callback()
|
||||
except Exception:
|
||||
logger.exception("injection_callback failed")
|
||||
logger.opt(exception=tool_log_content_allowed()).error("injection_callback failed")
|
||||
return []
|
||||
if not items:
|
||||
return []
|
||||
@@ -318,7 +319,7 @@ class AgentRunner:
|
||||
try:
|
||||
await hook.on_finally(context)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
logger.opt(exception=tool_log_content_allowed()).error(
|
||||
"AgentHook.on_finally error after {}",
|
||||
context.stop_reason or "run exception",
|
||||
)
|
||||
@@ -1181,7 +1182,7 @@ class AgentRunner:
|
||||
transcript=messages,
|
||||
)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
logger.opt(exception=tool_log_content_allowed()).error(
|
||||
"Budget-exhausted finalization failed for {}; using fallback",
|
||||
spec.session_key or "default",
|
||||
)
|
||||
|
||||
@@ -213,13 +213,14 @@ def _is_transient_connection_failure(exc: BaseException) -> bool:
|
||||
|
||||
|
||||
def _log_mcp_connection_failure(name: str, exc: BaseException, hint: str = "") -> None:
|
||||
exception = exc if tool_log_content_allowed() else False
|
||||
if _is_transient_connection_failure(exc):
|
||||
logger.warning("MCP server '{}': transient connection failure", name)
|
||||
logger.opt(exception=exc).debug(
|
||||
logger.opt(exception=exception).debug(
|
||||
"MCP server '{}' transient connection failure details", name
|
||||
)
|
||||
return
|
||||
logger.opt(exception=exc).error("MCP server '{}': failed to connect: {}", name, hint)
|
||||
logger.opt(exception=exception).error("MCP server '{}': failed to connect: {}", name, hint)
|
||||
|
||||
|
||||
def _is_session_terminated(exc: BaseException) -> bool:
|
||||
|
||||
Reference in new issue
Block a user