feat(logging): unify canonical task CoT events
This commit is contained in:
@@ -82,7 +82,7 @@ from .api.routes import (
|
||||
)
|
||||
from .api.routes.validation_tasks import router as validation_tasks
|
||||
from .core.auth.security import get_password_hash
|
||||
from ss_tools.shared.cot_logger import get_trace_id, seed_trace_id, set_trace_id
|
||||
from ss_tools.shared.cot_logger import build_cot_event, get_trace_id, seed_trace_id, set_trace_id
|
||||
from .core.database import AuthSessionLocal, init_db
|
||||
from .core.encryption_key import ensure_encryption_key
|
||||
from .core.logger import belief_scope, logger
|
||||
@@ -949,7 +949,7 @@ async def websocket_endpoint(websocket: WebSocket, task_id: str, source: str = N
|
||||
|
||||
def matches_filters(log_entry) -> bool:
|
||||
"""Check if log entry matches the filter criteria."""
|
||||
log_source = getattr(log_entry, "source", None)
|
||||
log_source = getattr(log_entry, "src", None) or getattr(log_entry, "source", None)
|
||||
if source_filter and str(log_source or "").lower() != source_filter:
|
||||
return False
|
||||
if level_filter:
|
||||
@@ -1014,12 +1014,13 @@ async def websocket_endpoint(websocket: WebSocket, task_id: str, source: str = N
|
||||
# ── Send synthetic AWAITING_INPUT prompt if needed ──
|
||||
task = task_manager.get_task(task_id)
|
||||
if task and task.status == "AWAITING_INPUT" and task.input_request:
|
||||
synthetic_log = {
|
||||
"timestamp": task.logs[-1].timestamp.isoformat() if task.logs else "2024-01-01T00:00:00",
|
||||
"level": "INFO",
|
||||
"message": "Task paused for user input (Connection Re-established)",
|
||||
"context": {"input_request": task.input_request},
|
||||
}
|
||||
synthetic_log = build_cot_event(
|
||||
src="task.lifecycle.websocket_reconnect",
|
||||
marker="REFLECT",
|
||||
intent="Task paused for user input (connection re-established)",
|
||||
payload={"input_request": task.input_request},
|
||||
)
|
||||
synthetic_log = {"task_id": task_id, **synthetic_log}
|
||||
await websocket.send_json(synthetic_log)
|
||||
logger.reason(
|
||||
"Replayed awaiting-input prompt to restored WebSocket client",
|
||||
@@ -1070,10 +1071,11 @@ async def websocket_endpoint(websocket: WebSocket, task_id: str, source: str = N
|
||||
"level": log_dict.get("level"),
|
||||
},
|
||||
)
|
||||
if "Task completed successfully" in result.message or "Task failed" in result.message:
|
||||
result_intent = getattr(result, "intent", None) or getattr(result, "message", "")
|
||||
if "Task completed successfully" in result_intent or "Task failed" in result_intent:
|
||||
logger.reason(
|
||||
"Observed terminal task log entry; delaying to preserve client visibility",
|
||||
payload={"task_id": task_id, "message": result.message},
|
||||
payload={"task_id": task_id, "intent": result_intent},
|
||||
)
|
||||
await asyncio.sleep(2)
|
||||
except (WebSocketDisconnect, StopIteration) as _ws_exc:
|
||||
|
||||
Reference in New Issue
Block a user