Skip to content

feat(workflow-editor): create workflow characters atomically - #198

Merged
xyh202131 merged 3 commits into
1024XEngineer:mainfrom
huyanxius:feat/workflow-character-create
Aug 11, 2026
Merged

feat(workflow-editor): create workflow characters atomically#198
xyh202131 merged 3 commits into
1024XEngineer:mainfrom
huyanxius:feat/workflow-character-create

Conversation

@huyanxius

@huyanxius huyanxius commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

在 Workflow Editor 确认身份母版时创建正式 Character,并在后端保证每个 WorkflowRun 只关联一个同项目 Character,使并发编辑会话也能安全继续真实动作生成流程。

Why

PR #190 接入真实 WorkflowRun 画布后,新建流程在确认身份母版时仍可能没有对应 Character。仅在前端 session 内判断无法处理两个编辑会话的并发创建:重复 Character 会让后续恢复失败,冲突回查若不校验项目归属还可能暴露其他项目的角色数据。

Changes

  • 确认身份母版时,为尚未绑定角色的 WorkflowRun 创建 Character。
  • 为首次创建且没有造型的 Character 补充默认 Outfit,并将结果回填页面状态。
  • workflow_run_id 增加数据库唯一约束,避免并发请求持久化多个 Character。
  • POST /characters 在唯一约束冲突后 rollback,并通过项目归属校验安全返回既有 Character。
  • 补充后端幂等与跨项目权限回归测试,以及 Workflow Editor 有行为价值的分支测试。

Implementation

  • session runtime 继续集中编排 Character 创建、默认 Outfit 持久化与 WorkflowController.confirmCharacterTemplate,页面不直接调用资产 API。
  • CharacterService 增加按 WorkflowRun ID 查询的最小边界;API 只在回查 Character 属于本次已鉴权项目时复用。
  • 沿用仓库现有 SQLAlchemy create_all / model 约束模式,不引入迁移框架。

Verification

  • npm test -- src/pages/workflow-editor/runtime.test.ts src/pages/workflow-editor/index.test.tsx:2 个测试文件、36 项测试通过。
  • npm run test:coverage -- src/pages/workflow-editor/runtime.test.ts src/pages/workflow-editor/index.test.tsx:通过;runtime.ts 行覆盖率 91.66%,分支覆盖率 88.88%。
  • npm run typecheck:通过。
  • npm run lint -- src/pages/workflow-editor/runtime.ts src/pages/workflow-editor/runtime.test.ts src/pages/workflow-editor/index.tsx src/pages/workflow-editor/index.test.tsx:通过。
  • npm run format:check -- src/pages/workflow-editor/runtime.ts src/pages/workflow-editor/runtime.test.ts src/pages/workflow-editor/index.tsx src/pages/workflow-editor/index.test.tsx:通过。
  • uv run pytest -q tests/test_character_api.py:10 项测试通过。
  • uv run ruff check <相关 Character 文件>:通过。
  • uv run lint-imports:2 项分层契约通过。
  • git diff --check upstream/main...HEAD:通过。

Scope

  • 本 PR 仅处理身份母版确认时的 Character 创建、默认 Outfit、页面状态回填及其并发唯一性。
  • 不修改 Workflow 节点模型、动作发布流程或其他模块。
  • 无视觉变化。

New WorkflowRuns can confirm a character template before any Character asset exists.

Create the bound Character, seed its default outfit, and return it to the editor before advancing the template node.

Keep subsequent action generation on the real Character and cover the flow with runtime and page regressions.
@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
windup Ignored Ignored Preview Aug 11, 2026 6:56am

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

Review Summary

Found one correctness issue in the new Character creation path. git diff --check passed. Targeted tests could not be rerun because the mounted workspace has no runnable local Vitest installation (vitest: Permission denied / module unavailable).

View job run

Comment thread frontend/src/pages/workflow-editor/runtime.ts
Template confirmation has validation and idempotent paths that lacked behavior coverage.

Exercise invalid selection inputs and the existing Character with Outfit path.

Keep patch coverage focused on observable session behavior.
Concurrent editor sessions could persist multiple Characters for one WorkflowRun.

Enforce database uniqueness and recover conflicts through a project-scoped get-or-create path.

Keep duplicate creation idempotent without exposing Characters across projects.
@huyanxius huyanxius changed the title feat(workflow-editor): create character on template confirmation feat(workflow-editor): create workflow characters atomically Aug 11, 2026
@huyanxius

Copy link
Copy Markdown
Collaborator Author

@fennoai 还有其他问题吗

@fennoai

fennoai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

还有 3 个问题

  1. P1:现有数据库不会获得唯一约束backend/packages/app/src/windup_app/server/character/model.py:61

    • 项目启动仅调用 Base.metadata.create_all(...);它只创建缺失表,不会给已存在的 windup_characterUNIQUE(workflow_run_id)
    • 因此新库测试会通过,但升级现有部署后,并发请求仍可能落下多个 Character,之前的核心问题在生产库中仍存在。
    • 需要提供真实 schema 升级步骤(并考虑升级前重复数据的清理),不能只改 ORM metadata。
  2. P1:创建接口未校验 WorkflowRun 与项目归属backend/packages/app/src/windup_app/web/api/character.py:134

    • 当前只鉴权 project_id,随后直接接受任意正整数 workflow_run_id
    • 用户可把自己项目的 Character 绑定到不存在的 run,或绑定/抢占其他用户可猜测的 run ID;全局唯一约束随后会让真实项目创建时冲突并返回 404,形成跨项目数据污染和拒绝服务。
    • 现有跨项目测试只覆盖“合法 Character 已先创建”的顺序,缺少攻击者先占用 run ID 的反向场景。创建前应查询 WorkflowRun,并要求 run.project_id == body.project_id 且当前用户有权访问。
  3. P1:Character 与 WorkflowRun 的确认仍不是原子操作frontend/src/pages/workflow-editor/runtime.ts:101

    • 流程依次执行 Character POST、默认 Outfit PATCH、WorkflowRun PATCH;任一步失败都会留下部分成功状态。
    • 例如 Outfit 已保存但 WorkflowRun 更新失败后,重进页面仍处于 selecting,再次选择另一张图时因为 outfits.length > 0 会跳过 Character 更新,最终 WorkflowRun 的 selectedImageUrl 与 Character 的 referenceImageUrl / Outfit 预览不一致。两个并发会话也可通过交错 PATCH 产生同样结果。
    • 当前测试“已有 Character 和造型时只推进节点”实际上固化了这个不安全恢复路径。若目标是并发安全,建议由后端在一个事务内完成 get-or-create、默认 Outfit 和 WorkflowRun 确认(或至少提供带版本校验的原子命令端点)。

验证

  • git diff --check 28725986c80f75cac28bde99f2e270cab5ca4949...6a6a3353538230c488b80b41b784f8019a551026:通过。
  • 本环境没有 uv,前端依赖也未安装(vitest 无法执行),因此未能独立复跑 PR 描述中的测试;以上结论来自固定 SHA 范围的代码与调用链审查。
  • 未修改代码。

View job run

@xyh202131
xyh202131 merged commit 1656dcf into 1024XEngineer:main Aug 11, 2026
7 checks passed
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