Skip to content

feat(execd): add WebSocket PTY support#590

Merged
Pangjiping merged 5 commits intoalibaba:mainfrom
ctlaltlaltc:feat/execd-websocket-pty
Mar 30, 2026
Merged

feat(execd): add WebSocket PTY support#590
Pangjiping merged 5 commits intoalibaba:mainfrom
ctlaltlaltc:feat/execd-websocket-pty

Conversation

@ctlaltlaltc
Copy link
Copy Markdown
Contributor

@ctlaltlaltc ctlaltlaltc commented Mar 28, 2026

Summary

For context regarding API separation and integration, Ref #455

  • Add /pty/* REST endpoints to create, inspect, and delete PTY sessions (independent of existing /session/* flow)
  • Add GET /pty/:id/ws WebSocket endpoint for bidirectional interactive terminal acce
  • 1 MiB circular replay buffer — clients reconnect with ?since=<offset> for exact-once output delivery
  • PTY mode (default) and pipe mode (?pty=0) both supported
  • Windows build compatibility via stubs

Changes

File Description
pkg/runtime/replay_buffer.go Circular replay buffer
pkg/runtime/pty_session.go PTY session struct + lifecycle (!windows)
pkg/runtime/pty_session_windows.go Windows stubs
pkg/web/model/pty.go / pty_ws.go REST + WS frame models
pkg/web/controller/pty_controller.go REST handlers
pkg/web/controller/pty_ws.go WebSocket handler
pkg/runtime/ctrl.go +ptySessionMap sync.Map (only change)
pkg/web/router.go Register /pty/* routes (only change)

Zero modifications to existing bashSession, RunInSession, or /session/* endpoints.

Test coverage

  • replay_buffer_test.go — write/read, circular eviction, caught-up offset, large gap, concurrent (-race)
  • pty_session_test.go — basic execution, PTY resize, ANSI sequences, pipe mode, reconnect replay
  • pty_ws_test.go — 404 before upgrade, 409 already connected, ping/pong, stdin forwarding, replay on reconnect, exit
    frame, resize frame

Verified manually

  • POST /pty → session created
  • GET /pty/:id{"running":true,"output_offset":18}
  • wscat PTY mode and pipe mode (?pty=0)
  • Reconnect with ?since=0 delivers prior output

Testing

  • Not run (explain why)
  • Unit tests
  • Integration tests
  • e2e / manual verification

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

Copy link
Copy Markdown

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

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: 67a29319a2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@Pangjiping
Copy link
Copy Markdown
Collaborator

Could you provide some manual test cases or screenshots for reference?

@Pangjiping Pangjiping self-assigned this Mar 28, 2026
@Pangjiping Pangjiping added feature New feature or request component/execd labels Mar 28, 2026
@ctlaltlaltc ctlaltlaltc marked this pull request as draft March 28, 2026 08:49
@ctlaltlaltc ctlaltlaltc force-pushed the feat/execd-websocket-pty branch from 9beee69 to 8dc470f Compare March 28, 2026 09:24
@ctlaltlaltc ctlaltlaltc marked this pull request as ready for review March 28, 2026 09:24
Copy link
Copy Markdown

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

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: 8dc470f9dd

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@ctlaltlaltc
Copy link
Copy Markdown
Contributor Author

Could you provide some manual test cases or screenshots for reference?

Done.

https://gist.github.com/ctlaltlaltc/930aedb331caadd7fc1bffea74003a0a

execd.log in sandbox.
image

my xtermjs client connect to execd endpoint directly integrate.
image

@Pangjiping
Copy link
Copy Markdown
Collaborator

Could you provide some manual test cases or screenshots for reference?

Done.

https://gist.github.com/ctlaltlaltc/930aedb331caadd7fc1bffea74003a0a

execd.log in sandbox. image

my xtermjs client connect to execd endpoint directly integrate. image

Great Job. You can rebase main and fix the interface definition issue. #577

ctlaltlaltc and others added 3 commits March 28, 2026 18:23
Add interactive terminal sessions over WebSocket to execd:
- REST endpoints to create/resize/close PTY sessions
- WebSocket handler with output replay on reconnect
- Circular replay buffer (1 MiB) for session history
- Windows stubs for cross-platform build compatibility

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@ctlaltlaltc ctlaltlaltc force-pushed the feat/execd-websocket-pty branch from 8dc470f to e48c639 Compare March 28, 2026 10:42
@ctlaltlaltc
Copy link
Copy Markdown
Contributor Author

ctlaltlaltc commented Mar 28, 2026

@Pangjiping Done, thanks review.

Copy link
Copy Markdown
Collaborator

@Pangjiping Pangjiping left a comment

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 33a3292 into alibaba:main Mar 30, 2026
10 of 12 checks passed
@ctlaltlaltc ctlaltlaltc deleted the feat/execd-websocket-pty branch March 30, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/execd feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants