refactor: migrate executor handlers to free functions with ExecContext#225
refactor: migrate executor handlers to free functions with ExecContext#225ako merged 16 commits intomendixlabs:mainfrom
Conversation
Replace *Executor parameter with *ExecContext in StmtHandler type, Registry.Dispatch, and all 115 handler wrappers. Handlers access the Executor via ctx.executor during the migration period. Add newExecContext bridge that builds ExecContext from Executor state with the timeout context from Execute().
Convert execConnect, execDisconnect, execStatus, and reconnect from Executor methods to free functions receiving *ExecContext. Add temporary Executor method wrappers for callers not yet migrated (cmd_misc.go, cmd_catalog.go). Update register_stubs.go to call free functions directly.
Convert execCreateModule and execDropModule from Executor methods to free functions receiving *ExecContext. Add temporary method wrapper for execCreateModule (called from helpers.go auto-create). Leave showModules, describeModule, and helper methods as Executor methods for now.
…to free functions
…nsformer handlers to free functions
Migrate move/rename, folders, styling, widgets, features, diff, structure, mermaid, contract, context, search, lint, agent editor, languages, SQL, import, fragments, and misc handlers from Executor methods to free functions taking *ExecContext. 163 methods converted across 29 files.
Migrate helpers, format, hierarchy, autocomplete, validate, oql_type_inference, cmd_catalog, executor_query, and remaining cmd_modules methods from Executor methods to free functions. ~73 methods converted across 72 files. All handler and utility methods now use *ExecContext. Only Executor lifecycle methods (Execute, ExecuteProgram, SetQuiet, Close, etc.) remain as receiver methods.
Fix 32 remaining e.method() calls in free functions to use direct free function calls. Convert findImageCollection to *ExecContext. Remove 233 wrapper methods that no longer have callers. Executor method count: 295 → 62 (21 lifecycle/API + 38 required wrappers for exported API, tests, and internal callers + 3 infrastructure).
AI Code ReviewWhat Looks Good
RecommendationApprove - This is a well-executed, pure mechanical refactor that successfully completes the handler migration phase without changing behavior. The approach is consistent, thoroughly tested, and maintains all necessary backward compatibility while improving internal architecture. No issues were found against the review checklist. Automated review via OpenRouter (Nemotron Super 120B) — workflow source |
There was a problem hiding this comment.
Pull request overview
This PR completes the “handler migration” phase of the executor refactor by converting executor statement handlers from (*Executor) receiver methods to package-level functions that accept *ExecContext, and wiring dispatch/registrations to use the new handler signature.
Changes:
- Update
StmtHandlerand registry dispatch to pass*ExecContextinstead of*Executor. - Introduce
Executor.newExecContext(ctx)and migrate many handlers/utilities to usectx.Output,ctx.Format,ctx.Cache, etc. - Add transitional
Executorwrapper methods to keep unmigrated callers working during the incremental migration.
Reviewed changes
Copilot reviewed 86 out of 86 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| mdl/executor/registry_test.go | Update tests to use the new StmtHandler(ctx *ExecContext, ...) signature. |
| mdl/executor/registry.go | Change handler type + dispatch to accept *ExecContext. |
| mdl/executor/oql_type_inference.go | Convert OQL inference/validation helpers to *ExecContext-based free functions. |
| mdl/executor/hierarchy.go | Move hierarchy caching/invalidation to ExecContext cache; add temporary wrappers. |
| mdl/executor/format.go | Route output/format through ExecContext; add compatibility wrappers. |
| mdl/executor/executor_dispatch.go | Construct ExecContext per dispatch and call registry with it. |
| mdl/executor/executor_connect.go | Migrate connect/disconnect/status handlers to *ExecContext. |
| mdl/executor/executor.go | Pass the execution context.Context into executeInner. |
| mdl/executor/exec_context.go | Add a temporary back-reference from ExecContext to Executor during migration. |
| mdl/executor/cmd_workflows_write.go | Migrate workflow write handlers and related helpers to *ExecContext. |
| mdl/executor/cmd_workflows.go | Migrate workflow show/describe helpers to *ExecContext. |
| mdl/executor/cmd_snippets.go | Migrate snippet listing output to *ExecContext. |
| mdl/executor/cmd_settings.go | Migrate settings show/describe/alter helpers to *ExecContext. |
| mdl/executor/cmd_search.go | Migrate catalog-backed search/show commands to *ExecContext. |
| mdl/executor/cmd_rest_clients.go | Migrate REST client show/describe/create/drop helpers to *ExecContext. |
| mdl/executor/cmd_rename.go | Migrate rename entrypoint + helpers to *ExecContext and context output. |
| mdl/executor/cmd_published_rest.go | Migrate published REST show/describe/create/alter/drop to *ExecContext. |
| mdl/executor/cmd_pages_show.go | Migrate page listing to *ExecContext. |
| mdl/executor/cmd_pages_create_v3.go | Migrate V3 page/snippet creation to *ExecContext. |
| mdl/executor/cmd_pages_builder.go | Convert module ID/name helpers and drop handlers to *ExecContext + wrappers. |
| mdl/executor/cmd_page_wireframe.go | Migrate wireframe JSON generation to *ExecContext + wrappers. |
| mdl/executor/cmd_oql_plan.go | Migrate OQL plan ELK output to *ExecContext. |
| mdl/executor/cmd_navigation.go | Migrate navigation show/describe/alter output to *ExecContext. |
| mdl/executor/cmd_module_overview.go | Migrate module overview graph generation to *ExecContext + wrapper. |
| mdl/executor/cmd_misc.go | Migrate misc commands (update/help/version/exit/script) to *ExecContext. |
| mdl/executor/cmd_microflows_format_action.go | Migrate microflow formatting helpers to *ExecContext + wrappers. |
| mdl/executor/cmd_microflows_drop.go | Migrate microflow drop handler output/cache invalidation to *ExecContext. |
| mdl/executor/cmd_microflows_create.go | Migrate microflow create handler and helpers to *ExecContext. |
| mdl/executor/cmd_microflow_elk.go | Migrate microflow ELK generation to *ExecContext + wrapper. |
| mdl/executor/cmd_mermaid.go | Migrate Mermaid describe generation to *ExecContext + external wrapper. |
| mdl/executor/cmd_lint.go | Migrate lint command to *ExecContext and avoid name collision with lint context. |
| mdl/executor/cmd_layouts.go | Migrate layout listing output to *ExecContext. |
| mdl/executor/cmd_languages.go | Migrate language listing output to *ExecContext. |
| mdl/executor/cmd_jsonstructures.go | Migrate JSON structure show/describe/create/drop to *ExecContext. |
| mdl/executor/cmd_javascript_actions.go | Migrate JS action show/describe and refactor source reader to pure function. |
| mdl/executor/cmd_javaactions.go | Migrate Java action show/describe/create/drop and refactor source reader to pure function. |
| mdl/executor/cmd_import_mappings.go | Migrate import mapping show/describe/create/drop; make element printer io.Writer-based. |
| mdl/executor/cmd_import.go | Migrate import handler and link resolution to *ExecContext; thread DB context into helpers. |
| mdl/executor/cmd_imagecollections.go | Migrate image collection show/describe/create/drop/find to *ExecContext. |
| mdl/executor/cmd_fragments.go | Migrate fragment define/show/describe/describe-from to *ExecContext with shared session map. |
| mdl/executor/cmd_folders.go | Migrate folder drop/move and folder lookup to *ExecContext. |
| mdl/executor/cmd_features.go | Migrate feature gating + show features output to *ExecContext. |
| mdl/executor/cmd_export_mappings.go | Migrate export mapping show/describe/create/drop; make element printer io.Writer-based. |
| mdl/executor/cmd_enumerations.go | Migrate enumeration show/describe/create/drop/find to *ExecContext; adjust validation tables. |
| mdl/executor/cmd_entities_describe.go | Migrate entity show/describe helpers and related lookups to *ExecContext. |
| mdl/executor/cmd_entities_access.go | Migrate entity access grant output/formatting to *ExecContext. |
| mdl/executor/cmd_domainmodel_elk.go | Migrate domain model ELK generation to *ExecContext + wrapper. |
| mdl/executor/cmd_diff_output.go | Migrate diff renderers to *ExecContext output. |
| mdl/executor/cmd_dbconnection.go | Migrate DB connection show/describe/create and constant default resolution to *ExecContext. |
| mdl/executor/cmd_datatransformer.go | Migrate data transformer list/describe/create/drop to *ExecContext. |
| mdl/executor/cmd_constants.go | Migrate constants show/describe/create/drop and MDL output to *ExecContext + wrapper. |
| mdl/executor/cmd_businessevents.go | Migrate business events show/describe/create/drop to *ExecContext. |
| mdl/executor/cmd_alter_workflow.go | Migrate workflow alter entrypoint to *ExecContext; convert helper methods to free funcs. |
| mdl/executor/cmd_alter_page.go | Migrate page/snippet alter entrypoint + widget build helpers to *ExecContext. |
| mdl/executor/cmd_agenteditor_models.go | Migrate agent editor model show/describe/find to *ExecContext. |
| mdl/executor/cmd_agenteditor_mcpservices.go | Migrate agent editor MCP service show/describe/find to *ExecContext. |
| mdl/executor/cmd_agenteditor_kbs.go | Migrate agent editor knowledge base show/describe/find to *ExecContext. |
| mdl/executor/cmd_agenteditor_agents.go | Migrate agent editor agent show/describe/find and emitters to *ExecContext. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 86 out of 86 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
mdl/executor/cmd_oql_plan.go:479
- The file ends with a "Executor method wrapper for backward compatibility" marker, but no wrapper method is actually implemented. Since
OqlQueryPlanELKwas previously anExecutorreceiver method, this silently removes that API; either add the missing(*Executor) OqlQueryPlanELK(...)wrapper delegating to the new free function, or remove the compatibility comment and confirm the API break is intentional.
mdl/executor/cmd_languages.go:53 - There is a trailing "Executor method wrapper for backward compatibility" section marker but no wrapper implementation following it. If no wrapper is needed, please remove this comment to avoid confusion about expected backwards-compatibility surface.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ReviewOverall: mechanically correct, CI green, but this is the third PR in a stack with zero proof that the end-state architecture works. The migration itself is clean — 300 functions transformed with the same pattern, 15 commits that each compile independently. No behavioral changes. But no handler actually uses What I like
Concerns
Minor
VerdictApprove. The migration is mechanical and correct, CI is green, and the incremental commit structure is exemplary. But this PR + #224 + #222 form a three-PR stack of infrastructure prep. The next PR in the stack must include concrete Backend usage — without it, the architecture is untested and the 22-interface design is a guess. I won't approve a fourth infrastructure-only PR in this stack. |
Summary
Migrates ~450 Executor receiver methods to free functions receiving
*ExecContext, completing the handler migration phase of the executor refactoring.Why free functions?
Receiver methods on
*Executorhave implicit access to all 14 struct fields (reader, writer, cache, etc.), making the dependency surface invisible and preventing backend substitution. Free functions can only access what*ExecContextprovides — this makes dependencies explicit, enablesMockBackend-based testing without a.mprfile, and is a prerequisite for the next MR where handlers switch frome.reader.ListModules()toctx.Backend.ListModules()through domain-specific interfaces. The migration itself is mechanical (no behavioral changes) but necessary to decouple handlers from the concreteExecutorstruct.Changes
(e *Executor)receivers tofunc name(ctx *ExecContext, ...)free functionsregister_stubs.goto call free functions directly (zeroctx.executor.indirection)ExecContext.Fork()incaptureDescribe(parallel describe operations)Stacked on
Structure
15 incremental commits, each compiles independently:
StmtHandler→*ExecContext)2-10. Domain-by-domain handler migration (connection, module, enum/constant, entity, microflow, page, security, nav/settings/image/workflow, services, mapping/java)
e.method()calls)ExecContext.Fork()Testing
make build— cleanmake test— all passmake lint— Go lint passes