Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(daemon): give doc discussion replies the Windows cookbook and drop per-turn repeats (#11637)

Bohan Jiangf6c55406e81d
diff --git a/server/internal/daemon/execenv/execenv_test.go b/server/internal/daemon/execenv/execenv_test.go
index 7a0bed2708..86eda69ba1 100644
--- a/server/internal/daemon/execenv/execenv_test.go
+++ b/server/internal/daemon/execenv/execenv_test.go
@@ -5423,7 +5423,7 @@ func TestInjectRuntimeConfigMentionLoopHardening(t *testing.T) {
// Notifying FOLLOWERS is a false need: delivery already happens.
// Scoped to followers on purpose — for a non-follower, a mention
// IS how they find out (Elon's review catch on #7245).
- "followers of the issue already see your comment",
+ "followers already see your comment",
"completion notifications are platform-owned",
// The one real function, with its scope.
"pulls someone into work they are not doing yet",
diff --git a/server/internal/daemon/execenv/reply_instructions.go b/server/internal/daemon/execenv/reply_instructions.go
index b42f654fb4..48495b94fa 100644
--- a/server/internal/daemon/execenv/reply_instructions.go
+++ b/server/internal/daemon/execenv/reply_instructions.go
@@ -195,15 +195,37 @@ func buildCommentReplyInstructionsSlim(provider, issueID, triggerCommentID strin
if squadLeader {
lead = "Unless your outcome is `no_action`, post your reply as a comment — always use the trigger comment ID below, "
}
- // Cleanup is GATED on the post succeeding, never a separate statement.
- // Agents hand the whole snippet to one shell call, and an unconditional
- // cleanup line runs — and SUCCEEDS — after a failed post, so the call's
- // exit status becomes the cleanup's 0. Under `--output table` a failed
- // and a successful post both write nothing to stdout, which leaves the
- // exit status as the only machine-checkable signal; masking it lets an
- // agent end its turn believing an unposted result was delivered. The
- // gate also keeps ./reply.md on disk after a failure, so the retry does
- // not have to regenerate the body.
+ post := fmt.Sprintf("multica issue comment add %s --parent %s --content-file ./reply.md --output table", issueID, triggerCommentID)
+ if runtimeGOOS == "windows" {
+ return lead +
+ "do NOT reuse --parent values from previous turns in this session.\n\n" +
+ "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\n" +
+ "Do NOT write literal `\\n` escapes to simulate line breaks; the file preserves real newlines.\n"
+ }
+ return lead +
+ "do NOT reuse --parent values from previous turns in this session.\n\n" +
+ "Write the body file first (rules: ## Comment Formatting above — MUL-2904 / #4182):\n\n" +
+ gatedReplyPost(post) +
+ "Keep the `&&`: as two separate statements a failed post is masked by the cleanup's success, and the body file is deleted.\n\n" +
+ "Do NOT write literal `\\n` escapes to simulate line breaks; the file preserves real newlines.\n"
+}
+
+// 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.
+//
+// Cleanup is GATED on the post succeeding, never a separate statement.
+// Agents hand the whole snippet to one shell call, and an unconditional
+// cleanup line runs — and SUCCEEDS — after a failed post, so the call's
+// exit status becomes the cleanup's 0. Under `--output table` a failed
+// and a successful post both write nothing to stdout, which leaves the
+// exit status as the only machine-checkable signal; masking it lets an
+// agent end its turn believing an unposted result was delivered. The
+// gate also keeps ./reply.md on disk after a failure, so the retry does
+// not have to regenerate the body.
+func gatedReplyPost(post string) string {
if runtimeGOOS == "windows" {
// The daemon knows the host OS, not the shell behind the agent's
// command tool: Codex runs PowerShell on Windows, Claude Code runs
@@ -217,30 +239,28 @@ func buildCommentReplyInstructionsSlim(provider, issueID, triggerCommentID strin
// PowerShell 5.1 has no `&&` (it landed in PowerShell 7), so that
// variant checks $LASTEXITCODE — which carries the exit code of the
// last NATIVE command — and propagates it instead.
- return fmt.Sprintf(
- lead+
- "do NOT reuse --parent values from previous turns in this session.\n\n"+
- "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"+
- "PowerShell:\n\n"+
- " multica issue comment add %[1]s --parent %[2]s --content-file ./reply.md --output table\n"+
- " if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }\n"+
- " Remove-Item ./reply.md\n\n"+
- "Git Bash:\n\n"+
- " multica issue comment add %[1]s --parent %[2]s --content-file ./reply.md --output table && rm ./reply.md\n\n"+
- "Do NOT drop the exit-code check or the `&&`: a bare cleanup after a failed post reports success and deletes the body.\n\n"+
- "Do NOT write literal `\\n` escapes to simulate line breaks; the file preserves real newlines.\n",
- issueID, triggerCommentID,
- )
+ return "PowerShell:\n\n" +
+ " " + post + "\n" +
+ " if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }\n" +
+ " Remove-Item ./reply.md\n\n" +
+ "Git Bash:\n\n" +
+ " " + post + " && rm ./reply.md\n\n"
}
- return fmt.Sprintf(
- lead+
- "do NOT reuse --parent values from previous turns in this session.\n\n"+
- "Write the body file first (rules: ## Comment Formatting above — MUL-2904 / #4182):\n\n"+
- " multica issue comment add %s --parent %s --content-file ./reply.md --output table && rm ./reply.md\n\n"+
- "Keep the `&&`: as two separate statements a failed post is masked by the cleanup's success, and the body file is deleted.\n\n"+
- "Do NOT write literal `\\n` escapes to simulate line breaks; the file preserves real newlines.\n",
- issueID, triggerCommentID,
- )
+ return " " + post + " && rm ./reply.md\n\n"
+}
+
+// BuildDocCommentReplyInstructions is the reply step of a doc discussion
+// run's per-turn prompt (MUL-9933): how to post this turn's reply under
+// threadID. A doc run gets no `## Comment Formatting` section, so the Windows
+// variant carries the file-first encoding rule itself.
+func BuildDocCommentReplyInstructions(docID, threadID string) string {
+ post := fmt.Sprintf("multica doc comment add %s --parent %s --content-file ./reply.md --output table", docID, threadID)
+ if runtimeGOOS == "windows" {
+ return "Write the reply to a UTF-8 file in your working directory with your file-write tool — never pipe via `--content-stdin` (PowerShell drops non-ASCII). 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 "Write the reply to a UTF-8 file in your working directory, then post it:\n\n" + gatedReplyPost(post)
}
// ThreadReplyTarget is one root-thread group a coalesced run must answer.
diff --git a/server/internal/daemon/execenv/reply_instructions_shell_test.go b/server/internal/daemon/execenv/reply_instructions_shell_test.go
index 7fdf807bda..b57fbdf549 100644
--- a/server/internal/daemon/execenv/reply_instructions_shell_test.go
+++ b/server/internal/daemon/execenv/reply_instructions_shell_test.go
@@ -102,6 +102,10 @@ func runSnippet(t *testing.T, shell string, args []string, stubDir string) (int,
// prove the command itself returns an error, not that the pasted block
// preserves it.
//
+// 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.
+//
// Not parallel: mutates the package-level runtimeGOOS.
func TestCommentReplySnippetPropagatesPostFailure(t *testing.T) {
saved := runtimeGOOS
@@ -109,6 +113,13 @@ func TestCommentReplySnippetPropagatesPostFailure(t *testing.T) {
const issueID = "11111111-1111-1111-1111-111111111111"
const triggerID = "22222222-2222-2222-2222-222222222222"
+ renders := []struct {
+ name string
+ render func() string
+ }{
+ {"issue", func() string { return BuildCommentReplyInstructions("claude", issueID, triggerID, false) }},
+ {"doc", func() string { return BuildDocCommentReplyInstructions(issueID, triggerID) }},
+ }
for _, tc := range []struct {
name string
@@ -149,27 +160,29 @@ func TestCommentReplySnippetPropagatesPostFailure(t *testing.T) {
t.Skipf("%s not available: %v", tc.shell, err)
}
runtimeGOOS = tc.goos
- script := strings.Join(snippetBlock(t, BuildCommentReplyInstructions("claude", issueID, triggerID, false), tc.marker), "\n")
+ for _, r := range renders {
+ script := strings.Join(snippetBlock(t, r.render(), tc.marker), "\n")
- t.Run("failed post keeps the failure and the body", func(t *testing.T) {
- code, bodyKept := runSnippet(t, tc.shell, tc.wrap(script), stubMultica(t, 3))
- if code == 0 {
- t.Errorf("failed post reported success (exit 0); the cleanup masked it\n---\n%s", script)
- }
- if !bodyKept {
- t.Errorf("failed post deleted ./reply.md; the retry would have to regenerate the body\n---\n%s", script)
- }
- })
+ t.Run(r.name+"/failed post keeps the failure and the body", func(t *testing.T) {
+ code, bodyKept := runSnippet(t, tc.shell, tc.wrap(script), stubMultica(t, 3))
+ if code == 0 {
+ t.Errorf("failed post reported success (exit 0); the cleanup masked it\n---\n%s", script)
+ }
+ if !bodyKept {
+ t.Errorf("failed post deleted ./reply.md; the retry would have to regenerate the body\n---\n%s", script)
+ }
+ })
- t.Run("successful post still cleans up", func(t *testing.T) {
- code, bodyKept := runSnippet(t, tc.shell, tc.wrap(script), stubMultica(t, 0))
- if code != 0 {
- t.Errorf("successful post reported exit %d\n---\n%s", code, script)
- }
- if bodyKept {
- t.Errorf("successful post left ./reply.md behind\n---\n%s", script)
- }
- })
+ t.Run(r.name+"/successful post still cleans up", func(t *testing.T) {
+ code, bodyKept := runSnippet(t, tc.shell, tc.wrap(script), stubMultica(t, 0))
+ if code != 0 {
+ t.Errorf("successful post reported exit %d\n---\n%s", code, script)
+ }
+ if bodyKept {
+ t.Errorf("successful post left ./reply.md behind\n---\n%s", script)
+ }
+ })
+ }
})
}
}
diff --git a/server/internal/daemon/execenv/reply_instructions_test.go b/server/internal/daemon/execenv/reply_instructions_test.go
index 6220bcb5d1..58a929fd2f 100644
--- a/server/internal/daemon/execenv/reply_instructions_test.go
+++ b/server/internal/daemon/execenv/reply_instructions_test.go
@@ -358,3 +358,41 @@ func TestBuildCommentReplyInstructionsSquadLeaderCarveOut(t *testing.T) {
t.Errorf("ordinary reply instructions leaked the leader carve-out\n---\n%s", ordinary)
}
}
+
+// TestBuildDocCommentReplyInstructionsWindowsVariants pins the doc discussion
+// reply (MUL-9933) to the issue reply's per-shell cookbook: PowerShell 5.1 has
+// no `&&`, and a doc run gets no `## Comment Formatting` section, so the
+// Windows text must carry the file-first rule itself and must not point at a
+// section the brief does not have.
+//
+// Not parallel: mutates the package-level runtimeGOOS.
+func TestBuildDocCommentReplyInstructionsWindowsVariants(t *testing.T) {
+ saved := runtimeGOOS
+ t.Cleanup(func() { runtimeGOOS = saved })
+
+ const bash = " multica doc comment add doc-1 --parent thread-1 --content-file ./reply.md --output table && rm ./reply.md\n"
+
+ runtimeGOOS = "linux"
+ got := BuildDocCommentReplyInstructions("doc-1", "thread-1")
+ if !strings.Contains(got, bash) {
+ t.Fatalf("non-Windows doc reply missing the gated command:\n%s", got)
+ }
+ if strings.Contains(got, "PowerShell") {
+ t.Fatalf("non-Windows doc reply must not carry the PowerShell variant:\n%s", got)
+ }
+
+ runtimeGOOS = "windows"
+ got = BuildDocCommentReplyInstructions("doc-1", "thread-1")
+ for _, want := range []string{
+ "PowerShell:\n\n multica doc comment add doc-1 --parent thread-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`",
+ } {
+ if !strings.Contains(got, want) {
+ t.Fatalf("Windows doc reply missing %q:\n%s", want, got)
+ }
+ }
+ if strings.Contains(got, "Comment Formatting") {
+ t.Fatalf("doc runs have no ## Comment Formatting section to point at:\n%s", got)
+ }
+}
diff --git a/server/internal/daemon/execenv/runtime_config_sections.go b/server/internal/daemon/execenv/runtime_config_sections.go
index c2c3606363..0f500ac9f2 100644
--- a/server/internal/daemon/execenv/runtime_config_sections.go
+++ b/server/internal/daemon/execenv/runtime_config_sections.go
@@ -945,9 +945,11 @@ func writeMentions(b *strings.Builder, docsEnabled bool) {
// The notify caveat is scoped to FOLLOWERS on
// purpose — for a human who does not follow the issue, a mention is
// exactly how they find out, and that escalation must stay available
- // (Elon's review catch on #7245). The cost asymmetry line is what breaks
- // the ambiguous middle.
- b.WriteString("A mention pulls someone into work they are not doing yet: escalate to a human owner, hand another agent a concrete new sub-task, loop someone in because the user asked. It is not needed merely to notify — followers of the issue already see your comment, and completion notifications are platform-owned. Nor is it how a name is written — crediting a decision or citing someone's earlier point is prose about them, not work for them; the link form dispatches whoever it names, so a reference stays plain text. A thank-you / sign-off / FYI mention of another agent enqueues a paid run whose only possible reply is another courtesy; a missed mention costs one follow-up ask, a stray one costs a run. Silence ends conversations.\n\n")
+ // (Elon's review catch on #7245). It does not say "of the issue": doc
+ // discussion runs get this section too, and there the people already
+ // notified are the discussion's earlier writers (NotifyDocComment). The
+ // cost asymmetry line is what breaks the ambiguous middle.
+ b.WriteString("A mention pulls someone into work they are not doing yet: escalate to a human owner, hand another agent a concrete new sub-task, loop someone in because the user asked. It is not needed merely to notify — followers already see your comment, and completion notifications are platform-owned. Nor is it how a name is written — crediting a decision or citing someone's earlier point is prose about them, not work for them; the link form dispatches whoever it names, so a reference stays plain text. A thank-you / sign-off / FYI mention of another agent enqueues a paid run whose only possible reply is another courtesy; a missed mention costs one follow-up ask, a stray one costs a run. Silence ends conversations.\n\n")
}
// writeAttachments emits the Attachments pointer.
diff --git a/server/internal/daemon/prompt_doc.go b/server/internal/daemon/prompt_doc.go
index 0deb86ac8b..a0e2795d1a 100644
--- a/server/internal/daemon/prompt_doc.go
+++ b/server/internal/daemon/prompt_doc.go
@@ -3,12 +3,16 @@ package daemon
import (
"fmt"
"strings"
+
+ "github.com/multica-ai/multica/server/internal/daemon/execenv"
)
// buildDocCommentPrompt is the per-turn prompt of a run started from a doc
// discussion (MUL-9933). The doc, discussion and reply command are re-emitted
// on every turn: runs on one doc share a session, so a resumed session must
-// never reply under an earlier discussion's --parent.
+// never reply under an earlier discussion's --parent. The rules that hold for
+// every turn (changing the doc, what only people may do, no progress updates)
+// live in the runtime brief, not here.
func buildDocCommentPrompt(task Task) string {
var b strings.Builder
b.WriteString("You are running as a local coding agent for a Multica workspace.\n\n")
@@ -31,10 +35,9 @@ func buildDocCommentPrompt(task Task) string {
b.WriteString("Workflow:\n\n")
fmt.Fprintf(&b, "1. Read the doc: `multica doc get %s --output content`.\n", task.DocID)
fmt.Fprintf(&b, "2. Read the whole discussion: `multica doc comment list %s --thread %s --output json`.\n", task.DocID, task.DocThreadID)
- b.WriteString("3. Do what the comment asks. When it asks for a change to the doc, or changing the doc is clearly the best answer, make the change yourself: `multica doc edit` for targeted changes, `multica doc update` only to rewrite the whole doc (see `multica doc --help`). Every change is kept in the doc's history and can be restored.\n")
- b.WriteString("4. Reply in this discussion before you exit — this step is mandatory. Write the reply to a UTF-8 file in your working directory, then post it:\n\n")
- fmt.Fprintf(&b, " multica doc comment add %s --parent %s --content-file ./reply.md --output table && rm ./reply.md\n\n", task.DocID, task.DocThreadID)
- b.WriteString("Post one reply with your result, not progress updates. You can only reply in this discussion: starting a new one, resolving it and deleting comments are left to people.\n")
+ b.WriteString("3. Do what the comment asks: `multica doc edit` for targeted changes, `multica doc update` only to rewrite the whole doc.\n")
+ b.WriteString("4. Reply in this discussion before you exit — this step is mandatory. ")
+ b.WriteString(execenv.BuildDocCommentReplyInstructions(task.DocID, task.DocThreadID))
return b.String()
}
diff --git a/server/internal/daemon/prompt_doc_test.go b/server/internal/daemon/prompt_doc_test.go
index 8af382cf4c..9d7956908a 100644
--- a/server/internal/daemon/prompt_doc_test.go
+++ b/server/internal/daemon/prompt_doc_test.go
@@ -33,6 +33,14 @@ func TestBuildPromptDocCommentNamesDiscussionAndReplyCommand(t *testing.T) {
if strings.Contains(prompt, "multica issue") {
t.Fatalf("doc prompt must not send the agent to issue commands:\n%s", prompt)
}
+ // Rules that hold for every turn live once in the brief
+ // (writeWorkflowDocComment, Output); the per-turn prompt carries only what
+ // changes per turn.
+ for _, stable := range []string{"doc's history", "left to people", "progress updates"} {
+ if strings.Contains(prompt, stable) {
+ t.Fatalf("doc prompt repeats the brief's stable rule %q:\n%s", stable, prompt)
+ }
+ }
task.DocCommentContent = ""
if prompt := BuildPrompt(task, "claude"); !strings.Contains(prompt, "has been deleted") {
diff --git a/server/internal/service/builtin_skills/multica-platform/references/docs.md b/server/internal/service/builtin_skills/multica-platform/references/docs.md
index 0d84635689..c85c07cf67 100644
--- a/server/internal/service/builtin_skills/multica-platform/references/docs.md
+++ b/server/internal/service/builtin_skills/multica-platform/references/docs.md
@@ -57,9 +57,9 @@ with it. Moves and folder commands do not take it.
Reviewers leave feedback as comment threads anchored to doc text. Before
revising a doc someone reviewed, run `multica doc comment list <doc-id>`.
-Resolved threads are hidden unless you pass `--include-resolved`; each root
-comment's `anchor_quote` is the text it was left on, and `--output json` has
-the full comment text.
+Resolved threads are hidden unless you pass `--include-resolved` or
+`--thread`; each root comment's `anchor_quote` is the text it was left on,
+and `--output json` has the full comment text.
You can reply in an existing thread: