fix(agent): seed trace_id for agent process lifecycle

Agent logs had trace_id='no-trace' because the Gradio process
never called seed_trace_id(). The CotJsonFormatter reads trace_id
from ContextVar — without seeding, it defaults to empty string
displayed as 'no-trace'.

Fix:
- app.py: seed_trace_id() on every agent_handler invocation
- run.py: seed_trace_id() on agent startup (for LLM config fetch)

Each Gradio submit gets a fresh trace_id, making agent logs
correlatable with downstream FastAPI calls.
This commit is contained in:
2026-06-30 17:33:21 +03:00
parent 79d0f8f678
commit 2f238dee13
2 changed files with 9 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ import os
import socket
import httpx
from src.core.cot_logger import seed_trace_id
from src.core.logger import logger
FASTAPI_URL = os.getenv("FASTAPI_URL", "http://localhost:8000")
@@ -85,6 +86,8 @@ if __name__ == "__main__":
from src.agent.context import set_service_jwt
from src.agent.langgraph_setup import configure_from_api, init_checkpointer
seed_trace_id() # Seed trace for agent startup lifecycle
# Propagate SERVICE_JWT to ContextVar for tool calls
service_token = os.getenv("SERVICE_JWT", "")
if service_token: