Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThis PR adds match metadata persistence to executed rules by introducing a new Changes
Sequence DiagramsequenceDiagram
participant App as Application
participant AI as AI Rule Chooser
participant Matcher as Match Rules
participant Runner as Run Rules
participant DB as Prisma/Database
App->>AI: Choose rule for message
AI->>Matcher: Find matching rules
alt Rules Match
Matcher->>Matcher: Generate matchReasons<br/>(type, source)
Matcher-->>AI: Return matched rule +<br/>matchReasons
AI-->>Runner: Execute rule +<br/>matchReasons
Runner->>Runner: serializeMatchReasons()
Runner->>DB: Create ExecutedRule with<br/>matchMetadata (serialized)
DB-->>Runner: Persisted
else No Rules Match
Matcher->>Matcher: Capture AI reasoning
Matcher-->>AI: No matches, reasoning
AI-->>Runner: Skip execution +<br/>reason string
Runner->>DB: Create ExecutedRule<br/>status=SKIPPED,<br/>matchMetadata=undefined
DB-->>Runner: Persisted
end
Runner-->>App: Rule applied/skipped
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
apps/web/utils/ai/choose-rule/run-rules.ts (1)
98-98: Consider omitting the field instead of explicitundefined.Since
matchMetadatais an optional field in the Prisma schema, explicitly setting it toundefinedhas the same effect as omitting it from the data object. While the current approach is clear about intent, omitting the field is more concise:data: { threadId: message.threadId, messageId: message.id, automated: true, reason, - matchMetadata: undefined, status: ExecutedRuleStatus.SKIPPED, emailAccount: { connect: { id: emailAccount.id } }, },Either approach is valid; the current code is more explicit while omitting is more idiomatic for optional fields.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
apps/web/__tests__/ai-choose-rule.test.ts(1 hunks)apps/web/__tests__/helpers.ts(1 hunks)apps/web/prisma/migrations/20251024092349_match_metadata/migration.sql(1 hunks)apps/web/prisma/schema.prisma(1 hunks)apps/web/utils/ai/choose-rule/ai-choose-rule.ts(2 hunks)apps/web/utils/ai/choose-rule/match-rules.ts(2 hunks)apps/web/utils/ai/choose-rule/run-rules.ts(3 hunks)apps/web/utils/ai/choose-rule/types.ts(1 hunks)apps/web/utils/date.ts(1 hunks)version.txt(1 hunks)
🧰 Additional context used
📓 Path-based instructions (17)
apps/web/**/*.{ts,tsx}
📄 CodeRabbit inference engine (apps/web/CLAUDE.md)
apps/web/**/*.{ts,tsx}: Use TypeScript with strict null checks
Path aliases: Use@/for imports from project root
Use proper error handling with try/catch blocks
Format code with Prettier
Leverage TypeScript inference for better DX
Files:
apps/web/__tests__/helpers.tsapps/web/utils/ai/choose-rule/types.tsapps/web/utils/ai/choose-rule/ai-choose-rule.tsapps/web/utils/ai/choose-rule/match-rules.tsapps/web/utils/date.tsapps/web/utils/ai/choose-rule/run-rules.tsapps/web/__tests__/ai-choose-rule.test.ts
!{.cursor/rules/*.mdc}
📄 CodeRabbit inference engine (.cursor/rules/cursor-rules.mdc)
Never place rule files in the project root, in subdirectories outside .cursor/rules, or in any other location
Files:
apps/web/__tests__/helpers.tsapps/web/utils/ai/choose-rule/types.tsversion.txtapps/web/utils/ai/choose-rule/ai-choose-rule.tsapps/web/utils/ai/choose-rule/match-rules.tsapps/web/prisma/migrations/20251024092349_match_metadata/migration.sqlapps/web/prisma/schema.prismaapps/web/utils/date.tsapps/web/utils/ai/choose-rule/run-rules.tsapps/web/__tests__/ai-choose-rule.test.ts
**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/form-handling.mdc)
**/*.ts: The same validation should be done in the server action too
Define validation schemas using Zod
Files:
apps/web/__tests__/helpers.tsapps/web/utils/ai/choose-rule/types.tsapps/web/utils/ai/choose-rule/ai-choose-rule.tsapps/web/utils/ai/choose-rule/match-rules.tsapps/web/utils/date.tsapps/web/utils/ai/choose-rule/run-rules.tsapps/web/__tests__/ai-choose-rule.test.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/logging.mdc)
**/*.{ts,tsx}: UsecreateScopedLoggerfor logging in backend TypeScript files
Typically add the logger initialization at the top of the file when usingcreateScopedLogger
Only use.with()on a logger instance within a specific function, not for a global loggerImport Prisma in the project using
import prisma from "@/utils/prisma";
**/*.{ts,tsx}: Don't use TypeScript enums.
Don't use TypeScript const enum.
Don't use the TypeScript directive @ts-ignore.
Don't use primitive type aliases or misleading types.
Don't use empty type parameters in type aliases and interfaces.
Don't use any or unknown as type constraints.
Don't use implicit any type on variable declarations.
Don't let variables evolve into any type through reassignments.
Don't use non-null assertions with the ! postfix operator.
Don't misuse the non-null assertion operator (!) in TypeScript files.
Don't use user-defined types.
Use as const instead of literal types and type annotations.
Use export type for types.
Use import type for types.
Don't declare empty interfaces.
Don't merge interfaces and classes unsafely.
Don't use overload signatures that aren't next to each other.
Use the namespace keyword instead of the module keyword to declare TypeScript namespaces.
Don't use TypeScript namespaces.
Don't export imported variables.
Don't add type annotations to variables, parameters, and class properties that are initialized with literal expressions.
Don't use parameter properties in class constructors.
Use either T[] or Array consistently.
Initialize each enum member value explicitly.
Make sure all enum members are literal values.
Files:
apps/web/__tests__/helpers.tsapps/web/utils/ai/choose-rule/types.tsapps/web/utils/ai/choose-rule/ai-choose-rule.tsapps/web/utils/ai/choose-rule/match-rules.tsapps/web/utils/date.tsapps/web/utils/ai/choose-rule/run-rules.tsapps/web/__tests__/ai-choose-rule.test.ts
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
**/*.{js,jsx,ts,tsx}: Don't useelements in Next.js projects.
Don't use elements in Next.js projects.
Don't use namespace imports.
Don't access namespace imports dynamically.
Don't use global eval().
Don't use console.
Don't use debugger.
Don't use var.
Don't use with statements in non-strict contexts.
Don't use the arguments object.
Don't use consecutive spaces in regular expression literals.
Don't use the comma operator.
Don't use unnecessary boolean casts.
Don't use unnecessary callbacks with flatMap.
Use for...of statements instead of Array.forEach.
Don't create classes that only have static members (like a static namespace).
Don't use this and super in static contexts.
Don't use unnecessary catch clauses.
Don't use unnecessary constructors.
Don't use unnecessary continue statements.
Don't export empty modules that don't change anything.
Don't use unnecessary escape sequences in regular expression literals.
Don't use unnecessary labels.
Don't use unnecessary nested block statements.
Don't rename imports, exports, and destructured assignments to the same name.
Don't use unnecessary string or template literal concatenation.
Don't use String.raw in template literals when there are no escape sequences.
Don't use useless case statements in switch statements.
Don't use ternary operators when simpler alternatives exist.
Don't use useless this aliasing.
Don't initialize variables to undefined.
Don't use the void operators (they're not familiar).
Use arrow functions instead of function expressions.
Use Date.now() to get milliseconds since the Unix Epoch.
Use .flatMap() instead of map().flat() when possible.
Use literal property access instead of computed property access.
Don't use parseInt() or Number.parseInt() when binary, octal, or hexadecimal literals work.
Use concise optional chaining instead of chained logical expressions.
Use regular expression literals instead of the RegExp constructor when possible.
Don't use number literal object member names th...
Files:
apps/web/__tests__/helpers.tsapps/web/utils/ai/choose-rule/types.tsapps/web/utils/ai/choose-rule/ai-choose-rule.tsapps/web/utils/ai/choose-rule/match-rules.tsapps/web/utils/date.tsapps/web/utils/ai/choose-rule/run-rules.tsapps/web/__tests__/ai-choose-rule.test.ts
!pages/_document.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
!pages/_document.{js,jsx,ts,tsx}: Don't import next/document outside of pages/_document.jsx in Next.js projects.
Don't import next/document outside of pages/_document.jsx in Next.js projects.
Files:
apps/web/__tests__/helpers.tsapps/web/utils/ai/choose-rule/types.tsversion.txtapps/web/utils/ai/choose-rule/ai-choose-rule.tsapps/web/utils/ai/choose-rule/match-rules.tsapps/web/prisma/migrations/20251024092349_match_metadata/migration.sqlapps/web/prisma/schema.prismaapps/web/utils/date.tsapps/web/utils/ai/choose-rule/run-rules.tsapps/web/__tests__/ai-choose-rule.test.ts
apps/web/__tests__/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/llm.mdc)
Place LLM-specific tests under apps/web/tests/
Files:
apps/web/__tests__/helpers.tsapps/web/__tests__/ai-choose-rule.test.ts
**/__tests__/**
📄 CodeRabbit inference engine (.cursor/rules/testing.mdc)
Place AI tests in the
__tests__directory and exclude them from the default test run (they use a real LLM)
Files:
apps/web/__tests__/helpers.tsapps/web/__tests__/ai-choose-rule.test.ts
apps/web/utils/**
📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)
Create utility functions in
utils/folder for reusable logic
Files:
apps/web/utils/ai/choose-rule/types.tsapps/web/utils/ai/choose-rule/ai-choose-rule.tsapps/web/utils/ai/choose-rule/match-rules.tsapps/web/utils/date.tsapps/web/utils/ai/choose-rule/run-rules.ts
apps/web/utils/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/project-structure.mdc)
apps/web/utils/**/*.ts: Use lodash utilities for common operations (arrays, objects, strings)
Import specific lodash functions to minimize bundle size
Files:
apps/web/utils/ai/choose-rule/types.tsapps/web/utils/ai/choose-rule/ai-choose-rule.tsapps/web/utils/ai/choose-rule/match-rules.tsapps/web/utils/date.tsapps/web/utils/ai/choose-rule/run-rules.ts
apps/web/utils/ai/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/llm.mdc)
apps/web/utils/ai/**/*.{ts,tsx}: Place main LLM feature implementations under apps/web/utils/ai/
LLM feature functions should follow the provided TypeScript pattern (separate system/user prompts, use createGenerateObject, Zod schema validation, early validation, return result.object)
Keep system prompts and user prompts separate
System prompt should define the LLM's role and task specifications
User prompt should contain the actual data and context
Always define a Zod schema for response validation
Make Zod schemas as specific as possible to guide LLM output
Use descriptive scoped loggers for each feature
Log inputs and outputs with appropriate log levels and include relevant context
Implement early returns for invalid inputs
Use proper error types and logging for failures
Implement fallbacks for AI failures
Add retry logic for transient failures using withRetry
Use XML-like tags to structure data in prompts
Remove excessive whitespace and truncate long inputs in prompts
Format prompt data consistently across similar functions
Use TypeScript types for all parameters and return values in LLM features
Define clear interfaces for complex input/output structures in LLM features
Files:
apps/web/utils/ai/choose-rule/types.tsapps/web/utils/ai/choose-rule/ai-choose-rule.tsapps/web/utils/ai/choose-rule/match-rules.tsapps/web/utils/ai/choose-rule/run-rules.ts
apps/web/utils/{ai,llms}/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/llm.mdc)
Keep related AI functions co-located and extract common patterns into utilities; document complex AI logic with clear comments
Files:
apps/web/utils/ai/choose-rule/types.tsapps/web/utils/ai/choose-rule/ai-choose-rule.tsapps/web/utils/ai/choose-rule/match-rules.tsapps/web/utils/ai/choose-rule/run-rules.ts
apps/web/prisma/schema.prisma
📄 CodeRabbit inference engine (.cursor/rules/prisma.mdc)
The Prisma schema file must be located at
apps/web/prisma/schema.prisma
Files:
apps/web/prisma/schema.prisma
**/*.test.{ts,js}
📄 CodeRabbit inference engine (.cursor/rules/security.mdc)
Include security tests in your test suites to verify authentication, authorization, and error handling.
Files:
apps/web/__tests__/ai-choose-rule.test.ts
**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/ultracite.mdc)
**/*.{test,spec}.{js,jsx,ts,tsx}: Don't use export or module.exports in test files.
Don't use focused tests.
Don't use disabled tests.
Make sure the assertion function, like expect, is placed inside an it() function call.
Don't nest describe() blocks too deeply in test files.
Don't use focused tests.
Don't use disabled tests.
Don't use export or module.exports in test files.
Files:
apps/web/__tests__/ai-choose-rule.test.ts
**/*.test.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/testing.mdc)
**/*.test.{ts,tsx}: Use Vitest (vitest) as the testing framework
Colocate tests next to the file under test (e.g., dir/format.ts with dir/format.test.ts)
In tests, mock theserver-onlymodule withvi.mock("server-only", () => ({}));
When testing code that uses Prisma, mock it withvi.mock("@/utils/prisma")and use the mock from@/utils/__mocks__/prisma
Use provided helpers for mocks: import{ getEmail, getEmailAccount, getRule }from@/__tests__/helpers
Each test should be independent
Use descriptive test names
Mock external dependencies in tests
Clean up mocks between tests (e.g.,vi.clearAllMocks()inbeforeEach)
Avoid testing implementation details; focus on observable behavior
Do not mock the Logger
Files:
apps/web/__tests__/ai-choose-rule.test.ts
apps/web/__tests__/**/*.test.ts
📄 CodeRabbit inference engine (.cursor/rules/llm-test.mdc)
apps/web/__tests__/**/*.test.ts: Place all LLM-related tests under apps/web/tests/
Use Vitest in LLM tests and import { describe, expect, test, vi, beforeEach } from "vitest"
Mock the Next.js server runtime marker by adding vi.mock("server-only", () => ({})) in LLM tests
Gate LLM tests behind RUN_AI_TESTS using describe.runIf(process.env.RUN_AI_TESTS === "true")
Call vi.clearAllMocks() in a beforeEach for LLM tests
Set a TIMEOUT of 15_000ms for LLM-related tests and pass it to long-running tests/describe blocks
Create helper functions for common test data (e.g., getUser, getTestData) to reduce duplication
Include standard test cases: happy path, error handling, edge cases (empty/null), different user configurations, and various input formats
Use console.debug to log generated LLM content for inspection (e.g., console.debug("Generated content:\n", result.content))
Do not mock the actual LLM call in these tests; exercise real LLM integrations
Test both AI and non-AI paths, including cases where no AI processing is required
Prefer existing helpers from @/tests/helpers.ts (getEmailAccount, getEmail, getRule, getMockMessage, getMockExecutedRule) over custom helpers
Files:
apps/web/__tests__/ai-choose-rule.test.ts
🧠 Learnings (2)
📚 Learning: 2025-06-23T12:26:53.882Z
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/prisma.mdc:0-0
Timestamp: 2025-06-23T12:26:53.882Z
Learning: In this project, Prisma should be imported using 'import prisma from "@/utils/prisma";' in TypeScript files.
Applied to files:
apps/web/utils/ai/choose-rule/run-rules.ts
📚 Learning: 2025-10-02T23:23:48.064Z
Learnt from: CR
PR: elie222/inbox-zero#0
File: .cursor/rules/llm-test.mdc:0-0
Timestamp: 2025-10-02T23:23:48.064Z
Learning: Applies to apps/web/__tests__/**/*.test.ts : Test both AI and non-AI paths, including cases where no AI processing is required
Applied to files:
apps/web/__tests__/ai-choose-rule.test.ts
🧬 Code graph analysis (1)
apps/web/utils/ai/choose-rule/run-rules.ts (1)
apps/web/utils/ai/choose-rule/types.ts (1)
serializeMatchReasons(61-90)
⏰ 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). (1)
- GitHub Check: cubic · AI code reviewer
🔇 Additional comments (13)
apps/web/__tests__/helpers.ts (1)
14-14: LGTM!The nullish coalescing operator correctly preserves explicit boolean values from overrides while defaulting to
falsewhen undefined or null.apps/web/utils/ai/choose-rule/match-rules.ts (2)
78-83: LGTM!Cold email matches are now correctly tagged with AI-type match reasons, enabling proper metadata tracking for this rule type.
353-354: LGTM!The AI match reason case provides a clear, user-facing description consistent with other match types.
apps/web/__tests__/ai-choose-rule.test.ts (1)
20-20: LGTM!Test expectation correctly validates the new behavior where an empty rules array returns a descriptive reason instead of an empty string.
apps/web/prisma/migrations/20251024092349_match_metadata/migration.sql (1)
1-2: LGTM!The migration correctly adds a nullable JSONB column for storing structured match metadata. JSONB is the appropriate PostgreSQL type for JSON data with efficient querying support.
apps/web/utils/ai/choose-rule/ai-choose-rule.ts (2)
32-32: LGTM!Returning a descriptive reason when no rules are provided improves observability and aligns with test expectations.
41-46: LGTM!Populating the reason field with AI reasoning (or a descriptive fallback) when no match is found provides better observability and debugging information.
apps/web/prisma/schema.prisma (2)
480-480: LGTM!The optional
matchMetadataJSON field is appropriately typed for storing structured match information. The nullable constraint correctly handles existing records and cases without metadata.
483-484: Verify the implicitonDeletebehavior for the rule relation.Adding the explicit relation improves type safety and query capabilities. However, no
onDeleteaction is specified. Ensure the default behavior (likelySetNullsinceruleIdis nullable) aligns with your expectations for when rules are deleted.apps/web/utils/ai/choose-rule/types.ts (2)
40-56: LGTM! Well-structured serialization type.The
SerializedMatchReasontype properly converts the Prisma-basedMatchReasoninto a JSON-safe format suitable for database storage. The discriminated union structure is clear, and the conversion ofSystemTypeenum tostringis correct for serialization.
61-90: LGTM! Clean and type-safe serialization logic.The
serializeMatchReasonsfunction correctly handles allMatchReasonvariants with an exhaustive switch statement. The early return for empty/falsy input and the selective field extraction (especially forLEARNED_PATTERN) ensure clean, minimal JSON storage.apps/web/utils/ai/choose-rule/run-rules.ts (2)
12-12: LGTM! Correct import of serialization function.The import of
serializeMatchReasonsis properly placed and uses the correct syntax for importing a function (as opposed toimport typeused for type imports on line 11).
264-264: LGTM! Proper integration of match metadata serialization.The
matchMetadatafield is correctly populated usingserializeMatchReasons(matchReasons). The function handles the optionalmatchReasonsparameter gracefully and returns a value compatible with the PrismaJson?field type, ensuring match reasoning is persisted to the database.
| const aTime = a.internalDate | ||
| ? internalDateToDate(a.internalDate).getTime() | ||
| : 0; | ||
| const bTime = b.internalDate | ||
| ? internalDateToDate(b.internalDate).getTime() | ||
| : 0; |
There was a problem hiding this comment.
🧩 Analysis chain
Verify the behavior change for items without internalDate.
This changes sort behavior:
- Previously: Missing
internalDatewas treated as current date (viainternalDateToDate(undefined)returningnew Date()) - Now: Missing
internalDateis treated as epoch (timestamp0)
Items without internalDate will now sort to the beginning with asc or end with desc, rather than being treated as "now". Ensure this is intentional and that callers expecting the old behavior are updated.
🏁 Script executed:
#!/bin/bash
# Find all usages of sortByInternalDate to assess impact
rg -n "sortByInternalDate" --type=ts -C3Length of output: 3256
🏁 Script executed:
#!/bin/bash
# Get full context on internalDateToDate function
rg -n "function internalDateToDate|export.*internalDateToDate" --type=ts -A10Length of output: 729
🏁 Script executed:
#!/bin/bash
# Check what happens with undefined/null internalDate in actual data flow
rg -n "internalDate\?" --type=ts -B2 -A2 apps/web/utils/date.tsLength of output: 369
🏁 Script executed:
#!/bin/bash
# Get more context around the outbound.ts logic to understand the latestMessage selection
rg -n "actualLatestMessage" --type=ts -B5 -A5 apps/web/utils/reply-tracker/outbound.tsLength of output: 779
🏁 Script executed:
#!/bin/bash
# Check if there's validation or filtering for internalDate before sorting
rg -n "internalDate" --type=ts apps/web/utils/reply-tracker/ -B2 -A2 | head -60Length of output: 1811
🏁 Script executed:
#!/bin/bash
# Get the complete sortByInternalDate function to see the exact comparison logic
cat apps/web/utils/date.ts | sed -n '94,110p'Length of output: 420
🏁 Script executed:
#!/bin/bash
# Check where threadMessages parameter comes from and if internalDate is guaranteed
rg -n "getLatestMessageFromThread|isLatest.*boolean" --type=ts -B10 apps/web/utils/reply-tracker/outbound.ts | head -100Length of output: 277
🏁 Script executed:
#!/bin/bash
# Look for where messages are queried/loaded and if internalDate is filtered
rg -n "threadMessages|\.include|\.select" --type=ts apps/web/utils/reply-tracker/ -B2 -A2 | head -80Length of output: 5901
🏁 Script executed:
#!/bin/bash
# Check the ParsedMessage type to understand internalDate requirement
rg -n "type ParsedMessage|interface ParsedMessage" --type=ts -A15Length of output: 5774
🏁 Script executed:
#!/bin/bash
# Search for any validation or filtering of internalDate before sorting
rg -n "filter.*internalDate|internalDate.*filter" --type=ts -C3Length of output: 0
Fix the sort logic or validate internalDate presence before sorting.
This change introduces a critical bug in how "latest" messages are identified. Both outbound.ts (line 117-118) and handle-conversation-status.ts (line 50+) assume that in an ascending sort, the last element is the latest message. This assumption breaks when any message lacks internalDate:
- Old behavior: Missing
internalDate→ treated as current date → sorted to end (correct latest) - New behavior: Missing
internalDate→ timestamp0→ sorted to beginning (incorrect latest)
Since ParsedMessage.internalDate is optional and there's no validation ensuring it exists, any missing date causes actualLatestMessage to be wrong, leading to incorrect "not the latest" warnings or skipped processing.
Required fixes:
- Either ensure
internalDateis always populated before sorting, or - Change the "latest" detection logic to handle missing dates (e.g., use
Datefield or fallback todateheader), or - Revert to treating missing
internalDateas current date if that was intentional
🤖 Prompt for AI Agents
In apps/web/utils/date.ts around lines 98 to 103, the comparator sets missing
internalDate to 0 which pushes messages without internalDate to the beginning
(breaking callers that expect the last item to be the latest); fix by computing
a fallback timestamp for missing internalDate instead of 0 — either populate
internalDate before sorting (use the message Date header or parsed date) or
update the comparator to derive time = internalDate ?
internalDateToDate(internalDate).getTime() : (DateHeaderIfPresentParsedToMs) ||
Date.now(); ensure the fallback makes messages with missing internalDate sort as
latest so the last element in an ascending sort is the actual latest message and
update any related callers if you change the contract.
There was a problem hiding this comment.
1 issue found across 10 files
Prompt for AI agents (all 1 issues)
Understand the root cause of the following 1 issues and fix them.
<file name="apps/web/utils/date.ts">
<violation number="1" location="apps/web/utils/date.ts:98">
Defaulting falsy internalDate values to 0 changes the comparator semantics: previously internalDateToDate(undefined) returned the current time, so records without an internalDate still sorted chronologically. Now they sort as the Unix epoch, pushing them to the front of ascending lists (and the end of descending ones) and breaking message ordering for those cases.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
| return (a: T, b: T): number => { | ||
| const aTime = internalDateToDate(a.internalDate).getTime() || 0; | ||
| const bTime = internalDateToDate(b.internalDate).getTime() || 0; | ||
| const aTime = a.internalDate |
There was a problem hiding this comment.
Defaulting falsy internalDate values to 0 changes the comparator semantics: previously internalDateToDate(undefined) returned the current time, so records without an internalDate still sorted chronologically. Now they sort as the Unix epoch, pushing them to the front of ascending lists (and the end of descending ones) and breaking message ordering for those cases.
Prompt for AI agents
Address the following comment on apps/web/utils/date.ts at line 98:
<comment>Defaulting falsy internalDate values to 0 changes the comparator semantics: previously internalDateToDate(undefined) returned the current time, so records without an internalDate still sorted chronologically. Now they sort as the Unix epoch, pushing them to the front of ascending lists (and the end of descending ones) and breaking message ordering for those cases.</comment>
<file context>
@@ -95,8 +95,12 @@ export function sortByInternalDate<T extends { internalDate?: string | null }>(
return (a: T, b: T): number => {
- const aTime = internalDateToDate(a.internalDate).getTime() || 0;
- const bTime = internalDateToDate(b.internalDate).getTime() || 0;
+ const aTime = a.internalDate
+ ? internalDateToDate(a.internalDate).getTime()
+ : 0;
</file context>
Summary by CodeRabbit
Release v2.17.12
New Features
Bug Fixes