CodexAIModelCatalog: Fix sort comparator for app hang - #813
Conversation
Audit disposition — fix direction is correct; rebase and prove the comparator contract (2026-08-14)Making Before merge, add property-style tests for irreflexivity, antisymmetry, and transitivity across generated option triples, plus a deterministic final tie-breaker when localized display names compare equal. Resolve the current integration/CI failure and rerun on the exact final head. I would retain this fix rather than close it. |
Deep-review assessment — 2026-08-14Disposition: logically correct fix; add comparator-law coverage and rerun current CI. Making Please add property/table tests for irreflexivity, antisymmetry, and transitivity across default/non-default, same/different base, effort ranks, and equal localized display names. Add a stable final tie-break such as normalized ID when localized comparison is |
This PR addresses an app hang issue (REPOPROMPT-J0) caused by a Strict Weak Ordering violation in the sort comparator within
CodexAIModelCatalog.swift.Previously, the
options.sortedclosure inCodexAIModelCatalog.swiftchecked forleftBase == rightBasebefore evaluatinglhs.isDefault != rhs.isDefault. This ordering could create a sorting cycle (A < B, B < C, C < A) under specific conditions: when two items shared the same base but differed in theirisDefaultflag, and a third item had a different base. This cycle caused Swift'ssortfunction to enter a pathological state, leading to excessive reallocations and a main thread app hang of 2000ms or more.The fix involves reordering the comparator closure to prioritize the
isDefaultcheck. The conditionif lhs.isDefault != rhs.isDefault { return lhs.isDefault && !rhs.isDefault }is now the very first check, makingisDefaultthe primary sort key. This ensures a valid total order, preventing the sorting cycle and resolving the app hang.Fixes REPOPROMPT-J0