Skip to content

feat(api): mark which of my collections hold a title - #1907

Merged
Quick104 merged 5 commits into
feat/collections-revampfrom
feat/api-collections-contains-item
Oct 4, 2026
Merged

Quick104 merged 5 commits into
feat/collections-revampfrom
feat/api-collections-contains-item

Conversation

@Quick104

@Quick104 Quick104 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #192
Validation tasks: changes #193 S1, S2, S3

Stacked on #1904 (fix/sections-missing-collection-log).

The Add to collection dialog on a title's page can't show which of the profile's collections already hold that title. GET /api/v2/collections lists the collections but not their members, so a client would have to read every collection's items to find out. The redesigned dialog shows one checkbox per collection, ticked when the collection already holds the title, so it needs that answer from the list it already loads.

listCollections now accepts an optional contains_item, a title's content id. When a client sends it, each of the acting profile's own manual collections carries contains: true or false. getCollectionCapabilities reports contains_item: true so clients can check before sending the parameter.

Approach

  • Only the acting profile's own manual collections get contains, using the same ownership test as the routes that change a collection. Smart collections, synced lists and collections another profile shares leave it out, because Add to collection can't add titles to them. This follows the maintainer's decision for the collections redesign that Add to collection lists only the profile's own collections.
  • Before reading membership, the server checks that the profile can access the title, with the same check it runs when a title is added to a collection. A title in a library the profile can't see, above its rating limit, or that doesn't exist reports false on every collection, even one that still stores it. The parameter can't be used to learn that a hidden title exists.
  • Membership costs one query per request, however many collections the profile has: a select over the profile's manual collections with an EXISTS lookup on the collection item table's primary key. The PostgreSQL and SQLite user stores both implement it. Without the parameter the query doesn't run and the list request is unchanged.
  • /api/v1 is unchanged. contains is set only in the /api/v2 mapping, and the v1 list ignores the parameter.
  • contains is an optional member of the shared PersonalCollection schema, so the contract diff also lists it on the create, get, update, poster and import responses. Those responses never set it.
  • docs/catalog-api.md documents the parameter and the flag next to the other personal collection sections (there is no separate collections API doc). The OpenAPI document, fixtures, system-info digest and web types are regenerated. The new fixture is added at the end of the list, so no existing fixture's request id changes.

No web code sends the parameter yet; the redesigned Add to collection dialog will. jellycompat needs no change, and the user manual doesn't describe API fields. The silo-apple and silo-android follow-up is not filed yet: tick collections in Add to collection from contains when contains_item is true.

This changes validated behavior in #193. S3 needs re-validation after merge: contains_item is a new read path on the collection list, and its recorded pass predates it. The path still meets the S3 criterion: before reporting membership, the server runs the same title access check as an add, so a title in a hidden library or above the profile's rating limit reports false on every collection, including on a direct request. S1 and S2 need a re-check: the list now carries membership data, only on the acting profile's own manual collections, and contains should follow adds and removals. Without the parameter the list is unchanged.

Validation

  • Go: build, gofmt, vet and make lint-changed against fix/sections-missing-collection-log are clean. make test-go and make test-db-pins pass.
  • apiv2, userdb, userstore and api/handlers ran against a freshly migrated PostgreSQL database. The tests cover contains on own manual collections, no flag and no membership read without the parameter, no flag on smart, synced or shared-with-me collections, and a membership read error failing the request instead of reporting false. A store test runs on both user stores. Restating Collections — Server #193 S1 to S3: another profile on the same login sees only its own collection, another login gets nothing, and a title in a hidden library, above the profile's rating limit, or unknown reports false everywhere. The v1 list is byte-identical with and without the parameter. With the access check removed, the hidden-library case fails.
  • Two DB-backed handler tests this branch doesn't touch fail on that database, the same way on the base commit: TestAdminSubtitleListPageDB and TestCatalogTransferPersistsJobsAndSignedLink.
  • Contract: verify-apiv2-openapi, verify-apiv2-contract (11 additive changes, none breaking), verify-apiv2-fixtures, verify-apiv2-web-types, verify-route-inventory, verify-migration-ledger, verify-offline-routes and TestCommittedArtifactMatchesRouter pass. So do verify-settings-bindings-all, verify-playback-fixtures and verify-scenario-catalogs.
  • Web (generated types only): lint, format:check, build, budget:check, tsc -b and make test-web pass.
  • make verify-local-paths passes.

Risks

  • getCollectionCapabilities reports contains_item: true unconditionally. A user store without the membership read would answer the parameter with 501; both stores Silo ships implement it.
  • A request with contains_item runs the title access check and one membership query on top of the list. Requests without it are unchanged.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code (in T3 Code)
  • Tool(s): Claude Code subagents (implementer, independent reviewer)
  • Model(s): claude-opus-5-5[1m]
  • Involvement: Fully AI-generated, human review pending
  • Adversarial review: An independent reviewer subagent read the full diff. It checked that the ownership test matches the one the collection mutation routes use, that both production user stores implement the membership read, and that a hidden or unknown title returns an empty answer rather than an error that would reveal it exists. It ran the new tests and the whole apiv2 package on its own freshly migrated database and confirmed the generated files were current. It did not run mutation tests itself; the implementer removed the access check and saw the hidden-library case fail. The reviewer found nothing to fix.

🤖 Generated with Claude Code

Note

Add contains_item query to listCollections v2 API

  • GET /api/v2/collections accepts a contains_item title ID and returns a contains boolean on each of the acting profile's own manual collections. The member is omitted for shared, smart, synced, and other-profile collections, and when the query is absent.
  • Adds the CollectionMembershipReader store interface with a ManualCollectionsHolding method, implemented for SQLite and Postgres, and delegated through the notification interest-tracking store wrapper.
  • GET /api/v2/collections/capabilities now reports contains_item: true when the personal collection service is configured.
  • Regenerated OpenAPI contract, TypeScript schema, and fixtures; documented in catalog-api.md. A shared conformance suite in collection_holding.go checks membership rules across store backends.
  • Risk: none; the frozen v1 endpoint ignores contains_item and never emits contains, verified in collections_contains_item_test.go.

Macroscope summarized 3131f36.

Add to collection needs to tick the collections that already hold the
title. Until now a client had to read every collection's items to find
out.

listCollections takes an optional contains_item content id. Each of the
acting profile's own manual collections then carries contains, true or
false; smart collections, synced lists and collections another profile
shares carry no flag. One query answers it for every collection. A title
the profile can't access, or one that doesn't exist, reports false
everywhere, so the answer reveals nothing about hidden titles. The
collection capabilities report contains_item. The flag lives on the
/api/v2 mapping only; /api/v1 ignores the parameter and its list is
unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 63520f58-1800-4920-8470-7a1e068d234c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-04T22:04:50.059439Z 3131f36 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 897f80bfff

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


// PersonalCollectionListInput is the listCollections request.
type PersonalCollectionListInput struct {
ContainsItem string `query:"contains_item" doc:"A title's content id. Each of the acting profile's own manual collections then carries contains. Accepted when getCollectionCapabilities reports contains_item" example:"01J9Z8C3W4R5T6Y7U8I9O0P1Q5"`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge File the required mobile client follow-ups

This introduces a client-visible API parameter and response field, but the commit description explicitly says the silo-apple and silo-android follow-ups have not been filed. Create or complete both platform follow-ups before treating this change as done so neither client is left without the collection-membership behavior.

AGENTS.md reference: AGENTS.md:L146-L152

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed that the follow-ups are still open, but this is a process item rather than a code defect, so there is no commit for it. The silo-apple and silo-android issues (tick collections in Add to collection from contains when getCollectionCapabilities reports contains_item) are drafted and wait on the maintainer before they are filed. The PR body already lists them as not filed, and the change is not done until both exist.

@macroscopeapp

macroscopeapp Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Major change — #193 S3: GET /api/v2/collections?contains_item=… adds a new membership-read path that filters restricted titles before reporting collection membership. The recorded S3 result predates this path; the PR must explain why this changes validated behavior, and S3 needs re-validation after merge.

Minor changes — #193 S1 and S2: the same query adds owner-scoped membership data to the list and a new membership read for the add/remove workflow. Re-check profile/account ownership boundaries and that contains tracks persisted membership after add/remove. Without the parameter, the existing list remains unchanged.

Suggested replacement:
Validation tasks: changes #193 S1, S2, S3

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

…log' into feat/api-collections-contains-item

# Conflicts:
#	contracts/api/v2/fixtures/get_collection_capabilities_ok.json
#	contracts/api/v2/fixtures/get_system_info_ok.json
#	contracts/api/v2/fixtures/index.json
#	contracts/api/v2/openapi.json
#	internal/apiv2/personal_collections.go
#	internal/apiv2/personal_collections_test.go
@Quick104

Quick104 commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Updated the PR body: the Validation tasks line now reads changes #193 S1, S2, S3, and the Approach section explains why S3 needs re-validation after merge and S1 and S2 need a re-check.

…log' into feat/api-collections-contains-item

Brings in login-wide personal collection sharing (#1875), the scrobble
lock fix (#1887), and the earlier phase-1 collection PRs. The contains_item
tests now create shared collections with is_shared alone, since
allowed_profile_ids is gone. The capability test expects both
login_sharing and contains_item. The fixture list carries the shared
collection, which gets no contains flag. Contract artifacts were
regenerated.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3c3b0eb47c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +78 to +80
reader, ok := store.(userstore.CollectionMembershipReader)
if !ok {
return nil, apiError(http.StatusNotImplemented, "unsupported", "This store cannot report collection membership")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve collection membership through the store wrapper

In normal integrated/API startup, cmd/silo/main.go wraps the user-store provider with notifications.WrapUserStoreProvider, whose returned decorators embed only the userstore.UserStore interface and do not forward the new optional CollectionMembershipReader. Consequently this assertion fails for both PostgreSQL and SQLite in production, and every listCollections?contains_item=... request returns 501 capability_unsupported even though getCollectionCapabilities advertises contains_item: true. Forward this capability through the notification wrapper and cover the wrapped-provider path in a test.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 3131f36

Base automatically changed from fix/sections-missing-collection-log to feat/collections-revamp October 4, 2026 21:42
…at/api-collections-contains-item

# Conflicts:
#	contracts/api/v2/fixtures/get_system_info_ok.json
#	internal/apiv2/fixtures_test.go
#	internal/apiv2/personal_collections_test.go
#	web/src/api/v2/schema.ts

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 745470c674

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// Only the profile's own manual collections take a title from Add
// to collection; every other collection leaves contains out.
if marking && c.CreatorProfileID == profileID && c.CollectionType == collectionTypeManual {
item.Contains = new(holding[c.ID])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Allocate a pointer to the membership value correctly

This expression does not compile because new requires a type argument, while holding[c.ID] is a boolean value. As a result, the package cannot build; create a bool variable (or use a helper that returns *bool) and assign its address instead.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not a defect: go.mod sets go 1.26.4, and since Go 1.26 new accepts an expression and returns a pointer to a copy of its value, so new(holding[c.ID]) is a *bool holding the membership flag. The package builds and "ci / CI result" passed on 3131f36; go build ./... and TestContractFixtures (which pins contains: true/false in list_collections_contains_item_ok.json) also pass locally.

…tore wrapper

Production wraps every user store in the notification decorator, which
embeds only userstore.UserStore. The new CollectionMembershipReader was
lost there, so listCollections?contains_item answered 501 on both
backends. Forward it like the decorator's other optional reads, and run
the handler test through the wrapped provider.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@Quick104
Quick104 merged commit e60016c into feat/collections-revamp Oct 4, 2026
19 checks passed
@Quick104
Quick104 deleted the feat/api-collections-contains-item branch October 4, 2026 22:17
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