# Stable sort result check

`stable-sort-result-check` · version 1.0.0 · Numbers & math · free, no key needed

Check that a claimed record result is the exact ascending stable sort of the supplied source records.

**Use when you need to: check stable sorted result · validate claimed stable sort output · compare records with stable sort.**

## Decide before calling

Read the [versioned contract](/v1/tools/stable-sort-result-check/versions/1.0.0) and the supported scope below. Reuse `stable-sort-result-check@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `stable-sort-result-check@1.0.0` for check stable sorted result. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- check stable sorted result
- validate claimed stable sort output
- compare records with stable sort
- detect first stable sorting discrepancy
- check equal key record order
- verify exact sorted record claim

## Not supported

- sort records for the caller
- compare floating point or locale text keys

## Behavior

- Keys are canonical base-10 integer strings; negative zero is rejected, and null follows every integer.
- Equal keys retain source index order, as required by ECMA-262 Array.prototype.sort stability; ids are unique and records must match exactly.
- The first mismatch is reported at the lowest claimed-result index; the claim is never repaired.
- Every verdict names ECMA-262-2026-draft-Array.prototype.sort.

## Input

- `source` (array of object, required): min items 1; max items 4096
- `claimed_result` (array of object, required): min items 1; max items 4096

## Output

- `valid` (boolean, required)
- `reason` (string, optional): min length 1; max length 80
- `discrepancy` (object, optional)
- `reference_version` (constant "ECMA-262-2026-draft-Array.prototype.sort", required)

## Limits

- max items: 4096
- max key chars: 40
- max id chars: 80

## Example

Request input:

```json
{
  "source": [
    {
      "id": "a",
      "key": "2"
    },
    {
      "id": "b",
      "key": "1"
    }
  ],
  "claimed_result": [
    {
      "id": "b",
      "key": "1"
    },
    {
      "id": "a",
      "key": "2"
    }
  ]
}
```

Response:

```json
{
  "result": {
    "valid": true,
    "reference_version": "ECMA-262-2026-draft-Array.prototype.sort"
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "stable-sort-result-check",
  "version": "1.0.0",
  "input": {
    "source": [
      {
        "id": "a",
        "key": "2"
      },
      {
        "id": "b",
        "key": "1"
      }
    ],
    "claimed_result": [
      {
        "id": "b",
        "key": "1"
      },
      {
        "id": "a",
        "key": "2"
      }
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/stable-sort-result-check/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"source":[{"id":"a","key":"2"},{"id":"b","key":"1"}],"claimed_result":[{"id":"b","key":"1"},{"id":"a","key":"2"}]}'
```

The machine-readable contract is at [/v1/tools/stable-sort-result-check/versions/1.0.0](/v1/tools/stable-sort-result-check/versions/1.0.0).

### CLI

```sh
node cli.mjs run stable-sort-result-check 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Stable sort groups check](/tools/stable-sort-groups-check): Check claimed equal-key groups for exact key order, membership, and stable source order.
- [Stable sort indices check](/tools/stable-sort-indices-check): Check that claimed source indices are the exact ascending stable order for supplied integer keys.
- [Join inner result check](/tools/join-inner-result-check): Check a claimed ordered inner join index result and report its first discrepancy.
- [Join left result check](/tools/join-left-result-check): Check a claimed ordered left join index result and report its first discrepancy.
- [Join semi result check](/tools/join-semi-result-check): Check a claimed ordered semi-join index result and report its first discrepancy.
- [Filter result check](/tools/filter-result-check): Checks an exact claimed decimal filter result with source-order witnesses.
