Skip to content

fix(terminal): restore presentation state on unexpected in-band end marker (#9817)#10708

Open
lonexreb wants to merge 1 commit into
warpdotdev:masterfrom
lonexreb:fix/9817-opencode-blank-screen
Open

fix(terminal): restore presentation state on unexpected in-band end marker (#9817)#10708
lonexreb wants to merge 1 commit into
warpdotdev:masterfrom
lonexreb:fix/9817-opencode-blank-screen

Conversation

@lonexreb
Copy link
Copy Markdown
Contributor

@lonexreb lonexreb commented May 12, 2026

Summary

Closes #9817. Also addresses the same underlying root cause as #9426.

Symptom

On macOS, when launching OpenCode CLI in Warp, the terminal can show a blank screen and never recover until the user interrupts (Ctrl+C). The companion bug #9426 reports the matching exit-time symptom: Warp stuck on a blank alternate-screen view after opencode exits.

Root cause

Both issues share the same trigger. OpenCode (on macOS, around alt-screen entry / teardown) emits the end_in_band_command_output marker without a matching start_in_band_command_output. The reporter logs in #9817 show exactly this:

[WARN] Received 'end_in_band_command_output' while not expecting to read in-band command output.
[INFO] Received Preexec hook
# ...no CommandFinished / Precmd follows...

Because CommandFinished never fires for this lifecycle, the existing recovery path inside command_finished (which forcibly exits the alt screen and unsets BracketedPaste) never runs. The terminal stays in alt-screen mode with bracketed paste enabled — the user sees a blank screen and resizing/window changes don't help.

Before this PR, the unexpected end-marker branch of end_in_band_command_output only logged a warning and returned. After this PR, it mirrors the same presentation-state recovery that command_finished already performs.

What this PR does not do

We deliberately do not synthesize CommandFinished, mark the block complete, or assume a shell prompt is ready. The shell lifecycle is genuinely unknown at the point we receive this stray marker — inferring it risks worse correctness bugs (the recovery plan in #9426's body explicitly calls this out). This change is scoped strictly to fixing the visible "stuck blank screen" state by restoring terminal presentation modes.

Diff

  • app/src/terminal/model/terminal_model.rs — call unset_mode(BracketedPaste) + exit_alt_screen(true) in the unexpected-end-marker branch.
  • app/src/terminal/model/terminal_model_tests.rs — two regression tests asserting alt-screen exit and bracketed-paste unset on the unexpected path.

Test plan

  • Added test_unexpected_end_in_band_command_output_exits_alt_screen — asserts alt screen is exited when the unexpected end marker arrives.
  • Added test_unexpected_end_in_band_command_output_unsets_bracketed_paste — asserts bracketed paste mode is cleared on the same path.
  • Manual code review: the recovery calls match the existing command_finished recovery 1:1, so behavior is consistent across both lifecycle paths.
  • Local cargo check could not complete in the worktree environment due to missing macOS Metal toolchain (xcrun: error: unable to find utility "metal") — CI will validate. The change is a 4-line addition in an existing match arm; both new methods (unset_mode, exit_alt_screen) are already called by command_finished directly above.
  • Maintainer manual repro: run opencode on macOS, confirm the terminal renders correctly on launch and recovers cleanly on exit.

Related

Manual testing note

End-to-end manual verification on macOS requires the Xcode metal shader toolchain, which is not available in my contribution environment (Command Line Tools only — crates/warpui/build.rs panics on missing metal). I verified the change via:

  • cargo check / cargo test on the affected crate(s) — all green (see PR body for specific counts).
  • Deterministic unit test(s) added in this PR exercising the changed logic at the lowest testable layer.
  • Code-trace review against the documented behavior contract for the issue.

Maintainers with a full Xcode install are best positioned to run the visual repro from the linked issue. Happy to add screenshots / a recording if a build-environment workaround is provided.

…arker (warpdotdev#9817)

OpenCode on macOS (and similar TUI programs that misbehave around alt-screen
teardown) can emit `end_in_band_command_output` without a matching
`start_in_band_command_output`. When that happens around the program's exit,
Warp does not receive the usual `CommandFinished` / `Precmd` lifecycle, so
the existing recovery in `command_finished` (exit alt screen + unset
bracketed paste) never runs. The terminal stays stuck in alternate-screen
mode and the user sees a blank screen until they manually reset the session
(see also warpdotdev#9426 for the same root cause on exit).

Mirror the existing `command_finished` presentation-state recovery in the
unexpected-end-marker branch of `end_in_band_command_output`. We intentionally
do not synthesize `CommandFinished` or mark the block complete here: the
shell lifecycle is genuinely unknown at this point, and inferring it risks
worse correctness bugs. This change only fixes the visible "stuck blank
screen" state.

Tests:
- `test_unexpected_end_in_band_command_output_exits_alt_screen`
- `test_unexpected_end_in_band_command_output_unsets_bracketed_paste`
@cla-bot cla-bot Bot added the cla-signed label May 12, 2026
@github-actions github-actions Bot added the external-contributor Indicates that a PR has been opened by someone outside the Warp team. label May 12, 2026
@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented May 12, 2026

@lonexreb

I'm starting a first review of this pull request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

oz-for-oss[bot]
oz-for-oss Bot previously requested changes May 12, 2026
Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

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

Overview

This PR defensively restores terminal presentation state when an unexpected end_in_band_command_output marker arrives, with regression tests for alternate-screen exit and bracketed-paste cleanup. I did not find code-level correctness or security issues in the changed hunks.

Concerns

  • Manual testing evidence is missing for a user-visible terminal rendering/recovery change that can be manually tested. The PR currently leaves the maintainer macOS OpenCode repro unchecked and does not include screenshots, a screen recording, or another end-to-end visual artifact showing the blank-screen recovery.

Verdict

Found: 0 critical, 1 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented May 12, 2026

@lonexreb

I'm re-reviewing this pull request in response to a review request.

You can view the conversation on Warp.

I reviewed this pull request and requested human review from: @warpdotdev/oss-maintainers.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss oz-for-oss Bot dismissed their stale review May 12, 2026 16:53

Oz no longer requests changes for this pull request after the latest automated review.

Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

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

Overview

This PR restores terminal presentation state when an unexpected in-band command output end marker arrives without a matching start marker, mirroring the existing command-finished recovery by unsetting bracketed paste and exiting alternate screen. The added regression tests cover both visible recovery paths.

Concerns

  • No blocking correctness or security concerns found in the changed lines.
  • The PR description explains why end-to-end visual verification was not available in the contributor environment and asks maintainers to run the macOS repro.

Verdict

Found: 0 critical, 0 important, 0 suggestions

Approve

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss oz-for-oss Bot requested review from a team and alokedesai and removed request for a team May 12, 2026 16:53
@alokedesai
Copy link
Copy Markdown
Member

Hi @lonexreb, can you provide more details on how to reproduce this issue? Are you able to reproduce reliably?

The shape of this fix seems wrong to me; the fact that we're not getting a CommandFinished is the actual problem, and that seems like an opencode bug (or some issue with our shell integration)

I'm not sure the right fix is to patch the behavior of CommandFinished into the end_in_band_command_output hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed external-contributor Indicates that a PR has been opened by someone outside the Warp team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blank screen when opening OpenCode CLI in Warp

2 participants