Repository navigation
Recover ambiguous Lark worker returns without delayed duplicate sends - #9318
loopx-agent wants to merge 4 commits into
Conversation
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-astra · OpenAI · runtime_reported · xhigh
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
通过飞书委托工作的用户,在原对话里等候执行结果。飞书收下了结果,连接却在返回消息编号前断开。原版本将这次发送记成普通失败,下一次启动可能在去重期限过后把同一结论再发一遍。修复后,一次断流可以找回原消息编号。连续丢失回应时,原对话保留一条结论和未核实的投递状态。本次覆盖工作结果的单条飞书消息。多段消息沿用已有日志,实网用户投递与进程在写回前被强制终止均不在本次实测范围内。
改动思路 / Approach
飞书适配器负责辨认服务商返回值,原有结果投递事务负责持久化,应用继续读取同一份记录。改动限于单条工作结果的发送与回读,多段投递、工作执行和授权配置有各自现存的负责人。 消息编号与幂等键承担不同职责。前者定位已经发出的消息,后者仅在服务商的时限内约束重复投递。发送方第一次丢失应答时保存着完整请求,因而可以重新核对当前会话的授权,再用完全相同的请求尝试取得消息编号。
| 发送后的观察 | 下一步 |
|---|---|
| 连接断开且原授权有效 | 在去重时限内用原键尝试一次 |
| 已有消息编号,暂时读不到内容 | 重启后用编号核实 |
| 两次断流、授权撤销或输出被策略拦截 | 原对话保留结论,投递记为未核实 |
| 明确的流量限制 | 由原调度流程退避重试 |
具体改动 / Changes
关键代码讲解
_worker_send_failure在loopx/extensions/lark/inbox_reply.py读取飞书命令行的结构化回包。网络或无效应答可能发生在服务商收件之后。已明确的限流保留原重试路径,输出策略可能在写入后才拦截显示,因而单独保留不确定状态。_deliver_lark_inbox_outbound只为工作结果启用这次恢复。重放前重新检查发送身份、原来源、目标和授权,使用墙钟与单调时钟共同核对剩余时间,沿用原请求、原幂等键和既有的消息读回流程。_return_provider在loopx/capabilities/manager_context/roundtrip.py识别已经尝试写入而结果仍然未知的情况,通过deliveryOutcome写入已有的未核实状态。常规消息依然使用原入口。规格映射见docs/architecture/rfcs/human-confirmed-domain-operations-v0.md,基线d588d27fa5e09a516a66b56382606ba2d3ba8f1f。Reconcile the original worker result without delayed republication — implemented. 测试直接重开原对话存储,再次检查回执、消息数和宿主启动记录。
对主干的风险 / Risks
飞书去重期限之外再发相同内容,仍可能产生第二条消息。对照实验让模拟服务商清空幂等缓存,再让真实投递流程重开原会话。基线产生两条可见消息,候选版本保留一条。两个版本的普通会话回复和话题内回复均只发送一次,状态和键一致。七个实包用例同时覆盖持续断流、授权撤销、限流和输出拦截。若服务商始终不给出可验证的编号,仍需新的可信证据才能确认最终投递。实网行为和硬终止窗口仍待单独验证。
我的整体评价 / Verdict
后续宿主读取同一轮次的结论及投递状态,无需重新启动执行任务。用户可以在原对话看到结果;服务商没有给出可核实编号时,界面保留未核实状态。 精确基线的七条回归有六条失败,候选安装包七条全部通过。精确提交的 363 条相关源码测试及标准预检通过。这是作者侧评审,独立审阅和仓库合并状态应据其各自回执判定。
English verdict: APPROVE 9402915. The original worker return survives a lost response without an unbounded second send; persistent uncertainty remains visible.
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.2-astra · OpenAI · runtime_reported · xhigh
Approval conclusion (author-owned PR; GitHub blocks formal self-approval)
动机 / Motivation
在飞书原对话中接收工作结论的用户可能遇到重复收件。飞书已经收下工作结论,进程可能在保存消息编号前被终止。此时用户能在原对话看见结论,本地队列却仍允许再次发送。把时钟推进两小时并重启后,基线向同一收件人发送了第二条。这次验证覆盖了进程直接退出的窗口,也保留了上一版对连接中断的处理。服务商收件后强停,候选实包恢复后保留一条飞书消息、原 Turn 和一次工作执行,投递状态为未核实。实网飞书投递与混合版本降级尚未验证。
改动思路 / Approach
发送前先验证原会话的授权和消息预览,再持久化这次外部发送的状态。工作进程正常运行时,丢失应答仍可在服务商去重期限内用同一请求尝试一次。中途退出后,新进程只依靠落盘证据做决定。有消息编号便直接回读,没有编号就保留未核实状态。服务商明确拒绝写入时,调度器仍可安排重试。带精确 Goal 身份的路径沿用已有持久化准入,普通聊天和话题回复沿用原调用方式。
具体改动 / Changes
关键代码讲解
- 飞书的
_run_inbox_return将发送前的回调传给单条结果的写入入口。_deliver_lark_inbox_outbound在完成来源、权限和预览检查后,紧靠第一次 POST 调用它。_worker_send_failure区分明确限流、连接中断及回包被隐藏。 roundtrip.py的_ReturnAttemptRecorder使用原请求的版本分别保存发送检查点和消息编号。return_delivery.ts的finishReturn拒绝过期版本和无授权的发送。对于已经开始却没有消息编号的请求,后续撤权或异常不会将它重新排进发送队列。依据docs/architecture/rfcs/human-confirmed-domain-operations-v0.md的原会话回执约定,Recover the original result across worker termination — implemented。基线为d588d27fa5e09a516a66b56382606ba2d3ba8f1f。
对主干的风险 / Risks
强停发生在预览时,恢复后成功发出一次。消息编号落盘后强停,冷启动可验证已送达。另一个必须保留的边界是检查点已写、POST 尚未执行。此处强停实测零投递,本地同样只能标为未核实。即使同一结论仍在 Chat 里可读,这份本地记录也不能证明外部收件人看到了消息。四个位置均使用生产发送路径、真实磁盘状态和隔离的模拟服务商。
我的整体评价 / Verdict
同一强停实验让基线产生两条收件,修复后的候选包把已接收情形控制在一条。两种普通回复的调用次数、状态和幂等键与基线一致。候选实包的 12 个恢复用例、额外的发送前强停探针、65 个 TS 测试、456 个相关 Python 测试和标准合并前检查均通过。独立审阅及生产采用仍需各自的回执。
English verdict: APPROVE f73a35b. The installed candidate prevents a second post after process death, retains the original result, and exposes uncertainty when no provider locator survived.
Recover the original worker return after a disconnect or process exit
A worker's conclusion can reach its original Chat session while the Feishu provider has already published the message and its acknowledgement has been lost. After an outage longer than the provider's UUID retention, the return pump could send the same conclusion again.
Single-message worker returns now recheck the original audience, grant and time window before replaying a lost response once in the same process. For returns without an exact Goal admission, the pump records the pending external write after preflight and immediately before sending. Recovery uses the original message ID when it exists. An unknown write without an ID stays explicitly unverified. A confirmed rate-limit rejection remains retryable. The Chat conclusion remains on its original Turn.
Verification
An isolated provider and real Chat store exercised the installed candidate wheel. The delivery worker was killed with SIGKILL, its store reopened, and the pump drained twice more than two hours later. The host invocation log and original Turn remained unchanged.
The earlier PR head produced two visible messages in the post-acceptance case. The last row documents a limit of the recovery protocol. Without a locator or durable provider proof, the pump cannot distinguish a process exit just before the write from one just after acceptance.
The candidate wheel passed the three main process-death cases, two committed interruption regressions and seven response-fault cases covering delayed readback, repeated timeouts, revoked grants, expired replay windows, withheld output and rate limiting. A separate probe covered the fourth interruption above. Ordinary inbox sends in source chat and thread placement retained their baseline key and single outbound call. Multipart delivery uses its existing journal. The provider was emulated throughout.
The final head passed 456 related Python tests, 65 TypeScript return tests and the standard premerge checks. Six independent delegation fixture cases initially failed to import their sibling oracle under an inherited Python safe-path setting. The base reproduced all six failures. Restoring the default interpreter import behavior passed those six checks on the base and the full suite on the candidate.
Feishu documents its one-hour UUID deduplication guarantee in the send-message API.