Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(daemon): resolve six injected-instruction contradictions (MUL-5696 conflict audit) (#6354)
Bohan Jiang84fe84cd9ee4
diff --git a/server/cmd/multica/cmd_attachment.go b/server/cmd/multica/cmd_attachment.goindex acbcfab1b1..ffc453330d 100644--- a/server/cmd/multica/cmd_attachment.go+++ b/server/cmd/multica/cmd_attachment.go@@ -25,8 +25,9 @@ var attachmentDownloadCmd = &cobra.Command{Example: ` # Download an image attachment to the current directory$ multica attachment download abc123- # Download to a specific directory- $ multica attachment download abc123 -o /tmp/images`,+ # Download to a directory inside the working directory (keep agent+ # downloads out of /tmp and other machine-shared paths, MUL-4252)+ $ multica attachment download abc123 -o ./attachments`,Args: exactArgs(1),RunE: runAttachmentDownload,}@@ -156,8 +157,15 @@ func runAttachmentDownload(cmd *cobra.Command, args []string) error {return fmt.Errorf("download file: %w", err)}- // Write to the output directory.+ // Write to the output directory, creating it if needed so `-o` works+ // against a directory that does not exist yet (the help example's+ // `-o ./attachments` in a clean workdir).outputDir, _ := cmd.Flags().GetString("output-dir")+ if outputDir != "" {+ if err := os.MkdirAll(outputDir, 0o755); err != nil {+ return fmt.Errorf("create output directory: %w", err)+ }+ }destPath := filepath.Join(outputDir, filename)if err := os.WriteFile(destPath, data, 0o644); err != nil {diff --git a/server/cmd/multica/cmd_attachment_test.go b/server/cmd/multica/cmd_attachment_test.goindex 7448f0f677..bd779e3998 100644--- a/server/cmd/multica/cmd_attachment_test.go+++ b/server/cmd/multica/cmd_attachment_test.go@@ -42,6 +42,10 @@ func TestRunAttachmentDownloadWritesBasenameIntoOutputDir(t *testing.T) {}))defer srv.Close()setCLITestServerEnv(t, srv.URL)+ // A task-scoped mat_ token so the test also runs inside an agent workdir,+ // where a daemon task marker makes newAPIClient reject the helper's+ // default non-mat_ token before the download logic is reached.+ t.Setenv("MULTICA_TOKEN", "mat_test-token")outputDir := t.TempDir()cmd := newAttachmentDownloadTestCmd()@@ -73,6 +77,52 @@ func TestRunAttachmentDownloadWritesBasenameIntoOutputDir(t *testing.T) {}}+// TestRunAttachmentDownloadCreatesMissingOutputDir pins that `-o` works+// against a directory that does not exist yet — the shape the command's own+// help example (`-o ./attachments`) produces in a clean workdir (MUL-5696).+func TestRunAttachmentDownloadCreatesMissingOutputDir(t *testing.T) {+ const attachmentID = "att-456"+ const fileBody = "nested dir body"++ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ switch {+ case r.Method == http.MethodGet && r.URL.Path == "/api/attachments/"+attachmentID:+ _ = json.NewEncoder(w).Encode(map[string]any{+ "id": attachmentID,+ "filename": "shot.png",+ "download_url": "/downloads/shot.png",+ "size_bytes": "15",+ })+ case r.Method == http.MethodGet && r.URL.Path == "/downloads/shot.png":+ _, _ = w.Write([]byte(fileBody))+ default:+ t.Fatalf("unexpected request: %s %s", r.Method, r.URL.Path)+ }+ }))+ defer srv.Close()+ setCLITestServerEnv(t, srv.URL)+ t.Setenv("MULTICA_TOKEN", "mat_test-token")++ outputDir := filepath.Join(t.TempDir(), "attachments", "images")+ cmd := newAttachmentDownloadTestCmd()+ _ = cmd.Flags().Set("output-dir", outputDir)++ stderr := captureStderr(t)+ _, err := captureStdout(t, func() error { return runAttachmentDownload(cmd, []string{attachmentID}) })+ _ = stderr.read()+ if err != nil {+ t.Fatalf("runAttachmentDownload with missing output dir: %v", err)+ }++ data, readErr := os.ReadFile(filepath.Join(outputDir, "shot.png"))+ if readErr != nil {+ t.Fatalf("read downloaded file: %v", readErr)+ }+ if string(data) != fileBody {+ t.Fatalf("downloaded body = %q, want %q", data, fileBody)+ }+}+func newAttachmentUploadTestCmd() *cobra.Command {cmd := &cobra.Command{Use: "upload"}cmd.Flags().String("task", "", "")@@ -260,6 +310,7 @@ func TestRunAttachmentDownloadRequiresDownloadURL(t *testing.T) {}))defer srv.Close()setCLITestServerEnv(t, srv.URL)+ t.Setenv("MULTICA_TOKEN", "mat_test-token")cmd := newAttachmentDownloadTestCmd()if err := runAttachmentDownload(cmd, []string{"att-no-url"}); err == nil || !strings.Contains(err.Error(), "no download URL") {diff --git a/server/internal/daemon/daemon_test.go b/server/internal/daemon/daemon_test.goindex 658fdcf45d..2d00766479 100644--- a/server/internal/daemon/daemon_test.go+++ b/server/internal/daemon/daemon_test.go@@ -854,13 +854,19 @@ func TestBuildPromptAutopilotRunOnly(t *testing.T) {"Daily dependency check","Check dependencies and report outdated packages.","multica autopilot get autopilot-1 --output json",- "Do not run `multica issue get`",} {if !strings.Contains(prompt, want) {t.Fatalf("autopilot prompt missing %q\n---\n%s", want, prompt)}}+ // The issue-command boundary is emitted ONCE, by the brief's autopilot+ // workflow section (execenv.AutopilotIssueCommandsGuard). MUL-5696 found+ // that a second hand-maintained per-turn copy drifts, so the per-turn+ // prompt must not restate it in any form.+ if strings.Contains(prompt, "Do not run `multica issue get`") {+ t.Fatalf("autopilot prompt restates the issue-command boundary the brief owns (MUL-5696)\n---\n%s", prompt)+ }if strings.Contains(prompt, "Your assigned issue ID is:") {t.Fatalf("autopilot prompt should not use issue assignment template\n---\n%s", prompt)}diff --git a/server/internal/daemon/execenv/runtime_config_kind_test.go b/server/internal/daemon/execenv/runtime_config_kind_test.goindex f48612ecdb..cd441aa5de 100644--- a/server/internal/daemon/execenv/runtime_config_kind_test.go+++ b/server/internal/daemon/execenv/runtime_config_kind_test.go@@ -178,6 +178,38 @@ func TestBuildMetaSkillContentSlimKindMatrix(t *testing.T) {}}+// TestBriefDueDateTeachesCalendarDayFormat pins the --due-date synopsis to+// the calendar-day format the server canonically accepts+// (util.ParseCalendarDate: YYYY-MM-DD; an RFC3339 value passes only at exact+// UTC midnight). MUL-5696 found the brief teaching `<RFC3339>` while the CLI+// help and the projects skill say YYYY-MM-DD, steering agents that computed a+// natural timestamp into 400s.+func TestBriefDueDateTeachesCalendarDayFormat(t *testing.T) {+ for name, ctx := range map[string]TaskContextForEnv{+ "issue": {IssueID: "issue-1"},+ "quick-create": {QuickCreatePrompt: "create an issue"},+ } {+ out := buildMetaSkillContent("claude", ctx)+ if !strings.Contains(out, "--due-date <YYYY-MM-DD>") {+ t.Errorf("%s brief missing the calendar-day --due-date synopsis", name)+ }+ if strings.Contains(out, "--due-date <RFC3339>") {+ t.Errorf("%s brief still teaches --due-date <RFC3339>, which the server rejects except at UTC midnight (MUL-5696)", name)+ }+ }+}++// TestBriefOwnsAutopilotIssueCommandsGuard pins the guard's single emission+// point: the autopilot brief carries AutopilotIssueCommandsGuard, and the+// per-turn prompt defers to it (daemon.TestBuildPromptAutopilotRunOnly pins+// the deferral side). MUL-5696.+func TestBriefOwnsAutopilotIssueCommandsGuard(t *testing.T) {+ out := buildMetaSkillContent("claude", TaskContextForEnv{AutopilotRunID: "run-1"})+ if !strings.Contains(out, AutopilotIssueCommandsGuard) {+ t.Errorf("autopilot brief missing AutopilotIssueCommandsGuard — the per-turn prompt defers to this single emission point")+ }+}+// TestSlimQuickCreateAvailableCommands locks the minimal-variant content// for quick-create's Available Commands: `issue create` present, every// other Core command absent (the hard guardrails forbid the call).diff --git a/server/internal/daemon/execenv/runtime_config_sections.go b/server/internal/daemon/execenv/runtime_config_sections.goindex 112ced89f3..9121bbec0a 100644--- a/server/internal/daemon/execenv/runtime_config_sections.go+++ b/server/internal/daemon/execenv/runtime_config_sections.go@@ -263,8 +263,8 @@ func writeAvailableCommands(b *strings.Builder, ctx TaskContextForEnv) {b.WriteString("### Core\n")b.WriteString("- `multica issue get <id> --output json` — full issue.\n")b.WriteString("- `multica issue comment list <issue-id> [--roots-only] [--summary] [--thread <comment-id> [--tail N] | --recent N] [--since <RFC3339>] --output json` — thread-aware comment reads. Bound a wide read with `--roots-only --summary` (roots plus `reply_count` / `last_activity_at`, clipped bodies); bound a deep one with `--thread <id> --tail N`. Careful with `--recent N`: it caps THREADS, not comments, and can return the whole history on a small issue. Resolved-thread folding, paging cursors, and full flag semantics: `--help`.\n")- b.WriteString("- `multica issue create --title \"...\" [--description-file <path>] [--priority X] [--status X] [--assignee X | --assignee-id <uuid>] [--parent <issue-id>] [--stage N] [--project <project-id>] [--due-date <RFC3339>] [--attachment <path>]` — create an issue. For agent-authored long descriptions prefer `--description-file <path>` (heredoc stdin can swallow trailing flags, #4182). Write that file inside your working directory (e.g. `./description.md`), never `/tmp` or shared paths — same workdir rule as `## Comment Formatting`.\n")- b.WriteString("- `multica issue update <id> [--title X] [--description-file <path>] [--priority X] [--status X] [--assignee X] [--parent <issue-id>] [--stage N] [--project <project-id>] [--due-date <RFC3339>]` — update fields; pass `--parent \"\"` to clear parent.\n")+ b.WriteString("- `multica issue create --title \"...\" [--description-file <path>] [--priority X] [--status X] [--assignee X | --assignee-id <uuid>] [--parent <issue-id>] [--stage N] [--project <project-id>] [--due-date <YYYY-MM-DD>] [--attachment <path>]` — create an issue. For agent-authored long descriptions prefer `--description-file <path>` (heredoc stdin can swallow trailing flags, #4182). Write that file inside your working directory (e.g. `./description.md`), never `/tmp` or shared paths — same workdir rule as `## Comment Formatting`.\n")+ b.WriteString("- `multica issue update <id> [--title X] [--description-file <path>] [--priority X] [--status X] [--assignee X] [--parent <issue-id>] [--stage N] [--project <project-id>] [--due-date <YYYY-MM-DD>]` — update fields; pass `--parent \"\"` to clear parent.\n")b.WriteString("- `multica issue status <id> <status>` — flip status (todo / in_progress / in_review / done / blocked / backlog / cancelled).\n")b.WriteString("- `multica issue children <id> [--output json]` — list a parent's sub-issues grouped by stage.\n")b.WriteString("- `multica issue comment add <issue-id> [--content \"...\" | --content-file <path> | --content-stdin] [--parent <comment-id>] [--attachment <path>]` — post a comment. Agent-authored bodies MUST use `--content-file`; see `## Comment Formatting` for why. `multica issue comment add --help` for full flags.\n")@@ -291,7 +291,7 @@ func writeAvailableCommandsQuickCreate(b *strings.Builder) {b.WriteString("## Available Commands\n\n")b.WriteString("**Use `--output json` for structured data.** For anything beyond `issue create`, run `multica --help` or `multica <command> --help`.\n\n")b.WriteString("### Core\n")- b.WriteString("- `multica issue create --title \"...\" [--description \"...\" | --description-file <path> | --description-stdin] [--priority X] [--status X] [--assignee X | --assignee-id <uuid>] [--parent <issue-id>] [--stage N] [--project <project-id>] [--due-date <RFC3339>] [--attachment <path>]` — Create a new issue; `--attachment` may be repeated. For agent-authored long descriptions, prefer `--description-file <path>` over `--description-stdin` (flags after a HEREDOC terminator can be silently swallowed, #4182). Write that file inside your working directory (e.g. `./description.md`), never `/tmp` or shared paths, and treat a failed write as fatal — the CLI rejects a path outside the workdir so a stale file from another run can't leak in (MUL-4252).\n\n")+ b.WriteString("- `multica issue create --title \"...\" [--description \"...\" | --description-file <path> | --description-stdin] [--priority X] [--status X] [--assignee X | --assignee-id <uuid>] [--parent <issue-id>] [--stage N] [--project <project-id>] [--due-date <YYYY-MM-DD>] [--attachment <path>]` — Create a new issue; `--attachment` may be repeated. For agent-authored long descriptions, prefer `--description-file <path>` over `--description-stdin` (flags after a HEREDOC terminator can be silently swallowed, #4182). Write that file inside your working directory (e.g. `./description.md`), never `/tmp` or shared paths, and treat a failed write as fatal — the CLI rejects a path outside the workdir so a stale file from another run can't leak in (MUL-4252).\n\n")}// writeIssueBodyFormatting emits the default Markdown hierarchy for issue@@ -433,6 +433,13 @@ func writeWorkflowQuickCreate(b *strings.Builder) {b.WriteString("- If the CLI returns an error, exit with that error as the only output. Do not retry.\n\n")}+// AutopilotIssueCommandsGuard is the run-only autopilot issue-command boundary,+// shared verbatim by the runtime brief (writeWorkflowAutopilot) and the+// per-turn prompt (daemon.buildAutopilotPrompt). Both land in the same context+// window; MUL-5696 found the two hand-maintained copies had drifted into an+// unconditional ban on one surface and a conditional one on the other.+const AutopilotIssueCommandsGuard = "Do not run `multica issue get`, `multica issue comment add`, or `multica issue status` for this run unless the autopilot instructions explicitly tell you to create or update an issue"+// writeWorkflowAutopilot emits the autopilot run-only workflow.func writeWorkflowAutopilot(b *strings.Builder, ctx TaskContextForEnv) {b.WriteString("**This task was triggered by an Autopilot in run-only mode.** There is no assigned Multica issue for this run.\n\n")@@ -458,7 +465,7 @@ func writeWorkflowAutopilot(b *strings.Builder, ctx TaskContextForEnv) {fmt.Fprintf(b, "- Run `multica autopilot get %s --output json` if you need the full autopilot configuration\n", ctx.AutopilotID)}b.WriteString("- Complete the autopilot instructions directly\n")- b.WriteString("- Do not run `multica issue get`, `multica issue comment add`, or `multica issue status` for this run unless the autopilot instructions explicitly tell you to create or update an issue\n\n")+ b.WriteString("- " + AutopilotIssueCommandsGuard + "\n\n")}// writeWorkflowIssue emits the single issue workflow used by BOTHdiff --git a/server/internal/daemon/prompt.go b/server/internal/daemon/prompt.goindex 36d67cabdc..2bc41fba1c 100644--- a/server/internal/daemon/prompt.go+++ b/server/internal/daemon/prompt.go@@ -104,7 +104,7 @@ func buildPromptBody(task Task, provider string) string {fmt.Fprintf(&b, "> %s\n\n", task.HandoffNote)}fmt.Fprintf(&b, "Start by running `multica issue get %s --output json` to understand your task, then complete it.\n", task.IssueID)- fmt.Fprintf(&b, "For comment history, follow the rule in your runtime workflow file (assignment-triggered tasks treat the read as mandatory). Scan the threads first with `multica issue comment list %s --roots-only --summary --output json`, then expand only what matters with `--thread <thread-id> --tail 30`. Your runtime workflow file documents the rest of the read surface, including pagination and `--since` for incremental polling.\n", task.IssueID)+ fmt.Fprintf(&b, "For comment history, follow the rule in your runtime workflow file (assignment-triggered tasks treat the read as mandatory). Scan the threads first with `multica issue comment list %s --roots-only --summary --output json`, then expand only what matters with `--thread <thread-id> --tail 30`. For `--since` incremental polling, pagination, and folding, see `multica issue comment list --help`.\n", task.IssueID)return b.String()}@@ -200,7 +200,7 @@ func buildQuickCreatePrompt(task Task) string {}}b.WriteString("- **status**: omit (defaults to `todo`).\n")- b.WriteString("- **attachments**: do NOT pass `--attachment`. The flag only accepts LOCAL file paths. Any image URL in the user input is already markdown — keep it inline in `--description` instead.\n\n")+ b.WriteString("- **attachments**: `--attachment` takes LOCAL file paths, never URLs. Image URLs in the user input are already markdown — keep them inline. Files you produced: see `## Output`.\n\n")// output formatb.WriteString("Output format:\n")@@ -570,6 +570,9 @@ func buildAutopilotPrompt(task Task) string {} else {b.WriteString("Complete the instructions above.\n")}- b.WriteString("Do not run `multica issue get`; this run does not have an issue ID.\n")+ // The issue-command boundary (execenv.AutopilotIssueCommandsGuard) is NOT+ // restated here: the brief's autopilot workflow section is its single+ // emission point, and a second hand-maintained per-turn copy is exactly+ // how the two surfaces drifted into conflict before (MUL-5696).return b.String()}diff --git a/server/internal/daemon/prompt_test.go b/server/internal/daemon/prompt_test.goindex 2efde9f749..6725f32275 100644--- a/server/internal/daemon/prompt_test.go+++ b/server/internal/daemon/prompt_test.go@@ -45,12 +45,22 @@ func TestBuildQuickCreatePromptRules(t *testing.T) {// hard rules"never invent requirements","never reduce multi-sentence input",+ // attachment boundary (MUL-5696): the ban is scoped to URLs, and file+ // delivery defers to the quick-create ## Output section — a blanket+ // "do NOT pass --attachment" contradicted it (it names --attachment+ // on the create call as this surface's only file-delivery channel).+ "`--attachment` takes LOCAL file paths, never URLs",+ "Files you produced: see `## Output`",}for _, s := range mustContain {if !strings.Contains(out, s) {t.Errorf("buildQuickCreatePrompt output missing required rule: %q", s)}}++ if strings.Contains(out, "do NOT pass `--attachment`") {+ t.Errorf("buildQuickCreatePrompt carries the unconditional --attachment ban that conflicts with the quick-create ## Output delivery channel (MUL-5696)\n--- output ---\n%s", out)+ }}// TestBuildQuickCreatePromptAssigneeIncludesSquads locks in the MUL-2165diff --git a/server/internal/service/builtin_skills/multica-squads/SKILL.md b/server/internal/service/builtin_skills/multica-squads/SKILL.mdindex 775d2937a8..f96e1ff9f7 100644--- a/server/internal/service/builtin_skills/multica-squads/SKILL.md+++ b/server/internal/service/builtin_skills/multica-squads/SKILL.md@@ -83,10 +83,13 @@ Issue/comment commands often needed with squads:```bashmultica issue get <issue-id> --output jsonmultica issue update <issue-id> --help-multica issue comment list <issue-id> --output json+multica issue comment list <issue-id> --roots-only --summary --output jsonmultica issue comment add <issue-id> --help```+Comment reads stay bounded — the scan-then-expand sequence from the quick+start above — never one unbounded `issue comment list` pull.+Prefer `--output json` for reads. Use `--help` before writes.## Squad fieldsdiff --git a/server/internal/service/builtin_skills_test.go b/server/internal/service/builtin_skills_test.goindex 62982aabf9..d783d002f2 100644--- a/server/internal/service/builtin_skills_test.go+++ b/server/internal/service/builtin_skills_test.go@@ -450,6 +450,19 @@ func TestSquadsSkillCoversLeaderRoutingContract(t *testing.T) {}}+ // MUL-5696: no unbounded comment pull anywhere in the skill. #6347 fixed+ // the quick start's `--recent 10` but missed a second unbounded+ // `issue comment list` in the CLI section; both shapes contradict the+ // brief's "two bounded reads, never one bulk pull" doctrine.+ for _, banned := range []string{+ "multica issue comment list <issue-id> --output json",+ "--recent 10",+ } {+ if strings.Contains(body, banned) {+ t.Errorf("squads skill carries the unbounded comment read %q (MUL-5696)", banned)+ }+ }+if !skillHasFile(skill, "references/squad-source-map.md") {t.Errorf("squads skill missing supporting file references/squad-source-map.md")}