Skip to content

fix(tv): withdraw the sign-in request when a phone abandons setup - #752

Merged
Quick104 merged 2 commits into
mainfrom
fix/issue-667-withdraw-cancelled-request
Oct 31, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/issue-667-withdraw-cancelled-request

Conversation

@Quick104

@Quick104 Quick104 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #667
Related issue: Silo-Server/silo-server#1192
Validation tasks: changes #337 C2 (not yet run)

When an iPhone or iPad cancels phone setup of an Android TV (for example after the person taps Doesn't match), the TV goes back to "Set up with your phone" but leaves the sign-in request it opened on the server pending. For up to 15 minutes, /activate and the Sign in a TV screen still offer to approve it, and approving says the TV is signing in, though the TV has moved on. The same happens when the phone's connection drops mid-setup. An Android phone hides this by denying the request itself; the Apple TV withdraws its own request.

Approach

In setup mode, PairingReceiver now tracks the request each attempt opens. When the attempt is abandoned before the TV collects it, the TV withdraws it with POST /api/v2/auth/device/cancel. That covers a phone cancel, a dropped connection, a newer push, and Cancel on the TV. This mirrors the tvOS ReceiverPairingCoordinator:

  • A request the server already ended (denied, used, withdrawn, or approved and collected) is left alone. An expiry may be this TV's own deadline, so that request is still withdrawn, as on tvOS.
  • DeviceLoginPort.withdraw follows the rule DeviceSignInMachine uses. It skips only a server whose capability says it has no cancel. A capability read that fails or takes over two seconds counts as unknown, and the cancel is still sent.
  • The withdraw is best effort, runs even when the attempt was cancelled, and is bounded to five seconds. Each attempt claims the shared device-login state before it starts a request, and only the attempt that still owns that state reads or resets it. An attempt still saving a session after the advertiser restarts can't withdraw or reset the request a newer attempt opened.

Sign-in mode is unchanged. When the TV is on its sign-in screen, it lends the code it is already showing to the phone and never opens a second request. When the phone cancels there, that code stays on screen, still waiting for approval, and stays approvable. The Apple TV does the same: its handleLoginPush has no withdraw, and the sign-in screen goes on polling its own request.

Validation

  • Live, Android TV emulator against a dev sandbox. The sender was a scripted client sending the iPhone's frames for Doesn't match: push a server, wait for the TV's code, then cancel with reason match_declined and no deny. I replayed the frames because the iOS simulator available for this run couldn't discover TVs. See Evidence.
    • Before (main): after the cancel, the TV's request stayed pending and approvable until it expired.
    • After: the request was canceled 0.4 s after the cancel. Rechecked on the current head after each review fix.
    • Sign-in mode, after: the TV kept showing its code, and the request stayed pending.
  • New PairingReceiverTest table: a phone cancel or a dropped connection withdraws, while a server deny or a cancel in sign-in mode doesn't. It can't run on main because the fake implements the new port method, so the live run is the before-and-after proof. A second new test, in which an attempt still saving after a restart leaves the newer request alone, fails on the PR's earlier head and passes on the current one.
  • ./gradlew testDebugUnitTest and the CONTRIBUTING lint set pass. I did not run the two supply-chain scripts locally because they need Ruby, which this machine lacks. No build files change.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-android/issue-667/

Surface and build: Android TV emulator (Android 14), debug builds of main and this branch. The TV's screens look the same before and after; the change is the request's state on the server, recorded in the evidence notes.

Risks

None identified beyond a best-effort network call on teardown (at most five seconds, off the main thread). This PR and #748 both edit PairingReceiver.kt in different functions, so whichever merges second may need a rebase.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code in T3 Code
  • Tool(s): Claude Code; OpenAI Codex for the plan review and the adversarial review
  • Model(s): claude-opus-5-5 (implementation, verification); gpt-6.1-sol (reviews)
  • Involvement: AI-assisted
  • Adversarial review: gpt-6.1-sol reviewed the change before the PR opened. It confirmed the server and sign-in-mode boundaries and found two problems. First, the five-second withdraw delayed the shared state reset, so an attempt after an advertiser restart could see the old request; the reset now happens before the withdraw. Second, a slow capability read could use up the whole budget; it now has its own two-second bound. The background review of this PR (gpt-6.1-sol, reviewed 3180f6518) and Kody found that an attempt still saving its session after an advertiser restart could read, withdraw and reset a newer attempt's request. Fixed in ee0323a76 with attempt ownership of the shared state, plus a regression test. Nothing is left open.

🤖 Generated with Claude Code

When a phone cancelled phone setup of an Android TV (an iPhone's "Doesn't
match", for one), or its connection dropped, the TV went back to waiting
but left the device-login request it had opened on the server pending, so
its code could still be approved for up to 15 minutes. The receiver now
withdraws a request it opened and didn't collect, following the shared
withdraw rule DeviceSignInMachine uses. The sign-in screen's own request,
which the TV keeps showing, is never withdrawn.

Closes #667

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Oct 30, 2026
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 5 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 128 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

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: 3b5805de-3e0c-4c11-bece-fca42e2f6341
Commits

Reviewing files that changed from the base of the PR and between 238134a and ee0323a.

Files selected for processing: 3
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/pairing/DeviceLoginPort.kt
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/pairing/PairingReceiver.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/pairing/PairingReceiverTest.kt
  • 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 30, 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 ❌

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 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-30T23:24:28.891971Z ee0323a New commits
🔒 Security Review ✅ Completed 2026-10-30T23:25:25.525241Z ee0323a 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.

@silo-triage silo-triage Bot added bug Something isn't working priority: P2 Limited scope, workaround exists, or polish labels Oct 30, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 30, 2026

Copy link
Copy Markdown

The TV-side withdrawal changes what the Android phone app’s “Sign in a TV” lookup offers for an abandoned code (android-shared/src/androidMain/kotlin/org/siloserver/silo/common/pairing/PairingReceiver.kt). The PR describes an Android TV emulator run, but the linked evidence page should also show the phone approval state on an Android phone, tablet, and foldable both folded and open; provide before-and-after captures of the same lookup and a recording of the cancellation-to-lookup flow.

Suggested fix: Add those phone-form-factor captures and the flow recording to the evidence page.

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 Author

Choose a reason for hiding this comment

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

Adversarial review (gpt-6.1-sol, reviewed 3180f65)

One verified finding: F1 (P2), an old attempt can withdraw a newer setup request after an advertiser restart.

AI disclosure: Reviewed with Codex, gpt-6.1-sol.

…et it

A save that outlives its connection could otherwise read and withdraw the
request a newer attempt opened after the advertiser restarted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-kody

silo-kody Bot commented Oct 30, 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 ❌

@Quick104

Copy link
Copy Markdown
Contributor Author

Evidence updated: phone, tablet and foldable (folded and open) before/after captures of the abandoned code typed into Sign in a TV: before it is offered for approval, after it is refused. Devices: Pixel 8 phone, Pixel Tablet and Pixel Fold emulators (API 34) with an Android TV emulator on its first-run screen. Before is TV main at 76dee90ad, after is ee0323a76. Setup was abandoned by a scripted sender that replays the iPhone's cancel frames; discovery between the emulators was relayed.

@Quick104
Quick104 merged commit ad92e00 into main Oct 31, 2026
12 of 16 checks passed
@Quick104
Quick104 deleted the fix/issue-667-withdraw-cancelled-request branch October 31, 2026 19:38
Quick104 added a commit that referenced this pull request Oct 31, 2026
Resolves the conflicts with #752 (withdraw an abandoned sign-in request)
in PairingReceiver.kt and PairingReceiverTest.kt. Both behaviours hold:

- Imports and companion: keep IDLE_TIMEOUT (180 s) next to #752's
  WITHDRAW_TIMEOUT, and both sets of coroutine imports.
- Fields: keep the idle timer state (idleJob, sessionClosing,
  sessionLock) next to #752's deviceLoginOwner/deviceLoginLock.
- startAttempt: keep this branch's sessionLock block (no attempt starts
  once the session is closing, the idle timer pauses while an attempt
  runs and restarts only after a finished one). Drop the branch's
  try/finally deviceLogin.reset() around runAttempt: #752 moved that
  reset into runAttempt's finally, where only the attempt that still
  owns the shared state resets it and then withdraws its request. The
  withdraw runs inside the attempt, so the idle timer restarts after it.
- Tests: keep both branches' new PairingReceiverTest cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working 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.

[bug] Android TV keeps its sign-in code open after an iPhone cancels phone setup

1 participant