Skip to content

[v2] workflow skill start preflight, personal skill visibility hints, and starter/retry tests - #437

Open
wanglongan587 wants to merge 5 commits into
ora-space:mainfrom
wanglongan587:feat/1391-workflow-skill-preflight
Open

wanglongan587 wants to merge 5 commits into
ora-space:mainfrom
wanglongan587:feat/1391-workflow-skill-preflight

Conversation

@wanglongan587

@wanglongan587 wanglongan587 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

v2,不涉及 specs(phase:1,仅变更 v2-server/ 与 frontend-v2/)。

Refs ora-space/circus#1391

  • Skills 启动时整图预检(v2-server & frontend-v2):
    • 新增 Graph.SkillReferences(),收集冻结图中根图、Iteration 区域成员与全部 Loop 体内已启用 Agent 节点的 skills(排除禁用绑定与备用节点,空白节点标题回退节点 ID)。
    • store.ResolveWorkflowSkills 区分缺失/未下发技能(MissingWorkflowSkillError / ErrSkillNotFound)与底层数据库错误;workflowhost.Host.StartRun 在发起首波调度前按启动者身份与目标项目整图预检角色与技能,缺技能返回 400 workflow_skill_not_found(params 携带 nodeId、nodeTitle、skillId),运行保持 pending 且不启动会话,补齐技能后同一运行可直接启动;启动后删除或移除技能时节点失败且可续跑;运行中途读取技能遇到数据库故障时记为 FailureSession(交互节点转为 FailureInteractiveSession)并使用通用提示,不再误报为 missing_agent_config 或泄漏 SQL 细节。
    • 拆分入口(internal/taskdecomp + main.go):将 WorkflowSkillNotFound、ErrWorkflowRoleNotFound、ErrWorkflowRunNotStartable 映射为本地化失败原因,对内部/数据库错误返回安全通用提示而不写入 SQL 细节,并在启动被拒后通过 runs.Cancel 取消挂起的 pending 运行。
    • 任务处理、评论 @ 工作流与定时工作流同步映射 workflow_skill_not_found:定时适配器将缺角色 / 缺技能 / 不可启动(含 WorkflowRunInputInvalid)分别记为 skipped 原因 workflow_role_not_found / workflow_skill_not_found / workflow_run_not_startable,手动「立即运行」返回 400 携带 params.occurrenceId。
    • 前端修复 localizeContractError 对运行态文案包(workflowRunTranslations)的解析并本地化 workflow_skill_not_found(按节点与技能展示明细,无明细时回退通用提示),同步对齐运行页、协作页与定时任务页。
  • 个人 Skill 发起人读取与团队可见提示(frontend-v2):
    • 更新工作流编辑器检查器提示为「运行时读取发起人同名的个人 Skill,其内容在节点会话中对团队可见。」。
    • 新增共享检测与文案模块 src/lib/workflows/personal-skills.ts,在工作流创建/启动对话框、任务处理/拆分/评论 @ 工作流及定时任务表单中,对启用了个人 Skill 的工作流同步展示同一可见性提示;兼容备用节点非法或非数组的 skills 配置并按 enabled !== false 对齐后端语义。
  • 回归测试补齐(v2-server & frontend-v2):
    • 补齐 Iteration 成员、Loop 体与整图预检、插件技能库故障(store 与 workflowhost)、中途中止/数据库错误精确通用提示、同工作流 @ 恢复与拆分启动拒绝取消测试。
    • 补齐 startedBy / startedByName 在 FinishWorkflowRun(成功/失败)、CancelWorkflowRun 及真实 workflowhost 定时触发路径下保持一致的直接测试。
    • 补齐重试失败块在 agentPrompt 中位于 <required_skills> 之后、<structured_output_contract> 之前的顺序断言,以及 agent_refusal 保留节点 output 但在注入重试提示时丢弃回答的正反对照测试。

Verification

  • v2-server: gofmt -l ., go vet ./..., demo-link check, go test -race -count=1 ./internal/workflow ./internal/store ./internal/workflowhost ./internal/scheduler ./internal/taskdecomp ./internal/server .
  • frontend-v2: npm run api:check:* (all 14 OpenAPI specs), npm run typecheck, npm run lint (oxlint --deny-warnings), vitest (127 files / 1130 tests), npm run build, npm run demo:check

@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.

需要修改(b2940aa)

@wanglongan587 我看了这个 PR,理解它是要在首次调度前按发起人和目标项目校验冻结图中的 Skill,在各启动入口提示个人 Skill 的团队可见性,并补齐发起人持久化和重试提示词的回归测试。有 1 处合并前需要改,其余都是建议。

合并前先修复个人 Skill 提示对备用节点配置的处理。一个后端允许发布的备用节点就能让运行页崩溃,阻止用户启动工作流。拆分和手动触发定时任务的拒绝反馈也需要补齐。

  • ❗ P1-1(合并前需要改):备用节点的 Skill 配置会让运行页崩溃(见行内)
  • 📌 建议另开 PR 处理:P2-2 拆分入口会把 Skill 查询故障写入公开记录(不影响这次合并)
  • 💬 其他建议:P2-1 手动触发计划时缺 Skill 会返回 500
  • 测试:go test -race -count=1 -v ./internal/workflowhost ./internal/server ./internal/scheduler ./internal/store -run 'Test(WorkflowFreezesSelectedSkill|StartRefusesASkill|SkillDeletedAfterStart|SkillLookupDatabaseError|PreviousFailureForInjection|RetryInjectsPreviousFailure|AgentPromptBlockOrder|AgentRefusalKeepsNodeOutput|WorkflowRunLifecycleRefusals|TaskWorkflowChoiceErrorsHTTP|TaskCommentWorkflowMissingSkill|ScheduledWorkflowRunsThroughTheRunEntry|ScheduledWorkflowTheBridgeRefuses|WorkflowStartRefusalWithdrawsTheRun|WorkflowRunStarterPersists)' 通过;go test ./internal/workflow -run 'Test(LoopValidation|IterationValidation|ReconnectValidatesPreviouslySpareConfiguration|DormantLoopDoesNotRequireConfiguration|StructureCannotBeHiddenInSpareNodes)' 通过;npx vitest run src/features/chat/workflow-run/run-flow.test.tsx src/features/collaboration/task-model.test.ts src/features/collaboration/task-page.test.tsx src/features/schedules/schedule-form.test.tsx src/features/workflows/editor/workflow-inspector.test.tsx src/lib/workflows/host/contract-error.test.ts src/lib/workflows/personal-skills.test.ts 失败(两次运行均为 131 条通过、1 条失败,既有用例在同步查找侧栏的运行中条目时失败。);npx vitest run src/features/chat/workflow-run/run-flow.test.tsx 通过;npx vitest run src/features/chat/workflow-run/run-flow.test.tsx src/features/collaboration/task-model.test.ts src/features/collaboration/task-page.test.tsx src/features/schedules/schedule-form.test.tsx src/features/workflows/editor/workflow-inspector.test.tsx 通过;没跑全量和 e2e。

涉及对外 API/协议,建议 owner 再看一眼。

P1 改完后我会再看一轮;其余都是建议,怎么处理由你决定。

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

Comment on lines +24 to +26
if (!skills) continue;
for (const binding of skills) {
if (binding.enabled && isPersonalSkillId(binding.skillId)) {

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.

P1-1(合并前需要改) 发布校验允许未连线的备用 Agent 保留未完成的配置,运行页会在渲染时直接扫描冻结图。给备用 Agent 留下 skills: {} 后,创建运行仍能成功,但打开运行页会抛出 skills is not iterable,启动按钮无法渲染。建议先检查数组和条目类型,并与后端 enabledBindings 对齐,将省略 enabled 的有效绑定视为启用,否则这类已发布工作流也会漏掉可见性提示。

Suggested change
if (!skills) continue;
for (const binding of skills) {
if (binding.enabled && isPersonalSkillId(binding.skillId)) {
if (!Array.isArray(skills)) continue;
for (const binding of skills) {
if (
typeof binding?.skillId === "string" &&
binding.enabled !== false &&
isPersonalSkillId(binding.skillId)
) {

可直接采纳这条修改。

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.

已处理,谢谢。

if run.Status == store.WorkflowStatusPending {
if _, err = a.runs.Start(ctx, scope, run.ID); err != nil {
if errors.Is(err, ErrWorkflowNotStartable) || errors.Is(err, execution.ErrUnavailable) {
if reason := workflowStartRejected(err); reason != "" {

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(建议) 点定时任务的「立即运行」时,缺 Skill 已经把这次触发记为 skipped,但 scheduleActionError 会将返回的错误映射成 500 internal。前端因此提示重试同一请求并保留请求键,补齐 Skill 后第一次点击仍会重放已跳过的触发。建议在确认触发已跳过后,把缺 Skill 和缺角色映射为带 occurrenceId 的明确拒绝,让用户看到原因并能直接重新触发。

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.

已处理,谢谢。

Reason: missing.Reason,
}
}
return err

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-2(建议) 拆分也调用 StartRun。v2-server/internal/taskdecomp/taskdecomp.go 会把这里返回的 err.Error() 存进拆分记录的 failure,随后以 201 返回。Skill 查询发生数据库故障时,包装后的 PostgreSQL 错误会被持久化并展示在协作页。建议在拆分入口识别缺 Skill 的结构化错误并给出可操作提示,其他内部故障只向用户返回安全文案,原始错误保留在服务端日志。

改动较大,建议另开 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.

已处理,谢谢。

@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.

Thanks — the start preflight is well-scoped and mirrors RoleReferences; the same-run-restart, DB-vs-missing split, schedule reasons and frontend localization all check out. go test -race on workflow/store/workflowhost/scheduler/server and the related vitest suites pass; 11/15 Go and 14/14 frontend mutations are killed.

Please fix before merge

  1. Decomposition entry isn't mapped (internal/taskdecomp/taskdecomp.go:198-202). A missing Skill now fails at start, and Host.Start settles the decomposition with the raw Go error (工作流没有启动:workflow skill not found: node "…" (a) skill "x": Skill x is missing…) and leaves the run pending. Please map WorkflowSkillNotFound / ErrWorkflowRoleNotFound to a localized failure and cancel the pending run, as the schedule adapter does. Add a test.
  2. SQL-leak assertion is vacuous (workflowhost/skills_test.go:251). The error mentions the original column content, not broken_content. With msg := err.Error() the test still passes and the message reads … column "content" does not exist (SQLSTATE 42703). Assert the exact generic message instead.

Nits

  • Iteration-member Skill preflight is untested; skipping RegionOwner != "" in SkillReferences survives.
  • The non-ErrNoRows plugin lookup error path (store/workflow_skills.go:87) is untested.
  • schedule_workflow_target.go:58 now maps WorkflowRunInputInvalid to workflow_run_not_startable. Please mention it in the PR and add a case.
  • workflow_run_lifecycle.go:51: desktop's WorkflowSkillNotFound has empty params, so the nodeId/nodeTitle/skillId params are a v2 extension, not a mirror.
  • The schedule starter test's fake host sets the starter itself, so it does not exercise the real start path.
  • The comment-@ recovery test switches to a different workflow, so it does not prove the original one starts after the Skill is created.
  • Frontend hasEnabledPersonalSkills requires enabled === true, while the server treats a missing enabled as enabled.

@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(5bd0758)

@wanglongan587 我看了这个 PR,理解它是要在首次调度前按发起人和目标项目校验冻结图中启用的 Skill,在各发起入口提示个人 Skill 的团队可见性,并补齐发起人持久化和重试提示词的回归测试。这是第 2 轮,我看了 b2940aa 之后的改动。上轮三条意见均已处理,可以合并。本轮建议补齐两个边界:保留并发读取下的拆分拒绝原因,以及在取消和落库均确认后再把定时触发判为终态拒绝。

  • 🔧 2 处小改已写成建议(P2-3、P2-4):见行内 suggestion,可以一键采纳,也可以不改或留到以后。
  • ✅ 上轮的 P1-1、P2-1、P2-2 已处理,谢谢。
  • 测试:go test -race -v -count=1 ./internal/taskdecomp ./internal/server ./internal/store ./internal/workflowhost . -run 'Test.*(Skill|Decomp|RunNow|WorkflowSchedule|ScheduledWorkflow)' 没跑(首次运行时未配置 PostgreSQL,单元用例通过,相关数据库用例跳过,随后使用隔离数据库补跑。);go test -race -count=1 ./internal/taskdecomp ./internal/server ./internal/store ./internal/workflowhost ./internal/scheduler . -run 'Test(DecompositionStartRefusals|WorkflowRunStarterMapsPreflightRefusalsForDecomposition|ScheduledWorkflow|TaskCommentWorkflowMissingSkillReturns400AndRecovers|WorkflowSkillRequiresMatchingProjectReceiptAndUser|StartRefusesASkillMissingFromAnyNodeOfTheGraph|SkillDeletedAfterStartFailsTheNodeResumably|SkillLookupDatabaseErrorIsNotReportedAsMissingSkill)$|TestScheduledWorkflow' 通过;go test -race -count=1 ./internal/scheduler ./internal/store ./internal/workflowhost -run 'Test(WorkflowStartRefusalWithdrawsTheRun|WorkflowRunStarterPersistsAcrossFinishCancelAndSchedule|AgentPromptBlockOrderWithPreviousFailure|AgentRefusalKeepsNodeOutputButDropsAnswerWhenInjectingRetry)$' 通过;npm test -- src/lib/workflows/personal-skills.test.ts src/lib/workflows/host/contract-error.test.ts src/features/schedules/schedule-form.test.tsx src/features/chat/workflow-run/run-flow.test.tsx src/features/collaboration/task-page.test.tsx 通过;没跑全量和 e2e。

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

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

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

Comment on lines 186 to 188
_, cancelErr := a.runs.Cancel(writeCtx, scope, run.ID)
reason := "workflow_run_not_startable"
if errors.Is(err, execution.ErrUnavailable) {
reason = "execution_unavailable"
}
_, applyErr := a.apply(writeCtx, scope, o, "rejected", "", reason)
return errors.Join(err, cancelErr, applyErr)

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-3(建议) 缺 Skill 后,如果取消运行或写入 skipped 时发生数据库错误,errors.Join 仍保留缺 Skill sentinel。HTTP 层可能因此返回 400,前端会清掉请求键,但旧运行可能仍是 pending,旧触发也可能仍占着计划的运行名额。建议取消失败时保留触发供协调器核对,等取消和 skipped 均写入成功后再返回依赖拒绝。

Suggested change
_, cancelErr := a.runs.Cancel(writeCtx, scope, run.ID)
reason := "workflow_run_not_startable"
if errors.Is(err, execution.ErrUnavailable) {
reason = "execution_unavailable"
}
_, applyErr := a.apply(writeCtx, scope, o, "rejected", "", reason)
return errors.Join(err, cancelErr, applyErr)
if _, cancelErr := a.runs.Cancel(writeCtx, scope, run.ID); cancelErr != nil {
return fmt.Errorf("withdraw refused workflow run: %w", cancelErr)
}
if _, applyErr := a.apply(writeCtx, scope, o, "rejected", "", reason); applyErr != nil {
return fmt.Errorf("record refused workflow run: %w", applyErr)
}
return err

可直接采纳,也可以不改。

Comment on lines +221 to 228
cancelCtx, stopCancel := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Second)
defer stopCancel()
if cancelErr := h.runs.Cancel(cancelCtx, tenant, user, run.ID); cancelErr != nil &&
!errors.Is(cancelErr, store.ErrWorkflowRunState) && !errors.Is(cancelErr, store.ErrWorkflowRunNotFound) {
h.log.Warn("cancel refused decomposition run", "task", taskID, "run", run.ID, "error", cancelErr)
}
settled, _, e := h.store.SettleTaskDecomposition(context.WithoutCancel(ctx), d.ID, nil, startFailureMessage(e))
return settled, e

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-4(建议) 缺 Skill 或角色时,Cancel 先把运行写成 cancelled,此时拆分记录仍是 running。如果另一个页面正好读取拆分列表,List 会替它结算为「工作流运行已取消。」,而 SettleTaskDecomposition 只接受第一次结算,用户就看不到该补哪个依赖。建议先保存预检失败原因,再取消运行。

Suggested change
cancelCtx, stopCancel := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Second)
defer stopCancel()
if cancelErr := h.runs.Cancel(cancelCtx, tenant, user, run.ID); cancelErr != nil &&
!errors.Is(cancelErr, store.ErrWorkflowRunState) && !errors.Is(cancelErr, store.ErrWorkflowRunNotFound) {
h.log.Warn("cancel refused decomposition run", "task", taskID, "run", run.ID, "error", cancelErr)
}
settled, _, e := h.store.SettleTaskDecomposition(context.WithoutCancel(ctx), d.ID, nil, startFailureMessage(e))
return settled, e
settled, _, settleErr := h.store.SettleTaskDecomposition(context.WithoutCancel(ctx), d.ID, nil, startFailureMessage(e))
cancelCtx, stopCancel := context.WithTimeout(context.WithoutCancel(ctx), 5*time.Second)
defer stopCancel()
if cancelErr := h.runs.Cancel(cancelCtx, tenant, user, run.ID); cancelErr != nil &&
!errors.Is(cancelErr, store.ErrWorkflowRunState) && !errors.Is(cancelErr, store.ErrWorkflowRunNotFound) {
h.log.Warn("cancel refused decomposition run", "task", taskID, "run", run.ID, "error", cancelErr)
}
return settled, settleErr

可直接采纳,也可以不改。

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