feat(workflow): typed park classification and split remediation budgets
The F2+F3 schema wave from the auto-fix/resume investigation, sequenced together as one migration. Every failure funneled to one parked status with free-text ParkReason, and Task.RetryCount doubled as the operator-retry budget and the review-remediation round budget -- so N operator retries ate the remediation budget, a repo-level round cap could re-park a task an operator had just legally retried, and no surface could answer what a park needed from an operator. Park class (F2): a producer-recorded vocabulary in taskstate -- needs_human (the default, so an unclassified park always reads as operator-actionable), transient (environmental; a requeue can succeed), terminal (retrying is pointless). Recorded at the park site, never inferred from reason text; NormalizeParkClass makes unknown values persist as needs_human. Transition-to-parked defaults the class, so every existing unclassified park site reads correctly with no call-site churn; the classified ParkTask write follows for parks that know better. Requeue, RetryTask and BeginRemediation clear the class back to the default with the reason. Split budgets (F3): Task.RemediationRounds is the remediation's own budget; RetryCount stays the operator's. The round-cap stage counts and caps rounds; operator retry keeps counting RetryCount and can drive a task to dead without touching rounds. remediation_rounds is a presence-gated migrator column written through Update. Known state: proto fields, the ParkTask RPC, the staterpc mapping and the daemon-side park-site classification follow in the wire half of this wave (the proto parity test is intentionally red until then).
This commit is contained in:
7 files changed
+258
-29
No files matched your search
@@ -155,19 +155,22 @@ func StageResumeWorktree() Stage {
|
||||
|
||||
// StageRemediationRoundCap enforces the hard stop on an unbounded
|
||||
// remediate/re-review exchange (decision 5, "bounding the exchange").
|
||||
// Task.RetryCount doubles as the remediation round counter here: on the
|
||||
// Task.RemediationRounds is the remediation's own budget, separate from
|
||||
// RetryCount (the operator's): one shared counter made N operator retries
|
||||
// eat the review-remediation budget and vice versa, and let a repo-level
|
||||
// round cap re-park a task an operator had just legally retried. On the
|
||||
// cap it parks the task and posts one comment explaining why, without
|
||||
// running the builder; under the cap it counts this round and proceeds.
|
||||
func StageRemediationRoundCap() Stage {
|
||||
return Stage{Name: "round-cap", Run: func(ctx context.Context, tc *TaskContext) error {
|
||||
maxRounds := tc.Repo.EffectiveMaxRetries(tc.Cfg.MaxRetries)
|
||||
if maxRounds > 0 && tc.Task.RetryCount >= maxRounds {
|
||||
detail := fmt.Sprintf("remediation round cap reached (%d/%d); stopping and parking for an operator", tc.Task.RetryCount, maxRounds)
|
||||
if maxRounds > 0 && tc.Task.RemediationRounds >= maxRounds {
|
||||
detail := fmt.Sprintf("remediation round cap reached (%d/%d); stopping and parking for an operator", tc.Task.RemediationRounds, maxRounds)
|
||||
postRemediationComment(ctx, tc, "Archie has stopped remediating this review: "+detail+".")
|
||||
tc.Outcome = Outcome{Status: StatusParked, Detail: clip(detail, remediationRoundCapBytes)}
|
||||
return nil
|
||||
}
|
||||
tc.Task.RetryCount++
|
||||
tc.Task.RemediationRounds++
|
||||
return nil
|
||||
}}
|
||||
}
|
||||
@@ -272,7 +275,7 @@ func StageRemediationReply() Stage {
|
||||
if tc.BuildNoChanges {
|
||||
summary = "Reviewed -- no code change was required."
|
||||
}
|
||||
reply := fmt.Sprintf("%s\n\n---\n*archie remediation, round %d*", summary, tc.Task.RetryCount)
|
||||
reply := fmt.Sprintf("%s\n\n---\n*archie remediation, round %d*", summary, tc.Task.RemediationRounds)
|
||||
|
||||
if id, ok := tc.reviewUnit.replyTarget(); ok {
|
||||
if err := tc.Forge.ReplyToReview(ctx, tc.Task.Owner, tc.Task.Repo, tc.Task.PRNumber, id, reply); err != nil {
|
||||
@@ -283,7 +286,7 @@ func StageRemediationReply() Stage {
|
||||
}
|
||||
|
||||
tc.Task.ReviewPayload = ""
|
||||
tc.Outcome = Outcome{Status: StatusPROpen, Detail: fmt.Sprintf("remediated review round %d", tc.Task.RetryCount)}
|
||||
tc.Outcome = Outcome{Status: StatusPROpen, Detail: fmt.Sprintf("remediated review round %d", tc.Task.RemediationRounds)}
|
||||
return nil
|
||||
}}
|
||||
}
|
||||
|
||||
@@ -70,14 +70,14 @@ func TestStageResumeWorktreeResumesOntoTheTaskBranch(t *testing.T) {
|
||||
func TestStageRemediationRoundCapCountsARoundUnderTheCap(t *testing.T) {
|
||||
forge := &fakeForge{}
|
||||
tc := &TaskContext{
|
||||
Task: &Task{ID: 1, RetryCount: 1}, Repo: config.Repo{MaxRetries: 3}, Forge: forge,
|
||||
Task: &Task{ID: 1, RemediationRounds: 1}, Repo: config.Repo{MaxRetries: 3}, Forge: forge,
|
||||
Log: slog.New(slog.DiscardHandler),
|
||||
}
|
||||
if err := StageRemediationRoundCap().Run(t.Context(), tc); err != nil {
|
||||
t.Fatalf("StageRemediationRoundCap: %v", err)
|
||||
}
|
||||
if tc.Task.RetryCount != 2 {
|
||||
t.Fatalf("RetryCount = %d, want 2", tc.Task.RetryCount)
|
||||
if tc.Task.RemediationRounds != 2 {
|
||||
t.Fatalf("RemediationRounds = %d, want 2", tc.Task.RemediationRounds)
|
||||
}
|
||||
if tc.Outcome.Status != "" {
|
||||
t.Fatalf("Outcome = %+v, want zero value (workflow continues)", tc.Outcome)
|
||||
@@ -90,14 +90,14 @@ func TestStageRemediationRoundCapCountsARoundUnderTheCap(t *testing.T) {
|
||||
func TestStageRemediationRoundCapParksAtTheCapAndPostsOneComment(t *testing.T) {
|
||||
forge := &fakeForge{}
|
||||
tc := &TaskContext{
|
||||
Task: &Task{ID: 1, RetryCount: 3, PRNumber: 9}, Repo: config.Repo{MaxRetries: 3}, Forge: forge,
|
||||
Task: &Task{ID: 1, RemediationRounds: 3, PRNumber: 9}, Repo: config.Repo{MaxRetries: 3}, Forge: forge,
|
||||
Log: slog.New(slog.DiscardHandler),
|
||||
}
|
||||
if err := StageRemediationRoundCap().Run(t.Context(), tc); err != nil {
|
||||
t.Fatalf("StageRemediationRoundCap: %v", err)
|
||||
}
|
||||
if tc.Task.RetryCount != 3 {
|
||||
t.Fatalf("RetryCount = %d, want unchanged at 3", tc.Task.RetryCount)
|
||||
if tc.Task.RemediationRounds != 3 {
|
||||
t.Fatalf("RemediationRounds = %d, want unchanged at 3", tc.Task.RemediationRounds)
|
||||
}
|
||||
if tc.Outcome.Status != StatusParked {
|
||||
t.Fatalf("Outcome.Status = %q, want parked", tc.Outcome.Status)
|
||||
@@ -109,7 +109,7 @@ func TestStageRemediationRoundCapParksAtTheCapAndPostsOneComment(t *testing.T) {
|
||||
|
||||
func TestStageRemediationRoundCapZeroMeansUnlimited(t *testing.T) {
|
||||
tc := &TaskContext{
|
||||
Task: &Task{ID: 1, RetryCount: 50}, Repo: config.Repo{}, Cfg: config.Config{MaxRetries: 0},
|
||||
Task: &Task{ID: 1, RemediationRounds: 50}, Repo: config.Repo{}, Cfg: config.Config{MaxRetries: 0},
|
||||
Forge: &fakeForge{}, Log: slog.New(slog.DiscardHandler),
|
||||
}
|
||||
if err := StageRemediationRoundCap().Run(t.Context(), tc); err != nil {
|
||||
@@ -118,8 +118,8 @@ func TestStageRemediationRoundCapZeroMeansUnlimited(t *testing.T) {
|
||||
if tc.Outcome.Status == StatusParked {
|
||||
t.Fatal("Outcome = parked, want no cap enforced when max_retries is unset")
|
||||
}
|
||||
if tc.Task.RetryCount != 51 {
|
||||
t.Fatalf("RetryCount = %d, want 51", tc.Task.RetryCount)
|
||||
if tc.Task.RemediationRounds != 51 {
|
||||
t.Fatalf("RemediationRounds = %d, want 51", tc.Task.RemediationRounds)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,8 +240,8 @@ func TestRemediateEndToEndAddressesCommentsAndReplies(t *testing.T) {
|
||||
if forge.replyCommentID != 10 {
|
||||
t.Fatalf("replyCommentID = %d, want 10", forge.replyCommentID)
|
||||
}
|
||||
if task.RetryCount != 1 {
|
||||
t.Fatalf("RetryCount = %d, want 1 (one round consumed)", task.RetryCount)
|
||||
if task.RemediationRounds != 1 {
|
||||
t.Fatalf("RemediationRounds = %d, want 1 (one round consumed)", task.RemediationRounds)
|
||||
}
|
||||
if task.ReviewPayload != "" {
|
||||
t.Fatalf("ReviewPayload = %q, want cleared", task.ReviewPayload)
|
||||
|
||||
@@ -100,6 +100,17 @@ type Task struct {
|
||||
// the remediation round counter for this same task, bounded by the
|
||||
// repo's existing max_retries (decision 5's round cap).
|
||||
ReviewPayload string `json:"review_payload"`
|
||||
// ParkClass is the producer-recorded answer to "what kind of
|
||||
// intervention does this park need?" (taskstate.ParkClass). Set at the
|
||||
// park site, never inferred from reason text; needs_human is the
|
||||
// default an unclassified park reads as.
|
||||
ParkClass string `json:"park_class"`
|
||||
// RemediationRounds counts review-triggered remediation rounds,
|
||||
// bounded by the repo's max_retries (pr-review-remediation.md
|
||||
// decision 5). Deliberately separate from RetryCount, the operator
|
||||
// budget: one shared counter made N operator retries eat the
|
||||
// review-remediation budget and vice versa.
|
||||
RemediationRounds int `json:"remediation_rounds"`
|
||||
// CreatedAt and UpdatedAt are the SQLite row timestamps, exposed so
|
||||
// callers can show a task's age and last activity. They are written by
|
||||
// column defaults and the UPDATE statements, never by the caller.
|
||||
|
||||
@@ -107,3 +107,114 @@ func TestUpdateReviewPayloadAppendsOnlyWhileARemediationIsQueued(t *testing.T) {
|
||||
t.Errorf("UpdateReviewPayload while running err = %v, want ErrStaleTransition", err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestParkTaskWritesItsClassification pins the classified park write: the
|
||||
// class is recorded at the park site in the same guarded write, and an
|
||||
// unclassified park defaults to needs_human.
|
||||
func TestParkTaskWritesItsClassification(t *testing.T) {
|
||||
s := openTest(t)
|
||||
ctx := t.Context()
|
||||
if _, err := s.EnqueueIssue(ctx, "acme", "widgets", 1, "t", "b", "", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
task, _ := s.TaskByIssue(ctx, "acme", "widgets", 1)
|
||||
if _, err := s.ClaimNext(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := s.ParkTask(ctx, task.ID, workflow.StatusRunning, "container acquire failed", "transient"); err != nil {
|
||||
t.Fatalf("ParkTask: %v", err)
|
||||
}
|
||||
got, err := s.TaskByID(ctx, task.ID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.Status != workflow.StatusParked || got.ParkReason != "container acquire failed" {
|
||||
t.Errorf("park row = status:%q reason:%q", got.Status, got.ParkReason)
|
||||
}
|
||||
if got.ParkClass != "transient" {
|
||||
t.Errorf("park_class = %q, want transient", got.ParkClass)
|
||||
}
|
||||
|
||||
// Requeue clears the class with the reason: a stale class on a queued
|
||||
// task would group a live task with parked ones.
|
||||
if err := s.Requeue(ctx, task.ID, workflow.StatusParked, ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, _ = s.TaskByID(ctx, task.ID)
|
||||
if got.ParkClass != "needs_human" || got.ParkReason != "" {
|
||||
t.Errorf("after requeue: class=%q reason=%q, want cleared", got.ParkClass, got.ParkReason)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParkTaskRejectsAnUnknownClass(t *testing.T) {
|
||||
s := openTest(t)
|
||||
ctx := t.Context()
|
||||
if _, err := s.EnqueueIssue(ctx, "acme", "widgets", 1, "t", "b", "", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
task, _ := s.TaskByIssue(ctx, "acme", "widgets", 1)
|
||||
if _, err := s.ClaimNext(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// An unknown class normalizes to needs_human rather than persisting a
|
||||
// value no consumer knows how to group.
|
||||
if err := s.ParkTask(ctx, task.ID, workflow.StatusRunning, "x", "urgent"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, _ := s.TaskByID(ctx, task.ID)
|
||||
if got.ParkClass != "needs_human" {
|
||||
t.Errorf("park_class = %q, want the needs_human fallback", got.ParkClass)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParkTaskStaleGuard(t *testing.T) {
|
||||
s := openTest(t)
|
||||
ctx := t.Context()
|
||||
if _, err := s.EnqueueIssue(ctx, "acme", "widgets", 1, "t", "b", "", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
task, _ := s.TaskByIssue(ctx, "acme", "widgets", 1)
|
||||
// Still queued, not running: the from guard must refuse.
|
||||
if err := s.ParkTask(ctx, task.ID, workflow.StatusRunning, "x", "transient"); !errors.Is(err, ErrStaleTransition) {
|
||||
t.Errorf("ParkTask stale err = %v, want ErrStaleTransition", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTransitionToParkedDefaultsTheClass(t *testing.T) {
|
||||
s := openTest(t)
|
||||
ctx := t.Context()
|
||||
if _, err := s.EnqueueIssue(ctx, "acme", "widgets", 1, "t", "b", "", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
task, _ := s.TaskByIssue(ctx, "acme", "widgets", 1)
|
||||
if _, err := s.ClaimNext(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// The generic transition is the workflow engine's park path: every
|
||||
// unclassified park reads as operator-actionable.
|
||||
if err := s.Transition(ctx, task.ID, workflow.StatusRunning, workflow.StatusParked, "gate failed"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, _ := s.TaskByID(ctx, task.ID)
|
||||
if got.ParkClass != "needs_human" {
|
||||
t.Errorf("park_class = %q, want the needs_human default", got.ParkClass)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateCarriesRemediationRounds(t *testing.T) {
|
||||
s := openTest(t)
|
||||
ctx := t.Context()
|
||||
if _, err := s.EnqueueIssue(ctx, "acme", "widgets", 1, "t", "b", "", ""); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
task, _ := s.TaskByIssue(ctx, "acme", "widgets", 1)
|
||||
task.RemediationRounds = 2
|
||||
if err := s.Update(ctx, task); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, _ := s.TaskByID(ctx, task.ID)
|
||||
if got.RemediationRounds != 2 {
|
||||
t.Errorf("remediation_rounds = %d, want 2", got.RemediationRounds)
|
||||
}
|
||||
}
|
||||
+60
-12
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/samcharles93/archie-core/internal/domain/storecontract"
|
||||
"github.com/samcharles93/archie-core/internal/domain/workflow"
|
||||
"github.com/samcharles93/archie-core/internal/events"
|
||||
"github.com/samcharles93/archie-core/internal/taskstate"
|
||||
)
|
||||
|
||||
type Store struct {
|
||||
@@ -102,6 +103,8 @@ func migrateTasks(ctx context.Context, db *sql.DB) error {
|
||||
}{
|
||||
{"tasks", "watch_comment_id", `ALTER TABLE tasks ADD COLUMN watch_comment_id INTEGER NOT NULL DEFAULT 0`},
|
||||
{"tasks", "review_cursor", `ALTER TABLE tasks ADD COLUMN review_cursor INTEGER NOT NULL DEFAULT 0`},
|
||||
{"tasks", "park_class", `ALTER TABLE tasks ADD COLUMN park_class TEXT NOT NULL DEFAULT 'needs_human'`},
|
||||
{"tasks", "remediation_rounds", `ALTER TABLE tasks ADD COLUMN remediation_rounds INTEGER NOT NULL DEFAULT 0`},
|
||||
{"tasks", "retry_count", `ALTER TABLE tasks ADD COLUMN retry_count INTEGER NOT NULL DEFAULT 0`},
|
||||
{"tasks", "source", `ALTER TABLE tasks ADD COLUMN source TEXT NOT NULL DEFAULT 'forge'`},
|
||||
{"tasks", "identity", `ALTER TABLE tasks ADD COLUMN identity TEXT NOT NULL DEFAULT ''`},
|
||||
@@ -295,6 +298,8 @@ CREATE TABLE IF NOT EXISTS tasks (
|
||||
attempt INTEGER NOT NULL DEFAULT 0,
|
||||
park_reason TEXT NOT NULL DEFAULT '',
|
||||
watch_comment_id INTEGER NOT NULL DEFAULT 0,
|
||||
park_class TEXT NOT NULL DEFAULT 'needs_human',
|
||||
remediation_rounds INTEGER NOT NULL DEFAULT 0,
|
||||
retry_count INTEGER NOT NULL DEFAULT 0,
|
||||
source TEXT NOT NULL DEFAULT 'forge',
|
||||
identity TEXT NOT NULL DEFAULT '',
|
||||
@@ -381,7 +386,7 @@ func (s *Store) EnqueueChatTask(ctx context.Context, owner, repo, title, body, w
|
||||
workflow, stage, branch, plan, notes, pr_number, tokens_used,
|
||||
iterations, attempt, park_reason, watch_comment_id, retry_count,
|
||||
source, identity, binding_id, binding_version, review_payload,
|
||||
workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at`,
|
||||
workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, park_class, remediation_rounds, created_at, updated_at`,
|
||||
owner, repo, owner, repo, syntheticIssueNumberBase-1, title, body, wf, identity)
|
||||
return scanTask(row)
|
||||
}
|
||||
@@ -423,7 +428,7 @@ func (s *Store) ClaimNext(ctx context.Context) (*workflow.Task, error) {
|
||||
workflow, stage, branch, plan, notes, pr_number, tokens_used,
|
||||
iterations, attempt, park_reason, watch_comment_id, retry_count,
|
||||
source, identity, binding_id, binding_version, review_payload,
|
||||
workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at`,
|
||||
workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, park_class, remediation_rounds, created_at, updated_at`,
|
||||
workflow.StatusRunning, workflow.StatusQueued)
|
||||
t, err := scanTask(row)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
@@ -440,6 +445,7 @@ func scanTask(row *sql.Row) (*workflow.Task, error) {
|
||||
&t.WatchCommentID, &t.RetryCount, &t.Source, &t.Identity,
|
||||
&t.BindingID, &t.BindingVersion, &t.ReviewPayload,
|
||||
&t.WorkflowDefinitionVersion, &t.WorkflowDefinitionDigest, &t.WorkflowDefinitionYAML,
|
||||
&t.ParkClass, &t.RemediationRounds,
|
||||
sqliteTime{&t.CreatedAt}, sqliteTime{&t.UpdatedAt})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -459,7 +465,7 @@ func (s *Store) ClaimByIssue(ctx context.Context, owner, repo string, number int
|
||||
workflow, stage, branch, plan, notes, pr_number, tokens_used,
|
||||
iterations, attempt, park_reason, watch_comment_id, retry_count,
|
||||
source, identity, binding_id, binding_version, review_payload,
|
||||
workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at`,
|
||||
workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, park_class, remediation_rounds, created_at, updated_at`,
|
||||
workflow.StatusRunning, owner, repo, number, workflow.StatusQueued)
|
||||
t, err := scanTask(row)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
@@ -488,9 +494,11 @@ func (s *Store) Transition(ctx context.Context, taskID int64, from, to, detail s
|
||||
UPDATE tasks
|
||||
SET status=?,
|
||||
park_reason=CASE WHEN ?=? THEN ? ELSE park_reason END,
|
||||
park_class=CASE WHEN ?=? THEN ? ELSE park_class END,
|
||||
updated_at=datetime('now')
|
||||
WHERE id=? AND status=?`,
|
||||
to, to, workflow.StatusParked, clip(detail, 4000), taskID, from)
|
||||
to, to, workflow.StatusParked, clip(detail, 4000),
|
||||
to, to, taskstate.ParkNeedsHuman, taskID, from)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -512,17 +520,57 @@ func (s *Store) Transition(ctx context.Context, taskID int64, from, to, detail s
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
// ParkTask is the classified park write: the same guarded running->parked
|
||||
// transition Transition performs, carrying the park class the site chose.
|
||||
// The class is normalized here so an unknown value persists as needs_human
|
||||
// -- the safe misread is "an operator should look at this".
|
||||
func (s *Store) ParkTask(ctx context.Context, taskID int64, from, detail, class string) error {
|
||||
tx, err := s.db.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
res, err := tx.ExecContext(ctx, `
|
||||
UPDATE tasks
|
||||
SET status=?,
|
||||
park_reason=?,
|
||||
park_class=?,
|
||||
updated_at=datetime('now')
|
||||
WHERE id=? AND status=?`,
|
||||
workflow.StatusParked, clip(detail, 4000),
|
||||
taskstate.NormalizeParkClass(class), taskID, from)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
n, err := res.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if n == 0 {
|
||||
return ErrStaleTransition
|
||||
}
|
||||
|
||||
if _, err := tx.ExecContext(ctx,
|
||||
`INSERT INTO transitions (task_id, from_status, to_status, detail) VALUES (?, ?, ?, ?)`,
|
||||
taskID, from, workflow.StatusParked, clip(detail, 4000)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
// Update persists mutable task fields written by workflows.
|
||||
func (s *Store) Update(ctx context.Context, t *workflow.Task) error {
|
||||
_, err := s.db.ExecContext(ctx, `
|
||||
UPDATE tasks SET workflow=?, stage=?, branch=?, plan=?, notes=?,
|
||||
pr_number=?, tokens_used=?, iterations=?, park_reason=?,
|
||||
watch_comment_id=?, retry_count=?, review_payload=?, workflow_definition_version=?,
|
||||
watch_comment_id=?, retry_count=?, remediation_rounds=?, review_payload=?, workflow_definition_version=?,
|
||||
workflow_definition_digest=?, workflow_definition_yaml=?, updated_at=datetime('now')
|
||||
WHERE id=?`,
|
||||
t.Workflow, t.Stage, t.Branch, t.Plan, t.Notes,
|
||||
t.PRNumber, t.TokensUsed, t.Iterations, clip(t.ParkReason, 4000),
|
||||
t.WatchCommentID, t.RetryCount, t.ReviewPayload, t.WorkflowDefinitionVersion,
|
||||
t.WatchCommentID, t.RetryCount, t.RemediationRounds, t.ReviewPayload, t.WorkflowDefinitionVersion,
|
||||
t.WorkflowDefinitionDigest, t.WorkflowDefinitionYAML, t.ID)
|
||||
return err
|
||||
}
|
||||
@@ -541,7 +589,7 @@ func (s *Store) BeginRemediation(ctx context.Context, taskID int64, payload stri
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
res, err := tx.ExecContext(ctx, `
|
||||
UPDATE tasks SET status=?, workflow=?, stage='', park_reason='', review_payload=?,
|
||||
UPDATE tasks SET status=?, workflow=?, stage='', park_reason='', park_class='needs_human', review_payload=?,
|
||||
updated_at=datetime('now')
|
||||
WHERE id=? AND status=?`, workflow.StatusQueued, "remediate", clip(payload, 4000), taskID, workflow.StatusPROpen)
|
||||
if err != nil {
|
||||
@@ -616,7 +664,7 @@ func (s *Store) TaskByIssue(ctx context.Context, owner, repo string, number int)
|
||||
workflow, stage, branch, plan, notes, pr_number, tokens_used,
|
||||
iterations, attempt, park_reason, watch_comment_id, retry_count,
|
||||
source, identity, binding_id, binding_version, review_payload,
|
||||
workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at
|
||||
workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, park_class, remediation_rounds, created_at, updated_at
|
||||
FROM tasks WHERE owner=? AND repo=? AND issue_number=?`, owner, repo, number)
|
||||
t, err := scanTask(row)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
@@ -632,7 +680,7 @@ func (s *Store) OpenTaskByPR(ctx context.Context, owner, repo string, number int
|
||||
workflow, stage, branch, plan, notes, pr_number, tokens_used,
|
||||
iterations, attempt, park_reason, watch_comment_id, retry_count,
|
||||
source, identity, binding_id, binding_version, review_payload,
|
||||
workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at
|
||||
workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, park_class, remediation_rounds, created_at, updated_at
|
||||
FROM tasks
|
||||
WHERE owner=? AND repo=? AND pr_number=? AND status=?`,
|
||||
owner, repo, number, workflow.StatusPROpen)
|
||||
@@ -652,7 +700,7 @@ func (s *Store) TaskByID(ctx context.Context, taskID int64) (*workflow.Task, err
|
||||
workflow, stage, branch, plan, notes, pr_number, tokens_used,
|
||||
iterations, attempt, park_reason, watch_comment_id, retry_count,
|
||||
source, identity, binding_id, binding_version, review_payload,
|
||||
workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, created_at, updated_at
|
||||
workflow_definition_version, workflow_definition_digest, workflow_definition_yaml, park_class, remediation_rounds, created_at, updated_at
|
||||
FROM tasks WHERE id=?`, taskID)
|
||||
t, err := scanTask(row)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
@@ -678,7 +726,7 @@ func (s *Store) Requeue(ctx context.Context, taskID int64, fromStatus, wf string
|
||||
res, err := tx.ExecContext(ctx, `
|
||||
UPDATE tasks SET status=?,
|
||||
workflow=CASE WHEN ?='' THEN workflow ELSE ? END,
|
||||
stage='', park_reason='', updated_at=datetime('now')
|
||||
stage='', park_reason='', park_class='needs_human', updated_at=datetime('now')
|
||||
WHERE id=? AND status=?`, workflow.StatusQueued, wf, wf, taskID, fromStatus)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -714,7 +762,7 @@ func (s *Store) RetryTask(ctx context.Context, taskID int64, fromStatus, wf stri
|
||||
res, err := tx.ExecContext(ctx, `
|
||||
UPDATE tasks SET status=?, retry_count=retry_count+1,
|
||||
workflow=CASE WHEN ?='' THEN workflow ELSE ? END,
|
||||
stage='', park_reason='', updated_at=datetime('now')
|
||||
stage='', park_reason='', park_class='needs_human', updated_at=datetime('now')
|
||||
WHERE id=? AND status=?`, workflow.StatusQueued, wf, wf, taskID, fromStatus)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -194,3 +194,38 @@ func ActionCatalog() []ActionMeta {
|
||||
{ID: string(ActionOpenIssue), Label: "Open issue", Kind: "link"},
|
||||
}
|
||||
}
|
||||
|
||||
// Park classes: the producer-side answer to "what kind of intervention does
|
||||
// this park need?" (docs/prds/pr-review-remediation.md's F2, the typed
|
||||
// classification agent-system.md:327 acknowledges the data model lacks).
|
||||
// The class is recorded at the park site, where the cause is known, and is
|
||||
// never inferred later from reason text. It is part of the on-disk format.
|
||||
const (
|
||||
// ParkNeedsHuman parks need an operator decision: gate failures,
|
||||
// review verdicts, diff caps, remediation round caps. It is the
|
||||
// default, so an unclassified park always reads as operator-actionable.
|
||||
ParkNeedsHuman ParkClass = "needs_human"
|
||||
// ParkTransient parks are environmental: storage, container pool,
|
||||
// grants, transport. Nothing about the work is wrong; a requeue can
|
||||
// succeed. Nothing retries them automatically yet -- the class is
|
||||
// recorded so a future retry pass has a safe, queryable input.
|
||||
ParkTransient ParkClass = "transient"
|
||||
// ParkTerminal parks cannot be retried into success: the repo left the
|
||||
// config, the owning identity retired. An operator archives these.
|
||||
ParkTerminal ParkClass = "terminal"
|
||||
)
|
||||
|
||||
// ParkClass is the persisted park classification string.
|
||||
type ParkClass = string
|
||||
|
||||
// NormalizeParkClass maps a park class written by a producer to the value
|
||||
// the store persists. Empty and unknown fall back to NeedsHuman: the safe
|
||||
// misread is "an operator should look at this", never "nothing to do".
|
||||
func NormalizeParkClass(class string) ParkClass {
|
||||
switch class {
|
||||
case ParkTransient, ParkTerminal:
|
||||
return class
|
||||
default:
|
||||
return ParkNeedsHuman
|
||||
}
|
||||
}
|
||||
@@ -153,3 +153,24 @@ func TestActionsReturnsIndependentSlices(t *testing.T) {
|
||||
t.Fatalf("mutating returned actions changed lifecycle table: %v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeParkClass(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
want ParkClass
|
||||
}{
|
||||
{name: "empty defaults to needs_human", input: "", want: ParkNeedsHuman},
|
||||
{name: "a known class passes through", input: ParkTransient, want: ParkTransient},
|
||||
{name: "terminal passes through", input: ParkTerminal, want: ParkTerminal},
|
||||
{name: "an unknown class falls back to needs_human", input: "urgent", want: ParkNeedsHuman},
|
||||
{name: "case differences are not classes", input: "TRANSIENT", want: ParkNeedsHuman},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := NormalizeParkClass(tt.input); got != tt.want {
|
||||
t.Errorf("NormalizeParkClass(%q) = %q, want %q", tt.input, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user