improvement(chat): stop reloading the full transcript on every turn and event

Merged
WA
1mo ago
+465-182

Summary

  • Each chat turn loaded the chat's full transcript through resolveOrCreateChat just to read the MCP server ids earlier user messages were tagged with. resolveOrCreateChat now never loads the transcript, and a new loadChatMcpServerIds reads only the MCP context ids with one jsonb query, in the same first-tagged order
  • Split the chat loaders: getAccessibleCopilotChatDetail (row plus authorization, no transcript) backs both resolveOrCreateChat and getAccessibleCopilotChatWithMessages. Dropped the includeTranscript option and the conversationHistory field, which nothing read
  • Client: a completed event for the viewer's own live stream no longer refetches the chat detail, because the client's own stream finalization already refetches it. renamed marks the detail stale without refetching; the lists that show titles still refetch

Type of Change

  • Improvement

Testing

  • New chat-mcp-servers.integration.ts (real Postgres), 5 tests:
    • servers from earlier turns match the old transcript-based collection
    • ordering follows seq
    • malformed contexts are ignored
    • a deleted message's server is not inherited
    • no cross-chat reads
  • Mutating each query guard turns the matching test red
  • Chat-events hook tests use a real QueryClient and count actual detail fetches. The own-stream-completion and rename tests fail on the old code; another viewer's completion still refetches
  • Type-check, lint, check:audits, and the mothership chat, v2 chat, and inbox unit suites pass

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)