Skip to content

fix: anthropic passthrough path for Docker Model Runner + align config defaults - #171

Merged
thushan merged 2 commits into
mainfrom
fix/anthropic-passthrough-messages-path
Jun 9, 2026
Merged

thushan merged 2 commits into
mainfrom
fix/anthropic-passthrough-messages-path

Conversation

@thushan

@thushan thushan commented Jun 9, 2026 •

Copy link
Copy Markdown
Owner

What

Extracts the behaviour and config changes from the v0.0.28 documentation work into a focused, testable PR so the docs branch can stay purely documentation.

Anthropic passthrough path (the main fix)

Docker Model Runner exposes the Anthropic Messages API at /anthropic/v1/messages, and its profile declares this via anthropic_support.messages_path. The translator hardcoded /v1/messages and ignored the profile, so passthrough to DMR returned 404.

executePassthroughRequest now resolves the target path from the backend profile via resolvePassthroughTargetPath. Because the proxy selector chooses the actual endpoint after the path is set, the override only applies when every passthrough candidate agrees on the same native path; otherwise it falls back to the neutral /v1/messages. This is behaviour-preserving for every existing backend (they all use /v1/messages) and fixes the homogeneous DMR case.

Tests added:

  • TestPassthrough_ProfileMessagesPathOverride (homogeneous DMR fleet uses /anthropic/v1/messages)
  • TestPassthrough_MixedMessagesPathsKeepsNeutralTargetPath (mixed DMR + vLLM keeps the neutral path)

Known limitation (documented in the docs branch): a single passthrough fleet should not mix backend types with different native message paths.

Unification cleanup_interval now takes effect

model_registry.unification.cleanup_interval (and stale_threshold) were silently ignored: the registry built a config but factory.CreateWithConfig(DefaultUnifierType, ...) discarded it and called NewDefaultUnifier(), which hard-coded a 5m cleanup interval. So config.yaml advertised 10m while the unifier actually ran at 5m.

  • NewDefaultUnifierWithConfig now honours the supplied CleanupInterval/ModelTTL (with safe fallbacks), and CreateWithConfig uses it for the default unifier.
  • The registry gate also triggers on a cleanup_interval-only config, with each override guarded so an unset field can't zero a default.
  • DefaultConfig() sets the same values so no-config-file runs match the shipped config.

Tests added in internal/adapter/unifier covering config propagation and zero-value fallback.

Smaller fixes

  • /version self-path: the handler reported its own path as /internal/version in the JSON body, but the registered route is /version (the old value always 404'd). Corrected.
  • llamacpp.yaml: corrected a stale comment claiming llama.cpp is the only backend with token counting (DMR and vLLM-MLX also set token_count: true).
  • config.yaml: prefix_hash comment now names the algorithm correctly (64-bit FNV-1a).

Config defaults made consistent without changing runtime behaviour

config.yaml and DefaultConfig() had drifted apart. This reconciles them to a single source of truth, choosing the safest value for each so existing deployments are not disrupted: never lowering a timeout, only adopting safe increases.

  • load_balancer: kept at least-connections (shipped value); the code default constant now matches
  • connection_timeout: 60s, response_timeout: 15m, read_timeout: 10m (shipped values; code defaults raised to match rather than lowered)
  • max_body_size 50MB to 100MB, max_header_size 512KB to 1MB, server read_timeout 20s to 30s (safe increases, applied to both)

Net effect: no existing setup gets a tighter timeout or a different balancer on upgrade. The unification cleanup cadence moves from an effective 5m to the documented 10m, which is benign housekeeping.

Verification

make ready passes (short + race tests, fmt, vet, golangci-lint 0 issues, betteralign).

Summary by CodeRabbit

  • Bug Fixes

    • Fixed message routing to use backend-specific paths when available, ensuring requests are sent to the correct endpoint.
  • Chores

    • Updated default server timeouts and request limits for improved performance and stability.
    • Adjusted default load balancer strategy and proxy timeout configuration.
    • Updated backend documentation to clarify token-counting support across multiple backends.
    • Enhanced model registry cleanup configuration flexibility.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026 •

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Adds backend-aware passthrough target path resolution with tests; increases server and proxy timeouts and request size limits; updates code defaults for load balancing and model-unifier thresholds; fixes version endpoint and profile documentation.

Changes

Passthrough Message Path Resolution

Layer / File(s) Summary
Handler implementation and logging
internal/app/handlers/handler_translation.go
Passthrough execution resolves target path via new resolvePassthroughTargetPath helper by checking candidate endpoints' Anthropic MessagesPath; if all agree, that path is used; otherwise the translator default is preserved. Passthrough start log includes target_path.
Test coverage for path override behaviour
internal/app/handlers/handler_translation_passthrough_test.go
Two tests: a single backend with custom MessagesPath forwards to that backend path; multiple backends with differing MessagesPath retain the neutral /v1/messages target when no agreement exists.

Configuration and Runtime Tuning

Layer / File(s) Summary
Server and proxy transport configuration
config/config.yaml
Server read_timeout increased to 30s; server.request_limits max_body_size → 100MB and max_header_size → 1MB; proxy backend response_timeout and read_timeout increased; proxy default-engine comment and sticky-session prefix_hash comment updated.
Code defaults, API path, and profile docs
internal/config/config.go, internal/app/handlers/handler_version.go, config/profiles/llamacpp.yaml
DefaultConfig sets proxy default timeouts and DefaultLoadBalancer to least-connections, and Unification.StaleThreshold to 24h; version endpoint changed to /version; llamacpp profile comment broadened token-counting support.
Unifier configuration and factory wiring
internal/adapter/unifier/*.go, internal/adapter/registry/unified_memory_registry.go, internal/adapter/unifier/default_unifier_config_test.go
Default unifier construction now accepts operator-supplied CleanupInterval and ModelTTL via NewDefaultUnifierWithConfig; Factory.CreateWithConfig and registry wiring were updated to propagate config; tests added to validate propagation and fallbacks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • thushan/olla#108: Modifies passthrough logic in the same handler code path (endpoint filtering) and is closely related to this PR's passthrough target path resolution.

Suggested labels

configuration

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main objectives: fixing Anthropic passthrough path handling for Docker Model Runner and aligning configuration defaults across the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/anthropic-passthrough-messages-path

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
internal/app/handlers/handler_translation.go (1)

97-118: 💤 Low value

Consider adding a doc comment and optional fallback logging.

The resolvePassthroughTargetPath function correctly implements consensus resolution, but lacks a doc comment explaining the "why" (per coding guidelines, comments should explain why rather than what). The function returns defaultPath in several fallback scenarios (nil profile, empty MessagesPath, mismatched paths), but doesn't log these cases, which could make troubleshooting harder for operators.

📝 Suggested improvement

Add a doc comment and consider optional debug logging:

+// resolvePassthroughTargetPath returns the agreed MessagesPath when all candidate
+// endpoints share the same non-empty native path, otherwise returns defaultPath.
+// This ensures homogeneous backend fleets (e.g., all DMR) can use their native path
+// whilst mixed deployments (DMR + vLLM) fall back to the neutral translator default.
 func (a *Application) resolvePassthroughTargetPath(endpoints []*domain.Endpoint, defaultPath string) string {
 	if a.profileLookup == nil || len(endpoints) == 0 {
 		return defaultPath
 	}
 
 	var resolvedPath string
 	for _, endpoint := range endpoints {
 		support := a.profileLookup.GetAnthropicSupport(endpoint.Type)
 		if support == nil || support.MessagesPath == "" {
+			// Optional: a.logger.Debug("falling back to neutral path", "endpoint", endpoint.Name, "reason", "missing_or_empty_messages_path")
 			return defaultPath
 		}
 		if resolvedPath == "" {
 			resolvedPath = support.MessagesPath
 			continue
 		}
 		if support.MessagesPath != resolvedPath {
+			// Optional: a.logger.Debug("falling back to neutral path", "reason", "path_mismatch", "expected", resolvedPath, "got", support.MessagesPath)
 			return defaultPath
 		}
 	}
 
 	return resolvedPath
 }

As per coding guidelines, comment on 'why' rather than 'what' in code.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/app/handlers/handler_translation.go` around lines 97 - 118, Add a
doc comment above resolvePassthroughTargetPath explaining why consensus-style
resolution is used (to ensure all endpoints agree on a single Anthropic
MessagesPath or else fall back to defaultPath) and add optional debug-level
logging where the function currently returns defaultPath (when a.profileLookup
is nil, endpoints empty, support == nil, support.MessagesPath == "", or
mismatched MessagesPath) to record which condition caused the fallback; use the
existing a.profileLookup.GetAnthropicSupport, endpoint.Type, and
support.MessagesPath symbols to construct concise log messages (debug) so
operators can trace why defaultPath was chosen without changing behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/app/handlers/handler_translation.go`:
- Around line 97-118: Add a doc comment above resolvePassthroughTargetPath
explaining why consensus-style resolution is used (to ensure all endpoints agree
on a single Anthropic MessagesPath or else fall back to defaultPath) and add
optional debug-level logging where the function currently returns defaultPath
(when a.profileLookup is nil, endpoints empty, support == nil,
support.MessagesPath == "", or mismatched MessagesPath) to record which
condition caused the fallback; use the existing
a.profileLookup.GetAnthropicSupport, endpoint.Type, and support.MessagesPath
symbols to construct concise log messages (debug) so operators can trace why
defaultPath was chosen without changing behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8b0d07a7-cff3-43b5-ae5d-31c84109d573

📥 Commits

Reviewing files that changed from the base of the PR and between 4874156 and 6a2f905.

📒 Files selected for processing (6)
  • config/config.yaml
  • config/profiles/llamacpp.yaml
  • internal/app/handlers/handler_translation.go
  • internal/app/handlers/handler_translation_passthrough_test.go
  • internal/app/handlers/handler_version.go
  • internal/config/config.go

@thushan
thushan force-pushed the fix/anthropic-passthrough-messages-path branch from 6a2f905 to dd257ed Compare June 9, 2026 11:54

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@config/config.yaml`:
- Line 80: Update the comment describing the prefix_hash configuration to
accurately name the algorithm: change the comment text for "prefix_hash" from
"FNV-64a" to "64-bit FNV-1a" so it matches Go's fnv.New64a() behavior; locate
the "prefix_hash" entry in the config and edit its trailing comment accordingly.

In `@internal/config/config.go`:
- Around line 136-141: Update the comment around the StaleThreshold and
CleanupInterval defaults to accurately describe current behavior: note that
unified_memory_registry only uses the custom-config path when
unificationConfig.StaleThreshold > 0 and that
CreateWithConfig(unifier.DefaultUnifierType, ...) currently ends up constructing
NewDefaultUnifier(), which hard-codes the CatalogStore cleanup interval to 5 *
time.Minute, so the effective cleanup cadence is 5m in both branches (and the
prior "intended 10m" rationale is incorrect). Reference the symbols
unified_memory_registry, StaleThreshold, Create, CreateWithConfig, and
NewDefaultUnifier in the comment so readers can locate the behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7f253965-9eb7-4efa-97df-684bf2bd3c3c

📥 Commits

Reviewing files that changed from the base of the PR and between 6a2f905 and dd257ed.

📒 Files selected for processing (6)
  • config/config.yaml
  • config/profiles/llamacpp.yaml
  • internal/app/handlers/handler_translation.go
  • internal/app/handlers/handler_translation_passthrough_test.go
  • internal/app/handlers/handler_version.go
  • internal/config/config.go
✅ Files skipped from review due to trivial changes (1)
  • internal/app/handlers/handler_version.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • config/profiles/llamacpp.yaml
  • internal/app/handlers/handler_translation.go
  • internal/app/handlers/handler_translation_passthrough_test.go

Comment thread config/config.yaml Resolved
Comment thread internal/config/config.go Resolved
@thushan
thushan force-pushed the fix/anthropic-passthrough-messages-path branch from dd257ed to 0923b19 Compare June 9, 2026 12:11

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
internal/adapter/unifier/default_unifier.go (1)

50-57: ⚡ Quick win

Avoid duplicating fallback default durations in the constructor.

Line 52 and Line 56 hard-code defaults that already exist in DefaultConfig(). If those defaults change later, this path can silently drift.

Suggested refactor
 func NewDefaultUnifierWithConfig(config Config) ports.ModelUnifier {
+	defaults := DefaultConfig()
 	cleanupInterval := config.CleanupInterval
 	if cleanupInterval <= 0 {
-		cleanupInterval = 5 * time.Minute
+		cleanupInterval = defaults.CleanupInterval
 	}
 	staleThreshold := config.ModelTTL
 	if staleThreshold <= 0 {
-		staleThreshold = 24 * time.Hour
+		staleThreshold = defaults.ModelTTL
 	}
 	return &DefaultUnifier{
 		store:          NewCatalogStore(cleanupInterval),
 		extractor:      NewModelExtractor(),
 		staleThreshold: staleThreshold,
 	}
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/adapter/unifier/default_unifier.go` around lines 50 - 57, The
constructor is re-duplicating default durations instead of reusing the canonical
defaults from DefaultConfig(); replace the hard-coded fallbacks for
cleanupInterval and staleThreshold with values taken from DefaultConfig() (e.g.,
call defaultCfg := DefaultConfig() and set cleanupInterval =
defaultCfg.CleanupInterval when config.CleanupInterval <= 0, and staleThreshold
= defaultCfg.ModelTTL when config.ModelTTL <= 0) so changes to DefaultConfig()
remain authoritative; update the code paths referencing CleanupInterval and
ModelTTL accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/adapter/unifier/default_unifier.go`:
- Around line 50-57: The constructor is re-duplicating default durations instead
of reusing the canonical defaults from DefaultConfig(); replace the hard-coded
fallbacks for cleanupInterval and staleThreshold with values taken from
DefaultConfig() (e.g., call defaultCfg := DefaultConfig() and set
cleanupInterval = defaultCfg.CleanupInterval when config.CleanupInterval <= 0,
and staleThreshold = defaultCfg.ModelTTL when config.ModelTTL <= 0) so changes
to DefaultConfig() remain authoritative; update the code paths referencing
CleanupInterval and ModelTTL accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 743dda15-c3ff-450f-8229-7a987b3c68f5

📥 Commits

Reviewing files that changed from the base of the PR and between dd257ed and 5dd9945.

📒 Files selected for processing (10)
  • config/config.yaml
  • config/profiles/llamacpp.yaml
  • internal/adapter/registry/unified_memory_registry.go
  • internal/adapter/unifier/default_unifier.go
  • internal/adapter/unifier/default_unifier_config_test.go
  • internal/adapter/unifier/factory.go
  • internal/app/handlers/handler_translation.go
  • internal/app/handlers/handler_translation_passthrough_test.go
  • internal/app/handlers/handler_version.go
  • internal/config/config.go
✅ Files skipped from review due to trivial changes (1)
  • internal/adapter/unifier/default_unifier_config_test.go
🚧 Files skipped from review as they are similar to previous changes (6)
  • internal/app/handlers/handler_version.go
  • config/profiles/llamacpp.yaml
  • internal/config/config.go
  • config/config.yaml
  • internal/app/handlers/handler_translation_passthrough_test.go
  • internal/app/handlers/handler_translation.go

@thushan
thushan merged commit b8f1341 into main Jun 9, 2026
5 checks passed
@thushan
thushan deleted the fix/anthropic-passthrough-messages-path branch June 9, 2026 12:26
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.

1 participant