Skip to content

Conversation

@ibolton336
Copy link
Member

@ibolton336 ibolton336 commented Oct 23, 2025

Related to #888

Summary by CodeRabbit

Release Notes

  • Refactor

    • Optimized internal chat message state management and handling for improved reliability.
  • Chores

    • Updated ignore patterns and removed debug logging to streamline codebase.

@ibolton336 ibolton336 requested a review from a team as a code owner October 23, 2025 17:40
@coderabbitai
Copy link

coderabbitai bot commented Oct 23, 2025

Walkthrough

This PR introduces a selective mutation mechanism for chat messages in the extension state management. A new mutateChatMessages() method is added to the ExtensionState interface and implemented in the VsCodeExtension class, providing dedicated handling for chat-related state updates. The mutation calls in the message processing pipeline are refactored to use this new method instead of the generic mutateData(). The webview context is updated to handle partial state updates via a CHAT_MESSAGES_UPDATE event type. Debug console logs are also removed from the components, and two new ignore patterns are added to .gitignore.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

This change involves mixed complexity across multiple files. While the pattern is consistent (adding a new mutation method, updating call sites, and handling partial updates), it requires understanding the state mutation flow, the relationship between full and partial updates, and how the webview context processes different event types. The changes span interface definitions, implementation logic, refactored method calls, and event handling paths.

Possibly related PRs

Suggested reviewers

  • djzager
  • pranavgaikwad
  • fabianvf

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description Check ❓ Inconclusive The provided description template only specifies title prefix formatting conventions and does not define any required sections, structure, or content requirements for the PR description body itself. The actual PR description consists solely of a link to a related issue without explanation of the changes, impact, or rationale. Without clear criteria from the template about what the description body should contain, it is ambiguous whether the minimal description meets, exceeds, or falls short of the repository's actual expectations for PR documentation. To resolve this ambiguity, clarify the repository's PR description template to specify required sections (such as motivation, changes, testing instructions, or impact) beyond just the title prefix format. Alternatively, if the template is complete as-is, consider adding a brief explanation in the PR description of what changes were made and why, as a single issue link provides limited context for reviewers.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The PR title ":sparkles: Address message bloat causing crash in extension" is directly related to the main changes in this pull request. The changes introduce a selective mutation mechanism (mutateChatMessages) that broadcasts only chat message updates instead of full state updates, which directly addresses the "message bloat" problem described in the title. The emoji prefix :sparkles: is correctly used for a non-breaking feature, the title is concise and clear, and it avoids noise or vague terminology. The title effectively summarizes the primary change from the developer's perspective.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
webview-ui/src/context/ExtensionStateContext.tsx (1)

70-78: Improve type safety for chat messages.

The union type uses any[] for chatMessages, which reduces type safety. Consider using the specific ChatMessage[] type from the shared package.

Additionally, the timestamp field in the CHAT_MESSAGES_UPDATE payload is sent but not used in this handler. Consider either using it (e.g., for debugging or staleness checks) or removing it from the payload.

Apply this diff to improve type safety:

-    const handleMessage = (event: MessageEvent<ExtensionData | { type: string; chatMessages: any[]; timestamp: string }>) => {
+    const handleMessage = (event: MessageEvent<ExtensionData | { type: 'CHAT_MESSAGES_UPDATE'; chatMessages: ChatMessage[]; timestamp: string }>) => {
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 711c2bb and 4cfa414.

📒 Files selected for processing (6)
  • .gitignore (1 hunks)
  • vscode/core/src/extension.ts (2 hunks)
  • vscode/core/src/extensionState.ts (1 hunks)
  • vscode/core/src/utilities/ModifiedFiles/processMessage.ts (3 hunks)
  • webview-ui/src/components/ViolationIncidentsList.tsx (2 hunks)
  • webview-ui/src/context/ExtensionStateContext.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
vscode/core/src/extensionState.ts (1)
shared/src/types/types.ts (1)
  • ExtensionData (114-136)
vscode/core/src/extension.ts (1)
shared/src/types/types.ts (1)
  • ExtensionData (114-136)
webview-ui/src/context/ExtensionStateContext.tsx (1)
shared/src/types/types.ts (1)
  • ExtensionData (114-136)
🪛 GitHub Check: Lint
webview-ui/src/context/ExtensionStateContext.tsx

[warning] 86-86:
Replace ⏎··········?·data.enhancedIncidents⏎········· with ·?·data.enhancedIncidents


[warning] 75-75:
Replace ·?·event.data.chatMessages with ⏎············?·event.data.chatMessages⏎···········


[warning] 73-73:
Replace prevState with (prevState)


[warning] 72-72:
Replace 'type'·in·event.data·&&·event.data.type·===·'CHAT_MESSAGES_UPDATE' with "type"·in·event.data·&&·event.data.type·===·"CHAT_MESSAGES_UPDATE"


[warning] 70-70:
Replace event:·MessageEvent<ExtensionData·|·{·type:·string;·chatMessages:·any[];·timestamp:·string·}> with ⏎······event:·MessageEvent<ExtensionData·|·{·type:·string;·chatMessages:·any[];·timestamp:·string·}>,⏎····

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build (macos)
  • GitHub Check: Build (linux)
  • GitHub Check: Build (windows)
🔇 Additional comments (4)
.gitignore (1)

20-21: LGTM!

These ignore patterns appropriately exclude VSCode test artifacts and Eclipse workspace files from version control.

vscode/core/src/extensionState.ts (1)

28-28: LGTM!

The new mutateChatMessages method signature correctly mirrors the existing mutateData pattern and provides the foundation for selective chat message updates.

webview-ui/src/components/ViolationIncidentsList.tsx (1)

114-114: LGTM!

Removing debug console logs improves performance and code cleanliness for production.

Also applies to: 205-205

vscode/core/src/utilities/ModifiedFiles/processMessage.ts (1)

164-164: Correct usage of the new API, but effectiveness depends on fixing the duplicate propagation issue.

The migration from state.mutateData to state.mutateChatMessages is appropriate since all three call sites only mutate the chatMessages array. However, the full benefit of this change depends on resolving the duplicate state propagation issue identified in vscode/core/src/extension.ts (lines 119-136).

Also applies to: 295-295, 308-308

Comment on lines +119 to +136
// Selective state mutator for chat messages only
const mutateChatMessages = (
recipe: (draft: ExtensionData) => void,
): Immutable<ExtensionData> => {
const data = produce(getData(), recipe);
setData(data);

// Send only chat messages to webview instead of full state
this.state.webviewProviders.forEach((provider) => {
provider.sendMessageToWebview({
type: "CHAT_MESSAGES_UPDATE",
chatMessages: data.chatMessages,
timestamp: new Date().toISOString(),
});
});

return data;
};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: Duplicate state propagation defeats message bloat reduction.

The mutateChatMessages function calls setData(data) on line 124, which fires the _onDidChange event. The existing listeners on lines 676-680 are subscribed to this event and send the FULL ExtensionData to all webviews:

this.onDidChangeData((data) => {
  provider.sendMessageToWebview(data);  // Sends full state including all chatMessages
})

Then lines 127-133 send the selective CHAT_MESSAGES_UPDATE. This means webviews receive:

  1. Full ExtensionData (including the complete chatMessages array)
  2. Selective CHAT_MESSAGES_UPDATE (just the chatMessages)

This sends MORE data than before, not less, defeating the PR's goal of addressing message bloat.

Solution: Consider one of these approaches:

  1. Introduce a separate event emitter for chat-only changes that doesn't trigger full state propagation
  2. Modify mutateChatMessages to update internal state without firing onDidChange
  3. Add a flag to distinguish between full state changes and chat-only changes, and filter in the listeners
🤖 Prompt for AI Agents
In vscode/core/src/extension.ts around lines 119-136, calling setData(data)
inside mutateChatMessages triggers the global onDidChangeData listeners (sending
the full ExtensionData) and then you also send a CHAT_MESSAGES_UPDATE, causing
duplicate/full-state propagation and negating the message-bloat fix; fix by
preventing the global onDidChangeData event from firing for chat-only updates:
add a dedicated chat-only EventEmitter (e.g., onChatMessagesChange) and have
mutateChatMessages update the in-memory data without invoking the global emitter
(either by using a setDataSilent internal helper or by passing an options flag
to setData to suppress the global event), then emit only the new chat-only event
to notify webviews; update existing global onDidChangeData listeners to remain
unchanged and replace chat-specific webview sends to subscribe to the new chat
emitter so webviews receive only the selective CHAT_MESSAGES_UPDATE.

Copy link
Contributor

@pranavgaikwad pranavgaikwad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad you were able to figure this out. Will give this a test before approving.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants