fix: close the duplicate-work loop and the dead paths around it
Applies the four-reviewer pass over the forge/dashboard-actions work. The through-line is that several capabilities were wired but inert, and one of them could cost real work. DUPLICATE WORK. "Closes #N" was dropped from PR bodies in favour of LinkBranch, which is sidebar linkage on Gitea and a no-op stub on GitHub -- neither closes anything, and nothing else did either. So a merged task left its issue open, labelled and assigned; the next poll re-enqueued it, and once the dashboard's Clear removed the task row that became a second implementation and a second PR for work already merged. reconcilePRs now closes the issue on merge, and a rejected task closes its issue too. A PR closed without merging deliberately leaves the issue open: that usually means "try again". MAX RETRIES. Configured, defaulted and reported by /api/config, and enforced nowhere -- markDead was unreachable and EffectiveMaxRetries had no callers, so the dashboard's retry incremented retry_count forever. The retry action now retires a task to dead at the cap. DEAD ON ARRIVAL. Tasks() never selected plan or source, so the "Decision required" panel could not render and chat tasks -- whose issue number is synthetic -- linked to forge issues that do not exist. COSMETIC FAILURE, FATAL RESULT. OpenPR failed the whole stage when LinkBranch errored, so the pull request was never opened and the task parked; a retry re-links the same branch, which Gitea answers with a conflict, so every retry parked again. It is best-effort now. INVISIBLE ACTIONS. Approve/retry/reject wrote store rows and nothing else, so the timeline and activity stream never showed that a human had intervened. They emit events now. Also: store write failures answer 500 rather than 409; the dashboard surfaces the server's actual reason instead of "409 Conflict"; action buttons stop propagation (acting on a task no longer also expands it), disable in flight, keep per-task errors instead of one shared string, and confirm before rejecting. Removed: the maybeRetryParked shim and markDead with their now-vacuous tests, WaitingTasks (no consumers; its tests were rewritten to assert the same routing through TaskByID), write-only Daemon.Runtime, and dir/dirs response bloat from /api/skills. skillSource checked workDir before sharedDir, mislabelling every shared skill when the two are equal. DefaultRoots now dedupes roots differing only by a trailing separator. The air build rule claiming to keep ui/dist current never ran -- it required one file to satisfy include_dir and include_file together, and ui/ is excluded from the walk. Deleted with the comment that promised it. task test:ui joins task check and CI; it ran nowhere before, so the dashboard suite could rot silently. Docs corrected where they described behaviour that no longer exists: parks no longer comment on the issue, state labels no longer drive retries, and forgerpc's doc claimed four proxied methods while listing three of five.
This commit is contained in:
1 parent
a751be66b3
commit
170fe0250b
60 files changed
+2081
-768
No files matched your search
@@ -62,8 +62,7 @@ func Feasibility() Workflow {
|
||||
tc.decision = &decision{Fit: *captured.Fit, Reasons: captured.Reasons}
|
||||
if !tc.decision.Fit {
|
||||
if tc.Task.IsForgeBacked() {
|
||||
comment := fmt.Sprintf("**archie assessed this feature as not a fit -- closing as won't-do.**\n\n%s\n\n_Reopen and re-assign if you disagree._", tc.decision.Reasons)
|
||||
if err := tc.Forge.CloseIssue(context.Background(), tc.Task.Owner, tc.Task.Repo, tc.Task.IssueNumber, comment); err != nil {
|
||||
if err := tc.Forge.CloseIssue(context.Background(), tc.Task.Owner, tc.Task.Repo, tc.Task.IssueNumber, ""); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -94,18 +93,9 @@ func Feasibility() Workflow {
|
||||
},
|
||||
}.Stage(),
|
||||
|
||||
// Deliver the PRD and block on Sam: issue comment (the reply
|
||||
// channel the daemon watches) plus the notify webhook (n8n →
|
||||
// email).
|
||||
// Persist the PRD and block on Sam. Messaging and the Web UI are
|
||||
// the decision surfaces; the forge issue is not a chat log.
|
||||
{Name: "deliver", Run: func(ctx context.Context, tc *TaskContext) error {
|
||||
if tc.Task.IsForgeBacked() {
|
||||
body := fmt.Sprintf("**archie's PRD -- awaiting your go/no-go.** Reply on this issue; I'll read your answer.\n\n%s", tc.Task.Plan)
|
||||
commentID, err := tc.Forge.Comment(ctx, tc.Task.Owner, tc.Task.Repo, tc.Task.IssueNumber, body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tc.Task.WatchCommentID = commentID
|
||||
}
|
||||
notify(ctx, tc, "feasibility_prd")
|
||||
tc.Outcome = Outcome{Status: store.StatusWaitingHuman, Detail: "PRD delivered, awaiting go/no-go"}
|
||||
return nil
|
||||
|
||||
@@ -119,13 +119,6 @@ func Implement() Workflow {
|
||||
},
|
||||
OnResult: func(tc *TaskContext, res agentexec.Result) error {
|
||||
tc.Task.Plan = res.Summary
|
||||
if !tc.Task.IsForgeBacked() {
|
||||
return nil
|
||||
}
|
||||
body := fmt.Sprintf("**archie's plan** (review now if you want to veto -- building starts immediately):\n\n%s", res.Summary)
|
||||
if _, err := tc.Forge.Comment(context.Background(), tc.Task.Owner, tc.Task.Repo, tc.Task.IssueNumber, body); err != nil {
|
||||
tc.Log.Warn("failed to post plan comment", "err", err)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}.Stage(),
|
||||
@@ -166,8 +159,7 @@ func Implement() Workflow {
|
||||
StageDiffCap(),
|
||||
StageOpenPR(func(tc *TaskContext) string {
|
||||
return fmt.Sprintf("%s\n\n---\n*workflow: implement · %d iterations · %d tokens*",
|
||||
tc.BuildSummary, tc.Task.Iterations, tc.Task.TokensUsed) +
|
||||
issueClosureReference(tc.Task)
|
||||
tc.BuildSummary, tc.Task.Iterations, tc.Task.TokensUsed)
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -2,9 +2,10 @@ package workflow
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/forge"
|
||||
"github.com/samcharles93/archie-core/internal/store"
|
||||
)
|
||||
@@ -13,6 +14,9 @@ import (
|
||||
type fakeForge struct {
|
||||
closed int
|
||||
commented []string
|
||||
calls []string
|
||||
linkErr error
|
||||
prNumber int
|
||||
}
|
||||
|
||||
func (f *fakeForge) CloseIssue(ctx context.Context, owner, repo string, number int, comment string) error {
|
||||
@@ -40,7 +44,11 @@ func (f *fakeForge) IssuesWithLabel(ctx context.Context, owner, repo, label stri
|
||||
}
|
||||
|
||||
func (f *fakeForge) CreatePR(ctx context.Context, owner, repo, title, head, base, body string) (int, error) {
|
||||
return 0, nil
|
||||
f.calls = append(f.calls, "pr:"+head)
|
||||
// A real forge never answers 0, and returning it let a test pass while
|
||||
// the PR number was never recorded.
|
||||
f.prNumber++
|
||||
return f.prNumber, nil
|
||||
}
|
||||
|
||||
func (f *fakeForge) PRState(ctx context.Context, owner, repo string, number int) (string, error) {
|
||||
@@ -57,6 +65,11 @@ func (f *fakeForge) RepliesAfter(ctx context.Context, owner, repo string, number
|
||||
|
||||
func (f *fakeForge) SetStateLabel(ctx context.Context, owner, repo string, number int, label string, known []string) {
|
||||
}
|
||||
|
||||
func (f *fakeForge) LinkBranch(ctx context.Context, owner, repo string, number int, branch string) error {
|
||||
f.calls = append(f.calls, "link:"+branch)
|
||||
return f.linkErr
|
||||
}
|
||||
func (f *fakeForge) VerifyPush(ctx context.Context, owner, repo string) error { return nil }
|
||||
|
||||
// TestStageCommitPushClosesIssueWhenBuildNoChanges verifies that
|
||||
@@ -94,15 +107,24 @@ func TestStageCommitPushClosesIssueWhenBuildNoChanges(t *testing.T) {
|
||||
t.Log("Outcome set to Merged (workflow stops)")
|
||||
}
|
||||
|
||||
found := false
|
||||
for _, c := range f.commented {
|
||||
if strings.Contains(c, "no changes required") {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
if len(f.commented) != 0 {
|
||||
t.Errorf("expected no forge comments, got %d", len(f.commented))
|
||||
}
|
||||
if !found {
|
||||
t.Error("expected a comment about no changes required")
|
||||
}
|
||||
|
||||
func TestOpenPRLinksSourceBranchBeforeCreatingPR(t *testing.T) {
|
||||
f := &fakeForge{}
|
||||
tc := &TaskContext{
|
||||
Forge: f,
|
||||
Task: &store.Task{ID: 1, Owner: "acme", Repo: "widget", IssueNumber: 42, Title: "Fix bug"},
|
||||
Repo: config.Repo{Owner: "acme", Name: "widget", Base: "main"},
|
||||
Branch: "fix/42-bug",
|
||||
}
|
||||
if err := OpenPR(context.Background(), tc, "summary"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(f.calls) != 2 || f.calls[0] != "link:fix/42-bug" || f.calls[1] != "pr:fix/42-bug" {
|
||||
t.Fatalf("forge calls = %v, want [link:fix/42-bug pr:fix/42-bug]", f.calls)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,19 +155,43 @@ func TestStageCommitPushDoesNotUseSyntheticIssueForChatNoOp(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssueClosureReferenceOnlyForForgeTasks(t *testing.T) {
|
||||
// LinkBranch is cosmetic: it puts the branch in the issue's sidebar on Gitea
|
||||
// and does nothing at all on GitHub. Failing the stage on it meant the pull
|
||||
// request -- the entire point of the run -- was never opened, and the task
|
||||
// parked. Worse, a retry re-links the same branch, which Gitea answers with
|
||||
// a conflict, so every retry parked again.
|
||||
func TestOpenPRSurvivesALinkBranchFailure(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
task *store.Task
|
||||
want string
|
||||
name string
|
||||
linkErr error
|
||||
}{
|
||||
{name: "forge", task: &store.Task{IssueNumber: 42}, want: "\n\nCloses #42"},
|
||||
{name: "chat", task: &store.Task{IssueNumber: 999_001, Source: store.SourceChat}, want: ""},
|
||||
{name: "already linked", linkErr: errors.New("409 Conflict: branch already linked")},
|
||||
{name: "endpoint unavailable", linkErr: errors.New("404 Not Found")},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := issueClosureReference(tt.task); got != tt.want {
|
||||
t.Errorf("issueClosureReference() = %q, want %q", got, tt.want)
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
f := &fakeForge{linkErr: tc.linkErr}
|
||||
taskCtx := &TaskContext{
|
||||
Forge: f,
|
||||
Task: &store.Task{ID: 1, Owner: "acme", Repo: "widget", IssueNumber: 42, Title: "Fix bug"},
|
||||
Repo: config.Repo{Owner: "acme", Name: "widget", Base: "main"},
|
||||
Branch: "fix/42-bug",
|
||||
}
|
||||
|
||||
if err := OpenPR(context.Background(), taskCtx, "summary"); err != nil {
|
||||
t.Fatalf("OpenPR: %v\nthe PR is the load-bearing step; cosmetic "+
|
||||
"linkage must not stop it", err)
|
||||
}
|
||||
if taskCtx.Outcome.Status != store.StatusPROpen {
|
||||
t.Errorf("Outcome.Status = %q, want %q", taskCtx.Outcome.Status, store.StatusPROpen)
|
||||
}
|
||||
if taskCtx.Task.PRNumber == 0 {
|
||||
t.Error("PRNumber is 0: the pull request was never opened")
|
||||
}
|
||||
// The link is still attempted -- it is useful when it works.
|
||||
if len(f.calls) != 2 || f.calls[0] != "link:fix/42-bug" {
|
||||
t.Errorf("forge calls = %v, want the link attempted before the PR", f.calls)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
+16
-13
@@ -69,10 +69,6 @@ func closeNoChangesIssue(ctx context.Context, tc *TaskContext) error {
|
||||
tc.Outcome = Outcome{Status: store.StatusMerged, Detail: "completed -- no changes required"}
|
||||
return nil
|
||||
}
|
||||
body := fmt.Sprintf("**archie closed this issue -- no changes required.**\n\n%s", tc.BuildSummary)
|
||||
if _, err := tc.Forge.Comment(ctx, tc.Task.Owner, tc.Task.Repo, tc.Task.IssueNumber, body); err != nil {
|
||||
tc.Log.Warn("no-op close comment failed", "err", err)
|
||||
}
|
||||
if err := tc.Forge.CloseIssue(ctx, tc.Task.Owner, tc.Task.Repo, tc.Task.IssueNumber, ""); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -182,6 +178,21 @@ func StageYaegiGate() Stage {
|
||||
func OpenPR(ctx context.Context, tc *TaskContext, body string) error {
|
||||
t := tc.Task
|
||||
title := fmt.Sprintf("%s (archie)", t.Title)
|
||||
if t.IsForgeBacked() {
|
||||
// Best-effort. The link is cosmetic -- it puts the branch in the
|
||||
// issue's sidebar on Gitea and does nothing on GitHub -- so failing
|
||||
// the stage on it meant the pull request, the entire point of the
|
||||
// run, was never opened and the task parked. A retry then re-links
|
||||
// the same branch, which Gitea answers with a conflict, so every
|
||||
// retry parked again.
|
||||
if err := tc.Forge.LinkBranch(ctx, t.Owner, t.Repo, t.IssueNumber, tc.Branch); err != nil {
|
||||
if tc.Log != nil {
|
||||
tc.Log.Warn("link branch to issue failed; opening the PR anyway",
|
||||
"repo", t.Owner+"/"+t.Repo, "issue", t.IssueNumber,
|
||||
"branch", tc.Branch, "err", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
num, err := tc.Forge.CreatePR(ctx, t.Owner, t.Repo, title, tc.Branch, tc.Repo.BaseBranch(), body)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -198,13 +209,6 @@ func StageOpenPR(body func(*TaskContext) string) Stage {
|
||||
}}
|
||||
}
|
||||
|
||||
func issueClosureReference(task *store.Task) string {
|
||||
if !task.IsForgeBacked() {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("\n\nCloses #%d", task.IssueNumber)
|
||||
}
|
||||
|
||||
func taskPromptBlock(task *store.Task) string {
|
||||
if task.IsForgeBacked() {
|
||||
return fmt.Sprintf("<issue number=%d>\n# %s\n\n%s\n</issue>",
|
||||
@@ -250,8 +254,7 @@ func Bootstrap() Workflow {
|
||||
}),
|
||||
StageDiffCap(),
|
||||
StageOpenPR(func(tc *TaskContext) string {
|
||||
return "Deterministic bootstrap PR from archie's plumbing walk-through." +
|
||||
issueClosureReference(tc.Task)
|
||||
return "Deterministic bootstrap PR from archie's plumbing walk-through."
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -132,17 +132,10 @@ func TDD() Workflow {
|
||||
// evidence the bug was reproduced before the fix.
|
||||
{Name: "open-pr", Run: func(ctx context.Context, tc *TaskContext) error {
|
||||
body := fmt.Sprintf("%s\n\n---\n*workflow: tdd (failing repro committed first) · %d iterations · %d tokens*",
|
||||
tc.BuildSummary, tc.Task.Iterations, tc.Task.TokensUsed) +
|
||||
issueClosureReference(tc.Task)
|
||||
tc.BuildSummary, tc.Task.Iterations, tc.Task.TokensUsed)
|
||||
if err := OpenPR(ctx, tc, body); err != nil {
|
||||
return err
|
||||
}
|
||||
if tc.ReproProof != "" {
|
||||
proof := fmt.Sprintf("**Proof the repro tests failed before the fix** (commit 1 of this PR):\n\n```\n%s\n```", tc.ReproProof)
|
||||
if _, err := tc.Forge.Comment(ctx, tc.Task.Owner, tc.Task.Repo, tc.Task.PRNumber, proof); err != nil {
|
||||
tc.Log.Warn("failed to post repro proof", "err", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}},
|
||||
},
|
||||
|
||||
@@ -23,10 +23,9 @@ import (
|
||||
// forge.Forge (the daemon's real implementations) and forgerpc.Client
|
||||
// (archie-agent's NATS-backed proxy) both satisfy it.
|
||||
type Forger interface {
|
||||
Comment(ctx context.Context, owner, repo string, number int, body string) (int64, error)
|
||||
CloseIssue(ctx context.Context, owner, repo string, number int, comment string) error
|
||||
CreatePR(ctx context.Context, owner, repo, title, head, base, body string) (int, error)
|
||||
SetStateLabel(ctx context.Context, owner, repo string, number int, label string, knownLabels []string)
|
||||
LinkBranch(ctx context.Context, owner, repo string, issueNumber int, branch string) error
|
||||
}
|
||||
|
||||
// Trees is the subset of *worktree.Manager that workflow stages call
|
||||
@@ -220,50 +219,16 @@ func finish(ctx context.Context, tc *TaskContext, log *slog.Logger) {
|
||||
}
|
||||
_ = tc.Store.Update(ctx, t)
|
||||
_ = tc.Store.Transition(ctx, t.ID, store.StatusRunning, tc.Outcome.Status, tc.Outcome.Detail)
|
||||
if t.IsForgeBacked() {
|
||||
tc.Forge.SetStateLabel(ctx, t.Owner, t.Repo, t.IssueNumber, stateLabelFor(tc.Cfg.Dispatch, tc.Outcome.Status), tc.Cfg.Dispatch.LabelValues())
|
||||
}
|
||||
tc.Emit(events.KindOutcome, t.Stage, tc.Outcome.Detail, map[string]any{"status": tc.Outcome.Status})
|
||||
log.Info("workflow finished", "status", tc.Outcome.Status)
|
||||
}
|
||||
|
||||
// stateLabelFor maps a terminal workflow status to its forge label by
|
||||
// looking up the configured [dispatch.labels]; empty clears (done states
|
||||
//
|
||||
// -- the issue closes or the PR speaks).
|
||||
func stateLabelFor(d config.Dispatch, status string) string {
|
||||
switch status {
|
||||
case store.StatusPROpen:
|
||||
return d.StateLabel("pr")
|
||||
case store.StatusWaitingHuman:
|
||||
return d.StateLabel("waiting")
|
||||
case store.StatusParked:
|
||||
return d.StateLabel("parked")
|
||||
case store.StatusDead:
|
||||
return d.StateLabel("dead")
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func park(ctx context.Context, tc *TaskContext, reason string) {
|
||||
t := tc.Task
|
||||
t.ParkReason = reason
|
||||
_ = tc.Store.Update(ctx, t)
|
||||
_ = tc.Store.Transition(ctx, t.ID, store.StatusRunning, store.StatusParked, reason)
|
||||
tc.Emit(events.KindParked, t.Stage, reason, nil)
|
||||
if !t.IsForgeBacked() {
|
||||
// Chat-sourced tasks have no real forge issue to label or
|
||||
// comment on; the park reason is visible via /status and the
|
||||
// task's ParkReason field instead.
|
||||
return
|
||||
}
|
||||
tc.Forge.SetStateLabel(ctx, t.Owner, t.Repo, t.IssueNumber, tc.Cfg.Dispatch.StateLabel("parked"), tc.Cfg.Dispatch.LabelValues())
|
||||
body := fmt.Sprintf("**archie parked this task.**\n\n```\n%s\n```\n\nThe worktree is kept for inspection.",
|
||||
clip(reason, 3000))
|
||||
if _, err := tc.Forge.Comment(ctx, t.Owner, t.Repo, t.IssueNumber, body); err != nil {
|
||||
tc.Log.Error("failed to post park comment", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
func clip(s string, n int) string {
|
||||
|
||||
Reference in new issue
Block a user