feat(state-store): flag parked tasks when the resource their blocker names changes (#1839)

This commit is contained in:
sam committed 2026-11-09 14:40:58 +11:00
1 parent e34941b1eb
commit 82313e4af5
3 files changed
+51

No files matched your search

@@ -866,6 +866,23 @@ func (q *Queries) LockTaskStatus(ctx context.Context, id int64) (string, error)
return status, err
}
const markBlockerChanged = `-- name: MarkBlockerChanged :execrows
UPDATE tasks
SET park_reason = park_reason || ' [blocker changed]', updated_at = now()
WHERE status = 'parked' AND park_blocker = ANY($1::text[])
AND park_reason NOT LIKE '%[blocker changed]'
`
// A parked task that names one of these blockers is flagged once, so the
// operator sees the resource it waited on was edited; retry stays theirs.
func (q *Queries) MarkBlockerChanged(ctx context.Context, blockers []string) (int64, error) {
result, err := q.db.Exec(ctx, markBlockerChanged, blockers)
if err != nil {
return 0, err
}
return result.RowsAffected(), nil
}
const markHandedOff = `-- name: MarkHandedOff :execrows
UPDATE tasks SET handoff_to_task_id = $1, updated_at = now()
WHERE id = $2 AND handoff_to_task_id IS NULL
@@ -330,3 +330,11 @@ SELECT sqlc.arg(successor_id), t.owner, t.repo, t.issue_number, t.title, t.body,
t.binding_addr, t.origin, t.call_parent_task_id, t.call_depth, t.id
FROM tasks t WHERE t.id = sqlc.arg(id)
RETURNING *;
-- name: MarkBlockerChanged :execrows
-- A parked task that names one of these blockers is flagged once, so the
-- operator sees the resource it waited on was edited; retry stays theirs.
UPDATE tasks
SET park_reason = park_reason || ' [blocker changed]', updated_at = now()
WHERE status = 'parked' AND park_blocker = ANY(sqlc.arg(blockers)::text[])
AND park_reason NOT LIKE '%[blocker changed]';
@@ -12,6 +12,7 @@ import (
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/postgresdb"
"github.com/samcharles93/archie-core/internal/taskstate"
)
// Resources is the PostgreSQL implementation of the State Store's
@@ -85,6 +86,26 @@ func checkResourceKey(orgID, kind string) error {
return nil
}
// blockersFixedBy names the park blockers an edit of a resource kind may have
// cleared.
func blockersFixedBy(kind string) []string {
switch kind {
case "forge-connections":
return []string{taskstate.BlockerConnectionPermit, taskstate.BlockerConnectionCredential, taskstate.BlockerForgeExtension, taskstate.BlockerRepository}
case "identity-grants":
return []string{taskstate.BlockerConnectionPermit, taskstate.BlockerAgentAssignment}
case "repository-policies":
return []string{taskstate.BlockerRepository}
case "credential-bindings":
return []string{taskstate.BlockerConnectionCredential, taskstate.BlockerModelCredential}
case "provider-settings":
return []string{taskstate.BlockerModelCredential}
case "workflow-enablement":
return []string{taskstate.BlockerWorkflowDisabled}
}
return nil
}
// PutResource applies one control-plane resource write, idempotent per
// request ID.
func (s *Resources) PutResource(ctx context.Context, write storecontract.ResourceWrite) (_ storecontract.Resource, retErr error) {
@@ -125,6 +146,11 @@ func (s *Resources) PutResource(ctx context.Context, write storecontract.Resourc
if err != nil {
return storecontract.Resource{}, err
}
if blockers := blockersFixedBy(write.Kind); len(blockers) > 0 {
if _, err := queries.MarkBlockerChanged(ctx, blockers); err != nil {
return storecontract.Resource{}, err
}
}
if err := tx.Commit(ctx); err != nil {
return storecontract.Resource{}, err
}