Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
Honor agent identity in assignment workflow (#3802)
Multica Eve63b847ee48ed
diff --git a/server/internal/daemon/execenv/runtime_config.go b/server/internal/daemon/execenv/runtime_config.goindex 416b836b26..f3e9e86cbc 100644--- a/server/internal/daemon/execenv/runtime_config.go+++ b/server/internal/daemon/execenv/runtime_config.go@@ -525,6 +525,14 @@ func buildMetaSkillContent(provider string, ctx TaskContextForEnv) string {b.WriteString("- **Recommended keys** (reuse these names so queries stay consistent across the workspace; coin a new key only when none fits): `pr_url`, `pr_number`, `pipeline_status`, `deploy_url`, `external_issue_url`, `waiting_on`, `blocked_reason`, `decision`. Use snake_case ASCII. The list is short on purpose — most issues only need 1-2 of these pinned, not the full set.\n\n")}+ isAssignmentTriggered := ctx.ChatSessionID == "" && ctx.QuickCreatePrompt == "" && ctx.AutopilotRunID == "" && ctx.TriggerCommentID == ""+ if isAssignmentTriggered {+ b.WriteString("## Instruction Precedence\n\n")+ b.WriteString("Agent Identity instructions have priority over the assignment workflow below. ")+ b.WriteString("If a workflow step conflicts with Agent Identity, skip the conflicting action and continue with the remaining compatible steps. ")+ b.WriteString("Never treat this runtime workflow as permission to change issue status, investigate, implement, or otherwise act beyond your Agent Identity.\n\n")+ }+b.WriteString("### Workflow\n\n")if ctx.ChatSessionID != "" {@@ -606,20 +614,20 @@ func buildMetaSkillContent(provider string, ctx TaskContextForEnv) string {b.WriteString("9. Do NOT change the issue status unless the comment explicitly asks for it\n\n")} else {// Assignment-triggered: defer to agent Skills for workflow specifics.- b.WriteString("You are responsible for managing the issue status throughout your work.\n\n")+ b.WriteString("You are responsible for managing the issue status throughout your work, unless your Agent Identity forbids issue status changes.\n\n")fmt.Fprintf(&b, "1. Run `multica issue get %s --output json` to understand your task\n", ctx.IssueID)fmt.Fprintf(&b, "2. Run `multica issue metadata list %s --output json` to see what prior agents pinned — best-effort, empty `{}` and CLI failures are normal. See the `## Issue Metadata` section above for what to look for.\n", ctx.IssueID)fmt.Fprintf(&b, "3. Run `multica issue comment list %s --output json` to read the full comment history (returns all comments, capped server-side at 2000) — this is mandatory, not optional. Earlier comments often carry context the issue body lacks (e.g. which repo to work in, the prior agent's findings, the reason the issue was reassigned to you). Skipping this step is the most common cause of agents acting on stale or incomplete instructions. When the flat dump is too large to ingest in one shot, treat `--recent 20 --output json` plus the `--before` / `--before-id` cursor (from the stderr `Next thread cursor:` line) as a paging strategy: keep walking older threads until you have read enough history to satisfy this mandatory step. `--recent` is a way to read the full history page-by-page, not a shortcut that replaces it.\n", ctx.IssueID)- fmt.Fprintf(&b, "4. Run `multica issue status %s in_progress`\n", ctx.IssueID)- b.WriteString("5. Follow your Skills and Agent Identity to complete the task (write code, investigate, etc.)\n")+ fmt.Fprintf(&b, "4. Run `multica issue status %s in_progress` unless your Agent Identity forbids issue status changes; if it does, skip this step.\n", ctx.IssueID)+ b.WriteString("5. Complete the task within your Agent Identity boundaries. Do not investigate, implement, create issues, update issues, or delegate if your Agent Identity forbids that action; if your role is delegation-only, perform the allowed delegation work and stop once that outcome is delivered.\n")if ctx.IsSquadLeader {fmt.Fprintf(&b, "6. **Post your final results as a comment** (unless your outcome is `no_action` — in that case, calling `multica squad activity %s no_action --reason \"...\"` alone is sufficient; you MUST exit without posting any comment. DO NOT post a comment announcing no_action or saying you are exiting silently): post it with `multica issue comment add %s` using the platform-correct non-inline mode from ## Comment Formatting (never inline `--content`). Your results are only visible to the user if posted via this CLI call; text in your terminal or run logs is NOT delivered.\n", ctx.IssueID, ctx.IssueID)} else {fmt.Fprintf(&b, "6. **Post your final results as a comment — this step is mandatory**: post it with `multica issue comment add %s` using the platform-correct non-inline mode from ## Comment Formatting (never inline `--content`). Your results are only visible to the user if posted via this CLI call; text in your terminal or run logs is NOT delivered.\n", ctx.IssueID)}b.WriteString("7. Before exiting: only if this run produced a fact that clears the high bar (important AND likely to be re-read by future runs on this same issue, e.g. a new PR URL or deploy URL), or you noticed a metadata key from entry that is now stale, pin or clear it via `multica issue metadata set`/`delete`. Most runs write nothing here — that is the expected outcome, not a gap. When in doubt, do not write. See the `## Issue Metadata` section above for the full bar.\n")- fmt.Fprintf(&b, "8. When done, run `multica issue status %s in_review`\n", ctx.IssueID)- fmt.Fprintf(&b, "9. If blocked, run `multica issue status %s blocked` and post a comment explaining why\n\n", ctx.IssueID)+ fmt.Fprintf(&b, "8. When done, run `multica issue status %s in_review` unless your Agent Identity forbids issue status changes; if it does, skip this step.\n", ctx.IssueID)+ fmt.Fprintf(&b, "9. If blocked, run `multica issue status %s blocked` unless your Agent Identity forbids issue status changes. Post a comment explaining the blocker unless your Agent Identity forbids issue comments.\n\n", ctx.IssueID)}// Sub-issue creation semantics — the only piece of the old Parent /diff --git a/server/internal/daemon/execenv/runtime_config_test.go b/server/internal/daemon/execenv/runtime_config_test.goindex 38b1b092a9..cbf58ad44a 100644--- a/server/internal/daemon/execenv/runtime_config_test.go+++ b/server/internal/daemon/execenv/runtime_config_test.go@@ -256,19 +256,84 @@ func TestCommentTriggeredBriefResumedNoDeltaSkipsDefaultThreadRead(t *testing.T)}}-// Assignment-triggered briefs are the inverse boundary: when the agent-// owns the issue lifecycle, the brief AS A WHOLE must still tell it to-// flip to in_review on completion. The flip lives in the-// assignment-triggered workflow above (with the real id substituted).-func TestAssignmentTriggeredProtocolStillFlipsInReview(t *testing.T) {+// Assignment-triggered briefs are the high-risk path for role conflicts:+// non-executor agents still need issue context, but the runtime workflow must+// not turn status changes, investigation, implementation, or delegation into+// permissions that override Agent Identity.+func TestAssignmentTriggeredProtocolHonorsAgentIdentity(t *testing.T) {t.Parallel()const issueID = "77777777-8888-9999-aaaa-bbbbbbbbbbbb"ctx := TaskContextForEnv{IssueID: issueID}out := buildMetaSkillContent("claude", ctx)- want := "`multica issue status " + issueID + " in_review`"- if !strings.Contains(out, want) {- t.Errorf("assignment-triggered brief must still flip to in_review on completion (expected %q in the workflow above)", want)+ for _, want := range []string{+ "## Instruction Precedence",+ "Agent Identity instructions have priority over the assignment workflow below.",+ "If a workflow step conflicts with Agent Identity, skip the conflicting action",+ "Never treat this runtime workflow as permission to change issue status, investigate, implement",+ "Run `multica issue status " + issueID + " in_progress` unless your Agent Identity forbids issue status changes; if it does, skip this step.",+ "Complete the task within your Agent Identity boundaries.",+ "Do not investigate, implement, create issues, update issues, or delegate if your Agent Identity forbids that action",+ "When done, run `multica issue status " + issueID + " in_review` unless your Agent Identity forbids issue status changes; if it does, skip this step.",+ "If blocked, run `multica issue status " + issueID + " blocked` unless your Agent Identity forbids issue status changes.",+ } {+ if !strings.Contains(out, want) {+ t.Errorf("assignment-triggered brief missing identity-bound workflow text %q\n---\n%s", want, out)+ }+ }++ for _, banned := range []string{+ "4. Run `multica issue status " + issueID + " in_progress`\n",+ "5. Follow your Skills and Agent Identity to complete the task (write code, investigate, etc.)",+ "8. When done, run `multica issue status " + issueID + " in_review`\n",+ } {+ if strings.Contains(out, banned) {+ t.Errorf("assignment-triggered brief still contains unconditional legacy workflow text %q\n---\n%s", banned, out)+ }+ }+}++func TestInstructionPrecedenceOnlyAppliesToAssignmentWorkflow(t *testing.T) {+ t.Parallel()+ cases := []struct {+ name string+ ctx TaskContextForEnv+ }{+ {+ name: "comment-triggered",+ ctx: TaskContextForEnv{+ IssueID: "11111111-2222-3333-4444-555555555555",+ TriggerCommentID: "22222222-3333-4444-5555-666666666666",+ },+ },+ {+ name: "chat",+ ctx: TaskContextForEnv{ChatSessionID: "chat-1"},+ },+ {+ name: "quick-create",+ ctx: TaskContextForEnv{QuickCreatePrompt: "create me an issue"},+ },+ {+ name: "autopilot run-only",+ ctx: TaskContextForEnv{AutopilotRunID: "run-1"},+ },+ }+ for _, tc := range cases {+ tc := tc+ t.Run(tc.name, func(t *testing.T) {+ t.Parallel()+ out := buildMetaSkillContent("claude", tc.ctx)+ for _, banned := range []string{+ "## Instruction Precedence",+ "assignment workflow below",+ "Never treat this runtime workflow as permission to change issue status",+ } {+ if strings.Contains(out, banned) {+ t.Errorf("%s brief must not inherit assignment-only precedence text %q\n---\n%s", tc.name, banned, out)+ }+ }+ })}}