Repository navigation
feat(v2): 协作任务各操作按 #1376 规则表授权,待验收可退回待处理 - #433
Conversation
… task - Edit, reassign and split: the creator, the workspace owner and whoever does the work now (the assignee, or a member of the assigned squad). An Agent task has no person doing it, so only its creator and the owner manage it. A finished task is read-only (409 task_closed). - Reassigning waits for a running Agent turn (409 run_active). - Splitting only applies to a task still being worked; a task in review answers 409 task_in_review. - Stopping a run: whoever started it, the creator and the owner. - The creator and the owner may send a task in review back to pending while no run executes it. Anyone else gets 403 forbidden.
The task page follows the server's rules: editing, reassigning and splitting name the creator, assignee or squad; stopping names the run's starter and the creator; the creator gets 退回待处理 in review, also on the board. A creator or owner who cannot run the task's Agent can still stop its run. 「我的任务」 says it keeps work handed in for review.
wanglongan587
left a comment
There was a problem hiding this comment.
审查版本:ora-space/cloud#433 head 7e1dbab81fe02cd1a7df0e365dc736528b2af4ef(base upstream/main c3b62695a5c8f016dfa0dc3249cd47a32df9b9e6),对照决策 ora-space/circus#1376 与父事项 ora-space/circus#1035。
审查方式:静态代码与契约核对 + 运行 #1383 界面截图人工检视(PR CI server、frontend、e2e 在 7e1dbab8 全绿;本轮未在本地重跑测试)。
阻塞项(需修改后重新送审)
-
v2-server/tasks.openapi.json漏了stopTaskRun的403响应声明(Medium)- 位置:
v2-server/tasks.openapi.json(POST /api/v2/tenants/{tid}/tasks/{taskid}/runs/{rid}/stop,L952–L1030)、v2-server/internal/server/task_runs.go:115-116,186-197。 - 问题:
taskrun.Host.Stop新增返回store.ErrForbidden并经taskRunFault映射为403 forbidden,但tasks.openapi.json的stopTaskRun仍只声明了200/401/404/409/500/503,缺403(其余几个被加权的接口都有403)。server/tasks_test.go的taskClient会用openapi3filter.ValidateResponse按该文件校验 HTTP 响应,经 HTTP 测试旁观者停止运行返回403会直接在契约校验阶段失败。 - 建议:在
v2-server/tasks.openapi.json的stopTaskRun补上403(TaskError),如前端生成的客户端有变化一并同步,并在v2-server/internal/server/task_runs_test.go补一条经taskClient的旁观者停止403 forbiddenHTTP 测试。
- 位置:
-
前端
TaskFamily的「重新拆分」按钮漏了canDecompose和canManage门禁(Medium)- 位置:
frontend-v2/src/features/collaboration/task-page.tsx:252-253,265、frontend-v2/src/features/collaboration/task-decomposition.tsx:101,116,131-143。 - 问题:顶栏「拆分」按钮已改为仅在
canDecompose(task)时显示,且!canManage时禁用并给出manageRefusal(task, '拆分')。但正文下方TaskFamily→DecompositionStatus在上一次拆分失败(latest.status === 'failed')时仍无条件渲染可点击的「重新拆分」按钮(L141)。这导致:- 旁观者(
!canManage)在拆分失败提示里仍能点开弹窗提交拆分,直到服务端返回403; - 任务进入
待验收(review)或已结束(done/cancelled)后,顶栏「拆分」已隐藏,但「重新拆分」仍可点开提交,直到服务端返回409 task_in_review/task_closed。
- 旁观者(
- 建议:把
canDecompose(task)、canManage和manageRefusal(task, '拆分')传给TaskFamily/DecompositionStatus:非canDecompose(task)时不渲染「重新拆分」,!canManage时禁用并加上title={manageRefusal(task, '拆分')},并在task-page.test.tsx补对应单测。
- 位置:
-
taskdecomp.Host.Start在h.lock(taskID)之前读取task并判权,锁内未重读(Medium)- 位置:
v2-server/internal/taskdecomp/taskdecomp.go:133-159。 - 问题:
taskrun.Host.Start(taskrun.go:265)、taskrun.Host.Stop(taskrun.go:430)与taskworkflow.Host.Start(taskworkflow/host.go:61)都是在获取h.lock(taskID)之后再读task并判权;而taskdecomp.Host.Start在 L135 读task、L139 调store.CanManageTask,L145 才加锁且锁内不重读task。若请求在h.lock(taskID)排队等待前一次操作,后续锁内的TaskFinished/TaskReview校验和input拼装都会继续使用锁前旧快照。 - 建议:将
defer h.lock(taskID)()挪到h.store.Task(ctx, tenant, taskID)之前(跨路由CreateTaskDecomposition未锁v2_tasks行的小窗口在 phase1 可接受,无需扩改事务边界)。
- 位置:
非阻塞建议
taskrun.Host.Stop测试覆盖边界与陈旧注释(Low)v2-server/internal/taskrun/taskrun_test.go:416-447的TestStopEndsTheRunAndReturnsTheTask用f.owner测停止,但f.owner同时是RoleOwner和任务创建人(删掉task.CreatedBy == a.UserID条件该用例也能过)。建议补全三个独立身份的测试:非 owner 的创建人、非创建人的 owner、以及非创建人/非 owner 的运行发起人本人。v2-server/internal/taskrun/taskrun_test.go:716残留旧注释// Anyone may still stop the run: it spends nobody's identity.,建议一并更新。
已核对通过的重点项(回应作者指定审查内容)
taskrun.Host.Stop逻辑:在h.lock(taskID)内重读task、run与最新TenantAccess,并在!run.Live()与seen幂等判断之前校验CanStopTaskRun(旁观者无法绕过),停止时仍以run.StartedByscope 调执行服务——逻辑严密。taskdecomp.Host.Start鉴权与幂等顺序:CanManageTask在TaskDecompositionByKey之前、TaskDecompositionByKey在TaskFinished/TaskReview之前,与taskworkflow.Host.Start口径一致;ArchiveSquad会写ended_at,已归档小队与已移除队员都能被InSquad拦住。- 改派在 Agent 执行中返回
run_active、在工作流处理中仍放行的取舍:接受。- 与
circus#1376原文及结论(「服务端补上前端已有的限制」)一致; - 核对
store/tasks.go:254-258、store/task_workflows.go及store/task_workflows_edits_test.go:改派不会递增v2_task_workflow_runs.status_revision,工作流结算的status_revision = 1栅栏不受影响;工作流处理中时,CreateTaskRun/CreateTaskWorkflowRun都会检查运行中的v2_task_workflow_runs、SetTaskStatus返回409 workflow_active,新负责人无法在工作流结束前并发启动或手动改状态; - Agent
idle会话期间改派后,原发起人仍可通过!runsAgent && task.activeRun区块结束自己的空闲会话,新负责人「重新执行」也会以TaskRunReplaced结束旧会话。
- 与
- 截图核对:已下载并检视
#1383所附两张截图(1383-bystander-bob.png与1383-creator-owner.png):旁观者 Bob 视角下编辑/改派/确认完成/退回待处理/取消均已禁用并写明原因,owner 创建人视角下待验收状态可点「退回待处理」并显示返工提示,与说明一致(两张截图未涵盖拆分失败与运行中停止区块,改完以上阻塞项后请按 v2 规则附新 commit 截图重新送审)。
…he task lock - tasks.openapi.json: stopTaskRun answers 403 forbidden to anyone but the run's starter, the task's creator and the workspace owner; an HTTP test stops as a bystander through the contract-checking client. - taskdecomp.Start reads and judges the task after taking its lock, like the run and workflow hosts, so a start that waited sees the task as the previous one left it. - Stop tests cover the starter, a creator who is not the owner and an owner who did not create the task, each on their own standing.
The failed-split notice follows the header's 拆分 rule: no retry once the task is in review or finished, and a disabled retry naming who can for a member who may not split it. The tasks client picks up the stop route's description.
wanglongan587
left a comment
There was a problem hiding this comment.
上一轮的三个阻塞项都已改好,剩 v2-server/README.md 还写着旧规则
审过 903199fb7705f19eec4d85fc9be79e3b415fd373(在 7e1dbab8 之上两个 commit)。规则本身、两处新增判定的位置、以及 run_active 只拦 Agent 执行中这个取舍,都与 #1376 的 owner 结论一致,不用再改。剩下的是一条文档:这次改动让 v2-server/README.md 里几句关于任务权限的话直接变成假的,而 v2-server/AGENTS.md 要求把 v2 的行为写进这份 README。
已复核通过
stopTaskRun补403:tasks.openapi.json的该路由现在声明403(TaskError),描述写明谁能停;TestTaskRunHTTP用独立的taskClient以旁观者身份走契约校验拿到403 forbidden,再以发起人身份停下。code是自由字符串、403也是新加的状态码,不会破坏既有断言。- 「重新拆分」按顶栏规则门禁:
TaskFamily的onRetry只在canDecompose(task)时传入,retryRefusal用manageRefusal(task, '拆分'),待验收/已结束时按钮整体不渲染,无权限时禁用并在title写明谁能拆。 taskdecomp.Host.Start先加锁再读任务:defer h.lock(taskID)()移到h.store.Task之前,锁内读到的task同时用于判权和后续ErrTaskClosed/ErrTaskInReview,与taskrun.Host.Start/Stop、taskworkflow.Host.Start一致。- 建议 4:
TestStopIsForTheStarterTheCreatorAndTheOwner覆盖发起人本人、非 owner 的创建人、非创建人的 owner 三种各自成立的身份;taskrun_test.go的旧注释也已改成「创建人虽然不能发起,但能停」。
我本地复核的证据:
npm ci后在frontend-v2跑vitest run src/features/collaboration:7 个文件 102 条通过。对新用例做了两次变异——把onRetry换回无条件传入、把retryRefusal恒设为''——两次都只有offers to split again after a failure only while the caller may split the task失败,说明它确实守着这两个条件,不是空断言。- Go 侧本机没有可用的 PostgreSQL(
TEST_DATABASE_URL未设、55432拒绝连接、无 docker),所以没有本地跑;以 CI 在同一个 head 上的server(Linux + Postgres 17.11,go test -race -count=1 ./...)、frontend(npm run check,含api:check:tasks)、e2e(8m55s)三个 job 全绿为准,另gofmt/go vet也在该 job 内。 - 截图:
1383-bystander-bob-903199f.png里 Bob 的「编辑」「确认完成」「退回待处理」「取消任务」都是禁用态(与1383-creator-sent-back-903199f.png的黑色可用态对比明显),指派下拉是禁用态,两处文案各自写明谁能做;owner 退回后状态回到待处理、顶栏「拆分」重新出现、编辑恢复可用,和说明一致。
阻塞项:README 与新规则相反
这几句现在与代码矛盾(行号按 903199fb):
281路由表 stop:「任何成员都可以停」→ 现在是运行发起人、任务创建人、工作区 owner,其他人403 forbidden。305:「当前工作区任意成员都可读写、指派与推进任务」→ 编辑、改派只给创建人、owner、当前负责人;确认完成、取消、退回待处理只给创建人和 owner。324(派给人的任务):「别人仍能看过程、停止」→ 别人能看,但停不了,除非是创建人或 owner。297、302:生命周期漏了review → pending;「后两种人不能手动做」也不再准确——运行造成的回退人不能手动做,但创建人/owner 可以手动把待验收退回待处理。
同一节里顺带补齐(这几处本来只是没写全,一起补省一轮):
274(PUT tasks):补谁能改(创建人、owner、当前负责人)与已结束409 task_closed。275(status):确认完成、取消之外,退回待处理也只限创建人和 owner。277(assignment):补谁能改派(按改派前的负责人算)、已结束409 task_closed、Agent 执行中409 run_active。453(任务拆分):补谁能拆(创建人、owner、当前负责人;其他人403 forbidden)与待验收409 task_in_review。
非阻塞
taskdecomp.Host.Start的判权在TaskDecompositionByKey之前:同一次拆分(同一个 key)如果在途期间调用方失去了管理权(任务被改派走、或不再是队员),重试会拿到403而不是那次拆分本身。范围很窄,TaskDecompositionByKey本来就按人查,把它挪到判权之前也说得通,随你判断。- #1376 结论里的「我参与的」:你在 issue 里问 EricWvi 的那条还没有回应。
我的任务不按状态过滤、负责人跑完一轮进入待验收的任务确实在里面,实质满足;但这个视图名并不存在,等 EricWvi/owner 给了口径再关 #1035 那一条,这轮先不要当成已确认。
v2-server/README.md and the collaboration README still said any member may edit, reassign, split and stop. They now state the #1376 rules, the review → pending send-back, and the 403, task_closed, run_active and task_in_review answers of each route.
wanglongan587
left a comment
There was a problem hiding this comment.
审过 commit 2ad85c1e(相对 903199fb 只改文档:v2-server/README.md、frontend-v2/src/features/collaboration/README.md,+21/−12)。上轮的阻塞项已修好,规则与代码一致,同意合并。
复核(对照 2ad85c1e 的代码)
- 路由表:编辑、状态、改派、停止四条都补上了
403 forbidden,编辑/改派补上task_closed,改派补上run_active。与store/tasks.go的requireManage(先ErrForbidden,再ErrTaskClosed)、SetTaskAssignee的ErrRunActive一致。 - 生命周期:
review → pending已补,并写明退回只有人工能做。「人不能手动从running进入review/pending」成立:SettleDeliveredTaskTurn在同一事务里锁任务行并要求turn_active,交付期间ActiveRun仍是running,SetTaskStatus会先返回 409run_active;CanRunTransitionTask不含review → pending。 - 谁不能改:
canCloseTask/CanManageTask/CanStopTaskRun三个函数与文中四条一一对应;「改派按改派前的负责人算」对得上requireManage(ctx, tx, a, before)。 - 拆分:
taskdecomp.Start的判定顺序(CanManageTask→task_closed→task_in_review→subtask_not_decomposable)与新写的状态限制一致。 - 前端 README:新增的「谁能改任务」与
task-views.ts的canManageTask/canStopRun一致;「重新拆分」的禁用与原因也和task-page.tsx对齐。 - 保留的旧说法是对的:工作流页签里「停止不限发起人」不属于 #1376 规则表,
workflowhost.CancelRun确实只按租户查运行、不校验发起人。
证据
gh pr checks 433在同一 head 上server、frontend、e2e全绿(run 45102165912)。- 两条 README 的改动只描述已有行为,没有引入与
store/task_access.go、task-views.ts不一致的规则。
非阻塞(一行措辞,可改可不改)
frontend-v2/src/features/collaboration/README.md 的「创建人和 owner 看不到「用 Agent 处理」」在创建人同时是负责人时不成立:runsAgent 只看指派人,自己建给自己的人仍能开运行。写成「不是负责人的创建人和 owner 看不到」更准确。
Refs ora-space/circus#1383
v2,不涉及 specs。
按决策 circus#1376 的 owner 结论(选项 A 加规则表)落地 circus#1035 的第 2 条:协作任务各项操作由谁来做。服务端判定,不允许时返回
403 forbidden。前端按同一套规则禁用按钮,并写明谁能做,写法沿用确认完成(cloud#339)。规则
409 task_closed)task_closed);Agent 这一轮在执行时不能改(409 run_active)409 task_in_reviewAuthorizeTaskRunner不变)。改了什么
store/task_access.go:CanManageTask、CanStopTaskRun,以及已有的canCloseTask。UpdateTask、SetTaskAssignee改成接收调用方的Access,在锁住任务的同一事务里判定。CanTransitionTask加上 待验收 → 待处理,由canCloseTask把关。CanRunTransitionTask不变。taskdecomp.Start)和停止(taskrun.Host.Stop)各自补上判定。task-views.ts新增canManageTask、manageRefusal、canStopRun、stopRefusal、needsCloser,和服务端一一对应。取舍
task_workflows_edits_test.go),工作流结束时按处理链接结算,不受负责人变化影响。界面原来也只在 Agent 执行时禁用改派。workflow-runs/.../stop、任务页「工作流」标签里的停止)不在 #1376 的规则表里,这次不动。验证
go test -race跑了store、server、taskdecomp、taskrun、workflowhost、taskworkflow,全部通过。TestTaskManageNeedsCreatorOwnerOrAssignee、TestTaskSendBackNeedsCreatorOrOwner、TestDecompositionNeedsCreatorOwnerOrAssignee,以及停止和待验收拆分的断言。typecheck、lint通过。403 forbidden。