Skip to content

fix(go): agent settings update clearing DSL - #16495

Merged
yuzhichang merged 3 commits into
infiniflow:mainfrom
Harry-Hz-Zhang:fix/agent-update
Jul 2, 2026
Merged

yuzhichang merged 3 commits into
infiniflow:mainfrom
Harry-Hz-Zhang:fix/agent-update

Conversation

@Harry-Hz-Zhang

Copy link
Copy Markdown
Contributor

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

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jun 30, 2026
@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bc65be71-1f2e-4d68-8298-088a128dc35e

📥 Commits

Reviewing files that changed from the base of the PR and between bc0af7f and eb72ff2.

📒 Files selected for processing (5)
  • internal/dao/user_canvas.go
  • internal/handler/agent.go
  • internal/handler/agent_test.go
  • internal/handler/agent_wait_for_user_test.go
  • internal/service/agent.go
💤 Files with no reviewable changes (1)
  • internal/service/agent.go
🚧 Files skipped from review as they are similar to previous changes (4)
  • internal/dao/user_canvas.go
  • internal/handler/agent.go
  • internal/handler/agent_wait_for_user_test.go
  • internal/handler/agent_test.go

📝 Walkthrough

Walkthrough

UpdateAgent now accepts a generic patch payload, applies partial draft updates, and persists them through a new DAO helper. The handler and test doubles were updated for the new request shape, and service tests cover DSL preservation and JSON map persistence.

Changes

Patch-based UpdateAgent refactor

Layer / File(s) Summary
DAO partial update method
internal/dao/user_canvas.go
Adds UserCanvasDAO.UpdateFields for canvas-scoped partial GORM updates using a supplied field map.
Service patch logic and tests
internal/service/agent.go, internal/service/agent_test.go
UpdateAgent now accepts patch map[string]interface{}, updates selected draft fields, validates and normalizes dsl when present, forces release=false, and persists only changed fields. New tests verify settings-only updates preserve DSL and explicit DSL patches persist correctly.
Handler and test double updates
internal/handler/agent.go, internal/handler/agent_test.go, internal/handler/agent_wait_for_user_test.go
updateAgentRequest now uses a generic map, nil requests are normalized before service calls, and fake UpdateAgent signatures are aligned in tests.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

🐇 A patch-map hopped through fields so neat,
The DSL stayed snug, and updates stayed sweet.
With partial writes and tests in tow,
The canvas keeps just what should show.
Thump-thump, the warren now flows just right.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise, specific, and accurately reflects the main change: preventing agent settings updates from clearing DSL.
Description check ✅ Passed The description includes the required summary, background, changes, and test notes, which is sufficient for the template.
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.

@Harry-Hz-Zhang Harry-Hz-Zhang added the ci Continue Integration label Jun 30, 2026
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft June 30, 2026 09:02
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review June 30, 2026 09:02
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft June 30, 2026 09:07
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review June 30, 2026 09:07

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

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

405-414: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Non-string values for string columns are passed through untyped.

Only title is type-checked; avatar, description, permission, canvas_type, and canvas_category are written as-is. A malformed request (e.g. description: 123) reaches GORM as a float64 and can produce a DB-level error or an unexpected write instead of a clean 400. Consider validating/asserting these as strings before adding them to updates.

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 09dc4c8 and 3b3d8e6.

📒 Files selected for processing (6)
  • internal/dao/user_canvas.go
  • internal/handler/agent.go
  • internal/handler/agent_test.go
  • internal/handler/agent_wait_for_user_test.go
  • internal/service/agent.go
  • internal/service/agent_test.go

@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft June 30, 2026 10:39
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review June 30, 2026 10:39
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft June 30, 2026 11:21
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review June 30, 2026 11:21
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft July 1, 2026 01:29
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review July 1, 2026 01:29
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft July 1, 2026 02:36
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review July 1, 2026 02:36
@codecov

codecov Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (540acb4) to head (bc0af7f).
⚠️ Report is 45 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft July 1, 2026 03:31
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review July 1, 2026 03:31
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft July 1, 2026 08:08
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review July 1, 2026 08:08
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as draft July 2, 2026 01:27
@Harry-Hz-Zhang
Harry-Hz-Zhang marked this pull request as ready for review July 2, 2026 01:27
@yuzhichang
yuzhichang self-requested a review July 2, 2026 04:42

@yuzhichang yuzhichang left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 2, 2026
@yuzhichang
yuzhichang merged commit d0d0339 into infiniflow:main Jul 2, 2026
3 checks passed
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 3, 2026
### 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]>
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 6, 2026
### 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants