# Stable sort groups check

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

Check claimed equal-key groups for exact key order, membership, and stable source order.

**Use when you need to: check stable equal key groups · validate grouped stable sort certificate · check tie group source order.**

## Decide before calling

Read the [versioned contract](/v1/tools/stable-sort-groups-check/versions/1.0.0) and the supported scope below. Reuse `stable-sort-groups-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-groups-check@1.0.0` for check stable equal key groups. 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 equal key groups
- validate grouped stable sort certificate
- check tie group source order
- detect first grouping discrepancy
- validate sorted equivalence classes
- check grouped sorting claim

## Not supported

- create groups from source data
- merge approximately equal keys

## Behavior

- Keys are canonical base-10 integer strings; negative zero is rejected, and null follows every integer.
- Each group contains all source indices for one key in ascending source order; groups follow key order, implementing ECMA-262 stability.
- Groups are flattened in group/member order and compared to the unique expected grouping; the first path mismatch is returned without repair.
- Every verdict names ECMA-262-2026-draft-Array.prototype.sort.

## Input

- `source_keys` (array of string or null, required): min items 1; max items 4096; each max length 40; each pattern `^(0|-?[1-9][0-9]*)$`
- `claimed_groups` (array of array of integer, required): min items 1; max items 4096; each min items 1; each max items 4096; each each min 0; each each max 4095

## 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 group members: 4096

## Example

Request input:

```json
{
  "source_keys": [
    "2",
    "1",
    "1"
  ],
  "claimed_groups": [
    [
      1,
      2
    ],
    [
      0
    ]
  ]
}
```

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-groups-check",
  "version": "1.0.0",
  "input": {
    "source_keys": [
      "2",
      "1",
      "1"
    ],
    "claimed_groups": [
      [
        1,
        2
      ],
      [
        0
      ]
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/stable-sort-groups-check/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"source_keys":["2","1","1"],"claimed_groups":[[1,2],[0]]}'
```

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

### CLI

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

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

## Related tools

- [Stable sort result check](/tools/stable-sort-result-check): Check that a claimed record result is the exact ascending stable sort of the supplied source records.
- [Stable sort indices check](/tools/stable-sort-indices-check): Check that claimed source indices are the exact ascending stable order for supplied integer keys.
- [Foreign key claim check](/tools/foreign-key-claim-check): Check an exact referential-inclusion claim and first violation under an explicit composite-null policy.
- [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.
