Skip to content

fix(pairing): stop the phone approving a TV that cancelled sign-in - #749

Merged
Quick104 merged 2 commits into
mainfrom
fix/issue-738-cancelled-tv-approve
Oct 31, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/issue-738-cancelled-tv-approve

Conversation

@Quick104

@Quick104 Quick104 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #738
Related issue: Silo-Server/silo-server#1192
Validation tasks: changes #336 C1; changes #337 C2; changes Silo-Server/silo-apple#327 C2

When an Android phone or tablet signs in a TV that sits on its sign-in screen, and the person at the TV chooses Allow and then Cancel while the phone shows the code to compare, the phone kept "Yes, this matches" on screen. Tapping it approved the TV's sign-in request, and the TV signed in even though its user had cancelled. A signed-out Apple TV or Android TV keeps that request alive after cancelling the phone attempt (it is the same code shown on screen and in the QR), so the late approval lands. A late "Doesn't match" had the opposite problem: it denied the TV's live code and then showed a raw TLS error.

iPhone and iPad already stop as soon as the TV cancels. This change brings Android phones and tablets in line: once the TV ends the attempt, the phone stops at once and sends no approval or denial.

Approach

CompanionPairingCoordinator read the TV's messages only when it next waited for one, which came after the approve call. The coordinator now records, as messages arrive, anything that ends the TV's side of an attempt: a cancel, the connection closing, or a failed result for the server being signed in (for example, the TV's code expired while the phone was showing it). The code comparison races the person's answer against that signal, so the card's buttons go away as soon as the TV leaves. Every point that would approve or deny on the server checks it first, including the lookup step, the mismatch denial, and later servers that are approved without asking.

The phone's failure text is unchanged. For a TV that hangs up without sending cancel it still reads " closed the connection. Try again."; #669 covers that wording. A phone that has already sent its approval cannot take it back. The change stops decisions made after the phone knows the TV left.

No Apple change is needed: the iOS sender already concludes on cancel, stream end, and failed results.

Validation

  • Live, on a Silo dev deployment: reproduced on the base build against an Android TV emulator and an Apple TV simulator, then verified the fix on both. After the TV's Cancel, the phone switched to the failure card within a second, no answer was possible, the TV stayed signed out, and the server request stayed pending. Try again → Allow → Yes still signs the TV in. Discovery between the emulators was injected through a relay, not native mDNS; the pairing connection itself was the real TLS session.
  • Late "Doesn't match" on the base build denied the TV's live request. After the fix there is no button left to tap.
  • New coordinator tests fail on the base and pass with the fix. They cover the TV cancelling, hanging up, or reporting a failed result during the comparison, and cancelling during the lookup.
  • ./gradlew testDebugUnitTest, the five lint tasks, and both assembleDebug builds pass. The two supply-chain scripts could not run locally because ruby is missing; this change touches no build or workflow files, so CI runs them.
  • Tablet not run separately; it uses the same coordinator and card as the phone.

Evidence

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

Surface and build: Android phone emulator (API 34) as the sender; Android TV emulator (API 34) and Apple TV simulator (tvOS 27) as receivers; silo-server sandbox at 9d3f24ca.

Risks

None identified. The change adds no settings or protocol messages. A failed ServerResult for the active server now ends the comparison early with the TV's reason instead of after the approve call.

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 background adversarial review
  • Model(s): claude-opus-5-5; gpt-6.1-sol
  • Involvement: Fully AI-generated; not yet human verified
  • Adversarial review: before implementing, gpt-6.1-sol reviewed the plan and found two gaps. A cancel that arrived during the lookup could still deny or approve, and a failed result with the connection still open did not end the comparison. Both are fixed and covered by tests. The background adversarial review (gpt-6.1-sol, reviewed 908037d) found nothing; a7000ea was pushed after it.

🤖 Generated with Claude Code

Note

Fix phone approving a TV pairing attempt that already cancelled

  • Adds a PeerState tracker in CompanionPairingCoordinator.pair that records incoming TV cancellations, connection closure, and failed server results as they arrive, instead of only noticing them when the inbox is next read.
  • Each per-server pairing attempt now checks for interruptions at multiple points (lookup, account name retrieval, before approval, during code confirmation, and before denial). During confirmation it races the user's answer against interruption and cancels the answer flow if the TV ends the attempt.
  • PeerInterruption.failure maps recorded interruptions to the matching exception types: PeerCancelledException, a connection-closed exception, or an IllegalStateException with the server failure message.
  • Behavioral Change: a phone-side approval or denial no longer proceeds after the TV cancels, disconnects, or reports that server's attempt failed; the pairing result now reflects the interruption. Covered by new tests in CompanionPairingCoordinatorTest.kt.

Macroscope summarized 968e9cf.

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

@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:44:21.898604Z 968e9cf New commits
🔒 Security Review ✅ Completed 2026-10-31T19:47:36.850642Z 968e9cf 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.

@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 57 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: 47e59bfc-9a3c-4040-a3c0-a2ebc27749b4
Commits

Reviewing files that changed from the base of the PR and between 3b1a792 and 968e9cf.

Files selected for processing: 2
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/pairing/CompanionPairingCoordinator.kt
  • android-shared/src/androidUnitTest/kotlin/org/siloserver/silo/common/pairing/CompanionPairingCoordinatorTest.kt
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@macroscopeapp

macroscopeapp Bot commented Oct 30, 2026

Copy link
Copy Markdown

The TV-pairing confirmation now disappears and shows a failure when the TV cancels, disconnects, or reports failure. The linked evidence and validation notes cover the Android phone, but not the Android tablet or foldable folded and open; please add a short recording of the cancellation flow on those devices, since the change reaches them through the phone app. The code is wired only into the phone app, so Android TV is not an affected surface.

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 evidence-required Needs before-and-after evidence before the Evidence check passes impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage labels Oct 30, 2026
@silo-triage

silo-triage Bot commented Oct 30, 2026

Copy link
Copy Markdown

The Evidence section still needs the affected-device coverage required by CONTRIBUTING.md: before-and-after captures on an Android tablet and a foldable, folded and open, plus a short recording showing TV cancellation removing the phone's comparison buttons. The body says tablets share the changed coordinator and card, so that does not establish that they are unaffected. If a device cannot reach this flow, explain that instead.

AI disclosure: openai/gpt-6.1-sol via OpenClaw (Silo Triage); triage only, no code execution.

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

@macroscopeapp

macroscopeapp Bot commented Oct 30, 2026

Copy link
Copy Markdown

The cancellation flow in android-shared/src/androidMain/kotlin/org/siloserver/silo/common/pairing/CompanionPairingCoordinator.kt visibly replaces the phone's code-comparison choices with a failure when the TV cancels, disconnects, or reports failure. It is wired only into the phone app, so it reaches Android phones, tablets, and foldables folded and open, but not Android TV. The PR describes phone/API 34 validation and links private evidence, but identifies no tablet or foldable captures; the evidence page should show before-and-after captures on a phone, tablet, and foldable folded and open, plus a short recording of the cancellation flow. The TV receiver tests do not cover the Android TV app surface.

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

Posted via Macroscope — Visible change evidence

@Quick104

Copy link
Copy Markdown
Contributor Author

Evidence updated: tablet and foldable (folded and open) before/after captures of the code step and of the card after the TV cancels, plus a short phone recording of the cancellation. Devices: Pixel 8 phone, Pixel Tablet and Pixel Fold emulators (API 34) with an Android TV emulator. Before is main at 76dee90ad, after is a7000ea4f. Discovery between the emulators was relayed.

Quick104 and others added 2 commits October 31, 2026 15:41
Once a TV ends a phone sign-in attempt (it cancels, hangs up, or reports
the server failed), the phone no longer approves or denies its request.
The code-comparison card stops waiting for an answer at once, and every
decision point checks the TV's side first. A signed-out TV keeps its own
sign-in request after cancelling, so a late "Yes" used to sign it in and a
late "Doesn't match" denied its live code.

Closes #738

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Leaving the confirmation scope waits for the cancelled watcher, and the
TV can end the attempt in that time; declining then would deny the
request the TV still shows. Check again right before the decline, as
before the approval.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Quick104
Quick104 force-pushed the fix/issue-738-cancelled-tv-approve branch from a7000ea to 968e9cf Compare October 31, 2026 19:43
@silo-kody

silo-kody Bot commented Oct 31, 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
Quick104 merged commit c031104 into main Oct 31, 2026
5 checks passed
@Quick104
Quick104 deleted the fix/issue-738-cancelled-tv-approve branch October 31, 2026 19:43
// The TV hung up (or the read failed): wake any wait
// for its next message instead of sitting on it until
// the step's timeout.
peer.ended()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Kody Rules high

Server-selection hang occurs when the incoming flow completes normally while chooseServers(orderedServers) awaits UI input: recording transport closure with peer.ended() only wakes the match-confirmation interruption watcher, and normal collector completion and closing inbox do not cancel the separate UI wait, leaving the phone stuck after the TV disconnects. Propagate unexpected transport completion to the entire pairing operation, or race server selection against peer termination and cancel the pending selection when termination wins; add a regression test for clean EOF during server selection.

Kody rule violation: Propagate transport closure to pending interaction and preserve terminal failures

Prompt for LLM

File android-shared/src/androidMain/kotlin/org/siloserver/silo/common/pairing/CompanionPairingCoordinator.kt:

Line 324:

Server-selection hang occurs when the incoming flow completes normally while `chooseServers(orderedServers)` awaits UI input: recording transport closure with `peer.ended()` only wakes the match-confirmation interruption watcher, and normal collector completion and closing `inbox` do not cancel the separate UI wait, leaving the phone stuck after the TV disconnects. Propagate unexpected transport completion to the entire pairing operation, or race server selection against peer termination and cancel the pending selection when termination wins; add a regression test for clean EOF during server selection.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working evidence-required Needs before-and-after evidence before the Evidence check passes impact: security Auth, privacy, or permission boundary priority: P0 Fix/merge first: data-loss, security, or widespread breakage 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] An Android phone still signs a TV in after the TV cancels phone sign-in

1 participant