Skip to content

Stop the first terminal attach from waiting on a protocol ping - #525

Merged
powerfooI merged 2 commits into
powerfooI:mainfrom
thiblahute:upstream/clipboard-relay-protocol
Oct 31, 2026
Merged

powerfooI merged 2 commits into
powerfooI:mainfrom
thiblahute:upstream/clipboard-relay-protocol

Conversation

@thiblahute

Copy link
Copy Markdown
Contributor

The first terminal attach on every connection could stall for the full 500 ms clipboard relay wait.

The clipboard relay check asked Herdr for its protocol through args.herdrProtocol(), bypassing the bridge's cached bridgeProtocol(). Over a remote link that ping takes longer than the relay wait (CLIPBOARD_RELAY_READY_WAIT_MS), so the first attach waited the whole 500 ms before learning that protocol 22 skips the relay anyway.

Changes

  • The relay check uses bridgeProtocol(), which the attach has already resolved.
  • The relay ThinClient and the legacy direct terminal streams get bridgeProtocol too, so they no longer send a control call each to learn the protocol.

Verification

  • bun test server/src/bridge/terminal-bridge.test.ts server/src/bridge/endpoint-terminal-session.test.ts: 167 pass, 0 fail. New test: with fake timers frozen and a protocol probe that only answers once, the first protocol 22 attach completes without a second probe. It fails on main and passes with this change.
  • bun run format:check on the changed files: clean.
  • bun run lint: clean apart from the existing TerminalView.tsx exhaustive-deps warning.
  • bun run typecheck: passes, including the web build and asset budget check (initial JS 805.0/805 KiB).
  • bun run test:quick with an isolated HOME, on main plus this change and the other small fixes I am sending alongside: 3965 pass, 4 skip, 2 fail. Both failures (useMobileControlsDrag.keyboard.test.ts and the SSH paths test) fail the same way on main on macOS.

Not measured on this branch: the attach latency over a real remote link.

Compatibility

No API or protocol changes. The protocol is resolved once per bridge, as navigation mode and tab.move support already assume.

The clipboard relay check pinged Herdr for its protocol without the
bridge's cache. Over a remote link that ping takes longer than the
500 ms relay wait, so the first attach of every connection stalled for
the full wait before learning that protocol 22 skips the relay. Use the
protocol the attach already resolved, and let the direct terminal
streams reuse it too.
@github-actions github-actions Bot added the enhancement New feature or request label Oct 31, 2026
The "collapse and outside drag" capsule test expected the Send button to
re-enable right after dispatching compositionend. TerminalComposer
deliberately releases its IME lock one setTimeout(0) tick later, and the
test only passed when that timer happened to fire before act() resolved.
React's async act() resolves after a setImmediate flush, and in Bun a
setImmediate runs before a 0 ms timer unless about a millisecond has
already passed. The outcome therefore depended on machine speed and
load: the test failed every time on a fast macOS machine and
intermittently in CI.

Install Bun's fake timers around compositionend, check that the lock is
still held before the tick, then advance timers by 0 inside act() and
restore real timers in finally.
@powerfooI
powerfooI merged commit 61915cb into powerfooI:main Oct 31, 2026
4 checks passed
@powerfooI powerfooI added the bug Something isn't working label Oct 31, 2026 — with ChatGPT Codex Connector
@powerfooI powerfooI removed the enhancement New feature or request label Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants