Skip to content

A pane waiting for another web bridge is resumed and held again when herdr answers a retry slowly #240

Closed

Description

@devswha

What fails

server/attach-held.contract.test.ts, "a terminal another web bridge holds > waits for that bridge instead of ending, then attaches when it lets go":

expect(b.state.errors.filter((code) => code === "attach_held")).toHaveLength(1)   // received 2 (line 130)
expect(b.state.errors.filter((code) => code === "attach_held")).toHaveLength(2)   // received 3 (line 148)

The client is told attach_held twice while it waits. Between the two it also gets an attach-resumed, so the browser shows the pane as connected for a moment although the other bridge still holds it.

How often

1 of 20 runs of the file alone on a 32-core Linux workstation with other work running (herdr 0.9.3, Bun 1.4.2). It was first seen during a full bun run test:integration.

Cause

This is a product bug, not a test bug. server/index.ts holds an attach's first bytes for ATTACH_HOLD_MS (100 ms) and, if herdr's refusal has not arrived by then, decides the attach took: it clears held and broadcasts attach-resumed.

The timer starts at the attach's first bytes. Those first bytes are terminal mode changes (mouse reporting off, ESC[?1006l ..., then the alternate screen on, ESC[?1049h) that the herdr terminal attach CLI writes itself, before the herdr server has answered. The server's answer (the refusal, or the screen) comes after them, and how long after depends on how busy herdr is. Measured on 400 refused attaches in a row on a busy machine: in 4 of them the refusal came more than 100 ms after the first byte (up to 218 ms). When that happens, the timer fires on the mode changes alone, the pane is resumed, and the refusal that arrives right after holds it again and sends attach_held a second time. In between, keys and input from the waiting bridge are let through to a pane the other bridge holds.

Counting from the first byte that is not a mode change instead, the refusal was never more than 1 ms away in the same 400 attaches: herdr writes it together with that byte.

Reproduction

for i in $(seq 1 20); do HERDR_TEST_MODE=integration bun test --timeout 15000 ./server/attach-held.contract.test.ts || echo FAIL; done

Deterministic: a scripted herdr that prints the mode changes, sleeps 0.4 s, then prints the refusal and exits 1. On main the client gets ["attach_held", "attach_held"].

Activity

  1. added a commit that references this issue on Oct 1, 2026
    f46ff44
  2. added a commit that references this issue on Oct 1, 2026
    d672035
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions