mirror of
https://github.com/kvcache-ai/AgentENV.git
synced 2026-11-05 01:17:36 +00:00
[GH-ISSUE #36] Ctrl-C cannot interrupt foreground processes in aenv interactive shell #18
Labels
No labels
bug
documentation
enhancement
enhancement
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/AgentENV#18
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @LSX-s-Software on GitHub (Jul 28, 2026).
Original GitHub issue: https://github.com/kvcache-ai/AgentENV/issues/36
Summary
Foreground processes started from an interactive
aenv start/aenv connectshell cannot reliably be interrupted with Ctrl-C. The terminal remains attached to the foreground process and appears hung until the process is killed from another session or the sandbox is deleted.Observed on current
mainat6296bc4be7.Reproduction
Start or connect to a sandbox using the native CLI:
In the interactive sandbox shell, run a long-lived foreground process:
Press Ctrl-C.
Actual behavior
aenvterminal appears stuck.aenvclient, or deleting the sandbox.The same class of problem can affect other foreground processes such as
sleepor development servers.Expected behavior
Ctrl-C in an
aenvinteractive shell should have normal terminal semantics: send SIGINT to the foreground process group inside the sandbox and return control to the shell when that process exits.Disconnecting the local client should also not require deleting the sandbox, and the local terminal must always be restored from raw mode.
Initial analysis
crates/aenv/src/commands/connect.rsenters terminal raw mode throughRawModeGuard. In raw mode, the local terminal does not generate SIGINT for theaenvprocess. Instead, Ctrl-C is read as byte0x03and forwarded as PTY input throughStreamInput/SendInput.The CLI does not currently install a local Ctrl-C handler or explicitly send SIGINT through envd. It relies entirely on the remote PTY path to interpret
0x03and signal the foreground process group. In the observed case, that does not happen reliably, leaving the CLI waiting for the foreground process indefinitely.The current process protocol also only exposes SIGTERM and SIGKILL in the
Signalenum, not SIGINT:There may also be a recovery-path issue: control-only input such as
0x03is not treated as input that should produce output byshould_expect_output, so a lost or stalled Ctrl-C may not trigger the same input/output recovery logic as printable input.Suggested direction
Acceptance criteria
python3 -m http.server ...inaenv connectand pressing Ctrl-C stops the server and returns to the shell prompt.sleep 3600and similar foreground processes.@Jainil-Gosalia commented on GitHub (Jul 29, 2026):
Potential Fix:
The fix will address three issues in crates/aenv/src/commands/connect.rs and the proto file. First, it will add SIGNAL_SIGINT = 2 to the Signal enum in thirdparty/envd/proto/process.proto and regenerate the stubs. Second, in maintain_stream_input, it will intercept byte 0x03 (Ctrl-C) and issue a SendSignal(SIGINT) unary RPC instead of forwarding it as PTY input, bypassing the unreliable remote PTY discipline. Third, it will expand should_expect_output to include 0x03 so Ctrl-C output triggers stall-detection recovery, and add a Ctrl-] escape sequence to drop raw mode without needing a remote response. The sandbox will stay alive (SIGINT, not SIGKILL) and terminal restoration will be verified on all exit paths. The external envd server changes will remain out of scope in the e2b-dev/infra fork.
@LSX-s-Software commented on GitHub (Aug 6, 2026):
Updated analysis based on repository history
This supersedes the earlier Potential Fix comment. The current evidence does not support adding SIGINT to the vendored envd protocol as the first fix.
Historical context
The original native CLI used sequential unary
SendInputrequests. After a send failure, its stdin pump stopped permanently.Commit
f603d754changed input toStreamInputas part of a larger terminal recovery state machine. Its purpose was to recover from transient envd/proxy disconnections, reconnect output, and exit cleanly when the sandbox was deleted or envd remained unreachable. I found no evidence that the change was made for Ctrl-C semantics or measured input performance.Current suspected failure mode
The current implementation has several delivery gaps consistent with this bug:
route_input()treats a successful write to the localstream_txchannel as success, but that does not confirm that envd received or wrote the bytes to the PTY.should_expect_output()excludes control-only input such as Ctrl-C (0x03), so a lost Ctrl-C does not activate the input/output stall recovery path.send_recovery_input()drains all remaining queued stdin after sending one recovery request, which can discard repeated control input.These findings show an AgentENV-specific input reliability risk, but they do not yet prove which transport failure occurs in the reported reproduction.
Why SIGINT RPC is not the current direction
Ctrl-C should normally remain PTY input byte
0x03. The remote terminal driver then sends SIGINT to the PTY foreground process group.Adding SIGINT only to the vendored client proto would not update the deployed envd server. Also, the existing process selector identifies the shell process, not necessarily the foreground job process group, so sending SIGINT to that PID would not preserve normal terminal semantics.
Proposed validation
sleep 3600, send PTY byte0x03, and verify that the foreground command stops while the shell remains usable.StreamInputpath.If the direct envd test passes but the aenv/proxy test fails, the fix belongs in the aenv input transport/recovery layer.
A likely client-only fix is to use batched unary
SendInputinside the current session state machine. This must preserve the reconnect behavior introduced byf603d754; simply reverting to the old stdin pump would reintroduce the bug where one transient send failure permanently disables input.Keeping
StreamInputis also possible, but reliable delivery would require an acknowledgement or an equivalent ordering/delivery boundary. Merely adding0x03toshould_expect_output()would improve recovery detection but would not guarantee delivery of the first Ctrl-C.