feat: implement engine kind detection for default context in context ls#823
feat: implement engine kind detection for default context in context ls#823ilopezluna wants to merge 3 commits into
Conversation
ilopezluna
commented
Apr 2, 2026
There was a problem hiding this comment.
Code Review
This pull request implements dynamic engine kind detection for the "default" Docker context to provide more accurate host and description information in the CLI. However, the current implementation hardcodes connection schemes and ports, failing to account for TLS configurations. Additionally, the detection logic is inefficiently called within loops, potentially causing significant delays, and it lacks handling for specific WSL2 edge cases where Moby-based runners are used.
- Handle WSL2 edge case in DetectEngineKind where a Moby controller container may be running alongside Docker Desktop - Respect MODEL_RUNNER_TLS env var in resolveDefaultContext to show correct scheme (https) and TLS ports (12444/12445) when TLS is enabled - Resolve default context info lazily once in inspect command to avoid repeated network probes when 'default' appears multiple times in args
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
resolveDefaultContext, consider adding adefaultbranch in theswitch kindto ensurehostis always initialized sensibly if newModelRunnerEngineKindvalues are introduced in the future. - The host/port construction logic in
resolveDefaultContextduplicates logic from the runtime detection path; it might be worth centralizing this mapping (kind + TLS → URL) in a shared helper to avoid future drift between what is displayed and what is actually used.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `resolveDefaultContext`, consider adding a `default` branch in the `switch kind` to ensure `host` is always initialized sensibly if new `ModelRunnerEngineKind` values are introduced in the future.
- The host/port construction logic in `resolveDefaultContext` duplicates logic from the runtime detection path; it might be worth centralizing this mapping (kind + TLS → URL) in a shared helper to avoid future drift between what is displayed and what is actually used.
## Individual Comments
### Comment 1
<location path="cmd/cli/commands/context.go" line_range="94-101" />
<code_context>
+ detectCtx, cancel := context.WithTimeout(ctx, defaultContextDetectTimeout)
+ defer cancel()
+
+ kind := desktop.DetectEngineKind(detectCtx, dockerCLI)
+ description = "Model Runner on " + kind.String()
+
+ // Check whether TLS is enabled so the displayed scheme and port match
+ // what DetectContext would actually use at runtime.
+ useTLS := os.Getenv("MODEL_RUNNER_TLS") == "true"
+
+ switch kind {
+ case types.ModelRunnerEngineKindDesktop:
+ host = kind.String()
</code_context>
<issue_to_address>
**issue:** Handle unexpected/unknown engine kinds to avoid returning an empty host string
If `DetectEngineKind` ever returns a new/unknown `ModelRunnerEngineKind` (e.g., after future enum extensions), this `switch` will leave `host` empty while still setting a non-empty `description`. Consider adding a `default` case that falls back to the generic `(auto-detect)` host (and possibly description) to keep the output consistent and user-friendly for unhandled kinds.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
No tests for DetectEngineKind/resolveDefaultContext happy path, missing default case in switch, nil-CLI contract not documented |
| } | ||
| case types.ModelRunnerEngineKindMoby, types.ModelRunnerEngineKindMobyManual: | ||
| if envconfig.TLSEnabled() { | ||
| host = "https://localhost:" + strconv.Itoa(standalone.DefaultTLSPortMoby) |
There was a problem hiding this comment.
probably can refactor this into a helper function since the same is duplicated like host := resolveKindHost(...)