跳转到内容

错误恢复与工作流日志

系统包含多个后台恢复机制和工作流引擎,确保异常情况下的数据一致性。这些日志帮助监控后台任务的健康状态。

当服务重启或 Turn 执行异常中断时,系统自动扫描并恢复过期的 Turn。

事件触发时机关键字段
[Server] recoverStaleTurns: found stale turns发现过期 Turncount
[Server] recoverStaleTurns: published submit已发布恢复提交turn
[Server] recoverStaleTurns: skip closed session跳过已关闭的 Sessionsession
[Server] recoverStaleTurns: skip already-interrupted turn跳过已中断的 Turnturn
[Server] recoverStaleTurns: requeued ghost work重新入队幽灵任务work_id
[Server] recoverStaleTurns: released session lock释放 Session 锁session
[Server] recoverStaleTurns: skip lock release -- worker alive跳过锁释放(Worker 仍存活)session
[Server] periodicRecoverStaleTurns: found stale turns周期性扫描发现过期 Turncount
[Server] periodicRecoverStaleTurns: checkpoint expired检查点已过期turn
[Server] periodicRecoverStaleTurns: recovering stale running/interrupted turn正在恢复运行中/已中断的 Turnturn
[Server] publishRecoveryWorkItem: published恢复工作项已发布session, turn
事件触发时机关键字段
[loop.Recovery] started恢复扫描启动interval
[loop.Recovery] cancelled expired loop取消过期 Looploop_id
[loop.Recovery] re-enqueued stale loop重新入队停滞 Looploop_id
[loop.Cleanup] cancelled active loop清理活跃 Looploop_id
[loop.Cleanup] cancelled active goal清理活跃 Goalgoal_id
事件触发时机关键字段
[turnagent] createLoop.completedLoop 创建完成loop_id, session_id
[turnagent] createGoal.completedGoal 创建完成goal_id, session_id
[turnagent] pauseLoop.completedLoop 暂停loop_id, session_id
[turnagent] resumeLoop.completedLoop 恢复loop_id, session_id
[turnagent] listLoops.completedLoop 列表查询session_id, count
[turnagent] loopWorkflow.loop_exhaustedLoop 达到最大迭代loop_id, session_id
[turnagent] loopWorkflow.loop_extendedLoop 扩展迭代loop_id, session_id, iteration
[turnagent] loopWorkflow.scheduled_next已调度下一次执行loop_id, task_id
[turnagent] goalWorkflow.goal_exhaustedGoal 达到最大迭代goal_id, session_id
[turnagent] goalWorkflow.goal_extendedGoal 扩展迭代goal_id, session_id, iteration
事件触发时机关键字段
[lifecycle.Manager] component started组件启动成功component
[lifecycle.Manager] component stopped组件停止成功component
[lifecycle.Manager] start component failed组件启动失败component, error
[lifecycle.Manager] stop component failed组件停止失败component, error
[lifecycle.Manager] shutdown timeout关闭超时-
[lifecycle.Manager] goroutine panic组件 Goroutine 异常component, panic, stack
事件触发时机关键字段
Starting RTC Agent server...服务启动-
HTTP server listeningHTTP 服务就绪addr
LLM initializedLLM 初始化完成provider, model
Tracing enabledTracing 启用endpoint, sample_rate
Shutting down server...服务关闭中-
Server failed服务启动失败error
Database migration completed successfully数据库迁移完成-
事件触发时机关键字段
goroutine leak threshold exceededGoroutine 数超过阈值count, threshold
{service="server"} | json | msg=~"\\[Server\\] (recoverStaleTurns|periodicRecoverStaleTurns|publishRecoveryWorkItem)"
{service="server"} | json count="count" | msg=~"\\[Server\\] (recoverStaleTurns|periodicRecoverStaleTurns): found stale turns"
{service="server"} | json turn="turn" | msg=~"\\[Server\\] (recoverStaleTurns|periodicRecoverStaleTurns)" | turn="turn-123"
{service="server"} | json | msg=~"\\[Server\\] (recoverStaleTurns|periodicRecoverStaleTurns).*(failed|error)"
{service="server"} | json | msg=~"\\[loop\\.(Recovery|Cleanup)\\]"
{service="server"} | json | msg=~"\\[turnagent\\] (createLoop|createGoal|pauseLoop|resumeLoop|loopWorkflow|goalWorkflow)"
{service="server"} | json loop_id="loop_id" | msg=~"\\[turnagent\\] (createLoop|pauseLoop|resumeLoop|loopWorkflow|listLoops)" | loop_id="loop-abc"
{service="server"} | json | msg="[turnagent] loopWorkflow.loop_exhausted"
{service="server"} | json | msg="[turnagent] goalWorkflow.goal_exhausted"
{service="server"} | json component="component", error="error" | msg="[lifecycle.Manager] start component failed"
{service="server"} | json component="component", error="error" | msg="[lifecycle.Manager] stop component failed"
{service="server"} | json count="count", threshold="threshold" | msg="goroutine leak threshold exceeded"
{service="server"} | json | msg=~"Starting RTC Agent server|HTTP server listening|LLM initialized|Tracing enabled"
{service="server"} | json | msg=~"Shutting down server|centrifuge node shutdown|broker close|Server shutdown"
{service="server"} | json | msg=~"Running database migration|Database migration completed"

查看关闭超时(可能有 Goroutine 泄漏)

Section titled “查看关闭超时(可能有 Goroutine 泄漏)”
{service="server"} | msg="[lifecycle.Manager] shutdown timeout, goroutines still running"
{service="server"} | json panic="panic", stack="stack" | msg=~"panic recovered|panic|\\[Centrifuge\\] OnConnect panic"
指标类型Labels用途
rtc_stale_turns_recovered_totalCounterstatus过期 Turn 恢复统计
rtc_checkpoint_operations_totalCounteroperation, status检查点操作统计
rtc_checkpoint_data_bytesHistogramoperation检查点数据大小
# 每分钟恢复的过期 Turn 数
sum(rate(rtc_stale_turns_recovered_total[5m])) by (status)
# 检查点操作速率
sum(rate(rtc_checkpoint_operations_total[5m])) by (operation, status)
告警条件说明
Stale Turn 恢复频繁每分钟恢复 > 30服务可能频繁重启或 Turn 执行不稳定
Goroutine 泄漏Goroutine 数超过阈值存在 Goroutine 泄漏
组件启动失败连续启动失败依赖服务不可用
关闭超时出现 shutdown timeout需检查是否有阻塞的 Goroutine
Loop 恢复频繁每分钟恢复 > 10任务队列可能有问题
  1. 查看恢复日志:{service="server"} | msg=~"recoverStaleTurns" | json
  2. 检查服务是否频繁重启:{service="server"} | msg="Starting RTC Agent server"
  3. 检查 Worker 是否存活:{service="server"} | msg="skip lock release -- worker alive"
  4. 如确认服务正常,检查 Turn 执行是否超时
  1. 查看工作流日志:{service="server"} | msg=~"loopWorkflow|goalWorkflow" | json
  2. 检查 Loop 状态:是否有 loop_exhausted 事件
  3. 查看恢复日志:{service="server"} | msg=~"\\[loop\\.(Recovery|Cleanup)\\]"
  4. 检查 asynq 任务是否正常执行
  1. 查看关闭日志:{service="server"} | msg=~"Shutting down|stopped|shutdown"
  2. 检查是否有超时:{service="server"} | msg="shutdown timeout"
  3. 查看 Goroutine 数量:{service="server"} | msg="goroutine leak threshold exceeded"
  4. 导出 pprof:GET /debug/pprof/goroutine