Skip to content

feat: implement engine kind detection for default context in context ls#823

Open
ilopezluna wants to merge 3 commits intomainfrom
context-ls-show-detected-engine-kind
Open

feat: implement engine kind detection for default context in context ls#823
ilopezluna wants to merge 3 commits intomainfrom
context-ls-show-detected-engine-kind

Conversation

@ilopezluna
Copy link
Copy Markdown
Contributor

 docker model context ls
NAME     HOST                    DESCRIPTION                     CURRENT  
default  Docker Desktop          Model Runner on Docker Desktop           
debug    http://localhost:13434                                  *       

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@ilopezluna ilopezluna marked this pull request as ready for review April 2, 2026 12:03
@ilopezluna ilopezluna requested a review from a team April 2, 2026 12:03
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue, and left some high level feedback:

  • 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.
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants