Skip to content

rex: resolve session from REX_BLOCK when REX_SESSION is unset - #42

Closed
Sipym wants to merge 1 commit into
rednafi:masterfrom
Sipym:fix/rex-block-session
Closed

Sipym wants to merge 1 commit into
rednafi:masterfrom
Sipym:fix/rex-block-session

Conversation

@Sipym

@Sipym Sipym commented Dec 2, 2026

Copy link
Copy Markdown

Implements the fallback suggested in #41.

Problem

Recent Rex builds export only REX_BLOCK (plus REX_BIN_DIR) in terminal environments; REX_SESSION is empty. New() then returns nil, false, so s shows "not in Rex, press y to copy" and agent state watching (Last Turn) cannot work either.

Fix

When REX_SESSION is empty but REX_BLOCK is set, resolve the session with rex block inspect "$REX_BLOCK" --json → .session_id (3s timeout). This mirrors the CLI's own documented session resolution: use the session containing REX_BLOCK when available, otherwise REX_SESSION, otherwise the only session.

No behavior change when REX_SESSION is set.

Tests

  • TestNewBlockSessionFallback: only REX_BLOCK set → client resolves the session and uses it for session.list_blocks
  • TestNewBlockSessionFallbackFailure: unresolvable block → nil, false
  • Full suite passes (go test ./...)

Live verification

Built locally on macOS arm64 against Rex app 0.1.0-preview.38 / server 0.1.0-preview.25: comments now send successfully ("sent 1 comment to shell") with the stock generated rexdiff_toggle.lua, no local patches needed.

Closes #41

Recent Rex builds export only REX_BLOCK in terminals. Instead of failing
with 'not in Rex', inspect the block to find its session, mirroring the
CLI's own session resolution rules. Adds fallback success/failure tests.
@rednafi

rednafi commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Closing in favor of #39. Thanks for the report.

@rednafi rednafi closed this Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"not in Rex" on recent Rex builds: REX_SESSION is no longer set in terminals

2 participants