Files
archie/internal/infrastructure/taskactions/store.go
T
sam 72fcab3a13 feat(taskactions): one approval path answers the review gate from every surface
Decision 1 of docs/prds/pr-review-operator-response.md: the dashboard's
POST /api/tasks/{id}/action is the authoritative surface, chat's /approve
is a shortcut that posts every offered finding, and both reach the same
Service.Apply so one operator intent cannot be recorded as two decisions.

The action body now carries instructions (required by rereview) and the
finding keys an approve posts. taskactions.Service answers an offer
through the guarded RespondReviewGate write: approve records the
selection on the offer, rereview records the instructions, increments the
round and clears the offer, and a rereview with no instructions, with no
offer, or at the cap is refused as a conflict with nothing written. Chat
reaches the same service: chatTaskControllerAdapter.ApproveChatTask
delegates to b.taskActions() instead of its own requeue, which is what
removed the handler's hardcoded implement handoff -- feasibility's deliver
stage now names implement on the task before it waits, the invariant the
handler needs.

The payload crosses every hop it must: the NATS action request, the
gateway.v1 gRPC contract (regenerated), the LocalChatAdapter, and the
webui handler, which answers 400 for a rereview without instructions and
409 for the cap. A rereview event kind names its actor the way the
approval and rejection trios do.

taskactions.Task gains review_gate and rereview_rounds, and the two
surfaces' tests assert they agree.
2026-10-02 02:27:59 +10:00

88 lines
3.3 KiB
Go

// Package taskactions adapts legacy task persistence to operator actions.
package taskactions
import (
"context"
"fmt"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/domain/taskactions"
)
type Store struct{ storecontract.TaskStore }
func (s Store) TaskByID(ctx context.Context, id int64) (*taskactions.Task, error) {
t, err := s.TaskStore.TaskByID(ctx, id)
if err != nil || t == nil {
return nil, err
}
return &taskactions.Task{ID: t.ID, Owner: t.Owner, Repo: t.Repo, Identity: t.Identity, Status: t.Status, ParkReason: t.ParkReason, IssueNumber: t.IssueNumber, RetryCount: t.RetryCount, Attempt: t.Attempt, ForgeBacked: t.IsForgeBacked(), ReviewGate: t.ReviewGate, RereviewRounds: t.RereviewRounds}, nil
}
// CancelExecution delegates to the store's one cancel path
// (docs/prds/execution-tree-state-machine.md). Both adapters -- the
// PostgreSQL store and the remote gRPC client -- implement it; the type
// assertion failing would be a composition bug, so it is named rather than
// panicked over.
func (s Store) CancelExecution(ctx context.Context, taskID int64, reason, to string) ([]int64, error) {
canceller, ok := s.TaskStore.(storecontract.ExecutionCanceller)
if !ok {
return nil, fmt.Errorf("task store cannot cancel executions")
}
return canceller.CancelExecution(ctx, taskID, reason, to)
}
// RespondReviewGate delegates to the store's guarded response write. Both
// adapters -- the PostgreSQL store and the remote gRPC client -- implement it
// (internal/domain/storecontract.ReviewGateResponder); the type assertion
// failing would be a composition bug, so it is named rather than panicked
// over, exactly like CancelExecution above.
func (s Store) RespondReviewGate(ctx context.Context, taskID int64, fromStatus, gate string, rereview bool, maxRounds int) error {
responder, ok := s.TaskStore.(storecontract.ReviewGateResponder)
if !ok {
return fmt.Errorf("task store cannot record a review gate response")
}
return responder.RespondReviewGate(ctx, taskID, fromStatus, gate, rereview, maxRounds)
}
func MaxRetries(cfg *config.Holder) func(*taskactions.Task) int {
return func(t *taskactions.Task) int {
if cfg == nil {
return 0
}
c := cfg.Get()
// A multi-identity deployment declares its repositories under
// [[identities.repos]] and has no global [[repos]] at all, so the
// task's owning identity is the only place a per-repo override can
// live. Without this lookup the override is never matched and the
// task dies at the global cap instead of the configured one.
if t.Identity != "" {
for _, identity := range c.Identities {
if identity.Name != t.Identity {
continue
}
if n, ok := repoMaxRetries(identity.Repos, t, c.MaxRetries); ok {
return n
}
break
}
}
if n, ok := repoMaxRetries(c.Repos, t, c.MaxRetries); ok {
return n
}
return c.MaxRetries
}
}
// repoMaxRetries returns the effective cap for the task's repository within one
// repository list, and whether that list knows the repository at all.
func repoMaxRetries(repos []config.Repo, t *taskactions.Task, global int) (int, bool) {
for _, repo := range repos {
if repo.Owner == t.Owner && repo.Name == t.Repo {
return repo.EffectiveMaxRetries(global), true
}
}
return 0, false
}