Skip to content

feat(agent/reconnectingpty): allow selecting backend type #17011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2025

Conversation

johnstcn
Copy link
Member

In #8640 we added an alternative 'screen' backend for our reconnectingpty endpoint used by our web terminal.
This opportunistically checks for the presence of screen in $PATH and selects the screen backend if screen is available, falling back to the default "buffered" backend.

This is fantastic for long-lived shell sessions, but another use case for rpty is just executing "one-off" commands (basically, anything that isn't a shell).
In these cases, the screen backend is actually kind of annoying, as you get the following output:

<output of command>






[screen is terminating]

I considered the alternative of stripping the extraneous output, but decided it made more sense to skip the overhead of executing screen if it won't be needed anyway for a simple one-shot command.

The definition of a "one-shot" command is somewhat open to interpretation.
This should not affect any existing usage, as omitting BackendType should result in the same behaviour as before.

Note: this also loses the extra "Connected to agent" and "reconnect ID" output from the exp rpty command. I didn't find them especially useful, but can easily add these back if needed.

@johnstcn johnstcn self-assigned this Mar 19, 2025
@johnstcn johnstcn requested review from mafredri and ThomasK33 March 19, 2025 21:42
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

Cool, thanks for adding this. Having this configurable is very nice!

@@ -64,13 +66,20 @@ func New(ctx context.Context, logger slog.Logger, execer agentexec.Execer, cmd *
// runs) but in CI screen often incorrectly claims the session name does not
// exist even though screen -list shows it. For now, restrict screen to
// Linux.
backendType := "buffered"
autoBackendType := "buffered"
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: can we call this plain? Otherwise it feels like we're leaking implementation details.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll do this as a follow-up refactor 👍

// If the user specified a command, we'll prefer to use the buffered method.
// The screen backend is not well suited for one-shot commands.
backend = "buffered"
}
Copy link
Member

@mafredri mafredri Mar 20, 2025

Choose a reason for hiding this comment

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

Suggestion: It'd be nice to see this as a CLI flag too, to (auto, plain, screen).

Side-note: I guess screen could even be called multiplexer to allow to swap out for e.g. tmux in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I considered having it a CLI flag, but hesitated exposing this internal implementation detail. It does make sense, especially with your vim comment below.

return false
}
return true
}
Copy link
Member

@mafredri mafredri Mar 20, 2025

Choose a reason for hiding this comment

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

This has some interesting repercussions when it's neither a shell and not a one-shot command. Imagine doing vim /my/file.txt. Here we would return true but vim is one of the reasons we have the screen backend.

This is probably fine though, but I'm flagging this behavior as it's not ideal. At the very least worth a comment.

(The flag would alleviate this as you can enforce the behavior then.)

@johnstcn johnstcn merged commit 6862409 into main Mar 20, 2025
32 checks passed
@johnstcn johnstcn deleted the cj/reconnectingpty-backend branch March 20, 2025 13:45
@github-actions github-actions bot locked and limited conversation to collaborators Mar 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants