fix(desktop): let the chat transcript render without a workspace host

Merged
KI
4d ago
+321-144

Links

Summary

  • Opening a cloud workspace while its box is asleep showed "This view hit an error – Unable to find tRPC Context" instead of the workspace's chat. It survived a reload.
  • The chat transcript now reads the workspace host only where the pane gives it one. It no longer needs a workspace tRPC provider to render.
  • This replaces the fake provider from #9621 (a client that fails every call) with that source fix.

Why / Context

This ships to everyone in desktop v2.0.8. In v2.0.7 it was behind the WORKSPACE_MOVES flag. Two changes made it reachable:

  • #9339 added StoredCloudChat: a cloud workspace opens on its newest stored chat while its box wakes. That screen renders StoredChatTranscript → Transcript from the $workspaceId route layout, outside WorkspaceProvider. This is by design, because the sandbox has no host URL until it wakes.
  • #9565 removed the flag gate, so every user can reach that screen.

The transcript was written when every transcript sat inside the provider (#8941). Three paths call workspaceTrpc hooks, which throw without a provider even when the query is disabled:

  • TurnChangesCard: workspace.get for the worktree path. This is the one that crashed in the field.
  • AttachmentImage → useChatImageSource: workspace.get and filesystem.readFile. These also back ChatImageGalleryOverlay and PrefetchChatImage.
  • AttachmentPartImage → useAttachmentSource: workspaceTrpc.useUtils().

A stored chat with a settled edit turn or an image attachment crashed the screen.

How It Works

  • ChatPaneActions.workspaceId is now documented as the signal that a workspace host is mounted. StoredCloudChat supplies no actions, so it has no host.
  • TurnChangesCard takes worktreePath from ChatPaneActions, which SessionView supplies, instead of querying the host itself.
  • AttachmentImage mounts HostAttachmentImage (the old body) only when the pane has a workspace. Otherwise it shows a file card, which the old hook already returned without a workspace.
  • AttachmentPartImage passes a host read to useAttachmentSource only when the pane has a workspace. Without one, cloud-stored (fileId) attachments still load; host-only ones show a name badge.
  • DraftChat's ChatPaneActionsProvider now wraps the whole pane, so its warm StoredChatTranscript keeps reading images from the host.
  • StoredCloudChat loses the fake provider from #9621.

Design Decisions

  • Why not mount a provider in StoredCloudChat: there is no host to point it at until the box wakes. A provider whose client fails every call (#9621) stops the crash but hides the missing host. The rows then fire requests that are meant to fail, and a real live surface that forgets its provider is no longer caught. The transcript should say it has no host, not pretend to have one.
  • Why workspaceId as the signal: ChatPaneActions already documented it as "absent where the chat has no workspace", and useChatImageSource already returned an error without it. A live pane that forgets the provider still crashes loudly.

Manual QA

Ran the dev app from this worktree and drove it over CDP with real mouse input (Workspaces → Cloud → Kiet Email Triage, box asleep):

  • Before (main at 56025a8, before #9621): the content area showed the error boundary "This view hit an error – Unable to find tRPC Context". The renderer log named <TurnChangesCard>.
  • After (this change): after a reload, the same journey shows the stored chat under the "Waking up workspace" pill, with no error boundary.
  • Image attachments, same no-host state: no chat of this user had one, so I rewrote the real chatHistory.events response over CDP. I added a path-tagged image, a host-only attachmentId image and a cloud fileId image to the newest user message. All three rendered as file cards with no error. The dev API returned no URL for the cloud file, so a loaded cloud thumbnail was not exercised.
  • Log: 0 "tRPC Context" lines from the renderer after the fix (2 on the before run).
  • Screenshots are attached to SUPER-3412.

Testing

  • New: StoredChatTranscript.test.tsx renders a stored chat with no workspace tRPC provider. The chat has a completed edit (changes card), a path-tagged image and a host-only image attachment. It fails with "Unable to find tRPC Context" when the transcript fix is reverted, and passes with it.

  • bun run --cwd apps/desktop typecheck: clean. Full bun run typecheck before rebasing: 42/42 tasks.

  • bun test on the desktop $workspaceId/components, ChatSession and ChatPane directories: 646 pass, 0 fail.

  • bun run lint:fix: no changes. bunx sherif: clean. bun run check:i18n: 0 missing in every locale, no catalog changes.

  • Full bun run test --continue, run locally before rebasing: 27/30 tasks pass. The red tasks fail on code this PR doesn't touch:

    • shared, 1 failure: local date formatting writes "at" where the test expects a comma.
    • desktop, 39–42 failures: git and shell-spawning tests whose git calls fail on this machine ("fatal: permission denied").
    • host-service, 21 failures: no diff against main.

    CI is the reference for those.

Risks / Rollback

  • Low risk. Renderer only, no tRPC procedure or data changes.
  • Rollback: revert this PR. That also restores #9621's stub, which already prevents the crash.

Summary by cubic

Opening a cloud workspace while its box is asleep showed "This view hit an error – Unable to find tRPC Context" instead of the workspace's chat. The chat transcript now renders without a workspace host, reading the host only where the pane provides one.

  • TurnChangesCard takes the worktree path from ChatPaneActions instead of querying the workspace host.
  • Image attachments without a host fall back to file cards; cloud-stored ones still load.
  • Removes the fake tRPC provider from StoredCloudChat that failed every call.
  • Adds a StoredChatTranscript test rendering a changes card and image attachments with no workspace provider.

Summary by CodeRabbit

  • Bug Fixes
    • Stored chat transcripts in cloud workspaces now display edit summaries and attachment names even when the workspace host is unavailable.
    • Attachments without an available workspace host display as file cards instead of relying on host-based image loading.
  • Improvements
    • Attachment previews now show a loading placeholder, fall back to a file card when an image can’t be displayed, and support opening eligible previews in the gallery.