Fix/model status mysql query#22
Conversation
📝 WalkthroughWalkthroughThe PR adds cache-aware status retrieval methods to the model status service while introducing SQL timestamp normalization to handle millisecond/second unit mismatches in logs. It moves shared type conversion helpers to a new utility module and includes comprehensive test coverage for SQL generation patterns. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.11.4)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
backend/internal/service/type_conversions.go (1)
6-32: Consider handling unsigned integer types for broader database driver compatibility.Some database drivers may return unsigned integer types (
uint,uint32,uint64) for COUNT or similar aggregate results. Currently these would fall through to thedefaultcase and return0.♻️ Optional: Add unsigned integer support
case float32: return int64(val) + case uint64: + return int64(val) + case uint: + return int64(val) + case uint32: + return int64(val) case string: var n int64🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/internal/service/type_conversions.go` around lines 6 - 32, toInt64 currently ignores unsigned integer types returned by some DB drivers; update the function to handle uint, uint8, uint16, uint32, uint64 (and optionally uintptr) by adding cases for those types in the type switch (e.g., case uint64: if val > math.MaxInt64 { return math.MaxInt64 } else { return int64(val) }) and similarly cast other uint* types to int64; remember to import math for MaxInt64 to safely clamp uint64 values that would overflow int64.backend/internal/service/model_status.go (1)
138-143: Global state may complicate testing and hot schema changes.The
sync.Oncepattern caches the column existence check for the process lifetime. This is efficient but means:
- Schema migrations adding
completion_tokenswon't be detected until service restart- Tests sharing this global state may have interdependencies
This is likely acceptable given schema changes typically require deployment, but worth noting.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/internal/service/model_status.go` around lines 138 - 143, The package-level caching via logsCompletionTokensOnce and logsHasCompletionTokensCol in logsHaveCompletionTokens() prevents detecting schema changes and interferes with tests; refactor by moving the cache into ModelStatusService (add a logsCompletionTokensOnce sync.Once and logsHasCompletionTokensCol bool as fields) or provide a test-only reset (e.g., ResetLogsCompletionTokensCache) and change logsHaveCompletionTokens() to call s.db.ColumnExists("logs","completion_tokens") inside that instance-level once so s.db.ColumnExists is invoked per service instance and test suites can reset the cache as needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@backend/internal/service/model_status.go`:
- Around line 138-143: The package-level caching via logsCompletionTokensOnce
and logsHasCompletionTokensCol in logsHaveCompletionTokens() prevents detecting
schema changes and interferes with tests; refactor by moving the cache into
ModelStatusService (add a logsCompletionTokensOnce sync.Once and
logsHasCompletionTokensCol bool as fields) or provide a test-only reset (e.g.,
ResetLogsCompletionTokensCache) and change logsHaveCompletionTokens() to call
s.db.ColumnExists("logs","completion_tokens") inside that instance-level once so
s.db.ColumnExists is invoked per service instance and test suites can reset the
cache as needed.
In `@backend/internal/service/type_conversions.go`:
- Around line 6-32: toInt64 currently ignores unsigned integer types returned by
some DB drivers; update the function to handle uint, uint8, uint16, uint32,
uint64 (and optionally uintptr) by adding cases for those types in the type
switch (e.g., case uint64: if val > math.MaxInt64 { return math.MaxInt64 } else
{ return int64(val) }) and similarly cast other uint* types to int64; remember
to import math for MaxInt64 to safely clamp uint64 values that would overflow
int64.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: a44edf39-78da-4d20-a625-1e48b1dec6a0
📒 Files selected for processing (5)
backend/internal/handler/model_status.gobackend/internal/service/model_status.gobackend/internal/service/model_status_test.gobackend/internal/service/type_conversions.gobackend/internal/service/user_management.go
💤 Files with no reviewable changes (1)
- backend/internal/service/user_management.go
Summary by CodeRabbit
New Features
Bug Fixes
Tests