multica-ai/multica · error

archive agent: %w

Error message

archive agent: %w

What it means

Wrapped error returned when `multica agent archive <id>` fails to POST to `/api/agents/{id}/archive`. Archiving is a soft-delete/lifecycle transition; the wrapped cause is typically 404 (unknown agent), 409/400 (agent already archived or in a state that cannot be archived), auth failure, or a connectivity error.

Source

Thrown at server/cmd/multica/cmd_agent.go:836

		return cli.PrintJSON(os.Stdout, result)
	}

	fmt.Printf("Agent updated: %s (%s)\n", strVal(result, "name"), strVal(result, "id"))
	return nil
}

func runAgentArchive(cmd *cobra.Command, args []string) error {
	client, err := newAPIClient(cmd)
	if err != nil {
		return err
	}

	ctx, cancel := cli.APIContext(context.Background())
	defer cancel()

	var result map[string]any
	if err := client.PostJSON(ctx, "/api/agents/"+args[0]+"/archive", nil, &result); err != nil {
		return fmt.Errorf("archive agent: %w", err)
	}

	output, _ := cmd.Flags().GetString("output")
	if output == "json" {
		return cli.PrintJSON(os.Stdout, result)
	}

	fmt.Printf("Agent archived: %s (%s)\n", strVal(result, "name"), strVal(result, "id"))
	return nil
}

func runAgentRestore(cmd *cobra.Command, args []string) error {
	client, err := newAPIClient(cmd)
	if err != nil {
		return err
	}

	ctx, cancel := cli.APIContext(context.Background())

View on GitHub (pinned to 2c0912b6ec)

Solutions

  1. Verify the agent id and its current status: `multica agent get <id>`
  2. If already archived, treat the outcome as success in scripts (idempotency check) rather than retrying
  3. Fix connectivity/auth if the wrapped error is a connection or 401/403 error
  4. Re-run once the state or environment is corrected

Example fix

# before
multica agent archive agt_1   # already archived
# Error: archive agent: 400: agent already archived

# after
multica agent get agt_1        # confirm status=archived; nothing to do
Defensive patterns

Strategy: try-catch

Validate before calling

status=$(multica agent get "$AGENT_ID" --output json | jq -r .status)
[ "$status" = "archived" ] || multica agent archive "$AGENT_ID"

Try / catch

if err := runAgentArchive(cmd, args); err != nil {
	if strings.Contains(err.Error(), "already archived") { return nil } // idempotent scripts
	return fmt.Errorf("archive agent: %w", err)
}

Prevention

When it happens

Trigger: `multica agent archive <id>` on a deleted or mistyped id, archiving an already-archived agent, or when the server/auth is unreachable.

Common situations: Script archives agents in a loop and one id was already archived in a prior run; id copied with a trailing space; token expired mid-script.

Related errors


AI-assisted analysis of multica-ai/multica@2c0912b6ec (2026-08-15). Data as JSON: /api/errors/438d9662450f2e69. Report an issue: GitHub.