coder / coder/code-marketplace

Platform selection bug: darwin-arm64 extensions served instead of linux-x64 due to alphabetical sorting

Open
#122 1 comment 0 reactions 1 assignee Claimed by @code-asher View on GitHub
bug
Dominant language
Go
Stars
370
Forks
46
PR merge metrics
No merged PRs in 30d

Description

## Bug Description

When using the `/api/vscode/{publisher}/{extension}/latest` endpoint (introduced in v2.4.0), the marketplace incorrectly serves `darwin-arm64` extension variants instead of the appropriate platform-specific versions (e.g., `linux-x64`) due to alphabetical sorting of platform names.

## Root Cause

The issue is in the `ByVersion.Less()` method in `/storage/storage.go`:

```go
if vs[i].Version == vs[j].Version {
return vs[i].TargetPlatform < vs[j].TargetPlatform
}
```

When multiple platform variants exist for the same semantic version (e.g., `2.36.4@darwin-arm64`, `2.36.4@linux-x64`), they are sorted alphabetically by platform string. Since `"darwin-arm64" < "linux-x64"` alphabetically, darwin-arm64 versions are always selected first when using `IncludeLatestVersionOnly`.

## Impact

- Extensions fail to install in VS Code/code-server running on Linux platforms
- Affects all extensions that have multiple platform-specific variants
- Introduced in v2.4.0 when the new `/latest` endpoint started being used by VS Code

## Example Logs

**Expected behavior (linux-x64 environment should get linux-x64 variant):**
```
ComputeTargetPlatform: linux-x64
2025-09-20 09:42:42.565 [debu] GET /files/hashicorp/terraform/2.36.4@linux-x64/hashicorp.terraform-2.36.4@linux-x64.vsix
```

**Actual behavior (linux-x64 environment incorrectly gets darwin-arm64 variant):**
```
ComputeTargetPlatform: linux-x64
2025-09-20 09:42:40.247 [debu] GET /files/hashicorp/terraform/2.36.4@darwin-arm64/extension/package.json
```

## Environment

- code-marketplace version: v2.4.0
- VS Code/code-server: 1.104.0
- Platform: Linux x64 containers
- Extensions affected: Any extension with multiple platform variants (e.g., HashiCorp Terraform)

## Proposed Solutions

1. **Platform-aware filtering**: Filter versions by the requesting client's target platform before sorting
2. **Universal version priority**: Prioritize universal platform versions when available
3. **Platform preference order**: Define a logical platform ordering instead of alphabetical (e.g., prefer common platforms like linux-x64 over darwin-arm64)
4. **Client platform detection**: Extract target platform from request headers or query parameters

## Reproduction Steps

1. Set up code-marketplace v2.4.0
2. Upload an extension with multiple platform variants (e.g., versions for both `linux-x64` and `darwin-arm64`)
3. Make a request to `/api/vscode/{publisher}/{extension}/latest` from a linux-x64 environment
4. Observe that darwin-arm64 variant is returned instead of linux-x64

## Workaround

Temporarily downgrade to v2.3.1 or modify the version sorting logic to prioritize the appropriate platform for your environment.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.