Repository navigation
feat(subtitles): run AI subtitle jobs on v2 - #392
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 ( |
27dac38 to
5b65565
Compare
ab1c048 to
5c0bd73
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5b65565fdb
ℹ️ 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".
| } catch HTTPError.authorityChanged, HTTPError.requestIdentityChanged { | ||
| // `requestIdentityChanged` is raised both just before the bytes | ||
| // leave and after the response arrives, so it cannot prove the | ||
| // job was never started. | ||
| throw SubtitleCreationError.outcomeUnknown |
There was a problem hiding this comment.
Distinguish owner changes that occur before dispatch
Use a dispatch record or the existing APIv2OwnerChangedBeforeDispatch mechanism before converting every ownership error to .outcomeUnknown. If the profile or credential changes after the initial check on line 40 but before withOwnerFence or requestData dispatches any bytes, those preflight checks throw authorityChanged/requestIdentityChanged; this catch then incorrectly holds the request as possibly started, blocking a safe retry until the user manually discards it.
Useful? React with 👍 / 👎.
5c0bd73 to
90b2781
Compare
The player's AI subtitle suite still called five /api/v1 routes for the
capability, the ASR quota, job creation, polling and cancel. Creation is
non_retryable on v2, and the controller showed every failed POST the
same way, so a lost receipt could be resent and start a second job.
SiloAI now reads the capability and quota from /api/v2/subtitles/ai/status
and /quota, starts jobs with POST /api/v2/subtitles/ai/translate, and polls
and cancels through /api/v2/subtitles/ai/jobs/{job_id}. The capability is
on only when the viewer is allowed and the state is available; a failed
probe keeps the last value. Jobs are polled and cancelled for the owner
that started them, and job and result IDs stay opaque strings.
A create whose outcome is unknown (connection lost after sending, an owner
change once dispatch could have begun, or an unusable 2xx receipt) is held
per owner, file and job. An identical request is refused without being sent
until the user picks "Discard held request" in the menu. A server answer or
a request that never left releases it. When the poller gives up, the menu
now says the job may still finish instead of showing progress forever.
The v1 methods, the tolerant v1 decoders for SubtitleJob, SubtitleAIStatus
and SubtitleAIQuota, SubtitleJobEnvelope and their decoding tests are gone.
Stack-PR: W5-R
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Stack-PR: W5-R Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
When five job reads failed in a row, the controller failed the job even while the websocket was still streaming its cues. That closed the live track, restored the old selection, and dropped the websocket completed frame, so the finished track was never selected. Now a poller give-up fails the job only when no live track is attached. With one attached, the controller keeps the live track and lets the websocket settle the job: a completed frame hands off, selects the stored track and moves the menu to completed; a failed frame fails it. If the socket drops, the live track times out, or a completed frame carries no subtitle ID after the give-up, the job fails with the lost-track message. Stack-PR: W5-R Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
5b65565 to
6e408ef
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
The in-player AI subtitle suite (translate, transcribe, transcribe and translate) now runs entirely on
/api/v2. Job creation is sent once, and a request with an unknown outcome is held until the user discards it instead of being resent.Problem
SiloAIstill sent five subtitle AI calls to/api/v1(inventory rows 105-109):GET /api/v1/subtitles/ai/status(capability, read byAICapabilities)GET /api/v1/subtitles/ai/quota(ASR quota gauge)POST /api/v1/subtitles/ai/translate(job creation, fromSubtitleAIController)GET /api/v1/subtitles/ai/jobs/{id}(polling)POST /api/v1/subtitles/ai/jobs/{id}/cancelThe v2 contract differs from v1 in these ways:
allowed,state,revision). The v1 model read onlyenabledandtranscribe_enabled, and defaulted both tofalsewhen missing.SubtitleAICreateBodysetsadditionalProperties: false, takesmedia_file_idas a string, and requiressource_language,target_languageandstart_position.id,media_file_idandresult_subtitle_idare strings. The player'sSubtitleJobdecodedresult_subtitle_idasInt, so a non-numeric result ID would fail every poll.createSubtitleAIJobisnon_retryable: the server deduplicates active jobs but keeps no replay receipt. The controller showed every failed POST the same way, and the user could tap the language again after a lost receipt and start a second job.Inventory row 107 lists
POST /api/v2/subtitles/ai/jobsas the target. That operation does not exist; this PR usesPOST /api/v2/subtitles/ai/translate(createSubtitleAIJob), as the plan corrects.Solution
APIv2Client+SubtitleAI.swiftwithsubtitleAIStatus(),subtitleAIQuota(),createSubtitle(_:auth:),subtitleJob(id:auth:)andcancelSubtitleJob(id:auth:). Create and cancel moved here fromAPIv2Client.swift. Each call checks one exact status (200, 202 or 204), sendsX-Profile-Idwhen a profile is selected (optional in the contract), and runs insidewithOwnerFence. The subtitle transport inAPIv2Client+Subtitles.swiftis now shared by both files. Job IDs are percent-encoded as one path segment. Create failures are sorted by the sharedAPIv2DispatchFailure/APIv2MutationOutcomeclassifier, withSubtitleCreationError.outcomeUnknownadded for an owner change after dispatch.APIv2SubtitleAIModels.swiftholds the wire models. The AI job models moved here fromAPIv2SubtitleModels.swift.APIv2SubtitleAIStatusandAPIv2SubtitleAIQuotadecode strictly; the contract requires every field.allowed && state == "available" && enabled, and transcription only whenallowed && state == "available" && transcribe_enabled. An unknownstatecounts as unavailable. The existing rule that transcription also needs translation enabled (AICapabilities.transcribeEnabled) is unchanged. A failed status probe no longer clears a known value:AICapabilitieskeeps the last subtitle status, and the existing foreground and session refreshes ask again.SubtitleJob.resultSubtitleIdis nowString?. The handoff matches it to the stored-subtitle listing by string, which removes theString(resultId)bridge W5-Q left. Onlymedia_file_idstill needs an exact positive integer, because the player addresses files byInt. The websocketcompletedandsubtitle_readyevents still carry integer IDs; the controller converts them withString(_:).SiloAI.captureAuthority()), then polls and cancels for that owner. A poll or cancel for a replaced owner is refused before sending.SiloAI.translateSubtitle(_:auth:)records each request by owner (account and profile), file, kind, source index and both languages. The playhead and live session are left out, so a moved playhead cannot turn a lost receipt into a new request. This matches Android'sSubtitleAiCreateV2Api.Intent. An identical request whose outcome is unknown is refused withSubtitleCreationError.unresolvedand nothing is sent. In the translate menu, the failure panel adds a "Discard held request" button next to "Dismiss" on iOS and tvOS. On tvOS it is a second native focus target; "Dismiss" keeps the initial focus. The hold is process-local, like Android's; it is not an offline queue.AIJobPollerstopped after five failed reads in a row, the menu used to stay on "Translating…" indefinitely. For a poll-only job, it now fails with "Silo lost track of this subtitle job. If it finishes, the subtitles will appear in the subtitle list." If the websocket is streaming the job's cues, the controller keeps the live track and lets the websocket settle the job. Acompletedframe hands off, selects the stored track, and moves the menu to completed. Afailedframe fails the job. If the socket drops, the live track hits its 30-second safety timeout, or acompletedframe arrives without a subtitle ID, the job fails with the lost-track message.LiveSubtitleCoordinatorgainshasLiveTrackand anonSafetyTimeouthook for this.detail(for example the quota message on 429). A 503 without a problem document keeps "AI subtitles aren't available right now. Try again later." An unknown outcome shows "Silo couldn't confirm that the subtitle job started. If it did, the subtitles will appear in the subtitle list when it finishes." A held repeat shows "An earlier request for these subtitles may still be running, so Silo didn't send it again."SiloAIpaths andSiloAI'sHTTPClientdependency. Also deleted: the tolerant v1 decoders onSubtitleJob,SubtitleAIStatusandSubtitleAIQuota(now plain domain values built from the v2 models),SubtitleJobEnvelope,TranslateSubtitleBody'sEncodableconformance, and theAIModelDecodingTestscases that decoded v1 shapes. Stale/api/v1comments inAIModels.swift,AICapabilities.swiftandSubtitleAIController.swiftare updated.Failure outcomes for
POST /api/v2/subtitles/ai/translate(non_retryable)cannotConnectToHost, DNS, TLS); any non-2xx answer (for example 400, 404 for an unknown session, 422, 429 quota, 500, 503)detail, server-update copy, or the generic line). The user may tap the language again.SubtitleCreationError.outcomeUnknown)unresolvedand sends nothing.Cancel (
natural_idempotent) stays best effort, as before: the controller sends it once for the job's owner and ignores its result, because polling decides the final state. The job and quota reads are not retried beyond the poller's existing five-failure budget.Validation
APIv2SubtitleTests,AIModelDecodingTests,AIJobPollerTests,SubtitleAIControllerTests,SubtitleSearchModelTestsandLiveSubtitleCoordinatorTests, 73 tests each, 0 failures.scripts/ci/check-no-api-v1.shpasses.SiloAI.swiftandAIModels.swiftno longer contain/api/v1; per the stack rules the allowlist is unchanged.withOwnerFence|sameCredentialIdentityline count iniosApp/iosAppstays at 69.testCreateHoldsOnlyAnUnknownOutcome,testCreateForAReplacedOwnerIsRefusedOrHeldandtestControllerHoldsAnUnknownOutcomeUntilDiscardedfail. Removing the poller give-up handling madetestControllerReportsAJobThePollerLostTrackOffail. Failing the job on every give-up, even with a live track attached, madetestWebsocketCompletesAJobThePollerLostTrackOfandtestSocketLossFailsAJobThePollerLostTrackOffail.New
StubURLProtocoltests inAPIv2SubtitleTests:allowed,state,enabledandtranscribe_enabled, and refusal of the v1 shapeAICapabilitieskeeps a known subtitle status when the probe failssession_idfor a live transcriptionoutcomeUnknownand holds.failedafter exactly five reads and ends the preparing presentationcompletedframe then registers and selects the stored track and ends in.completed, and a socket drop instead fails the job and closes the live trackpendingNobody ran the app against a live server or on a simulator, so the menu's held state and the discard button have not been seen on a device.
Risks and follow-ups
SiloAIkeeps that hold, so the same language fails with the held message until the user discards it.live_delivery_attached: false(for example a deduplicated job) is not handled beyond the existing receipt check. The controller stays in the poll-only flow it already uses when realtime is unavailable, so the player waits for the poller to finish.session_idsent with a live transcription comes from the v2 playback session that W2-B (PR 29) introduced. Nobody checked against a live server thatBindTranslationaccepts it.completedorfailed, the menu stays on "Translating…" while the live cues play. The coordinator's safety timer covers only the wait for the first cue.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 44 of 50 in the Apple API v2 stack. Base:
apiv2-stack/43-subtitles-v2. Merge in order from the bottom of the stack. The plan and full index are in PR 01.🤖 Generated with Claude Code