Repository navigation
fix: anthropic passthrough path for Docker Model Runner + align config defaults - #171
Conversation
WalkthroughAdds 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. ChangesPassthrough Message Path Resolution
Configuration and Runtime Tuning
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/app/handlers/handler_translation.go (1)
97-118: 💤 Low valueConsider adding a doc comment and optional fallback logging.
The
resolvePassthroughTargetPathfunction correctly implements consensus resolution, but lacks a doc comment explaining the "why" (per coding guidelines, comments should explain why rather than what). The function returnsdefaultPathin 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
📒 Files selected for processing (6)
config/config.yamlconfig/profiles/llamacpp.yamlinternal/app/handlers/handler_translation.gointernal/app/handlers/handler_translation_passthrough_test.gointernal/app/handlers/handler_version.gointernal/config/config.go
6a2f905 to
dd257ed
Compare
There was a problem hiding this comment.
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
📒 Files selected for processing (6)
config/config.yamlconfig/profiles/llamacpp.yamlinternal/app/handlers/handler_translation.gointernal/app/handlers/handler_translation_passthrough_test.gointernal/app/handlers/handler_version.gointernal/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
dd257ed to
0923b19
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/adapter/unifier/default_unifier.go (1)
50-57: ⚡ Quick winAvoid 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
📒 Files selected for processing (10)
config/config.yamlconfig/profiles/llamacpp.yamlinternal/adapter/registry/unified_memory_registry.gointernal/adapter/unifier/default_unifier.gointernal/adapter/unifier/default_unifier_config_test.gointernal/adapter/unifier/factory.gointernal/app/handlers/handler_translation.gointernal/app/handlers/handler_translation_passthrough_test.gointernal/app/handlers/handler_version.gointernal/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
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 viaanthropic_support.messages_path. The translator hardcoded/v1/messagesand ignored the profile, so passthrough to DMR returned 404.executePassthroughRequestnow resolves the target path from the backend profile viaresolvePassthroughTargetPath. 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(andstale_threshold) were silently ignored: the registry built a config butfactory.CreateWithConfig(DefaultUnifierType, ...)discarded it and calledNewDefaultUnifier(), which hard-coded a 5m cleanup interval. So config.yaml advertised10mwhile the unifier actually ran at5m.NewDefaultUnifierWithConfignow honours the suppliedCleanupInterval/ModelTTL(with safe fallbacks), andCreateWithConfiguses it for the default unifier.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/unifiercovering config propagation and zero-value fallback.Smaller fixes
/versionself-path: the handler reported its own path as/internal/versionin 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 settoken_count: true).config.yaml:prefix_hashcomment now names the algorithm correctly (64-bit FNV-1a).Config defaults made consistent without changing runtime behaviour
config.yamlandDefaultConfig()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 matchesconnection_timeout: 60s,response_timeout: 15m,read_timeout: 10m (shipped values; code defaults raised to match rather than lowered)max_body_size50MB to 100MB,max_header_size512KB to 1MB, serverread_timeout20s 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 readypasses (short + race tests, fmt, vet, golangci-lint 0 issues, betteralign).Summary by CodeRabbit
Bug Fixes
Chores