Repository navigation
Conversation
WalkthroughOpenAI response timestamps now use ChangesUnix timestamp handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
dto/openai_responses_created_at_test.go (1)
11-64: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winTests cover the decimal-timestamp regression well; consider adding
nulland round-trip marshal cases.The
null→0path inparseUnixTimestampJSONand theMarshalJSONinteger output are both untested. Adding anullcase and a marshal round-trip would protect these invariants against future changes.💡 Suggested additional test cases
// Add to the table in TestOpenAIResponsesResponseCreatedAtAcceptsFloat: { name: "integer timestamp", payload: `{"id":"resp_1","object":"response","created_at":1710000000}`, expected: 1710000000, }, { name: "null timestamp", payload: `{"id":"resp_1","object":"response","created_at":null}`, expected: 0, }, // New test for MarshalJSON round-trip: func TestUnixTimestampMarshalJSON(t *testing.T) { t.Parallel() ts := UnixTimestamp(1710000000) data, err := ts.MarshalJSON() require.NoError(t, err) assert.Equal(t, []byte("1710000000"), data) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@dto/openai_responses_created_at_test.go` around lines 11 - 64, Extend TestOpenAIResponsesResponseCreatedAtAcceptsFloat with integer and null created_at payload cases, expecting the integer value and zero respectively. Add TestUnixTimestampMarshalJSON to verify UnixTimestamp.MarshalJSON returns the decimal integer representation for a known timestamp.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@dto/values.go`:
- Line 120: Update the upper-bound checks in the parsing logic at both
occurrences to reject values equal to the rounded MaxInt64 boundary by using a
non-strict comparison; keep the existing lower-bound validation unchanged.
---
Nitpick comments:
In `@dto/openai_responses_created_at_test.go`:
- Around line 11-64: Extend TestOpenAIResponsesResponseCreatedAtAcceptsFloat
with integer and null created_at payload cases, expecting the integer value and
zero respectively. Add TestUnixTimestampMarshalJSON to verify
UnixTimestamp.MarshalJSON returns the decimal integer representation for a known
timestamp.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ec8bfc7d-f24f-401b-87ab-8214a4aba5a0
📒 Files selected for processing (7)
dto/openai_compaction.godto/openai_response.godto/openai_responses_created_at_test.godto/values.gorelay/channel/openai/chat_via_responses.goservice/relayconvert/internal/oai_chat/to_oai_responses_resp.goservice/relayconvert/internal/oai_chat/to_oai_responses_stream_resp.go
19fba50 to
5178bcf
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@service/relayconvert/internal/oai_chat/to_oai_responses_resp.go`:
- Around line 216-221: Update the string parsing branch in the timestamp
conversion logic to distinguish a successfully parsed Unix timestamp of zero
from parse failure. Replace the `common.String2Int`/`parsed != 0` check with an
error-aware parse or equivalent success indicator, returning
`dto.UnixTimestamp(0)` for valid `"0"` input while retaining the current-time
fallback only for invalid values.
- Around line 208-215: Validate float64 and float32 inputs in the timestamp
conversion switch before passing them to dto.UnixTimestamp, rejecting NaN,
infinities, and values outside the supported timestamp range. Preserve the
existing direct conversions for valid finite values and the int/int64 cases.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 55a79db6-c213-4466-b64a-322f5171f948
📒 Files selected for processing (8)
dto/openai_compaction.godto/openai_response.godto/openai_responses_created_at_test.godto/values.gorelay/channel/openai/chat_via_responses.goservice/relayconvert/internal/oai_chat/to_oai_responses_resp.goservice/relayconvert/internal/oai_chat/to_oai_responses_resp_test.goservice/relayconvert/internal/oai_chat/to_oai_responses_stream_resp.go
🚧 Files skipped from review as they are similar to previous changes (6)
- dto/openai_compaction.go
- service/relayconvert/internal/oai_chat/to_oai_responses_stream_resp.go
- dto/openai_response.go
- relay/channel/openai/chat_via_responses.go
- dto/openai_responses_created_at_test.go
- dto/values.go
22bb372 to
aa85f26
Compare
aa85f26 to
772e2c2
Compare
移植自上游 PR QuantumNous#6165。OpenAIResponsesResponse/CompactionResponse 的 created_at 是 int,上游返回 1783476848.2598 这类浮点值时整条 响应解析失败。新增 dto.UnixTimestamp 类型(接受 int/float/string, 截断取整,含 NaN/Inf/越界防护),替换两个响应结构的 CreatedAt, chatCreatedAt 同步改造并加 UnixTimestamp 分支处理进程内往返。 与原 PR 差异:UnixTimestamp 的 Unmarshaler 沿用 dto/values.go 的 encoding/json(该文件是围绕 json.Number 的自定义 Unmarshaler 适配层, 属项目既有例外),与文件内 StringValue/IntValue/BoolValue 一致, 不引入 dto→common 依赖。补 dto 层解析测试与转换往返测试。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
51fdfc5 to
2b6f1df
Compare
经过/v1/responses的请求报错,相关报错信息如下
📝 变更描述 / Description
上游返回的created_at时间存在小数的情况,导致反序列化失败报错,本PR把created_at统一为int64,截断到整数秒,解决了类型反序列化错误。本次变更覆盖了/v1/responses、/v1/responses/compact、以及 responses<->chat 互转链路
🚀 变更类型 / Type of change
🔗 关联任务 / Related Issue
可能有关的PR #5787
✅ 提交前检查项 / Checklist
Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。📸 运行证明 / Proof of Work
dto/openai_responses_created_at_test.go 增加了测试用例
Summary by CodeRabbit
Summary by CodeRabbit
Bug Fixes
created_attimestamp handling across responses and streams when provided as integers, decimals, numeric strings, or fractional values.NaN/±Inf, while enforcing valid Unix-second ranges and truncating fractional seconds toward zero.Tests