Skip to content

feat: 定时任务按需提醒,并可配置应用内与社交平台提醒 - #1736

Merged
chen-ran merged 11 commits into
mainfrom
feat/memoh-256-schedule-attention
Nov 6, 2026
Merged

chen-ran merged 11 commits into
mainfrom
feat/memoh-256-schedule-attention

Conversation

@LittleSound

@LittleSound LittleSound commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Author

  • Human
  • Agent

Type

  • bug
  • feat
  • test

Summary

定时任务现在可以区分「这次运行需要你关注」和「这次没什么事」,不打开任务就能看出来。默认不打扰你,只在有必要时提醒。

之前的问题

  • 每次新建会话的定时任务没有任何未读提醒,运行失败或在等审批时也不会提醒(feat: 会话未读状态与系统通知 #1645 的资格条件只放行 chat / acp_agent)。
  • 挂在已有会话上的任务,每次运行完都会记一次「已回复」,没有新内容时也一样。

这个 PR 的行为

  • 每个定时任务新增两个设置。新建任务和存量任务都使用默认值(迁移 0173_schedule_notify):
    • notify_policy:important(默认)表示只在需要你关注时,在 Memoh 中提醒;every_run 表示每次运行都提醒。
    • contact_via_channels:默认打开,表示「有更新时,通过已配置的平台主动联系我」。
  • 新工具 notify_user:
    • 没有参数,只在 important 的定时任务运行中注册。原生运行时和外部 Agent 运行时都可用,判断方式一致:按会话找到正在进行的那次运行,读取它所属任务的设置。
    • Bot 调用后,这个会话记一次新的 attention kind update,界面显示为「有更新」。每次运行最多记一次。
    • 提醒只有状态,没有文字,和 feat: 会话未读状态与系统通知 #1645 的未读、「需要你」、系统通知完全一致。
  • 判定规则:
    • 由定时任务触发、设置为 important 的运行,正常完成且没有调用 notify_user 时,不再记「已回复」。挂在已有会话上的任务也一样:只跳过定时任务那一轮,你自己在这个会话里发的消息照常提醒。
    • 运行失败或等待确认时总会提醒。every_run 每次正常完成都记「已回复」。
  • 社交平台尽量保持原有行为:
    • 开关打开时,提示词与改动前逐字一致。之前的提示词里本来就没有指明平台:发到哪里,靠建任务时写进 command 的 send 目标,或者 Bot 运行时用 get_contacts 自己查。所以以后接入新平台,行为也不会变。
    • 开关关闭时,只在本次运行的触发提示末尾追加一句:「No need to notify the user through social platforms for this task; they follow it in Memoh.」。没有加针对存量 command 的反向指令。
  • create_schedule / update_schedule 增加 notify_policy 和 contact_via_channels 两个参数。工具描述写明了默认值和推荐值,并说明除非用户要求,否则不要修改。
  • Web:
    • 任务表单新增「提醒」区:「在 Memoh 中提醒我」二选一,下面一行是「有更新时,通过已配置的平台主动联系我」开关。开关下方列出这个 Bot 已配置的平台,并提供「配置平台 ›」,跳转到 Bot 设置 › 平台。
    • 「需要你」把同一个定时任务的多条未读合并成一行,显示带数字的徽标,颜色取其中最紧急的那种。
    • 任务卡片显示未读数,运行行显示未读点,标题加粗。
    • 聊天记录里,notify_user 不再收在工具组里,而是单独显示为一张「已提醒你」卡片。
    • 在「需要你」或系统通知里点开某个定时任务的提醒:侧边栏切到「日程」,展开这个任务的卡片,并滚动到这次运行所在的行(不在第一页时,最多再加载 5 页)。如果是「有更新」,聊天记录还会滚动到「已提醒你」那张卡片。挂在固定会话上的任务只打开会话。
    • 「需要你」里由定时任务产生的行,头像右下角有一个小时钟。
    • 任务卡片的「…」菜单里有「全部标为已读」,只在这个任务有未读运行时出现,固定会话的任务不显示。操作后可以撤销。
    • 读取 Bot 平台列表的查询抽成了 useBotChannels。原来「平台」tab 和「概览」各写了一份相同的查询,现在和表单共用这一份。

数据与接口

  • 迁移 0173_schedule_notify:
    • schedule 表新增 notify_policy(CHECK 约束)和 contact_via_channels;
    • bot_sessions.attention_kind 的 CHECK 加入 update;
    • 新增部分索引 idx_schedule_logs_session,供未读汇总按会话查找所属任务。
    • down 迁移会先把 update 改回 reply,再恢复旧约束。
    • 0001_init 快照已同步。
  • 资格条件 MarkSessionAttention / MarkSessionsUnread / ListUnreadSessionsForUser 放行 type = 'schedule'。未读汇总和 session_attention 事件新增 schedule_id。

Related Issues

Validation

2026-11-07 rebase 后复测(Agent QA)

  • 推送后的 CI 状态:ESLint、Electron 三平台、Docker 变更检测及 Contribution governance/PR Format 在准备阶段被 GitHub installation API 限流阻塞(API rate limit exceeded for installation,remaining=0,日志 reset 为 2026-11-07 06:50:02 Asia/Shanghai);尚不能认定 CI 全绿。Go CI 与迁移作业仍在运行,Pgvector bootstrap 已通过。6 张新增图片均已回读验证为 GitHub attachment URL,HTTP 200 / image/jpeg。
  • 已 rebase 到 main 的 b8eaa9eb795410af4b06c1270ebe47c030885488,当前 head 2f19485382015d0b0c29da03c72ef82bac69df8b。保留 main 的 actor 授权接口,移除 PR 新增测试替身的旧 JWT 参数与字段;三语冲突同时保留浏览器通知与日程未读词条,保留中文已有标点规范。
  • 隔离 worktree 与独立 Compose 栈 memoh-pr1736,使用仓库开发服务定义及入口脚本,前端宿主 Vite http://127.0.0.1:19182,Server :19080、Channel :19081。Server/Channel/PostgreSQL/pgvector/Connect-It 容器健康,挂载本次 worktree;第二次 rebase 后已重启 Server/Channel 并重新运行真实模型用例。Bot 关闭记忆,未接入社交平台。
  • 真实模型为已有本地 QA 配置的 MiMo V2.6 Pro。在真实浏览器中创建 QA-有更新,默认 important / contact_via_channels=true,每分钟执行、最多 3 次,数据库确认设置已保存。其余场景通过 API 准备,再通过真实 UI 与 PostgreSQL 运行记录交叉验证。
  • 最终 head 的 06:31(Asia/Shanghai)运行矩阵:important 无变化 → ok 且无 attention;every_run → ok/reply;调用 notify_user → ok/update;固定会话调用 notify_user → ok/update;专用不可达 Provider 用例在重试耗尽后 → error/failed(agent.provider_unreachable)。前四项使用真实 MiMo;失败项为受控连接故障,不是模型服务实测。
  • 固定会话静默轮次在 06:30 完成后保留原普通聊天的 attention 时间 06:28:40,06:31 调用 notify_user 后才更新。普通 UI 聊天正常回复。
  • 实际 UI 验证:不刷新时同一日程聚合未读;点击“有更新”切换日程面板、展开任务、选中运行并显示 Notified you 卡片;打开运行扣减未读;每次运行任务的“全部标为已读”移除 3 条,点击 Undo 恢复 3 条;固定会话任务菜单没有“全部标为已读”,点击任务直接打开原会话;失败运行显示红色标记。所有测试任务达到次数上限后自动停用。
  • 检查通过:mise run sqlc-generate(无生成差异);mise run lint(0 error,保留既有 warnings);Web typecheck;8 个相关 Web Vitest 文件、63 个测试;Desktop attention 测试 3 个;Go chat/application/tool/native/schedule/handlers/channel-inbound 相关包测试。
  • PostgreSQL 完整 migrate up → down → up 通过,版本 173、dirty=false;-tags=integration -count=1 的 internal/chat/attention、internal/db、internal/chat/message、internal/chat/checkpoint、internal/chat/thread、internal/agent/view 全部通过。迁移与前端检查在第二次 rebase 前完成;第二次 rebase 只新增 main 的后端 fork 快照/渠道回放改动,相关 Go 测试和全量 lint 已重跑。
  • 本次未覆盖:外部 Agent 运行时、真实 OS 通知、社交平台消息发送、审批等待、多页运行定位,以及全量 Web Vitest。以下保留原有历史验证记录;Agent QA 不计为 Human QA。

自动检查

  • Go:./internal/chat/attention/、./internal/agent/application/、./internal/agent/tool/...(含 schema golden,本次有意更新了 schedule.json,并新增 notify.json)、./internal/agent/runtime/native/、./internal/schedule/、./internal/chat/...、./internal/handlers/ 全部通过。
  • 提交钩子:golangci-lint 2.10.1 和 go test 通过。
  • Web:vue-tsc typecheck、ESLint(改动文件没有 error)、scripts/check-ui-contract.mjs 通过。
  • Vitest:除 ui-icon-contract、chat-user-input-form、panel-preview、useMediaGallery、keyboard-bindings 外全部通过;这 5 个在干净的 origin/main 上同样失败,和本 PR 无关。全量运行时 markdown/index、markdown-dollar.render 偶尔超时,单独运行通过。
  • 新增的测试覆盖:
    • 静默完成的判定,以及「每次运行最多提醒一次」;
    • notify_user 只在 important 的定时任务运行中注册;
    • 服务层的默认值和校验;
    • 关闭开关时提示词末尾多出那句说明,打开时逐字不变;
    • 「需要你」按任务合并;
    • 运行行的未读点;
    • 表单发送默认值,编辑时保留原值。
    • 提醒的跳转参数(notice、schedule),以及桌面端主进程对这两个参数的校验;
    • 运行行滚动到目标位置,以及不在第一页时翻页查找;
    • 「全部标为已读」只在有未读时出现,固定会话的任务不出现;只读传入的那几个会话;
    • 「已提醒你」从工具组里拆出来,以及什么情况下算已提醒。

开发环境实测(Agent 自测,不算 Human QA)

  • 环境:用 memoh-dev 启动独立栈 memoh-256(server :18280),宿主机 vite 地址 http://127.0.0.1:25100,空数据库。迁移版本为 173,dirty=false。
  • 模型:宿主机上的 OpenAI 兼容假模型。指令里含 [notify] 时调用 notify_user,[quiet] 时只回复,[fail] 时返回 500。假模型的模型配置需要打开 tool_call;没打开时,运行中不会提供任何工具(send 也没有)。
  • 在 UI 中新建「每日 AI 新闻」,表单默认是「仅在需要我关注时」,开关打开。数据库里存的是 important / true。另外通过 API 建了 5 个任务,全部设为每分钟运行,跑了两三轮。数据库和假模型日志的结果如下:
    • [notify] + important:模型能看到 notify_user,调用后会话记为 update。
    • [quiet] + important(特殊天气提醒、不走平台):没有任何 attention。
    • [quiet] + every_run(工作区备份检查):每轮都记 reply,模型一次也没有看到 notify_user。
    • [fail]:记 failed。
    • 挂在我自己发过消息的对话上的「GitHub 周报」:[quiet] 的几轮运行都没有改动这个对话的 attention,它仍是我自己那条消息的 reply(08:52:08)。改成 [notify] 后,变成 update(09:03:00)。
    • 关闭开关的「不走平台」:6 次请求末尾都带有那句说明。开关打开的任务,提示末尾仍是指令本身。
  • 界面上:
    • 「需要你」合并成 4 行:失败测试 6(红色)、工作区备份检查 6、每日 AI 新闻 4、宿主对话 1(显示「有更新」)。
    • 日程卡片显示计数,运行行有未读点,标题加粗。
    • 打开一次运行后,聊天记录里显示「已提醒你」,这一行变为已读,卡片计数从 4 降到 3。

Human QA 期间发现并修复的问题

  • 页面开着时,同一个定时任务新冒出来的运行在「需要你」里不合并,刷新后才会合并。原因是 SSE 实时帧是逐个字段手工拼的,漏了 schedule_id;汇总接口带着这个字段,所以刷新后正常。现在实时帧也带上 schedule_id,并补了服务端和前端 store 的测试。在真实模型的环境里,页面一直不刷新,同一行从「有更新」依次变成「2 条未读」……「5 条未读」。
  • CI 的 PostgreSQL migrations 失败:0173 的 down 迁移在 bot_sessions 上执行 UPDATE,这张表是 FORCE RLS,而迁移连接不会设置 memoh.team_id。按 0165 的做法,在数据步骤前后先解除再恢复 RLS。本地按 CI 的步骤(migrate up → down → up,再跑 go test -tags=integration)验证通过。
  • 更新了 feat: 会话未读状态与系统通知 #1645 的 attention 资格集成测试:schedule 运行会话现在应当可以产生 attention。
  • 合并了 origin/main。冲突只在三个 locale 文件,保留 main 规范化后的文案,再加上本分支的词条;中文单句说明按 main 的新规范去掉了末尾句号。
  • Web 端在合并后的代码上 typecheck 和 UI 契约检查通过。Vitest 有 5 个文件失败,在干净的 origin/main 上同样失败:除之前列出的 4 个外,新增的 src/lib/keyboard-bindings.test.ts(en closeCurrentWorkspaceTab 缺少 label)也来自 main。

提示词改进(Human QA 中发现:Bot 建监控任务时误选 every_run,命中后也没调用 notify_user)

  • 排查结果:改成 important 之后,每次运行都提供了 notify_user(运行上下文快照 context_lifecycles 可以证实),工具注册没有 bug。问题有两处:建任务时 Bot 不知道 important 是怎么提醒用户的,所以为了「让用户看到效果」选了 every_run;运行时它把「在会话里回复」当成了已经提醒。
  • create_schedule 的描述现在讲清 important 和 every_run 怎么选,即使测试时把间隔设得很短,也应选 important;在 command 里写清什么时候该告诉用户,不要写「只回复本会话」之类。
  • Schedule 工具组的 Usage 增加一句:提醒按 notify_policy 工作,notify_user 只存在于 important 的运行里,聊天回合里没有。
  • notify_user 的描述增加:在会话里回复不等于提醒了用户。
  • 存量提示词(mode_schedule.md、send 的描述等)都没有改,社交平台行为保持不变。补充了 3 条测试,固定这几句关键文字。
  • 用真实模型(deepseek-flash)在 UI 里端到端复测:我让 Coder「每分钟看当前时间,偶数分钟告诉我,先每分钟跑一次看看效果」,这正是上次导致误选的那种说法。这次 Bot 选了 important。14:26、14:28、14:30(偶数)三次运行都调用了 notify_user,记为「有更新」;14:27、14:29(奇数)两次保持安静,没有任何提醒。

every_run 与 notify_user 的引导冲突(subagent 多场景实测中发现)

  • 现象:用户说「每天早上给我发科技新闻摘要」时,Bot 正确选了 every_run,但 command 里写了「通过 notify_user 发送」。every_run 的运行本来就没有这个工具,于是每轮都在找它,又去试 send(7 次都报 unsupported channel type: local),最后回复「无法送达用户」。实际上每次运行都已经提醒了用户。
  • A:create_schedule 的描述补充三点:
    • every_run 的运行结束本身就会通知用户,运行里没有 notify_user,command 里不要提它;
    • notify_user 没有参数、不带内容,只是把运行标成「有更新」,用户读到的是运行的回复;
    • every_run 不是为了测试时看效果。
  • B:every_run 的运行,触发提示末尾追加一句「The user is notified when this run finishes; your final reply is what they read.」。默认设置的任务提示词仍与改动前逐字一致。
  • 真实模型复测:
    • 让 Coder 再建科技新闻摘要:它沿用了已有的同名任务,并按新引导改写了 command,不再提到 notify_user。6 轮运行都带有新说明,0 次 send,没有一轮声称送达失败,回复都是摘要本身,每轮记「已回复」。
    • 用 API 建了一个故意写成「通过 notify_user 发送」的旧写法 every_run 任务,跑了 2 轮。Bot 的推理是「the run has no notify_user tool — the final reply is what the user reads」,没有调用 send,直接回复结果,每轮记「已回复」。
  • 补充了相应测试:触发提示里的两句说明、create_schedule 新加的文字,以及 runSchedule 会把这两个设置传给运行。

提醒跳转与「全部标为已读」(Agent 自测,不算 Human QA)

  • 环境同上,宿主机 vite http://127.0.0.1:25100,数据是 Human QA 留下的真实运行。用无界面 Chrome 驱动:
    • 「需要你」3 行都来自定时任务,头像角上都有时钟,无障碍名称里带「定时任务」。
    • 点「每日科技新闻摘要」(13 条,every_run):从 Gamer 跳到 Coder,侧边栏切到「日程」,这个任务的卡片展开,最新一次运行被选中。
    • 点「Gematsu 最新标题监控」(有更新):跳到 Mclaw,卡片展开。目标运行在第二页(15:11),已自动加载并滚动到这一行;聊天记录停在「已提醒你」卡片上。
    • 在「每日科技新闻摘要」卡片的「…」菜单里点「全部标为已读」:计数徽标和运行行的未读点都消失,提示「已将 11 条标为已读」,并带「撤销」。

没有验证的

  • 这个测试 Bot 没有接入任何社交平台,所以只验证了「还没有接入平台 · 配置平台」的空状态,没有验证有平台时的列表样式,也没有验证 Bot 实际通过 Telegram 发消息。开关打开时提示词逐字不变,所以社交平台上的行为和之前一致。
  • 无界面浏览器弹不出真正的系统通知。这部分直接沿用 feat: 会话未读状态与系统通知 #1645 的通知路径,kind 文案已加上 update。
  • 深色模式没有截图。改动里只使用了语义 token,UI 契约检查已通过。

Screenshots / Recordings

2026-11-07 最终 head 的真实 UI 截图

新建任务默认提醒设置:
默认提醒设置

真实运行的实时聚合、失败提醒和固定会话更新:
最终未读状态

点击提醒后定位到运行及通知卡片:
提醒跳转

批量已读与撤销后的计数恢复:
全部已读
撤销恢复未读

固定会话中先静默完成,后调用 notify_user:
固定会话验证

任务表单里的「提醒」区,显示默认值;这个 Bot 没有平台,所以显示空状态和「配置平台」:

任务表单的提醒区

「需要你」把同一个任务的未读合并成一行,并显示数字;挂在对话上的任务显示「有更新」:

需要你按定时任务合并

日程卡片显示未读数,展开后运行行有未读点:

日程卡片与运行行

打开一次运行:聊天记录里显示「已提醒你」,这一行变为已读,计数从 4 降到 3:

运行详情与已读

用真实模型新建监控任务:Bot 选择 important,并说明只有调用 notify_user 的运行才会提醒:

真实模型新建监控任务

偶数分钟(14:30)的运行调用了 notify_user 并提醒;运行行只在偶数分钟带未读点:

偶数分钟运行已提醒

奇数分钟(14:29)的运行保持安静,没有任何提醒:

奇数分钟运行保持安静

页面不刷新时,同一个任务新冒出来的运行实时合并成一行(5 条未读):

实时合并

every_run 旧写法任务(command 写着「通过 notify_user 发送」)的运行:直接给出结果,说明「运行结束后系统会推送」,没有尝试 send,也没有声称送达失败:

every_run 旧写法运行

「需要你」里由定时任务产生的行,头像角上有时钟:

需要你里的定时任务标记

点开「每日科技新闻摘要」的合并提醒:侧边栏切到「日程」,展开任务卡片,选中这次运行:

跳转到日程并展开

点开「有更新」的提醒:卡片翻到第二页,滚动到 15:11 这次运行;聊天记录停在「已提醒你」卡片上:

滚动到运行行和已提醒你卡片

任务卡片「…」菜单里的「全部标为已读」:

全部标为已读菜单

全部标为已读后,计数和未读点消失,提示可以撤销:

全部标为已读之后

Human QA

  • Human QA passed

@github-actions github-actions Bot added change:migrations Adds, modifies, or removes database migrations change:server Changes backend code, configuration, or API contracts change:web Changes web frontend or shared frontend packages feat Adds or improves functionality size:L PR size uses the larger of added or deleted lines, excluding generated files change:desktop Changes the Electron desktop app or shared desktop configuration labels Nov 3, 2026
LittleSound and others added 11 commits November 7, 2026 06:29
Schedules gain notify_policy (important by default, also for existing
schedules) and contact_via_channels (on by default). attention_kind gains
update, and schedule run sessions become eligible for unread attention.

Refs MEMOH-256
notify_user registers only in a schedule fire whose schedule tells its
owner on request, and raises an update once per fire. A scheduled run that
completes without it raises no reply under the important policy; failures
and decisions still reach the owner. Turning channel contact off adds one
note to the trigger prompt; with it on the prompt reads as before.

Refs MEMOH-256
…lls you

The schedule form gains a Notifications section: notify in Memoh only when
the run needs you (default) or after every run, and whether the bot may
reach you on its configured platforms, with the platforms it is on and a
link to set them up. Needs you folds one schedule's unread runs into a row
with their count; schedule cards count unread runs and run rows carry the
unread dot. update attention reads as Update, and notify_user shows as
Notified you in the transcript. The bot channel list query moves into
useBotChannels so the Platforms tab, the overview and the form share it.

Refs MEMOH-256
The attention stream built its frames field by field and left out
schedule_id, so a run that raised attention while the page was open
arrived without its schedule and got a Needs you row of its own; only a
reload folded it into its schedule's row. Live frames now carry
schedule_id like the unread summary.

Refs MEMOH-256
The down migration rewrote update attention to reply on bot_sessions,
which is under FORCE row level security keyed on memoh.team_id that a
migration connection never sets, so rolling back past 0173 failed. Lift
the policy for the data step and restore it after, as 0165 does.

Refs MEMOH-256
A bot creating a watch task picked every_run so the user would see test
runs, and a run that found what the user asked about replied in its
conversation without calling notify_user. create_schedule now says when
to pick important and every_run and to state in the command when the
user should be told; the schedule usage says notify_user exists only
inside important runs; notify_user says a reply alone does not notify.

Refs MEMOH-256
QA found a daily digest created with every_run whose command said to
send the summary with notify_user. Its runs have no notify_user, so each
one searched for it, tried send, and reported it could not reach the
user although every run did notify them. create_schedule now says that
every_run runs have no notify_user and must not mention it, that
notify_user carries no text, and that every_run is not a way to watch
test runs. An every_run trigger also says the run's reply is what the
user reads; schedules with default settings still read as before.

Refs MEMOH-256
Opening a schedule's notification switches the sidebar to Schedules,
expands that schedule's card and scrolls to the run's row; an update
also scrolls the transcript to the notice notify_user left there, which
now breaks out of the tool group as a standalone card. Inbox rows a
schedule raised carry a clock on the avatar, and a schedule card's menu
can read all of its unread runs at once.

Refs MEMOH-256
@chen-ran
chen-ran force-pushed the feat/memoh-256-schedule-attention branch from 2260e7e to 2f19485 Compare November 6, 2026 22:33
@chen-ran
chen-ran merged commit 82b0e6f into main Nov 6, 2026
9 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:desktop Changes the Electron desktop app or shared desktop configuration change:migrations Adds, modifies, or removes database migrations change:server Changes backend code, configuration, or API contracts change:web Changes web frontend or shared frontend packages feat Adds or improves functionality size:L PR size uses the larger of added or deleted lines, excluding generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants