Skip to content

fix(assistant): carry bound SOP context and clarify intent on issue handoff - #1349

Merged
newexploreor merged 4 commits into
mainfrom
diagnose_issue_prompt
Nov 26, 2026
Merged

newexploreor merged 4 commits into
mainfrom
diagnose_issue_prompt

Conversation

@newexploreor

Copy link
Copy Markdown
Collaborator

背景与问题

用户在新建需求时已经选择了「按 SOP 交付」及具体 SOP 流程,点击 「创建并去对话澄清」 进入 AI 工作台后,助手仍会反问交付方式(例如让用户在「直接在工作区实现 / 派发 SOP / 调整描述 / 仅查看状态」之间选择)。

原因有两处:

  1. 后端 @需求 上下文未透传 SOP 绑定信息:workbenchReference(case "issue")只返回了 id/title/description/status/projectId/repositoryId/repositoryIds,遗漏了 workflowId、sopMode、sopBindings 等;workspaceTurnContext 也只写了 没跑过 SOP,模型无从得知该需求已经绑定了哪条 SOP。
  2. 前端「创建并去对话澄清」未透传澄清意图:交接时只在输入框预填了 @<需求标题> ,用户直接发送后模型仅看到裸 @需求,且受系统提示词约束不敢主动推进。

修改内容

  • 后端(internal/httpapi/assistant_workbench.go)
    • workbenchReference(case "issue")新增透传 workflowId、boundSops(解析 SOP 名称)、sopMode(不使用 SOP 时为 "none")和 baseBranch,首轮 @需求 与后续轮次「会话主需求」统一生效。
    • workspaceTurnContext 在需求运行状态后补充 已绑定 SOP:名称(id) 或 交付方式:不使用 SOP,并增加明确指引:需求已绑定 SOP 时不再反问交付方式;用户只 @ 需求或要求澄清时直接围绕需求内容梳理边界条件与验收标准,清晰后提示更新需求或按已绑定 SOP 派发;标记为不使用 SOP 的需求默认围绕澄清与对话工作区直接实现协作。
  • 前端(web/app/composer.js、web/app.js、chatbot/src/App.jsx)
    • 「创建并去对话澄清」调用 openIssueInChat(issue, { intent: 'clarify' }),经 URL(mentionIntent=clarify)和 postMessage 传递澄清意图(普通「去对话」入口行为不变)。
    • chatbot/src/App.jsx 识别 clarify 意图后自动预填 @<需求标题> 帮我澄清这个需求,并在完成后清理 URL 参数 mentionIntent。

验证

  • npm --prefix chatbot run build
  • npm --prefix chatbot test -- tests/app-render.test.jsx(41/41 通过,含新增 mentionIntent=clarify 用例)
  • go test ./web -run "TestIssueBaseBranchComposer|TestRequirementDirectCreateUI|TestNativeChat" -v
  • go test ./internal/httpapi -run "TestFirstTurnMentioningAnIssueLinksItAndStarts|TestTurnRefusesAConcurrentIssueRebinding|TestIssueReferenceAndTurnContextIncludeBoundSOPAndDeliveryMode|TestWorkbenchReferencesAreScopedAndRolesBecomeSubagents|TestProjectParticipantOpensAndSwitchesSharedWorkspace|TestConversationSandbox|TestRequirementWithoutSOP" -v

Robert0622
Robert0622 previously approved these changes Nov 25, 2026

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CR + 部署实测:LGTM ✅(head d6f4706)

本机按 PR 分支编译部署了一套平台(MariaDB 11.8 + CodeBuddy CLI 2.187.0,模型 deepseek-v4.1-flash),同时部署了一套 main 058a530 做对照。项目绑定的是一个私有测试仓库,没有拿 Tencent/LoopForge 做实测对象。

实测场景与结果

# 场景 main 058a530 本 PR
1 真实 UI:新建需求 → 按 SOP 交付,选「前端交付」,绑定仓库,继续开发分支填 aicb/payment-timeout-retry → 点「创建并去对话澄清」 输入框只预填 @<标题> 输入框预填 @<标题> 帮我澄清这个需求(走 postMessage)
2 直接打开 /chatbot/?mentionIssue=…&mentionIntent=clarify(走 URL 参数) — 预填澄清语,之后 URL 里 mentionIssue 和 mentionIntent 都被清掉
3 不带 intent 的普通「去对话」 @<标题> 不变,仍是 @<标题> ,没有误加澄清语
4 UI 发送场景 1(deepseek-v4.1-flash) — 28 秒回复。开头就说「已绑定『前端交付b』SOP」,接着给出口径、字段、权限、异常和验收标准,结尾是「补全后直接按已绑定的『前端交付b』派发」。没有反问交付方式
5 API:单 SOP 需求,追问「这个需求应该怎么交付?」 建议改绑「后端交付b」,不用当前的「前端交付b」(这就是本 PR 要修的问题) 先补口径,再按已绑定的「前端交付b」派发,没有要求重新选交付方式
6 API:两段 SOP 链(前端 → 后端) 澄清正常 识别出两个 SOP,说「按前端 → 后端的顺序派发」
7 API:sopMode=none 的需求 澄清正常,提到「无法派发执行」 围绕澄清给出验收标准,最后提议「在本对话工作区直接改」,没有建议改走 SOP
8 后续轮次不带 @ — 会话 issueId 已关联,追问时上下文里仍有已绑定的 SOP(见场景 5)

截图(PR 分支):

新建需求弹窗(已选 SOP、仓库和继续开发分支):
modal

点「创建并去对话澄清」后的预填 —— main 和 PR 对比:
main-prefill
pr-prefill

deepseek-v4.1-flash 的真实回复:
pr-reply

本地测试

  • scripts/build-chatbot.sh:vitest 62 个文件、532 个用例全部通过(含新增的 mentionIntent=clarify 用例)
  • go vet ./internal/httpapi ./web 通过;go test ./web 通过
  • go test ./internal/httpapi:跑了 Mention、Assistant、Workspace、Sandbox 相关的一组用例,新增的 TestIssueReferenceAndTurnContextIncludeBoundSOPAndDeliveryMode 和 TestFirstTurnMentioningAnIssueLinksItAndStarts 都通过。只有 TestNestedSOPWorkspaceReviewAndRestore 和 TestWorkspacePreparationAPISeparatesReadersAndWriters 失败,原因是容器里 bwrap 不能创建 user namespace,main 上同样失败,跟本 PR 无关
  • 合并后的代码跑 go test ./internal/engine,失败的都是 bwrap / 工作区准备类用例,main 78cdab4 上同一批用例也失败(同样是环境原因),本 PR 没有改 engine
  • 本地把本 PR 和最新 main 78cdab4 合并,没有冲突,可以编译;上面那组 httpapi 用例和 main CI 上失败的 TestChatClarificationInAGroup 在合并后的代码上都通过

关于 CI 红

两项失败都来自 base 058a530,不是本 PR 引起的:

  • core:internal/engine/sop_executors_test.go 里 selectSOPExecutionTarget 参数不够,编译失败。这是 #1339 和 #1291 一起合入后 main 上本来就有的问题,main 78cdab4 已经修好。
  • browser:路由覆盖率 350/412 = 84.95%,低于 85%。本 PR 没有新增路由,base 上也是同一个数,main 78cdab4 的 browser 作业已经是绿的。

建议点一下 Update branch 同步最新 main 再跑一次 CI。

非阻塞建议(P3)

  1. workbenchReference 里的 workflowId 取自 v.WorkflowID,boundSops 取自 EffectiveSOPBindings(),两个字段来源不同。我用 POST /api/issues 只传 sopBindings、不传 workflowId 建单时,存下来的 workflowId 是项目默认的 generic-backend-delivery,而绑定的是 wf-fe-b → wf-be-b。这样 @需求 的上下文里会同时出现 workflowId=generic-backend-delivery 和 boundSops=[前端, 后端]。这次 deepseek-flash 没有被误导,但建议有 bindings 时 workflowId 取 bindings[0],或者干脆不输出 workflowId,只保留 boundSops。UI 建单会同时传 workflowId,所以 UI 流程不受影响。
  2. 预填的「帮我澄清这个需求」是写死的中文,英文界面下也是中文。目前 chatbot 本身也没做 i18n,可以以后统一处理。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CR + 部署实测(增量):新提交和 main 冲突,需要先解决(head fb14906)

这次只多了 fb14906a(fix(ci)),只改了两个测试文件。功能代码和上一轮 Approve 的 d6f47063 相同。现在 PR 显示 This branch has conflicts,CI 没有跑起来(只跑了开源扫描),所以这次先评论,不 Approve。

冲突原因

fb14906a 修的两处 CI 问题,main 已经用别的写法修过了(058a530b..832e2bef 之间合入的 #1342、#1343、#1301、#1348),两边改了同一批行:

  1. internal/engine/sop_executors_test.go:三处 selectSOPExecutionTarget(&execution, …),main 传 true,PR 传 false。建议用 main 的 true。线上 SOP 运行走 run_start.go:186 的 selectSOPExecutionTarget(&executionContext, !workspace),非工作区运行就是 true,测试应该测这条路径。
  2. e2e/api/69-assistant-sessions.test.mjs 的 generation endpoints answer for an idle conversation:main 已经改成 path 变量,加了 post/newId 写法和报错文案断言,steer 和 diagnostics 两条也已经覆盖。建议以 main 为准,只把 PR 新增、main 里还没有的 3 条覆盖补到末尾:
  await post(`${path}/read`, {}, { expect: 400 });
  await post(`${path}/read`, { generationId: newId('missing-generation') }, { expect: 404 });
  await post(`${path}/native-approvals/${newId('missing-approval')}`, { decision: 'approve' }, { expect: 404 });

按上面方式解冲突后的本机实测(PR + main 832e2be)

本机编译部署了合并后的版本和 main 各一套(MariaDB 11.8,AGENTFLOW_AUTH_REQUIRED=true)。项目用的是本地一次性测试仓库,没有用 Tencent/LoopForge 做测试对象。

项 结果
e2e/api/69-assistant-sessions.test.mjs(含上面补的 3 条) 11/11 通过,/read 返回 400/404,native-approvals/:id 返回 404,符合预期
API e2e 全量 合并版本和 main 一样:186 个用例中 164 通过、16 跳过、4 失败。4 个失败都在 35-runner-mode,main 上是同样 4 个,属于本机环境问题,与本 PR 无关
路由覆盖(只跑 API e2e,没跑 UI 套件,所以比 CI 低) 合并版本 335/416,main 334/416,比 main 多 1 条
go vet ./internal/engine + go test ./internal/engine -run TestExecutorCredentials 合并版本和 PR head 上都通过
go test ./internal/httpapi -run 'TestIssueReferenceAndTurnContextIncludeBoundSOPAndDeliveryMode|TestFirstTurnMentioningAnIssueLinksItAndStarts|Mention' 通过
chatbot vitest 62 个文件、534 个用例全部通过
go test ./web 通过
真实模型冒烟(CodeBuddy deepseek-v4.1-flash):需求绑定「前端交付s」后,发 @需求 这个需求应该怎么交付? 29 秒完成。会话已关联这个需求,回复开头就说「已绑定 SOP『前端交付s』…交付路线本身是定好的:走这条 SOP 派发即可」,没有建议改绑「后端交付s」

需要作者做的事:按上面方式解冲突(或 Update branch 后同样处理),推上来让 CI 跑一遍。功能部分上一轮已经实测通过,解完冲突、CI 绿了就可以批。上一轮的两条 P3 建议还在(只传 sopBindings 时 workflowId 和实际绑定不一致;预填澄清语写死中文),不阻塞。

yowucai added 2 commits November 26, 2026 14:33
# Conflicts:
#	e2e/api/69-assistant-sessions.test.mjs
#	internal/engine/sop_executors_test.go
#	internal/httpapi/assistant_workbench.go
#	web/app/composer.js
#	web/syntax_test.go

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CR + 部署实测(增量):#1349 02ba4286 — LGTM,Approve

上一轮只评论没批,是因为和 main 有冲突、CI 没跑。现在冲突解决了,CI 全绿,在真实部署上复测也通过。

  • Reviewed head:02ba4286。上次评审的是 fb14906a,这次新增 f079c75e(合入 main c039a78a)和 02ba4286(composer-flow.test.mjs 补上了 intent: 'clarify' 的断言,修好了 f079c75e 上 core job 的失败)。
  • 冲突的处理方式和上一轮建议的一样:sop_executors_test.go 用 main 的写法(非工作区路径传 true),69-assistant-sessions 以 main 为准。PR 和 main 相比只剩 9 个功能/测试文件(+276/−33)。
  • CI:16 个检查全绿。和最新 main 39e39eb9 用 git merge-tree 检查,没有冲突。
  • 测试方式:本机真实部署。Go 1.26.11,MySQL 8.4.7 空库,AGENTFLOW_AUTH_REQUIRED=true。对话用 CodeBuddy CLI,CLI 入口把模型强制改成 deepseek-v4.1-flash(日志能看到 claude-sonnet-5 被改写)。页面用 Chromium(Playwright)实际点击。

实测

场景 结果
需求向导写两行描述,选「不使用 LOOP」,点「创建并去对话澄清」 新建的需求 sopMode=none,自动切到协作页,输入框预填 「@订单列表支持按日期筛选 帮我澄清这个需求」 ✅
对话已打开时,调用 openIssueInChat(issue,{intent:'clarify'}) 输入框变成「@列表页导出 CSV 帮我澄清这个需求」,iframe 没有重新加载 ✅
冷启动 URL ?mentionIssue=…(不带 intent) 输入框是「@列表页导出 CSV 」,URL 里的参数被清掉 ✅
冷启动 URL ?mentionIssue=…&mentionIntent=clarify 输入框是「@列表页导出 CSV 帮我澄清这个需求」,mentionIssue / mentionIntent 都被清掉 ✅
真实模型:需求绑定了「前端交付s」,发送上面的澄清语 22 秒回复,直接按导出范围、字段、数据量、权限、交互、文件格式给出澄清点,开头写「走前端交付之前有几处必须先定下来」,没有反问「直接改代码还是走 LOOP」。追问一句后回复「交付方式按这条需求已绑定的「前端交付s」LOOP 执行」 ✅
全程 pageerror / console.error / 4xx·5xx 0 ✅

创建并去对话澄清:预填澄清语
真实模型回复:按已绑定 LOOP 澄清

自动化测试(本机)

  • webtest:315 个用例全部通过(包括 创建并去对话澄清…);chatbot vitest:62 个文件、536 个用例通过;vite build 通过。
  • go test ./internal/repo ./internal/schedule ./web 通过;./internal/httpapi(bwrap 替身)通过。环境问题导致的失败和 main 上一样。

上一轮的两条 P3(只传 sopBindings 时 workflowId 和实际绑定不一致;预填的澄清语写死了中文)还在,不阻塞。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LoopForge PR Review — head 02ba4286

Conclusion: Pass ✅

#1349 fix(assistant): carry bound SOP context and clarify intent on issue handoff

上一轮()已 COMMENTED,本轮新增提交只有 ( +10/-2):为「创建并澄清」聊天交接补了 断言,以及冷启动时 的 URL 参数断言,不涉及任何生产代码。

本机 无告警,CI 全绿(browser / core / e2e 全 pass)。

可合入。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

CR + 部署实测(增量):功能没问题,CI core 被 PR 自己的改动弄红了,需要改一个测试(head f079c75)

上一轮(fb14906a)只评论、没有批准,原因是和 main 冲突。这次的 f079c75e 合入了 main c039a78a,冲突按上一轮的建议处理:e2e/api/69-assistant-sessions.test.mjs 和 internal/engine/sop_executors_test.go 现在和 main 完全一致(selectSOPExecutionTarget(..., true));assistant_workbench.go 保留了 PR 的 if ok { … } 结构,文案是 LOOP;测试断言里的「已绑定 SOP」也已改成「已绑定 LOOP」。这部分没问题。

阻塞:webtest/tests/composer-flow.test.mjs 失败(PR 引起)

CI core 中的 Browser-free UI tests 报 # fail 1,失败的是 not ok 60 - 创建并去对话澄清 creates the issue and opens a new chat with the requirement @-mentioned。platform-required 失败是因为它依赖 core。

原因:PR 让 createIssueFromChat 在 toChat 时调用 openIssueInChat(issue,{intent:'clarify'}),pendingChatIssueMention 和 postMessage 的内容多了 intent: 'clarify',但这个测试的两处 deepEqual 还是旧的期望值。我在本机复现了:PR 分支 3/4 通过,main 4/4 通过。按下面的改法改完后 PR 分支 4/4 通过,webtest 全量除了这个用例都通过(314/315)。

--- a/webtest/tests/composer-flow.test.mjs
+++ b/webtest/tests/composer-flow.test.mjs
@@ -146,11 +146,11 @@
-  assert.deepEqual(JSON.parse(JSON.stringify(app.evaluate(`pendingChatIssueMention`))), { issueId: 'issue-chat', projectId: 'project-1' });
+  assert.deepEqual(JSON.parse(JSON.stringify(app.evaluate(`pendingChatIssueMention`))), { issueId: 'issue-chat', projectId: 'project-1', intent: 'clarify' });
@@
-  assert.deepEqual(posted[0], { type: 'agentflow-chat-mention-issue', issueId: 'issue-chat', projectId: 'project-1' });
+  assert.deepEqual(posted[0], { type: 'agentflow-chat-mention-issue', issueId: 'issue-chat', projectId: 'project-1', intent: 'clarify' });

同一个用例后面 openIssueInChat({id:'issue-next',…}) 那段没有传 intent,期望值不用改。

部署实测(CodeBuddy deepseek-v4.1-flash,PR f079c75e 对比 main c039a78a)

两边都建了两条需求:一条绑定了「前端交付c → 后端交付c」两个 LOOP,一条是 sopMode=none。在关联该需求的会话里问「要不要建议我改走 LOOP、你打算怎么交付」:

需求 main PR
已绑定 2 个 LOOP 回答「建议走」,把绑定当成待决定的事,还提议可以改走产品类 LOOP 回答「不需要建议,它已经在 LOOP 上了」,按已绑定的 LOOP 依次交付,只追问数据来源,确认后 issues_save 再派发
sopMode=none — 回答「不建议」,说明需求已标记不使用 LOOP,按对话澄清并直接改代码,仓库为空时要求先绑定仓库

非阻塞,供参考:PR 侧回答「先跑后端交付c,再做前端交付c」,和绑定顺序(前端 → 后端)相反。这是因为测试数据里两个绑定的 order 都是 0,存储时 workflowId 是 wf-be,模型可能把 workflowId 当成了首个。这和上一轮提的建议是同一个问题:有 bindings 时 workflowId 取 bindings[0],或者干脆不输出 workflowId。

其他测试:go vet ./internal/httpapi ./web 无输出;TestIssueReferenceAndTurnContextIncludeBoundSOPAndDeliveryMode 等 5 个 turn-context 测试通过;go test ./web ok;chatbot 536/536 通过。

把上面这个测试改掉、CI 变绿后就可以 Approve。

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.

2 participants