fix(cron): preserve reminder delivery target from session context#6
fix(cron): preserve reminder delivery target from session context#6
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 67dd45a4dd
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| func (t *RemindTool) SetContext(channel, chatID string) { | ||
| t.defaultChannel = channel | ||
| t.defaultChatID = chatID |
There was a problem hiding this comment.
Avoid shared mutable delivery context in RemindTool
This commit makes RemindTool store defaultChannel/defaultChatID as global mutable fields, but the same tool instance is shared across all sessions and AgentLoop processes sessions concurrently (see buildSessionShards/processMessage in pkg/agent/loop.go). When two chats are handled at the same time, one request can call SetContext between another request's context set and Execute, so AddJob persists the wrong Payload.Channel/Payload.To and reminders may be delivered to the wrong user; this is also an unsynchronized read/write data race.
Useful? React with 👍 / 👎.
Motivation
remind工具创建定时任务时未携带会话目标(channel/chatID)的问题,导致deliver=true的任务触发时无法走外发投递链路。Description
RemindTool中新增defaultChannel和defaultChatID字段并实现SetContext(channel, chatID)来保存当前会话上下文。RemindTool.Execute中将AddJob的channel/to参数由空值替换为t.defaultChannel/t.defaultChatID,确保持久化的任务包含投递目标。AgentLoop的工具上下文更新位置注册remind工具的SetContext调用,保证每条消息处理时刷新提醒工具的会话上下文。pkg/tools/remind_test.go校验在设置上下文后创建的提醒任务其Payload.Deliver、Payload.Channel与Payload.To被正确持久化。Testing
gofmt -w pkg/tools/remind.go pkg/tools/remind_test.go pkg/agent/loop.go,格式化成功。go test ./pkg/tools ./pkg/agent ./pkg/cron -count=1,pkg/tools和pkg/agent测试通过,pkg/cron无测试文件。pkg/tools/remind_test.go已执行并通过,验证提醒任务保存了正确的投递目标。Codex Task