Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(cli): add autopilot deliveries so agents can read why a webhook was ignored (MUL-10265) (#11633)
Bohan Jiang411045068951
diff --git a/CLI_AND_DAEMON.md b/CLI_AND_DAEMON.mdindex 1e10a87970..f6c7391708 100644--- a/CLI_AND_DAEMON.md+++ b/CLI_AND_DAEMON.md@@ -1226,6 +1226,19 @@ multica autopilot runs <id>multica autopilot runs <id> --limit 50 --output json```+### Webhook Deliveries++```bash+multica autopilot deliveries <id>+multica autopilot deliveries <id> --limit 50 --output json+```++Every webhook request the autopilot received, newest first — including+`ignored` ones that created no run and so never appear in `runs`. The table+shows `REASON` (`reason_code`) and `ERROR`; `--output json` also carries+`payload_condition_failure`, the condition that rejected a `payload_filtered`+delivery and the payload value it saw.+### Schedule Triggers```bashdiff --git a/apps/docs/content/docs/autopilots.fr.mdx b/apps/docs/content/docs/autopilots.fr.mdxindex 843e02a946..5250c33a03 100644--- a/apps/docs/content/docs/autopilots.fr.mdx+++ b/apps/docs/content/docs/autopilots.fr.mdx@@ -189,6 +189,7 @@ La mise en pause manuelle arrête les planifications, les webhooks et **Exécutemultica autopilot get <autopilot-id> --output jsonmultica autopilot trigger <autopilot-id>multica autopilot runs <autopilot-id>+multica autopilot deliveries <autopilot-id>multica autopilot trigger-rotate-url <autopilot-id> <trigger-id>```diff --git a/apps/docs/content/docs/autopilots.ja.mdx b/apps/docs/content/docs/autopilots.ja.mdxindex 24e3a272b8..96dfa60ca4 100644--- a/apps/docs/content/docs/autopilots.ja.mdx+++ b/apps/docs/content/docs/autopilots.ja.mdx@@ -189,6 +189,7 @@ Multica は最近の実行が継続的に失敗していないか定期的に確multica autopilot get <autopilot-id> --output jsonmultica autopilot trigger <autopilot-id>multica autopilot runs <autopilot-id>+multica autopilot deliveries <autopilot-id>multica autopilot trigger-rotate-url <autopilot-id> <trigger-id>```diff --git a/apps/docs/content/docs/autopilots.ko.mdx b/apps/docs/content/docs/autopilots.ko.mdxindex 497351fe24..443913439f 100644--- a/apps/docs/content/docs/autopilots.ko.mdx+++ b/apps/docs/content/docs/autopilots.ko.mdx@@ -189,6 +189,7 @@ Multica는 최근 실행이 계속 실패하는지 정기적으로 확인합니multica autopilot get <autopilot-id> --output jsonmultica autopilot trigger <autopilot-id>multica autopilot runs <autopilot-id>+multica autopilot deliveries <autopilot-id>multica autopilot trigger-rotate-url <autopilot-id> <trigger-id>```diff --git a/apps/docs/content/docs/autopilots.mdx b/apps/docs/content/docs/autopilots.mdxindex a8c8feb800..c9ea481224 100644--- a/apps/docs/content/docs/autopilots.mdx+++ b/apps/docs/content/docs/autopilots.mdx@@ -189,6 +189,7 @@ Pausing manually stops schedules, webhooks, and **Run now**. Deletion is actuallmultica autopilot get <autopilot-id> --output jsonmultica autopilot trigger <autopilot-id>multica autopilot runs <autopilot-id>+multica autopilot deliveries <autopilot-id>multica autopilot trigger-rotate-url <autopilot-id> <trigger-id>```diff --git a/apps/docs/content/docs/autopilots.zh-Hant.mdx b/apps/docs/content/docs/autopilots.zh-Hant.mdxindex fcc3eda641..e15ff58c71 100644--- a/apps/docs/content/docs/autopilots.zh-Hant.mdx+++ b/apps/docs/content/docs/autopilots.zh-Hant.mdx@@ -186,6 +186,7 @@ Multica 定期檢查近期執行是否持續失敗:過去 7 天內已完成或multica autopilot get <autopilot-id> --output jsonmultica autopilot trigger <autopilot-id>multica autopilot runs <autopilot-id>+multica autopilot deliveries <autopilot-id>multica autopilot trigger-rotate-url <autopilot-id> <trigger-id>```diff --git a/apps/docs/content/docs/autopilots.zh.mdx b/apps/docs/content/docs/autopilots.zh.mdxindex 46c8bd61b9..0846bcc54d 100644--- a/apps/docs/content/docs/autopilots.zh.mdx+++ b/apps/docs/content/docs/autopilots.zh.mdx@@ -189,6 +189,7 @@ Multica 定期检查近期运行是否持续失败:过去 7 天内已完成或multica autopilot get <autopilot-id> --output jsonmultica autopilot trigger <autopilot-id>multica autopilot runs <autopilot-id>+multica autopilot deliveries <autopilot-id>multica autopilot trigger-rotate-url <autopilot-id> <trigger-id>```diff --git a/server/cmd/multica/cmd_autopilot.go b/server/cmd/multica/cmd_autopilot.goindex e51b13179b..199277f29c 100644--- a/server/cmd/multica/cmd_autopilot.go+++ b/server/cmd/multica/cmd_autopilot.go@@ -70,6 +70,13 @@ var autopilotRunsCmd = &cobra.Command{RunE: runAutopilotRuns,}+var autopilotDeliveriesCmd = &cobra.Command{+ Use: "deliveries <id>",+ Short: "List webhook deliveries for an autopilot, including ones that created no run",+ Args: exactArgs(1),+ RunE: runAutopilotDeliveries,+}+var autopilotTriggerAddCmd = &cobra.Command{Use: "trigger-add <autopilot-id>",Short: "Add a schedule or webhook trigger to an autopilot",@@ -113,6 +120,7 @@ func init() {autopilotCmd.AddCommand(autopilotDeleteCmd)autopilotCmd.AddCommand(autopilotTriggerCmd)autopilotCmd.AddCommand(autopilotRunsCmd)+ autopilotCmd.AddCommand(autopilotDeliveriesCmd)autopilotCmd.AddCommand(autopilotTriggerAddCmd)autopilotCmd.AddCommand(autopilotTriggerListCmd)autopilotCmd.AddCommand(autopilotTriggerUpdateCmd)@@ -165,6 +173,11 @@ func init() {autopilotRunsCmd.Flags().Int("offset", 0, "Pagination offset")autopilotRunsCmd.Flags().String("output", "table", "Output format: table or json")+ // deliveries+ autopilotDeliveriesCmd.Flags().Int("limit", 20, "Max number of deliveries to return (server caps at 100)")+ autopilotDeliveriesCmd.Flags().Int("offset", 0, "Pagination offset")+ autopilotDeliveriesCmd.Flags().String("output", "table", "Output format: table or json")+// trigger-add — supports schedule and webhookautopilotTriggerAddCmd.Flags().String("kind", "schedule", "Trigger kind: schedule or webhook")autopilotTriggerAddCmd.Flags().String("cron", "", "Cron expression (required for --kind schedule)")@@ -728,6 +741,64 @@ func runAutopilotRuns(cmd *cobra.Command, args []string) error {return nil}+func runAutopilotDeliveries(cmd *cobra.Command, args []string) error {+ client, err := newAPIClient(cmd)+ if err != nil {+ return err+ }++ ctx, cancel := cli.APIContext(context.Background())+ defer cancel()++ autopilotRef, err := resolveAutopilotID(ctx, client, args[0])+ if err != nil {+ return fmt.Errorf("resolve autopilot: %w", err)+ }++ params := url.Values{}+ if v, _ := cmd.Flags().GetInt("limit"); v > 0 {+ params.Set("limit", fmt.Sprintf("%d", v))+ }+ if v, _ := cmd.Flags().GetInt("offset"); v > 0 {+ params.Set("offset", fmt.Sprintf("%d", v))+ }+ path := "/api/autopilots/" + autopilotRef.ID + "/deliveries"+ if len(params) > 0 {+ path += "?" + params.Encode()+ }++ var resp struct {+ Deliveries []map[string]any `json:"deliveries"`+ Total int `json:"total"`+ }+ if err := client.GetJSON(ctx, path, &resp); err != nil {+ return fmt.Errorf("list deliveries: %w", err)+ }++ output, _ := cmd.Flags().GetString("output")+ if output == "json" {+ return cli.PrintJSON(os.Stdout, resp)+ }++ // An ignored delivery has no run, so REASON / ERROR are the only place+ // the table says why. payload_condition_failure is JSON-only.+ headers := []string{"ID", "EVENT", "STATUS", "REASON", "ERROR", "RUN", "RECEIVED_AT"}+ rows := make([][]string, 0, len(resp.Deliveries))+ for _, d := range resp.Deliveries {+ rows = append(rows, []string{+ strVal(d, "id"),+ strVal(d, "event"),+ strVal(d, "status"),+ strVal(d, "reason_code"),+ strVal(d, "error"),+ strVal(d, "autopilot_run_id"),+ strVal(d, "received_at"),+ })+ }+ cli.PrintTable(os.Stdout, headers, rows)+ return nil+}+func runAutopilotTriggerList(cmd *cobra.Command, args []string) error {client, err := newAPIClient(cmd)if err != nil {diff --git a/server/cmd/multica/cmd_autopilot_test.go b/server/cmd/multica/cmd_autopilot_test.goindex f1fb1c34fd..6a851a8606 100644--- a/server/cmd/multica/cmd_autopilot_test.go+++ b/server/cmd/multica/cmd_autopilot_test.go@@ -1501,3 +1501,81 @@ func TestFormatAutopilotAssignee(t *testing.T) {})}}++func newAutopilotDeliveriesTestCmd(output string) *cobra.Command {+ cmd := &cobra.Command{Use: "deliveries"}+ cmd.Flags().Int("limit", 20, "")+ cmd.Flags().Int("offset", 0, "")+ cmd.Flags().String("output", output, "")+ return cmd+}++// An ignored delivery creates no run, so `runs` cannot explain it; the+// deliveries command is the only CLI surface for reason_code / error.+func TestRunAutopilotDeliveriesShowsIgnoredReason(t *testing.T) {+ const autopilotID = "11111111-1111-1111-1111-111111111111"++ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ if r.Method != http.MethodGet || r.URL.Path != "/api/autopilots/"+autopilotID+"/deliveries" {+ t.Fatalf("request = %s %s, want GET deliveries", r.Method, r.URL.Path)+ }+ if got := r.URL.Query().Get("limit"); got != "20" {+ t.Errorf("limit = %q, want 20", got)+ }+ _ = json.NewEncoder(w).Encode(map[string]any{+ "deliveries": []map[string]any{+ {+ "id": "d-1",+ "event": "pull_request",+ "status": "ignored",+ "reason_code": "payload_filtered",+ "error": "payload_filtered: pull_request.draft",+ "payload_condition_failure": map[string]any{+ "condition": map[string]any{"path": "pull_request.draft", "op": "equals", "value": false},+ "actual_values": []string{"true"},+ },+ "received_at": "2026-11-26T01:00:00Z",+ },+ {+ "id": "d-2",+ "event": "push",+ "status": "ignored",+ "error": "autopilot_paused",+ "received_at": "2026-11-26T00:00:00Z",+ },+ },+ "total": 2,+ })+ }))+ defer srv.Close()++ setCLITestServerEnv(t, srv.URL)++ out, err := captureStdout(t, func() error {+ return runAutopilotDeliveries(newAutopilotDeliveriesTestCmd("table"), []string{autopilotID})+ })+ if err != nil {+ t.Fatalf("runAutopilotDeliveries: %v", err)+ }+ for _, want := range []string{"REASON", "ERROR", "ignored", "payload_filtered", "pull_request.draft", "autopilot_paused"} {+ if !strings.Contains(out, want) {+ t.Fatalf("table output missing %q:\n%s", want, out)+ }+ }++ out, err = captureStdout(t, func() error {+ return runAutopilotDeliveries(newAutopilotDeliveriesTestCmd("json"), []string{autopilotID})+ })+ if err != nil {+ t.Fatalf("runAutopilotDeliveries json: %v", err)+ }+ var got struct {+ Deliveries []map[string]any `json:"deliveries"`+ }+ if err := json.Unmarshal([]byte(out), &got); err != nil {+ t.Fatalf("json output invalid: %v\n%s", err, out)+ }+ if len(got.Deliveries) != 2 || got.Deliveries[0]["payload_condition_failure"] == nil {+ t.Fatalf("json output dropped payload_condition_failure:\n%s", out)+ }+}diff --git a/server/internal/handler/autopilot.go b/server/internal/handler/autopilot.goindex a9c90543e3..0fed992a02 100644--- a/server/internal/handler/autopilot.go+++ b/server/internal/handler/autopilot.go@@ -2376,7 +2376,12 @@ func (h *Handler) ListAutopilotRuns(w http.ResponseWriter, r *http.Request) {// full payload from GetAutopilotRun.resp[i] = runToResponseSlim(run)}- writeJSON(w, http.StatusOK, map[string]any{"runs": resp, "total": len(resp)})+ total, err := h.Queries.CountAutopilotRuns(r.Context(), autopilot.ID)+ if err != nil {+ writeError(w, http.StatusInternalServerError, "failed to count runs")+ return+ }+ writeJSON(w, http.StatusOK, map[string]any{"runs": resp, "total": total})}// GetAutopilotRun returns a single run including its full trigger_payload.diff --git a/server/internal/handler/webhook_delivery.go b/server/internal/handler/webhook_delivery.goindex 82856e080f..8e7b3a90a2 100644--- a/server/internal/handler/webhook_delivery.go+++ b/server/internal/handler/webhook_delivery.go@@ -202,7 +202,16 @@ func (h *Handler) ListAutopilotDeliveries(w http.ResponseWriter, r *http.Requestfor i, row := range rows {resp[i] = slimDeliveryToResponse(row)}- writeJSON(w, http.StatusOK, map[string]any{"deliveries": resp, "total": len(resp)})+ total, err := h.Queries.CountWebhookDeliveriesByAutopilot(r.Context(), db.CountWebhookDeliveriesByAutopilotParams{+ AutopilotID: autopilot.ID,+ WorkspaceID: autopilot.WorkspaceID,+ })+ if err != nil {+ slog.Error("count deliveries failed", "error", err, "autopilot_id", autopilotID)+ writeError(w, http.StatusInternalServerError, "failed to list deliveries")+ return+ }+ writeJSON(w, http.StatusOK, map[string]any{"deliveries": resp, "total": total})}// GetAutopilotDelivery returns one delivery in full, including the raw bodydiff --git a/server/internal/handler/webhook_delivery_test.go b/server/internal/handler/webhook_delivery_test.goindex b528daa313..924ee310ac 100644--- a/server/internal/handler/webhook_delivery_test.go+++ b/server/internal/handler/webhook_delivery_test.go@@ -1164,3 +1164,52 @@ func TestSetSigningSecretParams_NullableWrite(t *testing.T) {t.Fatalf("sqlc NULL write: %v", err)}}++// total counts every row for the autopilot, not just the returned page, so a+// paging client can tell when it has seen everything.+func TestListAutopilotDeliveriesAndRuns_TotalCountsAllRows(t *testing.T) {+ agentID := createWebhookTestAgent(t, "DeliveryTotal Agent")+ apID := createWebhookTestAutopilot(t, agentID, "active", "run_only")+ trig := createWebhookTriggerViaHandler(t, apID)++ for _, key := range []string{"total-1", "total-2"} {+ w := postWebhook(t, *trig.WebhookToken, map[string]any{"key": key}, map[string]string{"Idempotency-Key": key})+ if w.Code != http.StatusOK {+ t.Fatalf("post webhook %s: %d body=%s", key, w.Code, w.Body.String())+ }+ }++ for _, tc := range []struct {+ name string+ list func(http.ResponseWriter, *http.Request)+ key string+ }{+ {"deliveries", testHandler.ListAutopilotDeliveries, "deliveries"},+ {"runs", testHandler.ListAutopilotRuns, "runs"},+ } {+ t.Run(tc.name, func(t *testing.T) {+ w := httptest.NewRecorder()+ req := newRequest("GET", "/api/autopilots/"+apID+"/"+tc.name+"?limit=1", nil)+ req = withURLParam(req, "id", apID)+ tc.list(w, req)+ if w.Code != http.StatusOK {+ t.Fatalf("list %s: %d body=%s", tc.name, w.Code, w.Body.String())+ }+ var resp map[string]json.RawMessage+ if err := json.Unmarshal(w.Body.Bytes(), &resp); err != nil {+ t.Fatalf("decode: %v", err)+ }+ var rows []map[string]any+ var total int+ if err := json.Unmarshal(resp[tc.key], &rows); err != nil {+ t.Fatalf("decode rows: %v", err)+ }+ if err := json.Unmarshal(resp["total"], &total); err != nil {+ t.Fatalf("decode total: %v", err)+ }+ if len(rows) != 1 || total != 2 {+ t.Fatalf("got %d rows, total %d; want 1 row, total 2", len(rows), total)+ }+ })+ }+}diff --git a/server/internal/service/builtin_skills/multica-platform/references/autopilots.md b/server/internal/service/builtin_skills/multica-platform/references/autopilots.mdindex d76222487c..4a34a5fbe5 100644--- a/server/internal/service/builtin_skills/multica-platform/references/autopilots.md+++ b/server/internal/service/builtin_skills/multica-platform/references/autopilots.md@@ -33,6 +33,7 @@ multica autopilot create --title "<title>" --description "<task prompt>" --squadmultica autopilot update <autopilot-id> --squad <squad-name-or-id> --output jsonmultica autopilot update <autopilot-id> --status active|paused --output jsonmultica autopilot runs <autopilot-id> --output json+multica autopilot deliveries <autopilot-id> --output jsonmultica autopilot trigger-add <autopilot-id> --kind schedule --cron "0 9 * * *" --timezone Asia/Shanghai --output jsonmultica autopilot trigger-add <autopilot-id> --kind webhook --label "ci" --output jsonmultica autopilot trigger-add <autopilot-id> --kind webhook --event-filters-file ./filters.json --output json@@ -109,7 +110,7 @@ material into comments, logs, docs, or PRs.2. `multica autopilot runs <id> --output json` — run status and failure reason.3. If assigned to a squad, inspect the squad: `multica squad get <squad-id> --output json`; execution goes to the leader.4. Inspect the target agent/runtime: `multica agent get <agent-id> --output json` and `multica runtime list --output json`.-5. For webhooks, inspect delivery status: `queued` means the worker has not completed dispatch; `failed` carries the worker error. A provider retry with the same `X-GitHub-Delivery` / `Idempotency-Key` reuses the original delivery.+5. For webhooks, inspect deliveries with `multica autopilot deliveries <id> --output json`: `queued` means the worker has not completed dispatch; `failed` carries the worker error. A provider retry with the same `X-GitHub-Delivery` / `Idempotency-Key` reuses the original delivery.An `ignored` delivery created no run, so `runs` shows nothing for it. `trigger_disabled`, `autopilot_paused`, and `autopilot_archived` are recorded in its `error`; `quota_exceeded`, `event_filtered`, and `payload_filtered` in its `reason_code`. `event_filtered` means no row matched the event or action, and `payload_filtered` means a row matched but one of its `conditions` failed — `payload_condition_failure` names that condition and the payload value it saw.6. For `create_issue`, inspect the created issue if the run records one.diff --git a/server/pkg/db/generated/autopilot.sql.go b/server/pkg/db/generated/autopilot.sql.goindex b1014eac6e..75104600c3 100644--- a/server/pkg/db/generated/autopilot.sql.go+++ b/server/pkg/db/generated/autopilot.sql.go@@ -92,6 +92,18 @@ func (q *Queries) ArchiveAutopilot(ctx context.Context, id pgtype.UUID) error {return err}+const countAutopilotRuns = `-- name: CountAutopilotRuns :one+SELECT count(*) FROM autopilot_run+WHERE autopilot_id = $1+`++func (q *Queries) CountAutopilotRuns(ctx context.Context, autopilotID pgtype.UUID) (int64, error) {+ row := q.db.QueryRow(ctx, countAutopilotRuns, autopilotID)+ var count int64+ err := row.Scan(&count)+ return count, err+}+const createAutopilot = `-- name: CreateAutopilot :oneINSERT INTO autopilot (workspace_id, title, description, assignee_type, assignee_id,diff --git a/server/pkg/db/generated/webhook_delivery.sql.go b/server/pkg/db/generated/webhook_delivery.sql.goindex eaae099d3a..9e9001d731 100644--- a/server/pkg/db/generated/webhook_delivery.sql.go+++ b/server/pkg/db/generated/webhook_delivery.sql.go@@ -240,6 +240,27 @@ func (q *Queries) CompleteClaimedWebhookDelivery(ctx context.Context, arg Complereturn i, err}+const countWebhookDeliveriesByAutopilot = `-- name: CountWebhookDeliveriesByAutopilot :one+SELECT count(*)+FROM webhook_delivery d+JOIN autopilot a ON a.id = d.autopilot_id+WHERE d.autopilot_id = $1+ AND a.workspace_id = $2+`++type CountWebhookDeliveriesByAutopilotParams struct {+ AutopilotID pgtype.UUID `json:"autopilot_id"`+ WorkspaceID pgtype.UUID `json:"workspace_id"`+}++// Workspace-scoped the same way as ListWebhookDeliveriesByAutopilot.+func (q *Queries) CountWebhookDeliveriesByAutopilot(ctx context.Context, arg CountWebhookDeliveriesByAutopilotParams) (int64, error) {+ row := q.db.QueryRow(ctx, countWebhookDeliveriesByAutopilot, arg.AutopilotID, arg.WorkspaceID)+ var count int64+ err := row.Scan(&count)+ return count, err+}+const createWebhookDelivery = `-- name: CreateWebhookDelivery :oneINSERT INTO webhook_delivery (diff --git a/server/pkg/db/queries/autopilot.sql b/server/pkg/db/queries/autopilot.sqlindex b4f6f81ed8..76490f1f54 100644--- a/server/pkg/db/queries/autopilot.sql+++ b/server/pkg/db/queries/autopilot.sql@@ -474,6 +474,10 @@ WHERE autopilot_id = $1ORDER BY created_at DESCLIMIT $2 OFFSET $3;+-- name: CountAutopilotRuns :one+SELECT count(*) FROM autopilot_run+WHERE autopilot_id = $1;+-- name: UpdateAutopilotRunIssueCreated :oneUPDATE autopilot_runSET status = 'issue_created', issue_id = $2diff --git a/server/pkg/db/queries/webhook_delivery.sql b/server/pkg/db/queries/webhook_delivery.sqlindex 12d5504661..d20e3d6f84 100644--- a/server/pkg/db/queries/webhook_delivery.sql+++ b/server/pkg/db/queries/webhook_delivery.sql@@ -183,3 +183,11 @@ WHERE d.autopilot_id = $1AND a.workspace_id = $2ORDER BY d.created_at DESCLIMIT $3 OFFSET $4;++-- name: CountWebhookDeliveriesByAutopilot :one+-- Workspace-scoped the same way as ListWebhookDeliveriesByAutopilot.+SELECT count(*)+FROM webhook_delivery d+JOIN autopilot a ON a.id = d.autopilot_id+WHERE d.autopilot_id = $1+ AND a.workspace_id = $2;