Skip to content

refactor: replace clientexec usage with services.Exec - #1520

Open
EmanuelJr wants to merge 1 commit into
mainfrom
refactor/exec
Open

refactor: replace clientexec usage with services.Exec#1520
EmanuelJr wants to merge 1 commit into
mainfrom
refactor/exec

Conversation

@EmanuelJr

Copy link
Copy Markdown
Contributor

Important

Every PR MUST have exactly one of these labels, the merge is blocked otherwise:

  • major / minor / patch publishes a new release on merge with the corresponding semver bump.
  • skip-release merges without publishing a release (use for docs, CI changes, refactors, etc.).

📝 Description

Introduces a centralized services.Exec helper in gateway/services/exec.go and replaces the repeated clientexec.New + goroutine + channel + select boilerplate scattered across the gateway API handlers and the event-routing dispatcher. The new helper encapsulates client creation, execution, context-based timeout handling, and guaranteed single client close (via sync.Once), returning a (*clientexec.Response, error) so callers can handle results with a simple switch on the error (including context.DeadlineExceeded for the async/timeout path).

This is a pure refactor — no behavioral changes to the execution flow, timeouts, or response semantics.

🔗 Related Issue

🚀 Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🎨 Style/UI update
  • ♻️ Code refactor
  • ⚡ Performance improvement
  • ✅ Test update
  • 🔧 Build configuration change
  • 🧹 Chore

📋 Changes Made

  • Added gateway/services/exec.go with a reusable Exec(ctx, ExecOptions) function and an ExecOptions struct that wraps clientexec creation, execution, context-driven timeout handling, and idempotent client close via sync.Once.
  • Refactored all exec call sites to use services.Exec instead of the duplicated clientexec.New + goroutine + channel + select pattern: session/run-exec.go, session/session.go, connections/connections.go, connections/database_explorer.go (ListDatabases, ListTables, GetTableColumns), mcpserver/tools_exec.go, mcpserver/tools_reviews.go, mcpserver/tools_schema.go, runbooks/runbooks.go, runbooks/runbooksV2.go, and eventrouting/dispatcher.go.
  • Standardized timeout/async handling to branch on errors.Is(err, context.DeadlineExceeded), preserving the existing async-return behavior on timeout.
  • Removed now-unused direct clientexec imports from the refactored handlers.

🧪 Testing

This is a non-functional refactor that preserves the existing execution and timeout behavior across all affected exec call sites.

Test Configuration:

  • Browser(s): N/A
  • OS: macOS

Tests performed:

  • Unit tests pass
  • Integration tests pass
  • Manual testing completed

📸 Screenshots (if applicable)

✅ Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes
  • I have checked my code and corrected any misspellings

📄 Additional Notes

services.Exec centralizes the timeout/close semantics that were previously copy-pasted (and slightly inconsistent) across handlers. The sync.Once-guarded close prevents double-close races when both the response and the context-cancellation paths fire. Reviewers may want to focus on the timeout branches in eventrouting/dispatcher.go and session/run-exec.go, where the timeout now surfaces as context.DeadlineExceeded rather than a separate channel case.

@EmanuelJr EmanuelJr added the skip-release Merges without publishing a release (docs, CI, refactors, etc.) label Jun 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Migration Safety Analysis

No database migrations were changed in this PR. Safe to deploy to sandbox.

@github-actions

Copy link
Copy Markdown
Contributor

📋 API Changelog

API Changelog unknown vs. unknown

No changes detected

@sandromello

Copy link
Copy Markdown
Contributor

✅ Build Completed with Success, Version=1520.0.0-g5e6da7d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-release Merges without publishing a release (docs, CI, refactors, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants