Repository navigation
feat(webhook): 持久异步触发与能力探测;修复 TraeX 真实用户输入溯源 - #2734
Conversation
Add GET ?capabilities=1 so programmatic callers can discover durable async support, and ?async=1&durable=1 to route fresh virtual async turns through the daemon's durable at-most-once idempotency lease. Durable requests keep volatile source fields out of the request hash so retries resolve to the same sessionId/triggerId, and reject chat/session/rootMessageId injection.
New TraeX rollouts persist genuine user input in history_mutation with internal_chat_message_metadata_passthrough. Require the runtime's user.text provenance and a matching native turn ID so AGENTS/environment/runtime injections with role=user are not treated as the submitted task, and so the final answer can be recovered by trigger-result.
type-ahead 场景下后一 turn 的 history_mutation 会先于前一 turn 的 task_complete 落盘;原先 traexPendingAgentCache.delete(path) 清掉整个 路径下所有 turn 的待决 agent 消息,前一 turn 终态 last_agent_message 为空时无法恢复,最终答复丢失。改为只删本 turn 桶并前移 activeKey, 补两轮排队探针与回归用例(vitest/bun 双腿变异咬红)。 Co-Authored-By: Claude Code <[email protected]>
自动评审初步意见(Claude,最终以维护者审阅为准)整体方向认可:webhook 侧复用 daemon 已有的 已代修并推送(新 head
|
复审探针发现同一 turn 的 item_completed AgentMessage 可能先于 provenance 用户边落盘(含跨 drain):c332d90d9 的 per-turn delete 会清掉本 turn 已缓冲的最终答复,空 last_agent_message 终态无法恢复 (master 同 shape 可恢复)。对齐旧 user_message / item_completed 两条 用户边的既有做法:只把无 turn_id 的 active 桶前移到本 turn,不删任何 桶——本 turn 已有证据时保留,type-ahead 的在飞前一 turn 也不受影响。 补三条回归(证据先于用户边的同 drain / 跨 drain、无 turn_id 的 AgentMessage 经 activeKey 归属),vitest 与 bun 双腿对「删 activeKey」 「恢复 per-turn delete」「恢复整 path delete」三类变异均咬红。 Co-Authored-By: Claude Code <[email protected]>
转发头白名单是连接器属主可配的,其中 x-request-id、网关 delivery id 这类头每次投递都变;它们既进模型上下文也进 daemon 请求哈希。durable 模式刻意关闭 edge 去重闸,逐投递变化的头会让同键重试在 daemon 侧撞 409 idempotency_conflict,与「重试解析到同一会话」的契约直接冲突。 durable 请求改发空 headers(非 durable 路径不变),并在中英文 webhook 指南补全 async=1 / durable=1 / capabilities=1 的完整服务契约说明。 测试:补 durable 10 项拒绝矩阵(token/HMAC/dynamic/fixed/async/wait/ dryRun/key 长度/chatId/sessionId/rootMessageId,断言命中 edge 自身错误) 与 capabilities 三个 false 分支;header 剥离在 durable / 非 durable 两路径各一用例。变异 12 枪(10 闸门 + 2 能力谓词 + header 剥离)全部 咬红。 Co-Authored-By: Claude Code <[email protected]>
复审跟进(新 head
|
|
已合并,感谢贡献!🎉 最终落地包含两个提交的跟进修改(评审过程中追加,未改动你的原始提交):
两个可继续推进的 follow-up(均不影响本次合并):
|
|
🚀 Released in v3.57.0 |
改了什么
两件互相独立的事:
1. Webhook 持久异步触发 + 能力探测
?async=1&durable=1:外部系统触发新虚拟会话时,改走 daemon 已有的落盘 at-most-once 派发租约(options.idempotencyKey),而不是 Dashboard 进程内的去重窗口。同一幂等键的重试始终返回第一次的sessionId/triggerId,Dashboard / daemon 重启都不丢。async=1与非空且 ≤200 字符的幂等键;不能与wait=1/dryRun=1同用;禁止请求携带chatId/sessionId/rootMessageId。whapi:+sha256([connectorId, 业务幂等键]);触发请求刻意省略每次变化的requestId/receivedAt,durable 模式下不转发连接器白名单里的逐投递变化头(否则同键重试会在 daemon 侧撞 409)。GET ?capabilities=1,调用方可凭同一凭证探测该连接器是否支持持久异步(token + dynamic + 幂等开启三者同时满足才为 true)。2. TraeX 新 rollout 的真实用户输入识别
TraeX 新版(实测 0.211.1)把真实用户输入只写在
history_mutation的 items 中,而其中 role=user 的消息同时混有 AGENTS.md / environment 等运行时注入。新逻辑只承认带internal_chat_message_metadata_passthrough.content_item_kinds含user.text、且 meta.turn_id 与记录 turn_id 一致的 message,抽取其中 input_text 作为用户开场,保证 trigger-result 在新 rollout 上能恢复用户开场与最终答复。识别到用户边时只把无 turn_id 的待决桶前移(activeKey),不删除任何 turn 已缓冲的待决答复,兼容证据先于用户边落盘与 type-ahead 两种顺序。为什么
影响面
durable=1的请求行为完全不变;能力探测是只读 GET。文档
docs-site/docs/{zh,en}/webhook.md新增「异步触发与结果轮询」章节,覆盖async=1/durable=1契约、capabilities=1探测、409 语义、header 不透传、崩溃与并发重试语义及 trigger-result 四态链接。测试
test/webhook-idempotency.test.ts:durable 重试请求逐字节相等与引用保持、转发头剥离(durable / 非 durable 两路径)、10 项准入拒绝矩阵、capabilities 三个 false 分支。test/traex-history-user.test.ts:溯源用户边、注入与 turn_id 不一致拒绝、probe 不消费 claim、与旧镜像不重复、跨 drain 切分、证据先于用户边(同/跨 drain)、无 turn_id 的 AgentMessage 经 activeKey 归属、type-ahead 双 turn 不丢前一 turn 答复。已知 follow-up(不阻断)
traexRolloutUserInputs(/adopt 归属判定的 canonical 输入通道)尚未复用本次的 provenance 谓词;当前方言有 item_completed 镜像兜底,计划单独 PR 收口。