mirror of
https://github.com/coder/coder.git
synced 2026-10-16 06:37:58 +08:00
`OrganizationAutocomplete` declared `options: Organization[]` (mutable), but `useDashboard().organizations` returns `readonly Organization[]`. Callers forced to spread to satisfy the type even though the component never mutates the array. While fixing this, found two more issues with how organization context is resolved: - `AgentCreateForm`, `ChatPageContent`, and `OrganizationRedirect` used `organizations[0]` assuming the default org is first — nothing guarantees that ordering. - `ChatPageInput` was guessing the org from `useDashboard()` for file uploads on existing chats, even though the chat already has `organization_id`. In multi-org deployments, uploads could land in the wrong org. Changes: - Widen `OrganizationAutocomplete` `options` to `readonly Organization[]` - Remove unnecessary `[...organizations]` spread in `AgentCreateForm` - Replace all `organizations[0]` with `.find(o => o.is_default) ?? organizations[0]` for users not in the default org - Eliminate `[...organizations].sort()` allocation in `OrganizationRedirect` with direct `.find()` lookups (equivalent priority: editable default → any editable → viewable default → any viewable) - Thread `chat.organization_id` from `AgentChatPage` → `AgentChatPageView` → `ChatPageInput` so file uploads use the chat's actual org instead of guessing Closes #24285 > 🤖 PR initially created by Claude Opus 4.6