Skip to content

fix(tv): drop a silent phone after three minutes of phone setup - #748

Merged
Quick104 merged 3 commits into
mainfrom
fix/issue-739-receiver-idle-timeout
Oct 31, 2026
Merged

Quick104 merged 3 commits into
mainfrom
fix/issue-739-receiver-idle-timeout

Conversation

@Quick104

@Quick104 Quick104 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

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

If a phone loses its network while an Android TV asks "Allow this setup?", the TV waits for that phone forever. It serves one phone at a time, so it also turns away every other phone or tablet ("Setup didn't finish", "Connection reset") until someone presses Don't allow on the TV. The Apple TV and Roku apps give up on a silent phone after 180 seconds; the Android TV app had no limit.

Approach

PairingReceiver now closes a phone session that has been silent for 180 seconds and returns to waiting, so the next phone can connect. It uses the same rules as the tvOS ReceiverPairingCoordinator:

  • The timer starts when the phone connects and restarts on every message from the phone.
  • It pauses while a sign-in attempt is in flight, since the code's own expiry bounds that wait and the unreachable-address choice waits on the TV user. It restarts when the attempt ends, so a failure left on screen with the phone gone also ends the session, keeping its explanation on screen.
  • When it expires, the TV closes the connection without sending a goodbye frame, because a write to a dead peer can block the close. Both phone apps already treat a closed connection as the end of setup. A failure left on screen stays there when the connection closes, however it closes.
  • One lock orders expiry against activity. A message that arrives first cancels the timer. Once expiry wins, a late Allow or push starts nothing, and a newer connection's session is never touched.

Only PairingReceiver.kt changes. iOS and tvOS already behave this way. Android phones are senders, so they are unaffected.

Validation

  • Live, Android TV emulator against a dev sandbox (rechecked on the current head after the review fixes), Android phone emulator as the sender (discovery injected into the emulators). To simulate the phone losing its network, I froze that connection with no data and no close; see Evidence.
    • Before (main): 3 min 28 s after the cut the TV was still on "Allow this setup?", and it refused a second connection as busy.
    • After: the TV dropped the phone 180.0 s after its last message and returned to "Set up with your phone". It accepted the next connection, and a full setup through it signed the TV in.
  • Two new PairingReceiverTest cases fail on main and pass here: a silent phone is dropped at the limit (and a late Allow starts nothing), and the limit restarts after an attempt ends, keeping its failure.
  • ./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-739/

Surface and build: Android TV emulator (Android 14), debug builds of main and this branch. Phones and tablets don't run the receiver.

Risks

A phone that sends nothing for three minutes while the TV waits for consent now gets disconnected, which matches tvOS and Roku. Sign-in attempts in flight are not timed out. An Android phone left on its server chooser for three minutes keeps showing the chooser after the TV drops it, which already happens with Apple TV and Roku; that's filed as #750. The parallel fix for #667 also edits PairingReceiver.kt, 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 plan before implementation. It found that sending a goodbye before closing could block the close, that a cancelled timer could still close a session, and that a cancelled attempt could restart the timer. All three were fixed: the timer only closes, one lock orders expiry against activity, and only a finished attempt restarts the timer. A background review of this PR (gpt-6.1-sol, reviewed 9c4afedfc) raised two findings, and Kody raised three. Fixed in 90774f2fd: a failure is kept when the real socket's close ends the stream with an error, inbound messages no longer restart the timer during an attempt, and the timer checks it still owns its session after the wait. The phone-side chooser finding isn't new; it's filed as [bug] Android phone keeps the server chooser open after the TV drops the setup connection #750. Nothing is left open.

🤖 Generated with Claude Code

Note

Drop silent phone after 180 seconds of inactivity in PairingReceiver

  • Adds a 180-second idle deadline to pairing sessions in PairingReceiver.kt. On expiry, the active transport closes and any pending push is cleared.
  • Incoming messages and finished push attempts restart the timer; push attempts pause it and are refused once the session starts closing.
  • A stream error no longer clears an existing Failed session status.
  • Adds unit tests for idle expiry, post-attempt timer restart, and failure preservation on socket-close errors.
  • Behavioral Change: a consent-requesting phone that stays silent for 180 seconds is dropped; a later Allow does not start device login.

Macroscope summarized 743a62c.

A phone that lost its network while the Android TV asked "Allow this
setup?" kept the TV waiting forever, and the TV refused every other phone
meanwhile. The receiver now closes a session that has been silent for 180
seconds (the Apple TV and Roku limit) and goes back to waiting. The timer
pauses while a sign-in attempt is in flight, and expiry never starts a
new attempt.

Closes #739

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
@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 ❌

@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 55 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 99 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: 6437c4b4-32b3-4cfb-83e3-9cf8e4d02063
Commits

Reviewing files that changed from the base of the PR and between 3b1a792 and 743a62c.

Files selected for processing: 2
  • 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

@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-31T19:46:42.830235Z 743a62c New commits
🔒 Security Review ✅ Completed 2026-10-31T19:47:46.610765Z 743a62c 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.

@macroscopeapp

macroscopeapp Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

The timeout also affects the phone sender: if someone leaves server selection open for three minutes, the TV closes the session and the phone can report a setup failure when it sends. The evidence description names only an Android TV emulator. Please add a short recording of this timing/disconnect flow on an Android phone, tablet, and foldable both folded and open, or explain why those phone surfaces cannot be reached. The evidence page should also let reviewers check the Android TV timeout flow.

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

Posted via Macroscope — Visible change evidence

@silo-triage silo-triage Bot added bug Something isn't working impact: usability Core flow broken or severely blocked priority: P2 Limited scope, workaround exists, or polish labels Oct 30, 2026

@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: 9c4afedfc1

ℹ️ 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".

@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 9c4afed)

Two findings below. F1 independently confirms the existing socket-close finding; F2 concerns the Android phone chooser after idle expiry.

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

Closing the real socket ends the phone stream with an error, not a clean
end, and that path dropped a lone failure. Also hold the idle timer for
the whole attempt, and check the timer still owns its session after the
wait.

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 ❌

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]>
@Quick104
Quick104 merged commit 25ebeef into main Oct 31, 2026
9 checks passed
@Quick104
Quick104 deleted the fix/issue-739-receiver-idle-timeout branch October 31, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working impact: usability Core flow broken or severely blocked 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 phone setup waits forever when the phone goes quiet

1 participant