Two robot data exports can contain the same records and use the same stable sort while producing different orders within a tied group. Stability preserves an existing relative order. It does not invent an ordering criterion for records that have equal keys.

That distinction matters when a report needs reproducible presentation across merged inputs. A stable result can faithfully preserve an input order that was itself different on each run.

The following records and permutations are original examples. They do not describe a live robot scheduler, event chronology, or executed sorting-library result.

Define the primary comparison

Give each record a unique identifier and an integer group key. For this example, smaller group keys appear first. The group key is a display category, not a physical urgency or a processing-time objective.

Input sequence L1 is:

A with key 2, B with key 1, C with key 2, D with key 1, and E with key 2.

The input positions of the key-one records are B before D. The key-two records appear as A before C before E.

A stable ascending sort using only the group key therefore produces [B, D, A, C, E]. It orders the two key groups and retains relative input order within each group.

Python's sorting guide defines that stability property. NumPy's sort reference separately makes stability an explicit option for its array operation and documents when order preservation is not guaranteed. Those are API contracts; the record ledger is independently constructed.

Change the input permutation

Now supply the identical five records in another sequence L2: [E, D, C, B, A]. The group keys attached to each record remain unchanged.

The key-one input order is now D before B. The key-two input order is E before C before A. A stable primary-key sort produces [D, B, E, C, A].

Both outputs correctly satisfy ascending group order. Both correctly preserve their own input tie order. They differ because the input permutations differ.

It would therefore be inaccurate to call one output unstable simply because it differs from the other export. Testing stability requires comparing each tied group's output order with that same run's input order.

Conversely, an algorithm that happens to preserve one small tied example has not established a general stability guarantee. The operation's documented comparison and stability contract remain relevant.

Add a declared secondary key

Suppose the report instead requires identifiers in alphabetic order within each group, using the simple A-through-E identifiers in this example. Define the complete comparison key as the pair (group, identifier).

Both L1 and L2 then produce [B, D, A, C, E]. The identifier decides between B and D, and between A, C, and E, irrespective of their incoming positions.

This consistency comes from the additional comparison rule. Under this particular dataset, no two complete keys are equal because identifiers are unique. Stability no longer determines the relative order of any pair.

If identifiers were repeated or the complete keys otherwise tied, stability would again retain their incoming relative order. An explicit secondary key resolves only the distinctions it actually contains.

Choosing the identifier also assigns a meaning. Alphabetic record order may be suitable for presentation, but it does not establish acquisition order, causal order, or which task a robot should execute first.

Build a multi-key order through stable passes

The same pair ordering can be understood as two stable passes. First sort all records by the secondary identifier. Either input becomes [A, B, C, D, E] for these unique identifiers.

Then perform a stable sort by the primary group key. The key-one group retains B before D, and the key-two group retains A before C before E. The final list is [B, D, A, C, E].

The less significant key is handled first because the final stable primary pass groups records without destroying the secondary ordering already present within equal-primary groups.

Reversing the pass order changes the operation. Sorting by group first and then globally by identifier produces [A, B, C, D, E], which interleaves the two groups. It no longer satisfies group-first ordering.

These lists are worked logical outcomes, not outputs from an executed program. They illustrate why the pass order is part of the definition of a multi-pass stable sort.

Descending order has its own tie behavior

For L1, a stable descending sort by group alone puts the key-two group first while preserving its original order. The result is [A, C, E, B, D].

Reversing the entire ascending output [B, D, A, C, E] instead gives [E, C, A, D, B]. That reverses the order inside every tied group as well as reversing group order.

The two operations therefore differ even though both show key two before key one. A descending comparison and reversing an already sorted list are separate procedures when equal keys matter.

Python's documented reverse sorting preserves stability. An interface in another library needs its own contract rather than an assumption based on a similarly named option.

Retain the actual comparison domain

The examples use integer group keys and a simple fixed identifier order. Missing keys, locale-dependent text order, and special numerical values can change how equal or ordered comparisons are defined.

NumPy's documentation also notes that structured-array field ordering can use unspecified fields to break ties. That is a broader comparison than the group-only key explicitly assumed in the first ledger.

An input position can itself be recorded as a secondary key when preserving one captured order is the goal. That preserves the captured sequence; it does not make a newly merged sequence share the same positions automatically.

For robot data reports, retain the input provenance, complete key definition, direction of each key, and tie rule. Stability then has a precise role: it preserves an order already present among records that the chosen comparison still regards as equal.

Sources checked October 23, 2026

Python 3.14, Sorting Techniques, Sort Stability and Complex Sorts and Odds and Ends:

https://docs.python.org/3.14/howto/sorting.html

NumPy 2.3, numpy.sort:

https://numpy.org/doc/2.3/reference/generated/numpy.sort.html

All record identifiers, keys, and sequence comparisons are original hypothetical examples. No sorting library was executed.

Illustration note: A generic robot-and-computer scene is a concept illustration. It does not show these records, a live queue, or verified event ordering.