Skip to content

Preserve exact remote window names during mirroring - #859

Open
cweill wants to merge 4 commits into
mainfrom
fix/numeric-window-mirror
Open

cweill wants to merge 4 commits into
mainfrom
fix/numeric-window-mirror

Conversation

@cweill

@cweill cweill commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Attaching a remote window named 2 initially selects the correct window, but the mirror subscription and later layout reconciliation interpret that name as window index 2. The mirror can resize and switch to an unrelated window.

Summary

  • Resolve the protocol's WindowName field as an exact name, rejecting missing and duplicate names before subscribing or resizing.
  • Preserve exact-name semantics when applying remote layout updates.
  • Add unit coverage for numeric names, missing names, prefixes, and ambiguity, plus an integration regression that splits a numeric-named remote window after attachment.

Testing

  • Confirmed both new regression tests fail on the original implementation.

  • Pre-push merged diff coverage: 100% (20/20 executable changed lines). The subsequent test-fixture-only commit passed its targeted tests 100 times; its push reused this coverage result without rerunning the pre-push hook.

  • TMPDIR=/tmp go test ./internal/server ./test -run 'TestAttachWindowUsesExactName|TestRemoteCLIAttachNumericWindowName' -count=100 -timeout 300s

  • TMPDIR=/tmp go test ./test -run '^TestAttachWindow(StreamsLayoutUpdates|InitialResizeBroadcasts)$' -count=100 -timeout 300s

  • TMPDIR=/tmp go vet ./...

  • TMPDIR=/tmp go test ./internal/server ./internal/server/mirror ./test -run 'TestAttachWindow|TestRemoteCLI.*Window|TestWindowMirrorCheckpointAndRestore' -count=1 -timeout 60s

  • The full TMPDIR=/tmp go test ./... -timeout 120s run reported failures in untouched audit-log descriptor, pprof socket-path, wedged-socket, chooser, and key-pacing tests. The audit-log, pprof, and dial timeout failures reproduce independently in packages unchanged from origin/main.

  • CI is blocked at lint by pre-existing SA1006 in internal/server/commands/layout/args.go:161 (fmt.Errorf(remoteAttachUsage)). Confirmed the same line on origin/main, with no diff to that file. Failed CI job.

  • Manual review and simplification passes completed; Claude review returned lgtm.

Review focus

The mirror protocol already identifies windows by name. Ordinary CLI window resolution retains its existing index and prefix semantics. Check that both initial subscription and ongoing reconciliation use the exact name, and that an ambiguous name cannot resize either window.

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @cweill's task in 18s —— View job


Review of PR #859

  • Read the diff
  • Checked the subscription path (attachWindowClientEvent.handle) and the reconcile path (enqueueWindowLayoutReconcile)
  • Checked for other callers that use loose resolution on WindowName

Findings

No blocking issues.

  • Subscription: resolveWindowName (internal/server/session_window.go:125) matches by exact name only. Numeric names are not treated as indexes and prefixes are not accepted. A duplicate name returns an "ambiguous" error before attachWindowClientEvent.handle (session_events_client.go:89) does any sizing or subscribing.
  • Reconcile: enqueueWindowLayoutReconcile (session_window_mirror.go:32) now calls resolveRemoteWindowSnapshot with SelectorName. That function does exact matching and reports ambiguity (commands_remote.go:949-963). The old remote.ResolveWindowFromLayout call in this path is gone.
  • Other callers: I found no other non-test caller that resolves WindowName loosely. server.go:1007 passes the name straight into the now-exact attach path.
  • Tests: the unit table covers a numeric name, an ordinary name, a missing name, a numeric name that doesn't exist, a prefix, and a duplicate. The integration test covers a numeric-named window being split after attach.

Minor, non-blocking notes

  • The reconcile path silently returns on a resolve error (session_window_mirror.go:35-37). That behavior was already there, but if a remote later renames the window to a duplicate, the mirror will stop updating with no log line. A debug log would help.
  • The two exact-name implementations are separate: resolveWindowName over live windows, and resolveRemoteWindowSnapshot over snapshots. They are small and consistent, so this is fine for now.
  • I did not run the tests. The PR description reports the targeted runs and says unrelated tests fail in the full suite.

LGTM

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium impact] Changes how remote window names are resolved during mirroring.

The PR appears safe to merge, with a non-blocking improvement to the ambiguous-name regression test.

Findings

  1. P2 Rejected attach effects go unchecked ▶

Summary

The PR keeps exact window names through mirror subscription and later layout updates.

  • Remote mirrors keep following the window with the exact requested name.

Duplicate-name rejection is intentional: cweill explicitly requires ambiguous names to be rejected before subscription or resizing.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    A[Resolve remote selection] --> B[Save exact window name]
    B --> C[Subscribe by exact name]
    C --> D{Exactly one match?}
    D -->|No| E[Reject before resize or registration]
    D -->|Yes| F[Resize and subscribe]
    F --> G[Receive layout updates]
    G --> H[Find saved exact name]
    H --> I[Update local mirror]
Loading

Reviews (1) · Last reviewed commit: "test: cover numeric names in window prot..." · Reviewed by Greptile

Comment on lines +38 to +43
result := sess.enqueueAttachWindowClient(cc, tt.ref, 0, 0)
if tt.wantErr != "" {
if result.err == nil || !strings.Contains(result.err.Error(), tt.wantErr) {
t.Fatalf("attach error = %v, want %q", result.err, tt.wantErr)
}
return

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 Rejected attach effects go unchecked

TestAttachWindowUsesExactName passes zero dimensions and checks only the error for duplicate names. It cannot catch an attach that resizes either window or registers the client before returning the ambiguity error.

Pass nonzero dimensions in the duplicate-name case, then assert that both windows keep their sizes and the client remains unregistered. This would protect the no-change behavior required for rejected attaches.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

This branch has not been deployed

No deployments
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