Repository navigation
feat(metadata): read metadata AI status and translate descriptions through v2 - #390
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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.
Quick104 has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Code review summaryReviewed head: Process: an adversarial review of this PR's diff with each candidate finding independently verified before any fix, a simplify pass for medium and larger PRs, and a whole-stack review across contract conformance, authority and failure handling, data integrity, user-visible behavior and cross-PR integration. Verified findings, all fixed on this branch:
Validation: this branch builds on its own for iOS, tvOS and macOS, and its focused tests passed. The completed stack passed the full iOS suite (1981 tests) and tvOS suite (1792 tests) with 0 failures, the macOS build and the v1 path guard. The final stack was also exercised on iOS and tvOS simulators against a v1/v2 bridge server: sign-in (password and QR), restore, browse, search, detail, favorites and watchlist, playback (direct play, transcode, subtitles, stop), audiobooks, downloads with offline playback, settings, requests, profiles, push registration and diagnostics. Server logs showed no Remaining: no open verified findings. Merge in stack order. Mergeability: 8/10 — conditional. The approach holds up and every verified finding is fixed. Conditions: this PR's CI must pass (it was pending at review time), and the owner still plans a physical-device check of the completed stack. Review by Claude Opus 5.5 ( |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c54f7063d1
ℹ️ 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".
| auth = try await api.captureAuthority() | ||
| guard isCurrentRun(runID) else { return } | ||
| let job = try await api.translateDescription(contentId: contentId, targetLanguage: targetLanguage, auth: auth) |
There was a problem hiding this comment.
Bind translation to the displayed detail owner
The repository ownership contract says a displayed catalog read must authorize its later action rather than capturing whichever profile is current after asynchronous work begins (docs/native-api-v2.md:12-16). Here no owner is retained from the displayed detail, and captureAIAuthority() itself awaits gate() before reading TokenStore; if the identity changes while the task is queued or that gate is suspended and the view remains active, this captures the replacement profile and posts the old item's translation for it. isCurrentRun only checks cancellation/run identity, so pass the detail's captured owner into the coordinator (or otherwise snapshot it before the first suspension) and fence the POST against that owner.
Useful? React with 👍 / 👎.
c54f706 to
ca67075
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ca67075250
ℹ️ 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".
| } | ||
| guard raw.statusCode == 202 else { throw APIv2Error.httpStatus(raw.statusCode) } | ||
| let job = try HTTPClient.makeJSONDecoder().decode(APIv2MetadataTranslationJob.self, from: raw.data) | ||
| guard !job.id.isEmpty, job.contentId == contentID, ["item", "season", "episode"].contains(job.targetKind) else { |
There was a problem hiding this comment.
Verify the translation job's target language
When the 202 response names the requested item but contains a different target_language, this guard accepts it even though the decoded field is the only evidence that the returned/coalesced job represents the requested translation. The coordinator then polls for the requested language while tracking an unrelated job, leaving the UI spinning until its roughly 31-second timeout or potentially applying an unintended translation; reject responses whose job.targetLanguage does not match language.
Useful? React with 👍 / 👎.
40e5048 to
7330831
Compare
…rough v2
SiloAI still read the metadata AI capability from
/api/v1/metadata/ai/status and queued description translations at
/api/v1/items/{id}/translate-description. A 1.0 server answers both with
410, so the on-view translate affordance never appeared. The v2
translation answers 202 with a job body, needs a selected profile, and
can return a recently failed job without starting new work.
SiloAI now calls the shared APIv2Client for both. The capability read
sends X-Profile-Id and enables the feature only when the profile is
allowed and the state is available. DescriptionTranslationCoordinator
captures the owner before its first await, sends the POST for that
owner, shows the failed state for a reused failed or canceled job, and
stops polling without applying a detail read once the account or
profile changes. The POST is coalescing, so a failed attempt stays
retryable from the Translate button.
Move the metadata AI methods to APIv2Client+MetadataAI.swift and their
wire models to APIv2MetadataAIModels.swift, rename the shared AI owner
capture to captureAIAuthority, and delete the v1 MetadataAIStatus
decoder and its test.
Stack-PR: W5-S
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The AIModels.swift header still said every model rides /api/v1 and listed the metadata AI status and translate-description routes, which this PR moved to APIv2Client. Point the header at APIv2MetadataAIModels.swift for the metadata wire shapes and keep only the subtitle AI routes in the v1 endpoint list. Stack-PR: W5-S Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ca67075 to
827f7d3
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
The item-detail "Translate" affordance works on 1.0 servers again: the metadata AI capability read and the description translation now use v2.
Problem
The Apple clients still read the metadata AI capability from
GET /api/v1/metadata/ai/statusand queued description translations withPOST /api/v1/items/{id}/translate-description. A 1.0 server answers both with 410, so the item-detail "Translate" affordance never appears. The v2 translate operation differs from v1: it answers 202 with aMetadataTranslationJobbody, requiresX-Profile-Id, and can return a recently failed job without starting new work.Solution
SiloAI.metadataAIStatus()callsGET /api/v2/capabilities/metadata-ai(getMetadataAICapability) on the sharedSiloAPI.shared.apiV2Client. The read needs a selected profile and sendsX-Profile-Id. The feature is enabled only whenallowed && state == "available". An unknownon_viewvalue decodes to.off, and an emptyrevisionis rejected.SiloAI.translateDescription(contentId:targetLanguage:auth:)callsPOST /api/v2/catalog/items/{id}/translate-description(translateCatalogItemDescription) with acatalogPathSegment-encoded id. The call runs insidewithOwnerFencefor the captured owner and accepts only 202. It rejects a job that names a different item or an unknowntarget_kind.DescriptionTranslationCoordinatorcaptures the owner before its first await and sends the POST for that owner. A returnedfailedorcanceledjob puts the coordinator in its failed state. Before each detail poll and before applying a result, it checks that the owner is still current. After an account or profile change, it stops with the failed state and applies nothing.APIv2Client+MetadataAI.swiftand their wire models move toAPIv2MetadataAIModels.swift. The shared AI owner capture is renamed fromsubtitleCreateAuthority()tocaptureAIAuthority(); it had no app callers yet.MetadataAIStatusdecoder and its v1 wire test, and the v1TranslateDescriptionBody.MetadataAIStatusis now a plain domain value. TheAIModels.swiftheader no longer lists the metadata routes as v1 and points toAPIv2MetadataAIModels.swift.Failure outcomes for the translate POST. The contract marks it
x-silo-retry-safety: coalescing, so the server reuses an active job for the same item and language:pending_translation_languageclears..autolatch prevents automatic re-firing.Validation
MetadataAIV2Tests,APIv2ContractTests,AIModelDecodingTestsandAPIv2SubtitleTests, 61 tests each, 0 failures.MetadataAIV2Tests(StubURLProtocol) cover:X-Profile-Idallowed/stategate{"target_language"}bodyscripts/ci/check-no-api-v1.shpasses. ThewithOwnerFence/sameCredentialIdentitycount iniosApp/iosAppstays at 69.Risks and follow-ups
AICapabilitiesstill treats a failed capability read as "feature unavailable" until the next refresh (app foreground, cold launch, sign-in or profile switch). That matches the current behavior, but plan invariant I9 asks for a retryable state. This PR does not add a retry path.ETagandIf-None-Match, and the server's 304 is not used.SiloAPI.itemDetail, which captures the current owner itself. The coordinator's owner checks before and after the poll keep another owner's detail from being applied.AI disclosure
Code and description written by Claude Opus 5.5 (
claude-opus-5-5) agents in Claude Code (T3 Code), orchestrated by a Claude Code workflow.Part 42 of 50 in the Apple API v2 stack. Base:
apiv2-stack/41-requests-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.🤖 Generated with Claude Code