Skip to content

fix(remote): stream a terminal again after its PTY respawns - #312

Merged
johannesjo merged 1 commit into
mainfrom
ccr-b3399b1c-df93um
Oct 11, 2026
Merged

johannesjo merged 1 commit into
mainfrom
ccr-b3399b1c-df93um

Conversation

@johannesjo

Copy link
Copy Markdown
Owner

Problem

On the phone, one task's terminal showed only a black area while every other task worked. That task had been switched to the built-in chat (UI mode) and back on the desktop.

Switching back starts a new PTY under the same agent ID (restartAgent → spawnAgent). The old PTY's subscribers die with it, and its exit event clears the phone's entry in clientSubs. The phone never unsubscribed, because while the task was in chat mode it stayed listed under that same ID. So it never subscribed again, and on spawn the server only republished the agent list.

The earlier Android-side fix (#311) didn't help because nothing reached the server.

Fix

electron/remote/server.ts

  • Track the agents each client asked to stream (clientWants). A subscribe adds to it and an unsubscribe removes it. Unlike clientSubs, this outlives the PTY.
  • On a non-reattach spawn, every client still wanting that agent ID drops any stale subscriber and is streamed again from the new PTY's snapshot.
  • Moved the subscribe body into streamAgent(ws, agentId) so the subscribe message and the spawn handler share it. Its behaviour is unchanged.

This covers both the Android app and the phone web UI.

Tests

  • server-ws.test.ts, new tests:
    • A phone watching an agent gets the respawned PTY's snapshot. This test fails without the fix.
    • Phones that unsubscribed are left alone, and so are reattached PTYs.
  • npm run check passes.
  • npm run test:unit -- electron/remote electron/ipc/pty: 18 files, 484 tests pass.
  • Not tried end to end with a real phone and desktop.

🤖 Generated with Claude Code

https://claude.ai/code/session_012boc2XLLaQiSeNwAqk8YYs


Generated by Claude Code

Switching a task to the built-in chat and back to the terminal starts a
new PTY under the same agent ID. The old PTY's subscribers died with it,
and its exit cleared the phone's subscription on the server, but the
phone never unsubscribed: the task stayed listed under the same ID, as
the chat. So it never subscribed again, and the task's terminal stayed
black on the phone while every other task worked.

Remember which agents each client asked to stream, and when a PTY
spawns under one of those IDs, send that client the new terminal's
snapshot and output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012boc2XLLaQiSeNwAqk8YYs
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 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-11T20:40:58.085345Z f1b4bd0 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.

@johannesjo
johannesjo merged commit ef289e7 into main Oct 11, 2026
2 checks passed
@johannesjo
johannesjo deleted the ccr-b3399b1c-df93um branch October 11, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants