refactor: replace clientexec usage with services.Exec - #1520
Open
EmanuelJr wants to merge 1 commit into
Open
Conversation
EmanuelJr
requested review from
matheusfrancisco,
p3rotto,
racerxdl and
sandromello
June 11, 2026 13:19
Contributor
Migration Safety AnalysisNo database migrations were changed in this PR. Safe to deploy to sandbox. |
Contributor
📋 API ChangelogAPI Changelog unknown vs. unknownNo changes detected |
Contributor
|
✅ Build Completed with Success, Version=1520.0.0-g5e6da7d |
matheusfrancisco
approved these changes
Jun 11, 2026
sandromello
approved these changes
Jun 19, 2026
p3rotto
approved these changes
Jun 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
Every PR MUST have exactly one of these labels, the merge is blocked otherwise:
major/minor/patchpublishes a new release on merge with the corresponding semver bump.skip-releasemerges without publishing a release (use for docs, CI changes, refactors, etc.).📝 Description
Introduces a centralized
services.Exechelper ingateway/services/exec.goand replaces the repeatedclientexec.New+ goroutine + channel +selectboilerplate 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 (viasync.Once), returning a(*clientexec.Response, error)so callers can handle results with a simpleswitchon the error (includingcontext.DeadlineExceededfor 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
📋 Changes Made
gateway/services/exec.gowith a reusableExec(ctx, ExecOptions)function and anExecOptionsstruct that wrapsclientexeccreation, execution, context-driven timeout handling, and idempotent client close viasync.Once.services.Execinstead of the duplicatedclientexec.New+ goroutine + channel +selectpattern: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, andeventrouting/dispatcher.go.errors.Is(err, context.DeadlineExceeded), preserving the existing async-return behavior on timeout.clientexecimports 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:
Tests performed:
📸 Screenshots (if applicable)
✅ Checklist
📄 Additional Notes
services.Execcentralizes the timeout/close semantics that were previously copy-pasted (and slightly inconsistent) across handlers. Thesync.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 ineventrouting/dispatcher.goandsession/run-exec.go, where the timeout now surfaces ascontext.DeadlineExceededrather than a separate channel case.