Repository navigation
feat(im): 把聊天发起人记入需求操作日志,并在平台管理里配置外部访问地址 - #1300
Conversation
…operations Creating a requirement or triggering its SOP from a WeCom, Feishu or DingTalk Bot ran as the platform account the sender is bound to, but the requirement's audit trail only named that account: the operation log of a requirement created from chat was indistinguishable from one created on the platform, and the IM member who asked for it could not be recovered (the sender was only kept in bot_chat_origins, which is notification routing and is never exposed). Carry the IM sender of a chat turn in the request context of the internal platform calls the turn makes (botChatActor, next to the request user) and record it on IssueOperation as ActorChannel/ActorSender. Actor keeps its meaning: the platform account whose permissions were used. Both new fields stay empty for operations taken on the platform itself. The actor is injected on every write path of a chat turn: writes made within the turn, drafts confirmed on the platform page or on a chat card, and the SOP started right after a chat clarification is saved. create, update and dispatch all go through recordIssueOperation, so all three are covered. Operations are stored in the issue JSON payload, so no migration is needed. The requirement drawer now shows "企业微信 <userid>(平台账号 <account>)" for chat-initiated entries and is unchanged for platform ones.
…ly its ID The audit entry added by the previous commit identified a chat-initiated operation by raw sender ID, which reads as an opaque string in the requirement drawer and in the member picker. Capture the display name the channel reports for a sender and keep it next to the identity. DingTalk is the only channel that sends one (senderNick), so it is mapped onto InboundEvent and persisted with the interaction; the name is then cached on the binding, because the later actions of the same sender carry none - card clicks, confirmations on the platform page, and the SOP started right after a chat clarification is saved. A revoked binding drops the cached name with the rest of the identity, and an empty report never clears a stored one. WeCom and Feishu bot callbacks carry the sender ID alone and their credentials are bot-scoped, so no name is invented for them: those senders keep being named by the platform account they are bound to, which the entry already shows. The new column is the place a contact-directory lookup would fill later without touching the schema again. IssueOperation gains ActorSenderName as a snapshot of the name at the time of the action. Node approvals, retries and answers now put the name next to the sender ID in the run's decision note, and the Feishu/DingTalk notification-target picker shows it instead of a masked ID. New columns only, filled by AutoMigrate; no data migration.
The platform's external address was only readable from
AGENTFLOW_PUBLIC_URL at startup, so a deployment that did not set it had
no way to recover: chat Bots answered "平台外部访问地址尚未配置,请联系
管理员" and could build neither an account binding link nor a write
confirmation link, and notifications lost their run detail link. Fixing it
meant editing .env and restarting.
Add 平台管理 → 外部访问地址, where a platform administrator saves the
address once. A saved value wins over the environment, so the page can
always correct a wrong or missing deployment configuration; the page names
the effective source and shows the shadowed environment value, so a
configured AGENTFLOW_PUBLIC_URL is never silently mistaken for the one in
use.
Reading it on use required a resolver. Service.PublicURL was a string read
from the environment once and copied again into botIdentityHandlers, so
nothing could change it at runtime. Service.PublicAddress now resolves the
stored value first and the environment second, and every link builder goes
through it; botIdentityHandlers takes a func instead of a string. The row is
a single primary-key lookup and the callers run at chat-event rate, so there
is no cache to invalidate.
The suggested value comes from the administrator's own browser
(location.origin), never from a Host header the platform received: this
address is pasted into binding links that carry a one-time token, so a
forgeable source would be a phishing vector. Accepted shapes mirror
scripts/install-address.py so the installer and the page agree; a loopback
address is saved with a warning rather than refused, because it is what a
local trial uses but cannot work in a link sent to a phone.
Also make the authorization failures say what to do about them, which is
what sent people looking at the wrong layer:
- WeCom 850002 ("no authorization") fell through to the generic "请检查机器
人授权或稍后重试" and was not counted as awaiting authorization, so the
configuration showed a plain error and retrying looked reasonable. It now
names the capability grant, where to grant it, and that retrying will not
help; 851009 (pending approval) and 853006 (tenant capability blocked) get
their own text, and awaiting_authorization is decided by one predicate
shared by the health and delivery paths. 853006 stays a plain error because
no authorization resolves it.
- The Feishu/DingTalk enterprise-confirmation notice now names the step that
unblocks it instead of asking the sender to retry, which cannot succeed
until an administrator confirms the enterprise.
New table only, filled by AutoMigrate; no data migration.
|
审查了
PR 自带的相关 Go 定向测试通过。上述行为已用隔离快照复现。 |
Robert0622
left a comment
There was a problem hiding this comment.
Review:feat(im) 聊天发起人记入需求操作日志 + 平台管理「外部访问地址」
结论:不通过(有 2 个 P1:主路径的 IM 发起人没有记上;PR 让 CI 里一个现有前端测试失败)
审阅的 head:32b6b70951b58ce6bae59d674dfe00e248467c88(base main be35aff)
「外部访问地址」这部分本身做得不错。只有平台管理员能读写(GET/PUT/DELETE 都校验了),CSRF 的 Origin 校验有效,scheme、userinfo、path、query 和 0.0.0.0、链路本地地址都会拒绝,回环地址给出提示,「填入当前访问地址」取的是 location.origin 而不是 Host 头。保存后立即生效,不用重启。需要改的问题主要在归因链路和授权恢复上,见下文。
P1
P1-1 原生 MCP 工具调用的写操作没有带上 botChatActor,自动写入模式下操作日志里没有 IM 发起人
- 现象:Bot 回合中,模型通过原生 MCP 网关(
/internal/agent-tools/<token>/mcp,CLI 类引擎就走这条)调用agentflow__issues_save/issues_dispatch等写工具时,记下的操作只有actor,actorChannel和actorSender都是空的。PR 自带的TestIssueOperationNamesWeComSenderOnAutoWrite测的是commitFinal里的 drafts 路径,没有覆盖这条主路径。 - 复现步骤:写一个单测(思路同
TestIssueOperationNamesWeComSenderOnAutoWrite),在h.generate里对h.api发起tools/call agentflow__issues_save {"body":{"projectId":"p","title":"..."}},然后看最新的create操作:op: actor="other-user" actorUserId=43 channel="" sender="" REPRODUCED: native MCP write recorded no IM sender - 位置:
internal/httpapi/agent_tool_mcp.go:423-427。这里只从session.ctx复制了botStartOriginFrom,没有复制botChatActorFrom。确认模式(drafts)的写入不走这里,所以不受影响;只读模式本来就不写。 - 建议:在同一处补上
再加一个走 MCP 网关的回归测试(
if actor, ok := botChatActorFrom(session.ctx); ok { ctx = withBotChatActor(ctx, actor.Channel, actor.SenderID, actor.SenderName) }
issues_save和issues_dispatch各测一次)。
P1-2 新增第 5 个 tab 后,webtest/tests/platform-admin.test.mjs 失败(CI core 作业,platform-required 会是红的)
- 现象:
platform admin page separates accounts, admins, shared keys and Git host trust断言arrow keys wrap around,即在「Git 主机信任」上按 ArrowRight 应回到「成员账号」。现在会先到「外部访问地址」,所以断言失败。 - 复现步骤:
cd webtest && npm ci && node --test tests/platform-admin.test.mjs- PR head:
# pass 5 / # fail 1,失败在platform-admin.test.mjs:75,actual [] / expected ['accounts'] - main:
# pass 6 / # fail 0
- PR head:
- 位置:
webtest/tests/platform-admin.test.mjs:57,71-77;tab 定义在web/app/workbench.js:1665。 - 说明:键盘导航的实现是通用的,没有问题。真实浏览器里实测,从「Git 主机信任」按 → 到「外部访问地址」,再按 → 回到「成员账号」,按 ← 回到「外部访问地址」,
aria-selected、tabIndex和焦点都对。过时的只是这个测试。 - 建议:更新测试,在
shown()里加入publicUrl,补一次 ArrowRight 到publicUrl,再断言回到accounts。最好再加一条外部访问地址 tab 的 jsdom 用例(mock/api/platform/public-url)。
P2
P2-1 群聊里「保存并启动」把 SOP 启动归到发起澄清的人,而不是实际操作的人
- 现象:成员 A 在群里发起澄清,需求负责人 B 发「保存并启动」(或点卡片)。
dispatch用的是 B 的平台账号,IM 发起人却记成 A。 - 复现步骤:单测里用
newClarifyChatFixture(feishu),让ou_member发「澄清 #7」,把会话置为 concluded,再让ou_owner发「保存并启动」:dispatch op: actor="bot-owner" actorUserId=42 channel="feishu" sender="ou_member" - 位置:
internal/httpapi/bot_clarify.go:883,withBotChatActor(..., sess.StarterSender, ...)。文本命令路径上,generateBotReply已经在bot_interactions.go:99放进了正确的发送者 B,这一行又把它覆盖成了 A。 - 建议:归因用当前这条消息或卡片点击的发送者,把
item.SenderID传进botClarifySave。BotChatOrigin继续用 starter 来路由通知,这两件事要分开。
P2-2 升级前已有的绑定行 sender_name 是 NULL,sender_name <> ? 永远不成立,显示名不会被缓存
- 现象:AutoMigrate 给
bot_user_bindings加的sender_name varchar(191)可为空、默认 NULL,存量绑定都是 NULL。NoteBotSenderName的WHERE ... AND sender_name <> ?遇到 NULL 结果是 UNKNOWN,行不会更新。所以升级前就绑定的钉钉用户,之后的卡片点击、网页确认、「保存并启动」都拿不到名字;通知目标列表里也只显示掩码 ID。 - 复现步骤(真实 MySQL 8.4):
- 用 main 的二进制初始化空库
lf_upg,插入一条user_id=1的绑定。 - 换 PR 的二进制启动,AutoMigrate 后
SHOW COLUMNS得到sender_name varchar(191) YES NULL,该行sender_name IS NULL = 1。 - 执行与
NoteBotSenderName相同的UPDATE ... WHERE id=? AND user_id > 0 AND sender_name <> '张三',得到ROW_COUNT() = 0,值仍是 NULL。
- 用 main 的二进制初始化空库
- 位置:
internal/repo/bot_identities.go:68;字段定义在internal/domain/bot_identity.go(SenderName ... gorm:"size:191")。 - 建议:条件改成
(sender_name IS NULL OR sender_name <> ?),或给列加not null;default:''。注意 AutoMigrate 不会回填已有的 NULL 行,所以改 SQL 条件更稳。再加一个预置 NULL 行的测试。
P2-3 新增的 850002、851009 进入 awaiting_authorization 后不会自动重新排队,851009 的文案却写着「审批通过后自动恢复」
- 现象:
awaitingAuthorization()新纳入了 850002 和 851009,这两类投递失败后状态变成awaiting_authorization。但ClaimNotification只领取pending(以及租约过期的sending)。仓库里把awaiting_authorization改回pending的只有手动「重试」(repo/notifications.go:513)。Bot 健康检查恢复成ready时,也不会重新排队这些投递。管理员审批通过后,这些通知会一直卡着,和文案说的不一致。另外,main 上 850002 会以 pending 退避重试最多 5 次,现在改成直接挂起。 - 复现步骤:代码确认,未实测真实企业微信。
notification/service.go:356-358把状态设为 awaiting_authorization;repo/notifications.go:476只 claimpending;全仓 grepawaiting_authorization,除手动重试外没有任何恢复路径。 - 位置:
internal/notification/provider.go:45-46(文案),:60(分类);internal/notification/service.go:356-358;internal/repo/notifications.go:476。 - 建议:二选一。
- 在 Bot 验证或健康检查回到
ready时(service.go:105-113),把该 Bot 的awaiting_authorization投递重新排为pending,这样文案才成立。 - 或者把文案改成「审批通过后请在投递记录里点重试」。
- 在 Bot 验证或健康检查回到
P3
P3-1 外部访问地址没有校验端口范围:65536、99999999、0 和末尾空冒号都能保存(另一位 reviewer 定为 P2,我复核后建议定 P3)
- 现象:
PUT /api/platform/public-url提交https://lf.example.com:65536、:99999999、:0、https://lf.example.com:都返回 200,并且立即成为生效地址,此后绑定链接和确认链接都会是坏的。页面上的<input type="url">会被 Chromium 拦下(checkValidity()=false),所以只有直接调 API 才会触发,而且只有平台管理员能调,因此建议 P3。注释说规则「mirror scripts/install-address.py」,但安装脚本里的parsed.port对 >65535 会抛 ValueError,两边并不一致。 - 复现步骤:
curl -X PUT .../api/platform/public-url -d '{"value":"https://lf.example.com:65536"}'返回200 {"source":"settings","stored":"https://lf.example.com:65536",...}。 - 位置:
internal/domain/platform_settings.go:67。net.SplitHostPort只拆分,不检查范围;Go 的url.Parse也只检查端口是数字。 - 建议:端口非空时用
strconv.Atoi校验 1..65535,空端口(末尾冒号)也拒绝,并补对应的表驱动用例。
P3-2 钉钉 senderNick 按字节截断到 191,可能把 UTF-8 字符切断,导致消息入库被 MySQL 拒绝
- 现象:
truncate()是s[:n]字节切片。昵称超过 191 字节时(例如 64 个汉字是 192 字节,或者较长的 emoji 昵称),结果是非法 UTF-8。MySQL strict 模式会报ERROR 1366 Incorrect string value,accept把存储错误返回给适配器重投,于是这条消息会一直失败。触发概率低,但后果是这条消息永远处理不了。 - 复现步骤:单测里
dingtalkEvent(..., senderNick=strings.Repeat("张",64))得到len=191 valid=false;在真实 MySQL 上插入同样被切断的字节,报ERROR 1366 (HY000): Incorrect string value: '\xE4' for column 'sender_name'。 - 位置:
internal/botinteraction/channel_dingtalk.go:485,internal/botinteraction/inbound.go:65-70;internal/repo/bot_identities.go:66的len(name) > 191也是按字节算的。 - 建议:按 rune 截断(项目里已有
truncateRunes),或截断后用strings.ToValidUTF8修正;191 的判断也改成按 rune 计数。
P3-3 创建需求时客户端提交的 operations 会原样保留,可以伪造 IM 发起人(main 上已有,本 PR 让影响变大)
- 现象:
PUT /api/issues新建需求时,body 里的operations(现在包括actorChannel、actorSender、actorSenderName)会原样保存,服务端只在后面追加一条真实的create。有项目写权限的成员因此可以在操作日志里伪造「钉钉 老板(boss)(平台账号 ceo)」这样的记录。main 上已经可以伪造actor,本 PR 让 IM 归因字段也能伪造。编辑时mergeIssueEdit(issues.go:416)会用服务端副本覆盖,没有这个问题。 - 复现步骤:
PUT /api/issues {"projectId":"welcome","title":"forge-test","operations":[{"actor":"ceo","actorChannel":"dingtalk","actorSender":"boss","actorSenderName":"老板","action":"create","detail":"forged"}]},返回里保留了伪造的那一条,详情抽屉里按真实 IM 记录展示(见截图)。在 main lane 上同样的请求也会保留伪造的actor。 - 位置:
internal/httpapi/issues.go:348-349(!found分支直接在客户端的v.Operations上追加)。 - 建议:新建时先
v.Operations = nil,再recordIssueOperation。
P3-4 小问题(nit)
botChatActor.Label()(internal/httpapi/bot_chat_actor.go:65)没有任何调用方,是死代码,建议删除或用起来。DELETE /api/platform/public-url会写入updatedAt,但清空了updatedBy,看不出是谁清除的(platform_public_url.go:88,传入的 actor 是"")。清除之前也没有二次确认。- 环境变量为空时清除,toast 仍提示「已清除,改回使用环境变量」,实际状态是「未配置」(
web/app/platform-public-url.js的clear.onclick)。
复核另一位 reviewer(crispinhu27)的结论
| 结论 | 复核结果 | 依据 |
|---|---|---|
| [P1] 原生 MCP 写操作缺少 botChatActor | 确认 | agent_tool_mcp.go:423-427;单测复现 channel="" sender=""(我用的是 issues_save,dispatch 走同一个 ctx) |
| [P1] e2e 里「Git 主机信任」ArrowRight 回到「成员账号」的断言 | 确认(具体是 webtest/tests/platform-admin.test.mjs:75,属于 platform workflow 的 core 作业,不是 e2e/ 目录) |
PR 5/6,main 6/6 |
| [P2] 「保存并启动」在群聊里记错 IM 成员 | 确认 | bot_clarify.go:883;单测复现 actorUserId=42 sender="ou_member" |
[P2] 升级前的钉钉绑定 sender_name 为 NULL,<> ? 跳过 |
确认 | 真实 MySQL 升级复现,ROW_COUNT()=0 |
| [P2] 端口 65536 被接受(200) | 确认,但建议定 P3(UI 的 type=url 会拦截,只有管理员直接调 API 才会触发) |
curl 返回 200;platform_settings.go:67 |
| [P2] 企业微信 awaiting_authorization 审批后不会重新排队 | 确认(代码层面;未实测真实企业微信) | repo/notifications.go:476、service.go:356-358、provider.go:45 |
验证
- 代码阅读:
git diff main...pr-1300,39 个文件,+1352/-71。 go vet(domain、repo、notification、botinteraction、httpapi、web):通过。go test -count=1:internal/domain、internal/repo、internal/notification、internal/botinteraction、web全部 ok。internal/httpapi有 14 个失败(浏览器、沙箱、SSH 类用例,如TestMainBotBrowserStartsAndDrivesRunBrowser、TestSSHRepositoryCheckoutAndDelivery)。在 main 上跑同一组用例,失败集合完全相同,属于本容器环境问题,与本 PR 无关。PR 新增的TestIssueOperation*、TestBotSenderName*、TestPlatformPublicURL*等全部通过。
- webtest:
node --test tests/platform-admin.test.mjs,PR 5 通过 1 失败,main 6 通过(即 P1-2)。 - 复现单测(审阅用的临时文件,已从 worktree 移除):MCP 归因缺失、保存并启动归因错误、钉钉昵称 UTF-8 截断,三项都复现。
- 真实部署(PR lane,
http://127.0.0.1:18100,MySQL 8.4,AGENTFLOW_PUBLIC_URL=http://127.0.0.1:18100):- AutoMigrate 建好了
platform_settings(id, payload json, updated_at),bot_user_bindings和bot_interactions也加上了sender_name。 - 用 main 的 schema 升级到 PR,复现了 P2-2。
- 管理员 GET:
source=env,带回环地址提示。 - 保存
https://LoopForge.Example.com/后规范化为https://loopforge.example.com,source=settings,页面提示环境变量已被覆盖,并显示最后修改人。 - 无效输入返回 400:
ftp://、javascript://、http://0.0.0.0、/path、u:p@、?x=1、169.254.169.254。 - 回环地址
http://localhost:18100、http://[::1]:80:200,带 warning,toast 也会提示。 :65536、:99999999、:0、末尾冒号:200(P3-1)。- 普通成员 member1 的 GET、PUT、DELETE 都返回 403;未登录 401;没有 Origin 或跨源的 PUT 都是 403;POST 405。
- 保存后
POST /api/notification-preview里的链接立即变成https://lf-review.example.com/#/runs/example,无需重启。main lane 上同样的请求仍是环境变量地址,而且 main 上没有这个接口(404)。 - 平台管理 tab 的键盘导航在真实浏览器里正常(P1-2 的说明)。
- AutoMigrate 建好了
- 未实测:真实的企业微信、飞书、钉钉收发,包括绑定链接送达、850002/851009/853006 的真实返回和审批后的恢复,以及钉钉回调里的 senderNick。
截图
Robert0622
left a comment
There was a problem hiding this comment.
Review:feat(im) 聊天发起人记入需求操作日志 + 平台管理「外部访问地址」(复审)
结论:✅ 通过(Approve)
审阅的 head:576324a3bec237188b5f02f9a0ad0be4557447fa(新提交 fix(im): address audit and public URL review feedback;上一轮审的是 32b6b709)
上一轮我和 crispinhu27 提的 2 个 P1、4 个 P2 都修好了,P3 也基本都处理了。我逐条看了代码,在真实 MySQL 8.4 上部署跑了一遍,没有发现新的阻塞问题。
上一轮问题逐条复核
| 问题 | 状态 | 依据 |
|---|---|---|
P1 原生 MCP 写入没带 botChatActor |
✅ 已修 | agent_tool_mcp.go:427-429 从 session.ctx 恢复 actor。TestAutoModeStartsRecordTheChat 现在通过真实的 /internal/agent-tools/<token>/mcp 网关调用 issues_save 和 issues_dispatch,并断言 ActorChannel=wecom、ActorSender=new-wecom-user。反向验证:删掉这 3 行后,用例失败,报 create audit attribution = {... ActorChannel: ActorSender: ...} |
P1 platform-admin.test.mjs 因第 5 个 tab 失败 |
✅ 已修 | node --test tests/platform-admin.test.mjs:9/9 通过(新增了外部访问地址 tab 的用例) |
| P2 群聊「保存并启动」记成了发起澄清的人 | ✅ 已修 | botClarifySave 不再用 StarterSender 覆盖 actor。文本命令沿用 generateBotReply 放进去的当前发送者,卡片路径在 botClarifyCardAction 里用 item.SenderID 设置。TestChatClarificationStartAttributesTheSavingMember 通过。反向验证:去掉卡片路径那一行后,用例失败,报 dispatch attribution = {... ActorChannel: ActorSender: ...} |
P2 升级前绑定行的 sender_name 是 NULL,名字写不进去 |
✅ 已修 | 条件改成了 (sender_name IS NULL OR sender_name <> ?)。真实 MySQL 8.4.7 升级实测:先用 main 二进制建库并插入一条旧绑定,再让 PR 的 repo.Open() 做 AutoMigrate,得到 sender_name IS NULL = 1。之后调 NoteBotSenderName("张三"),读回 "张三" ✅ |
P2 awaiting_authorization 审批后不会自动恢复,和文案不一致 |
✅ 已修(选了「改文案」方案) | 851009 去掉了「审批通过后自动恢复」。所有待授权类错误码的文案都补上了「到『机器人 → 记录 → 发送记录』点击『重试』」。我核对过前端,这条路径确实存在:bots.js 有「发送记录」tab,awaiting_authorization 状态会显示「重试」按钮 |
| P3 端口范围没有校验 | ✅ 已修 | 详见下面的实测 |
| P3 钉钉昵称按字节截断,会切坏 UTF-8 | ✅ 已修 | 入站按 rune 截断到 BotSenderNameMaxRunes=191,NoteBotSenderName 也改成按 rune 计数。真实 MySQL 实测:192 个汉字被忽略,191 个汉字正常写入,没有出现 1366 错误 |
P3 新建需求时能伪造客户端传入的 operations |
✅ 已修 | 新建时先 v.Operations = nil。实测带伪造 actorChannel=dingtalk / actorSender=boss 的 PUT /api/issues,返回里只有服务端记录的那一条 create(actor=admin(admin)) |
P3 nit:Label() 是死代码;DELETE 不记录操作人;toast 文案不准;清除前没有确认 |
✅ 已修 | Label() 已删除。DELETE 后 updatedBy=admin。清除前会弹 afConfirm。toast 区分了两种情况:有环境变量时提示「改回使用环境变量」,没有时提示「外部访问地址未配置」 |
部署实测
环境:PR 二进制,MySQL 8.4.7,AGENTFLOW_PUBLIC_URL=http://127.0.0.1:18100;另起一个不设环境变量的实例用来对比。
- 端口校验(API):
:65536、:99999999、:0、https://host:、http://[::1]:都返回 400,提示「端口必须为 1 到 65535」。:443、:8443、http://[2001:db8::1]:8090返回 200。HTTPS://LF-Review.Example.com:8443/被规范化成https://lf-review.example.com:8443。 - 校验失败时保留原值:先保存
https://lf-review.example.com,再 PUT:65536,返回 400,GET 拿到的仍是原地址。 - 页面(Chromium):输入
:0能通过浏览器的 URL 校验,提交后 toast 显示「端口必须为 1 到 65535」,当前地址不变。空值被required拦下(checkValidity()=false)。点「清除」会弹出「清除外部访问地址」确认框,确认后:- 有环境变量的实例 toast 为「已清除,改回使用环境变量」;
- 没有环境变量的实例 toast 为「已清除,外部访问地址未配置」。
- 生效链路:保存后
POST /api/notification-preview生成的链接立即变成https://lf-review.example.com/#/runs/example,清除后回到http://127.0.0.1:18100/#/runs/example,不用重启。 - 权限:普通成员对
/api/platform/public-url的 GET、PUT、DELETE 都返回 403。
测试
go vet(domain、repo、notification、botinteraction、httpapi、web):通过。go test -count=1:internal/domain、repo、notification、botinteraction、web全部 ok。internal/httpapi有 21 个失败,都是浏览器、沙箱、SSH、workspace 类用例,本容器缺少运行条件。其中 14 个在同一个 base(be35aff8)的 main 上失败得一模一样。另外 7 个(TestConversationRootsFollowConversationDir、TestResolveCodeBuddyManagedInventory、TestDevServerPreviewServesWorkspaceFiles等)我在 PR 和 main 上分别单独重跑,都能通过,说明是全量并发跑时环境不稳定导致的,和本 PR 无关。- CI 全绿。和最新的 main(
177d881)试合并没有冲突,go build ./...和go vet都通过。
非阻塞的小建议(nit)
strconv.ParseUint接受前导零,https://host:0443会原样保存成:0443。浏览器能打开,只是不够规整,可以考虑用规范化后的端口重建。- 850002 原来的文案里有「重试不会解决这个问题」,现在换成了「权限恢复后到发送记录里重试」。意思没错,但授权恢复之前重试仍然会失败,可以在文案里再强调一下「先授权、后重试」的顺序。
未实测:真实的企业微信、飞书、钉钉收发(包括钉钉回调里的 senderNick,以及 850002/851009 的真实返回)。这部分由单测覆盖。
Resolve conflicts between the platform settings introduced here and the new Git HTTP host trust (aibot credentials) landed on main: - internal/httpapi/server.go: both the platformSettingsHandlers and the gitHTTPHostTrustHandlers wiring and routes, added next to each other; - internal/repo/models.go: platformSettingsRow joins the AutoMigrate list alongside main's PlatformGitHTTPHost; - web/app/workbench.js: the Git host trust tab keeps main's HTTP host panel and this branch's 外部访问地址 tab.
Robert0622
left a comment
There was a problem hiding this comment.
复审 e4b24a25(合并 main):合并本身没问题,但 CI 的 e2e 路由覆盖率卡在 84.8%,暂不 Approve
上次 Approve 的是 576324a3。这次新增的只有合并 main 的提交 e4b24a25(main 在 2ad5659b)。我按冲突解决情况、CI 和部署实测重新看了一遍。
阻塞:CI browser / platform-required 失败,e2e 路由覆盖率 84.8%,低于 85%
- 现象:browser 作业 失败在
Require registered routes to be hit at least 85%:e2e route coverage: 347/409 = 84.8% ... DELETE /api/platform/public-url PUT /api/platform/public-url FAIL: route coverage 84.8% is below 85%platform-required因此也是红的。 - 原因:本 PR 新增 3 条路由(
GET/PUT/DELETE /api/platform/public-url),e2e 只走到了 GET。main(2ad5659b)的 platform 作业是346/406 = 85.2%,PR 加上这 3 条、只覆盖 1 条,就变成347/409 = 84.8%。576324a3时 CI 是绿的,因为那时 main 上还没有 #1279 新增的git-http-hosts路由(其中 POST/DELETE 也没被 e2e 覆盖),余量还够。合并 main 之后,余量就不够了。 - 建议:在
e2e/api/50-platform.test.mjs里补一条 public-url 用例,覆盖 PUT 和 DELETE,并在track里恢复原值,避免污染共享 e2e 环境。补上后是349/409 = 85.3%。下面这段我在本机部署上跑过,✔ 1 pass:test('platform: public URL can be overridden, validated and reset by admins only', async () => { const path = '/api/platform/public-url'; const before = await get(path); track('platform public URL', async () => { if (before.stored) await put(path, { value: before.stored }, { expect: 200 }); else await del(path, { expect: 200 }); }); await put(path, { value: 'ftp://lf.example.com' }, { expect: 400 }); const saved = await put(path, { value: 'https://LF-E2E.Example.com/' }, { expect: 200 }); assert.equal(saved.value, 'https://lf-e2e.example.com'); assert.equal(saved.source, 'settings'); if (cfg.tokenB) { await get(path, asB({ expect: 403 })); await put(path, { value: 'https://b.example.com' }, asB({ expect: 403 })); await del(path, asB({ expect: 403 })); } const reset = await del(path, { expect: 200 }); assert.equal(reset.stored, ''); assert.notEqual(reset.source, 'settings'); });
合并冲突的解决是对的
git show --remerge-diff e4b24a25 显示 3 处冲突,两边的改动都保留了下来:
internal/httpapi/server.go:platformSetting和 main 的httpHostTrust两个 handler 都在,/api/platform/public-url的 3 条路由和/api/platform/git-http-hosts的 4 条路由也都在。internal/repo/models.go:AutoMigrate 列表同时包含platformSettingsRow{}和PlatformGitHTTPHost{}。web/app/workbench.js:「Git 主机信任」tab 同时显示 SSH、HTTPS 和 HTTP 三块内容,「外部访问地址」tab 照旧;loadPlatformPublicURL和loadPlatformHTTPHosts都会被调用。
部署实测(PR head e4b24a25,本机原生部署,MySQL 8.4.7 空库,AGENTFLOW_PUBLIC_URL=http://127.0.0.1:18100)
- 建表:
platform_settings和platform_git_http_hosts都建好了;bot_user_bindings.sender_name、bot_interactions.sender_name也都加上了。 - 外部访问地址(管理员):
- GET 返回
source=env,并带回环地址提示。 - PUT
https://LoopForge.Example.com/后规范化为https://loopforge.example.com,source=settings,带updatedBy。 ftp://返回 400;:65536返回 400(端口必须为 1 到 65535,上一轮的 P3 已修)。http://localhost:18100返回 200 并带 warning。- DELETE 后回到
source=env。
- GET 返回
- 权限:普通成员 GET/PUT/DELETE 都是 403,未登录 401,跨源 PUT 403。
- main 带进来的 HTTP 主机信任:
- POST
git.internal.example:8080返回 201。 - 普通成员
GET /api/git-http-hosts能看到http://git.internal.example:8080。 - 普通成员 POST 返回 403。
- 不带
If-Match的 DELETE 返回 428,带上 revision 后返回 204。 - HTTPS 主机列表正常。
- POST
- 页面(Chromium,真实登录):
- tab 依次是 成员账号 / 平台管理员 / 共享 CodeBuddy Key / Git 主机信任 / 外部访问地址。
- 「Git 主机信任」里 SSH、HTTPS、HTTP 三块都在,并且能看到刚加的 HTTP 主机;这个 tab 里没有混进外部访问地址的内容。
- 「外部访问地址」从页面保存成功,并提示「环境变量 … 已被这里的设置覆盖」。
- 键盘导航:在 Git 主机信任上按 → 到外部访问地址,再按 → 回到成员账号,按 ← 又回到外部访问地址。
- 页面没有 JS 报错。820 宽深色布局也看过。
- 单测:
go vet通过。domain、notification、botinteraction、web全部通过。webtest/tests/platform-admin.test.mjs9/9 通过。repo(真实 MySQL)和httpapi的失败与 main 在同一环境下的结果对比见下。
- 未实测:真实企业微信、飞书、钉钉的收发。这部分合并没有改动,上一轮已经审过。
repo / httpapi 的失败与本 PR 无关:同一容器、同一 MySQL 跑 main 2ad5659b,失败的是同样 24 个用例(TestMySQLGitSSHCredentialLifecycle、TestMySQLReadsObserveExternalChangesWithoutReload,以及浏览器/沙箱/SSH 类用例)。PR 和 main 的失败集合完全一致。本 PR 新增的 TestIssueOperation*、TestBotSenderName*、TestPlatformPublicURL* 等全部通过。
截图和完整记录在评审方的资料库里。按要求不往本仓库上传图片,也不开截图分支。
|
复审
本地复跑了 PR 和合并快照 |
Robert0622
left a comment
There was a problem hiding this comment.
Review(增量):#1300 dacb9565
结论:LGTM,Approve。 上一轮(e4b24a25)唯一的阻塞是 CI 红:e2e 路由覆盖率 84.8%,低于 85%,原因是 PUT/DELETE /api/platform/public-url 没有被 e2e 测到。这次的新提交补上了这两个接口的 e2e 测试,CI 现在 16/16 全绿。
- Reviewed head:
dacb9565fc5f2440f0032c2b87e0802cc317b5a6(上次评审e4b24a25)。新提交只有dacb9565 test(e2e): cover public URL settings lifecycle,改了 1 个文件e2e/api/50-platform.test.mjs(+29)。 - 和当前 main
848793b3合并没有冲突(git merge-tree干净)。
代码审阅
新用例 platform: saves and clears the external access address 覆盖了保存、拒绝非法端口和清除三个环节:
- 保存时带末尾
/,断言返回的value/stored已去掉斜杠,source=settings,envValue不变,updatedBy有值; - 端口
65536返回 400,而且之后 GET 结果和保存后完全一样(失败请求没有改动数据); - 清除后
source按部署环境回到env或none,stored为空,再 GET 结果一致; t.after会恢复到测试前的设置,不会污染共享环境。
部署实测(本机,PR 构建 + MySQL 8.4.10 空库)
| 场景 | 结果 |
|---|---|
node --test api/50-platform.test.mjs 全文件 |
13 通过 / 0 失败 / 1 跳过(跳过的那条需要真实模型,和本 PR 无关) |
| 新用例单独跑 | ✅ |
测试前先设置 https://pre-existing.example.com,再跑新用例 |
✅ 跑完后恢复成原来的地址,t.after 的恢复逻辑有效 |
普通成员 PUT /api/platform/public-url |
403 |
CI(browser / platform-required / core / e2e 等) |
16/16 通过 |
#1300 added a clarification test that expects the bot reply "已启动 SOP" and a comment that says "a SOP started". This branch already renders "已启动 LOOP", so the test failed after merging main. Co-Authored-By: Claude Code <noreply@anthropic.com>
* feat: rename SOP to LOOP across LoopForge * Apply LOOP terminology to copy merged from main and fix CHANGELOG anchor Rename the user-visible SOP copy that main added for the enterprise IM channels, observability dashboard and docs, following the same rules as the rest of this branch (routes, JSON fields and identifiers unchanged). Keep accepting the old wording where it can still arrive: notification cards skip both LOOP and SOP header lines, chat drafts recognise both (LOOP:…) and (SOP:…) notes, and the clarification command accepts "保存并启动 LOOP" as well as "保存并启动 SOP". Point the CHANGELOG link at #updating-existing-public-loops. Co-Authored-By: Claude Code <noreply@anthropic.com> * Renumber the LOOP terminology migration to 043 and re-apply the rename to main's new copy main added 042_project_credentials.sql and 042_skill_bodies_to_files.sql, so the terminology migration becomes 043_loop_terminology.sql; the installer, its test and the deployment guide follow. Rename the user-visible SOP copy from #1264, #1294, #1295, #1296 and #1298 (project roles, join requests, project credentials, workspace preview messages) with the same rules as the rest of the branch. Co-Authored-By: Claude Code <noreply@anthropic.com> * Restore the legacy (SOP:…) draft note check clobbered by the rename sweep Co-Authored-By: Claude Code <noreply@anthropic.com> * fix(chatbot): recognize proposal receipts saved before the LOOP rename Conversations saved before the rename still hold the SOP wording of the declined and timed-out proposal receipts. The chat matched only the new LOOP text, so these internal resume turns showed up as user messages. Accept both wordings. Rooms also parse LOOP「…」 authors with the correct length and keep recognizing legacy SOP「…」 authors. Co-Authored-By: Claude Code <noreply@anthropic.com> * Apply LOOP terminology to the chat attribution copy merged from main #1300 added a clarification test that expects the bot reply "已启动 SOP" and a comment that says "a SOP started". This branch already renders "已启动 LOOP", so the test failed after merging main. Co-Authored-By: Claude Code <noreply@anthropic.com> * Resume paused children marked before the LOOP rename The child-resume marker merged from #1327 now reads "等待继续子 LOOP". A parent paused on a build that stored "等待继续子 SOP" still resumes its child after admission. Co-Authored-By: Claude Code <noreply@anthropic.com> * test: cover run evaluation before approval * test: exercise five previously uncovered platform routes * fix: translate LOOP evaluation and runner allocation messages * fix(engine): name LOOP in the remaining auto-assign errors The default-executor fallback label and the no-compatible-sandbox error still said SOP after the main merge. Co-Authored-By: Claude Code <noreply@anthropic.com> * fix: name LOOP in errors merged from main Four user-visible errors that arrived with main (#1342 work branch naming, #1343/#1348 runner auto-assign, #1301 child artifacts) still said SOP. Co-Authored-By: Claude Code <noreply@anthropic.com> * fix(migrations): preserve customized LOOP template copy * test(install): copy migration 043 into the live install fixture install-schema-extensions.sh now replays migrations/043_loop_terminology.sql, but test-install-live.sh only copied 001/033/038/042 into its trimmed fixture, so every live install identity stopped at the first install with 'cat: migrations/043_loop_terminology.sql: No such file or directory'. Copy 043 as well, and add a test-install.py check that every migration the installer replays is in the live fixture's copy list, so CI catches the next one. Co-Authored-By: Claude Code <noreply@anthropic.com> * Name LOOP in comments and test copy merged from main The merge of main kept the product copy for requirements without a LOOP, but comments, test fixtures and failure messages around #1411's sopMode still said SOP. Use the LOOP terminology there too; protocol values such as sopMode none/sop and Go identifiers keep their names. Co-Authored-By: Claude Code <noreply@anthropic.com> --------- Co-authored-by: roberttwang <roberttwang@tencent.com> Co-authored-by: roberttwang <u_dc6754cd1ee5@users.noreply.local> Co-authored-by: Claude Code <noreply@anthropic.com> Co-authored-by: Codex <codex@users.noreply.github.com>









本 PR 含两部分,针对的是企业 IM 渠道上两个互相挡路的问题:聊天建的需求查不到是谁发起的,以及没配对外访问地址时 Bot 连绑定链接都生成不了(后者会直接挡住前者的验收)。
ec1e4aa、f51a4f5)32b6b70)两部分只在
internal/botinteraction/inbound.go和internal/httpapi/bot_drafts.go有文件重叠,改的是不同位置,无语义冲突。第一部分:把聊天发起人记入需求操作日志
问题
从企业微信、飞书、钉钉的 Bot 创建需求或触发 SOP,执行用的是发送者绑定的平台账号,但需求的操作日志里只有这个账号:
bot_chat_origins里,那张表的职责是把运行事件路由回原会话,SenderID标的是json:"-",没有任何接口或页面读它。改动
1. 操作日志记录 IM 身份
domain.IssueOperation新增三个字段:ActorChannelwecom/feishu/dingtalk)ActorSenderActorSenderNameActor语义不变,仍是「实际用谁的权限执行的平台账号」。平台页面上的操作三个字段都为空。2. 身份通过请求上下文传递
新增
botChatActor(internal/httpapi/bot_chat_actor.go),挂在内部平台调用的 request context 上,和requestUserContextKey并列——mcpserver.LocalInvoker会把 ctx 透传进内部请求,所以 handler 侧读得到。没有复用
BotChatOrigin:那个结构负责通知路由、缺 channel、且要求会话行存在;这里只做归属标注,在聊天轮次的每条写入路径上都设。注入点覆盖三条写入路径:
bot_interactions.gogenerateBotReplybot_drafts.goexecuteBotDraftbot_clarify.gobotClarifySavecreate/update/dispatch都走recordIssueOperation这一个函数,所以三个动作一次覆盖。3. 发送者显示名
只有钉钉的回调自带
senderNick,映射到InboundEvent.SenderName并随互动记录持久化;之后缓存到绑定上,因为同一发送者后续的动作不再带名字(卡片点击、网页确认、澄清后启动 SOP)。解绑时和其余身份信息一起清掉;空名字不会覆盖已存的名字。企业微信和飞书的机器人回调只给发送者 ID,凭据也是机器人维度的,所以不为它们编造名字:这类发送者继续由绑定的平台账号来指名(账号本身带中文名,日志里已经显示)。新增的列就是以后接通讯录查询时的落点,不用再改一次 schema。
顺带两处可读性改进:节点审批 / 重试 / 回答的运行决策备注里,发送者 ID 后面补上已知姓名;飞书、钉钉的通知接收人选择器在知道姓名时显示姓名而不是打码 ID。
4. 前端
需求详情的操作日志:聊天发起的条目显示
钉钉 张三(staff-1)(平台账号 xxx),企业微信显示企业微信 wangxx(平台账号 roberttwang(王某)),平台操作显示不变。迁移
只新增列,由
repo.Open()的 gorm AutoMigrate 补齐,无需数据迁移脚本。测试
新增
internal/httpapi/bot_issue_attribution_test.go(7 例)和internal/botinteraction/sender_name_test.go(2 例):wecom/new-wecom-user,Actor仍是绑定账号ActorSenderName="张三"senderNick到事件和互动记录;企业微信事件确实不带姓名每个关键断言都做了反向验证(临时打断链路确认用例会红),不是空跑。
go test ./internal/httpapi ./internal/domain ./internal/repo ./internal/botinteraction ./internal/notification ./web通过。internal/httpapi里有若干 workspace / 沙箱用例在本环境失败(缺bwrap、web/native-chat是 gitignore 的构建产物),已用git stash在干净 main 上复跑确认与本次改动无关。gofmt、go vet干净。第二部分:平台管理里配置外部访问地址
问题
平台的对外访问地址只能在启动时从
AGENTFLOW_PUBLIC_URL读一次。部署时没设的话,没有任何补救办法:要修只能改
.env再重启。改动
1. 平台管理 → 外部访问地址
新增分区,管理员填一次存库。页面设置优先于环境变量,这样页面永远能纠正部署时的错配或漏配;同时页面标注当前生效来源,并显示被盖掉的环境变量值,避免「我改了 env 怎么没生效」。
2. 为此需要一个 resolver
Service.PublicURL原本是启动时读一次 env 的字符串,还被再拷一份进botIdentityHandlers,所以运行时改不动。Service.PublicAddress():先查库里保存的值,再回落到环境变量;notification/service.go、push.go、httpapi/notifications.go、httpapi/bot_drafts.go);botIdentityHandlers.publicURL从string改成func() string。单行主键查询,调用方都是 IM 事件级频率,所以不加缓存,省掉缓存失效的复杂度。
3. 「自动识别」怎么做的
页面上的「填入当前访问地址」取的是管理员浏览器自己的
location.origin,不读也不信任服务端收到的Host头。这点是刻意的:这个地址会被拼进带一次性 token 的绑定链接,并引导用户去那里登录平台。来源可伪造就等于一条钓鱼链路。所以没有做「运行时从请求头自动学习」。
校验规则照搬
scripts/install-address.py:86-95已有的那套,保证安装器和页面接受完全相同的值:拒绝 userinfo / query / fragment / 路径、拒绝0.0.0.0和链路本地地址。回环地址保存但附警告而不是拒绝——它是本机联调会用的,但发到手机上点不开。另外校验会把 scheme 和 host 规范化成小写(
HTTPS://X→https://x),因为这个值要被拼进链接。这是写测试时发现的。4. 顺带:让授权类报错说清下一步
这几条是实际踩坑时把人引向错误方向的提示:
no authorization)原先掉进兜底文案「请检查机器人授权或稍后重试」,而且没被计入awaiting_authorization,所以 Bot 在管理页显示成笼统的error,「重试一下」看起来很合理——但这个码重试一万次也一样。现在明确说是机器人的「消息」能力授权没给、该由谁去哪里授权、以及重试不解决问题。awaiting_authorization的判定收敛成一个awaitingAuthorization()谓词,健康状态和发送失败两条路径共用。853006 故意不算在内——没有任何授权能解决它,算进去会让人一直等一个等不到的审批。迁移
只新增一张表,由
repo.Open()的 gorm AutoMigrate 补齐,不需要迁移脚本。测试
新增 4 个测试文件:
internal/domain/platform_settings_test.goUsablePublicURL、长度上限internal/httpapi/platform_public_url_test.goPublicAddress()和绑定链接立刻生效(resolver 的真正验收点)internal/repo/platform_settings_test.gointernal/notification/wecom_authorization_test.goawaitingAuthorization();853006 不算待授权;未知码保持兜底反向验证做了两处,确认测试在测链路不是空跑:
PublicAddress()的查库分支 →TestSavedPublicURLAppliesWithoutRestart报address after saving = "";TestPublicURLRequiresPlatformAdmin报GET as a plain member = 200。回归对比:
go test ./internal/httpapi在改动前后的失败用例名完全一致(12 个,均为本环境缺bwrap、以及web/native-chat是 gitignore 的构建产物所致),用git stash在干净 main 上复跑确认。./internal/domain、./internal/repo、./internal/notification、./internal/botinteraction全绿。gofmt、go vet干净。合并后的整体验证
go test ./internal/httpapi在本分支与干净main的失败用例名逐字一致(12 个,均为本环境缺bwrap、以及web/native-chat是 gitignore 的构建产物所致),用git stash复跑确认。两部分各自的测试在合并后同时通过,共 17 例:
./internal/domain、./internal/repo、./internal/notification、./internal/botinteraction、./web全绿;gofmt、go vet干净。两部分都只新增列或新增表,由 AutoMigrate 补齐,不需要迁移脚本。