Skip to content

fix(cron): preserve reminder delivery target from session context#6

Merged
YspCoder merged 1 commit intomainfrom
codex/clawgo
Mar 2, 2026
Merged

fix(cron): preserve reminder delivery target from session context#6
YspCoder merged 1 commit intomainfrom
codex/clawgo

Conversation

@YspCoder
Copy link
Copy Markdown
Owner

@YspCoder YspCoder commented Mar 2, 2026

Motivation

  • 修复 remind 工具创建定时任务时未携带会话目标(channel/chatID)的问题,导致 deliver=true 的任务触发时无法走外发投递链路。

Description

  • RemindTool 中新增 defaultChanneldefaultChatID 字段并实现 SetContext(channel, chatID) 来保存当前会话上下文。
  • RemindTool.Execute 中将 AddJobchannel/to 参数由空值替换为 t.defaultChannel / t.defaultChatID,确保持久化的任务包含投递目标。
  • AgentLoop 的工具上下文更新位置注册 remind 工具的 SetContext 调用,保证每条消息处理时刷新提醒工具的会话上下文。
  • 新增回归测试 pkg/tools/remind_test.go 校验在设置上下文后创建的提醒任务其 Payload.DeliverPayload.ChannelPayload.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=1pkg/toolspkg/agent 测试通过,pkg/cron 无测试文件。
  • 新增回归测试 pkg/tools/remind_test.go 已执行并通过,验证提醒任务保存了正确的投递目标。

Codex Task

@YspCoder YspCoder merged commit 798a3bd into main Mar 2, 2026
@YspCoder YspCoder deleted the codex/clawgo branch March 2, 2026 14:26
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread pkg/tools/remind.go
Comment on lines +21 to +23
func (t *RemindTool) SetContext(channel, chatID string) {
t.defaultChannel = channel
t.defaultChatID = chatID
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant