Skip to content

refactor(storage): decode conversation columns through shared helpers - #1923

Merged
edenreich merged 2 commits into
mainfrom
fix/issue-1919
Nov 20, 2026
Merged

edenreich merged 2 commits into
mainfrom
fix/issue-1919

Conversation

@inference-gateway-maintainer

Copy link
Copy Markdown
Contributor

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/storage so one place decides what the empty-JSON sentinels and corrupt columns mean. Behavior is unchanged one-for-one, D1's title path keeps RequestCount: MessageCount / 2 per the issue (aligning it with the SQL store is a separate decision). no docs ticket: internal-only refactor

Changes

  • New internal/platform/storage/conversation_decode.go with the four helpers owning the sentinel checks and fallbacks: tokenStats(input, output, requests int), decodeCostStats(raw string), firstModel(raw string) and decodeTags(raw string).
  • sqlStore.loadConversationMetadata, sqlStore.ListConversations and sqlStore.ListConversationsNeedingTitles call the helpers instead of inlining the costStatsJSON/modelsJSON/tagsJSON blocks and the SessionTokenStats literal.
  • D1Storage.loadConversationMetadata, D1Storage.ListConversations and mapTitleSummaryRow call the same helpers, removing their drifted copies.
  • Behavior preserved: corrupt cost_stats yields a zero SessionCostStats, corrupt models leaves Model empty, corrupt tags leaves Tags nil, and the in-place unmarshal of decodeTags keeps whatever decoded before an error (as the old code did with _ = json.Unmarshal).
  • New table-driven tests (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",""]).
  • Drive-by: TestNewJsonlStorage's "expands tilde in path" subtest now runs with t.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.

@github-project-automation github-project-automation Bot moved this to Todo in 2026 Nov 20, 2026
@inference-gateway-maintainer
inference-gateway-maintainer Bot marked this pull request as ready for review November 20, 2026 14:58
@inference-gateway-maintainer
inference-gateway-maintainer Bot requested a review from a team as a code owner November 20, 2026 14:58
@edenreich
edenreich merged commit b65d3e2 into main Nov 20, 2026
1 check passed
@edenreich
edenreich deleted the fix/issue-1919 branch November 20, 2026 15:36
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.265.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Nov 20, 2026
@edenreich edenreich moved this from Todo to Done in 2026 Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[TASK] Refactor conversation column decoding shared by the SQL and D1 stores

1 participant