Repository navigation
fix(go): agent settings update clearing DSL - #16495
Conversation
|
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 (5)
💤 Files with no reviewable changes (1)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthrough
ChangesPatch-based UpdateAgent refactor
Estimated code review effort: 3 (Moderate) | ~20 minutes 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.
🧹 Nitpick comments (1)
internal/service/agent.go (1)
405-414: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winNon-string values for string columns are passed through untyped.
Only
titleis type-checked;avatar,description,permission,canvas_type, andcanvas_categoryare written as-is. A malformed request (e.g.description: 123) reaches GORM as afloat64and can produce a DB-level error or an unexpected write instead of a clean 400. Consider validating/asserting these as strings before adding them toupdates.🤖 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/agent.go` around lines 405 - 414, The patch builder in agent.go is letting non-string values through for string-backed fields, since only title is asserted as a string before being added to updates. Update the loop in the patch handling logic to type-check and normalize avatar, description, permission, canvas_type, and canvas_category the same way as title in the updates map, and only include them when the value is a valid string (trimming where appropriate) so malformed requests are rejected before reaching GORM.
🤖 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.
Nitpick comments:
In `@internal/service/agent.go`:
- Around line 405-414: The patch builder in agent.go is letting non-string
values through for string-backed fields, since only title is asserted as a
string before being added to updates. Update the loop in the patch handling
logic to type-check and normalize avatar, description, permission, canvas_type,
and canvas_category the same way as title in the updates map, and only include
them when the value is a valid string (trimming where appropriate) so malformed
requests are rejected before reaching GORM.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7bc87ea4-1bf0-47b2-979a-730a9e3a4ae7
📒 Files selected for processing (6)
internal/dao/user_canvas.gointernal/handler/agent.gointernal/handler/agent_test.gointernal/handler/agent_wait_for_user_test.gointernal/service/agent.gointernal/service/agent_test.go
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16495 +/- ##
=======================================
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:
|
### Summary This PR fixes a Go backend bug where updating agent settings, such as description, could clear the agent DSL. Root cause: PUT /api/v1/agents/:canvas_id only bound the dsl field in Go. When the frontend submitted settings without dsl, the service still updated the canvas with an empty DSL value. Changes: - Treat agent updates as partial patches. - Preserve existing DSL when dsl is not present in the request. - Update only specified user_canvas fields instead of saving the full row. - Add a regression test for settings updates preserving DSL. Test: `go test ./internal/service ./internal/handler` Co-authored-by: Zhichang Yu <[email protected]>
### Summary This PR fixes a Go backend bug where updating agent settings, such as description, could clear the agent DSL. Root cause: PUT /api/v1/agents/:canvas_id only bound the dsl field in Go. When the frontend submitted settings without dsl, the service still updated the canvas with an empty DSL value. Changes: - Treat agent updates as partial patches. - Preserve existing DSL when dsl is not present in the request. - Update only specified user_canvas fields instead of saving the full row. - Add a regression test for settings updates preserving DSL. Test: `go test ./internal/service ./internal/handler` Co-authored-by: Zhichang Yu <[email protected]>
Summary
This PR fixes a Go backend bug where updating agent settings, such as description, could clear the agent DSL.
Root cause:
PUT /api/v1/agents/:canvas_id only bound the dsl field in Go. When the frontend submitted settings without dsl, the service still updated the canvas with an empty DSL value.
Changes:
Test:
go test ./internal/service ./internal/handler