Repository navigation
fix(go-models): fix Moonshot model and balance requests - #15528
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:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughRefactors Moonshot client to validate API key and model name early, always use Bearer Authorization, force chat/stream modes, use body-less GET with typed parsing for models/balance, improve SSE scanning/error handling, and add comprehensive tests validating these behaviors and error conditions. ChangesMoonshot Model Hardening
Sequence DiagramsequenceDiagram
participant Client
participant MoonshotAPI
participant Sender
Client->>MoonshotAPI: POST /chat/completions (stream=true, Authorization: Bearer <apiKey>, Accept: text/event-stream)
MoonshotAPI->>Sender: data: <delta chunk>
MoonshotAPI->>Sender: data: [DONE]
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/entity/models/moonshot.go (1)
382-388:⚠️ Potential issue | 🟠 Major | ⚡ Quick winDon't emit
[DONE]after a scanner failure.If
scanner.Scan()stops because of a read error, timeout, or oversized SSE frame, this path still sends the completion sentinel before returning the error. That can make callers treat a failed stream as successfully finished and commit partial output.Suggested fix
+ if err := scanner.Err(); err != nil { + return err + } + // Send [DONE] marker for OpenAI compatibility endOfStream := "[DONE]" if err = sender(&endOfStream, nil); err != nil { return err } - return scanner.Err() + return nil🤖 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/entity/models/moonshot.go` around lines 382 - 388, The code currently always sends the "[DONE]" sentinel via sender(&endOfStream, nil) even when scanner.Scan() failed; change the logic to check scanner.Err() first and only call sender for the endOfStream if scanner.Err() returns nil (no read/timeout/oversize error). Concretely, query err2 := scanner.Err() (or reuse err) after the scan loop, return that error immediately if non-nil, and only then call sender(&endOfStream, nil) before returning nil; reference the scanner variable and the sender(...) call to locate where to adjust the flow.
🤖 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.
Outside diff comments:
In `@internal/entity/models/moonshot.go`:
- Around line 382-388: The code currently always sends the "[DONE]" sentinel via
sender(&endOfStream, nil) even when scanner.Scan() failed; change the logic to
check scanner.Err() first and only call sender for the endOfStream if
scanner.Err() returns nil (no read/timeout/oversize error). Concretely, query
err2 := scanner.Err() (or reuse err) after the scan loop, return that error
immediately if non-nil, and only then call sender(&endOfStream, nil) before
returning nil; reference the scanner variable and the sender(...) call to locate
where to adjust the flow.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 120f4214-1ae5-4a5d-8068-fc5000d7bb28
📒 Files selected for processing (2)
internal/entity/models/moonshot.gointernal/entity/models/moonshot_test.go
|
Hi @Haruko386 @JinHai-CN - please review when you have a little time. 🤝 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15528 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@oktofeesh1 Would you please resolve the conflicts? |
d7653ec to
fbfa05b
Compare
Fixed, thank you and sorry for delay |
This is now resolved :) |
|
Thanks, I fetched/rebased onto the latest upstream code and rechecked the requested pattern. |
ac50490 to
f2414d5
Compare
Summary
What changed
Why
Kimi/Moonshot documents both model listing and balance checks as GET endpoints with bearer auth and no request body:
The previous driver sent JSON bodies on those GET requests, let callers flip the expected stream mode, and could panic on malformed model or balance responses.
Validation
Notes