Repository navigation
Port agent PRs to GO - 5 - #16667
Port agent PRs to GO - 5#16667
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds query-parameter bounds checks, updates OpenAI completion timestamp handling, extends object-field parsing, and changes agent chat-completions to support both SSE streaming and aggregated JSON responses. ChangesMemory and OpenAI Chat Fixes
Agent chat-completions response modes
Object field parsing in user fill-up
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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)
internal/service/openai_chat.go (1)
81-81: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win
resp.Createdis never populated, sogetCreatedOrDefaultalways falls back totime.Now().The struct literal building
resp(Lines 436-442) never setsCreated, so at Line 475resp.Createdis alwaysnil, andgetCreatedOrDefaultwill always execute itstime.Now().Unix()fallback branch. This makes the pointer indirection and the non-nil branch of the helper effectively dead code for this call path, and also shifts the captured timestamp from response-construction time to JSON-serialization time (a minor timing drift versus the prior behavior).If the goal is only to guard against a nil value from some other producer, consider directly assigning
Created: nowPtrwhen constructingresphere so the intent is explicit, or clarify (e.g., via comment) that this path intentionally always defers totime.Now().♻️ Possible fix: populate Created explicitly
+ now := time.Now().Unix() resp := &OpenAICompletionResponse{ Model: openaiReq.Model, Content: content, PromptTokens: promptTokens, CompletionTokens: completionTokens, TotalTokens: promptTokens + completionTokens, + Created: &now, }Also applies to: 436-442, 475-475, 846-852
🤖 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 `@internal/service/openai_chat.go` at line 81, The resp.Created field in the OpenAI chat response path is never set, so getCreatedOrDefault always takes the time.Now() fallback and the non-nil branch is dead code. Update the resp struct literal in the response-building logic to populate Created explicitly (for example from the same captured timestamp used for the response) so the intent is clear, and verify the helper is still appropriate for any other callers that may pass a nil Created. If the fallback is intentional here, add a brief comment near resp construction or getCreatedOrDefault to document that this path deliberately relies on the default.
🤖 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 `@internal/handler/memory.go`:
- Around line 941-947: The top_n validation in the memory search handler has two
issues: the error message references page_size instead of top_n, and negative
values are not rejected. Update the argument validation in the handler around
strconv.Atoi/topN so it enforces a valid range for top_n (reject values below 1
as well as above 100), and change the jsonError message to explicitly mention
top_n. Keep the fix localized to the search request parsing path that feeds
h.memoryService.SearchMessage.
---
Nitpick comments:
In `@internal/service/openai_chat.go`:
- Line 81: The resp.Created field in the OpenAI chat response path is never set,
so getCreatedOrDefault always takes the time.Now() fallback and the non-nil
branch is dead code. Update the resp struct literal in the response-building
logic to populate Created explicitly (for example from the same captured
timestamp used for the response) so the intent is clear, and verify the helper
is still appropriate for any other callers that may pass a nil Created. If the
fallback is intentional here, add a brief comment near resp construction or
getCreatedOrDefault to document that this path deliberately relies on the
default.
🪄 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: dc37243b-b0c3-419c-aca1-225bad4f9c99
📒 Files selected for processing (2)
internal/handler/memory.gointernal/service/openai_chat.go
dc47661 to
a828fc7
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
internal/agent/component/userfillup.go (1)
241-249: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winLarge integers in object fields will lose precision.
json.Unmarshalintoanydecodes all JSON numbers asfloat64, so integer values above 2^53 in parsed objects can lose precision.♻️ Proposed fix using json.Number
if isObjectType(m) { if rawStr, ok := m["value"].(string); ok && strings.TrimSpace(rawStr) != "" { - var parsed any - if err := json.Unmarshal([]byte(rawStr), &parsed); err != nil { + var parsed any + dec := json.NewDecoder(strings.NewReader(rawStr)) + dec.UseNumber() + if err := dec.Decode(&parsed); err != nil { return rawStr } return parsed } }If downstream consumers of this field only need the raw value round-tripped (e.g. re-serialized as JSON) rather than numerically manipulated, this may not matter in practice — please confirm the expected use of object-typed field values downstream.
🤖 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 `@internal/agent/component/userfillup.go` around lines 241 - 249, `userfillup.go` in the object-field parsing path is losing precision because `json.Unmarshal` into `parsed any` turns JSON numbers into `float64`. Update the parsing logic in the `isObjectType` block to preserve numeric fidelity, for example by decoding with a `json.Decoder` configured for `UseNumber` and carrying `json.Number` through, or otherwise ensure object-typed values round-trip without precision loss. Check the downstream consumers of the value returned from this branch to confirm they expect preserved JSON values rather than native numeric arithmetic.
🤖 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 `@internal/agent/component/userfillup.go`:
- Around line 264-270: Update the doc comment on isObjectType so it describes
the Go behavior directly instead of referencing fillup.py or migration history;
keep it focused on what the helper does for the type field in the current Go
codebase and remove the Python implementation comparison.
- Around line 222-224: The rules comment in userfillup.go is anchored to the
Python migration source instead of describing the current Go behavior. Update
the doc comment near the fillup handling logic to reflect the Go runtime rules
directly, using the relevant symbols in this file that implement the behavior
rather than referencing fillup.py; keep it aligned with the current types and
parsing path for file-like dicts and object/string JSON handling.
---
Nitpick comments:
In `@internal/agent/component/userfillup.go`:
- Around line 241-249: `userfillup.go` in the object-field parsing path is
losing precision because `json.Unmarshal` into `parsed any` turns JSON numbers
into `float64`. Update the parsing logic in the `isObjectType` block to preserve
numeric fidelity, for example by decoding with a `json.Decoder` configured for
`UseNumber` and carrying `json.Number` through, or otherwise ensure object-typed
values round-trip without precision loss. Check the downstream consumers of the
value returned from this branch to confirm they expect preserved JSON values
rather than native numeric arithmetic.
🪄 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: 11f3346d-db2a-4a11-911f-b01d6a40474a
📒 Files selected for processing (5)
internal/agent/component/userfillup.gointernal/handler/agent.gointernal/handler/agent_test.gointernal/handler/memory.gointernal/service/openai_chat.go
🚧 Files skipped from review as they are similar to previous changes (2)
- internal/handler/memory.go
- internal/service/openai_chat.go
Summary
Port
#15376
#16401
#15484
#16685