feat(sdk): add PTY (interactive terminal) support to Go SDK#815
Open
chaojixinren wants to merge 1 commit into
Open
feat(sdk): add PTY (interactive terminal) support to Go SDK#815chaojixinren wants to merge 1 commit into
chaojixinren wants to merge 1 commit into
Conversation
PTY Go SDK — Code ReviewOverviewA well-structured, idiomatic Go PTY implementation that mirrors the Python/Node SDK surfaces. Seven inline comments have been posted for specific issues; this comment summarizes all findings and adds context. Inline Comments Summary
Additional Findings (not inlined)Test Coverage Gaps (Medium)
Performance (Medium)
Minor
Positive Highlights
|
9e523bf to
bc263fe
Compare
chaojixinren
added a commit
to chaojixinren/CubeSandbox
that referenced
this pull request
Jul 8, 2026
newEnvdRequest — the shared request builder for every envd data-plane RPC (commands, files, filesystem, and the PTY added in TencentCloud#815) — hardcoded the Jupyter port (49999) as the virtual host prefix. CubeProxy routes by that prefix, so these requests reached the Jupyter kernel gateway, which does not serve /process.Process/*, /files, or /filesystem.Filesystem/*, yielding a non-2xx error (HTTP 404 or 502, depending on the template's Jupyter upstream) against real deployments. Only RunCode (/execute) worked, since /execute genuinely lives on the Jupyter port. Add a dedicated EnvdPort (49983) constant and use it in newEnvdRequest, matching the Python (ENVD_PORT) and Node SDKs; RunCode's /execute stays on JupyterPort. Update the affected unit-test host assertions and the README proxy example. Verified against a live CubeSandbox: /files read/write and filesystem.Filesystem/* now succeed on 49983 (previously non-2xx on 49999). Closes TencentCloud#816 Signed-off-by: chaojixinren <chaoji_xinren@163.com>
This was referenced Jul 8, 2026
Add sandbox.Pty() mirroring the Python/Node pty API: Create/Connect streaming RPCs plus Kill/SendStdin/Resize selector RPCs over envd's Connect-JSON protocol. PtyHandle streams raw output, exposes Wait for the exit code (surfacing envd end errors such as "signal: killed"), and supports Disconnect to detach and later reattach via Connect. Includes a client-side idle timeout, exit-code-from-status parsing, and httptest-based unit tests. Closes TencentCloud#811 Signed-off-by: chaojixinren <chaoji_xinren@163.com>
chaojixinren
added a commit
to chaojixinren/CubeSandbox
that referenced
this pull request
Jul 8, 2026
newEnvdRequest — the shared request builder for every envd data-plane RPC (commands, files, filesystem, and the PTY added in TencentCloud#815) — hardcoded the Jupyter port (49999) as the virtual host prefix. CubeProxy routes by that prefix, so these requests reached the Jupyter kernel gateway, which does not serve /process.Process/*, /files, or /filesystem.Filesystem/*, yielding a non-2xx error (HTTP 404 or 502, depending on the template's Jupyter upstream) against real deployments. Only RunCode (/execute) worked, since /execute genuinely lives on the Jupyter port. Add a dedicated EnvdPort (49983) constant and use it in newEnvdRequest, matching the Python (ENVD_PORT) and Node SDKs; RunCode's /execute stays on JupyterPort. Update the affected unit-test host assertions and the README proxy example. Verified against a live CubeSandbox: /files read/write and filesystem.Filesystem/* now succeed on 49983 (previously non-2xx on 49999). Closes TencentCloud#816 Signed-off-by: chaojixinren <chaoji_xinren@163.com>
8a9fa92 to
15cb3db
Compare
ls-ggg
pushed a commit
that referenced
this pull request
Jul 9, 2026
newEnvdRequest — the shared request builder for every envd data-plane RPC (commands, files, filesystem, and the PTY added in #815) — hardcoded the Jupyter port (49999) as the virtual host prefix. CubeProxy routes by that prefix, so these requests reached the Jupyter kernel gateway, which does not serve /process.Process/*, /files, or /filesystem.Filesystem/*, yielding a non-2xx error (HTTP 404 or 502, depending on the template's Jupyter upstream) against real deployments. Only RunCode (/execute) worked, since /execute genuinely lives on the Jupyter port. Add a dedicated EnvdPort (49983) constant and use it in newEnvdRequest, matching the Python (ENVD_PORT) and Node SDKs; RunCode's /execute stays on JupyterPort. Update the affected unit-test host assertions and the README proxy example. Verified against a live CubeSandbox: /files read/write and filesystem.Filesystem/* now succeed on 49983 (previously non-2xx on 49999). Closes #816 Signed-off-by: chaojixinren <chaoji_xinren@163.com>
Collaborator
|
Thanks for the pr,Could you add some test results here? |
Contributor
Author
|
Thanks! Here are the actual test results, run on the rebased branch.@ls-ggg Base branch: latest Unit tests —
|
Collaborator
|
LGTM @tinklone |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds PTY (pseudo-terminal) support to the Go SDK (
sdk/go), closing thecross-SDK parity gap called out in #811. Go users can now run interactive
programs that need a real TTY — shells/REPLs, full-screen tools (
vim,top), agent-driven terminals — mirroring the Python (sandbox.pty,#579) and Node (
sandbox.pty, #792) surface.What's added
sandbox.Pty()namespace over envd's Connect-JSON RPC:Create(/process.Process/Start, runs/bin/bash -i -l) andConnect(/process.Process/Connect, reattach by PID).Kill(SendSignal+SIGNAL_SIGKILL),SendStdin(SendInput),Resize(Update).PtyHandle— streams raw output viaOutput()(channel) orWait(onData); exposesPID()/ExitCode()/ErrorMessage();Disconnect()to detach without killing; and per-handleKill/SendStdin/Resize.Behavior matches Python/Node:
TERM=xterm-256color,LANG/LC_ALL=C.UTF-8(caller-overridable).Killreturnsfalse(not an error) on Connectnot_found/ HTTP 404.timeoutis sent to envd asConnect-Timeout-Msand enforcedclient-side as an idle abort that resets on every frame (default 60s).
Waitsurfaces envd's end-event error (e.g.signal: killed) and parsesexit codes from
exitCode/exit_code/status.Testing
sdk/go/pty_test.go,httptest-mocked envd): create/connect,kill (success + 404 + Connect
not_foundbody + error), sendStdin,resize, wait error propagation, handle→PID delegation, disconnect, and
idle timeout.
gofmt/go vetclean;go test -race ./...green.echoroundtrip →resize verified via
stty sizereadback (40 120) → disconnect +reattach-by-PID → kill (
Waitreportssignal: killed) → second killreports not-found. All pass.
Scope
Changes are confined to
sdk/go/pty.go,sdk/go/pty_test.go, and the PTYsection of
sdk/go/README.md. No shared code is touched — the PTY reusesthe existing
newEnvdRequest/Connect-framing helpers.Closes #811