fix: guard against undefined updatedAt when sorting provider accounts#1132
Open
dongsheng123132 wants to merge 1 commit into
Open
Conversation
The provider-account comparators call `updatedAt.localeCompare(...)`
assuming `updatedAt` is always a string. When a persisted account is
missing `updatedAt` (e.g. a record written by an external tool /
migration / a hand-edited clawx-providers.json), the value is
`undefined` and the whole renderer crashes at the error boundary:
TypeError: Cannot read properties of undefined (reading 'localeCompare')
at Array.sort (<anonymous>)
at buildConfiguredModelOptions / buildRuntimeProviderOptions (useMemo)
`listProviderAccounts()` returns stored accounts verbatim without
normalization, so a single bad record takes down both the Chat page
(model picker) and the Agents page.
Make the three `updatedAt` comparators null-safe with `?? ''`.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
buildConfiguredModelOptionsandbuildRuntimeProviderOptions(insrc/lib/model-options.ts), and the account-list builder insrc/lib/provider-accounts.ts, sort accounts with:This assumes every
ProviderAccount.updatedAtis a string. ButlistProviderAccounts()returns the persistedproviderAccountsmap verbatim — no normalization / backfill:So if a single persisted account is missing
updatedAt(a record written by an external tool, an import/migration, or a hand-editedclawx-providers.json),updatedAtisundefinedat runtime. As soon as there are ≥2 qualifying accounts,Array.sortinvokes the comparator and the entire renderer crashes at the error boundary:This takes down both the Chat page (model picker) and the Agents page — the user only sees "Something went wrong", and the Reload button doesn't help because the malformed record is still on disk.
Fix
Make the three
updatedAtcomparators null-safe:src/lib/model-options.ts(×2 —buildRuntimeProviderOptions,buildConfiguredModelOptions)src/lib/provider-accounts.ts(×1)An empty string sorts such a record to the end (reasonable for an account with no known update time), and a single malformed record can no longer crash the whole app.
Repro
%APPDATA%/ClawX/clawx-providers.json, remove theupdatedAtfield from one entry underproviderAccounts.localeComparecrash.With this patch, ClawX loads normally.
🤖 Generated with Claude Code