Skip to content

fix(catalog): accept true/false strings and reject other values in boolean filters - #3173

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/1253-bool-filter-validation
Nov 1, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/1253-bool-filter-validation

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #1253
Validation tasks: changes Silo-Server/silo-android#350 C1 (released Android TV's Watch Status filters start working)

A catalog query with a true/false filter whose value is a string, such as {"field":"watched","op":"is","value":"true"}, answers 500 "An unexpected error occurred". Released Android TV builds send exactly that, so choosing Watched, In progress or Favorites shows a generic error. The rule passes validation and only fails later, in the query builder. Other strings, such as "yes", fail the same way.

The six true/false rule fields now accept a real boolean or exactly the strings "true" and "false", and any other value gets a 422 that names the field.

Approach

  • validateRuleValue checks watched, in_progress, favorited, in_watchlist, hdr and dolby_vision with one helper. It accepts a boolean or exactly "true"/"false", and rejects anything else, including "True", "1" and " true", as it already does for numbers, dates and decades.
  • QueryDefinition.Normalize() turns the two strings into booleans for those fields. The query builder, the item and episode executors and saved-definition loading all run on normalized definitions, so they only see booleans.
  • Released Android TV keeps its working HDR filter, which sends "true" inside an any group, and its Watched, In progress and Favorites filters now return results. Android main already sends booleans (fix(catalog): send boolean filter values as JSON booleans silo-android#702). Saved smart collections that hold the strings keep working. Saved rules with any other value are refused when saved instead of failing when they run.

Validation

  • New table test: all six fields × "true"/"false" × all/any groups validate and build the same SQL and arguments as the real boolean. It failed before the change, and still fails with only the Normalize step removed.
  • The existing malformed-rule-value test now rejects "True", "1", " true", numbers and null for each field; its rows failed before the change.
  • go test ./internal/catalog/... ./internal/apiv2/... ./internal/collections/..., make lint-changed: pass.
  • Runtime: see Evidence; on the fix build the string "true" returns the same items as the boolean.

Evidence

Evidence: POST /api/v2/catalog/query (native API) on a test audiobook library, as a viewer profile, with one watched is <value> rule. Before: a server built from the base commit e6df1d8ed. After: a server built from this branch's head 36d3ed9da merged with the other #1253 fixes. The two servers have separate test databases, so their watched books differ; on each server, compare the string rule with the real boolean.

Rule value Before (e6df1d8ed) After (36d3ed9da)
"true" (string) 500 "An unexpected error occurred." 200, 1 item: Hours of Static
"yes" (string) 500 "An unexpected error occurred." 422 "groups[0].rules[0]: watched requires true or false"
true (boolean) 200, 2 items 200, 1 item: Hours of Static

Risks

None identified.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (T3 Code)
  • Tool(s): Claude Code, Codex CLI, GitHub CLI, Playwright, Docker, ffmpeg
  • Model(s): claude-opus-5-5; gpt-6.1-sol (review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: Independent Claude Opus 5.5 and GPT 6.1 Sol reviews of the branch diff (correctness, repo standards, the bug as described), including how stored smart collections with string values load. Neither found a defect. Opus suggested marking boolean fields in queryFieldDefs instead of listing them in the validation switch; declined because the same switch already names its numeric and date fields this way.

Note

Fix catalog rule validation to reject non-boolean values for true/false filters

Adds a booleanRuleFields map covering watched, in_progress, favorited, in_watchlist, hdr, and dolby_vision in query_definition.go. validateRuleValue now accepts only Go booleans and the exact lowercase strings "true"/"false" for these fields, and QueryDefinition.Normalize converts accepted values to Go booleans. Other representations such as "1" and "T" are rejected. Tests in query_builder_rule_fields_test.go cover both rejection of malformed values and equivalence of canonical strings to boolean inputs.

  • Behavioral Change: queries previously accepted for these boolean fields (e.g. "1", "T", nil) now fail definition and catalog overlay validation

Macroscope summarized 36d3ed9.

A catalog query whose watched, in_progress, favorited, in_watchlist, hdr or
dolby_vision rule carried a string such as "true" passed validation and then
failed in the query builder, so the API answered 500. Validate the value with
the other rule values so the request gets a 422 naming the field.
@silo-triage silo-triage Bot added the size/S 0–49 added + deleted lines (all files); change volume, not priority. label Oct 27, 2026
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a4e355e6-ed4b-4d21-8d65-de418c63ace4
Commits

Reviewing files that changed from the base of the PR and between 62b1a6e and 36d3ed9.

Files selected for processing: 2
  • internal/catalog/query_builder_rule_fields_test.go
  • internal/catalog/query_definition.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Walkthrough

Boolean query rules now accept boolean values and the exact strings "true" and "false". Normalization converts accepted strings to booleans. Tests cover invalid values and equivalent query output.

Changes: Boolean query rule values

Layer / File(s) Summary
Validation, normalization, and query coverage
internal/catalog/query_definition.go, internal/catalog/query_builder_rule_fields_test.go
Boolean rule validation accepts booleans and exact "true" or "false" strings. Normalization converts those strings to booleans. Tests cover malformed values and confirm string inputs produce the same SQL and arguments as boolean inputs for all and any matching.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: quick104

Merge Risk: Minimal · up to 36d3e

Exact boolean strings remain supported, and no merge-blocking regression was identified.

Security architecture risk: Minimal · up to 36d3e

The accepted strings are restricted to exactly "true" and "false" and become ordinary booleans before SQL construction. The reviewed paths retain existing query scoping and validation controls. No material security risk introduced or worsened by this change was identified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The newly executable string forms reach existing catalog predicates over media metadata and profile-specific viewing/list state. Their normalized values express the same two choices already available through native booleans; they do not supply identity, library scope or arbitrary SQL.

Trust Boundaries and Controls

  • observed — Personal predicates still require user/profile scope and use scoped query arguments. HDR values are bound parameters, Dolby Vision uses fixed predicates selected by a boolean, and the complete query expression remains parenthesized when combined with outer constraints.

Resilience and Maintainability Implications

  • observed — The relevance-search overlay uses a separate in-memory matcher without boolean-field cases or explicit normalization. That divergence already exists in the base revision; the inspected change does not establish a new access-control bypass through it.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: boolean catalog filters now accept exact "true"/"false" strings and reject other values.
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.
Description check Passed The pull request description directly explains the boolean catalog filter validation and normalization changes, including affected fields, tests, compatibility behavior, and user-visible error handlin…
Full details: Description check

Explanation

The pull request description directly explains the boolean catalog filter validation and normalization changes, including affected fields, tests, compatibility behavior, and user-visible error handling.

Full details: Docstring Coverage

Explanation

Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@silo-kody

silo-kody Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Oct 27, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 27, 2026

Copy link
Copy Markdown

The catalog-query API now returns 422 instead of 500 for a non-boolean filter value, which changes the response visible to clients. The before/after table covers that response change, but does not name the surface or identify the build/commit for each capture. Please identify the catalog-query API surface and tie each response to its source commit; the Evidence: none statement also conflicts with the response comparison.

Suggested fix: update the Evidence section with the surface and before/after commits, and remove the Evidence: none statement.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

AI-generated review posted by Quick104 using Codex (gpt-6.1-sol, xhigh) in T3 Code, with an independent Claude (claude-opus-5-5, high) review. Evidence comes from source inspection and an executable harness; no live server or device run was performed.

One P2 finding remains at c5aa5cb936031c32d532948d3990da7ec7180167: strict HDR validation rejects the request sent by released Android clients. The inline finding gives the trigger, evidence, and repair. Preserving the existing HDR string form is my recommendation; requiring a newer Android release needs an explicit rollout decision.

Comment thread internal/catalog/query_definition.go Resolved
@Quick104

Quick104 commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Fit: 10/10 · Readiness: 9/10 — ready.

Reviewed head 36d3ed9da53fc1076d82d0ddd54e1d2c99d1ea7f against base 62b1a6e82408eb4be3409255583bf8b0a192a69f.

The fix belongs in the catalog rule validator, and it now keeps released clients working. The HDR finding from the previous round is fixed: the six true/false fields accept a boolean or exactly "true"/"false", Normalize turns those strings into booleans, and any other value gets a 422 that names the field. No findings remain.

Verification

  • Both PR tests fail on the base and pass at the head. TestMalformedRuleValuesFailValidation fails on all six new rows. TestBooleanRuleStringValuesBuildAsBooleans fails for every field: the base rejects the strings in all groups, and in any groups it builds HDR with the string argument instead of the boolean.
  • Every builder that reads rule.Value.(bool) (the item query builder and both episode catalog builders) receives a normalized definition, so they only see booleans.
  • The head merged onto current main passes the catalog, apiv2, collections, sections and jellycompat Go suites. CI is green on the head.
  • This round reviewed only the change since c5aa5cb93, by hand. The earlier round's Codex and Claude reviews covered the rest of the diff. No new live HTTP or device run; the PR's Evidence table records the author's before-and-after API responses.

Remaining for maintainers: none blocking. One edge case is accepted on purpose: the base accepted other PostgreSQL boolean strings such as "1" or "t" for hdr/dolby_vision inside any groups, and those now get a 422. No first-party client sends them: Apple and web send booleans, and Android beta.27 sends only "true"/"false".

Validated features: Silo-Server/silo-android#350 C1 changes as the PR's Validation tasks: line says. Released Android TV's Watched, In progress and Favorites filters return results instead of an error, and its HDR filter keeps working. After merge, the validator should re-test C1 on the merged build.

Clients and docs: no client change is needed. Android main already sends booleans (Silo-Server/silo-android#702), and Apple and web always did. jellycompat shares the saved-definition validation and gets the same behavior. The manual describes neither the error nor the accepted value types, so it needs no issue.

Note

AI-generated review posted by Quick104. Previous round: Codex (gpt-6.1-sol) with one Claude (claude-opus-5-5) round. This round: 🤖 Claude Code (claude-opus-5-5) in T3 Code, with GitHub CLI and Go.

Released Android TV v1.0.0-beta.27 sends the HDR filter, and its watched,
in-progress and favorites filters, as the JSON strings "true" and "false".
The previous commit answered those with 422. Read exactly those two strings
as booleans when the definition is validated and normalized, so the query
builder only sees real booleans and saved definitions that hold them keep
working. Any other non-boolean value still fails validation.
@silo-triage silo-triage Bot added size/M 50–199 added + deleted lines (all files); change volume, not priority. and removed size/S 0–49 added + deleted lines (all files); change volume, not priority. labels Oct 28, 2026
@silo-kody

silo-kody Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Rhainland Rhainland changed the title fix(catalog): reject non-boolean values for true/false filters fix(catalog): accept true/false strings and reject other values in boolean filters Oct 28, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 28, 2026

Copy link
Copy Markdown

At internal/catalog/query_definition.go, released Android TV boolean-string filters such as watched is "true" now return filtered items instead of an error. The Evidence table gives the after result as an expectation from builder tests, not an API response captured from this head. Please add before-and-after catalog-query response excerpts for the same request and name the source commit/build for each capture.

The invalid-string case (watched is "yes") also changes from a generic failure to a field-specific 422, but its table entry likewise lacks captured before-and-after API responses and their source commits/builds.

Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness.

Posted via Macroscope — Visible change evidence

@Quick104
Quick104 merged commit 57727ff into Silo-Server:main Nov 1, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants