Skip to content

Port agent PRs to GO - 5 - #16667

Merged
yuzhichang merged 6 commits into
infiniflow:mainfrom
qinling0210:port_to_go
Jul 8, 2026
Merged

yuzhichang merged 6 commits into
infiniflow:mainfrom
qinling0210:port_to_go

Conversation

@qinling0210

@qinling0210 qinling0210 commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Port

#15376
#16401
#15484
#16685

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 6, 2026
@qinling0210 qinling0210 self-assigned this Jul 6, 2026
@coderabbitai

coderabbitai Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds 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.

Changes

Memory and OpenAI Chat Fixes

Layer / File(s) Summary
Page size validation in memory handlers
internal/handler/memory.go
SearchMessage and GetMessages reject top_n and limit values outside 1..100.
Optional created timestamp in OpenAI chat responses
internal/service/openai_chat.go
OpenAICompletionResponse.Created becomes nullable, non-stream construction leaves it unset, and serialization falls back to the current Unix time when needed.

Agent chat-completions response modes

Layer / File(s) Summary
Chat-completions response contract
internal/handler/agent.go
The non-OpenAI chat-completions comment now describes SSE streaming for stream=true and aggregated JSON for the default path.
SSE streaming branch
internal/handler/agent.go
The handler’s streaming branch writes SSE frames for run events and returns [DONE] when no events are present.
Non-stream aggregation and assertions
internal/handler/agent.go, internal/handler/agent_test.go
The default branch aggregates event data into one JSON response, and tests now expect JSON by default plus the updated OpenAI-compatible payload shape.

Object field parsing in user fill-up

Layer / File(s) Summary
Object value parsing
internal/agent/component/userfillup.go
resolveFieldValue now parses non-empty JSON strings for object fields and falls back to the original string when parsing fails.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested labels: 💞 feature, size:XXL

Suggested reviewers: yuzhichang

Poem

A rabbit hops through fields of text,
JSON and streams both neatly flexed.
A limit set, a timestamp freed,
And chats now choose just what they need.
🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description only lists source PR links and lacks the required summary and background context. Add a brief Summary explaining what the PR changes and why, plus any helpful background; keep the linked source PRs as supporting context.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the main change: porting agent PRs to Go.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
internal/service/openai_chat.go (1)

81-81: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

resp.Created is never populated, so getCreatedOrDefault always falls back to time.Now().

The struct literal building resp (Lines 436-442) never sets Created, so at Line 475 resp.Created is always nil, and getCreatedOrDefault will always execute its time.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: nowPtr when constructing resp here so the intent is explicit, or clarify (e.g., via comment) that this path intentionally always defers to time.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

📥 Commits

Reviewing files that changed from the base of the PR and between 57625c9 and 1e6d92a.

📒 Files selected for processing (2)
  • internal/handler/memory.go
  • internal/service/openai_chat.go

Comment thread internal/handler/memory.go Resolved
@qinling0210 qinling0210 added the ci Continue Integration label Jul 6, 2026
@qinling0210
qinling0210 marked this pull request as draft July 7, 2026 01:33
@qinling0210
qinling0210 force-pushed the port_to_go branch 2 times, most recently from dc47661 to a828fc7 Compare July 7, 2026 07:11
@qinling0210
qinling0210 marked this pull request as ready for review July 7, 2026 07:13
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jul 7, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
internal/agent/component/userfillup.go (1)

241-249: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Large integers in object fields will lose precision.

json.Unmarshal into any decodes all JSON numbers as float64, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0766851 and a828fc7.

📒 Files selected for processing (5)
  • internal/agent/component/userfillup.go
  • internal/handler/agent.go
  • internal/handler/agent_test.go
  • internal/handler/memory.go
  • internal/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

Comment thread internal/agent/component/userfillup.go Resolved
Comment thread internal/agent/component/userfillup.go Resolved
@qinling0210
qinling0210 marked this pull request as draft July 7, 2026 07:51
@qinling0210
qinling0210 marked this pull request as ready for review July 7, 2026 09:18
@yuzhichang
yuzhichang merged commit 8e3bbad into infiniflow:main Jul 8, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants