Skip to content

fix: accept scientific-notation numeric created_at in responses stream#2946

Open
seefs001 wants to merge 1 commit intoQuantumNous:mainfrom
seefs001:fix/scientific-notation-created_at
Open

fix: accept scientific-notation numeric created_at in responses stream#2946
seefs001 wants to merge 1 commit intoQuantumNous:mainfrom
seefs001:fix/scientific-notation-created_at

Conversation

@seefs001
Copy link
Collaborator

@seefs001 seefs001 commented Feb 13, 2026

fix #2267

兼容这种不知道是哪家莫名其妙的供应商返回的科学计数法形式的created_at

如果是什么野鸡渠道那就不合并,先放着

Summary by CodeRabbit

  • Bug Fixes
    • Improved timestamp handling in API responses with enhanced validation and JSON serialization support.
    • Added support for scientific notation in timestamp values.
    • Strengthened error handling for invalid timestamp formats in responses.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 13, 2026

Walkthrough

This PR introduces a new UnixTimestamp type with custom JSON (un)marshalling capabilities to handle Unix timestamps, including those in scientific notation. The type is applied to CreatedAt fields in OpenAI response DTOs, and downstream code is updated to access the value via a new .Int64() method.

Changes

Cohort / File(s) Summary
Timestamp Type Definition
dto/values.go
Adds new UnixTimestamp type (int64) with UnmarshalJSON() for numeric JSON parsing (including json.Number), MarshalJSON() for serialization, and Int64() accessor. Handles null/empty values and rejects string inputs. Imports bytes and fmt.
DTO Field Updates
dto/openai_compaction.go, dto/openai_response.go
Updates CreatedAt field type from int to UnixTimestamp in OpenAIResponsesCompactionResponse and OpenAIResponsesResponse structs.
Tests
dto/values_test.go
Adds 61 lines of unit tests covering UnixTimestamp unmarshalling from integers and scientific notation, string rejection, and nested timestamp parsing in response structures.
Integration
relay/channel/openai/chat_via_responses.go
Updates two locations in OaiResponsesToChatStreamHandler to extract CreatedAt via .Int64() method instead of direct int64 cast.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A timestamp's tale in scientific dress,
Once caused the streams to reconnect and stress,
But now UnixTimestamp holds the key,
JSON numbers parse with perfect harmony! ✨

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding support for scientific-notation numeric created_at fields in responses stream, which directly addresses the PR's objective.
Linked Issues check ✅ Passed The PR implements type-safe handling of created_at timestamps in scientific notation through UnixTimestamp type, addressing the stream disconnection issue (#2267) caused by improper timestamp parsing.
Out of Scope Changes check ✅ Passed All changes are directly related to supporting scientific-notation timestamps: new UnixTimestamp type, updated DTO fields, comprehensive tests, and handler updates. No extraneous modifications present.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

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.

Codex使用问题

1 participant

Comments