Skip to content

fix(cli): delete the PTY session when the terminal WebSocket never opens - #2523

Merged
Pangjiping merged 1 commit into
opensandbox-group:mainfrom
acodercat:fix/cli-terminal-delete-unconnected-session
Nov 1, 2026
Merged

Pangjiping merged 1 commit into
opensandbox-group:mainfrom
acodercat:fix/cli-terminal-delete-unconnected-session

Conversation

@acodercat

Copy link
Copy Markdown
Contributor

osb terminal first creates a PTY session with POST /pty and then opens /pty/{id}/ws. In its finally, it deletes the session only when teardown is set, and teardown is set only after asyncio.run returns: on a clean exit or a reported startup failure.

When the WebSocket connect itself fails, asyncio.run raises before teardown is set. That happens when the connect is refused, gets an HTTP status (InvalidStatus), or is interrupted. On current main the command exits 1 with "Terminal connection failed", the session created by POST /pty is never deleted, and its ID is never printed, so the user can't clean it up either. Per components/execd/PTY.md, the shell starts on the first WebSocket, so such a session has nothing worth keeping.

Summary

  • _connect_and_stream takes an optional on_connected callback, called once the WebSocket is open.
  • terminal records whether the connection opened, and also deletes the session when it never did.
  • A connection lost on a live shell is still the one case where the session is kept and its ID printed, as before. _delete_pty_session ignores HTTP errors, so a failed delete can't hide the connect error.

Testing

  • Not run (explain why)

  • Unit tests

  • Integration tests

  • e2e / manual verification

  • New test_failed_connect_deletes_session, for an OSError and an InvalidStatus(403) from the connect: the command must exit 1 and delete sess-1. Both cases fail on current main.

  • The existing test_closed_without_exit_frame_fails_and_keeps_session still passes, so the session is still kept after a lost connection.

  • The full CLI suite passes (332 passed). ruff and pyright are clean.

Breaking Changes

  • None
  • Yes (describe impact and migration path)

Checklist

  • Linked Issue or clearly described motivation
  • Added/updated docs (if needed)
  • Added/updated tests (if needed)
  • Security impact considered
  • Backward compatibility considered

`osb terminal` creates a PTY session and then connects its WebSocket.
The session was torn down only after a clean exit or a reported startup
failure, so when the connect itself failed (refused, rejected with an
HTTP status, or interrupted) the session stayed on the sandbox and its
ID was never shown.

The shell starts on the first WebSocket, so a session whose WebSocket
never opened has nothing to keep. Track whether the connection opened
and delete the session otherwise. A connection lost on a live shell
still keeps it, as before.
@github-actions github-actions Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Oct 31, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 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-31T08:54:41.940068Z 1760f43 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.

@Pangjiping Pangjiping left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@Pangjiping
Pangjiping merged commit a6c0cfc into opensandbox-group:main Nov 1, 2026
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants