Repository navigation
Description
Summary
The conversations table columns are decoded by hand in six places across the two backends that share its schema: internal/platform/storage/sql_store.go (loadConversationMetadata, ListConversations, ListConversationsNeedingTitles) and internal/platform/storage/d1.go (loadConversationMetadata, ListConversations, mapTitleSummaryRow). Every copy repeats the same blocks: build convdomain.SessionTokenStats with TotalTokens: totalInputTokens + totalOutputTokens, unmarshal cost_stats unless it is "" or "{}" and fall back to a zero SessionCostStats on error, unmarshal models unless it is "" or "[]" and keep only the first entry, and unmarshal tags unless it is "" or "[]" with the error discarded (_ = json.Unmarshal(...)).
The copies have already drifted. D1's mapTitleSummaryRow sets RequestCount: summary.MessageCount / 2 and its query does not select request_count, while sqlStore.ListConversationsNeedingTitles reads the column. Any change to the empty-JSON sentinels or to what a corrupt column means has to be made six times.
Principle: clean-code "duplication" (copy-pasted function bodies - extract the shared logic once) and clean-code "error handling" (one place decides what a corrupt JSON column decodes to). The fix stays inside the storage package: a few unexported helpers, no new types, no interface or schema change.
Acceptance Criteria
-
internal/platform/storagehas unexported helpers that own the sentinel checks and fallbacks once, for exampletokenStats(input, output, requests int) convdomain.SessionTokenStats,decodeCostStats(raw string) convdomain.SessionCostStats,firstModel(raw string) stringanddecodeTags(raw string) []string. - Before:
sqlStore.loadConversationMetadata,sqlStore.ListConversationsandsqlStore.ListConversationsNeedingTitlesinline thecostStatsJSON != "" && costStatsJSON != "{}",modelsJSONandtagsJSONblocks and theSessionTokenStats{...}literal. After: they call the helpers. - Before:
D1Storage.loadConversationMetadata,D1Storage.ListConversationsandmapTitleSummaryRowcarry their own copies of the same blocks. After: they call the same helpers. - Behavior is unchanged: a corrupt
cost_statsstill yields a zeroSessionCostStats, a corruptmodelsstill leavesModelempty, a corrupttagsstill leavesTagsnil, and D1's title path keepsRequestCount: MessageCount / 2(aligning it with the SQL store is a separate decision). - A table-driven test covers each helper with an empty string, the empty-JSON sentinel, valid JSON and corrupt JSON.
- Existing tests still pass.
Activity
edenreich commentedon Nov 20, 2026
@infer can you work on this? use /ponytail:ponytail /domain-driven-design /go /go-concurrency
inference-gateway-maintainer commentedon Nov 20, 2026
Model:
ollama_cloud/glm-5.3-flash· Action:v0.59.11· CLI:v0.263.0· Gateway:v0.68.0· View JobTodos
Pull Request
#1923
✅ Infer Result: Success
All todos complete, tree clean, everything pushed. Final summary:
Done - refactor extracted the shared conversation column decoding (PR #1923 ready for review)
PR: #1923 (branch
fix/issue-1919, 2 commits)What changed
internal/platform/storage/conversation_decode.gowith four unexported helpers owning the sentinel checks and fallbacks exactly once:tokenStats(input, output, requests int) convdomain.SessionTokenStats,decodeCostStats(raw string),firstModel(raw string),decodeTags(raw string).sqlStore.loadConversationMetadata,sqlStore.ListConversations,sqlStore.ListConversationsNeedingTitles(sql_store.go) andD1Storage.loadConversationMetadata,D1Storage.ListConversations,mapTitleSummaryRow(d1.go). Net -2.7k bytes of duplicated blocks.cost_statsstill yields a zeroSessionCostStats, corruptmodelsstill leavesModelempty, corrupttagsstill leavesTagsnil (including encoding/json's in-place partial-decode quirk, now locked by a test:["code",3]keeps["code",""]), and D1's title path still usesRequestCount: MessageCount / 2per the issue - aligning it with the SQL store remains a separate decision.conversation_decode_test.go) cover each helper with an empty column, the empty-JSON sentinel ({}/[]), valid JSON and corrupt JSON.TestNewJsonlStorage's "expands tilde in path" subtest now runs witht.Setenv("HOME", t.TempDir())- it was failing with "permission denied" on this runner because it mkdirs under the real$HOME, which the sandbox denies (it passes in real CI; recorded as a known pitfall in memory).Verification
go test ./internal/platform/storage- all green (new helper tests + existing conformance suites)go build ./...- module compilestask precommit:run(the CI gate: mod tidy, mocks, fmt, lint:imports, golangci-lint) - 0 issues, both commits landed through the pre-commit hookSkipped: full
go test ./...locally (several other packages fail here purely on sandbox-denied$HOMEwrites, unrelated to this diff - CI will cover them), and D1-vs-SQLRequestCountalignment was deliberately left out as the issue specifies. Risk: if anyone ever wanted "corrupt tags always means nil" even for partly valid arrays, that is a deliberate behavior change this refactor intentionally does not make.Model:
ollama_cloud/glm-5.3-flash· Action:v0.59.11· CLI:v0.263.0· Gateway:v0.68.0· Exit Code:0· Duration: 7m 39sTokens: 3,594,562 in · 35,688 out · 3,630,250 total (37 requests)
Tool calls: 60 total · 100% success rate
Traces
Stats
Triggered by edenreich · Infer Action · OSS
inference-gateway-releaser commentedon Nov 20, 2026
🎉 This issue has been resolved in version 0.265.4 🎉
The release is available on:
Your semantic-release bot 📦🚀