Skip to content

fix: restore exact focus after pane creation - #346

Merged
EtanHey merged 1 commit into
mainfrom
fix/restore-origin-surface
Aug 2, 2026
Merged

fix: restore exact focus after pane creation#346
EtanHey merged 1 commit into
mainfrom
fix/restore-origin-surface

Conversation

@EtanHey

@EtanHey EtanHey commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • capture the exact origin workspace/surface before pane or workspace creation can move focus
  • observe post-creation focus instead of assuming whether cmux focused the new pane, so restoration is transport- and cmux-version-independent
  • restore only when focus still exactly matches cmuxlayer's observed post-creation focus, preserving deliberate user movement
  • add transport-level surface focus support and keep successful spawn handles even when focus restoration fails
  • preserve explicit focus behavior and target-workspace placement when identity is degraded

Verification

  • lead-routed Claude pair review: ACCEPT (round 3)
  • focus regression gate: 16/16
  • affected suites: 515/515
  • canonical suite: 106 files, 2348/2348 tests
  • typecheck: pass
  • build: pass
  • diff check: pass
  • pre-push suite: 2348/2348
  • remote CI: pass

Review dispositions

  • CodeRabbit target-selection finding: fixed; degraded focus identity no longer skips selecting the target workspace.
  • CodeRabbit hook-warning suggestion: declined; the hook currently calls a helper that catches identify/enumeration failures and returns null, so warning plumbing there would describe an unreachable failure path.
  • Reviewer NOT VERIFIED narrowed: cmuxlayer never requests focus from send/send-key (their CLI path has no focus argument or focus call), but the cmux app could still focus as an undocumented input side effect. This is narrowed, not closed, pending installed live verification.
  • Follow-up, not a gate: CmuxClient.newSurface does not forward its currently-unused focus option.

PR #343 and its worktree are intentionally untouched. Release, fleet reconnect, and Etan-observed live verification are owned by the lead; this PR is merged, not declared live-done.

@cursor

cursor Bot commented Aug 2, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_547c9e94-0ca1-48a8-84b6-0277a5284452)

@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@EtanHey, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 8b6bccbf-8eef-4558-8f23-835a3886763f

📥 Commits

Reviewing files that changed from the base of the PR and between df184a2 and f98f50e.

📒 Files selected for processing (10)
  • src/agent-engine.ts
  • src/cmux-client.ts
  • src/cmux-socket-client.ts
  • src/cmux-transport-self-heal.ts
  • src/server.ts
  • tests/cmux-client.test.ts
  • tests/cmux-socket-client.test.ts
  • tests/cmux-transport-self-heal.test.ts
  • tests/server-agent-tools.test.ts
  • tests/server.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread src/cmux-socket-client.ts
// parameter is not part of cmuxlayer's verified socket contract. Route an
// explicit preference through the pinned CLI instead of risking a silently
// ignored socket field.
if (opts?.focus !== undefined) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High src/cmux-socket-client.ts:416

newSplit in CmuxSocketClient throws unsupported_focus_option when focus: true is passed on a socket-only instance without a CLI fallback, even though true is the socket's default behavior. Only focus: false needs to be routed through the CLI. The current guard at line 416 checks opts?.focus !== undefined, which catches true and causes a regression for callers that pass focus: true explicitly.

🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @src/cmux-socket-client.ts around line 416:

`newSplit` in `CmuxSocketClient` throws `unsupported_focus_option` when `focus: true` is passed on a socket-only instance without a CLI fallback, even though `true` is the socket's default behavior. Only `focus: false` needs to be routed through the CLI. The current guard at line 416 checks `opts?.focus !== undefined`, which catches `true` and causes a regression for callers that pass `focus: true` explicitly.

@EtanHey
EtanHey merged commit 3e5a7af into main Aug 2, 2026
5 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f98f50ec0a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/server.ts
if (focused?.workspace_ref) {
return {
workspace: focused.workspace_ref,
...(focused.surface_ref ? { surface: focused.surface_ref } : {}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve stable UUIDs in focus leases

When cmux restarts or recycles refs during a readiness wait, this stores only the process-local surface:N ref and later both compares it and passes it as surface_id to surface.focus. The type contract in src/types.ts explicitly distinguishes this mutable ref from the stable surface UUID, so a recycled ref can make the lease appear unchanged and restore focus to the wrong pane. Resolve and retain the stable UUID in each focus target before waiting.

AGENTS.md reference: AGENTS.md:L38-L39

Useful? React with 👍 / 👎.

Comment thread src/server.ts
Comment on lines 5961 to +5965
if (!args.pane && !args.surface) {
priorFocus = await focusTargetBeforeSplit(targetWorkspace);
focusRestoreLease = await focusTargetBeforeSplit(
targetWorkspace,
args.focus !== true,
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Capture leases for explicitly anchored splits

When new_split is called with pane or surface and focus is omitted or false, this condition skips focus capture entirely. The commit also stops forwarding focus to client.newSplit, so cmux can focus the newly created surface while capturePostCreationFocus(null) and the eventual restore are no-ops, contradicting the tool's promise to restore the exact origin unless focus:true is requested. Capture the origin lease for anchored creations as well.

Useful? React with 👍 / 👎.

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.

1 participant