Skip to content

/agent:等审批卡时结束的那一轮不再当成回复发出 - #67

Merged
NginxL merged 3 commits into
mainfrom
fix/agent-approval-hold
Dec 6, 2026
Merged

NginxL merged 3 commits into
mainfrom
fix/agent-approval-hold

Conversation

@NginxL

@NginxL NginxL commented Dec 6, 2026 •

Copy link
Copy Markdown
Owner

问题

/agent 会话里一条命令被 Persona 命令闸拦下、主人 75 秒内没批时,Persona 给这次工具调用返回「The owner has not answered this approval yet … End this turn now … A later message will report its outcome」,会话照做结束本轮。OpenMate 在本轮结束、还没有经工具回复时,会把本轮最后一段文字当成答复发出(core/openmate_core/agent.py 的 _turn_ended 兜底)。于是「还卡在审批卡上…」被当成唯一一次回复发进群;微信只能回复一次,批准后真正的结果和截图被 _reply_tool 以「只回复一次,这条已经回复过了」拒掉。

做了什么

  • 本轮结束、请求还没有任何回复时,先问 hub 这个会话有没有本次请求之后新建、仍在等主人的卡:
    • 会话行 GET /api/v1/sessions?machine_id=&session_id= 的 pending_interactions(hub 用同一份待处理卡片表计算,命令闸的卡在返回 WaitingText 之前已经续期 24 小时并挂在表里);
    • 有计数时再读 GET /api/v1/interactions,按 machine_id/session_id/created_at 只认本次请求创建之后的卡(同一会话里更早请求留下的卡不压住这次的答复);hub 不给扩展看的私密卡按「可能是本次的」处理。
    • 两个接口都在扩展已有的 agents.read 权限内,不要新权限。
  • 有这样的卡:不发这段文字、不占唯一一次回复、运行保持 running,🤔 保留。审批结果(批准/拒绝/过期)由 Persona 作为新消息送进会话、开始下一轮,下一轮按原规则收尾:经工具回复(可带图),或本轮最后一段文字兜底发一次。
  • 挂起期间最长等 agent_approval_wait(25 小时,覆盖 Persona 卡片的 24 小时等待期),期间每 agent_hold_poll(30 秒)读一次会话;真没等到结果就发一次超时说明「要你处理的卡片等了 25 小时还没有结果…」。审批后的下一轮重新计 agent_timeout。
  • hub 暂时答不上来(网络、manager 掉线等)就先不发,下次轮询再问;hub 明确拒绝(403/404)时:读不到会话行退回原有行为,读不到卡片列表但会话行有计数就挂起。
  • 飞书同一套逻辑:等卡那一轮也不发;飞书本来能多次回复、能原地编辑进度,这部分不变。

怎么验证的

  • 新增 tests/test_agent_approval.py(第一版 11 条,审查后共 15 条):
    • 待批卡结束本轮 → 不发、fallback 未占用、发送日志里没有兜底记录;
    • 批准后下一轮经工具回复带图 → 文字和图片都发出,只有一条回复;
    • 拒绝 / 过期后下一轮 → 兜底发一次最终回复;
    • 卡一直没结果 → 25 小时(测试里缩短)后发一次超时说明;
    • 挂起期间会话又说「还在等卡」→ 继续挂起;
    • hub 暂时答不上 → 不发,恢复后挂起;hub 永久拒绝卡片列表 → 挂起;
    • 普通流程(没有卡)→ 和以前一样兜底发一次,且不读卡片列表;更早请求留下的卡不压住这次;
    • 飞书:挂起期间不发答复,批准后经工具回复正常发出。
  • 把 core/ 改动撤掉在旧代码上跑:8 条失败、1 条报错(旧代码没有新的时序参数),普通流程的 2 条照常通过。
  • bash scripts/test.sh:三组测试 960 / 419 / 191 全部通过(发版前的包校验在发版提交里处理)。

审查

  • 第一轮(本机 codex,只读)指出 3 个问题,已在 d5bfc02 修掉并补测试:
    1. hub 暂时答不上来、收尾被推迟(card_unsure)期间,审批结果先到、新一轮已经开始,下一次轮询会被强制收尾,把旧话或半截话发出去。→ 会话出现任何新条目就取消推迟、丢弃旧话,新一轮按原规则收尾。
    2. 飞书的「等任务结果」(awaiting)分支跳过了卡片检查。→ 先查卡,没卡才走 awaiting。
    3. 普通流程里读会话行一直失败时,兜底会被无限期压住,4 小时后的超时说明还会占掉微信唯一一次回复。→ 推迟最多 agent_hub_wait(5 分钟);之后读不到会话行就按原行为发出,会话行有计数但读不到卡片列表就挂起。
  • 第二轮:确认 3 个修复都成立,没有必须修的问题。两条不阻塞的观察暂不处理:
    • 审批结果开启的新一轮如果一个 assistant 条目都不产生、也不写 turn_duration,会一直挂满 25 小时;
    • 挂起期间每 30 秒才读一次会话,在 Persona App 里按停止最多晚 30 秒被识别。
  • 第二轮修复后:新增测试 15 条全过,在旧代码上 14 条失败或报错;scripts/test.sh 三组 965 / 419 / 191 全过。
  • 发版:c1d6976,openmate-feishu 0.11.82、openmate-wechat 0.1.77,package.py --check --published origin/main 通过。

没做什么

  • 没有按工具结果文字(WaitingText)判断,只用 hub 的会话状态和待处理卡片接口。
  • 没改 Persona hub,没改回复工具的「只回复一次」规则,没加新权限,没有新的对外发消息能力。
  • 走 agent_task_wait 的飞书「等任务结果」路径保持原样。

🤖 Generated with Claude Code

NginxL and others added 3 commits December 6, 2026 19:59
When a command in an /agent conversation is held for the owner's approval and
nobody answers in time, Persona gives the tool call a non-final result that
ends the turn, keeps the card waiting for 24 hours and tells the conversation
its outcome later, which starts the next turn. The turn's last words ("still
waiting on the approval card") were posted as the answer, and on WeChat that
took the one reply: the real result after the approval, with its picture, was
refused.

At a turn's end with no reply yet, the session's row (pending_interactions)
and the hub's waiting cards now say whether a card raised since the request
was asked still waits. If one does, nothing is posted and the reply stays
free; the run keeps waiting (agent_approval_wait, 25 h) and the turn after the
card's outcome answers as usual. A card from an earlier request does not hold
a later one. A read the hub cannot answer now is asked again before anything
is posted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…on; a card comes before awaited work; the put-off is bounded (review 1)

- A turn whose end was put off (the hub could not say whether a card waited)
  is no longer forced to end once its conversation goes on: any new item
  clears it, its words are not posted, and the turn under way ends as usual.
  Before, the card's outcome arriving with the hub back posted the old words
  or the next turn's half-written ones and ended the run.
- A card waiting is checked before the work the conversation handed out
  (Feishu's agent_task_wait): such a run is held and still followed, instead
  of ending as awaiting and missing the next turn's last words.
- The put-off lasts at most agent_hub_wait: then a row that cannot be read
  means the last words are the answer, as before, and a card list that cannot
  be read while the row counts a card holds the run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…当成回复发出

- 核心(飞书、微信都生效):/agent 会话里的命令被 Persona 拦下等主人审批、本轮因此结束时,不再把「还卡在审批卡上」这段话当成回复发出,也不占掉微信唯一一次回复。
  - 判断依据:hub 会话行的待处理卡片数,再看待处理卡片列表里有没有本次请求之后新建的卡;同一会话里更早请求留下的卡不压住这次的答复。
  - 审批有结果(批准、拒绝、过期)后,Persona 把结果送进会话开始下一轮,下一轮按原规则回复,可以带图。
  - 卡片最多等 25 小时(Persona 的卡等 24 小时后过期),真没等到就发一次超时说明。
  - hub 暂时答不上来时先不发,最多再问 5 分钟。
- 不新增权限,不新增以用户身份发的消息,不默认打开新功能。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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