Skip to content

Reopen the smart-home example's Fire TV connection after a socket reset - #5384

Open
zzstoatzz wants to merge 2 commits into
mainfrom
fix-fire-tv-stale-adb
Open

zzstoatzz wants to merge 2 commits into
mainfrom
fix-fire-tv-stale-adb

Conversation

@zzstoatzz

Copy link
Copy Markdown
Collaborator

The smart-home example's Fire TV tools failed permanently once the TV reset the ADB socket: every call raised ConnectionResetError until the server was restarted. The connection is now probed before each use and reopened when the probe fails.

Cause

androidtv only sets available to false on an explicit close. After the TV resets the socket the client still reports available, so FireTVConnection.get() skipped its reconnect branch and handed out a dead connection.

Seen on a running instance: tv_read_status returned [Errno 104] Connection reset by peer on repeated calls while a fresh ADB connection to the same TV worked. What made the TV reset the socket is not established; a single sleep/wake cycle did not reproduce it.

Change
  • FireTVConnection.get() sends a no-op shell command (true) when the client claims to be available, and closes the client if that raises, which lets the existing reconnect branch run.
  • This costs one extra ADB round trip per tool call.
  • Regression test: a fake TV that raises ConnectionResetError while still reporting available is reconnected, and the tool call succeeds.

🤖 Generated with Claude Code

androidtv only clears `available` on an explicit close, so once the TV
reset the ADB socket every tv tool call failed with ConnectionResetError
until the server restarted. Probe the link with a no-op shell command
before handing out the client, and close and reconnect when it fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

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-02T05:47:28.997993Z 3a75c3f PR opened
ℹ️ 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.

@marvin-context-protocol marvin-context-protocol Bot added bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. low-priority labels Oct 2, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

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: 3a75c3f6f9

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

Comment on lines +68 to +69
if self._client.available and not await self._responds(self._client):
await self._client.adb_close()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Serialize reconnects before closing the shared client

When two tool calls run concurrently after the same socket reset, both can enter this branch after failed probes; one call may finish reconnecting and return the shared client before the other executes adb_close(), allowing the second call to close the newly restored connection while the first tool is using it. Protect the probe/close/connect sequence with a per-connection lock so only one caller performs recovery and subsequent callers observe the restored client.

AGENTS.md reference: AGENTS.md:L180-L182

Useful? React with 👍 / 👎.

This branch has not been deployed

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

Labels

bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. low-priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant