Skip to content

lint: enable detekt rule: ConstructorParameterNaming#328

Open
AdrianLeeElder wants to merge 2 commits into
developfrom
fix/issue-324
Open

lint: enable detekt rule: ConstructorParameterNaming#328
AdrianLeeElder wants to merge 2 commits into
developfrom
fix/issue-324

Conversation

@AdrianLeeElder
Copy link
Copy Markdown
Contributor

@AdrianLeeElder AdrianLeeElder commented Mar 28, 2026

Closes #324

Automated by auto-agent.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Fixed synthetic replay event metadata extraction to use actual values from incoming data instead of defaults
    • Corrected system ID tracking in historical metrics reports
  • Chores

    • Improved error handling in metric and span data extraction processes
    • Code style consistency updates across the codebase

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 28, 2026

📝 Walkthrough

Walkthrough

The PR refactors internal Kotlin naming conventions from snake_case to camelCase across LLM provider DTOs while maintaining API compatibility via @SerialName serialization mappings. It also improves synthetic replay event metadata extraction from SentryEnvelope payloads, updates error handling patterns from suspending to non-suspending variants, fixes systemId population in monitoring responses, and enables the ConstructorParameterNaming detekt validation rule.

Changes

Cohort / File(s) Summary
Naming Conventions Refactoring
ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/AnthropicProvider.kt, ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/OpenAiProvider.kt
Renamed internal DTO properties from snake_case to camelCase (e.g., max_tokensmaxTokens, input_tokensinputTokens) with @SerialName annotations preserving JSON wire format compatibility.
Event Service Enhancements
backend/src/main/kotlin/com/moneat/events/services/EventService.kt
Modified synthetic replay event persistence to derive SDK/platform/environment/release metadata from the incoming SentryEnvelope by decoding payload fields instead of using fixed defaults. Switched per-key error handling from suspendRunCatching to runCatching in measurement and span extraction helpers.
Error Handling Refactoring
backend/src/main/kotlin/com/moneat/events/services/DashboardQueryHelper.kt
Changed parseTraceContext JSON parsing logic from suspendRunCatching to non-suspending runCatching, preserving return behavior (trace object or null on failure).
Monitor Service Fixes
backend/src/main/kotlin/com/moneat/monitor/services/MonitorService.kt
Updated getHistoricalMetrics to populate HistoricalMetricsResponse.systemId using hostId.toString() instead of empty string across all response paths.
Detekt Configuration
ee/backend/detekt.yml
Enabled naming.ConstructorParameterNaming validation rule by setting active: true.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 With camelCase hops and snake_case tamed,
Our Kotlin code now flows, well-framed!
Metadata extracted, errors caught just right,
The detekt rule watches—standards shine bright! 🌟

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 22.34% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Out of Scope Changes check ❓ Inconclusive While most changes align with enabling the detekt rule and standardizing naming conventions, the control-flow changes in DashboardQueryHelper and EventService (runCatching vs suspendRunCatching) appear tangential to the primary objective. Clarify whether control-flow modifications in DashboardQueryHelper and EventService are intentional or if they should be separated into a distinct PR.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: enabling the ConstructorParameterNaming detekt rule in the configuration file.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #324 by enabling the ConstructorParameterNaming rule and standardizing internal property naming from snake_case to camelCase.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-324

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
Copy Markdown

@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: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
backend/src/test/kotlin/com/moneat/services/EventServiceCoverageTest.kt (1)

147-158: ⚠️ Potential issue | 🟠 Major

These fixtures don't validate the external wire contract for future changes.

Using Json.encodeToString(...) round-trips the same Kotlin DTO shape, so a missing @SerialName annotation on a future camelCase field would pass the test. The round-trip succeeds because both encode and decode use the same field name when no annotation exists, even though the wire format would be incorrect. Keep at least one literal snake_case JSON fixture per DTO type to explicitly test the external Sentry payload schema (or assert the serialized keys match the expected wire format).

The same vulnerability applies to all other Json.encodeToString(Sentry...) fixtures in this file.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/src/test/kotlin/com/moneat/services/EventServiceCoverageTest.kt`
around lines 147 - 158, Replace the self-encoded fixtures with an explicit
snake_case JSON fixture (or add an assertion) so the test validates the external
wire contract: instead of using Json.encodeToString(...) for
SentryEvent/ExceptionInfo/ExceptionValue (the eventJson variable), supply a
hard-coded snake_case JSON string representing the Sentry payload (e.g.
"event_id", "exception": {"values":[{"type","value"}]}, etc.) and use that
fixture for decoding/round-trip checks, or after
Json.encodeToString(SentryEvent(...)) assert the produced JSON object's keys
match the expected snake_case names to ensure `@SerialName` mappings are
exercised.
ee/backend/src/main/kotlin/com/moneat/enterprise/mcp/services/SummaryService.kt (1)

261-269: ⚠️ Potential issue | 🟠 Major

Use suspendRunCatching for the suspend metric fetch.

The monitorService.getLatestMetrics(sys.id) call at line 262 is a suspend function inside a suspend context. Using runCatching will swallow CancellationException; use suspendRunCatching from com.moneat.utils instead to preserve proper cancellation semantics.

+import com.moneat.utils.suspendRunCatching
...
         val hostMetrics = systems.map { sys ->
-            val metrics = runCatching {
+            val metrics = suspendRunCatching {
                 monitorService.getLatestMetrics(sys.id)
             }.getOrNull()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@ee/backend/src/main/kotlin/com/moneat/enterprise/mcp/services/SummaryService.kt`
around lines 261 - 269, The mapping that builds hostMetrics in SummaryService
uses runCatching around the suspend call
monitorService.getLatestMetrics(sys.id), which can swallow
CancellationException; replace runCatching with the suspend-aware helper
suspendRunCatching (imported from com.moneat.utils) so cancellation semantics
are preserved when fetching metrics inside the coroutine. Locate the block that
constructs HostMetricSnapshot (the systems.map { sys -> ... } lambda) and change
the error wrapper to suspendRunCatching {
monitorService.getLatestMetrics(sys.id) } and keep the subsequent .getOrNull()
usage to preserve behavior.
backend/src/main/kotlin/com/moneat/summary/services/SummaryService.kt (1)

302-315: ⚠️ Potential issue | 🟠 Major

Replace runCatching with suspendRunCatching in suspend contexts.

monitorService.getLatestMetrics(...) is a suspend function. Using runCatching in suspend/coroutine functions catches CancellationException, preventing proper cancellation propagation. Use suspendRunCatching from com.moneat.utils instead to preserve CancellationException behavior.

Affects lines 303, 375, and 407 in getWeeklyReport() and getIncidentContext(). Add the import and replace the three occurrences as shown:

Suggested change
 import com.moneat.uptime.services.UptimeService
 import com.moneat.utils.recoverOnExpectedFailures
+import com.moneat.utils.suspendRunCatching
 import io.ktor.client.statement.bodyAsText
 import kotlinx.coroutines.async
 import kotlinx.coroutines.coroutineScope
@@
         val hostMetrics = if (hosts.isEmpty()) {
             emptyList()
         } else {
             hosts.mapNotNull {
-                runCatching {
+                suspendRunCatching {
                     monitorService.getLatestMetrics(it.id)
                 }.getOrNull()
             }
         }
@@
-                val metrics = runCatching { monitorService.getLatestMetrics(host.id) }.getOrNull()
+                val metrics = suspendRunCatching { monitorService.getLatestMetrics(host.id) }.getOrNull()
                 if (metrics != null) {
                     hostMetrics = HostMetricsWindow(
@@
-                val metrics = runCatching { monitorService.getLatestMetrics(host.id) }.getOrNull()
+                val metrics = suspendRunCatching { monitorService.getLatestMetrics(host.id) }.getOrNull()
                 if (metrics != null) {
                     hostMetrics = HostMetricsWindow(
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/src/main/kotlin/com/moneat/summary/services/SummaryService.kt` around
lines 302 - 315, In getWeeklyReport() and getIncidentContext(), replace usages
of runCatching { monitorService.getLatestMetrics(it.id) } with
suspendRunCatching { monitorService.getLatestMetrics(it.id) } so the suspend
call in monitorService.getLatestMetrics(...) preserves coroutine cancellation
semantics; add the import for com.moneat.utils.suspendRunCatching and update the
three occurrences referenced in those methods to use suspendRunCatching instead
of runCatching.
🧹 Nitpick comments (1)
backend/src/main/kotlin/com/moneat/monitor/services/MonitorService.kt (1)

339-355: Extract the default history interval constant.

The same raw 3600 fallback is now repeated in both historical response builders. Pulling it into one constant keeps the default synchronized and avoids a new magic-number footgun.

♻️ Suggested refactor
     companion object {
         const val ALERT_SCOPE_GLOBAL = "global"
         const val ALERT_SCOPE_SYSTEM = "system"
         const val ALERT_SCOPE_HOST = "host"
         const val INFRA_LOOKBACK_DAYS = 7
         const val MONITOR_HISTORY_CACHE_TTL_SECONDS = 30L
+        private const val DEFAULT_HISTORY_INTERVAL_SECONDS = 3600
     }
@@
             val host = getHostById(hostId) ?: return@cached HistoricalMetricsResponse(
                 systemId = "",
                 hostId = hostId,
                 from = fromTimestamp,
                 to = toTimestamp,
-                intervalSeconds = intervalSeconds ?: 3600,
+                intervalSeconds = intervalSeconds ?: DEFAULT_HISTORY_INTERVAL_SECONDS,
                 dataPoints = emptyList()
             )
@@
                 return@cached HistoricalMetricsResponse(
                     systemId = "",
                     hostId = hostId,
                     from = fromTimestamp,
                     to = toTimestamp,
-                    intervalSeconds = intervalSeconds ?: 3600,
+                    intervalSeconds = intervalSeconds ?: DEFAULT_HISTORY_INTERVAL_SECONDS,
                     dataPoints = emptyList()
                 )
@@
         val host = getHostById(hostId) ?: return ContainerMetricsResponse(
             containerName = containerName,
             from = fromTimestamp,
             to = toTimestamp,
-            intervalSeconds = intervalSeconds ?: 3600,
+            intervalSeconds = intervalSeconds ?: DEFAULT_HISTORY_INTERVAL_SECONDS,
             dataPoints = emptyList()
         )
@@
             return ContainerMetricsResponse(
                 containerName = containerName,
                 from = fromTimestamp,
                 to = toTimestamp,
-                intervalSeconds = intervalSeconds ?: 3600,
+                intervalSeconds = intervalSeconds ?: DEFAULT_HISTORY_INTERVAL_SECONDS,
                 dataPoints = emptyList()
             )

As per coding guidelines, "Use named constants instead of magic numbers (e.g., const val MAX_RETRIES = 5 instead of if (count > 5))".

Also applies to: 637-651

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/src/main/kotlin/com/moneat/monitor/services/MonitorService.kt` around
lines 339 - 355, Replace the repeated magic number 3600 with a single named
constant (e.g., DEFAULT_HISTORY_INTERVAL_SECONDS) and use it wherever the
HistoricalMetricsResponse fallback interval is set; specifically, add a const
val DEFAULT_HISTORY_INTERVAL_SECONDS = 3600 in the MonitorService companion
object (or appropriate top-level/constants file) and change the intervalSeconds
?: 3600 occurrences in the HistoricalMetricsResponse constructions (the blocks
around getHostById(...), clampRangeToRetention(...), and the other similar block
referenced) to intervalSeconds ?: DEFAULT_HISTORY_INTERVAL_SECONDS so the
default is centralized and consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backend/src/main/kotlin/com/moneat/events/services/EventService.kt`:
- Around line 628-634: The current fallback SyntheticReplayMetadata
instantiation uses platform "android" and environment "e2e-testing", which will
misclassify real sessions; change the fallback (the SyntheticReplayMetadata
instance named fallback in EventService.kt) to neutral values (e.g. empty
strings or an explicit neutral token such as "unknown") for sdkName, sdkVersion,
platform, environment and release so synthetic replay rows are not attributed to
a specific platform or test environment. Ensure the single fallback variable
used for the standalone replay_video path no longer defaults to
"sentry.java.android" or "e2e-testing".

In `@backend/src/main/kotlin/com/moneat/monitor/services/MonitorService.kt`:
- Around line 339-355: Several return paths in the cached block populate
HistoricalMetricsResponse with systemId = "" causing the host identifier to be
dropped; update all such returns (the ones after the getHostById null check,
after clampRangeToRetention null, and the other mentioned return paths) to set
systemId to the host ID string (use the existing hostId variable or host.id if
the Host model exposes it) so HistoricalMetricsResponse.systemId carries the
host identifier; ensure you change every occurrence where systemId is hardcoded
to "" within the HistoricalMetricsResponse constructions in this method
(references: getHostById, clampRangeToRetention, HistoricalMetricsResponse).

---

Outside diff comments:
In `@backend/src/main/kotlin/com/moneat/summary/services/SummaryService.kt`:
- Around line 302-315: In getWeeklyReport() and getIncidentContext(), replace
usages of runCatching { monitorService.getLatestMetrics(it.id) } with
suspendRunCatching { monitorService.getLatestMetrics(it.id) } so the suspend
call in monitorService.getLatestMetrics(...) preserves coroutine cancellation
semantics; add the import for com.moneat.utils.suspendRunCatching and update the
three occurrences referenced in those methods to use suspendRunCatching instead
of runCatching.

In `@backend/src/test/kotlin/com/moneat/services/EventServiceCoverageTest.kt`:
- Around line 147-158: Replace the self-encoded fixtures with an explicit
snake_case JSON fixture (or add an assertion) so the test validates the external
wire contract: instead of using Json.encodeToString(...) for
SentryEvent/ExceptionInfo/ExceptionValue (the eventJson variable), supply a
hard-coded snake_case JSON string representing the Sentry payload (e.g.
"event_id", "exception": {"values":[{"type","value"}]}, etc.) and use that
fixture for decoding/round-trip checks, or after
Json.encodeToString(SentryEvent(...)) assert the produced JSON object's keys
match the expected snake_case names to ensure `@SerialName` mappings are
exercised.

In
`@ee/backend/src/main/kotlin/com/moneat/enterprise/mcp/services/SummaryService.kt`:
- Around line 261-269: The mapping that builds hostMetrics in SummaryService
uses runCatching around the suspend call
monitorService.getLatestMetrics(sys.id), which can swallow
CancellationException; replace runCatching with the suspend-aware helper
suspendRunCatching (imported from com.moneat.utils) so cancellation semantics
are preserved when fetching metrics inside the coroutine. Locate the block that
constructs HostMetricSnapshot (the systems.map { sys -> ... } lambda) and change
the error wrapper to suspendRunCatching {
monitorService.getLatestMetrics(sys.id) } and keep the subsequent .getOrNull()
usage to preserve behavior.

---

Nitpick comments:
In `@backend/src/main/kotlin/com/moneat/monitor/services/MonitorService.kt`:
- Around line 339-355: Replace the repeated magic number 3600 with a single
named constant (e.g., DEFAULT_HISTORY_INTERVAL_SECONDS) and use it wherever the
HistoricalMetricsResponse fallback interval is set; specifically, add a const
val DEFAULT_HISTORY_INTERVAL_SECONDS = 3600 in the MonitorService companion
object (or appropriate top-level/constants file) and change the intervalSeconds
?: 3600 occurrences in the HistoricalMetricsResponse constructions (the blocks
around getHostById(...), clampRangeToRetention(...), and the other similar block
referenced) to intervalSeconds ?: DEFAULT_HISTORY_INTERVAL_SECONDS so the
default is centralized and consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c2ba56e6-8d64-4023-9fa0-41e85810bc30

📥 Commits

Reviewing files that changed from the base of the PR and between a69fa29 and e7fb872.

📒 Files selected for processing (31)
  • backend/detekt.yml
  • backend/src/main/kotlin/com/moneat/ai/AiModels.kt
  • backend/src/main/kotlin/com/moneat/ai/OpenAiClient.kt
  • backend/src/main/kotlin/com/moneat/auth/services/OAuthService.kt
  • backend/src/main/kotlin/com/moneat/events/models/SentryModels.kt
  • backend/src/main/kotlin/com/moneat/events/services/DashboardQueryHelper.kt
  • backend/src/main/kotlin/com/moneat/events/services/EventService.kt
  • backend/src/main/kotlin/com/moneat/incident/services/IncidentIoProvider.kt
  • backend/src/main/kotlin/com/moneat/monitor/models/MonitorModels.kt
  • backend/src/main/kotlin/com/moneat/monitor/routes/MonitorRoutes.kt
  • backend/src/main/kotlin/com/moneat/monitor/services/MonitorService.kt
  • backend/src/main/kotlin/com/moneat/notifications/services/DiscordService.kt
  • backend/src/main/kotlin/com/moneat/notifications/services/SlackService.kt
  • backend/src/main/kotlin/com/moneat/org/routes/IntegrationRoutes.kt
  • backend/src/main/kotlin/com/moneat/shared/services/SdkVersionService.kt
  • backend/src/main/kotlin/com/moneat/summary/services/SummaryService.kt
  • backend/src/test/kotlin/com/moneat/ai/AiChatServiceTest.kt
  • backend/src/test/kotlin/com/moneat/models/SentryTimestampParsingTest.kt
  • backend/src/test/kotlin/com/moneat/routes/MonitorRoutesMockTest.kt
  • backend/src/test/kotlin/com/moneat/services/DiscordServiceBuildersTest.kt
  • backend/src/test/kotlin/com/moneat/services/EventServiceCoverageTest.kt
  • backend/src/test/kotlin/com/moneat/services/EventServiceTest.kt
  • backend/src/test/kotlin/com/moneat/services/MonitorServiceExtendedTest.kt
  • backend/src/test/kotlin/com/moneat/services/NotificationFormattingTest.kt
  • backend/src/test/kotlin/com/moneat/services/NotificationServiceRoutingTest.kt
  • backend/src/test/kotlin/com/moneat/services/NotificationServiceTest.kt
  • backend/src/test/kotlin/com/moneat/services/SummaryServiceTest.kt
  • ee/backend/detekt.yml
  • ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/AnthropicProvider.kt
  • ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/OpenAiProvider.kt
  • ee/backend/src/main/kotlin/com/moneat/enterprise/mcp/services/SummaryService.kt

Comment thread backend/src/main/kotlin/com/moneat/events/services/EventService.kt
@AdrianLeeElder AdrianLeeElder changed the title Enable detekt rule: ConstructorParameterNaming lint: enable detekt rule: ConstructorParameterNaming Mar 29, 2026
Copy link
Copy Markdown

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
backend/src/test/kotlin/com/moneat/services/EventServiceTest.kt (1)

43-43: 🛠️ Refactor suggestion | 🟠 Major

Replace wildcard import with explicit import.

The wildcard import java.util.* violates the coding guideline requiring explicit imports. Based on usage in this file, only UUID is used.

Proposed fix
-import java.util.*
+import java.util.UUID

As per coding guidelines: "Never use wildcard imports; always use explicit imports (e.g., import com.moneat.models.User instead of import com.moneat.models.*)"

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/src/test/kotlin/com/moneat/services/EventServiceTest.kt` at line 43,
Replace the wildcard import `java.util.*` in EventServiceTest with an explicit
import for only the used symbol: `UUID`; update the import statement to `import
java.util.UUID` (remove the wildcard), save and reformat to satisfy the coding
guideline requiring explicit imports and to prevent accidental wildcard usage
elsewhere.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@backend/src/test/kotlin/com/moneat/services/EventServiceTest.kt`:
- Line 43: Replace the wildcard import `java.util.*` in EventServiceTest with an
explicit import for only the used symbol: `UUID`; update the import statement to
`import java.util.UUID` (remove the wildcard), save and reformat to satisfy the
coding guideline requiring explicit imports and to prevent accidental wildcard
usage elsewhere.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fbfffec0-6903-475b-8535-815b64cd2b71

📥 Commits

Reviewing files that changed from the base of the PR and between e7fb872 and f983f5a.

📒 Files selected for processing (31)
  • backend/detekt.yml
  • backend/src/main/kotlin/com/moneat/ai/AiModels.kt
  • backend/src/main/kotlin/com/moneat/ai/OpenAiClient.kt
  • backend/src/main/kotlin/com/moneat/auth/services/OAuthService.kt
  • backend/src/main/kotlin/com/moneat/events/models/SentryModels.kt
  • backend/src/main/kotlin/com/moneat/events/services/DashboardQueryHelper.kt
  • backend/src/main/kotlin/com/moneat/events/services/EventService.kt
  • backend/src/main/kotlin/com/moneat/incident/services/IncidentIoProvider.kt
  • backend/src/main/kotlin/com/moneat/monitor/models/MonitorModels.kt
  • backend/src/main/kotlin/com/moneat/monitor/routes/MonitorRoutes.kt
  • backend/src/main/kotlin/com/moneat/monitor/services/MonitorService.kt
  • backend/src/main/kotlin/com/moneat/notifications/services/DiscordService.kt
  • backend/src/main/kotlin/com/moneat/notifications/services/SlackService.kt
  • backend/src/main/kotlin/com/moneat/org/routes/IntegrationRoutes.kt
  • backend/src/main/kotlin/com/moneat/shared/services/SdkVersionService.kt
  • backend/src/main/kotlin/com/moneat/summary/services/SummaryService.kt
  • backend/src/test/kotlin/com/moneat/ai/AiChatServiceTest.kt
  • backend/src/test/kotlin/com/moneat/models/SentryTimestampParsingTest.kt
  • backend/src/test/kotlin/com/moneat/routes/MonitorRoutesMockTest.kt
  • backend/src/test/kotlin/com/moneat/services/DiscordServiceBuildersTest.kt
  • backend/src/test/kotlin/com/moneat/services/EventServiceCoverageTest.kt
  • backend/src/test/kotlin/com/moneat/services/EventServiceTest.kt
  • backend/src/test/kotlin/com/moneat/services/MonitorServiceExtendedTest.kt
  • backend/src/test/kotlin/com/moneat/services/NotificationFormattingTest.kt
  • backend/src/test/kotlin/com/moneat/services/NotificationServiceRoutingTest.kt
  • backend/src/test/kotlin/com/moneat/services/NotificationServiceTest.kt
  • backend/src/test/kotlin/com/moneat/services/SummaryServiceTest.kt
  • ee/backend/detekt.yml
  • ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/AnthropicProvider.kt
  • ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/OpenAiProvider.kt
  • ee/backend/src/main/kotlin/com/moneat/enterprise/mcp/services/SummaryService.kt
✅ Files skipped from review due to trivial changes (10)
  • backend/detekt.yml
  • ee/backend/detekt.yml
  • backend/src/main/kotlin/com/moneat/ai/OpenAiClient.kt
  • backend/src/test/kotlin/com/moneat/ai/AiChatServiceTest.kt
  • backend/src/test/kotlin/com/moneat/models/SentryTimestampParsingTest.kt
  • backend/src/test/kotlin/com/moneat/services/NotificationServiceTest.kt
  • backend/src/main/kotlin/com/moneat/incident/services/IncidentIoProvider.kt
  • backend/src/test/kotlin/com/moneat/services/DiscordServiceBuildersTest.kt
  • backend/src/test/kotlin/com/moneat/routes/MonitorRoutesMockTest.kt
  • backend/src/main/kotlin/com/moneat/shared/services/SdkVersionService.kt
🚧 Files skipped from review as they are similar to previous changes (13)
  • backend/src/main/kotlin/com/moneat/monitor/routes/MonitorRoutes.kt
  • backend/src/main/kotlin/com/moneat/org/routes/IntegrationRoutes.kt
  • backend/src/test/kotlin/com/moneat/services/NotificationServiceRoutingTest.kt
  • backend/src/main/kotlin/com/moneat/auth/services/OAuthService.kt
  • ee/backend/src/main/kotlin/com/moneat/enterprise/mcp/services/SummaryService.kt
  • backend/src/test/kotlin/com/moneat/services/EventServiceCoverageTest.kt
  • backend/src/main/kotlin/com/moneat/notifications/services/DiscordService.kt
  • ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/AnthropicProvider.kt
  • backend/src/main/kotlin/com/moneat/ai/AiModels.kt
  • ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/OpenAiProvider.kt
  • backend/src/main/kotlin/com/moneat/monitor/models/MonitorModels.kt
  • backend/src/main/kotlin/com/moneat/events/services/EventService.kt
  • backend/src/main/kotlin/com/moneat/events/models/SentryModels.kt

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backend/src/main/kotlin/com/moneat/ai/AiModels.kt`:
- Line 170: Replace the magic literal 2048 used as the default for the maxTokens
property with a named constant: define a top-level or companion-object const val
(e.g., DEFAULT_MAX_TOKENS or MAX_TOKENS_DEFAULT = 2048) in the same AiModels.kt
file and then change the property declaration "@SerialName("max_tokens") val
maxTokens: Int = 2048" to use that constant (e.g., = DEFAULT_MAX_TOKENS); keep
the constant visible to the class and add a brief descriptive name per project
naming conventions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5e3127a1-c847-4f75-90d6-09c2020956e0

📥 Commits

Reviewing files that changed from the base of the PR and between f983f5a and 39a8ba7.

📒 Files selected for processing (31)
  • backend/detekt.yml
  • backend/src/main/kotlin/com/moneat/ai/AiModels.kt
  • backend/src/main/kotlin/com/moneat/ai/OpenAiClient.kt
  • backend/src/main/kotlin/com/moneat/auth/services/OAuthService.kt
  • backend/src/main/kotlin/com/moneat/events/models/SentryModels.kt
  • backend/src/main/kotlin/com/moneat/events/services/DashboardQueryHelper.kt
  • backend/src/main/kotlin/com/moneat/events/services/EventService.kt
  • backend/src/main/kotlin/com/moneat/incident/services/IncidentIoProvider.kt
  • backend/src/main/kotlin/com/moneat/monitor/models/MonitorModels.kt
  • backend/src/main/kotlin/com/moneat/monitor/routes/MonitorRoutes.kt
  • backend/src/main/kotlin/com/moneat/monitor/services/MonitorService.kt
  • backend/src/main/kotlin/com/moneat/notifications/services/DiscordService.kt
  • backend/src/main/kotlin/com/moneat/notifications/services/SlackService.kt
  • backend/src/main/kotlin/com/moneat/org/routes/IntegrationRoutes.kt
  • backend/src/main/kotlin/com/moneat/shared/services/SdkVersionService.kt
  • backend/src/main/kotlin/com/moneat/summary/services/SummaryService.kt
  • backend/src/test/kotlin/com/moneat/ai/AiChatServiceTest.kt
  • backend/src/test/kotlin/com/moneat/models/SentryTimestampParsingTest.kt
  • backend/src/test/kotlin/com/moneat/routes/MonitorRoutesMockTest.kt
  • backend/src/test/kotlin/com/moneat/services/DiscordServiceBuildersTest.kt
  • backend/src/test/kotlin/com/moneat/services/EventServiceCoverageTest.kt
  • backend/src/test/kotlin/com/moneat/services/EventServiceTest.kt
  • backend/src/test/kotlin/com/moneat/services/MonitorServiceExtendedTest.kt
  • backend/src/test/kotlin/com/moneat/services/NotificationFormattingTest.kt
  • backend/src/test/kotlin/com/moneat/services/NotificationServiceRoutingTest.kt
  • backend/src/test/kotlin/com/moneat/services/NotificationServiceTest.kt
  • backend/src/test/kotlin/com/moneat/services/SummaryServiceTest.kt
  • ee/backend/detekt.yml
  • ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/AnthropicProvider.kt
  • ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/OpenAiProvider.kt
  • ee/backend/src/main/kotlin/com/moneat/enterprise/mcp/services/SummaryService.kt
✅ Files skipped from review due to trivial changes (12)
  • ee/backend/detekt.yml
  • backend/src/main/kotlin/com/moneat/ai/OpenAiClient.kt
  • ee/backend/src/main/kotlin/com/moneat/enterprise/mcp/services/SummaryService.kt
  • backend/src/test/kotlin/com/moneat/services/DiscordServiceBuildersTest.kt
  • backend/src/test/kotlin/com/moneat/models/SentryTimestampParsingTest.kt
  • backend/src/test/kotlin/com/moneat/ai/AiChatServiceTest.kt
  • backend/src/test/kotlin/com/moneat/services/NotificationFormattingTest.kt
  • backend/src/main/kotlin/com/moneat/incident/services/IncidentIoProvider.kt
  • backend/src/test/kotlin/com/moneat/services/NotificationServiceRoutingTest.kt
  • backend/src/main/kotlin/com/moneat/notifications/services/DiscordService.kt
  • backend/src/test/kotlin/com/moneat/routes/MonitorRoutesMockTest.kt
  • backend/src/test/kotlin/com/moneat/services/EventServiceCoverageTest.kt
🚧 Files skipped from review as they are similar to previous changes (11)
  • backend/detekt.yml
  • backend/src/test/kotlin/com/moneat/services/NotificationServiceTest.kt
  • backend/src/main/kotlin/com/moneat/monitor/routes/MonitorRoutes.kt
  • backend/src/main/kotlin/com/moneat/org/routes/IntegrationRoutes.kt
  • backend/src/test/kotlin/com/moneat/services/SummaryServiceTest.kt
  • backend/src/test/kotlin/com/moneat/services/MonitorServiceExtendedTest.kt
  • ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/AnthropicProvider.kt
  • ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/OpenAiProvider.kt
  • backend/src/main/kotlin/com/moneat/notifications/services/SlackService.kt
  • backend/src/main/kotlin/com/moneat/events/services/EventService.kt
  • backend/src/main/kotlin/com/moneat/events/models/SentryModels.kt

val model: String,
val messages: List<OpenAiMessage>,
val max_tokens: Int = 2048,
@SerialName("max_tokens") val maxTokens: Int = 2048,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Replace the 2048 default with a named constant.

Line 170 introduces an inline magic number for maxTokens; please lift it to a constant.

♻️ Proposed fix
+private const val DEFAULT_MAX_TOKENS = 2048
+
 `@Serializable`
 data class OpenAiChatRequest(
     val model: String,
     val messages: List<OpenAiMessage>,
-    `@SerialName`("max_tokens") val maxTokens: Int = 2048,
+    `@SerialName`("max_tokens") val maxTokens: Int = DEFAULT_MAX_TOKENS,
     val temperature: Double = 0.3,
     `@SerialName`("response_format") val responseFormat: OpenAiResponseFormat? = null
 )

As per coding guidelines: "Don't use magic numbers; use named constants instead (e.g., const val MAX_RETRIES = 5)."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@SerialName("max_tokens") val maxTokens: Int = 2048,
private const val DEFAULT_MAX_TOKENS = 2048
`@Serializable`
data class OpenAiChatRequest(
val model: String,
val messages: List<OpenAiMessage>,
`@SerialName`("max_tokens") val maxTokens: Int = DEFAULT_MAX_TOKENS,
val temperature: Double = 0.3,
`@SerialName`("response_format") val responseFormat: OpenAiResponseFormat? = null
)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/src/main/kotlin/com/moneat/ai/AiModels.kt` at line 170, Replace the
magic literal 2048 used as the default for the maxTokens property with a named
constant: define a top-level or companion-object const val (e.g.,
DEFAULT_MAX_TOKENS or MAX_TOKENS_DEFAULT = 2048) in the same AiModels.kt file
and then change the property declaration "@SerialName("max_tokens") val
maxTokens: Int = 2048" to use that constant (e.g., = DEFAULT_MAX_TOKENS); keep
the constant visible to the class and add a brief descriptive name per project
naming conventions.

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/OpenAiProvider.kt (1)

24-24: Extract the touched max-token default into a named constant.

Line 81 still embeds 4096 directly. Since this DTO default is being touched, naming it keeps the provider defaults self-documenting.

♻️ Proposed refactor
 private val logger = KotlinLogging.logger {}
+private const val DEFAULT_OPENAI_MAX_TOKENS = 4096
 
 class OpenAiProvider : LlmProvider {
@@
     `@Serializable` data class OpenAiRequest(
         val model: String,
         val messages: List<OpenAiMsg>,
-        `@SerialName`("max_tokens") val maxTokens: Int = 4096,
+        `@SerialName`("max_tokens") val maxTokens: Int = DEFAULT_OPENAI_MAX_TOKENS,
         val temperature: Double = 0.3,
         `@SerialName`("response_format") val responseFormat: OpenAiFormat? = null,
     )

As per coding guidelines, "Don't use magic numbers; use named constants instead."

Also applies to: 78-84

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/OpenAiProvider.kt`
at line 24, Extract the magic number 4096 into a named constant (e.g., private
const val DEFAULT_MAX_TOKENS = 4096) in OpenAiProvider.kt (place it near the
existing logger/private vals), then replace the hard-coded 4096 used as the
DTO/default max-tokens value (the embedded literal around where the DTO or
parameter maxTokens is defined and the code region touched in the OpenAiProvider
class) with that constant so the provider default is self-documenting and
consistent across the 78-84 / ~81 code region.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/OpenAiProvider.kt`:
- Line 24: Extract the magic number 4096 into a named constant (e.g., private
const val DEFAULT_MAX_TOKENS = 4096) in OpenAiProvider.kt (place it near the
existing logger/private vals), then replace the hard-coded 4096 used as the
DTO/default max-tokens value (the embedded literal around where the DTO or
parameter maxTokens is defined and the code region touched in the OpenAiProvider
class) with that constant so the provider default is self-documenting and
consistent across the 78-84 / ~81 code region.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 479dd6fb-dedc-4b24-ba38-c651e0afa30d

📥 Commits

Reviewing files that changed from the base of the PR and between 39a8ba7 and b73f886.

📒 Files selected for processing (6)
  • backend/src/main/kotlin/com/moneat/events/services/DashboardQueryHelper.kt
  • backend/src/main/kotlin/com/moneat/events/services/EventService.kt
  • backend/src/main/kotlin/com/moneat/monitor/services/MonitorService.kt
  • ee/backend/detekt.yml
  • ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/AnthropicProvider.kt
  • ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/OpenAiProvider.kt
✅ Files skipped from review due to trivial changes (1)
  • ee/backend/detekt.yml
🚧 Files skipped from review as they are similar to previous changes (2)
  • backend/src/main/kotlin/com/moneat/monitor/services/MonitorService.kt
  • ee/backend/src/main/kotlin/com/moneat/enterprise/ai/llm/providers/AnthropicProvider.kt

@github-actions
Copy link
Copy Markdown
Contributor

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.

1 participant