Repository navigation
refactor(storage): decode conversation columns through shared helpers - #1923
Merged
Merged
Conversation
inference-gateway-maintainer
Bot
marked this pull request as ready for review
November 20, 2026 14:58
inference-gateway-maintainer
Bot
requested a review
from a team
as a code owner
November 20, 2026 14:58
6 tasks
Contributor
|
🎉 This PR is included in version 0.265.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #1919
Summary
The conversations table columns were decoded by hand in six places across the two backends that share the schema, and the copies had already drifted (D1's title path vs the SQL store's request_count). This PR extracts the shared logic once into four unexported helpers inside
internal/platform/storageso one place decides what the empty-JSON sentinels and corrupt columns mean. Behavior is unchanged one-for-one, D1's title path keepsRequestCount: MessageCount / 2per the issue (aligning it with the SQL store is a separate decision). no docs ticket: internal-only refactorChanges
internal/platform/storage/conversation_decode.gowith the four helpers owning the sentinel checks and fallbacks:tokenStats(input, output, requests int),decodeCostStats(raw string),firstModel(raw string)anddecodeTags(raw string).sqlStore.loadConversationMetadata,sqlStore.ListConversationsandsqlStore.ListConversationsNeedingTitlescall the helpers instead of inlining thecostStatsJSON/modelsJSON/tagsJSONblocks and theSessionTokenStatsliteral.D1Storage.loadConversationMetadata,D1Storage.ListConversationsandmapTitleSummaryRowcall the same helpers, removing their drifted copies.cost_statsyields a zeroSessionCostStats, corruptmodelsleavesModelempty, corrupttagsleavesTagsnil, and the in-place unmarshal ofdecodeTagskeeps whatever decoded before an error (as the old code did with_ = json.Unmarshal).conversation_decode_test.go) cover each helper with an empty column, the empty-JSON sentinel ({}for cost stats,[]for models/tags), valid JSON and corrupt JSON, plus the partial-decode edge (["code",3]keeps["code",""]).TestNewJsonlStorage's "expands tilde in path" subtest now runs witht.Setenv("HOME", t.TempDir())so it no longer mkdirs under the real HOME (it failed with permission denied on the agent CI runner; it passes on real CI).Verification
go test ./internal/platform/storage- all green including the new helper tests and the existing conformance suites.go build ./...- module compiles.task precommit:run- mod tidy, mocks, fmt, lint:imports and golangci-lint pass with 0 issues.