Skip to content

Conversation

@fkesheh
Copy link
Contributor

@fkesheh fkesheh commented Dec 16, 2025

Summary by CodeRabbit

  • New Features

    • Implemented context-aware message summarization that dynamically selects prompts optimized for agent mode versus standard conversation mode.
  • Bug Fixes

    • Fixed message summary invalidation to properly account for both edited and deleted messages when determining cache invalidation.
  • Refactor

    • Centralized dialog close behavior for improved state management and consistent cleanup of file selection states.

✏️ Tip: You can customize this high-level summary in your review settings.

Previously, editing the cutoff message (the last message included in the
summary) would not invalidate the summary since the message was modified
in place rather than deleted. This caused stale summaries where the AI
context didn't match the actual conversation.

Now checkAndInvalidateSummary also checks if the edited message is the
cutoff, properly invalidating the summary when needed.
- AllFilesDialog: refactor state reset from useEffect to event handler
  to avoid cascading renders (react-hooks/set-state-in-effect)
- AllFilesDialog: remove unused useMemo import
- ComputerSidebar: add eslint-disable with explanation for intentional
  dependency omission
- chat: add eslint-disable with explanation for stable ref dependencies
@vercel
Copy link

vercel bot commented Dec 16, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
hackerai Ready Ready Preview, Comment Dec 16, 2025 11:36am

@coderabbitai
Copy link

coderabbitai bot commented Dec 16, 2025

Walkthrough

The pull request centralizes dialog cleanup logic in AllFilesDialog, updates message invalidation to include edited messages during summarization checks, and introduces mode-aware summarization that routes to different system prompts based on chat mode (agent vs. ask).

Changes

Cohort / File(s) Summary
Dialog cleanup refactoring
app/components/AllFilesDialog.tsx
Removed useMemo import; introduced centralized handleOpenChange handler that resets fileUrls, isLoadingUrls, selectionMode, and selectedFiles on dialog close; replaced direct onOpenChange calls and removed redundant cleanup effect.
Linting directives
app/components/ComputerSidebar.tsx, app/components/chat.tsx
Added ESLint disable comments (exhaustive-deps in ComputerSidebar; explanatory comment in chat.tsx) without runtime behavior changes.
Message invalidation & mode-aware summarization
convex/messages.ts, lib/api/chat-handler.ts, lib/utils/message-summarization.ts
Updated checkAndInvalidateSummary to include edited message ID alongside deleted IDs; narrowed summarization trigger to non-temporary chats; added mode parameter to checkAndSummarizeIfNeeded and wired mode-specific prompts (AGENT_SUMMARIZATION_PROMPT, ASK_SUMMARIZATION_PROMPT) via getSummarizationPrompt helper.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • lib/utils/message-summarization.ts: Verify mode parameter threading and correct prompt selection logic for agent vs. ask modes
  • convex/messages.ts: Confirm that including edited message ID in invalidation set produces expected summarization behavior
  • lib/api/chat-handler.ts: Review narrowed summarization trigger condition (non-temporary chats only) to ensure no unintended side effects
  • app/components/AllFilesDialog.tsx: Validate that centralized cleanup covers all required state resets and doesn't interfere with other dialog interactions

Possibly related PRs

Poem

🐰 A rabbit's ode to cleaner code:

Mode-aware prompts now guide the way,
Dialog close does cleanup today,
Edited messages won't be missed,
The chat flows smooth—no state dismissed! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: Ask Summarization' directly aligns with the main feature being introduced: mode-aware summarization that adapts prompts for 'Ask' chat mode versus agent mode, with updates throughout the codebase to support this functionality.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sumarization-for-chat

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1516738 and 81dc449.

📒 Files selected for processing (6)
  • app/components/AllFilesDialog.tsx (4 hunks)
  • app/components/ComputerSidebar.tsx (1 hunks)
  • app/components/chat.tsx (1 hunks)
  • convex/messages.ts (1 hunks)
  • lib/api/chat-handler.ts (2 hunks)
  • lib/utils/message-summarization.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
convex/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/convex_rules.mdc)

convex/**/*.{ts,tsx,js,jsx}: Always use the new function syntax for Convex functions with explicit args, returns, and handler properties
Use appropriate validators for all function arguments: v.array() for arrays, v.union() for discriminated unions, v.null() for null returns
Always use the v.int64() validator for 64-bit integers instead of the deprecated v.bigint()
Use v.record() for defining record types; v.map() and v.set() are not supported
Index fields must be queried in the same order they are defined in the schema
Use the Id<'tableName'> TypeScript type from './_generated/dataModel' for strict typing of document IDs
Always use as const for string literals in discriminated union types
When using the Array type, always define arrays as const array: Array<T> = [...]
When using the Record type, always define records as const record: Record<KeyType, ValueType> = {...}
Use internalQuery, internalMutation, and internalAction to register private functions that are not part of the public API
Use query, mutation, and action to register public functions that are exposed to the public API
Always include argument and return validators for all Convex functions, including returns: v.null() if the function doesn't return anything
Use ctx.runQuery to call a query from a query, mutation, or action; ctx.runMutation for mutations; ctx.runAction for actions
When calling functions in the same file using ctx.runQuery, ctx.runMutation, or ctx.runAction, add a type annotation on the return value to work around TypeScript circularity limitations
Do NOT pass the callee function directly into ctx.runQuery, ctx.runMutation, or ctx.runAction; use a FunctionReference instead
Use the api object from convex/_generated/api.ts to call public functions; use the internal object for private functions
Convex uses file-based routing; a public function in convex/example.ts named f has the function reference api.example.f
Convex uses file...

Files:

  • convex/messages.ts
🧠 Learnings (1)
📚 Learning: 2025-08-18T20:33:42.057Z
Learnt from: RostyslavManko
Repo: hackerai-tech/hackerai PR: 10
File: app/components/ComputerCodeBlock.tsx:154-158
Timestamp: 2025-08-18T20:33:42.057Z
Learning: In ComputerCodeBlock component, the wrap state should be controlled by the parent component (ComputerSidebar) which passes the wrap prop. The internal isWrapped state conflicts with parent state management when used in ComputerSidebar context.

Applied to files:

  • app/components/ComputerSidebar.tsx
🔇 Additional comments (8)
app/components/ComputerSidebar.tsx (1)

74-75: LGTM! Clear documentation of intentional dependency array.

The ESLint directive with explanation appropriately documents the intentional minimal dependency array to avoid re-initializing the ref on every tool execution.

app/components/chat.tsx (1)

521-521: LGTM! Appropriate documentation of ref usage pattern.

The ESLint directive correctly explains that todosRef and sandboxPreferenceRef are stable refs whose .current values are read at runtime, avoiding stale closures without triggering unnecessary effect re-runs.

convex/messages.ts (1)

1040-1046: LGTM! Improved summary invalidation to include edited messages.

The change correctly includes the edited message ID alongside deleted message IDs when checking for summary invalidation. This ensures that editing the cutoff message (in addition to deleting it) properly invalidates the summary, which is semantically correct since the summarized content has changed.

app/components/AllFilesDialog.tsx (2)

140-148: LGTM! Centralized dialog cleanup logic.

The new handleOpenChange function consolidates all dialog close cleanup (fileUrls, isLoadingUrls, selectionMode, selectedFiles) into a single handler, improving maintainability and ensuring consistent state resets.


3-3: useMemo import removal is safe.

The import is not used anywhere in the file. The removal is justified.

lib/utils/message-summarization.ts (2)

22-56: LGTM! Well-structured mode-aware summarization prompts.

The new prompts appropriately distinguish between agent mode (security assessment context with detailed technical preservation) and ask mode (conversational context). The getSummarizationPrompt helper cleanly encapsulates the mode-based selection logic.


99-104: All callers have been properly updated with the mode parameter.

The single call site to checkAndSummarizeIfNeeded at lib/api/chat-handler.ts:298 correctly passes all five required parameters including the new mode: ChatMode parameter.

lib/api/chat-handler.ts (1)

290-303: LGTM! Expanded summarization to both agent and ask modes.

The change appropriately expands summarization from agent-only to both modes in non-temporary chats, enabling mode-specific summarization prompts. This aligns with the PR's mode-aware summarization feature. The mode parameter is now correctly passed to checkAndSummarizeIfNeeded.


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.

@rossmanko
Copy link
Contributor

Looks good

@rossmanko rossmanko merged commit 0dfd1ab into main Dec 16, 2025
4 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Dec 30, 2025
This was referenced Feb 2, 2026
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.

3 participants