Skip to content

Add Docker host fallback for localhost provider endpoints#63

Merged
BillJr99 merged 2 commits into
masterfrom
claude/eager-edison-V1yNk
May 24, 2026
Merged

Add Docker host fallback for localhost provider endpoints#63
BillJr99 merged 2 commits into
masterfrom
claude/eager-edison-V1yNk

Conversation

@BillJr99
Copy link
Copy Markdown
Owner

Summary

When CLK runs inside a Docker container, HTTP endpoints configured as http://localhost:PORT cannot reach services (ollama, OpenWebUI) running on the host machine. This PR adds automatic fallback to host.docker.internal when localhost endpoints are unreachable, with detection and persistence of the swap across the codebase.

Key Changes

  • New module clk_harness/providers/_endpoint_fallback.py: Centralizes Docker host fallback logic with three main functions:

    • probe_endpoint(): Tests TCP connectivity to an endpoint with timeout
    • docker_host_swap(): Converts localhost URLs to host.docker.internal equivalents
    • maybe_docker_host_fallback(): Probes both endpoints and logs a one-time notice if fallback is needed
  • Provider updates (ollama.py, openwebui.py):

    • Refactored available() methods to use the new fallback utilities
    • Auto-mutate provider config when localhost fails but host.docker.internal works
    • Removed duplicate socket/URL parsing code
  • Installation script (scripts/install_tool.sh):

    • Added _it_probe_endpoint() helper for endpoint reachability checks
    • Added _it_offer_docker_host_fallback() to interactively prompt users during setup
    • Integrated fallback checks into ollama and openwebui configuration flows
  • Kickoff script (kickoff.sh):

    • New docker_host_fallback step that probes endpoints early in the setup process
    • Offers to rewrite .env file when fallback is needed
  • TUI integration (clk_harness/tui.py):

    • Detects endpoint mutations during provider health checks
    • Persists swapped endpoints to providers.json
    • Logs endpoint switches to the user

Implementation Details

  • Fallback detection is non-intrusive: only triggers when localhost is unreachable AND host.docker.internal works
  • One-time logging per (label, original, swapped) pair prevents spam in health-check loops
  • Config mutations are transparent to callers—subsequent API calls automatically use the working endpoint
  • Works across setup (interactive), runtime (TUI health checks), and provider invocation

https://claude.ai/code/session_019H5FnEyiYvomB64pFyozsK

claude added 2 commits May 24, 2026 14:11
When CLK runs in a container, http://localhost:... cannot reach an
ollama or OpenWebUI server bound to the host. Probe the same port on
host.docker.internal; if only that answers, warn and offer to rewrite
.env. Runs during the openwebui install branch, the ollama/openwebui
configure flows, and as a standalone setup step that fires regardless
of the active provider so the TUI's all-providers health check stops
flagging the host's ollama as UNAVAILABLE.
Ollama and OpenWebUI providers now probe their configured endpoint at
runtime and, if a localhost URL is dead but the host.docker.internal
equivalent answers, transparently switch self.config['endpoint'] and
log a one-line notice. The TUI provider-health pass snapshots
endpoints, detects the swap inside available_providers (which mutates
the shared providers_cfg dict), and persists the change to
providers.json so the fix survives across runs.
@BillJr99 BillJr99 merged commit 4d6952d into master May 24, 2026
4 checks passed
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