feat(webui): link parked tasks to the page that fixes their blocker
This commit is contained in:
24 files changed
+214
-50
No files matched your search
@@ -1871,8 +1871,11 @@ type Task struct {
|
||||
// of the captured event that started a binding task.
|
||||
BindingSignature string `protobuf:"bytes,46,opt,name=binding_signature,json=bindingSignature,proto3" json:"binding_signature,omitempty"`
|
||||
BindingAddr string `protobuf:"bytes,47,opt,name=binding_addr,json=bindingAddr,proto3" json:"binding_addr,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
// park_blocker names what a parked task is missing (taskstate.Blocker),
|
||||
// recorded at the park site; empty when the park has no known fix.
|
||||
ParkBlocker string `protobuf:"bytes,48,opt,name=park_blocker,json=parkBlocker,proto3" json:"park_blocker,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
|
||||
func (x *Task) Reset() {
|
||||
@@ -2235,6 +2238,13 @@ func (x *Task) GetBindingAddr() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *Task) GetParkBlocker() string {
|
||||
if x != nil {
|
||||
return x.ParkBlocker
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Event mirrors internal/events.Event. Data is carried as a JSON object
|
||||
// string (matching the store's own on-disk representation) rather than
|
||||
// google.protobuf.Struct, to stay a direct mirror of the existing column.
|
||||
@@ -5454,6 +5464,7 @@ type ParkTaskRequest struct {
|
||||
From string `protobuf:"bytes,2,opt,name=from,proto3" json:"from,omitempty"`
|
||||
Detail string `protobuf:"bytes,3,opt,name=detail,proto3" json:"detail,omitempty"`
|
||||
Class string `protobuf:"bytes,4,opt,name=class,proto3" json:"class,omitempty"`
|
||||
Blocker string `protobuf:"bytes,5,opt,name=blocker,proto3" json:"blocker,omitempty"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
sizeCache protoimpl.SizeCache
|
||||
}
|
||||
@@ -5516,6 +5527,13 @@ func (x *ParkTaskRequest) GetClass() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (x *ParkTaskRequest) GetBlocker() string {
|
||||
if x != nil {
|
||||
return x.Blocker
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type ParkTaskResponse struct {
|
||||
state protoimpl.MessageState `protogen:"open.v1"`
|
||||
unknownFields protoimpl.UnknownFields
|
||||
@@ -19493,7 +19511,7 @@ const file_state_v1_state_proto_rawDesc = "" +
|
||||
"\x06tokens\x18\x01 \x03(\v2\x17.state.v1.PersonalTokenR\x06tokens\",\n" +
|
||||
"\x1aRevokePersonalTokenRequest\x12\x0e\n" +
|
||||
"\x02id\x18\x01 \x01(\tR\x02id\"\x1d\n" +
|
||||
"\x1bRevokePersonalTokenResponse\"\xb8\f\n" +
|
||||
"\x1bRevokePersonalTokenResponse\"\xdb\f\n" +
|
||||
"\x04Task\x12\x0e\n" +
|
||||
"\x02id\x18\x01 \x01(\x03R\x02id\x12\x14\n" +
|
||||
"\x05owner\x18\x02 \x01(\tR\x05owner\x12\x12\n" +
|
||||
@@ -19556,7 +19574,8 @@ const file_state_v1_state_proto_rawDesc = "" +
|
||||
"\x06origin\x18, \x01(\tR\x06origin\x12\x1c\n" +
|
||||
"\tworkspace\x18- \x01(\tR\tworkspace\x12+\n" +
|
||||
"\x11binding_signature\x18. \x01(\tR\x10bindingSignature\x12!\n" +
|
||||
"\fbinding_addr\x18/ \x01(\tR\vbindingAddr\"\xf8\x02\n" +
|
||||
"\fbinding_addr\x18/ \x01(\tR\vbindingAddr\x12!\n" +
|
||||
"\fpark_blocker\x180 \x01(\tR\vparkBlocker\"\xf8\x02\n" +
|
||||
"\x05Event\x12\x0e\n" +
|
||||
"\x02id\x18\x01 \x01(\x03R\x02id\x12*\n" +
|
||||
"\x02at\x18\x02 \x01(\v2\x1a.google.protobuf.TimestampR\x02at\x12\x12\n" +
|
||||
@@ -19819,12 +19838,13 @@ const file_state_v1_state_proto_rawDesc = "" +
|
||||
"\vfrom_status\x18\x02 \x01(\tR\n" +
|
||||
"fromStatus\x12\x1a\n" +
|
||||
"\bworkflow\x18\x03 \x01(\tR\bworkflow\"\x11\n" +
|
||||
"\x0fRequeueResponse\"l\n" +
|
||||
"\x0fRequeueResponse\"\x86\x01\n" +
|
||||
"\x0fParkTaskRequest\x12\x17\n" +
|
||||
"\atask_id\x18\x01 \x01(\x03R\x06taskId\x12\x12\n" +
|
||||
"\x04from\x18\x02 \x01(\tR\x04from\x12\x16\n" +
|
||||
"\x06detail\x18\x03 \x01(\tR\x06detail\x12\x14\n" +
|
||||
"\x05class\x18\x04 \x01(\tR\x05class\"\x12\n" +
|
||||
"\x05class\x18\x04 \x01(\tR\x05class\x12\x18\n" +
|
||||
"\ablocker\x18\x05 \x01(\tR\ablocker\"\x12\n" +
|
||||
"\x10ParkTaskResponse\"\x15\n" +
|
||||
"\x13RecoverStaleRequest\",\n" +
|
||||
"\x14RecoverStaleResponse\x12\x14\n" +
|
||||
|
||||
@@ -1480,7 +1480,7 @@ func (d *Daemon) process(ctx context.Context, task *workflow.Task, hold *taskHol
|
||||
|
||||
trees, repo, err := d.taskWorkspace(ctx, task)
|
||||
if err != nil {
|
||||
d.parkRunningTask(ctx, task, err.Error(), pinParkClass(err))
|
||||
d.parkBlockedTask(ctx, task, err.Error(), pinParkClass(err), parkBlocker(err))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1801,13 +1801,19 @@ func (d *Daemon) parkCapabilityUnavailable(ctx context.Context, task *workflow.T
|
||||
// bounded context that ignores cancellation. ErrStaleTransition is ignored;
|
||||
// other errors are logged.
|
||||
func (d *Daemon) parkRunningTask(ctx context.Context, task *workflow.Task, reason string, class taskstate.ParkClass) {
|
||||
d.parkBlockedTask(ctx, task, reason, class, "")
|
||||
}
|
||||
|
||||
// parkBlockedTask is parkRunningTask recording the blocker the park site
|
||||
// knows, so the dashboard can link to its fix.
|
||||
func (d *Daemon) parkBlockedTask(ctx context.Context, task *workflow.Task, reason string, class taskstate.ParkClass, blocker taskstate.Blocker) {
|
||||
if d.Store == nil {
|
||||
return
|
||||
}
|
||||
writeCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
if err := d.Store.ParkTask(writeCtx, task.ID, workflow.StatusRunning, reason, class); err != nil {
|
||||
if err := d.Store.ParkTask(writeCtx, task.ID, workflow.StatusRunning, reason, class, blocker); err != nil {
|
||||
if !errors.Is(err, storecontract.ErrStaleTransition) {
|
||||
d.Log.Warn("terminal park transition failed", "task", task.ID, "reason", reason, "err", err)
|
||||
}
|
||||
@@ -1905,7 +1911,7 @@ func (d *Daemon) runViaAgent(ctx context.Context, task *workflow.Task, repo conf
|
||||
func (d *Daemon) pinTaskProfile(ctx context.Context, task *workflow.Task) (config.AgentProfile, bool) {
|
||||
if err := d.pinWorkflowDefinition(ctx, task); err != nil {
|
||||
d.Log.Error("pin workflow definition failed", "task", task.ID, "err", err)
|
||||
d.parkRunningTask(ctx, task, "pin workflow definition: "+err.Error(), pinParkClass(err))
|
||||
d.parkBlockedTask(ctx, task, "pin workflow definition: "+err.Error(), pinParkClass(err), parkBlocker(err))
|
||||
return config.AgentProfile{}, false
|
||||
}
|
||||
iface, err := workflowtask.ParseWorkflowInterface(task.WorkflowDefinitionYAML)
|
||||
@@ -1958,7 +1964,7 @@ func (d *Daemon) pinWorkflowDefinition(ctx context.Context, task *workflow.Task)
|
||||
return pinFailure{taskstate.ParkTransient, fmt.Errorf("workflow enablement: %w", err)}
|
||||
}
|
||||
if !enablement.Enabled(task.Org, task.Workflow) {
|
||||
return pinFailure{taskstate.ParkNeedsHuman, fmt.Errorf("workflow %s is disabled", task.Workflow)}
|
||||
return blockedPark{taskstate.BlockerWorkflowDisabled, pinFailure{taskstate.ParkNeedsHuman, fmt.Errorf("workflow %s is disabled", task.Workflow)}}
|
||||
}
|
||||
if err := d.checkPackageTrigger(ctx, task); err != nil {
|
||||
return pinFailure{taskstate.ParkNeedsHuman, err}
|
||||
@@ -2007,6 +2013,23 @@ func pinParkClass(err error) taskstate.ParkClass {
|
||||
return taskstate.ParkNeedsHuman
|
||||
}
|
||||
|
||||
// blockedPark names what a park is missing alongside the failure.
|
||||
type blockedPark struct {
|
||||
blocker taskstate.Blocker
|
||||
err error
|
||||
}
|
||||
|
||||
func (e blockedPark) Error() string { return e.err.Error() }
|
||||
func (e blockedPark) Unwrap() error { return e.err }
|
||||
|
||||
// parkBlocker reports the blocker err names, or empty.
|
||||
func parkBlocker(err error) taskstate.Blocker {
|
||||
if b, ok := errors.AsType[blockedPark](err); ok {
|
||||
return b.blocker
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// pinnedDefinitionID returns the workflow id a task's pin declares, checking
|
||||
// its digest. ok is false when there is no pin.
|
||||
func pinnedDefinitionID(task *workflow.Task) (string, bool, error) {
|
||||
|
||||
@@ -506,7 +506,7 @@ func (s *stubStore) ClaimNext(context.Context) (*workflow.Task, error) {
|
||||
|
||||
func (s *stubStore) Update(context.Context, *workflow.Task) error { return nil }
|
||||
|
||||
func (s *stubStore) ParkTask(context.Context, int64, string, string, string) error {
|
||||
func (s *stubStore) ParkTask(context.Context, int64, string, string, string, string) error {
|
||||
s.park()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ type parkStore struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (s parkStore) ParkTask(context.Context, int64, string, string, taskstate.ParkClass) error {
|
||||
func (s parkStore) ParkTask(context.Context, int64, string, string, taskstate.ParkClass, taskstate.Blocker) error {
|
||||
return s.err
|
||||
}
|
||||
|
||||
|
||||
@@ -26,29 +26,29 @@ import (
|
||||
func (d *Daemon) adoptWorkflowIdentity(ctx context.Context, task *workflow.Task) bool {
|
||||
if err := d.pinWorkflowDefinition(ctx, task); err != nil {
|
||||
d.Log.Error("pin workflow definition failed", "task", task.ID, "err", err)
|
||||
d.parkRunningTask(ctx, task, "pin workflow definition: "+err.Error(), pinParkClass(err))
|
||||
d.parkBlockedTask(ctx, task, "pin workflow definition: "+err.Error(), pinParkClass(err), parkBlocker(err))
|
||||
return false
|
||||
}
|
||||
iface, err := workflowtask.ParseWorkflowInterface(task.WorkflowDefinitionYAML)
|
||||
if err != nil {
|
||||
d.parkRunningTask(ctx, task, "workflow "+task.Workflow+": "+err.Error(), taskstate.ParkNeedsHuman)
|
||||
d.parkBlockedTask(ctx, task, "workflow "+task.Workflow+": "+err.Error(), taskstate.ParkNeedsHuman, taskstate.BlockerWorkflowIdentity)
|
||||
return false
|
||||
}
|
||||
if iface.Identity == "" {
|
||||
d.parkRunningTask(ctx, task, "workflow "+task.Workflow+" declares no identity to run as; set one in its settings", taskstate.ParkNeedsHuman)
|
||||
d.parkBlockedTask(ctx, task, "workflow "+task.Workflow+" declares no identity to run as; set one in its settings", taskstate.ParkNeedsHuman, taskstate.BlockerWorkflowIdentity)
|
||||
return false
|
||||
}
|
||||
runsAs, runnerName, err := d.declaredIdentity(ctx, task, iface.Identity)
|
||||
if err != nil {
|
||||
d.parkRunningTask(ctx, task, "workflow "+task.Workflow+": "+err.Error(), pinParkClass(err))
|
||||
d.parkBlockedTask(ctx, task, "workflow "+task.Workflow+": "+err.Error(), pinParkClass(err), parkBlocker(err))
|
||||
return false
|
||||
}
|
||||
if !d.mayRunWorkflow(ctx, task, d.publisherIdentity(task.Identity)) {
|
||||
d.parkRunningTask(ctx, task, "the identity that started it may not run workflow "+task.Workflow, taskstate.ParkNeedsHuman)
|
||||
d.parkBlockedTask(ctx, task, "the identity that started it may not run workflow "+task.Workflow, taskstate.ParkNeedsHuman, taskstate.BlockerPolicyDenied)
|
||||
return false
|
||||
}
|
||||
if !d.mayRunWorkflow(ctx, task, runsAs) {
|
||||
d.parkRunningTask(ctx, task, "identity "+iface.Identity+" may not run workflow "+task.Workflow, taskstate.ParkNeedsHuman)
|
||||
d.parkBlockedTask(ctx, task, "identity "+iface.Identity+" may not run workflow "+task.Workflow, taskstate.ParkNeedsHuman, taskstate.BlockerPolicyDenied)
|
||||
return false
|
||||
}
|
||||
// In memory only: the stored identity stays the starter's, so every
|
||||
@@ -90,14 +90,15 @@ func (d *Daemon) declaredIdentity(ctx context.Context, task *workflow.Task, ref
|
||||
func (d *Daemon) databaseExecutionIdentity(ctx context.Context, task *workflow.Task, id identity.IdentityID) (identity.Identity, error) {
|
||||
value, err := d.IdentityRepository.Get(ctx, id)
|
||||
if err != nil {
|
||||
class := taskstate.ParkTransient
|
||||
failure := pinFailure{taskstate.ParkTransient, fmt.Errorf("resolve execution identity %s: %w", id, err)}
|
||||
if errors.Is(err, identity.ErrNotFound) {
|
||||
class = taskstate.ParkNeedsHuman
|
||||
failure.class = taskstate.ParkNeedsHuman
|
||||
return identity.Identity{}, blockedPark{taskstate.BlockerAgentAssignment, failure}
|
||||
}
|
||||
return identity.Identity{}, pinFailure{class, fmt.Errorf("resolve execution identity %s: %w", id, err)}
|
||||
return identity.Identity{}, failure
|
||||
}
|
||||
if !value.Kind.Agent() || value.Lifecycle != identity.LifecycleActive {
|
||||
return identity.Identity{}, pinFailure{taskstate.ParkNeedsHuman, fmt.Errorf("execution identity %s must be an active bot or service account", id)}
|
||||
return identity.Identity{}, blockedPark{taskstate.BlockerAgentAssignment, pinFailure{taskstate.ParkNeedsHuman, fmt.Errorf("execution identity %s must be an active bot or service account", id)}}
|
||||
}
|
||||
if d.AgentAssignments == nil {
|
||||
return identity.Identity{}, pinFailure{taskstate.ParkTransient, fmt.Errorf("agent assignment authority unavailable")}
|
||||
@@ -111,14 +112,14 @@ func (d *Daemon) databaseExecutionIdentity(ctx context.Context, task *workflow.T
|
||||
return identity.Identity{}, pinFailure{taskstate.ParkTransient, fmt.Errorf("resolve execution principal: %w", err)}
|
||||
}
|
||||
if principal.Org != owner {
|
||||
return identity.Identity{}, pinFailure{taskstate.ParkNeedsHuman, fmt.Errorf("execution identity belongs to another organisation")}
|
||||
return identity.Identity{}, blockedPark{taskstate.BlockerAgentAssignment, pinFailure{taskstate.ParkNeedsHuman, fmt.Errorf("execution identity belongs to another organisation")}}
|
||||
}
|
||||
assignments, err := d.AgentAssignments.ListOrgAgents(access.WithPrincipal(ctx, principal), owner)
|
||||
if err != nil {
|
||||
return identity.Identity{}, pinFailure{taskstate.ParkTransient, fmt.Errorf("resolve execution identity assignment: %w", err)}
|
||||
}
|
||||
if !slices.ContainsFunc(assignments, func(a org.AgentAssignment) bool { return a.IdentityID == value.ID && a.OrgID == owner }) {
|
||||
return identity.Identity{}, pinFailure{taskstate.ParkNeedsHuman, fmt.Errorf("execution identity %s is not assigned to this organisation", id)}
|
||||
return identity.Identity{}, blockedPark{taskstate.BlockerAgentAssignment, pinFailure{taskstate.ParkNeedsHuman, fmt.Errorf("execution identity %s is not assigned to this organisation", id)}}
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ type identityStore struct {
|
||||
|
||||
func (*identityStore) Update(context.Context, *workflow.Task) error { return nil }
|
||||
|
||||
func (s *identityStore) ParkTask(context.Context, int64, string, string, taskstate.ParkClass) error {
|
||||
func (s *identityStore) ParkTask(context.Context, int64, string, string, taskstate.ParkClass, taskstate.Blocker) error {
|
||||
s.parked = true
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -47,10 +47,10 @@ type TaskLifecycle interface {
|
||||
RecoverStale(ctx context.Context) (int64, error)
|
||||
}
|
||||
|
||||
// TaskParker parks a task with a park class. Unknown classes become
|
||||
// needs_human.
|
||||
// TaskParker parks a task with a park class and the blocker the park site
|
||||
// knows, if any. Unknown classes become needs_human.
|
||||
type TaskParker interface {
|
||||
ParkTask(ctx context.Context, taskID int64, from, detail, class string) error
|
||||
ParkTask(ctx context.Context, taskID int64, from, detail, class, blocker string) error
|
||||
}
|
||||
|
||||
// StepRecorder records a running execution's steps.
|
||||
|
||||
@@ -125,6 +125,9 @@ type Task struct {
|
||||
// park site, never inferred from reason text; needs_human is the
|
||||
// default an unclassified park reads as.
|
||||
ParkClass string `json:"park_class"`
|
||||
// ParkBlocker is what a parked task is missing (taskstate.Blocker), set
|
||||
// at the park site; empty when no dashboard page fixes it.
|
||||
ParkBlocker string `json:"park_blocker,omitempty"`
|
||||
// RemediationRounds counts review-triggered remediation rounds.
|
||||
RemediationRounds int `json:"remediation_rounds"`
|
||||
// ReviewGate is the encoded review gate document; empty if the task never
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
-- What a parked task is missing, so the dashboard can route to the fix.
|
||||
|
||||
-- +goose Up
|
||||
ALTER TABLE tasks ADD COLUMN park_blocker text NOT NULL DEFAULT '';
|
||||
|
||||
-- +goose Down
|
||||
ALTER TABLE tasks DROP COLUMN park_blocker;
|
||||
@@ -24,7 +24,7 @@ func (q *Queries) CallStatusDetail(ctx context.Context, taskID int64) (string, e
|
||||
|
||||
const enqueueCallTask = `-- name: EnqueueCallTask :one
|
||||
WITH caller AS (
|
||||
SELECT t.id, t.owner, t.repo, t.issue_number, t.title, t.body, t.labels, t.status, t.workflow, t.branch, t.plan, t.notes, t.pr_number, t.tokens_used, t.iterations, t.attempt, t.park_reason, t.watch_comment_id, t.park_class, t.remediation_rounds, t.retry_count, t.source, t.identity, t.binding_id, t.binding_version, t.review_payload, t.workflow_definition_version, t.workflow_definition_digest, t.workflow_definition_yaml, t.created_at, t.updated_at, t.review_cursor, t.inputs, t.org_id, t.workspace_id, t.call_parent_task_id, t.call_depth, t.outputs, t.review_gate, t.rereview_rounds, t.retry_mode, t.resume_from, t.resume_results, t.pending_reviews, t.origin, t.call_key, t.outcome_posted, t.binding_signature, t.binding_addr FROM tasks t WHERE t.id = $1 FOR UPDATE
|
||||
SELECT t.id, t.owner, t.repo, t.issue_number, t.title, t.body, t.labels, t.status, t.workflow, t.branch, t.plan, t.notes, t.pr_number, t.tokens_used, t.iterations, t.attempt, t.park_reason, t.watch_comment_id, t.park_class, t.remediation_rounds, t.retry_count, t.source, t.identity, t.binding_id, t.binding_version, t.review_payload, t.workflow_definition_version, t.workflow_definition_digest, t.workflow_definition_yaml, t.created_at, t.updated_at, t.review_cursor, t.inputs, t.org_id, t.workspace_id, t.call_parent_task_id, t.call_depth, t.outputs, t.review_gate, t.rereview_rounds, t.retry_mode, t.resume_from, t.resume_results, t.pending_reviews, t.origin, t.call_key, t.outcome_posted, t.binding_signature, t.binding_addr, t.park_blocker FROM tasks t WHERE t.id = $1 FOR UPDATE
|
||||
), number AS (
|
||||
INSERT INTO chat_issue_numbers (owner, repo, last_number)
|
||||
SELECT caller.owner, caller.repo, $9::bigint + 1 FROM caller
|
||||
@@ -43,7 +43,7 @@ SELECT
|
||||
FROM caller, number
|
||||
WHERE caller.status = 'running' AND caller.call_depth + 1 <= $8::int
|
||||
ON CONFLICT (call_parent_task_id, call_key) WHERE call_key <> '' AND status NOT IN ('dead', 'closed_wont_do') DO UPDATE SET call_key = EXCLUDED.call_key
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker
|
||||
`
|
||||
|
||||
type EnqueueCallTaskParams struct {
|
||||
@@ -135,6 +135,7 @@ func (q *Queries) EnqueueCallTask(ctx context.Context, arg EnqueueCallTaskParams
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -541,6 +541,7 @@ type Task struct {
|
||||
OutcomePosted bool
|
||||
BindingSignature string
|
||||
BindingAddr string
|
||||
ParkBlocker string
|
||||
}
|
||||
|
||||
type ToolCall struct {
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
const activeTasksByOrigin = `-- name: ActiveTasksByOrigin :many
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr FROM tasks
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker FROM tasks
|
||||
WHERE origin = $1 AND origin <> '' AND status IN ('queued', 'running') AND ($2::text IS NULL OR org_id = $2)
|
||||
ORDER BY id
|
||||
`
|
||||
@@ -83,6 +83,7 @@ func (q *Queries) ActiveTasksByOrigin(ctx context.Context, arg ActiveTasksByOrig
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -162,7 +163,7 @@ func (q *Queries) BeginRemediationTask(ctx context.Context, arg BeginRemediation
|
||||
const claimByIssue = `-- name: ClaimByIssue :one
|
||||
UPDATE tasks SET status = 'running', attempt = attempt + 1, outputs = '', updated_at = now()
|
||||
WHERE owner = $1 AND repo = $2 AND issue_number = $3 AND status = 'queued'
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker
|
||||
`
|
||||
|
||||
type ClaimByIssueParams struct {
|
||||
@@ -226,6 +227,7 @@ func (q *Queries) ClaimByIssue(ctx context.Context, arg ClaimByIssueParams) (Tas
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -240,7 +242,7 @@ WHERE id = (
|
||||
FOR UPDATE SKIP LOCKED
|
||||
LIMIT 1
|
||||
)
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker
|
||||
`
|
||||
|
||||
// FOR UPDATE SKIP LOCKED replaces the SQLite single-writer assumption: two
|
||||
@@ -302,6 +304,7 @@ func (q *Queries) ClaimNextTask(ctx context.Context) (Task, error) {
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -419,7 +422,7 @@ FROM number, (SELECT COALESCE(
|
||||
'org-sys'
|
||||
) AS id) AS owner_org
|
||||
WHERE $11::text IS NULL OR owner_org.id = $11
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr
|
||||
RETURNING id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker
|
||||
`
|
||||
|
||||
type InsertChatTaskParams struct {
|
||||
@@ -515,6 +518,7 @@ func (q *Queries) InsertChatTask(ctx context.Context, arg InsertChatTaskParams)
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -756,15 +760,16 @@ func (q *Queries) MarkOutcomePosted(ctx context.Context, id int64) error {
|
||||
|
||||
const parkTask = `-- name: ParkTask :execrows
|
||||
UPDATE tasks
|
||||
SET status = 'parked', park_reason = $2, park_class = $3, updated_at = now()
|
||||
SET status = 'parked', park_reason = $2, park_class = $3, park_blocker = $5, updated_at = now()
|
||||
WHERE id = $1 AND status = $4
|
||||
`
|
||||
|
||||
type ParkTaskParams struct {
|
||||
ID int64
|
||||
ParkReason string
|
||||
ParkClass string
|
||||
Status string
|
||||
ID int64
|
||||
ParkReason string
|
||||
ParkClass string
|
||||
Status string
|
||||
ParkBlocker string
|
||||
}
|
||||
|
||||
func (q *Queries) ParkTask(ctx context.Context, arg ParkTaskParams) (int64, error) {
|
||||
@@ -773,6 +778,7 @@ func (q *Queries) ParkTask(ctx context.Context, arg ParkTaskParams) (int64, erro
|
||||
arg.ParkReason,
|
||||
arg.ParkClass,
|
||||
arg.Status,
|
||||
arg.ParkBlocker,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@@ -986,7 +992,7 @@ func (q *Queries) StampTaskBinding(ctx context.Context, arg StampTaskBindingPara
|
||||
}
|
||||
|
||||
const taskByID = `-- name: TaskByID :one
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr FROM tasks WHERE id = $1 AND ($2::text IS NULL OR org_id = $2)
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker FROM tasks WHERE id = $1 AND ($2::text IS NULL OR org_id = $2)
|
||||
`
|
||||
|
||||
type TaskByIDParams struct {
|
||||
@@ -1047,12 +1053,13 @@ func (q *Queries) TaskByID(ctx context.Context, arg TaskByIDParams) (Task, error
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const taskByIssue = `-- name: TaskByIssue :one
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr FROM tasks WHERE owner = $1 AND repo = $2 AND issue_number = $3
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker FROM tasks WHERE owner = $1 AND repo = $2 AND issue_number = $3
|
||||
AND ($4::text IS NULL OR org_id = $4)
|
||||
`
|
||||
|
||||
@@ -1121,12 +1128,13 @@ func (q *Queries) TaskByIssue(ctx context.Context, arg TaskByIssueParams) (Task,
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const taskByPR = `-- name: TaskByPR :one
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr FROM tasks WHERE owner = $1 AND repo = $2 AND pr_number = $3 AND status = $4
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker FROM tasks WHERE owner = $1 AND repo = $2 AND pr_number = $3 AND status = $4
|
||||
AND ($5::text IS NULL OR org_id = $5)
|
||||
`
|
||||
|
||||
@@ -1200,6 +1208,7 @@ func (q *Queries) TaskByPR(ctx context.Context, arg TaskByPRParams) (Task, error
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@@ -1209,6 +1218,7 @@ UPDATE tasks
|
||||
SET status = $2,
|
||||
park_reason = CASE WHEN $2 = 'parked' THEN $3 ELSE park_reason END,
|
||||
park_class = CASE WHEN $2 = 'parked' THEN $4 ELSE park_class END,
|
||||
park_blocker = CASE WHEN $2 = 'parked' THEN '' ELSE park_blocker END,
|
||||
updated_at = now()
|
||||
WHERE id = $1 AND status = $5
|
||||
`
|
||||
@@ -1238,7 +1248,7 @@ func (q *Queries) TransitionTask(ctx context.Context, arg TransitionTaskParams)
|
||||
}
|
||||
|
||||
const unpostedOutcomes = `-- name: UnpostedOutcomes :many
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr FROM tasks
|
||||
SELECT id, owner, repo, issue_number, title, body, labels, status, workflow, branch, plan, notes, pr_number, tokens_used, iterations, attempt, park_reason, watch_comment_id, park_class, remediation_rounds, retry_count, source, identity, binding_id, binding_version, review_payload, workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at, review_cursor, inputs, org_id, workspace_id, call_parent_task_id, call_depth, outputs, review_gate, rereview_rounds, retry_mode, resume_from, resume_results, pending_reviews, origin, call_key, outcome_posted, binding_signature, binding_addr, park_blocker FROM tasks
|
||||
WHERE origin <> '' AND NOT outcome_posted
|
||||
AND status IN ('merged', 'rejected', 'dead', 'closed_wont_do', 'completed')
|
||||
AND ($1::text IS NULL OR org_id = $1)
|
||||
@@ -1306,6 +1316,7 @@ func (q *Queries) UnpostedOutcomes(ctx context.Context, scopeOrg pgtype.Text) ([
|
||||
&i.OutcomePosted,
|
||||
&i.BindingSignature,
|
||||
&i.BindingAddr,
|
||||
&i.ParkBlocker,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -155,6 +155,7 @@ UPDATE tasks
|
||||
SET status = $2,
|
||||
park_reason = CASE WHEN $2 = 'parked' THEN $3 ELSE park_reason END,
|
||||
park_class = CASE WHEN $2 = 'parked' THEN $4 ELSE park_class END,
|
||||
park_blocker = CASE WHEN $2 = 'parked' THEN '' ELSE park_blocker END,
|
||||
updated_at = now()
|
||||
WHERE id = $1 AND status = $5;
|
||||
|
||||
@@ -165,7 +166,7 @@ FROM tasks t WHERE t.id = sqlc.arg(task_id);
|
||||
|
||||
-- name: ParkTask :execrows
|
||||
UPDATE tasks
|
||||
SET status = 'parked', park_reason = $2, park_class = $3, updated_at = now()
|
||||
SET status = 'parked', park_reason = $2, park_class = $3, park_blocker = $5, updated_at = now()
|
||||
WHERE id = $1 AND status = $4;
|
||||
|
||||
-- name: ClearTerminalTasks :execrows
|
||||
|
||||
@@ -120,6 +120,7 @@ func taskFromRow(t postgresdb.Task) *workflow.Task {
|
||||
ReviewGate: t.ReviewGate,
|
||||
RereviewRounds: int(t.RereviewRounds),
|
||||
ParkClass: t.ParkClass,
|
||||
ParkBlocker: t.ParkBlocker,
|
||||
RemediationRounds: int(t.RemediationRounds),
|
||||
CallParentTaskID: t.CallParentTaskID,
|
||||
CallDepth: int(t.CallDepth),
|
||||
@@ -318,7 +319,7 @@ func (s *Store) Transition(ctx context.Context, taskID int64, from, to, detail s
|
||||
// transition Transition performs, carrying the park class the site chose.
|
||||
// The park is only legal from running (the transition table), so a stale or
|
||||
// off-table from is refused before anything is written.
|
||||
func (s *Store) ParkTask(ctx context.Context, taskID int64, from, detail, class string) error {
|
||||
func (s *Store) ParkTask(ctx context.Context, taskID int64, from, detail, class, blocker string) error {
|
||||
tx, err := s.pool.Begin(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -331,7 +332,7 @@ func (s *Store) ParkTask(ctx context.Context, taskID int64, from, detail, class
|
||||
}
|
||||
n, err := q.ParkTask(ctx, postgresdb.ParkTaskParams{
|
||||
ID: taskID, ParkReason: clip(detail, 4000),
|
||||
ParkClass: taskstate.NormalizeParkClass(class), Status: from,
|
||||
ParkClass: taskstate.NormalizeParkClass(class), Status: from, ParkBlocker: blocker,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -237,8 +237,8 @@ func (c *Client) Requeue(ctx context.Context, taskID int64, fromStatus, wf strin
|
||||
return unmapError(err)
|
||||
}
|
||||
|
||||
func (c *Client) ParkTask(ctx context.Context, taskID int64, from, detail, class string) error {
|
||||
_, err := c.client.ParkTask(ctx, &pb.ParkTaskRequest{TaskId: taskID, From: from, Detail: detail, Class: class})
|
||||
func (c *Client) ParkTask(ctx context.Context, taskID int64, from, detail, class, blocker string) error {
|
||||
_, err := c.client.ParkTask(ctx, &pb.ParkTaskRequest{TaskId: taskID, From: from, Detail: detail, Class: class, Blocker: blocker})
|
||||
return unmapError(err)
|
||||
}
|
||||
|
||||
|
||||
@@ -433,7 +433,7 @@ func (s *server) Requeue(ctx context.Context, r *pb.RequeueRequest) (*pb.Requeue
|
||||
}
|
||||
|
||||
func (s *server) ParkTask(ctx context.Context, r *pb.ParkTaskRequest) (*pb.ParkTaskResponse, error) {
|
||||
if err := s.deps.Tasks.ParkTask(ctx, r.TaskId, r.From, r.Detail, r.Class); err != nil {
|
||||
if err := s.deps.Tasks.ParkTask(ctx, r.TaskId, r.From, r.Detail, r.Class, r.Blocker); err != nil {
|
||||
return nil, s.logErr("ParkTask", err)
|
||||
}
|
||||
return &pb.ParkTaskResponse{}, nil
|
||||
|
||||
@@ -77,6 +77,7 @@ func taskProto(t *task.Task) *pb.Task { // mirror-image field-by-field proto<->d
|
||||
RereviewRounds: int64(t.RereviewRounds),
|
||||
ReviewCursor: t.ReviewCursor,
|
||||
ParkClass: t.ParkClass,
|
||||
ParkBlocker: t.ParkBlocker,
|
||||
RemediationRounds: int32(t.RemediationRounds),
|
||||
WorkflowDefinitionVersion: t.WorkflowDefinitionVersion,
|
||||
WorkflowDefinitionDigest: t.WorkflowDefinitionDigest,
|
||||
@@ -113,6 +114,7 @@ func taskValue(t *pb.Task) *task.Task { // see taskProto above
|
||||
RereviewRounds: int(t.RereviewRounds),
|
||||
ReviewCursor: t.ReviewCursor,
|
||||
ParkClass: t.ParkClass,
|
||||
ParkBlocker: t.ParkBlocker,
|
||||
RemediationRounds: int(t.RemediationRounds),
|
||||
WorkflowDefinitionVersion: t.WorkflowDefinitionVersion,
|
||||
WorkflowDefinitionDigest: t.WorkflowDefinitionDigest,
|
||||
|
||||
@@ -251,6 +251,24 @@ const (
|
||||
ParkTerminal ParkClass = "terminal"
|
||||
)
|
||||
|
||||
// Blockers: what a parked task is missing, recorded at the park site so the
|
||||
// dashboard can route an operator to the page that supplies it. Part of the
|
||||
// on-disk format.
|
||||
const (
|
||||
// BlockerWorkflowDisabled: the task's org has the workflow turned off.
|
||||
BlockerWorkflowDisabled Blocker = "workflow_disabled"
|
||||
// BlockerWorkflowIdentity: the workflow declares no usable identity.
|
||||
BlockerWorkflowIdentity Blocker = "workflow_identity"
|
||||
// BlockerAgentAssignment: the execution identity is inactive or not
|
||||
// assigned to the task's org.
|
||||
BlockerAgentAssignment Blocker = "agent_assignment"
|
||||
// BlockerPolicyDenied: an access policy refuses the run.
|
||||
BlockerPolicyDenied Blocker = "policy_denied"
|
||||
)
|
||||
|
||||
// Blocker is the persisted park blocker string.
|
||||
type Blocker = string
|
||||
|
||||
// ParkClass is the persisted park classification string.
|
||||
type ParkClass = string
|
||||
|
||||
|
||||
@@ -39,6 +39,9 @@ type taskAttemptsView struct {
|
||||
Inputs map[string]any `json:"inputs,omitempty"`
|
||||
Outputs map[string]any `json:"outputs,omitempty"`
|
||||
CalledBy int64 `json:"called_by,omitempty"`
|
||||
// Recovery links a parked task to the page that fixes its blocker,
|
||||
// present only when the viewer may act there.
|
||||
Recovery *taskRecoveryView `json:"recovery,omitempty"`
|
||||
}
|
||||
|
||||
// taskAttemptView is one attempt, bounded by its first and last event.
|
||||
@@ -114,6 +117,7 @@ func (s *Server) handleTaskAttempts(w http.ResponseWriter, r *http.Request) {
|
||||
Inputs: t.Inputs,
|
||||
Outputs: t.Outputs,
|
||||
CalledBy: t.CallParentTaskID,
|
||||
Recovery: s.taskRecovery(r, t),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package webui
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/domain/access"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow/task"
|
||||
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||
)
|
||||
|
||||
// taskRecoveryView is the fix for a parked task's blocker: the dashboard page
|
||||
// that supplies what the task is missing.
|
||||
type taskRecoveryView struct {
|
||||
Blocker taskstate.Blocker `json:"blocker"`
|
||||
Label string `json:"label"`
|
||||
Link string `json:"link"`
|
||||
}
|
||||
|
||||
// recoveryRoute is where a blocker is fixed: the page, and the API write that
|
||||
// page makes, which decides whether the viewer may act there.
|
||||
type recoveryRoute struct {
|
||||
label, page, method, api string
|
||||
instance bool
|
||||
}
|
||||
|
||||
func blockerRoute(t *task.Task) (recoveryRoute, bool) {
|
||||
workflowPage := "/workflows?workflow=" + url.QueryEscape(t.Workflow)
|
||||
switch t.ParkBlocker {
|
||||
case taskstate.BlockerWorkflowDisabled:
|
||||
return recoveryRoute{label: "Enable workflow", page: workflowPage, method: http.MethodPut, api: "/api/workflows/" + url.PathEscape(t.Workflow) + "/enabled"}, true
|
||||
case taskstate.BlockerWorkflowIdentity:
|
||||
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.BlockerPolicyDenied:
|
||||
return recoveryRoute{label: "Edit policies", page: "/org/policies", method: http.MethodPut, api: "/api/access/policies"}, true
|
||||
}
|
||||
return recoveryRoute{}, false
|
||||
}
|
||||
|
||||
// taskRecovery returns the recovery link for a parked task, or nil when the
|
||||
// park names no blocker or the viewer may not make the fixing write.
|
||||
func (s *Server) taskRecovery(r *http.Request, t *task.Task) *taskRecoveryView {
|
||||
if t.Status != task.StatusParked || s.Access == nil {
|
||||
return nil
|
||||
}
|
||||
route, ok := blockerRoute(t)
|
||||
if !ok || (route.instance && !instanceViewer(r)) {
|
||||
return nil
|
||||
}
|
||||
principal, ok := access.PrincipalFromContext(r.Context())
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
action, kind, id := accessRequest(&http.Request{Method: route.method, URL: &url.URL{Path: route.api}})
|
||||
resource, err := s.recordResource(r.Context(), kind, id)
|
||||
if err != nil || !s.Access.Authorize(principal, action, resource, access.Context{}).Allowed {
|
||||
return nil
|
||||
}
|
||||
return &taskRecoveryView{Blocker: t.ParkBlocker, Label: route.label, Link: route.page}
|
||||
}
|
||||
Reference in new issue
Block a user