Skip to content

[v2] 交互 Agent 节点:跟进消息未送达时提示并可重发,首轮在发给 Node 前失败可续跑 - #391

Merged
EricWvi merged 6 commits into
ora-space:mainfrom
ObsisMc:fix/1225-interactive-undelivered-permit
Nov 17, 2026
Merged

EricWvi merged 6 commits into
ora-space:mainfrom
ObsisMc:fix/1225-interactive-undelivered-permit

Conversation

@ObsisMc

@ObsisMc ObsisMc commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Refs ora-space/circus#1225

v2,不涉及 specs。只改 v2-server/ 和 frontend-v2/,接口路径和数据库结构不变。

两处都是 #380 owner 验收时提出的 Low。

1. 跟进消息没送达时,页面要说出来

问题:发起人给等待输入的交互节点发消息,接口在认领节点后就返回 200,消息之后才交给会话。执行服务这时拒绝(服务不可用、冲突、正在关闭,或会话已在别处结束),消息就没有执行,只留一条服务端日志,节点照原样回到等待输入。

改动

  • 后端:
    • 这种拒绝之后,节点回到等待输入时在 payload.interactive 里写 last_turn_error: "not_delivered"。发起人的下一条消息被认领时,在同一次行更新里清掉;完成节点时写入的摘要不带它。
    • 摘要里加了 sent:发起人已发的消息数。last_turn_error 说的是第 sent 条。认领被拒(行没能改成运行中)的那一次不计数。
    • 发消息的接口在响应里返回这条消息的序号(sent,workflows.openapi.json 里的 WorkflowNodeTurnResponse),页面拿它和摘要的 sent 比对。
  • 前端:
    • 等待输入的节点在输入框上方提示「上一条消息未送达,请重发。」。会话已经结束的提示「……会话已结束,不能重发。」。
    • 发出这条消息的页面记着它的内容和接口返回的序号,序号对得上时可以点「重新填入」放回输入框。序号由服务端给,不从屏幕上的摘要推算,所以别的标签页发的、或更早的消息不会被放回来。被服务端拒绝的发送不记。
    • 未送达提示只对发起人显示,其他成员看到的仍是只读说明。
    • 屏幕上的摘要比本页面刚发的消息还旧时,提示说的是更早的消息,先不显示。这不依赖运行什么时候重新读回。
    • 节点换了一次新的尝试(续跑之后),输入框和记着的消息清空。

2. 首轮在发给 Node 之前就失败时,节点要能续跑

问题:会话在首轮被认领时就记为「已启动」,之后才构建 Agent 配置、取模型授权。这两步失败时什么都没发给 Node,但这一轮被当成「启动后丢失」。交互节点于是以 no_completed_turn 停住,运行只能取消。

改动:改为在发出 start_agent_session 之前才记为已启动。

  • 在这之前失败的首轮带 NotStarted,交互节点按 interactive_session 失败,可以续跑;结束这个会话不需要 Node 配合。
  • 授权期间如果有 End 到达,它找不到要停的 Agent,所以这一轮之后不再启动 Agent。
  • 授权期间 Node 断开的,也不发启动命令,会话不算已启动。
  • 顺带的效果:以前这种失败会给 Node 发一条它不认识的 end_session,结束得不到确认;现在不发了。

commit

  1. fix(v2): report a first turn refused before Node as not started
  2. feat(v2): record that an interactive node's message was not delivered
  3. feat(v2): show an undelivered message on the interactive node
  4. 合并 main(6b07eca9,含 cloud#389),只有 v2-server/README.md 有冲突
  5. fix(v2): answer an interactive message with its number
  6. fix(v2): take the undelivered message's number from the server

验证

本机 4 核,后端用 GOMAXPROCS=2 go test -p 1 -race,TEST_DATABASE_URL 指向本地 PostgreSQL。都在 head 36c9d687 上,base 是 main 5416335a(cloud#383、cloud#388 之后):

  • 后端:gofmt、go vet ./... 通过。只跑了相关的四个包:internal/workflowhost、internal/agentruntime、internal/executionruntime、internal/server。
    • 新增和改动的用例各跑 25 遍,全过。
    • workflowhost 整包跑了 6 遍:第 1 遍失败,没留住是哪个用例;之后 5 遍全过,没能复现。
  • 前端:14 项接口检查、tsc -b、oxlint --deny-warnings、npm run build 通过。vitest 945 个里 944 个通过,包括本 PR 的全部用例。
    • 失败的 1 个是 run-flow.test.tsx 的 "analyzes a finished run once and explains each Agent from that analysis with its own list",和本 PR 无关:在未改动的 main(rebase 前的 5058c817)上跑整套测试,同一个用例同样失败;单独跑这个文件 26 个全过。以 CI 为准。
  • 反向检查:每个新测试都在改坏的实现上确认过会失败,再还原。这些是开发过程中逐项做的,没有全部在最终 head 上重做一遍。
    • started 改回在 begin 里设置,或去掉记为已启动前对「已结束」「Node 已断开」的检查(3 种):对应的 TestDriverIPCFirstTurn… 用例失败。
    • 后端的未送达标记(8 种):不写、不清、认领时不改行、摘要里不带 last_turn_error、摘要里不带 sent、认领被拒时不还原标记、认领被拒时不退回计数、运行已停止的分支不标记。对应用例都失败。
    • 前端(8 种):摘要比刚发的消息旧时仍提示、序号对不上也提供「重新填入」、不读 sent、操作后不重新读取运行、消息序号不加一、会话结束仍可重新填入、消息序号只按屏幕上的数算、换了尝试不清空输入框。对应用例都失败。
  • 独立复审(Opus 5.5 high,只读,三轮):
    • 第 1 轮 0 High / 1 Medium / 3 Low / 5 Nit。Medium:重发成功后的一瞬间,旧提示会把刚发出的消息「重新填入」。
    • 第 2 轮 0 High / 1 Medium / 3 Low / 3 Nit。Medium:提示没有和具体哪条消息绑定,重新读取失败或开两个标签页时仍可能放回已送达的消息。改成按消息序号判断(加了 sent)。
    • 第 3 轮 0 High / 0 Medium / 2 Low / 3 Nit,都已改。这一轮之后的小改动(认领被拒时退回计数、消息序号接着本页面上一条算、按尝试重置输入框)没有再复审,各有测试和反向检查。
  • 真实 Node:只跑了一个临时流程,用来截图并确认端到端成立。本地构建里临时让一条指定内容的消息提交失败(未提交,已还原),在真实 Node 上走通:发消息 → 节点回到等待输入并提示未送达(摘要 sent: 1、last_turn_error: "not_delivered")→「重新填入」→ 改发一条正常消息 → 送达、Agent 回答、提示消失(sent: 2)。截图在运行 issue 里。
  • e2e:只跑了 frontend-v2/e2e/workflow-interactive.spec.ts(真实 Node,3 个用例),都通过。这几个用例在 CI 上没有真实 Node,会跳过。
  • 没跑:整个 Go 模块的测试、仓库里已有的真实 Node Go 用例、e2e 套件的其余部分。e2e 没有加用例:让执行服务拒绝一条已接受的消息需要故障注入,现有 e2e 没有这个入口。
  • 没有专门的全链路测试:「模型授权失败 → 节点按 interactive_session 失败」由三段各自的测试覆盖:驱动报告 NotStarted(本 PR 新增)、执行服务把驱动的错误记为 AgentLost 并保留 NotStarted(已有)、工作流据此按 interactive_session 失败且可续跑(已有,本 PR 加了一个用例)。

owner 验收第 1 轮之后(e3f01e1d..8a60e9ad)

  • 改动:上面第 5、6 个提交。发消息接口返回消息序号,页面用它判断「重新填入」;补了「被拒绝的发送不记」的用例;README 写明提示只对发起人显示。
  • 反向检查(都已还原):序号改回从屏幕推算、发送成功前就记下消息、接口响应不带 sent、服务端返回的序号少一,对应用例都失败。
  • 验证:go vet ./... 通过;workflowhost 和 server 两个包带 -race 通过;前端 api:check:workflows 无漂移,类型检查、lint、构建通过,单测 954 个全过。
  • 真实 Node:workflow-interactive.spec.ts 3 个用例通过;截图流程在 8a60e9ad 上重走了一遍,接口对两条消息分别返回 sent: 1 和 sent: 2。界面没有变化。
  • 没跑:整个 Go 模块的测试、已有的真实 Node Go 用例、e2e 套件的其余部分。

已知没处理的

  • 消息已被执行服务接受、之后在 Agent 驱动里被拒绝(例如项目的 Node 已断开)时,节点显示「会话已结束」并多算一轮,没有「未送达」提示。这是原有行为,不在 #1217 的范围内。
  • 页面刷新或关掉会话面板后,「重新填入」不再提供(消息内容只留在页面内存里),提示照常显示。

A session counted as started as soon as its first turn was claimed,
before the Agent configuration was built and the model permit taken.
When either of them failed, nothing had been sent to Node, yet the turn
was reported as a lost Agent rather than one that never started. An
interactive workflow node then parked with no answer and no
conversation, and its run could only be cancelled.

The session is now marked started just before the start command is
sent. A turn refused before that is NotStarted, so the interactive node
fails as interactive_session and the run can be resumed, and ending the
session asks nothing of Node. An End that arrives while the first turn
is being permitted finds no Agent to stop, so the turn does not start
one afterwards; a Node whose transport fails in that window is not sent
the start either.
A follow-up message is accepted before the execution service sees it.
When the service then refused it (unavailable, a conflict, shutting
down, or a session that ended elsewhere), the message never ran, the
request had already returned 200, and only the server log knew.

The node's summary now carries last_turn_error = not_delivered when it
parks after such a refusal, so the run page can tell the starter. The
notice is cleared in the same row update that claims the starter's next
message, and a completion writes the summary without it.

The summary also counts the starter's messages (sent). The notice is
about the latest of them, which lets a page tell whether it concerns a
message that page sent.
The run page reads last_turn_error from the node's session summary.
While the node waits for input, the starter sees above the composer
that the last message was not delivered and should be sent again. Once
the session has ended there is nowhere to send it, so the notice says
that instead.

The view that sent the message offers to put its text back. It keeps
the message's number, the summary's sent count plus one at the time of
the send, and offers the text only when the notice is about that
number, so a message sent from another tab or an earlier one is never
restored in its place. A summary older than the view's last send is
about an earlier message and its notice is not shown, however long the
next read of the run takes.

@zhangxinhao zhangxinhao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM(36c9d68)

@ObsisMc 我看了这个 PR,理解它是要让交互节点明确提示跟进消息未送达并支持重新填入,同时让首轮发给 Node 前的失败可以续跑。可以合并。发现一处跨标签页且摘要滞后时的消息关联问题,建议后续修正;工作流数据库测试本次未能执行。

  • 📌 建议另开 PR 处理:P2-1 跨标签页时推算序号仍会关联错消息(不影响这次合并)
  • 测试:cd frontend-v2 && npm test -- src/features/chat/workflow-run/run-node-session-actions.test.tsx src/features/chat/workflow-run/run-node-session-chat.test.tsx src/features/chat/workflow-run/server-run-adapter.test.ts 通过;cd v2-server && go test -race ./internal/agentruntime -run 'TestDriverIPCFirstTurn' -count=1 通过;cd v2-server && go test -race ./internal/agentruntime -count=1 通过;cd v2-server && go test -race ./internal/workflowhost -run 'Test(RefusedClaim|RefusedFollowUp|UndeliveredNotice|AcceptedFollowUpDoesNotRun|FirstTurnWithoutASession|AppendToAnEnded)' -v -count=1 没跑(命令执行完成,但所选测试因未设置 TEST_DATABASE_URL 全部跳过。);没跑全量和 e2e。

涉及对外 API/协议、并发核心,建议 owner 再看一眼。

以上都是建议,怎么处理由你决定。

自动检视 · 基于 36c9d68 · 第 1 轮(全量)

if (await act(() => sendNodeTurn(tenantId, runId, nodeId, draft))) setDraft('')
// v2 numbers the starter's messages as it accepts them. This one follows those on screen,
// and this view's previous one when the screen has not caught up with it yet.
const sent = { text: draft, number: Math.max(session?.sent ?? 0, lastSent?.number ?? 0) + 1 }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2-1(建议) 这里推算的序号不一定是服务端实际认领的序号。例如当前页仍显示 sent: 0,另一标签页已发送第 1 条且未送达,当前页再发送的实际是第 2 条,这里却记成第 1 条。若随后读到第 1 条的旧摘要,就会错误提供当前页消息的「重新填入」,即使它已经送达;而第 2 条真的未送达时又无法恢复正文。临时用例已复现错误按钮。建议由服务端在认领响应中返回本次实际序号,或回显消息 ID,再绑定本地正文,并补充这个交错场景的测试。

改动较大,建议另开 PR 处理,不影响这次合并。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已处理,谢谢。

main gained the session-slot wait marker (cloud#389). The only conflict
is in v2-server/README.md, where both sides edit the same long
paragraph lines: main's text is kept and this branch's six sentence
edits are applied to it again unchanged.

@zhangxinhao zhangxinhao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM(e3f01e1)

@ObsisMc 我看了这个 PR,理解它是要让交互节点提示跟进消息未送达并支持重新填入,同时让首轮发给 Node 前的失败可以续跑。这是第 2 轮,我看了 36c9d68 之后的改动。本轮合并 main 后,等待会话名额与未送达提示的逻辑均保留,未发现新增问题,可以合并。上轮 P2-1 尚未处理,仍建议后续另开 PR 修正。

  • ⏳ 上轮还没处理的:P2-1(仍是建议,不影响合并)。
  • 测试:cd frontend-v2 && npm test -- src/features/chat/workflow-run/run-node-session-actions.test.tsx src/features/chat/workflow-run/run-node-session-chat.test.tsx src/features/chat/workflow-run/server-run-adapter.test.ts 通过;cd frontend-v2 && npm run typecheck 通过;cd v2-server && go test -race ./internal/agentruntime -run 'TestDriverIPCFirstTurn' -count=1 通过;没跑全量和 e2e。

涉及对外 API/协议、并发核心,建议 owner 再看一眼。

以上都是建议,怎么处理由你决定。

自动检视 · 基于 e3f01e1 · 第 2 轮(增量)

@EricWvi EricWvi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

owner 验收第 1 轮(36c9d687):0H/0M/3L。请修 L1(「重新填入」用服务端返回的序号)、补 L2 的测试、README 写明 L3,并解决和 main(cloud#389)的冲突。详情见 ora-space/circus#1225。

The run page had to guess which of the starter's messages it had just
sent: the summary's sent count on screen plus one. A second tab of the
starter's sending at the same moment made that guess wrong, and the
page could then take the other tab's undelivered message for its own.

Sending a message now answers with the number the bridge claimed it
under, the value payload.interactive.sent has from then on. The turns
route returns it as sent, in its own response schema.
The view that sent a message keeps the number the send answered with
instead of counting from the summary on screen, and offers to put the
text back only when the notice is about that number. A message another
tab sent meanwhile can no longer be mistaken for it.

A send the server refused is not remembered, which a test now pins.
The README says that only the starter sees the undelivered notice.

@zhangxinhao zhangxinhao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM(8a60e9a)

@ObsisMc 我看了这个 PR,理解它是要让交互节点提示跟进消息未送达并支持重新填入,同时让首轮发给 Node 前的失败可以续跑;本轮改用服务端返回的消息序号,避免跨标签页关联错消息。这是第 3 轮,我看了 e3f01e1 之后的改动。整体没问题,可以合并。本轮增量已解决上轮 P2-1,未发现新增问题;相关前端测试通过,后端数据库测试因缺少配置未能执行。

  • ✅ 上轮的 P2-1 已处理,谢谢。
  • 测试:cd frontend-v2 && npm test -- src/features/chat/workflow-run/run-node-session-actions.test.tsx src/features/chat/workflow-run/run-node-session-chat.test.tsx src/features/chat/workflow-run/server-run-adapter.test.ts 通过;cd frontend-v2 && npm run typecheck 通过;cd frontend-v2 && npm run api:check:workflows 通过;cd v2-server && go test -race ./internal/workflowhost ./internal/server -run 'Test(RefusedFollowUpIsReportedAsNotDelivered|RefusedClaimKeepsTheUndeliveredNotice|UndeliveredNoticeFollowsTheLatestMessage|WorkflowNodeTurn)' -count=1 -v 没跑(编译通过,但未设置 TEST_DATABASE_URL,选中的数据库测试全部跳过。);没跑全量和 e2e。

涉及对外 API/协议、并发核心,建议 owner 再看一眼。

以上都是建议,怎么处理由你决定。

自动检视 · 基于 8a60e9a · 第 3 轮(增量)

@EricWvi EricWvi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

第 2 轮:L1(服务端返回序号)、L2(测试)、L3(README)已满足,冲突处理正确。

@EricWvi
EricWvi merged commit 9fbc9d7 into ora-space:main Nov 17, 2026
3 checks passed
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.

3 participants