Skip to content

Go: add context, part10 - #17417

Merged
JinHai-CN merged 6 commits into
infiniflow:mainfrom
JinHai-CN:fix587
Jul 27, 2026
Merged

JinHai-CN merged 6 commits into
infiniflow:mainfrom
JinHai-CN:fix587

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

No description provided.

Signed-off-by: Jin Hai <[email protected]>
@JinHai-CN
JinHai-CN marked this pull request as ready for review July 27, 2026 07:07
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 27, 2026
@coderabbitai

coderabbitai Bot commented Jul 27, 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 Plus

Run ID: c8a0efb1-2f0b-4d84-9c4e-6dd054823199

📥 Commits

Reviewing files that changed from the base of the PR and between e624f63 and 0c993c7.

📒 Files selected for processing (2)
  • internal/agent/sandbox/self_managed.go
  • internal/dao/system_settings.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • internal/agent/sandbox/self_managed.go
  • internal/dao/system_settings.go

📝 Walkthrough

Walkthrough

System settings DAO, service, and handler APIs now propagate request contexts and explicit database handles. Sandbox provider loading uses the same context/database-aware seam, while execution accepts a new structured-result metadata key with backward compatibility.

Changes

Context and database propagation

Layer / File(s) Summary
Context-aware system settings DAO
internal/dao/system_settings.go
System settings queries, mutations, transactions, and transaction helpers now use supplied context and database handles.
Context-aware variable endpoints
internal/admin/..., internal/handler/system.go, internal/service/system.go
Variable handlers pass request contexts through services to context-aware settings DAO operations.
Database-aware sandbox settings loading
internal/agent/sandbox/manager.go, internal/agent/sandbox/manager_test.go
Provider loading and reloading accept database handles, forward context and database values to settings readers, and update corresponding tests.
Sandbox execution result handling
internal/agent/sandbox/manager_client.go, internal/agent/sandbox/aliyun.go, internal/agent/sandbox/self_managed.go
Structured results prefer structured_result metadata with fallback to result; JSON decoding reuses the existing error variable, and imports are reordered.

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

Suggested labels: ☯️ refactor

Poem

A bunny hops through context streams,
With database paws and threaded dreams.
Settings flow, results gleam,
Old keys still sail compatibility streams.
“Carrots!” cheers the rabbit team.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is missing; the template requires a Summary section with purpose and background. Add a Summary section that explains the problem, the goal of the PR, and any relevant background.
Title check ❓ Inconclusive The title is relevant to the change but too vague to identify the main update. Rename it to something specific like "Add context to admin and DAO variable handling".
✅ Passed checks (3 passed)
Check name Status Explanation
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: 2

🤖 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/sandbox/manager_test.go`:
- Line 402: Update fakeSettingsReader.GetByName to match the SettingsReader
interface by adding the *gorm.DB parameter in the correct position, and import
GORM in the test file. Preserve the existing return behavior so
Load从SettingsWithReader tests compile and continue using the fake.

In `@internal/dao/system_settings.go`:
- Around line 37-39: Update SystemSettingsDAO.GetAll to query through
db.WithContext(ctx) instead of the global DB. Update Transaction to invoke the
transaction on db.WithContext(ctx), and ensure direct transaction helpers use a
context-bearing tx so cancellation and deadlines propagate through all queries.
🪄 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 Plus

Run ID: 067a0c48-c4ae-42e4-b4c6-c0c44c1a7109

📥 Commits

Reviewing files that changed from the base of the PR and between 3065a29 and e43a55a.

📒 Files selected for processing (10)
  • internal/admin/handler.go
  • internal/admin/service.go
  • internal/agent/sandbox/manager.go
  • internal/agent/sandbox/manager_client.go
  • internal/agent/sandbox/manager_test.go
  • internal/agent/tool/code_exec.go
  • internal/agent/tool/code_exec_client.go
  • internal/dao/system_settings.go
  • internal/handler/system.go
  • internal/service/system.go

Comment thread internal/agent/sandbox/manager_test.go Resolved
Comment thread internal/dao/system_settings.go Resolved

@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/agent/sandbox/manager_test.go (1)

405-405: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the new context/DB propagation.

The fake discards both new parameters, so these tests cannot detect a regression that passes the wrong context or DB. Capture them and assert the caller-provided sentinel values in one load and reload test.

As per coding guidelines, “Preserve valid behavior with focused tests.”

🤖 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/sandbox/manager_test.go` at line 405, Update
fakeSettingsReader.GetByName to capture the provided context and *gorm.DB
instead of discarding them, then add assertions in one load test and one reload
test that both match caller-provided sentinel values. Keep the existing settings
behavior intact while verifying propagation through the relevant load and reload
paths.

Source: Coding guidelines

🤖 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/sandbox/manager.go`:
- Around line 168-169: The runtime LoadFromSettings entry point currently
hard-codes dao.DB, preventing caller-owned database or transaction use. Update
ProviderManager.LoadFromSettings to accept a *gorm.DB parameter and pass it to
LoadFromSettingsWithReader; update the owning ManagerClient.ExecuteCode call
path to provide its active database handle.

---

Nitpick comments:
In `@internal/agent/sandbox/manager_test.go`:
- Line 405: Update fakeSettingsReader.GetByName to capture the provided context
and *gorm.DB instead of discarding them, then add assertions in one load test
and one reload test that both match caller-provided sentinel values. Keep the
existing settings behavior intact while verifying propagation through the
relevant load and reload paths.
🪄 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 Plus

Run ID: 8c726378-9a73-474e-b45e-a6a218c44fbd

📥 Commits

Reviewing files that changed from the base of the PR and between e43a55a and e624f63.

📒 Files selected for processing (6)
  • internal/agent/sandbox/aliyun.go
  • internal/agent/sandbox/manager.go
  • internal/agent/sandbox/manager_client.go
  • internal/agent/sandbox/manager_test.go
  • internal/agent/sandbox/self_managed.go
  • internal/dao/system_settings.go

Comment on lines 168 to +169
func (m *ProviderManager) LoadFromSettings(ctx context.Context) error {
return m.LoadFromSettingsWithReader(ctx, dao.NewSystemSettingsDAO())
return m.LoadFromSettingsWithReader(ctx, dao.DB, dao.NewSystemSettingsDAO())

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.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Keep the DB handle injectable on the runtime entry point.

LoadFromSettings hard-codes dao.DB, so the normal ManagerClient.ExecuteCode path cannot use a caller-owned database or transaction; only the test-oriented WithReader path can. Accept db *gorm.DB here and forward it from the owning caller instead of restoring a global-DB boundary.

🤖 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/sandbox/manager.go` around lines 168 - 169, The runtime
LoadFromSettings entry point currently hard-codes dao.DB, preventing
caller-owned database or transaction use. Update
ProviderManager.LoadFromSettings to accept a *gorm.DB parameter and pass it to
LoadFromSettingsWithReader; update the owning ManagerClient.ExecuteCode call
path to provide its active database handle.

Signed-off-by: Jin Hai <[email protected]>
@JinHai-CN JinHai-CN added the ci Continue Integration label Jul 27, 2026
@JinHai-CN
JinHai-CN merged commit 49e6181 into infiniflow:main Jul 27, 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.

1 participant