Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
refactor(daemon): retreat deep read semantics to --help, trim BTS prose (MUL-5442) (#6347)
Bohan Jiang766c7a7fa2b7
diff --git a/server/cmd/multica/cmd_issue.go b/server/cmd/multica/cmd_issue.goindex c4bf37f8df..dc37095d7c 100644--- a/server/cmd/multica/cmd_issue.go+++ b/server/cmd/multica/cmd_issue.go@@ -522,11 +522,11 @@ func init() {issueCommentListCmd.Flags().String("since", "", "Only return comments created after this timestamp (RFC3339)")issueCommentListCmd.Flags().String("thread", "", "Comment UUID — return the thread containing this comment (root + every descendant). May be a root or a reply id.")issueCommentListCmd.Flags().Int("tail", 0, "Only valid with --thread. Cap reply count to the N most recent replies; the thread root is always included (even with --tail 0). Use --before/--before-id to scroll to older replies.")- issueCommentListCmd.Flags().Int("recent", 0, "Return the N most recently active threads (root + descendants per thread). Use --before/--before-id from the previous response to scroll to older threads.")+ issueCommentListCmd.Flags().Int("recent", 0, "Return the N most recently active threads. N caps THREADS, not comments: every thread carries its root plus EVERY descendant with no per-thread cap, so on an issue with fewer than N root threads this returns the entire history (minus folded resolved threads). Prefer two bounded reads: scan with --roots-only --summary, then open selected threads with --thread <id> --tail N. Use --before/--before-id from the previous response to scroll to older threads.")issueCommentListCmd.Flags().Bool("roots-only", false, "Only return top-level comments (parent_id is null). Each root also carries reply_count + last_activity_at so you can triage which thread to open.")issueCommentListCmd.Flags().Bool("summary", false, "Clip each comment's content to a short preview (sets content_truncated) so you can scan a list without pulling full bodies. Composes with any mode.")issueCommentListCmd.Flags().Bool("full", false, "Escape hatch: return every comment in resolved threads verbatim. By default the complete-thread reads (default list, --recent, --thread without --tail) are folded — a resolved thread collapses to its root + conclusion, with the dropped count reported on the root — so you do not pay tokens for settled discussion. Pass --full when you need the folded discussion. No effect on --since/--tail/--roots-only reads, which are never folded.")- issueCommentListCmd.Flags().String("before", "", "Cursor (RFC3339Nano timestamp). With --recent: thread cursor (last_activity_at). With --thread + --tail: reply cursor (reply created_at). Read from the X-Multica-Next-Before response header; must be paired with --before-id.")+ issueCommentListCmd.Flags().String("before", "", "Cursor (RFC3339Nano timestamp). With --recent: thread cursor (last_activity_at). With --thread + --tail: reply cursor (reply created_at). Read from the X-Multica-Next-Before response header, printed on stderr as \"Next thread cursor\" / \"Next reply cursor\"; must be paired with --before-id.")issueCommentListCmd.Flags().String("before-id", "", "Cursor UUID. With --recent: thread root UUID. With --thread + --tail: oldest reply UUID. Read from the X-Multica-Next-Before-Id response header; must be paired with --before.")// issue runsdiff --git a/server/cmd/multica/cmd_issue_test.go b/server/cmd/multica/cmd_issue_test.goindex f39889cfc7..64da594b93 100644--- a/server/cmd/multica/cmd_issue_test.go+++ b/server/cmd/multica/cmd_issue_test.go@@ -3418,3 +3418,40 @@ func TestRunIssueUpdateOmitsPositionWhenUnset(t *testing.T) {t.Fatalf("position must be absent from the body when --position is not passed, got %#v", body["position"])}}++// TestIssueCommentListHelpCarriesReadContract pins the read-surface contract+// that MUL-5442 moved out of the runtime brief into this command's --help: the+// --recent saturation semantics (MUL-5372), the bounded two-step alternative,+// and the pagination cursor labels. The brief now only points here — if these+// leave the help, the pointer dangles and the over-read trap returns+// undocumented.+//+// The assertions run against the RENDERED FlagUsages output, not raw+// Flag.Usage: pflag's UnquoteUsage hijacks the first backtick pair in a usage+// string as the flag's value placeholder (see+// TestLoginTokenHelpOutputRendersCleanly for the original regression), so only+// the rendered output proves what an agent actually reads.+func TestIssueCommentListHelpCarriesReadContract(t *testing.T) {+ help := issueCommentListCmd.Flags().FlagUsages()++ for _, want := range []string{+ // --before must keep its string placeholder — a backticked phrase in+ // the usage text would replace it (the UnquoteUsage hijack).+ "--before string",+ // The saturation contract relocated from the brief (MUL-5372).+ "caps THREADS, not comments",+ "no per-thread cap",+ "fewer than N root threads",+ // The bounded alternative, as two sequential reads — the flags are+ // mutually exclusive, so the help must never suggest composing them.+ "scan with --roots-only --summary",+ "then open selected threads with --thread <id> --tail N",+ // Pagination cursor labels, exactly as the CLI prints them on stderr.+ "Next thread cursor",+ "Next reply cursor",+ } {+ if !strings.Contains(help, want) {+ t.Errorf("comment list rendered help missing %q, got:\n%s", want, help)+ }+ }+}diff --git a/server/internal/daemon/execenv/execenv_test.go b/server/internal/daemon/execenv/execenv_test.goindex eef0cf64c4..ebb6c1094f 100644--- a/server/internal/daemon/execenv/execenv_test.go+++ b/server/internal/daemon/execenv/execenv_test.go@@ -989,6 +989,10 @@ func TestInjectRuntimeConfigBackgroundTaskSafetyProviderAgnostic(t *testing.T) {s := string(data)for _, want := range []string{"## Background Task Safety",+ // The orphan rule is scoped to run-owned work — an unscoped+ // "anything still running" would sweep in external systems+ // (GitHub Actions) the section later says NOT to wait for.+ "any run-owned work still active is orphaned","Do NOT end your turn while background tasks","wait for a future notification/reminder","run the work synchronously instead",@@ -5471,14 +5475,12 @@ func TestInjectRuntimeConfigAssignmentTriggerScansRootsFirst(t *testing.T) {t.Errorf("assignment Workflow regressed mandatory scan-first catch-up, missing %q\n---\n%s", want, s)}}- // Older context must remain reachable through pagination. The cursor label- // and flags are documented in `## Available Commands` rather than restated- // inside the step (MUL-5372), so assert the label itself, not the literal- // `Next thread cursor: ...` stderr line the old step-3 copy quoted.+ // Older context must remain reachable through pagination. The cursor+ // labels and flags now live in the CLI's own --help (MUL-5442, pinned by+ // TestIssueCommentListHelpCarriesReadContract in cmd/multica); the brief+ // keeps a pointer in the flag reference.for _, want := range []string{- "Next thread cursor",- "--before",- "--before-id",+ "paging cursors, and full flag semantics: `--help`",} {if !strings.Contains(s, want) {t.Errorf("assignment Workflow missing older-history pagination guidance %q\n---\n%s", want, s)@@ -5533,11 +5535,11 @@ func TestInjectRuntimeConfigCatchUpScansRootsFirst(t *testing.T) {"multica issue comment list issue-1 --roots-only --summary --output json",// ...followed by an explicit, bounded drill-down."multica issue comment list issue-1 --thread <thread-id> --tail 30 --output json",- // The saturation semantics that made --recent 10 misleading are stated- // once, in the flag reference rather than in the step.+ // The headline saturation warning stays in the flag reference; the+ // deep semantics (per-thread cap, root-thread saturation) moved to the+ // CLI's own --help (MUL-5442) and are pinned there+ // (TestIssueCommentListHelpCarriesReadContract in cmd/multica)."caps THREADS, not comments",- "no per-thread cap",- "fewer than N root threads",} {if !strings.Contains(s, want) {t.Errorf("brief missing bounded catch-up guidance %q\n---\n%s", want, s)diff --git a/server/internal/daemon/execenv/runtime_config_sections.go b/server/internal/daemon/execenv/runtime_config_sections.goindex 3bd16d82cf..4790d57b75 100644--- a/server/internal/daemon/execenv/runtime_config_sections.go+++ b/server/internal/daemon/execenv/runtime_config_sections.go@@ -96,13 +96,13 @@ func writeHeader(b *strings.Builder) {// all, not to any one later bullet.func writeBackgroundTaskSafetySlim(b *strings.Builder) {b.WriteString("## Background Task Safety\n\n")- b.WriteString("Multica marks the task terminal the moment your top-level turn exits — any process, tool call, or subagent owned by this run that is still active is orphaned, its result lost, and the final comment you meant to post after it never sends. There is no background-completion wakeup here.\n\n")- b.WriteString("- Do NOT end your turn while background tasks or other work that still belongs to the current run is active, including async subagents, background shell commands, and detached tool calls. Never background-and-yield: no future notification or wakeup will arrive to resume you. A tool response that says to wait for a future notification/reminder, or that it is running in the background so you can keep working, does not change that — block before exiting. If you can't observe a result, run the work synchronously instead, and never end a turn with a \"standing by\" / \"I'll report back when X finishes\" message: that becomes your final output and the task ends.\n")+ b.WriteString("Multica marks the task terminal the moment your top-level turn exits — any run-owned work still active is orphaned, its result lost, and the final comment you meant to post never sends. There is no background-completion wakeup here.\n\n")+ b.WriteString("- Do NOT end your turn while background tasks or other run-owned work is active — async subagents, background shells, and detached tool calls included. Never background-and-yield: no future notification or wakeup will arrive to resume you. A tool response that says to wait for a future notification/reminder, or that it is running in the background so you can keep working, does not change that — block before exiting. If you can't observe a result, run the work synchronously instead, and never end a turn with a \"standing by\" / \"I'll report back when X finishes\" message: it becomes your final output.\n")b.WriteString("- When a required result from run-owned work must be collected, wait synchronously inside one foreground tool call that blocks to completion (e.g. a blocking test or build command); never split \"start the wait\" and \"collect the result\" across turns.\n")b.WriteString("- A user explicitly asking for a local service to stay available after the turn is a persistent service handoff, not background-and-yield — allowed only when the running service itself is the requested deliverable. Detach its lifecycle from this run first (durable logs, a recorded cleanup handle such as PID/profile), verify readiness, and reply with the URL, logs, and stop instructions. Without a supervisor, describe survival as best-effort, not guaranteed.\n")b.WriteString("- The persistent-service exception does not cover tests, builds, CI polling, monitors, or any other work whose completion the agent still owes; those remain run-owned, and the CI-specific rules below still apply.\n")b.WriteString("- External systems triggered by a completed action — for example GitHub Actions after a successful push — are not agent-owned background tasks. Do not wait for them by default; report them as pending and finish the handoff.\n")- b.WriteString("- Concretely, after a push or a PR create, unless the explicit exception below applies: do NOT run `gh pr checks --watch`, `gh run watch`, or any sleep / retry loop that polls check status (`gh pr merge --auto` is fine — it returns immediately). Take at most ONE non-blocking status snapshot (e.g. `gh pr checks <pr>`) and deliver the evidence you already have: \"Local tests pass; CI running: <PR link>\". A PR whose CI is still in flight is a complete hand-off.\n")+ b.WriteString("- Concretely, after a push or a PR create, unless the explicit exception below applies: do NOT run `gh pr checks --watch`, `gh run watch`, or any sleep / retry loop that polls check status (`gh pr merge --auto` is fine — it returns immediately). Take at most ONE non-blocking status snapshot (e.g. `gh pr checks <pr>`) and deliver what you have: \"Local tests pass; CI running: <PR link>\". A PR whose CI is still in flight is a complete hand-off.\n")b.WriteString("- A repo's merge requirements — \"CI must be green before merge\", required reviews, branch protection — are GitHub's merge gate, NOT your delivery acceptance criteria, and do not license a wait.\n")b.WriteString("- The one exception: when the trigger comment or the issue's acceptance criteria explicitly ask you for the CI result, that result IS the deliverable — wait for it as ONE foreground blocking call (`gh pr checks <pr> --watch`) inside this same turn and report the outcome. Nothing else re-opens this door.\n\n")}@@ -262,7 +262,7 @@ func writeAvailableCommands(b *strings.Builder, ctx TaskContextForEnv) {b.WriteString("Prefer `--output json` for structured data. The default brief lists only the core agent loop and common issue create/update tasks; for everything else run `multica --help` or `multica <command> --help`.\n\n")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] [--before <ts> --before-id <uuid>] [--since <RFC3339>] [--full] --output json` — thread-aware comment reads. `--recent N` caps THREADS, not comments: every returned thread carries its root plus EVERY descendant with no per-thread cap, so on an issue with fewer than N root threads it hands you the entire history apart from the resolved threads it folds. Bound a wide read with `--roots-only` (roots plus `reply_count` / `last_activity_at`) and `--summary` (bodies clipped to a preview); bound a deep one with `--thread <id> --tail N`. Resolved threads come back folded on complete-thread reads (default list, `--recent`, `--thread` without `--tail`); `--full` expands them. Page with `--before`/`--before-id` (stderr labels: `Next reply cursor`, `Next thread cursor`); `--help` for full semantics.\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 status <id> <status>` — flip status (todo / in_progress / in_review / done / blocked / backlog / cancelled).\n")@@ -515,7 +515,7 @@ func writeWorkflowIssue(b *strings.Builder, ctx TaskContextForEnv) {b.WriteString("**Steps 1–6 — both modes**\n\n")fmt.Fprintf(b, "1. Run `multica issue get %s --output json` to understand the issue context\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. What to look for: `## Issue Metadata`.\n", ctx.IssueID)- fmt.Fprintf(b, "3. Catch up on the comment history — this is mandatory, not optional — in two bounded reads, never one bulk pull. Scan every thread cheaply with `multica issue comment list %s --roots-only --summary --output json`, then expand only the threads that matter with `multica issue comment list %s --thread <thread-id> --tail 30 --output json`. 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 — so always run the scan, even when the trigger looks self-contained. In Reply mode the per-turn user message names the thread to expand first; the scan is how you decide whether any OTHER thread is also relevant. Flag semantics and pagination: `## Available Commands`.\n", ctx.IssueID, ctx.IssueID)+ fmt.Fprintf(b, "3. Catch up on the comment history — this is mandatory, not optional — in two bounded reads, never one bulk pull: scan every thread cheaply with `multica issue comment list %s --roots-only --summary --output json`, then expand only the threads that matter with `multica issue comment list %s --thread <thread-id> --tail 30 --output json`. Earlier comments often carry context the issue body lacks. Skipping this step is the most common cause of agents acting on stale or incomplete instructions — so always run the scan, even when the trigger looks self-contained. In Reply mode the per-turn user message names the thread to expand first; the scan is how you decide whether any OTHER thread is also relevant.\n", ctx.IssueID, ctx.IssueID)b.WriteString("4. Complete the task within your Agent Identity boundaries (`## Instruction Precedence` lists the actions Agent Identity can forbid). 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, "5. **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)diff --git a/server/internal/service/builtin_skills/multica-squads/SKILL.md b/server/internal/service/builtin_skills/multica-squads/SKILL.mdindex 1353a7aee7..775d2937a8 100644--- a/server/internal/service/builtin_skills/multica-squads/SKILL.md+++ b/server/internal/service/builtin_skills/multica-squads/SKILL.md@@ -15,9 +15,12 @@ If debugging why a squad did or did not run, inspect first:multica issue get <issue-id> --output jsonmultica squad get <squad-id> --output jsonmultica squad member list <squad-id> --output json-multica issue comment list <issue-id> --recent 10 --output json+multica issue comment list <issue-id> --roots-only --summary --output json+multica issue comment list <issue-id> --thread <thread-id> --tail 30 --output json```+The two comment reads are a sequence: scan the roots first, then open the threads that look relevant — mention triggers, failure reasons, and user instructions usually live in the replies, which the roots scan never returns.+If the command shape is unclear, check help instead of guessing:```bashdiff --git a/server/internal/service/builtin_skills_test.go b/server/internal/service/builtin_skills_test.goindex fce9e71034..aa162b1fcd 100644--- a/server/internal/service/builtin_skills_test.go+++ b/server/internal/service/builtin_skills_test.go@@ -411,6 +411,13 @@ func TestSquadsSkillCoversLeaderRoutingContract(t *testing.T) {"mention://squad/<squad-id>","recording squad activity","references/squad-source-map.md",+ // The debugging quick-start must stay a bounded two-step read+ // (MUL-5442): a roots-only scan alone never returns reply bodies,+ // where mention triggers and failure reasons usually live — and it+ // must not regress to a --recent bulk pull either.+ "--roots-only --summary",+ "--thread <thread-id> --tail 30",+ "scan the roots first, then open the threads",}for _, want := range mustContain {if !strings.Contains(body, want) {