[ai] 持久化 deadline 覆盖整次交互:超过 30s 后工具结果/最终答案/轮次收尾同时失败,整轮对话丢失

Abierto
#1,645 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 8 días

@ambiguous-pointer ya está trabajando en esto.

Desde el 14/11/2026.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
go
Área
ai, backend

Línea de trabajo

Start in ai/component/agent/react/react.go, where persistenceTimeout and persistCtx are created once per interaction, then follow persistenceContext in steps.go to the three writes: tool results, the final answer, and NextTurnForTurn. The fix proposed in the issue's solution comment should be checked against these call sites. Done means that a slow interaction (over 30s) still persists tool results and turn completion, and that a store failure on the final answer no longer hides the generated answer. Look for existing tests in the react package before changing behavior.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

概要

AI 助手的持久化 deadline 覆盖的是整次交互,而不是单次写入。一次交互很容易超过这个 deadline(多次模型调用 + 中间的工具调用),一旦超时,工具结果、最终答案、轮次收尾三处写库同时失败,整轮对话被 abort,该会话的下一个问题从零历史开始。

对用户的表现是:「AI 突然忘了我刚说过的话」,而且是在问题越多、工具越重的会话里越容易触发。

1. 问题

1.1 一个 deadline 被整个交互共享

ai/component/agent/react/react.go:

:76   const persistenceTimeout = 30 * time.Second
...
:337  persistCtx, persistCancel := context.WithTimeout(context.WithoutCancel(parent), persistenceTimeout)
:359  state := &interactionState{... persistCtx: persistCtx, persistCancel: persistCancel}
:362  ctx = context.WithValue(ctx, persistenceContextKey, persistCtx)

persistCtx 在交互开始时创建,30 秒后到期,并被注入整条交互链路的 context。

1.2 三个写库点全部使用这个共享 context

ai/component/agent/react/steps.go:

:291  func persistenceContext(ctx context.Context) context.Context {   // 取回共享的 persistCtx
:231  ra.messageStore.AddHistoryToTurn(persistenceContext(ctx), access, s.Session, turnID, message)   // ① 工具结果
:251  ra.messageStore.AddHistoryToTurn(persistenceContext(ctx), access, sessionID, turnID, message)   // ② 最终答案
:252  return fmt.Errorf("failed to persist final answer: %w", err)

ai/component/agent/react/react.go:

:254  ra.messageStore.NextTurnForTurn(state.persistCtx, access, sessionID, state.turnID)   // ③ 轮次收尾
     interactionErr = fmt.Errorf("failed to complete turn: %w", err)

deadline 一到,① ② ③ 全部返回 context deadline exceeded:

  • ① 工具结果丢失 → 下一轮上下文里没有工具输出;
  • ② 最终答案写库失败 并向上返回错误 → 已经生成好的答案被整个隐藏,用户收到的是失败而不是回答;
  • ③ 轮次收尾失败 → 该轮被 abort,下一次提问从空历史开始。
1.3 关键在于「答案已经生成成功了」

② 的失败发生在答案生成之后。当前实现把「存储暂时不健康」升级成了「用户拿不到回答」,这是错误的取舍。

2. 为什么重要

  • 数据丢失:用户这一轮说过的话、Agent 调过的工具结果、最终答案,在这 30s 之后都不入库。
  • 会话体验断裂:下一轮没有历史,模型看起来「失忆」,用户会重复描述已经给过的上下文。
  • 可用性反噬:存储后端(MySQL/PG)稍有抖动,答案就消失——存储故障被放大成了产品故障。
  • 触发条件不可控:交互耗时取决于模型输出长度和工具调用次数,用户无法预知;长问题 + 慢工具必然越界。

3. 证据

代码位置(ai 分支):

位置 内容
ai/component/agent/react/react.go:76 const persistenceTimeout = 30 * time.Second
ai/component/agent/react/react.go:337 persistCtx, persistCancel := context.WithTimeout(context.WithoutCancel(parent), persistenceTimeout)
ai/component/agent/react/react.go:359-362 persistCtx 存入 interactionState 并经 persistenceContextKey 注入交互 ctx
ai/component/agent/react/steps.go:231 工具结果写入使用共享 ctx
ai/component/agent/react/steps.go:251-252 最终答案写入使用共享 ctx,失败直接返回错误
ai/component/agent/react/react.go:254 轮次收尾使用 state.persistCtx

关键点:persistCtx 的 deadline 是从交互开始计时,而它服务的写操作发生在交互的末尾。一次交互 = 若干次模型调用 + 中间的工具调用,中间任何一段慢都会让末尾的写操作落在 deadline 之外。

4. 影响范围

  • 触发条件:单次交互耗时 > 30s(多轮工具调用、慢模型、慢存储都会叠加)。
  • 受影响组件:ai/component/agent/react 的 ReAct 循环 + ai/store 的会话持久化。
  • 已有可用修复(尚未提交 PR):见本 Issue 的解决方案评论。
Lenguaje dominante
Go
Estrellas
4.1k
Forks
2.2k
Merge medio
6 d 2 h
PR fusionados (30 d)
4

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/dubbo-admin

Todos los issues de apache/dubbo-admin

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.