Skip to content

fix(recommendations): do not panic when the engine is disabled - #679

Merged
Quick104 merged 3 commits into
mainfrom
cursor/critical-bug-management-446d
Aug 21, 2026
Merged

Quick104 merged 3 commits into
mainfrom
cursor/critical-bug-management-446d

Conversation

@cursor

@cursor cursor Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Problem

Part of #665

On a default install recommendations.enabled is false, so the recommendations engine is never constructed. The router still registers /api/v1/recommendations/taste-profile and /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: HandleSimilar returns an empty item list when the feature is off; HandleTasteProfile already 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, and HandleSimilar) 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

$ go test ./internal/api/handlers/ -run 'TestHandleTasteProfile_NilEngineReturnsEmpty|TestHandleBecauseWatched_NilEngineReturnsEmpty|TestHandleSimilar_NilEngineReturnsEmpty' -count=1
ok  \tgithub.com/Silo-Server/silo-server/internal/api/handlers\t0.061s

$ go test ./internal/api/handlers/ -run 'TestRecommendations|TestHandleTaste|TestHandleBecause|TestHandleSimilar|TestDiscover' -count=1
ok  \tgithub.com/Silo-Server/silo-server/internal/api/handlers\t0.060s

$ make verify-local-paths
scripts/check-local-path-leaks.sh

New tests construct the production default (engine=nil, enabled=false) and assert HTTP 200 with empty collections rather than a panic.

AI Disclosure

  • Tool(s): Cursor Automation (cron bug-finding agent)
  • Model(s): Cursor Grok 4.6
  • Involvement: fully AI-generated
  • Adversarial review: considered returning 404/503 instead of 200 empty; rejected because HandleSimilar and 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 / HandleRecentlyAdded still use recsRepo without 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

  • I ran an adversarial AI review of the diff and summarized findings above.
  • I ran the repo verify commands for the packages touched: targeted go test ./internal/api/handlers/... and make verify-local-paths. Full make lint / pnpm run lint were not re-run; this change is Go-only and CI lints new lines from merge-base.
Open in Web View Automation 

cursoragent and others added 2 commits August 19, 2026 11:09
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
Quick104 marked this pull request as ready for review August 21, 2026 01:23
@Quick104
Quick104 merged commit 78b5d39 into main Aug 21, 2026
3 checks passed
@Quick104
Quick104 deleted the cursor/critical-bug-management-446d branch August 21, 2026 01:24
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