fix(daemon): park a pushing workflow before it runs when its identity may not push, with a link to the connection
This commit is contained in:
1 parent
e2c79d3f67
commit
4752e03c01
4 files changed
+48
No files matched your search
@@ -1556,6 +1556,11 @@ func (d *Daemon) teardownStorage(ctx context.Context, task *workflow.Task, repo
|
||||
func (d *Daemon) taskWorkspace(ctx context.Context, task *workflow.Task) (*worktree.Manager, config.Repo, error) {
|
||||
if task.HasRepository() && d.ResolveRepository != nil {
|
||||
resolved, err := d.Repository(ctx, task, config.OperationClone)
|
||||
if err == nil && !task.IsTestRun() && workflow.DefinitionPushes(task.WorkflowDefinitionYAML) {
|
||||
// Checked before the run rather than at its commit step, so a
|
||||
// missing permit parks in seconds instead of after the agent's work.
|
||||
_, err = d.Repository(ctx, task, config.OperationPush)
|
||||
}
|
||||
return resolved.Trees, resolved.Repository, err
|
||||
}
|
||||
trees := d.treesFor(task)
|
||||
@@ -2073,6 +2078,9 @@ func parkBlocker(err error) taskstate.Blocker {
|
||||
if b, ok := errors.AsType[blockedPark](err); ok {
|
||||
return b.blocker
|
||||
}
|
||||
if failure, ok := errors.AsType[*forge.AccessError](err); ok && failure.Code == "operation_denied" {
|
||||
return taskstate.BlockerConnectionPermit
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"path"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
@@ -333,3 +334,37 @@ func stepsUseModel(steps []StepRecord) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// pushStepTypes are the steps that publish to the repository's forge.
|
||||
var pushStepTypes = []string{RepoCommitStepName, RepoOpenPRStepName}
|
||||
|
||||
// DefinitionPushes reports whether a workflow definition has a step, at any
|
||||
// depth, that pushes to the repository.
|
||||
func DefinitionPushes(src string) bool {
|
||||
var doc any
|
||||
if yaml.Unmarshal([]byte(src), &doc) != nil {
|
||||
return false
|
||||
}
|
||||
return hasStepType(doc, pushStepTypes)
|
||||
}
|
||||
|
||||
func hasStepType(node any, types []string) bool {
|
||||
switch n := node.(type) {
|
||||
case map[string]any:
|
||||
if t, ok := n["type"].(string); ok && slices.Contains(types, t) {
|
||||
return true
|
||||
}
|
||||
for _, v := range n {
|
||||
if hasStepType(v, types) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
case []any:
|
||||
for _, v := range n {
|
||||
if hasStepType(v, types) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -264,6 +264,9 @@ const (
|
||||
BlockerAgentAssignment Blocker = "agent_assignment"
|
||||
// BlockerPolicyDenied: an access policy refuses the run.
|
||||
BlockerPolicyDenied Blocker = "policy_denied"
|
||||
// BlockerConnectionPermit: the run's identity may not use the
|
||||
// repository's connection for an operation the workflow needs.
|
||||
BlockerConnectionPermit Blocker = "connection_permit"
|
||||
)
|
||||
|
||||
// Blocker is the persisted park blocker string.
|
||||
|
||||
@@ -33,6 +33,8 @@ func blockerRoute(t *task.Task) (recoveryRoute, bool) {
|
||||
return recoveryRoute{label: "Set execution identity", page: workflowPage, method: http.MethodPost, api: "/api/control-plane/resources/workflow-definitions/commands/apply"}, true
|
||||
case taskstate.BlockerAgentAssignment:
|
||||
return recoveryRoute{label: "Assign agent", page: "/org/agents", method: http.MethodPut, api: "/api/orgs/" + url.PathEscape(t.OrgOrDefault()) + "/agents/_", instance: true}, true
|
||||
case taskstate.BlockerConnectionPermit:
|
||||
return recoveryRoute{label: "Edit connection permissions", page: "/org/connections", method: http.MethodPost, api: "/api/control-plane/resources/forge-connections/commands/replace"}, true
|
||||
case taskstate.BlockerPolicyDenied:
|
||||
return recoveryRoute{label: "Edit policies", page: "/org/policies", method: http.MethodPut, api: "/api/access/policies"}, true
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user