revdiff icon indicating copy to clipboard operation
revdiff copied to clipboard

Launcher finds no overlay backend inside the Rex terminal

Open belaytzev opened this issue 1 week ago • 1 comments

Problem

I run Claude Code inside the Rex terminal. In a Rex block launch-revdiff.sh matches no backend and exits with error: no overlay terminal available, so the review never opens. The plan-review hook fails the same way.

Rex sets TERM_PROGRAM=rex, REX_SESSION and REX_BLOCK. The launcher checks none of them.

There is a second trap. When the Rex server was started from an agterm shell, every Rex block inherits AGTERM_*. The agterm branch then wins and opens the overlay in agterm, not next to the agent.

Proposed fix

A Rex branch first in the chain, gated on TERM_PROGRAM=rex + REX_SESSION + REX_BLOCK + rex on PATH:

rex split -s "$REX_SESSION" -b "$REX_BLOCK" --split=right --cwd "$CWD" \
    --label "$OVERLAY_TITLE" --shell=none --wait --json -- sh -c "$(write_rc_cmd "$SENTINEL")"
  • --wait blocks until revdiff exits. Rex closes the block after that, so there is no pane to clean up.
  • Session and block are passed explicitly. Without them rex acts on the focused block, which can be in another session.
  • The new block zooms itself (rex block zoom --on with its own $REX_BLOCK) to get a full-width diff. REVDIFF_REX_ZOOM=0 keeps a 50/50 split.
  • The exit code goes through the usual sentinel. A rex failure (block closed, server gone) then exits 1 with rex's error and never passes for 0 or 10.

Same branch in the codex copy and in launch-plan-review.sh. One rex row in launcherBackends() plus a rex case in the fake backend.

Size: about 30 lines per launcher.

Status

I have it working on a branch and tested it in a real Rex pane:

  • annotate + q: exit 10, the annotation comes back on stdout, the block closes, focus returns to the agent block
  • the block closed mid-review: exit 1, revdiff did not finish in the rex split: Error: block …0b25ad closed
  • go test ./app/revdiff/, shellcheck 0.11.0, /bin/bash -n pass

If this fits, I'll open a PR and update the terminal lists in README, both SKILL.md files, site/ and install.md.

belaytzev avatar Nov 21 '26 19:11 belaytzev

makes sense, pls open the PR. The Rex branch can go first, with the full gate (TERM_PROGRAM=rex, both REX_* ids, rex on PATH) so a Rex block wins over inherited agterm variables.

a few things for the PR:

  • drop REVDIFF_REX_ZOOM. Zoom by default is right for a diff, a side-by-side option can come later if someone asks for it.
  • take the exit code from the sentinel only. rex split --wait returns the wrapper's status, which is mv's 0 even when revdiff exits 10. Remove the sentinel right after mktemp, as the other branches do, and treat an absent or empty one as a failure even when rex returns 0. print_output_and_exit reads an empty rc as 0. A nonzero rex return should not trip set -e before the sentinel is read.
  • the EXIT trap keeps the existing output, err and stdin cleanup and adds the sentinel and its .tmp. launch-plan-review.sh has no stderr relay, so there it is the output and sentinel files only.
  • send rex's own stdout to /dev/null and keep its stderr. --wait still prints the creation result, and the launcher's stdout carries only the annotations. --json can go since nothing reads it.
  • tests: a rex row in launcherBackends(), plus a case with both rex and agtermctl on PATH and AGTERM_* set where Rex must win, and the reverse, stray REX_* ids without TERM_PROGRAM=rex, where agterm still wins.
  • the terminal list in the no overlay terminal available error needs Rex too.

one thing to check in a real Rex pane: what happens when the launcher itself is killed while the review is open (agent timeout, kill -TERM on the launcher)? Pls confirm the launcher process has actually exited while the Rex review is still open, then report whether quitting the review afterwards still writes annotations anywhere. If the EXIT trap runs while the block keeps going, the launcher's cleanup removes the output file under it and a later quit writes a sentinel nobody reads. The herdr branch had a similar late-write problem. Describe what you see in the PR, no need to add handling before we know.

umputun avatar Nov 21 '26 20:11 umputun