Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(daemon): give wakeup delivery replies the Windows cookbook and guard against hand-written reply posts (#11642)
Bohan Jiangf5519d4ad813
diff --git a/server/internal/daemon/execenv/reply_instructions.go b/server/internal/daemon/execenv/reply_instructions.goindex 48495b94fa..2672506414 100644--- a/server/internal/daemon/execenv/reply_instructions.go+++ b/server/internal/daemon/execenv/reply_instructions.go@@ -212,9 +212,24 @@ func buildCommentReplyInstructionsSlim(provider, issueID, triggerCommentID strin"Do NOT write literal `\\n` escapes to simulate line breaks; the file preserves real newlines.\n"}+// BuildWakeupReplyInstructions is the delivery step of an issue wakeup run+// whose rule was created from a comment (#8467 / #8807): the result goes back+// to that original thread. It used to be a hand-written bash one-liner in+// prompt.go, which PowerShell 5.1 cannot parse (MUL-10271).+func BuildWakeupReplyInstructions(issueID, deliveryCommentID string) string {+ post := fmt.Sprintf("multica issue comment add %s --parent %s --content-file ./reply.md --output table", issueID, deliveryCommentID)+ if runtimeGOOS == "windows" {+ return "Post your result in the original delivery thread — this is not a new comment trigger. Write the body file first — never pipe via `--content-stdin` (PowerShell drops non-ASCII; full rules: ## Comment Formatting above). Use the variant for the shell your command tool runs:\n\n" ++ gatedReplyPost(post) ++ "Do NOT drop the exit-code check or the `&&`: a bare cleanup after a failed post reports success and deletes the body.\n"+ }+ return "Post your result in the original delivery thread — this is not a new comment trigger:\n\n" + gatedReplyPost(post)+}+// gatedReplyPost renders the command block that posts ./reply.md with post.-// Shared by issue comment replies and doc discussion replies so the shell-// variants cannot drift apart.+// Shared by issue comment replies, doc discussion replies and wakeup+// deliveries so the shell variants cannot drift apart. Never hand-write the+// command elsewhere; TestNoHandWrittenReplyPost enforces it.//// Cleanup is GATED on the post succeeding, never a separate statement.// Agents hand the whole snippet to one shell call, and an unconditionaldiff --git a/server/internal/daemon/execenv/reply_instructions_shell_test.go b/server/internal/daemon/execenv/reply_instructions_shell_test.goindex b57fbdf549..781a802d64 100644--- a/server/internal/daemon/execenv/reply_instructions_shell_test.go+++ b/server/internal/daemon/execenv/reply_instructions_shell_test.go@@ -104,7 +104,8 @@ func runSnippet(t *testing.T, shell string, args []string, stubDir string) (int,//// The doc discussion reply (MUL-9933) is held to the same property: it shares// the snippet, and a doc run on Windows gets no `## Comment Formatting`-// section to fall back on.+// section to fall back on. So is the wakeup delivery reply (MUL-10271), which+// used to be a hand-written bash one-liner.//// Not parallel: mutates the package-level runtimeGOOS.func TestCommentReplySnippetPropagatesPostFailure(t *testing.T) {@@ -119,6 +120,7 @@ func TestCommentReplySnippetPropagatesPostFailure(t *testing.T) {}{{"issue", func() string { return BuildCommentReplyInstructions("claude", issueID, triggerID, false) }},{"doc", func() string { return BuildDocCommentReplyInstructions(issueID, triggerID) }},+ {"wakeup", func() string { return BuildWakeupReplyInstructions(issueID, triggerID) }},}for _, tc := range []struct {diff --git a/server/internal/daemon/execenv/reply_instructions_test.go b/server/internal/daemon/execenv/reply_instructions_test.goindex 58a929fd2f..06369522fe 100644--- a/server/internal/daemon/execenv/reply_instructions_test.go+++ b/server/internal/daemon/execenv/reply_instructions_test.go@@ -396,3 +396,40 @@ func TestBuildDocCommentReplyInstructionsWindowsVariants(t *testing.T) {t.Fatalf("doc runs have no ## Comment Formatting section to point at:\n%s", got)}}++// TestBuildWakeupReplyInstructionsWindowsVariants pins the wakeup delivery+// reply (MUL-10271) to the shared per-shell cookbook: it used to be a bash+// one-liner that PowerShell 5.1 cannot parse. The non-Windows command must+// stay byte-identical to the old one.+//+// Not parallel: mutates the package-level runtimeGOOS.+func TestBuildWakeupReplyInstructionsWindowsVariants(t *testing.T) {+ saved := runtimeGOOS+ t.Cleanup(func() { runtimeGOOS = saved })++ const bash = " multica issue comment add issue-1 --parent c-1 --content-file ./reply.md --output table && rm ./reply.md\n"++ runtimeGOOS = "linux"+ got := BuildWakeupReplyInstructions("issue-1", "c-1")+ for _, want := range []string{bash, "original delivery thread", "not a new comment trigger"} {+ if !strings.Contains(got, want) {+ t.Fatalf("non-Windows wakeup reply missing %q:\n%s", want, got)+ }+ }+ if strings.Contains(got, "PowerShell") {+ t.Fatalf("non-Windows wakeup reply must not carry the PowerShell variant:\n%s", got)+ }++ runtimeGOOS = "windows"+ got = BuildWakeupReplyInstructions("issue-1", "c-1")+ for _, want := range []string{+ "PowerShell:\n\n multica issue comment add issue-1 --parent c-1 --content-file ./reply.md --output table\n if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }\n Remove-Item ./reply.md\n",+ "Git Bash:\n\n" + bash,+ "never pipe via `--content-stdin`",+ "not a new comment trigger",+ } {+ if !strings.Contains(got, want) {+ t.Fatalf("Windows wakeup reply missing %q:\n%s", want, got)+ }+ }+}diff --git a/server/internal/daemon/prompt.go b/server/internal/daemon/prompt.goindex 97af7b4dd5..395746ac99 100644--- a/server/internal/daemon/prompt.go+++ b/server/internal/daemon/prompt.go@@ -370,7 +370,7 @@ func buildPromptBodyWithOptions(task Task, provider string, opts promptOpts) strfmt.Fprintf(&b, "Inspect this configuration with `multica issue wakeup get %s %s --output json`. If recurring work is no longer needed, disable it with `multica issue wakeup disable %s %s`.\n", task.IssueID, task.WakeupID, task.IssueID, task.WakeupID)}if task.TriggerCommentID != "" {- fmt.Fprintf(&b, "Post your result using `multica issue comment add %s --parent %s --content-file ./reply.md --output table && rm ./reply.md`. This is the original delivery thread, not a new comment trigger.\n", task.IssueID, task.TriggerCommentID)+ b.WriteString(execenv.BuildWakeupReplyInstructions(task.IssueID, task.TriggerCommentID))}return b.String()}diff --git a/server/internal/daemon/reply_post_guard_test.go b/server/internal/daemon/reply_post_guard_test.gonew file mode 100644index 0000000000..dc97fdea66--- /dev/null+++ b/server/internal/daemon/reply_post_guard_test.go@@ -0,0 +1,40 @@+package daemon++import (+ "io/fs"+ "os"+ "path/filepath"+ "strings"+ "testing"+)++// TestNoHandWrittenReplyPost keeps every reply-posting command on+// execenv.gatedReplyPost, the one place that renders the Windows variants+// (PowerShell 5.1 has no `&&`). Doc discussion replies (MUL-9933) and wakeup+// deliveries (MUL-10271) each shipped a hand-written bash one-liner that+// PowerShell agents could not run; a new run type that builds its own command+// fails here instead.+func TestNoHandWrittenReplyPost(t *testing.T) {+ const literal = "&& rm ./reply.md"+ allowed := filepath.Join("execenv", "reply_instructions.go")++ err := filepath.WalkDir(".", func(path string, d fs.DirEntry, err error) error {+ if err != nil {+ return err+ }+ if d.IsDir() || !strings.HasSuffix(path, ".go") || strings.HasSuffix(path, "_test.go") || path == allowed {+ return nil+ }+ src, err := os.ReadFile(path)+ if err != nil {+ return err+ }+ if strings.Contains(string(src), literal) {+ t.Errorf("%s hand-writes a reply post (%q); build it with an execenv reply builder so Windows gets the PowerShell variant", path, literal)+ }+ return nil+ })+ if err != nil {+ t.Fatal(err)+ }+}diff --git a/server/internal/daemon/wakeup_prompt_test.go b/server/internal/daemon/wakeup_prompt_test.goindex 0137475b87..bb6bb2b9be 100644--- a/server/internal/daemon/wakeup_prompt_test.go+++ b/server/internal/daemon/wakeup_prompt_test.go@@ -7,7 +7,7 @@ import (func TestWakeupPromptPreservesInstructionAndDeliveryThread(t *testing.T) {p := BuildPrompt(Task{IssueID: "issue", WakeupID: "wake", TriggerCommentID: "original", TriggerCommentContent: "old instruction", HandoffNote: "task.completed run-x; check its result"}, "codex")- for _, want := range []string{"[WAKEUP]", "check its result", "--parent original", "wakeup disable issue wake", "--roots-only"} {+ for _, want := range []string{"[WAKEUP]", "check its result", "--parent original", "not a new comment trigger", "wakeup disable issue wake", "--roots-only"} {if !strings.Contains(p, want) {t.Errorf("missing %q", want)}