From 16f5884f283ce50e87633dcc857b8c91ec6c2dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B4=AA=E5=88=9A?= <11776741+chgJava@user.noreply.gitee.com> Date: Tue, 17 Nov 2026 23:24:32 +0800 Subject: [PATCH 1/2] feat(engine): bind approvals to artifacts and gate verification nodes An approval could be recorded against a node that had moved on, and /pass could mark any failed script node as succeeded. Both conventions now have engine enforcement. - NodeExpectation gains artifactName/artifactSha256; approval verifies the newest artifact of that name still carries that hash, returns 409 on a stale decision, and writes gate.approval_rejected with expected and actual values. - WorkflowNode.requires supports artifact:@ and verdict:@; an unmet precondition fails the node with both values instead of silently skipping it. - WorkflowNode.verificationStep makes /pass refuse the node unless the request carries override:true; both outcomes are audited with the operator. The JSON name avoids the removed legacy `verification` gate-array field that the API strips on save. - Docs and OpenAPI updated; new engine and HTTP tests cover all three. Co-Authored-By: Claude Code --- docs/api/openapi.yaml | 27 +++- docs/api/orchestration.md | 27 +++- docs/enhancements/approval-binding.md | 81 ++++++++++++ internal/domain/issue.go | 14 ++- internal/domain/workflow.go | 28 +++-- internal/engine/bot_control.go | 63 +++++++++- internal/engine/gate_binding_test.go | 123 ++++++++++++++++++ internal/engine/node_execute.go | 4 + internal/engine/node_requires.go | 138 +++++++++++++++++++++ internal/engine/node_requires_test.go | 124 ++++++++++++++++++ internal/engine/pass_override_test.go | 92 ++++++++++++++ internal/engine/run_ops.go | 53 +++++++- internal/engine/workflow_graph.go | 5 + internal/httpapi/auth_tokens.go | 13 ++ internal/httpapi/gate_binding_http_test.go | 120 ++++++++++++++++++ internal/httpapi/runs.go | 4 +- 16 files changed, 898 insertions(+), 18 deletions(-) create mode 100644 docs/enhancements/approval-binding.md create mode 100644 internal/engine/gate_binding_test.go create mode 100644 internal/engine/node_requires.go create mode 100644 internal/engine/node_requires_test.go create mode 100644 internal/engine/pass_override_test.go create mode 100644 internal/httpapi/gate_binding_http_test.go diff --git a/docs/api/openapi.yaml b/docs/api/openapi.yaml index 4d993a599..7cccea3fc 100644 --- a/docs/api/openapi.yaml +++ b/docs/api/openapi.yaml @@ -2739,7 +2739,7 @@ paths: tags: [Runs] operationId: passFailedRunNode summary: Pass a failed script node - description: Marks a failed script or command node as succeeded and continues downstream without re-executing it. Agent nodes must use retry with optional human context instead. + description: Marks a failed script or command node as succeeded and continues downstream without re-executing it. Agent nodes must use retry with optional human context instead. A node marked verificationStep:true returns 409 unless the request carries override=true; pass, rejection and override are all audited. requestBody: $ref: "#/components/requestBodies/NodeAction" responses: @@ -3803,6 +3803,22 @@ components: properties: nodeId: type: string + reason: + type: string + context: + type: string + override: + type: boolean + description: Required to pass a node marked verificationStep; the request is audited with its operator. + expected: + type: object + description: Binds the decision to the attempt (and optionally the artifact) the operator reviewed. A mismatch returns 409 and leaves the node waiting. + properties: + status: {type: string} + attempt: {type: integer} + reworkCount: {type: integer} + artifactName: {type: string} + artifactSha256: {type: string} SyncConfig: required: true content: @@ -4905,6 +4921,15 @@ components: type: integer maxReworks: type: integer + requires: + type: array + description: Preconditions checked before the node executes. An unmet precondition fails the node with the expected and actual values. + items: + type: string + pattern: "^(artifact:[^@]+@.+|verdict:(PASS|FAIL)@.+)$" + verificationStep: + type: boolean + description: Marks a verification step. /pass refuses it unless the request carries override=true; both outcomes are audited. position: $ref: "#/components/schemas/OpenObject" WorkflowEdge: diff --git a/docs/api/orchestration.md b/docs/api/orchestration.md index 21afc3f58..c37f71f28 100644 --- a/docs/api/orchestration.md +++ b/docs/api/orchestration.md @@ -213,7 +213,7 @@ curl -u "$AGENTFLOW_USER:$AGENTFLOW_PASS" -OJ \ ## 人工动作 -以下接口成功均返回 `200 {"ok":true}`;run/node/状态错误通常 `400`。与 Issue 关联且执行被关闭/交付锁定的 run,在 approve、pass、reject、retry 时返回 `409`。 +以下接口成功均返回 `200 {"ok":true}`;run/node/状态错误通常 `400`。与 Issue 关联且执行被关闭/交付锁定的 run,以及 `expected` 中的节点尝试或产物哈希已变化、`verificationStep` 节点未带 `override` 的 pass,在 approve、pass、reject、retry 时返回 `409`。 ### `POST /api/runs/{runId}/approve` @@ -223,6 +223,23 @@ curl -u "$AGENTFLOW_USER:$AGENTFLOW_PASS" -OJ \ 批准等待中的节点。 +`expected` 可把批准绑定到操作者看到的那个节点尝试和产物上: + +```json +{ + "nodeId":"approval", + "expected":{ + "status":"waiting_approval", + "attempt":2, + "reworkCount":0, + "artifactName":"verify", + "artifactSha256":"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" + } +} +``` + +`artifactName`/`artifactSha256` 校验当前 run 中该名字的**最新**产物仍带这个内容哈希。节点状态或产物哈希任一不匹配时返回 `409`,节点保持 `waiting_approval`,run 追加 `gate.approval_rejected` 审计事件(写明期望值与实际值)。不带 `expected` 时行为不变。 + ### `POST /api/runs/{runId}/pass` ```json @@ -231,6 +248,14 @@ curl -u "$AGENTFLOW_USER:$AGENTFLOW_PASS" -OJ \ 将已失败的**脚本**节点视为通过并继续下游,不重新执行该节点。用于 `onFailure=fail` 停下来之后,或打回返工到达最大轮次后,避免硬脚本一直卡住。Agent / AI 节点不能手动通过,应走 `/retry` 并附带补充上下文。 +节点带 `verificationStep: true` 时,`/pass` 默认返回 `409`(节点保持失败,run 追加 `node.pass_rejected` 审计事件)。确需人工放行时显式带 `override`: + +```json +{"nodeId":"phpunit-full","override":true,"context":"环境问题,验证本身已人工复核"} +``` + +放行仍会写 `node.passed_override` 审计事件,并记录请求的操作者(登录用户,未登录记为「未记录操作者」)。 + ### `POST /api/runs/{runId}/reject` ```json diff --git a/docs/enhancements/approval-binding.md b/docs/enhancements/approval-binding.md new file mode 100644 index 000000000..03312b184 --- /dev/null +++ b/docs/enhancements/approval-binding.md @@ -0,0 +1,81 @@ +# Approval binding and engine-enforced verification gates + +This change upgrades two conventions into engine guarantees: + +1. A human approval can be bound to the exact artifact the operator reviewed, so an approval aimed at a stale run state is rejected instead of silently approving something else. +2. A verification node cannot be bypassed with `POST /api/runs/{id}/pass`; an explicit, audited override is required. + +It follows the enhancement plan in `plan.md` (P2–P4). P5 (sidecar integration with AegisOS) is not part of this change. + +## Baseline facts (P1, read from source) + +- A run freezes its workflow at start: `internal/engine/run_start.go:156` stores `WorkflowSnapshot`, and a later publish does not change it. `RefreshRunSOP` (`internal/engine/run_ops.go`) is the only explicit snapshot update. +- Every artifact, including engine-written `decision.md`, gets a SHA-256 in `newArtifact` (`internal/engine/artifacts.go`), so binding needs no new table. +- Before this change, `/pass` accepted any failed script/command node on a failed run (or a script parked by a pause) and had no type-level restriction, so a verification script could be bypassed. + +The live smoke test (`./start.sh dev`, first admin, minimal SOP run) was not run in the development session that produced this change: the dev image build failed inside Docker at `npm --prefix chatbot ci` with a network error. That is an environment failure, not a regression from this change. + +## P2 — binding an approval to an artifact + +`engine.NodeExpectation` and the HTTP `expected` object gained: + +- `artifactName`: logical artifact name, e.g. `verify`; +- `artifactSha256`: expected content hash. + +`checkNodeExpectation` compares against the **newest** artifact with that name (newest attempt, then newest creation time). Approving against an older attempt is exactly the stale decision this check exists to reject. + +On mismatch the engine returns an `apperr.Conflict` (HTTP `409`), appends `gate.approval_rejected` with the expected and actual values, and leaves the node in `waiting_approval`. Status/attempt/rework mismatches use the same `409` now, since they mean the same thing: the card the operator acted on is stale. + +```json +{ + "nodeId": "approval", + "expected": { + "status": "waiting_approval", + "attempt": 2, + "artifactName": "verify", + "artifactSha256": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08" + } +} +``` + +Omitting `expected` keeps the old behavior. + +## P3 — node preconditions with `requires` + +`WorkflowNode.requires` accepts: + +- `artifact:@`: the run must carry that artifact with that hash; +- `verdict:@`: the newest verdict artifact (named `verdict`, or whose path is `verify.json`) must be JSON with `verdict` and `diffHash` matching. + +Malformed values are rejected at workflow validation. At execution the scheduler checks the preconditions before spawning the node; an unmet precondition fails the node with the expected and actual values (no silent skip, no retry — a deterministic precondition will not change). + +```json +{ + "id": "ship", + "type": "agent", + "agentId": "releaser", + "requires": ["verdict:PASS@c0ffee"] +} +``` + +## P4 — closing the `/pass` bypass for verification nodes + +`WorkflowNode.verificationStep: true` marks a verification step. The JSON name avoids `verification` because that is the removed legacy gate-array field the API strips on save. + +- `POST /api/runs/{id}/pass` without `override` returns `409`, leaves the node failed, and appends `node.pass_rejected`. +- `{"nodeId":"...","override":true}` passes the node and appends `node.passed_override` naming the operator (the signed-in user; anonymous requests are recorded as `未记录操作者`). + +Non-verification script nodes keep the previous behavior, so the environment-problem workflow that `/pass` exists for still works. + +## Tests + +- `internal/engine/gate_binding_test.go`: matching hash approves, mismatched/missing artifact rejects and audits, omitted `expected` unchanged. +- `internal/engine/node_requires_test.go`: artifact hash mismatch stops the consumer with expected+actual, matching hash runs it, verdict mismatch names both, malformed `requires` fails validation. +- `internal/engine/pass_override_test.go`: verification node rejects `/pass` and audits; override passes and records the actor; plain script node unchanged. +- `internal/httpapi/gate_binding_http_test.go`: HTTP `409` for a stale approval and for `/pass` without override, `200` with override. + +Run with `GOFLAGS=-buildvcs=false go test ./internal/engine ./internal/httpapi` when the checkout sits under a directory tree that also contains an `.svn` directory (Go's VCS stamping refuses the nested build otherwise). + +## P5 — not implemented + +The sidecar interface (verify / critique / delivery-check) and its SOP integration are the next step. The deployment shape (same-host process, MCP, or container) must be confirmed before writing that adapter. diff --git a/internal/domain/issue.go b/internal/domain/issue.go index 5f0c3565a..4a48ae8ce 100644 --- a/internal/domain/issue.go +++ b/internal/domain/issue.go @@ -384,11 +384,19 @@ type HumanDecision struct { NodeID string `json:"nodeId"` Reason string `json:"reason,omitempty"` Context string `json:"context,omitempty"` + // Override lets /pass through a node marked verification:true. The request + // is still audited with its operator; without it the pass is refused. + Override bool `json:"override,omitempty"` } // NodeDecisionExpectation binds a workbench action to the attempt being viewed. +// artifactName/artifactSha256 additionally bind an approval to the artifact the +// operator reviewed: the action is rejected with 409 when the newest artifact +// of that name no longer carries that hash. type NodeDecisionExpectation struct { - Status string `json:"status"` - Attempt int `json:"attempt"` - ReworkCount int `json:"reworkCount"` + Status string `json:"status"` + Attempt int `json:"attempt"` + ReworkCount int `json:"reworkCount"` + ArtifactName string `json:"artifactName,omitempty"` + ArtifactSHA256 string `json:"artifactSha256,omitempty"` } diff --git a/internal/domain/workflow.go b/internal/domain/workflow.go index 59175e633..8ea06f7f8 100644 --- a/internal/domain/workflow.go +++ b/internal/domain/workflow.go @@ -69,14 +69,26 @@ type WorkflowNode struct { ExecutionScope string `json:"executionScope,omitempty"` // run, repositories; empty = run Command string `json:"command,omitempty"` // legacy command-node payload ArtifactOutputs []ArtifactContract `json:"artifactOutputs,omitempty"` - RejectTo string `json:"rejectTo,omitempty"` - OnFailure string `json:"onFailure,omitempty"` // fail, reject - RetryStrategy string `json:"retryStrategy,omitempty"` // targeted_fix, full_redo - CarryOver []string `json:"carryOver,omitempty"` - MaxAttempts int `json:"maxAttempts"` - MaxReworks int `json:"maxReworks"` - Notifications []NodeNotification `json:"notifications,omitempty"` - Position Position `json:"position"` + // Requires lists preconditions checked before the node executes. Supported + // forms: "artifact:@" (the run must carry that artifact with + // that content hash) and "verdict:@" (the verdict + // artifact must carry that verdict bound to that diff). An unmet + // precondition fails the node with the expected and actual values instead + // of silently skipping it. + Requires []string `json:"requires,omitempty"` + // VerificationStep marks the node as a verification step: /pass refuses it + // by default and only an explicit override, recorded with its operator, may + // let the run continue past it. The JSON name avoids `verification`, which + // is the removed legacy gate-array field the API strips on save. + VerificationStep bool `json:"verificationStep,omitempty"` + RejectTo string `json:"rejectTo,omitempty"` + OnFailure string `json:"onFailure,omitempty"` // fail, reject + RetryStrategy string `json:"retryStrategy,omitempty"` // targeted_fix, full_redo + CarryOver []string `json:"carryOver,omitempty"` + MaxAttempts int `json:"maxAttempts"` + MaxReworks int `json:"maxReworks"` + Notifications []NodeNotification `json:"notifications,omitempty"` + Position Position `json:"position"` } // ValidateWorkflowMetricStages prevents silently dropping a mistyped stage. diff --git a/internal/engine/bot_control.go b/internal/engine/bot_control.go index 749b53477..bae609048 100644 --- a/internal/engine/bot_control.go +++ b/internal/engine/bot_control.go @@ -1,15 +1,22 @@ package engine import ( + "agentflow/internal/apperr" "agentflow/internal/domain" "fmt" + "strings" ) // NodeExpectation binds chat-card actions to the exact attempt displayed. The // existing engine state lock and persistence conflict checks still apply. +// ArtifactName/ArtifactSHA256 additionally bind a human gate decision to the +// artifact the operator reviewed: the run must still carry that artifact with +// that content hash, or the decision is rejected as stale. type NodeExpectation struct { NodeID, Status string Attempt, ReworkCount int + ArtifactName string + ArtifactSHA256 string } func checkNodeExpectation(run domain.Run, expected []NodeExpectation) error { @@ -19,7 +26,61 @@ func checkNodeExpectation(run domain.Run, expected []NodeExpectation) error { want := expected[0] node := run.Nodes[want.NodeID] if node == nil || node.Status != want.Status || node.Attempt != want.Attempt || node.ReworkCount != want.ReworkCount { - return fmt.Errorf("通知对应的节点状态已变化,请查看最新消息") + return apperr.New(apperr.Conflict, "通知对应的节点状态已变化,请查看最新消息") + } + if strings.TrimSpace(want.ArtifactName) == "" { + return nil + } + artifact := latestRunArtifact(run, want.ArtifactName) + if artifact == nil { + return apperr.Newf(apperr.Conflict, "批准绑定的产物 %q 不在当前 run 中,请查看最新消息", want.ArtifactName). + With("expectedArtifact", want.ArtifactName). + With("expectedSha256", want.ArtifactSHA256) + } + if want.ArtifactSHA256 != "" && !strings.EqualFold(artifact.SHA256, want.ArtifactSHA256) { + return apperr.Newf(apperr.Conflict, "批准绑定的产物 %q 内容已变化:期望 sha256 %s,实际 %s", want.ArtifactName, want.ArtifactSHA256, artifact.SHA256). + With("expectedArtifact", want.ArtifactName). + With("expectedSha256", want.ArtifactSHA256). + With("actualSha256", artifact.SHA256) } return nil } + +// latestRunArtifact returns the newest artifact with this logical name. Old +// attempts stay in the run for audit, and a decision must bind to the newest +// one — binding an older attempt is exactly the stale approval this check +// exists to reject. +func latestRunArtifact(run domain.Run, name string) *domain.Artifact { + var best *domain.Artifact + for i := range run.Artifacts { + artifact := &run.Artifacts[i] + if artifact.Name != name { + continue + } + if best == nil || artifact.Attempt > best.Attempt || artifact.Attempt == best.Attempt && artifact.CreatedAt.After(best.CreatedAt) { + best = artifact + } + } + return best +} + +// auditActor names the operator in control events; an anonymous request is +// still recorded, so the audit trail never reads as if nobody made the call. +func auditActor(actor string) string { + if trimmed := strings.TrimSpace(actor); trimmed != "" { + return trimmed + } + return "未记录操作者" +} + +func describeExpectation(expected []NodeExpectation) string { + if len(expected) == 0 { + return "" + } + want := expected[0] + parts := []string{fmt.Sprintf("status=%s attempt=%d rework=%d", want.Status, want.Attempt, want.ReworkCount)} + if want.ArtifactName != "" { + parts = append(parts, fmt.Sprintf("artifact=%s sha256=%s", want.ArtifactName, want.ArtifactSHA256)) + } + return strings.Join(parts, " ") +} diff --git a/internal/engine/gate_binding_test.go b/internal/engine/gate_binding_test.go new file mode 100644 index 000000000..f2955855a --- /dev/null +++ b/internal/engine/gate_binding_test.go @@ -0,0 +1,123 @@ +package engine + +import ( + "strings" + "testing" + "time" + + "agentflow/internal/apperr" + "agentflow/internal/domain" +) + +func gateBindingRun(id string) domain.Run { + wf := domain.WorkflowDefinition{ + ID: "gate-binding-wf", SandboxProfileID: "local", + Nodes: []domain.WorkflowNode{ + {ID: "verify", Type: "script", ScriptLanguage: "shell", Script: "true", MaxAttempts: 1}, + {ID: "gate", Type: "approval"}, + }, + Edges: []domain.WorkflowEdge{{Source: "verify", Target: "gate"}}, + } + return domain.Run{ + ID: id, WorkflowID: wf.ID, WorkflowSnapshot: wf, Status: "waiting", + Nodes: map[string]*domain.NodeRun{ + "verify": {NodeID: "verify", Status: "succeeded", Attempt: 1}, + "gate": {NodeID: "gate", Status: "waiting_approval", Attempt: 1}, + }, + Artifacts: []domain.Artifact{{ + ID: "artifact-verify", RunID: id, NodeID: "verify", Attempt: 1, + Name: "verify", Path: "verify.json", MediaType: "application/json", + Size: 2, SHA256: "aaaa", Content: "{}", CreatedAt: time.Now().UTC(), + }}, + } +} + +func TestGateBindingApprovesMatchingArtifactHash(t *testing.T) { + e, _ := cvEEngine(t) + e.executeRuns = false + run := gateBindingRun("gate-binding-ok") + cvEPutRun(t, e, run) + + if err := e.Approve(run.ID, "gate", "", NodeExpectation{ + NodeID: "gate", Status: "waiting_approval", Attempt: 1, + ArtifactName: "verify", ArtifactSHA256: "aaaa", + }); err != nil { + t.Fatal(err) + } + got, _ := e.repo.RunState(run.ID) + if got.Nodes["gate"].Status != "succeeded" { + t.Fatalf("gate status = %q, want succeeded", got.Nodes["gate"].Status) + } +} + +func TestGateBindingRejectsMismatchedArtifactHash(t *testing.T) { + e, _ := cvEEngine(t) + e.executeRuns = false + run := gateBindingRun("gate-binding-mismatch") + cvEPutRun(t, e, run) + + err := e.Approve(run.ID, "gate", "", NodeExpectation{ + NodeID: "gate", Status: "waiting_approval", Attempt: 1, + ArtifactName: "verify", ArtifactSHA256: "bbbb", + }) + if err == nil { + t.Fatal("approval with a mismatched artifact hash was accepted") + } + if _, ok := apperr.As(err); !ok { + t.Fatalf("error is not an app error: %v", err) + } + if !strings.Contains(err.Error(), "bbbb") || !strings.Contains(err.Error(), "aaaa") { + t.Fatalf("error %q must name expected and actual hash", err) + } + + got, _ := e.repo.RunState(run.ID) + if got.Nodes["gate"].Status != "waiting_approval" || got.Status != "waiting" { + t.Fatalf("rejected approval changed run: status=%q node=%q", got.Status, got.Nodes["gate"].Status) + } + found := false + for _, event := range got.Events { + if event.Type == "gate.approval_rejected" { + found = true + if !strings.Contains(event.Message, "bbbb") || !strings.Contains(event.Message, "aaaa") { + t.Fatalf("audit event %q must name expected and actual hash", event.Message) + } + } + } + if !found { + t.Fatalf("gate.approval_rejected audit event missing: %+v", got.Events) + } +} + +func TestGateBindingRejectsMissingArtifact(t *testing.T) { + e, _ := cvEEngine(t) + e.executeRuns = false + run := gateBindingRun("gate-binding-missing") + cvEPutRun(t, e, run) + + err := e.Approve(run.ID, "gate", "", NodeExpectation{ + NodeID: "gate", Status: "waiting_approval", Attempt: 1, + ArtifactName: "absent", ArtifactSHA256: "aaaa", + }) + if err == nil || !strings.Contains(err.Error(), "absent") { + t.Fatalf("missing artifact must reject approval naming it, got %v", err) + } + got, _ := e.repo.RunState(run.ID) + if got.Nodes["gate"].Status != "waiting_approval" { + t.Fatalf("gate status = %q, want waiting_approval", got.Nodes["gate"].Status) + } +} + +func TestGateBindingWithoutExpectedKeepsLegacyBehavior(t *testing.T) { + e, _ := cvEEngine(t) + e.executeRuns = false + run := gateBindingRun("gate-binding-legacy") + cvEPutRun(t, e, run) + + if err := e.Approve(run.ID, "gate", ""); err != nil { + t.Fatal(err) + } + got, _ := e.repo.RunState(run.ID) + if got.Nodes["gate"].Status != "succeeded" { + t.Fatalf("gate status = %q, want succeeded", got.Nodes["gate"].Status) + } +} diff --git a/internal/engine/node_execute.go b/internal/engine/node_execute.go index cafa1b8a3..3ad7b3859 100644 --- a/internal/engine/node_execute.go +++ b/internal/engine/node_execute.go @@ -165,6 +165,10 @@ func (e *Engine) execute(ctx context.Context, runID string) { } for _, node := range ready { node := node + if err := checkNodeRequires(r, node); err != nil { + e.nodeRequirementFailed(runID, node, generation, err) + continue + } inflightMu.Lock() inflight[node.ID] = true inflightMu.Unlock() diff --git a/internal/engine/node_requires.go b/internal/engine/node_requires.go new file mode 100644 index 000000000..0aeccadde --- /dev/null +++ b/internal/engine/node_requires.go @@ -0,0 +1,138 @@ +package engine + +import ( + "encoding/json" + "fmt" + "path/filepath" + "strings" + "time" + + "agentflow/internal/domain" +) + +// verdictArtifactNames are the artifact names a verdict requirement reads. The +// verification sidecar publishes its JSON judgement under one of these. +var verdictArtifactNames = []string{"verdict", "verify.json"} + +type nodeRequirement struct { + kind string // artifact, verdict + name string // artifact name (kind=artifact) + want string // expected sha256 (kind=artifact) or verdict (kind=verdict) + diffHash string // expected diff hash (kind=verdict) +} + +// parseNodeRequirement parses the two supported precondition forms. Validation +// rejects malformed values at publish time so a typo never waits for a run. +func parseNodeRequirement(raw string) (nodeRequirement, error) { + value := strings.TrimSpace(raw) + kind, rest, ok := strings.Cut(value, ":") + if !ok { + return nodeRequirement{}, fmt.Errorf("expected artifact:@ or verdict:@") + } + target, hash, ok := strings.Cut(rest, "@") + target, hash = strings.TrimSpace(target), strings.TrimSpace(hash) + switch kind { + case "artifact": + if target == "" || hash == "" { + return nodeRequirement{}, fmt.Errorf("artifact requires a name and a sha256") + } + return nodeRequirement{kind: kind, name: target, want: hash}, nil + case "verdict": + verdict := strings.ToUpper(target) + if verdict != "PASS" && verdict != "FAIL" || hash == "" { + return nodeRequirement{}, fmt.Errorf("verdict requires PASS or FAIL and a diff hash") + } + return nodeRequirement{kind: kind, want: verdict, diffHash: hash}, nil + default: + return nodeRequirement{}, fmt.Errorf("unsupported requirement kind %q", kind) + } +} + +// checkNodeRequires reports the first unmet precondition with the expected and +// actual values, so the failed node explains itself without a log hunt. +func checkNodeRequires(run domain.Run, node domain.WorkflowNode) error { + for _, raw := range node.Requires { + requirement, err := parseNodeRequirement(raw) + if err != nil { + return fmt.Errorf("节点 %s 的前置条件 %q 无法解析:%w", node.ID, raw, err) + } + if err := requirement.unmet(run); err != nil { + return fmt.Errorf("节点 %s 的前置条件 %q 不满足:%w", node.ID, raw, err) + } + } + return nil +} + +func (requirement nodeRequirement) unmet(run domain.Run) error { + switch requirement.kind { + case "artifact": + artifact := latestRunArtifact(run, requirement.name) + if artifact == nil { + return fmt.Errorf("run 中没有产物 %q(期望 sha256 %s)", requirement.name, requirement.want) + } + if !strings.EqualFold(artifact.SHA256, requirement.want) { + return fmt.Errorf("产物 %q 的 sha256 为 %s,期望 %s", requirement.name, artifact.SHA256, requirement.want) + } + return nil + case "verdict": + artifact := latestVerdictArtifact(run) + if artifact == nil { + return fmt.Errorf("run 中没有判定产物(%s),期望 verdict=%s diffHash=%s", strings.Join(verdictArtifactNames, "/"), requirement.want, requirement.diffHash) + } + var document struct { + Verdict string `json:"verdict"` + DiffHash string `json:"diffHash"` + } + if err := json.Unmarshal([]byte(artifact.Content), &document); err != nil { + return fmt.Errorf("判定产物 %q 不是合法 JSON:%v", artifact.Name, err) + } + if !strings.EqualFold(strings.TrimSpace(document.Verdict), requirement.want) { + return fmt.Errorf("判定产物 %q 的 verdict 为 %q,期望 %q", artifact.Name, document.Verdict, requirement.want) + } + if !strings.EqualFold(strings.TrimSpace(document.DiffHash), requirement.diffHash) { + return fmt.Errorf("判定产物 %q 的 diffHash 为 %q,期望 %q", artifact.Name, document.DiffHash, requirement.diffHash) + } + return nil + default: + return fmt.Errorf("unsupported requirement kind %q", requirement.kind) + } +} + +func latestVerdictArtifact(run domain.Run) *domain.Artifact { + var best *domain.Artifact + for i := range run.Artifacts { + artifact := &run.Artifacts[i] + matches := false + for _, name := range verdictArtifactNames { + if artifact.Name == name || filepath.Base(artifact.Path) == name { + matches = true + break + } + } + if !matches { + continue + } + if best == nil || artifact.Attempt > best.Attempt || artifact.Attempt == best.Attempt && artifact.CreatedAt.After(best.CreatedAt) { + best = artifact + } + } + return best +} + +// nodeRequirementFailed parks the node as failed without consuming an attempt: +// a deterministic precondition will not change on retry. +func (e *Engine) nodeRequirementFailed(runID string, node domain.WorkflowNode, generation int, err error) { + e.updateRun(runID, func(r *domain.Run) { + if r.Generation != generation { + return + } + nr := r.Nodes[node.ID] + if nr == nil || nr.Status != "pending" { + return + } + nr.Status = "failed" + nr.FinishedAt = time.Now().UTC() + nr.Error = err.Error() + e.event(r, node.ID, "node.failed", err.Error()) + }) +} diff --git a/internal/engine/node_requires_test.go b/internal/engine/node_requires_test.go new file mode 100644 index 000000000..cf3b767d9 --- /dev/null +++ b/internal/engine/node_requires_test.go @@ -0,0 +1,124 @@ +package engine + +import ( + "crypto/sha256" + "fmt" + "strings" + "testing" + + "agentflow/internal/domain" + "agentflow/internal/repo" + "agentflow/internal/runtime" +) + +func requiresWorkflow(id, requirement string) domain.WorkflowDefinition { + return domain.WorkflowDefinition{ + ID: id, Name: id, SandboxProfileID: "local", + Nodes: []domain.WorkflowNode{ + {ID: "produce", Name: "Produce", Type: "script", ScriptLanguage: "shell", + Script: `printf '%s' '{"verdict":"PASS","diffHash":"d1"}' > verify.json`, MaxAttempts: 1, + ArtifactOutputs: []domain.ArtifactContract{{Name: "verify", Path: "verify.json", MediaType: "application/json", Required: true}}}, + {ID: "consume", Name: "Consume", Type: "script", ScriptLanguage: "shell", + Script: "printf ran > ran.txt", MaxAttempts: 1, + ArtifactOutputs: []domain.ArtifactContract{{Name: "ran", Path: "ran.txt", Required: true}}, + Requires: []string{requirement}}, + }, + Edges: []domain.WorkflowEdge{{ID: "produce-consume", Source: "produce", Target: "consume", When: "success"}}, + } +} + +func TestNodeRequiresArtifactHashMismatchStopsNode(t *testing.T) { + t.Parallel() + s, err := repo.OpenTest() + if err != nil { + t.Fatal(err) + } + defer s.Close() + wf := requiresWorkflow("requires-mismatch", "artifact:verify@deadbeef") + if err := s.PutWorkflow(wf); err != nil { + t.Fatal(err) + } + e := New(s, runtime.NewManagerWithLimit(t.TempDir(), 1)) + run, err := e.Start(wf.ID, "") + if err != nil { + t.Fatal(err) + } + waitFor(t, s, run.ID, "failed") + finished, _ := s.Run(run.ID) + consume := finished.Nodes["consume"] + if consume == nil || consume.Status != "failed" { + t.Fatalf("consume = %+v, want failed", consume) + } + var actual string + for _, artifact := range finished.Artifacts { + if artifact.Name == "verify" { + actual = artifact.SHA256 + } + if artifact.Name == "ran" { + t.Fatalf("required node executed and produced an artifact: %+v", artifact) + } + } + if actual == "" { + t.Fatalf("produce did not publish the verify artifact: %+v", finished.Artifacts) + } + if !strings.Contains(consume.Error, "deadbeef") || !strings.Contains(consume.Error, actual) { + t.Fatalf("error %q must name expected and actual hash %s", consume.Error, actual) + } +} + +func TestNodeRequiresMatchingArtifactHashRuns(t *testing.T) { + t.Parallel() + s, err := repo.OpenTest() + if err != nil { + t.Fatal(err) + } + defer s.Close() + sum := sha256.Sum256([]byte(`{"verdict":"PASS","diffHash":"d1"}`)) + wf := requiresWorkflow("requires-match", fmt.Sprintf("artifact:verify@%x", sum)) + if err := s.PutWorkflow(wf); err != nil { + t.Fatal(err) + } + e := New(s, runtime.NewManagerWithLimit(t.TempDir(), 1)) + run, err := e.Start(wf.ID, "") + if err != nil { + t.Fatal(err) + } + waitFor(t, s, run.ID, "succeeded") + finished, _ := s.Run(run.ID) + if finished.Nodes["consume"] == nil || finished.Nodes["consume"].Status != "succeeded" { + t.Fatalf("consume = %+v, want succeeded", finished.Nodes["consume"]) + } +} + +func TestNodeRequiresVerdictMustMatch(t *testing.T) { + t.Parallel() + s, err := repo.OpenTest() + if err != nil { + t.Fatal(err) + } + defer s.Close() + wf := requiresWorkflow("requires-verdict-reject", "verdict:FAIL@d1") + if err := s.PutWorkflow(wf); err != nil { + t.Fatal(err) + } + e := New(s, runtime.NewManagerWithLimit(t.TempDir(), 1)) + run, err := e.Start(wf.ID, "") + if err != nil { + t.Fatal(err) + } + waitFor(t, s, run.ID, "failed") + finished, _ := s.Run(run.ID) + consume := finished.Nodes["consume"] + if consume == nil || consume.Status != "failed" || !strings.Contains(consume.Error, "FAIL") || !strings.Contains(consume.Error, "PASS") { + t.Fatalf("consume = %+v, want failed naming expected FAIL and actual PASS", consume) + } +} + +func TestWorkflowValidationRejectsMalformedRequires(t *testing.T) { + for _, requirement := range []string{"verify@abc", "artifact:verify", "verdict:PASS", "artifact:@abc"} { + wf := requiresWorkflow("requires-invalid-"+strings.NewReplacer(":", "-", "@", "-").Replace(requirement), requirement) + if err := validate(wf); err == nil { + t.Fatalf("validate accepted malformed requirement %q", requirement) + } + } +} diff --git a/internal/engine/pass_override_test.go b/internal/engine/pass_override_test.go new file mode 100644 index 000000000..88d569700 --- /dev/null +++ b/internal/engine/pass_override_test.go @@ -0,0 +1,92 @@ +package engine + +import ( + "strings" + "testing" + + "agentflow/internal/domain" +) + +func verificationPassRun(id string) domain.Run { + wf := domain.WorkflowDefinition{ + ID: "pass-override-wf", SandboxProfileID: "local", + Nodes: []domain.WorkflowNode{ + {ID: "verify", Name: "Verify", Type: "script", ScriptLanguage: "shell", Script: "exit 1", MaxAttempts: 1, VerificationStep: true}, + {ID: "ship", Name: "Ship", Type: "script", ScriptLanguage: "shell", Script: "true", MaxAttempts: 1}, + }, + Edges: []domain.WorkflowEdge{{Source: "verify", Target: "ship"}}, + } + return domain.Run{ + ID: id, WorkflowID: wf.ID, WorkflowSnapshot: wf, Status: "failed", + Nodes: map[string]*domain.NodeRun{ + "verify": {NodeID: "verify", Status: "failed", Attempt: 1, Error: "exit status 1"}, + "ship": {NodeID: "ship", Status: "pending"}, + }, + } +} + +func TestPassRejectsVerificationNodeWithoutOverride(t *testing.T) { + e, _ := cvEEngine(t) + e.executeRuns = false + run := verificationPassRun("pass-override-reject") + cvEPutRun(t, e, run) + + err := e.Pass(run.ID, "verify", "environment broke the check") + if err == nil { + t.Fatal("verification node was passed without an override") + } + if !strings.Contains(err.Error(), "override") { + t.Fatalf("error %q must name the override switch", err) + } + got, _ := e.repo.RunState(run.ID) + if got.Nodes["verify"].Status != "failed" { + t.Fatalf("verify status = %q, want failed", got.Nodes["verify"].Status) + } + if !hasRunEvent(got, "node.pass_rejected") { + t.Fatalf("node.pass_rejected audit event missing: %+v", got.Events) + } +} + +func TestPassOverridePassesVerificationNodeAndRecordsActor(t *testing.T) { + e, _ := cvEEngine(t) + e.executeRuns = false + run := verificationPassRun("pass-override-accept") + cvEPutRun(t, e, run) + + err := e.PassWithOptions(run.ID, "verify", "flake, rerun manually", PassOptions{Override: true, Actor: "alice"}) + if err != nil { + t.Fatal(err) + } + got, _ := e.repo.RunState(run.ID) + if got.Nodes["verify"].Status != "succeeded" { + t.Fatalf("verify status = %q, want succeeded", got.Nodes["verify"].Status) + } + found := false + for _, event := range got.Events { + if event.Type == "node.passed_override" { + found = true + if !strings.Contains(event.Message, "alice") { + t.Fatalf("override event %q must name the operator", event.Message) + } + } + } + if !found { + t.Fatalf("node.passed_override audit event missing: %+v", got.Events) + } +} + +func TestPassKeepsWorkingForNonVerificationScriptNode(t *testing.T) { + e, _ := cvEEngine(t) + e.executeRuns = false + run := verificationPassRun("pass-override-plain") + run.WorkflowSnapshot.Nodes[0].VerificationStep = false + cvEPutRun(t, e, run) + + if err := e.Pass(run.ID, "verify", ""); err != nil { + t.Fatal(err) + } + got, _ := e.repo.RunState(run.ID) + if got.Nodes["verify"].Status != "succeeded" { + t.Fatalf("verify status = %q, want succeeded", got.Nodes["verify"].Status) + } +} diff --git a/internal/engine/run_ops.go b/internal/engine/run_ops.go index 24c1af67e..4af413a06 100644 --- a/internal/engine/run_ops.go +++ b/internal/engine/run_ops.go @@ -1,6 +1,7 @@ package engine import ( + "agentflow/internal/apperr" "agentflow/internal/domain" "agentflow/internal/repo" "context" @@ -155,6 +156,7 @@ func (e *Engine) Approve(runID, nodeID, humanContext string, expected ...NodeExp } } if err := checkNodeExpectation(r, expected); err != nil { + e.recordGateRejection(runID, &r, nodeID, expected, err) return err } if err := forbidClosedGongfengIssue(e.repo, r); err != nil { @@ -178,20 +180,57 @@ func (e *Engine) Approve(runID, nodeID, humanContext string, expected ...NodeExp return e.persistControlDecision(runID, r, expected...) } +// recordGateRejection keeps a rejected human decision in the run's audit trail +// while leaving the node parked at waiting_approval, so an approval aimed at a +// stale artifact cannot disappear without a record of what was expected. +func (e *Engine) recordGateRejection(runID string, r *domain.Run, nodeID string, expected []NodeExpectation, reason error) { + message := fmt.Sprintf("人工批准被拒绝:%s(期望 %s)", reason.Error(), describeExpectation(expected)) + e.persistAuditEvent(runID, r, nodeID, "gate.approval_rejected", message) +} + +// persistAuditEvent stores one control decision record without changing run or +// node status. The caller holds stateMu. +func (e *Engine) persistAuditEvent(runID string, r *domain.Run, nodeID, typ, message string) { + e.event(r, nodeID, typ, message) + appendControlTelemetry(r, nodeID, typ, message) + if err := e.repo.PutRun(*r); err != nil { + log.Printf("record %s %s: %v", typ, runID, err) + return + } + e.publish(runID) + if !e.executes() && r.OwnerInstanceID != "" { + _ = e.repo.ReleaseRunLease(runID, r.OwnerInstanceID, r.Generation) + } +} + +// PassOptions carries who overrode a verification node and why the override is +// allowed. A plain Pass never overrides; only an explicit request does. +type PassOptions struct { + Override bool + Actor string +} + // Pass marks a failed (or paused) node as succeeded so downstream can // continue without re-executing it. Operators use this after onFailure=fail, // when reject reworks are exhausted, or when a hard script is paused // mid-execution and retrying from scratch won't help (e.g. an environment // problem) — hard scripts can otherwise stall a run forever. func (e *Engine) Pass(runID, nodeID, humanContext string, expected ...NodeExpectation) error { - if err := e.pass(runID, nodeID, humanContext, expected...); err != nil { + return e.PassWithOptions(runID, nodeID, humanContext, PassOptions{}, expected...) +} + +// PassWithOptions is Pass plus the explicit override a verification node needs. +// Without Override a verification node stays failed and the request only leaves +// an audit record; with it the operator named in Actor is recorded too. +func (e *Engine) PassWithOptions(runID, nodeID, humanContext string, opts PassOptions, expected ...NodeExpectation) error { + if err := e.pass(runID, nodeID, humanContext, opts, expected...); err != nil { return err } e.resumeParentAfterChildRecovery(runID) return nil } -func (e *Engine) pass(runID, nodeID, humanContext string, expected ...NodeExpectation) error { +func (e *Engine) pass(runID, nodeID, humanContext string, opts PassOptions, expected ...NodeExpectation) error { e.stateMu.Lock() defer e.stateMu.Unlock() r, ok := e.repo.RunState(runID) @@ -246,6 +285,11 @@ func (e *Engine) pass(runID, nodeID, humanContext string, expected ...NodeExpect if !found || !isScriptNode(def) { return fmt.Errorf("only a failed script node can be passed") } + if def.VerificationStep && !opts.Override { + message := fmt.Sprintf("拒绝人工通过验证节点:operator=%s context=%q", auditActor(opts.Actor), humanContext) + e.persistAuditEvent(runID, &r, nodeID, "node.pass_rejected", message) + return apperr.New(apperr.Conflict, "该节点标记为验证节点,/pass 不能绕过验证;如确需人工放行,请在请求中带 override:true") + } n.Status = "succeeded" n.FinishedAt = time.Now().UTC() n.Activity = "人工通过,未重新执行" @@ -261,6 +305,11 @@ func (e *Engine) pass(runID, nodeID, humanContext string, expected ...NodeExpect appendArtifact(&r, nodeID, n.Attempt, "decision", "decision.md", "text/markdown", []byte(decision)) e.event(&r, nodeID, "node.passed", "人工通过该节点,继续下游") appendControlTelemetry(&r, nodeID, "node.passed", "人工通过该节点,继续下游") + if def.VerificationStep { + message := fmt.Sprintf("人工 override 通过验证节点:operator=%s context=%q", auditActor(opts.Actor), humanContext) + e.event(&r, nodeID, "node.passed_override", message) + appendControlTelemetry(&r, nodeID, "node.passed_override", message) + } r.CancelRequested = false r.PauseRequested = false r.Status = "running" diff --git a/internal/engine/workflow_graph.go b/internal/engine/workflow_graph.go index d4d299c32..08e46d6bf 100644 --- a/internal/engine/workflow_graph.go +++ b/internal/engine/workflow_graph.go @@ -223,6 +223,11 @@ func validateNode(workflowID string, n domain.WorkflowNode) error { if n.RetryStrategy != "" && n.RetryStrategy != "targeted_fix" && n.RetryStrategy != "full_redo" { return fmt.Errorf("node %s has invalid retryStrategy %q", n.ID, n.RetryStrategy) } + for _, raw := range n.Requires { + if _, err := parseNodeRequirement(raw); err != nil { + return fmt.Errorf("node %s has invalid requires %q: %w", n.ID, raw, err) + } + } artifactNames := map[string]bool{} for _, contract := range n.ArtifactOutputs { clean := filepath.Clean(contract.Path) diff --git a/internal/httpapi/auth_tokens.go b/internal/httpapi/auth_tokens.go index 002a5166e..685cc6512 100644 --- a/internal/httpapi/auth_tokens.go +++ b/internal/httpapi/auth_tokens.go @@ -130,6 +130,19 @@ func (d deps) requestUser(r *http.Request, allowBearer bool) (*auth.User, bool) return user, true } +// requestActor names the signed-in operator for audit records. Anonymous calls +// return an empty string and the engine records that fact instead of a name. +func requestActor(d *deps, r *http.Request) string { + user, ok := d.requestUser(r, true) + if !ok { + return "" + } + if name := strings.TrimSpace(user.ChineseName); name != "" { + return name + } + return strings.TrimSpace(user.LoginName) +} + func bearerToken(r *http.Request) (string, bool) { value := strings.TrimSpace(r.Header.Get("Authorization")) scheme, raw, ok := strings.Cut(value, " ") diff --git a/internal/httpapi/gate_binding_http_test.go b/internal/httpapi/gate_binding_http_test.go new file mode 100644 index 000000000..49462746a --- /dev/null +++ b/internal/httpapi/gate_binding_http_test.go @@ -0,0 +1,120 @@ +package httpapi + +import ( + "bytes" + "encoding/json" + "net/http" + "net/http/httptest" + "strings" + "testing" + "time" + + "agentflow/internal/domain" + "agentflow/internal/engine" + "agentflow/internal/repo" + + "github.com/gin-gonic/gin" +) + +func bindingServer(t *testing.T) (*repo.Store, *gin.Engine) { + t.Helper() + s, err := repo.OpenTest() + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { s.Close() }) + e := engine.New(s, nil) + e.ConfigureExecution("api", "test", time.Minute, false) + h := &runsHandlers{deps: &deps{repo: s, engine: e}} + gin.SetMode(gin.TestMode) + g := gin.New() + g.POST("/api/runs/:id/approve", h.run) + g.POST("/api/runs/:id/pass", h.run) + return s, g +} + +func postControl(t *testing.T, g *gin.Engine, path string, body any) (int, string) { + t.Helper() + raw, err := json.Marshal(body) + if err != nil { + t.Fatal(err) + } + req := httptest.NewRequest(http.MethodPost, path, bytes.NewReader(raw)) + req.Header.Set("Content-Type", "application/json") + w := httptest.NewRecorder() + g.ServeHTTP(w, req) + return w.Code, w.Body.String() +} + +func TestApproveHTTPRejectsStaleArtifactWithConflict(t *testing.T) { + s, g := bindingServer(t) + wf := domain.WorkflowDefinition{ + ID: "http-binding-wf", SandboxProfileID: "local", + Nodes: []domain.WorkflowNode{{ID: "verify", Type: "script", ScriptLanguage: "shell", Script: "true", MaxAttempts: 1}, {ID: "gate", Type: "approval"}}, + } + run := domain.Run{ + ID: "http-binding-run", WorkflowID: wf.ID, WorkflowSnapshot: wf, Status: "waiting", + Nodes: map[string]*domain.NodeRun{ + "verify": {NodeID: "verify", Status: "succeeded", Attempt: 1}, + "gate": {NodeID: "gate", Status: "waiting_approval", Attempt: 1}, + }, + Artifacts: []domain.Artifact{{ID: "a", RunID: "http-binding-run", NodeID: "verify", Attempt: 1, Name: "verify", Path: "verify.json", SHA256: "aaaa", CreatedAt: time.Now().UTC()}}, + } + if err := s.PutRun(run); err != nil { + t.Fatal(err) + } + + code, body := postControl(t, g, "/api/runs/http-binding-run/approve", map[string]any{ + "nodeId": "gate", + "expected": map[string]any{ + "status": "waiting_approval", "attempt": 1, "artifactName": "verify", "artifactSha256": "bbbb", + }, + }) + if code != http.StatusConflict { + t.Fatalf("stale approve = %d %s, want 409", code, body) + } + if !strings.Contains(body, "bbbb") || !strings.Contains(body, "aaaa") { + t.Fatalf("conflict body %q must name expected and actual hash", body) + } + stored, _ := s.RunState(run.ID) + if stored.Nodes["gate"].Status != "waiting_approval" { + t.Fatalf("gate status = %q, want waiting_approval", stored.Nodes["gate"].Status) + } +} + +func TestPassHTTPRequiresOverrideForVerificationNode(t *testing.T) { + s, g := bindingServer(t) + wf := domain.WorkflowDefinition{ + ID: "http-pass-wf", SandboxProfileID: "local", + Nodes: []domain.WorkflowNode{ + {ID: "verify", Name: "Verify", Type: "script", ScriptLanguage: "shell", Script: "exit 1", MaxAttempts: 1, VerificationStep: true}, + }, + } + run := domain.Run{ + ID: "http-pass-run", WorkflowID: wf.ID, WorkflowSnapshot: wf, Status: "failed", + Nodes: map[string]*domain.NodeRun{ + "verify": {NodeID: "verify", Status: "failed", Attempt: 1, Error: "exit status 1"}, + }, + } + if err := s.PutRun(run); err != nil { + t.Fatal(err) + } + + code, body := postControl(t, g, "/api/runs/http-pass-run/pass", map[string]any{"nodeId": "verify"}) + if code != http.StatusConflict { + t.Fatalf("pass without override = %d %s, want 409", code, body) + } + stored, _ := s.RunState(run.ID) + if stored.Nodes["verify"].Status != "failed" { + t.Fatalf("verify status = %q, want failed", stored.Nodes["verify"].Status) + } + + code, body = postControl(t, g, "/api/runs/http-pass-run/pass", map[string]any{"nodeId": "verify", "override": true}) + if code != http.StatusOK { + t.Fatalf("pass with override = %d %s, want 200", code, body) + } + stored, _ = s.RunState(run.ID) + if stored.Nodes["verify"].Status != "succeeded" { + t.Fatalf("verify status = %q, want succeeded", stored.Nodes["verify"].Status) + } +} diff --git a/internal/httpapi/runs.go b/internal/httpapi/runs.go index 0b4a757ba..7787da9e8 100644 --- a/internal/httpapi/runs.go +++ b/internal/httpapi/runs.go @@ -304,7 +304,7 @@ func (h *runsHandlers) run(c *gin.Context) { if rejectBlockedIssueRun(h.deps, c, id) { return } - respond(c, h.engine.Pass(id, req.NodeID, req.Context)) + respond(c, h.engine.PassWithOptions(id, req.NodeID, req.Context, engine.PassOptions{Override: req.Override, Actor: requestActor(h.deps, c.Request)})) } default: c.Status(http.StatusNotFound) @@ -498,5 +498,5 @@ func decisionExpectation(nodeID string, expected *domain.NodeDecisionExpectation if expected == nil { return nil } - return []engine.NodeExpectation{{NodeID: nodeID, Status: expected.Status, Attempt: expected.Attempt, ReworkCount: expected.ReworkCount}} + return []engine.NodeExpectation{{NodeID: nodeID, Status: expected.Status, Attempt: expected.Attempt, ReworkCount: expected.ReworkCount, ArtifactName: expected.ArtifactName, ArtifactSHA256: expected.ArtifactSHA256}} } From f5c9ac2569ae62d7b279d3760ba66ad411ec38f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B4=AA=E5=88=9A?= <11776741+chgJava@user.noreply.gitee.com> Date: Tue, 17 Nov 2026 23:48:20 +0800 Subject: [PATCH 2/2] fix(engine): harden approval binding and audit writes Review fixes for the approval-binding change: - Half an artifact binding (name without hash or hash without name) is now a 400, not a silently unbound approval. - The rejection audit releases only the lease it acquired and never a worker's live lease, and writes with the revision guard, re-applying the event to the newest snapshot on conflict. - Artifact recency is creation time, not attempt number: attempts are per node, so cross-node attempt comparison picked the wrong artifact. - A requires check is deferred while a sibling is still in flight, so a parallel producer cannot cause a spurious permanent failure. - The SOP overlay carries requires/verificationStep on retry. - Docs/OpenAPI: expected fan-out, half-binding rule, run-global artifact names, verdict case/whitespace, basename, parallel-producer rule, and the scope of /pass versus /approve on a verification step. Co-Authored-By: Claude Code --- docs/api/openapi.yaml | 5 ++- docs/api/orchestration.md | 2 +- docs/enhancements/approval-binding.md | 14 ++++---- internal/domain/issue.go | 6 ++-- internal/engine/bot_control.go | 38 +++++++++++++-------- internal/engine/gate_binding_test.go | 48 +++++++++++++++++++++++++++ internal/engine/node_execute.go | 17 ++++++++++ internal/engine/node_requires.go | 8 +++-- internal/engine/node_requires_test.go | 35 +++++++++++++++++++ internal/engine/pass_override_test.go | 21 ++++++++++++ internal/engine/run_ops.go | 31 ++++++++++++++--- 11 files changed, 192 insertions(+), 33 deletions(-) diff --git a/docs/api/openapi.yaml b/docs/api/openapi.yaml index 7cccea3fc..5cf0bc206 100644 --- a/docs/api/openapi.yaml +++ b/docs/api/openapi.yaml @@ -3812,7 +3812,7 @@ components: description: Required to pass a node marked verificationStep; the request is audited with its operator. expected: type: object - description: Binds the decision to the attempt (and optionally the artifact) the operator reviewed. A mismatch returns 409 and leaves the node waiting. + description: Binds the decision to the attempt (and optionally the artifact) the operator reviewed. Honoured by approve, reject, retry, decline-retry and resume; a mismatch returns 409 and leaves the node waiting. artifactName and artifactSha256 must be supplied together (400 otherwise) and bind to the newest artifact of that name by creation time. properties: status: {type: string} attempt: {type: integer} @@ -4923,10 +4923,9 @@ components: type: integer requires: type: array - description: Preconditions checked before the node executes. An unmet precondition fails the node with the expected and actual values. + description: "Preconditions checked before the node executes: artifact:@ or verdict:@. Values are trimmed and the verdict is case-insensitive. An unmet precondition fails the node with the expected and actual values when no sibling is still running; a parallel producer must be an upstream edge." items: type: string - pattern: "^(artifact:[^@]+@.+|verdict:(PASS|FAIL)@.+)$" verificationStep: type: boolean description: Marks a verification step. /pass refuses it unless the request carries override=true; both outcomes are audited. diff --git a/docs/api/orchestration.md b/docs/api/orchestration.md index c37f71f28..7a0b77922 100644 --- a/docs/api/orchestration.md +++ b/docs/api/orchestration.md @@ -238,7 +238,7 @@ curl -u "$AGENTFLOW_USER:$AGENTFLOW_PASS" -OJ \ } ``` -`artifactName`/`artifactSha256` 校验当前 run 中该名字的**最新**产物仍带这个内容哈希。节点状态或产物哈希任一不匹配时返回 `409`,节点保持 `waiting_approval`,run 追加 `gate.approval_rejected` 审计事件(写明期望值与实际值)。不带 `expected` 时行为不变。 +`artifactName`/`artifactSha256` 必须同时提供,校验当前 run 中该名字的**最新**产物(按创建时间)仍带这个内容哈希;只给其中一半返回 `400`(避免看起来绑定了实际没有)。节点状态或产物哈希任一不匹配时返回 `409`,节点保持 `waiting_approval`,run 追加 `gate.approval_rejected` 审计事件(写明期望值与实际值)。同一 `expected` 校验也作用于 `/reject`、`/retry`、`/decline-retry`、`/resume`。不带 `expected` 时行为不变。 ### `POST /api/runs/{runId}/pass` diff --git a/docs/enhancements/approval-binding.md b/docs/enhancements/approval-binding.md index 03312b184..e78f5b466 100644 --- a/docs/enhancements/approval-binding.md +++ b/docs/enhancements/approval-binding.md @@ -3,7 +3,7 @@ This change upgrades two conventions into engine guarantees: 1. A human approval can be bound to the exact artifact the operator reviewed, so an approval aimed at a stale run state is rejected instead of silently approving something else. -2. A verification node cannot be bypassed with `POST /api/runs/{id}/pass`; an explicit, audited override is required. +2. A verification node cannot be bypassed with `POST /api/runs/{id}/pass`; an explicit, audited override is required. `POST /api/runs/{id}/approve` on such a node (parked by a pause or the rework-budget human gate) remains an explicit human decision: it still writes `gate.approved` and the `decision` artifact, but it is not the `/pass` bypass and is out of P4's scope. It follows the enhancement plan in `plan.md` (P2–P4). P5 (sidecar integration with AegisOS) is not part of this change. @@ -38,6 +38,8 @@ On mismatch the engine returns an `apperr.Conflict` (HTTP `409`), appends `gate. } ``` +The lookup is run-global by artifact name: if two nodes publish the same name, the newest creation wins for both binding and `requires`. Artifact names are only unique within a node by validation, so a workflow that needs two distinct `verify` artifacts must give them distinct names. + Omitting `expected` keeps the old behavior. ## P3 — node preconditions with `requires` @@ -45,9 +47,9 @@ Omitting `expected` keeps the old behavior. `WorkflowNode.requires` accepts: - `artifact:@`: the run must carry that artifact with that hash; -- `verdict:@`: the newest verdict artifact (named `verdict`, or whose path is `verify.json`) must be JSON with `verdict` and `diffHash` matching. +- `verdict:@`: the newest verdict artifact (named `verdict`, or whose path basename is `verify.json`) must be JSON with `verdict` and `diffHash` matching (case-insensitive). -Malformed values are rejected at workflow validation. At execution the scheduler checks the preconditions before spawning the node; an unmet precondition fails the node with the expected and actual values (no silent skip, no retry — a deterministic precondition will not change). +Malformed values are rejected at workflow validation, which runs when a run starts (and on `RefreshRunSOP`); the save path does not call it, so a typo is reported at start. At execution the scheduler checks the preconditions before spawning the node. An unmet precondition fails the node with the expected and actual values; the failure bypasses `onFailure`, `MaxReworks` and the retry policy because a deterministic precondition will not change on retry. If a sibling node is still in flight, the check is deferred until it settles — a parallel producer must still be wired as an upstream edge, otherwise the consumer can be failed before that producer becomes ready. ```json { @@ -69,9 +71,9 @@ Non-verification script nodes keep the previous behavior, so the environment-pro ## Tests -- `internal/engine/gate_binding_test.go`: matching hash approves, mismatched/missing artifact rejects and audits, omitted `expected` unchanged. -- `internal/engine/node_requires_test.go`: artifact hash mismatch stops the consumer with expected+actual, matching hash runs it, verdict mismatch names both, malformed `requires` fails validation. -- `internal/engine/pass_override_test.go`: verification node rejects `/pass` and audits; override passes and records the actor; plain script node unchanged. +- `internal/engine/gate_binding_test.go`: matching hash approves, mismatched/missing artifact rejects and audits, half-filled binding returns an error, the newest artifact by creation time wins over a higher attempt number on an older artifact, omitted `expected` unchanged. +- `internal/engine/node_requires_test.go`: artifact hash mismatch stops the consumer with expected+actual, matching hash runs it, verdict mismatch names both, malformed verdict JSON names the artifact, malformed `requires` fails validation. +- `internal/engine/pass_override_test.go`: verification node rejects `/pass` and audits — on a failed run and on a paused script — override passes and records the actor; plain script node unchanged. - `internal/httpapi/gate_binding_http_test.go`: HTTP `409` for a stale approval and for `/pass` without override, `200` with override. Run with `GOFLAGS=-buildvcs=false go test ./internal/engine ./internal/httpapi` when the checkout sits under a directory tree that also contains an `.svn` directory (Go's VCS stamping refuses the nested build otherwise). diff --git a/internal/domain/issue.go b/internal/domain/issue.go index 4a48ae8ce..4b4001e3a 100644 --- a/internal/domain/issue.go +++ b/internal/domain/issue.go @@ -384,8 +384,10 @@ type HumanDecision struct { NodeID string `json:"nodeId"` Reason string `json:"reason,omitempty"` Context string `json:"context,omitempty"` - // Override lets /pass through a node marked verification:true. The request - // is still audited with its operator; without it the pass is refused. + // Override lets /pass through a node marked verificationStep:true. The + // request is still audited with its operator; without it the pass is + // refused. The field is shared with approve/retry/resume bodies, which + // ignore it. Override bool `json:"override,omitempty"` } diff --git a/internal/engine/bot_control.go b/internal/engine/bot_control.go index bae609048..711a3133e 100644 --- a/internal/engine/bot_control.go +++ b/internal/engine/bot_control.go @@ -25,22 +25,32 @@ func checkNodeExpectation(run domain.Run, expected []NodeExpectation) error { } want := expected[0] node := run.Nodes[want.NodeID] - if node == nil || node.Status != want.Status || node.Attempt != want.Attempt || node.ReworkCount != want.ReworkCount { - return apperr.New(apperr.Conflict, "通知对应的节点状态已变化,请查看最新消息") + if node == nil { + return apperr.Newf(apperr.Conflict, "通知对应的节点 %q 已不存在,请查看最新消息", want.NodeID) } - if strings.TrimSpace(want.ArtifactName) == "" { + if node.Status != want.Status || node.Attempt != want.Attempt || node.ReworkCount != want.ReworkCount { + return apperr.Newf(apperr.Conflict, "通知对应的节点状态已变化:期望 status=%s attempt=%d rework=%d,实际 status=%s attempt=%d rework=%d", + want.Status, want.Attempt, want.ReworkCount, node.Status, node.Attempt, node.ReworkCount) + } + name, sha := strings.TrimSpace(want.ArtifactName), strings.TrimSpace(want.ArtifactSHA256) + if name == "" && sha == "" { return nil } - artifact := latestRunArtifact(run, want.ArtifactName) + if name == "" || sha == "" { + // Half a binding is a caller bug, not an unbound approval: accepting it + // would let a client believe its approval is artifact-bound when it is not. + return apperr.New(apperr.Invalid, "expected.artifactName 与 expected.artifactSha256 必须同时提供") + } + artifact := latestRunArtifact(run, name) if artifact == nil { - return apperr.Newf(apperr.Conflict, "批准绑定的产物 %q 不在当前 run 中,请查看最新消息", want.ArtifactName). - With("expectedArtifact", want.ArtifactName). - With("expectedSha256", want.ArtifactSHA256) + return apperr.Newf(apperr.Conflict, "批准绑定的产物 %q 不在当前 run 中,请查看最新消息", name). + With("expectedArtifact", name). + With("expectedSha256", sha) } - if want.ArtifactSHA256 != "" && !strings.EqualFold(artifact.SHA256, want.ArtifactSHA256) { - return apperr.Newf(apperr.Conflict, "批准绑定的产物 %q 内容已变化:期望 sha256 %s,实际 %s", want.ArtifactName, want.ArtifactSHA256, artifact.SHA256). - With("expectedArtifact", want.ArtifactName). - With("expectedSha256", want.ArtifactSHA256). + if !strings.EqualFold(artifact.SHA256, sha) { + return apperr.Newf(apperr.Conflict, "批准绑定的产物 %q 内容已变化:期望 sha256 %s,实际 %s", name, sha, artifact.SHA256). + With("expectedArtifact", name). + With("expectedSha256", sha). With("actualSha256", artifact.SHA256) } return nil @@ -49,7 +59,8 @@ func checkNodeExpectation(run domain.Run, expected []NodeExpectation) error { // latestRunArtifact returns the newest artifact with this logical name. Old // attempts stay in the run for audit, and a decision must bind to the newest // one — binding an older attempt is exactly the stale approval this check -// exists to reject. +// exists to reject. Newest means creation time, not attempt number: attempts +// are per node, so comparing them across nodes is meaningless. func latestRunArtifact(run domain.Run, name string) *domain.Artifact { var best *domain.Artifact for i := range run.Artifacts { @@ -57,7 +68,8 @@ func latestRunArtifact(run domain.Run, name string) *domain.Artifact { if artifact.Name != name { continue } - if best == nil || artifact.Attempt > best.Attempt || artifact.Attempt == best.Attempt && artifact.CreatedAt.After(best.CreatedAt) { + if best == nil || artifact.CreatedAt.After(best.CreatedAt) || + artifact.CreatedAt.Equal(best.CreatedAt) && artifact.Attempt > best.Attempt { best = artifact } } diff --git a/internal/engine/gate_binding_test.go b/internal/engine/gate_binding_test.go index f2955855a..6127e8a78 100644 --- a/internal/engine/gate_binding_test.go +++ b/internal/engine/gate_binding_test.go @@ -107,6 +107,54 @@ func TestGateBindingRejectsMissingArtifact(t *testing.T) { } } +func TestGateBindingRejectsHalfBinding(t *testing.T) { + e, _ := cvEEngine(t) + e.executeRuns = false + run := gateBindingRun("gate-binding-half") + cvEPutRun(t, e, run) + + for _, expected := range []NodeExpectation{ + {NodeID: "gate", Status: "waiting_approval", Attempt: 1, ArtifactSHA256: "aaaa"}, + {NodeID: "gate", Status: "waiting_approval", Attempt: 1, ArtifactName: "verify"}, + } { + if err := e.Approve(run.ID, "gate", "", expected); err == nil { + t.Fatalf("half-filled binding %+v was accepted", expected) + } + } + got, _ := e.repo.RunState(run.ID) + if got.Nodes["gate"].Status != "waiting_approval" { + t.Fatalf("gate status = %q, want waiting_approval", got.Nodes["gate"].Status) + } +} + +func TestGateBindingBindsToNewestArtifactAttempt(t *testing.T) { + e, _ := cvEEngine(t) + e.executeRuns = false + run := gateBindingRun("gate-binding-newest") + older := time.Now().UTC().Add(-time.Minute) + run.Artifacts = []domain.Artifact{ + // Attempt numbers are per node, so the older artifact can carry the higher + // attempt: recency must come from creation time. + {ID: "old", RunID: run.ID, NodeID: "verify", Attempt: 5, Name: "verify", Path: "verify.json", SHA256: "aaaa", CreatedAt: older}, + {ID: "new", RunID: run.ID, NodeID: "verify", Attempt: 1, Name: "verify", Path: "verify.json", SHA256: "cccc", CreatedAt: time.Now().UTC()}, + } + cvEPutRun(t, e, run) + + err := e.Approve(run.ID, "gate", "", NodeExpectation{ + NodeID: "gate", Status: "waiting_approval", Attempt: 1, + ArtifactName: "verify", ArtifactSHA256: "aaaa", + }) + if err == nil || !strings.Contains(err.Error(), "cccc") { + t.Fatalf("approval must bind to the newest artifact, got %v", err) + } + if err := e.Approve(run.ID, "gate", "", NodeExpectation{ + NodeID: "gate", Status: "waiting_approval", Attempt: 1, + ArtifactName: "verify", ArtifactSHA256: "cccc", + }); err != nil { + t.Fatal(err) + } +} + func TestGateBindingWithoutExpectedKeepsLegacyBehavior(t *testing.T) { e, _ := cvEEngine(t) e.executeRuns = false diff --git a/internal/engine/node_execute.go b/internal/engine/node_execute.go index 3ad7b3859..f8e456d26 100644 --- a/internal/engine/node_execute.go +++ b/internal/engine/node_execute.go @@ -163,12 +163,20 @@ func (e *Engine) execute(ctx context.Context, runID string) { time.Sleep(80 * time.Millisecond) continue } + deferred, spawned := false, false for _, node := range ready { node := node if err := checkNodeRequires(r, node); err != nil { + if running > 0 { + // A parallel sibling may still be producing the artifact; its + // result wakes the scheduler and the check runs again then. + deferred = true + continue + } e.nodeRequirementFailed(runID, node, generation, err) continue } + spawned = true inflightMu.Lock() inflight[node.ID] = true inflightMu.Unlock() @@ -187,6 +195,15 @@ func (e *Engine) execute(ctx context.Context, runID string) { e.executeNode(ctx, runID, wf, node) }() } + if deferred && !spawned && running > 0 { + // Nothing was started this pass; wait for the in-flight sibling + // instead of spinning on the deferred node. + select { + case <-wake: + case <-ctx.Done(): + case <-time.After(500 * time.Millisecond): + } + } } } diff --git a/internal/engine/node_requires.go b/internal/engine/node_requires.go index 0aeccadde..ad28fb244 100644 --- a/internal/engine/node_requires.go +++ b/internal/engine/node_requires.go @@ -21,8 +21,9 @@ type nodeRequirement struct { diffHash string // expected diff hash (kind=verdict) } -// parseNodeRequirement parses the two supported precondition forms. Validation -// rejects malformed values at publish time so a typo never waits for a run. +// parseNodeRequirement parses the two supported precondition forms. Workflow +// validation (run start, and RefreshRunSOP) rejects malformed values; the save +// path does not call this validator, so a typo is reported when a run starts. func parseNodeRequirement(raw string) (nodeRequirement, error) { value := strings.TrimSpace(raw) kind, rest, ok := strings.Cut(value, ":") @@ -112,7 +113,8 @@ func latestVerdictArtifact(run domain.Run) *domain.Artifact { if !matches { continue } - if best == nil || artifact.Attempt > best.Attempt || artifact.Attempt == best.Attempt && artifact.CreatedAt.After(best.CreatedAt) { + if best == nil || artifact.CreatedAt.After(best.CreatedAt) || + artifact.CreatedAt.Equal(best.CreatedAt) && artifact.Attempt > best.Attempt { best = artifact } } diff --git a/internal/engine/node_requires_test.go b/internal/engine/node_requires_test.go index cf3b767d9..4eaa8ff08 100644 --- a/internal/engine/node_requires_test.go +++ b/internal/engine/node_requires_test.go @@ -114,6 +114,41 @@ func TestNodeRequiresVerdictMustMatch(t *testing.T) { } } +func TestNodeRequiresRejectsMalformedVerdictDocument(t *testing.T) { + t.Parallel() + s, err := repo.OpenTest() + if err != nil { + t.Fatal(err) + } + defer s.Close() + wf := domain.WorkflowDefinition{ + ID: "requires-verdict-broken", Name: "requires-verdict-broken", SandboxProfileID: "local", + Nodes: []domain.WorkflowNode{ + {ID: "produce", Name: "Produce", Type: "script", ScriptLanguage: "shell", + Script: "printf 'not json' > verify.json", MaxAttempts: 1, + ArtifactOutputs: []domain.ArtifactContract{{Name: "verify", Path: "verify.json", MediaType: "application/json", Required: true}}}, + {ID: "consume", Name: "Consume", Type: "script", ScriptLanguage: "shell", + Script: "printf ran > ran.txt", MaxAttempts: 1, + Requires: []string{"verdict:PASS@d1"}}, + }, + Edges: []domain.WorkflowEdge{{ID: "produce-consume", Source: "produce", Target: "consume", When: "success"}}, + } + if err := s.PutWorkflow(wf); err != nil { + t.Fatal(err) + } + e := New(s, runtime.NewManagerWithLimit(t.TempDir(), 1)) + run, err := e.Start(wf.ID, "") + if err != nil { + t.Fatal(err) + } + waitFor(t, s, run.ID, "failed") + finished, _ := s.Run(run.ID) + consume := finished.Nodes["consume"] + if consume == nil || consume.Status != "failed" || !strings.Contains(consume.Error, "不是合法 JSON") { + t.Fatalf("consume = %+v, want failed naming malformed JSON", consume) + } +} + func TestWorkflowValidationRejectsMalformedRequires(t *testing.T) { for _, requirement := range []string{"verify@abc", "artifact:verify", "verdict:PASS", "artifact:@abc"} { wf := requiresWorkflow("requires-invalid-"+strings.NewReplacer(":", "-", "@", "-").Replace(requirement), requirement) diff --git a/internal/engine/pass_override_test.go b/internal/engine/pass_override_test.go index 88d569700..a2e89527e 100644 --- a/internal/engine/pass_override_test.go +++ b/internal/engine/pass_override_test.go @@ -75,6 +75,27 @@ func TestPassOverridePassesVerificationNodeAndRecordsActor(t *testing.T) { } } +func TestPassRejectsVerificationNodeParkedByPause(t *testing.T) { + e, _ := cvEEngine(t) + e.executeRuns = false + run := verificationPassRun("pass-override-paused") + run.Status = "waiting" + run.PauseRequested = true + run.Nodes["verify"].Status = "waiting_approval" + cvEPutRun(t, e, run) + + if err := e.Pass(run.ID, "verify", ""); err == nil { + t.Fatal("paused verification node was passed without an override") + } + got, _ := e.repo.RunState(run.ID) + if got.Nodes["verify"].Status != "waiting_approval" { + t.Fatalf("verify status = %q, want waiting_approval", got.Nodes["verify"].Status) + } + if !hasRunEvent(got, "node.pass_rejected") { + t.Fatalf("node.pass_rejected audit event missing: %+v", got.Events) + } +} + func TestPassKeepsWorkingForNonVerificationScriptNode(t *testing.T) { e, _ := cvEEngine(t) e.executeRuns = false diff --git a/internal/engine/run_ops.go b/internal/engine/run_ops.go index 4af413a06..93b4fa034 100644 --- a/internal/engine/run_ops.go +++ b/internal/engine/run_ops.go @@ -5,6 +5,7 @@ import ( "agentflow/internal/domain" "agentflow/internal/repo" "context" + "errors" "fmt" "log" "sort" @@ -190,16 +191,35 @@ func (e *Engine) recordGateRejection(runID string, r *domain.Run, nodeID string, // persistAuditEvent stores one control decision record without changing run or // node status. The caller holds stateMu. +// +// The write is revision-guarded like the decision path: a stale snapshot must +// not overwrite a newer run header. When another writer won the revision, the +// record is re-applied to the newest snapshot instead of being dropped. The +// lease tail releases only the lease this call acquired; never the lease of a +// worker that owns the run. func (e *Engine) persistAuditEvent(runID string, r *domain.Run, nodeID, typ, message string) { e.event(r, nodeID, typ, message) appendControlTelemetry(r, nodeID, typ, message) - if err := e.repo.PutRun(*r); err != nil { - log.Printf("record %s %s: %v", typ, runID, err) - return + if err := e.repo.PutRunAtRevision(*r, r.Revision); err != nil { + if !errors.Is(err, repo.ErrRunDecisionStale) { + log.Printf("record %s %s: %v", typ, runID, err) + return + } + latest, ok := e.repo.RunState(runID) + if !ok { + log.Printf("record %s %s: run disappeared", typ, runID) + return + } + e.event(&latest, nodeID, typ, message) + appendControlTelemetry(&latest, nodeID, typ, message) + if err := e.repo.PutRunAtRevision(latest, latest.Revision); err != nil { + log.Printf("record %s %s: %v", typ, runID, err) + return + } } e.publish(runID) - if !e.executes() && r.OwnerInstanceID != "" { - _ = e.repo.ReleaseRunLease(runID, r.OwnerInstanceID, r.Generation) + if e.executes() { + _ = e.repo.ReleaseRunLease(runID, e.instanceID, r.Generation) } } @@ -1029,6 +1049,7 @@ func overlayLatestNodeBindings(st *repo.Store, r *domain.Run, nodeIDs map[string } n.AgentID, n.ExecutorID = src.AgentID, src.ExecutorID n.ArtifactOutputs = src.ArtifactOutputs + n.Requires, n.VerificationStep = src.Requires, src.VerificationStep n.OnFailure, n.RejectTo = src.OnFailure, src.RejectTo n.RetryStrategy, n.CarryOver = src.RetryStrategy, src.CarryOver if src.MaxAttempts > n.MaxAttempts {