[ai] 持久化 deadline 覆盖整次交互:超过 30s 后工具结果/最终答案/轮次收尾同时失败,整轮对话丢失
Maintainer thường phản hồi trong vòng 8 ngày
@ambiguous-pointer đang làm issue này rồi.
Từ ngày 14/11/2026.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
概要
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 的解决方案评论。
- Ngôn ngữ chính
- Go
- Star
- 4.1k
- Fork
- 2.2k
- Merge trung bình
- 6 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/dubbo-admin
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
apache/dubbo-admin#1659 ·
Maintainer thường phản hồi trong vòng 8 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
apache/dubbo-admin#1658 ·
Maintainer thường phản hồi trong vòng 8 ngày
-
Editing a tag rule in the UI form drops the addresses of its tagsCó thể đã có người làm @AsperforMias đã nhận 7 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
apache/dubbo-admin#1649 ·
Maintainer thường phản hồi trong vòng 8 ngày
-
[Bug] Generic invoke does not propagate timeoutMs to Dubbo client, causing per-request timeout to fall back to 3sCó thể đã có người làm @dodjdnh đã nhận 3 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
apache/dubbo-admin#1654 ·
Maintainer thường phản hồi trong vòng 8 ngày
-
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 40/100
apache/dubbo-admin#1646 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 8 ngày
Tất cả issue của apache/dubbo-admin
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
taskmanager: a failed v1alpha1 backup leaves the partial backup behindCó thể đã có người làm @arshil42 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
modelcontextprotocol/go-sdk#1557 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Packaging: support mise-en-placeĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100