Repository navigation
fix(recommendations): do not panic when the engine is disabled - #679
Merged
Merged
Conversation
Taste-profile and Because You Watched called a nil engine on the default install, where recommendations.enabled is false. Return the same empty payloads sibling handlers already use instead of HTTP 500. Part of #665 Co-authored-by: Quick <[email protected]>
Keep the nil-engine guard next to the other handler helpers instead of a package-level function that took the receiver as an argument. Co-authored-by: Quick <[email protected]>
Quick104
marked this pull request as ready for review
August 21, 2026 01:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Part of #665
On a default install
recommendations.enabledis false, so the recommendations engine is never constructed. The router still registers/api/v1/recommendations/taste-profileand/because-watched/{item_id}anyway. Those two handlers called methods on the nil engine, which panics (recovered as HTTP 500).Production logs from #665: 66/66 taste-profile requests failed over 17.5 hours, across 9 users. The web and Android taste-profile screens are broken for everyone until an admin turns recommendations on. Because You Watched has the same defect and would fail the first time a client hits it.
Sibling handlers already degrade:
HandleSimilarreturns an empty item list when the feature is off;HandleTasteProfilealready returned an empty summary on an engine error. The missing check was only the nil engine itself.Approach
Guard every handler that calls
h.engine(HandleTasteProfile,HandleBecauseWatched, andHandleSimilar) with!h.enabled || h.engine == nil, and return the same empty payloads those handlers already used on the disabled/error path.This keeps the v1 shape additive-safe: 500 → 200 empty on a path that never succeeded, so no working client behavior is being reused. Route registration is left as-is; gating that is a larger change and is not required to stop the panic.
Testing
New tests construct the production default (
engine=nil,enabled=false) and assert HTTP 200 with empty collections rather than a panic.AI Disclosure
HandleSimilarand the existing taste-profile error fallback already return 200 empty, and clients already decode that shape. Considered unregistering the routes when the engine is nil; that would be a larger contract change (clients that probe the path would start getting 404) and is not needed to stop the panic.HandlePopular/HandleRecentlyAddedstill userecsRepowithout a nil check, but in production that repo is constructed whenever the handler is; it is not the reported panic. Did not change session-liveness ([bug] Progress updates alone keep dead sessions alive forever — ghost sessions hold transcode slots for 15h with zero byte flow #666) in this PR — grace-window semantics are a product judgement, not a one-line correctness fix.Checklist
go test ./internal/api/handlers/...andmake verify-local-paths. Fullmake lint/pnpm run lintwere not re-run; this change is Go-only and CI lints new lines from merge-base.