Skip to content

refactor(site/src/pages/AgentsPage): make UploadState a discriminated union - #29901

Closed
DanielleMaywood wants to merge 4 commits into
mainfrom
nullability/upload-state-union
Closed

DanielleMaywood wants to merge 4 commits into
mainfrom
nullability/upload-state-union

Conversation

@DanielleMaywood

Copy link
Copy Markdown
Collaborator

Stacked on #29890.

Part of the AgentsPage nullability cleanup; see #29888 for the methodology.

UploadState (AttachmentPreview.tsx) was { status; fileId?; error?; draftWarning? }, so every consumer had to recheck fileId after checking status === "uploaded". It is now a discriminated union:

  • uploaded requires fileId: string, error requires error: string, and pending/processing/uploading have neither.
  • draftWarning? stays optional on every variant. It is set while pending/uploading and is not cleared when the upload later fails, so it can appear on error too.
  • The four status === "uploaded" && state.fileId checks in useFileAttachments.ts (x2), AgentCreateForm.tsx and ChatPageContent.tsx are now just status === "uploaded". The tooltip's ?? "Upload failed" fallback is removed.
  • useChatDraftAttachments.ts keeps its mutable registry/view types. A new uploadStateFromView helper is the one place that converts a view into an UploadState. It keeps the old fallbacks: uploaded with no fileId becomes an error state (previously it showed as uploaded and was silently dropped at send), and error with no message uses "Upload failed". No producer reaches either case.
  • Tests narrow on status === "error" before reading error. Fixtures and stories already matched the new type.

No producer creates uploaded without a fileId: uploads use result.id, restored attachments skip entries with no fileId, edit mode only sets uploaded when file_id is present, and restored draft records must have a string fileId.

Verified: pnpm lint:types, pnpm check, pnpm lint:oxlint, pnpm lint:compiler, pnpm lint:knip, pnpm test src/pages/AgentsPage (1617 passed), and pnpm test:storybook on AttachmentPreview.stories.tsx and AgentChatInput.stories.tsx (77 passed).

Plan excerpt

Analysed on a local, unpushed merge of all cleanup branches (/home/coder/wt/topdown); ranking script /home/coder/nullflow/topdown.cjs. After the bottom-up PRs only 43 dead slots remain, so what's left is nullability that is real at its origin. Two read-only agents reviewed the top origins in code. Guard counts from the tool overstate the win: many "guards" are real branches (loading, no workspace, first/last row).

# Change Guards removed Size Risk
T6 UploadState as a discriminated union (uploaded has fileId, error has error) 4 status === "uploaded" && fileId 4 files / ~30 lines Low

This PR was generated by Coder Agents on behalf of @DanielleMaywood.

@linear-code

linear-code Bot commented Sep 30, 2026

Copy link
Copy Markdown

CODAGT-1258

… props

AgentChatPage, AgentChatPageView, ChatPageContent, AgentCreateForm
and AgentChatInput always pass the composer, page shell, attachment
preview and skills menu props below, but the receiving components
still declared them optional and defaulted or guarded them.

Make them required and drop the dead defaults and guards:
AgentChatPageView and its loading view props, ChatPageTimeline and
ChatPageInput editor, MCP and loading props, AgentChatInput
initialValue/onContentChange/plan mode/catalog loading,
ChatMessageInput, SkillsTriggerMenu and AttachmentPreview callbacks
and flags. ChatMessageInput always autofocuses, so its autoFocus prop
is removed. Tests and stories now pass the values production sends;
the story for plan mode without a toggle handler is removed.
@DanielleMaywood
DanielleMaywood force-pushed the nullability/upload-state-union branch from ebe1a6e to 01de81e Compare October 6, 2026 11:18
Base automatically changed from nullability/chat-input to main October 6, 2026 12:30
@github-actions github-actions Bot added the stale This issue is like stale bread. label Oct 31, 2026
@github-actions github-actions Bot closed this Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale This issue is like stale bread.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant