Repository navigation
fix(bw*): keep OpenTUI capability queries off the main screen - #53
Merged
Max Rakitin (mrakitin) merged 4 commits intoDec 2, 2026
Merged
Max Rakitin (mrakitin) merged 4 commits into
Max Rakitin (mrakitin) merged 4 commits into
Conversation
OpenTUI sends its terminal capability queries before it switches to the alternate screen, so a terminal that does not know them (the VTE terminal on RHEL 8 workstations) prints them on the shell's screen, and the next prompt starts on the same line. Switch to the alternate screen in launch_sandbox, after its own messages, when a TUI will start: stdin and stdout are a terminal and there is no subcommand, --exec or --serve. BWRAP_OPENTUI_ALTSCREEN=0 turns it off. Assisted-by: opencode:claude-sonnet-5-5
If opencode exits before it draws anything, nothing is left to switch the terminal back, so the shell stays on the alternate screen. Document the recovery (tput rmcup) next to the switch. Assisted-by: opencode:claude-sonnet-5-5
There was a problem hiding this comment.
🟡 Changes recommended
The wrapper incorrectly enters the alternate screen for text-only commands and lacks restoration on startup failures, leaving subsequent prompts there with normal scrollback hidden.
2 open issues
What changed in this PR
Moves OpenTUI startup capability queries onto the alternate screen to prevent terminal artifacts when launching OpenCode through the sandbox wrappers.
Changes:
- Adds shared screen-switch preparation and integrates both OpenCode wrappers.
- Adds terminal and argument checks plus a host-environment opt-out.
- Documents the workaround and adds pseudo-terminal checks.
| File | Description |
|---|---|
| tests/test-opentui-altscreen.sh | Checks screen-switch decisions and output ordering. |
| lib/bwrap_sandbox_lib.sh | Adds preparation logic and the pre-launch screen switch. |
| docs/bw-wrappers.md | Documents behavior, limitations, and opt-out. |
| docs/beamline-agent.md | Explains applicability to beamline launches. |
| bin/bwopencode2 | Calls preparation outside exec and serve modes. |
| bin/bwopencode | Calls preparation outside exec mode. |
Review effort: Balanced
The first tool argument is not enough: the argument guard puts --standalone in front, so --version and --log-level info run hello looked like a TUI start and left the shell on the alternate screen. Let guard_tool_args, which already finds the subcommand, say whether the TUI starts (no subcommand, no --help, --version, --completions or --wizard), and test it with the rewritten arguments. bwopencode has no guard, so it switches only when given no arguments. opentui_altscreen_prepare keeps only the terminal and opt-out checks. Assisted-by: opencode:claude-sonnet-5-5
--completions=bash, with =, was not recognised as a text-only option, so the completion script was printed on the alternate screen and the shell was left there. Assisted-by: opencode:claude-sonnet-5-5
Max Rakitin (mrakitin)
approved these changes
Dec 2, 2026
Max Rakitin (mrakitin)
left a comment
Contributor
There was a problem hiding this comment.
I did not read the test in details, other changes look good.
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
Stop the capability queries that opencode's TUI sends at startup from being
printed on the shell's screen of beamline workstations that start it with
bla(orbwopencode/bwopencode2directly).Description
On the RHEL 8 workstations the screen showed, right after the launcher's
messages, a line of boxed
ESCglyphs and text such as?1016$p ?2027$p ... ?u 99;i=opentui-notifications:p=?; ... 7501;? ... Gi=31337,s=1,v=1,a=q,t=d,f=24;AAAAfollowed by the next prompt on the same line (e.g.
SXN bash-4.4$).These are the terminal capability queries of OpenTUI, the library opencode2
draws with (
queryTerminalSend()inpackages/native/src/session.zig, whichruns before
enterAltScreen()). They are sent to the main screen. A terminalthat does not know them prints them; newer terminals and tmux ignore them. The
launcher is not the cause:
sudopasses the bytes through unchanged, andbwopencode2started directly does the same. It is not the stray mouse-reportproblem of #23, which is input arriving after the tool exits.
Fix:
launch_sandboxwritesCSI ? 1049 h(switch to the alternate screen)as its last step before the
exec, so the queries land on the alternatescreen. OpenTUI clears that screen when it switches, and leaves it when it
exits, so the main screen and scrollback are not touched. The launcher's own
messages (network report, warnings) are printed before the switch and stay in
the scrollback.
bwopencode2decides fromguard_tool_args, which already finds thesubcommand (and adds
--standalone) and now also setsTOOL_STARTS_TUI: 1for no subcommand (or a directory argument) and no
-h/--help,-v/--version,--completions[=SHELL]or--wizardanywhere in the arguments. Sobla,bwopencode2andbwopencode2 -s ses_abcswitch;bwopencode2 run ...,--versionand--log-level info run hellodo not.bwopencodehas noguard, so it switches only when given no arguments.
opentui_altscreen_prepare(lib) adds the checks the wrapper cannot make(stdin and stdout are a terminal, the opt-out is not set), and the wrappers
call it just before
launch_sandbox, never for--execor--serve.BWRAP_OPENTUI_ALTSCREEN=0in the host environment turns it off.bla: it starts the wrapper with no arguments, on a terminal(sudo's pty).
Open points for reviewers:
alternate screen and the shell stays there until
tput rmcup(orreset):the launcher hands its process over to the sandbox, so nothing is left to
switch back. Documented in
docs/bw-wrappers.md. Switching back from insidethe sandbox when the tool fails (
CSI ? 1047 l) could be a follow-up.bwopencode(opencode 1) is covered too, because it also uses OpenTUI, but Ihave only seen the printed queries with
bwopencode2.the alternate screen. An issue for
anomalyco/opentuiis drafted separately;this change can be removed when that lands.
Testing
tests/test-opentui-altscreen.sh(new, 28 checks, run in a pseudo-terminal):which
bwopencode2arguments start the TUI (run throughguard_tool_args, soafter the
--standalonerewrite), when the switch is made, and thatlaunch_sandboxsends it afterits own messages and before the tool starts, with a stub in place of bwrap.
It is not run by CI (like the other shell tests);
pixi run -e dev testruns the Python tests only.
tests/test-bwopencode2-serve.sh,tests/test-bla-git-config.sh,tests/test-net-lustre-guard.sh,pixi run -e dev test, andprekon the changed files.vdi-10-65-31-215(RHEL 8.10, gnome-terminal 3.28.3, VTE 0.52.4,opencode v2.4.3; the same OS as the SXN workstation where the junk was
reported, and it shows the same junk), with this branch at
447e08a:bwopencode2prints the queries and the next prompt starts onthe same line;
bwopencode2andbwopencode2 -cleave a clean screen and a prompt ontheir own line after quitting opencode;
BWRAP_OPENTUI_ALTSCREEN=0the queries are printed again;--version,--help,--log-level info --versionand--exec echo helloprint normally with no screen switch:
scriptrecords noESC[?1049hfor--version;scripton a TUI start shows the switch to the alternate screen at byte 171,before OpenTUI's first query at byte 201, then OpenTUI's own switch at 391.
--promptwith novalue) leaves the shell on the alternate screen, with the error there and not
in the scrollback, until
tput rmcup(see the open points).blaon an SXN workstation, which needs the changedeployed.
Checklist
pixi run -e dev lintlocally (or wait for CI) — see.github/workflows/lint.ymlrunansibledeployment)Assisted-by: opencode:claude-sonnet-5-5