Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
Fix stale Done replies on comment follow-ups (#2495)
fr00stcc9fbd3db09c
diff --git a/server/internal/daemon/daemon.go b/server/internal/daemon/daemon.goindex a4d78d2188..55b388e88d 100644--- a/server/internal/daemon/daemon.go+++ b/server/internal/daemon/daemon.go@@ -1933,7 +1933,7 @@ func gcMetaForTask(task Task) (execenv.GCMeta, bool) {func providerNeedsInlineSystemPrompt(provider string) bool {switch provider {- case "openclaw", "hermes", "kiro", "kimi":+ case "openclaw", "kiro", "kimi":return truedefault:return false@@ -2167,9 +2167,6 @@ func (d *Daemon) runTask(ctx context.Context, task Task, provider string, slot i// write into the task workdir:// - openclaw loads bootstrap files (AGENTS.md, SOUL.md, ...) from its own// workspace dir rather than the task workdir.- // - hermes is driven through ACP and starts from a long-lived Hermes home;- // deployments that cross a wrapper/container boundary can miss the- // task-workdir AGENTS.md even when the prompt itself is delivered.// - kiro and kimi are wrapped through their own CLIs whose cwd handling// is opaque enough that we can't trust the file-based path either.// Pass the full runtime brief inline (CLI catalog + workflow steps + agent@@ -2178,6 +2175,11 @@ func (d *Daemon) runTask(ctx context.Context, task Task, provider string, slot i// these providers silently miss the workflow section and never call// `multica issue status` / `multica issue comment add`, leaving issues// stuck in `todo`.+ //+ // Hermes is intentionally excluded: ACP sessions start in the task cwd and+ // Hermes loads AGENTS.md / .agent_context itself. Prepending the full runtime+ // brief into the ACP user prompt duplicates that context, bloats every turn,+ // and has triggered upstream safety filters on harmless tasks.if providerNeedsInlineSystemPrompt(provider) {execOpts.SystemPrompt = runtimeBrief}diff --git a/server/internal/daemon/daemon_test.go b/server/internal/daemon/daemon_test.goindex ec784a2b4a..72c49bcb8a 100644--- a/server/internal/daemon/daemon_test.go+++ b/server/internal/daemon/daemon_test.go@@ -185,7 +185,10 @@ func TestProviderNeedsInlineSystemPrompt(t *testing.T) {want bool}{{provider: "openclaw", want: true},- {provider: "hermes", want: true},+ // Hermes ACP starts in the task cwd and loads AGENTS.md / .agent_context+ // directly. Inlining the full runtime brief duplicates that context and+ // can trip upstream provider safety filters on otherwise harmless tasks.+ {provider: "hermes", want: false},{provider: "kiro", want: true},{provider: "kimi", want: true},{provider: "codex", want: false},diff --git a/server/internal/handler/daemon.go b/server/internal/handler/daemon.goindex c09cc9b656..2f5f2b7fa7 100644--- a/server/internal/handler/daemon.go+++ b/server/internal/handler/daemon.go@@ -1215,16 +1215,21 @@ func (h *Handler) ClaimTaskByRuntime(w http.ResponseWriter, r *http.Request) {// Look up the prior session for this (agent, issue) pair so the daemon// can resume the Claude Code conversation context.//- // Skip the lookup when the task was flagged as a manual rerun: the- // user just judged the prior output bad, so the daemon must start a- // fresh agent session instead of resuming the same conversation that- // produced that output.+ // Skip all prior state when the task was flagged as a manual rerun:+ // the user just judged the prior output bad, so the daemon must start a+ // fresh agent session in a fresh workdir instead of resuming anything+ // from the same conversation that produced that output. For+ // comment-triggered follow-ups, skip only the session resume: resumed+ // issue conversations often inherit the prior final assistant message+ // (for example "Done.") and answer a new human comment with that stale+ // completion marker instead of the comment itself. Keep reusing the+ // workdir for comment follow-ups so the agent still sees the same checkout.if !task.ForceFreshSession {if prior, err := h.Queries.GetLastTaskSession(r.Context(), db.GetLastTaskSessionParams{AgentID: task.AgentID,IssueID: task.IssueID,}); err == nil && prior.SessionID.Valid {- if prior.RuntimeID == task.RuntimeID {+ if !task.TriggerCommentID.Valid && prior.RuntimeID == task.RuntimeID {resp.PriorSessionID = prior.SessionID.String}if prior.WorkDir.Valid {diff --git a/server/internal/handler/daemon_test.go b/server/internal/handler/daemon_test.goindex 5af95a3d69..4d3c244550 100644--- a/server/internal/handler/daemon_test.go+++ b/server/internal/handler/daemon_test.go@@ -1904,6 +1904,140 @@ func TestCompleteTask_CommentTriggered_SkipsSynthesisWhenAgentAlreadyCommented(t}}+func TestCompleteTask_CommentTriggered_SuppressesTrivialDoneOutput(t *testing.T) {+ if testHandler == nil {+ t.Skip("database not available")+ }++ ctx := context.Background()++ var agentID, runtimeID string+ if err := testPool.QueryRow(ctx, `+ SELECT a.id, a.runtime_id FROM agent a WHERE a.workspace_id = $1 LIMIT 1+ `, testWorkspaceID).Scan(&agentID, &runtimeID); err != nil {+ t.Fatalf("setup: get agent: %v", err)+ }++ var issueID string+ if err := testPool.QueryRow(ctx, `+ INSERT INTO issue (workspace_id, title, status, priority, creator_id, creator_type, number, position)+ VALUES ($1, 'trivial-done-suppression fixture', 'in_progress', 'none', $2, 'member', 81200, 0)+ RETURNING id+ `, testWorkspaceID, testUserID).Scan(&issueID); err != nil {+ t.Fatalf("setup: create issue: %v", err)+ }+ t.Cleanup(func() { testPool.Exec(ctx, `DELETE FROM issue WHERE id = $1`, issueID) })++ var triggerCommentID string+ if err := testPool.QueryRow(ctx, `+ INSERT INTO comment (issue_id, workspace_id, author_type, author_id, content, type)+ VALUES ($1, $2, 'member', $3, 'please follow up', 'comment')+ RETURNING id+ `, issueID, testWorkspaceID, testUserID).Scan(&triggerCommentID); err != nil {+ t.Fatalf("setup: create trigger comment: %v", err)+ }++ var taskID string+ if err := testPool.QueryRow(ctx, `+ INSERT INTO agent_task_queue (+ agent_id, runtime_id, issue_id, trigger_comment_id,+ status, priority, started_at+ )+ VALUES ($1, $2, $3, $4, 'running', 0, now())+ RETURNING id+ `, agentID, runtimeID, issueID, triggerCommentID).Scan(&taskID); err != nil {+ t.Fatalf("setup: create comment-triggered task: %v", err)+ }+ t.Cleanup(func() { testPool.Exec(ctx, `DELETE FROM agent_task_queue WHERE id = $1`, taskID) })++ w := httptest.NewRecorder()+ req := newDaemonTokenRequest("POST", "/api/daemon/tasks/"+taskID+"/complete",+ map[string]any{"output": "Done."},+ testWorkspaceID, "legit-daemon")+ rctx := chi.NewRouteContext()+ rctx.URLParams.Add("taskId", taskID)+ req = req.WithContext(context.WithValue(req.Context(), chi.RouteCtxKey, rctx))++ testHandler.CompleteTask(w, req)+ if w.Code != http.StatusOK {+ t.Fatalf("CompleteTask: expected 200, got %d: %s", w.Code, w.Body.String())+ }++ var count int+ if err := testPool.QueryRow(ctx, `+ SELECT count(*) FROM comment+ WHERE issue_id = $1 AND author_type = 'agent' AND author_id = $2+ `, issueID, agentID).Scan(&count); err != nil {+ t.Fatalf("count agent comments: %v", err)+ }+ if count != 0 {+ t.Fatalf("expected no synthesized agent comment for trivial Done output, got %d", count)+ }+}++func TestCompleteTask_AssignmentTriggered_DoesNotSuppressTrivialDoneOutput(t *testing.T) {+ if testHandler == nil {+ t.Skip("database not available")+ }++ ctx := context.Background()++ var agentID, runtimeID string+ if err := testPool.QueryRow(ctx, `+ SELECT a.id, a.runtime_id FROM agent a WHERE a.workspace_id = $1 LIMIT 1+ `, testWorkspaceID).Scan(&agentID, &runtimeID); err != nil {+ t.Fatalf("setup: get agent: %v", err)+ }++ var issueID string+ if err := testPool.QueryRow(ctx, `+ INSERT INTO issue (workspace_id, title, status, priority, creator_id, creator_type, number, position)+ VALUES ($1, 'assignment-trivial-done fixture', 'in_progress', 'none', $2, 'member', 81201, 0)+ RETURNING id+ `, testWorkspaceID, testUserID).Scan(&issueID); err != nil {+ t.Fatalf("setup: create issue: %v", err)+ }+ t.Cleanup(func() { testPool.Exec(ctx, `DELETE FROM issue WHERE id = $1`, issueID) })++ var taskID string+ if err := testPool.QueryRow(ctx, `+ INSERT INTO agent_task_queue (+ agent_id, runtime_id, issue_id,+ status, priority, started_at+ )+ VALUES ($1, $2, $3, 'running', 0, now())+ RETURNING id+ `, agentID, runtimeID, issueID).Scan(&taskID); err != nil {+ t.Fatalf("setup: create assignment-triggered task: %v", err)+ }+ t.Cleanup(func() { testPool.Exec(ctx, `DELETE FROM agent_task_queue WHERE id = $1`, taskID) })++ w := httptest.NewRecorder()+ req := newDaemonTokenRequest("POST", "/api/daemon/tasks/"+taskID+"/complete",+ map[string]any{"output": "Done."},+ testWorkspaceID, "legit-daemon")+ rctx := chi.NewRouteContext()+ rctx.URLParams.Add("taskId", taskID)+ req = req.WithContext(context.WithValue(req.Context(), chi.RouteCtxKey, rctx))++ testHandler.CompleteTask(w, req)+ if w.Code != http.StatusOK {+ t.Fatalf("CompleteTask: expected 200, got %d: %s", w.Code, w.Body.String())+ }++ var content string+ if err := testPool.QueryRow(ctx, `+ SELECT content FROM comment+ WHERE issue_id = $1 AND author_type = 'agent' AND author_id = $2+ ORDER BY created_at DESC LIMIT 1+ `, issueID, agentID).Scan(&content); err != nil {+ t.Fatalf("query synthesized comment: %v", err)+ }+ if content != "Done." {+ t.Fatalf("synthesized comment content = %q, want Done.", content)+ }+}+type claimRuntimeGuardTask struct {PriorSessionID string `json:"prior_session_id"`PriorWorkDir string `json:"prior_work_dir"`@@ -2199,6 +2333,96 @@ func TestClaimTask_IssuePriorSessionRuntimeGuard(t *testing.T) {if task.PriorWorkDir != "/tmp/same-runtime-workdir" {t.Fatalf("runtime match: expected PriorWorkDir='/tmp/same-runtime-workdir', got %q", task.PriorWorkDir)}++ var commentIssueID string+ if err := testPool.QueryRow(ctx, `+ INSERT INTO issue (workspace_id, title, status, priority, creator_id, creator_type, number, position)+ VALUES ($1, 'comment-triggered-session-skip fixture', 'in_progress', 'none', $2, 'member', 81205, 0)+ RETURNING id+ `, testWorkspaceID, testUserID).Scan(&commentIssueID); err != nil {+ t.Fatalf("setup: create comment-triggered issue: %v", err)+ }+ t.Cleanup(func() { testPool.Exec(ctx, `DELETE FROM issue WHERE id = $1`, commentIssueID) })++ var triggerCommentID string+ if err := testPool.QueryRow(ctx, `+ INSERT INTO comment (issue_id, workspace_id, author_type, author_id, content, type)+ VALUES ($1, $2, 'member', $3, 'please follow up', 'comment')+ RETURNING id+ `, commentIssueID, testWorkspaceID, testUserID).Scan(&triggerCommentID); err != nil {+ t.Fatalf("setup: create trigger comment: %v", err)+ }+ if _, err := testPool.Exec(ctx, `+ INSERT INTO agent_task_queue (+ agent_id, runtime_id, issue_id,+ status, priority, started_at, completed_at,+ session_id, work_dir+ )+ VALUES ($1, $2, $3, 'completed', 0, now(), now(), 'comment-prior-session', '/tmp/comment-prior-workdir')+ `, agentID, runtimeID, commentIssueID); err != nil {+ t.Fatalf("setup: create comment-trigger prior task: %v", err)+ }+ if _, err := testPool.Exec(ctx, `+ INSERT INTO agent_task_queue (+ agent_id, runtime_id, issue_id, trigger_comment_id,+ status, priority+ )+ VALUES ($1, $2, $3, $4, 'queued', 0)+ `, agentID, runtimeID, commentIssueID, triggerCommentID); err != nil {+ t.Fatalf("setup: create comment-triggered task: %v", err)+ }++ task = claimTaskForRuntimeGuard(t, runtimeID, daemonID)+ if task.PriorSessionID != "" {+ t.Fatalf("comment trigger: expected empty PriorSessionID, got %q", task.PriorSessionID)+ }+ if task.PriorWorkDir != "/tmp/comment-prior-workdir" {+ t.Fatalf("comment trigger: expected PriorWorkDir='/tmp/comment-prior-workdir', got %q", task.PriorWorkDir)+ }+ if _, err := testPool.Exec(ctx, `+ UPDATE agent_task_queue+ SET status = 'completed', completed_at = now()+ WHERE issue_id = $1 AND status IN ('dispatched', 'running')+ `, commentIssueID); err != nil {+ t.Fatalf("setup: complete claimed comment-trigger task: %v", err)+ }++ var freshIssueID string+ if err := testPool.QueryRow(ctx, `+ INSERT INTO issue (workspace_id, title, status, priority, creator_id, creator_type, number, position)+ VALUES ($1, 'force-fresh-session fixture', 'in_progress', 'none', $2, 'member', 81206, 0)+ RETURNING id+ `, testWorkspaceID, testUserID).Scan(&freshIssueID); err != nil {+ t.Fatalf("setup: create force-fresh issue: %v", err)+ }+ t.Cleanup(func() { testPool.Exec(ctx, `DELETE FROM issue WHERE id = $1`, freshIssueID) })+ if _, err := testPool.Exec(ctx, `+ INSERT INTO agent_task_queue (+ agent_id, runtime_id, issue_id,+ status, priority, started_at, completed_at,+ session_id, work_dir+ )+ VALUES ($1, $2, $3, 'completed', 0, now(), now(), 'force-fresh-prior-session', '/tmp/force-fresh-prior-workdir')+ `, agentID, runtimeID, freshIssueID); err != nil {+ t.Fatalf("setup: create force-fresh prior task: %v", err)+ }+ if _, err := testPool.Exec(ctx, `+ INSERT INTO agent_task_queue (+ agent_id, runtime_id, issue_id,+ status, priority, force_fresh_session+ )+ VALUES ($1, $2, $3, 'queued', 0, TRUE)+ `, agentID, runtimeID, freshIssueID); err != nil {+ t.Fatalf("setup: create force-fresh task: %v", err)+ }++ task = claimTaskForRuntimeGuard(t, runtimeID, daemonID)+ if task.PriorSessionID != "" {+ t.Fatalf("force fresh: expected empty PriorSessionID, got %q", task.PriorSessionID)+ }+ if task.PriorWorkDir != "" {+ t.Fatalf("force fresh: expected empty PriorWorkDir, got %q", task.PriorWorkDir)+ }}func TestClaimTask_ChatPriorSessionRuntimeGuard(t *testing.T) {diff --git a/server/internal/service/task.go b/server/internal/service/task.goindex ca3dd44ecd..58059c8449 100644--- a/server/internal/service/task.go+++ b/server/internal/service/task.go@@ -106,6 +106,26 @@ func NewTaskService(q *db.Queries, tx TxStarter, hub *realtime.Hub, bus *events.return &TaskService{Queries: q, TxStarter: tx, Hub: hub, Bus: bus, Wakeup: wakeup}}+var trivialDoneMarkers = []string{+ "done",+ "готово",+ "готова",+ "сделано",+ "完成",+ "完了",+}++func isTrivialDoneOutput(output string) bool {+ normalized := strings.TrimSpace(strings.ToLower(output))+ normalized = strings.Trim(normalized, ".!!。… ")+ for _, marker := range trivialDoneMarkers {+ if normalized == marker {+ return true+ }+ }+ return false+}+func (s *TaskService) captureTaskQueued(ctx context.Context, task db.AgentTaskQueue) {s.captureTaskEvent(ctx, analytics.AgentTaskQueued(s.taskAnalyticsContext(ctx, task)))}@@ -989,7 +1009,15 @@ func (s *TaskService) CompleteTask(ctx context.Context, taskID pgtype.UUID, resu// decoded into real newlines before the comment hits the DB. See// util.UnescapeBackslashEscapes for the exact contract.body := util.UnescapeBackslashEscapes(payload.Output)- s.createAgentComment(ctx, task.IssueID, task.AgentID, redact.Text(body), "comment", task.TriggerCommentID)+ if task.TriggerCommentID.Valid && isTrivialDoneOutput(body) {+ slog.Warn("suppressing trivial comment-trigger fallback output",+ "task_id", util.UUIDToString(task.ID),+ "issue_id", util.UUIDToString(task.IssueID),+ "agent_id", util.UUIDToString(task.AgentID),+ )+ } else {+ s.createAgentComment(ctx, task.IssueID, task.AgentID, redact.Text(body), "comment", task.TriggerCommentID)+ }}}}diff --git a/server/internal/service/trivial_done_test.go b/server/internal/service/trivial_done_test.gonew file mode 100644index 0000000000..a9b5474214--- /dev/null+++ b/server/internal/service/trivial_done_test.go@@ -0,0 +1,32 @@+package service++import "testing"++func TestIsTrivialDoneOutput(t *testing.T) {+ t.Parallel()++ tests := []struct {+ name string+ in string+ want bool+ }{+ {"plain english", "done", true},+ {"english punctuation", " Done. ", true},+ {"russian", "Готово!", true},+ {"russian feminine", "готова…", true},+ {"russian done", "Сделано", true},+ {"chinese", "完成!", true},+ {"japanese", "完了。", true},+ {"not only marker", "done, see PR", false},+ {"not acknowledgement", "好的", false},+ {"real answer", "I fixed the issue", false},+ }++ for _, tt := range tests {+ t.Run(tt.name, func(t *testing.T) {+ if got := isTrivialDoneOutput(tt.in); got != tt.want {+ t.Fatalf("isTrivialDoneOutput(%q) = %v, want %v", tt.in, got, tt.want)+ }+ })+ }+}diff --git a/server/pkg/agent/agent.go b/server/pkg/agent/agent.goindex 3704a5235f..bdfd088a81 100644--- a/server/pkg/agent/agent.go+++ b/server/pkg/agent/agent.go@@ -22,8 +22,11 @@ type Backend interface {// ExecOptions configures a single execution.type ExecOptions struct {- Cwd string- Model string+ Cwd string+ Model string+ // SystemPrompt is consumed only by providers that can pass or safely inline+ // developer/system instructions. Hermes ACP intentionally ignores it and+ // relies on cwd-scoped context files such as AGENTS.md instead.SystemPrompt stringMaxTurns intTimeout time.Durationdiff --git a/server/pkg/agent/hermes.go b/server/pkg/agent/hermes.goindex c14359825c..2ef2820abb 100644--- a/server/pkg/agent/hermes.go+++ b/server/pkg/agent/hermes.go@@ -6,7 +6,9 @@ import ("encoding/json""fmt""io"+ "os""os/exec"+ "path/filepath""regexp""strconv""strings"@@ -50,8 +52,16 @@ func (b *hermesBackend) Execute(ctx context.Context, prompt string, opts ExecOptcmd := exec.CommandContext(runCtx, execPath, hermesArgs...)hideAgentWindow(cmd)b.cfg.Logger.Info("agent command", "exec", execPath, "args", hermesArgs)+ agentsMDPresent := falseif opts.Cwd != "" {cmd.Dir = opts.Cwd+ if _, err := os.Stat(filepath.Join(opts.Cwd, "AGENTS.md")); err == nil {+ agentsMDPresent = true+ }+ }+ b.cfg.Logger.Info("hermes acp starting", "cwd", opts.Cwd, "agents_md_present", agentsMDPresent)+ if opts.SystemPrompt != "" {+ b.cfg.Logger.Debug("hermes ignoring ExecOptions.SystemPrompt; using cwd-scoped context files", "cwd", opts.Cwd)}env := buildEnv(b.cfg.Env)@@ -271,13 +281,13 @@ func (b *hermesBackend) Execute(ctx context.Context, prompt string, opts ExecOptb.cfg.Logger.Info("hermes session model set", "model", opts.Model)}- // 4. Build the prompt content. If we have a system prompt, prepend it.- userText := prompt- if opts.SystemPrompt != "" {- userText = opts.SystemPrompt + "\n\n---\n\n" + prompt- }-- // 5. Send the prompt and wait for PromptResponse. Flip the gate+ // 4. Send the prompt and wait for PromptResponse.+ //+ // Do NOT prepend opts.SystemPrompt here. Hermes ACP loads project/context+ // files from cwd (AGENTS.md, .agent_context, etc.) itself; duplicating the+ // full runtime brief in the user prompt makes the request much larger and+ // has triggered upstream safety filters on otherwise ordinary tasks.+ // Flip the gate// just before the request so any history replay flushed during// initialize / session setup stays dropped, but every notification// belonging to this turn is processed.@@ -285,7 +295,7 @@ func (b *hermesBackend) Execute(ctx context.Context, prompt string, opts ExecOpt_, err = c.request(runCtx, "session/prompt", map[string]any{"sessionId": sessionID,"prompt": []map[string]any{- {"type": "text", "text": userText},+ {"type": "text", "text": prompt},},})if err != nil {