Skip to content

fix(agent): idle 会话的结构化通知不再等到下次 busy - #470

Merged
Chronostasys merged 4 commits into
masterfrom
experiment/xbot
Nov 16, 2026
Merged

Chronostasys merged 4 commits into
masterfrom
experiment/xbot

Conversation

@Chronostasys

Copy link
Copy Markdown
Collaborator

问题

后台/卡片通知的 idle/busy 分支失效:会话 idle 时消息不立刻变成 user 消息,而是等到下一次 busy 才投递。

用户实测:卡片批复(decision / ask_user)在会话空闲时无反应,下次有请求跑起来才出现。

根因(两层)

  1. 我引入的(ccfbef9f):decision 路径的 persistUserNoticeFeedback 从「无条件落库」改成「仅 idle 落库」,移除了 busy 期的历史兜底副本。
  2. 既有设计缺陷(自 514ec7b3):drainStructuredQueue 只有 Run 的 iteration 边界一个消费点,drainAndProcessNotifications(idle 路径)从不处理该队列。

两者叠加:busy 期入队 → Run 在下一个 drain 边界前结束 → 既没落库、也没人消费 → 卡到下次 busy。

修复

  • 新增 flushStructuredQueueAsUserMessage(sessionKey):把队列残留合并成一条消息,内联 content、不带 structured_delivery(否则 processMessage 会跳过落 user 行),走 injectInboundWithMetadata → 落库 + 起新 turn,表现为普通 user 消息。
  • 在 drainAndProcessNotifications 开头按 !ss.busy 调用,覆盖 Run 正常结束 / 异常结束 / cancel ack 后的所有 idle 路径。
  • 新增只读访问器 peekStructuredQueue(不创建空队列)。

验证

  • TestFlushStructuredQueueTurnsResidueIntoUserMessage:busy 入队 2 条 → 置 idle → 真实 drain → 队列清空、收到 1 条合并消息、内容含两张卡片、无 structured_delivery 标记。
  • TestFlushStructuredQueueIsIdempotent:flush 后再 drain 不重复投递。
  • TestDeliverWhenIdleStillInjectsImmediately:idle 直接投递契约不变(persist 恰 1 次、不入队、立即注入)。
  • 变异:删掉 drain 里的 flush → 测试立刻红(queue must be empty after flush, got 2)。
  • 全仓 go test ./... EXIT=0;预提交检查(Go/前端/lint)通过。

已知残余风险(不在本 PR 范围)

内存队列无持久化:busy 入队与 Run 结束 flush 之间若进程被杀,消息仍会丢。彻底解法是 outbox 落库 + 启动重放,另开任务。

@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
xbot-preview Ready Ready Preview Nov 16, 2026 2:09pm UTC

@Chronostasys
Chronostasys merged commit 91b9f8a into master Nov 16, 2026
16 checks passed
@Chronostasys
Chronostasys deleted the experiment/xbot branch November 16, 2026 14:28

This branch was successfully deployed

1 active deployment
Preview — ce800141 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant