Skip to content

fix(chat): show a reply at once after a silent reconnect - #2848

Merged
devswha merged 5 commits into
mainfrom
fix/reconnect-late-reply
Nov 5, 2026
Merged

devswha merged 5 commits into
mainfrom
fix/reconnect-late-reply

Conversation

@devswha

@devswha devswha commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

What

After a network loss that leaves the old connections half-open (a phone changing networks, a
laptop waking elsewhere), the agent's reply showed in Chat 30-60 s after the agent had written it,
although its conversation-changed push reached the page at once (#2839).

Traced in a real browser against an isolated server behind a proxy that silences every open
connection, as such a loss does:

  1. While the network was gone, the page kept sending reads: the chat's newest page, worktree lists,
    omo tasks, health and machine checks. Each went out on a connection that never answers again.
  2. The browser keeps at most six connections to a host. Those stuck reads held all of them, so
    every later request queued behind them, the chat's reads included, even after the WebSocket
    was replaced and the push for the reply had come.
  3. The queue only moved when the browser finally gave the dead connections up (here about 30 s
    after the network came back), and then every queued request completed at once.

A smaller part: the chat's own newest read, if sent before the reconnect, kept the chat's serial
read lane busy until its 15 s deadline, so the push behind it waited too (the usual ~3 s gap).

Change

  • ws.ts / transport.ts: when a connection was dropped because a probe went unanswered (the
    silent-loss signal from fix(ws): probe a silent socket a few seconds after a send #2838), the next connection that opens gives up the native GET/HEAD reads
    still in flight (abandonNativeReads). This frees the browser's connections, so later requests
    open fresh ones. This server's own socket going silent gives up every read (it is the browser's path to the server); another PC's socket gives up only that PC's /api/machines/<id>/ reads. Only this server's /api/ reads are tracked; writes are never given up (the server may have done them), a caller's own abort
    still reaches the request and its body, and the relay transport is untouched (its requests ride
    the relay session).
  • ConversationRefresh.restart(): the chat's read on reconnect gives up the newest read in flight
    instead of queueing behind it. ChatView treats a read given up this way as no failure (no error
    flash, no failure count).

Measurements

perf-everyday's harness (isolated server: test herdr session, temp state and HOME, port 0; headless
Chromium on the built app behind a TCP proxy; a stand-in agent writes a reply to the transcript for
each message). The proxy silences all open connections for 3 s and keeps the old ones dead. Numbers
are from the moment the agent's reply is in the transcript until it is on screen, ABBA, 4 rounds
x desktop and phone per arm (A = origin/main, B = this branch):

arm desktop gap (ms) phone gap (ms)
A 2734, 2941, 2393, 2820 2877, 28942, 3207, 3247
B 32, 140, 7, 21 36, 0, 50, 65
B 63, 63, 1, 12 -10, 12, 26, 0
A 3086, 3102, 2812, 3173 52354, 3175, 3109, 3134

A: usually ~3 s, and 30-60 s in 2 of 16 rounds (4 of 16 and 3 of 16 in two earlier runs). B: at
most 0.14 s in all 16 rounds, no tail. The time until the message reaches the agent is unchanged
(9.5-10 s, set by #2838's probe).

An intermediate version that only re-sent the chat's read every 3 s after a reconnect did not
help on the phone: the new reads queued behind the other stuck requests, which is how the pool
cause was found.

Tests

  • src/lib/transport.test.ts: in-flight native reads are given up; a write, a read sent later and
    a caller's own abort behave as before.
  • src/lib/ws.test.ts: a connection dropped for an unanswered probe gives up the reads in flight
    when its replacement opens; a reconnect after a plain close gives up nothing.
  • src/lib/conversationFetch.test.ts: restart() gives up a newest read sent before a reconnect
    and reads again at once.

Each failed before the change (missing export / no abort / restart is not a function).

Validation

  • bun run check fast at 1731371: all ok (unit 11364 pass, 0 fail; typecheck, build, generated files, workflow syntax). The head merges origin/main, which touched only app/electron.
  • bun test src/lib/api-request-id.test.ts src/lib/conversationFetch.test.ts src/lib/transport.test.ts src/lib/ws.test.ts src/components/ChatView*: 194 pass.
  • ABBA above (loopback, desktop and phone). Not measured over the hosted relay: this change does not
    touch the relay transport's requests.

Fixes #2839.

After a network loss that leaves the old connections half-open, the reads
the page sent meanwhile (chat pages, worktree lists, health) never answer.
They hold the few connections the browser keeps to the server, so every
later request, the chat's reads included, waits behind them until the
browser gives them up: the agent's reply showed 30-60 s after it was
written, though its conversation-changed push came at once.

- ws: a connection dropped for an unanswered probe gives up the native
  GET/HEAD reads still in flight once a new connection opens
  (abandonNativeReads); writes are never abandoned.
- ConversationRefresh.restart(): the chat's reconnect read gives up the
  newest read in flight instead of queueing behind it; a read given up
  this way is no read failure.
External hosts and non-API paths keep the caller's init untouched; the request-id test checks that the caller's abort reaches the request rather than the signal's identity.
@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 18 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8f58003 and 4628a97.

Files selected for processing: 9

  • changelog.d/chat-reply-after-reconnect.md
  • src/components/ChatView.tsx
  • src/lib/api-request-id.test.ts
  • src/lib/conversationFetch.test.ts
  • src/lib/conversationRefresh.ts
  • src/lib/transport.test.ts
  • src/lib/transport.ts
  • src/lib/ws.test.ts
  • src/lib/ws.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying ovis with  Cloudflare Pages  Cloudflare Pages

Latest commit: ad0cbbc
Status: ✅  Deploy successful!
Preview URL: https://dc9145eb.ovis.pages.dev
Branch Preview URL: https://fix-reconnect-late-reply.ovis.pages.dev

View logs

…robe drop

A remote PC's socket going silent may be the server's own way to that PC: only its /api/machines/<id>/ reads are given up. This server's own socket going silent still gives up every read on the browser's way to it.
@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Review notes for this PR.

  • omo review: CLEAR at ad0cbbc.
  • Codex (adversarial, gpt-6.1-terra, xhigh) at ad0cbbc:
    1. MEDIUM, fixed in 1731371: each PC has its own socket, and a remote PC's probe drop gave up
      every read, including other PCs' healthy ones. Now this server's own socket going silent gives
      up every read (it is the browser's path to the server), and another PC's gives up only that
      PC's /api/machines/<id>/ reads. Test: src/lib/transport.test.ts "gives up only another
      PC's reads ...", which fails without the fix.
    2. MEDIUM, not changed: a read stops being tracked once its headers arrive, so a response whose
      body stalls after the headers on a lost connection is not given up. Reproduced only with a
      synthetic response; this server's API answers are small JSON bodies that come with their
      headers, and the measured stalls were all requests without an answer. Tracking bodies would
      mean wrapping every Response.
    3. LOW, not changed: on browsers without AbortSignal.any (Safari before 17.4) the fallback
      keeps one listener on a caller's signal per completed read until that signal is dropped.

Validation for the head after the fix (1731371, then a merge of origin/main touching only
app/electron): bun run check fast all ok (unit 11364 pass, 0 fail).

@devswha

devswha commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

Merge note: measured fix for replies showing late after a reconnect (ABBA 16 runs each: main 2.4-3.2 s typical with 29 s and 52 s outliers; this PR all <= 0.14 s). omo CLEAR at this head, Codex MEDIUM fixed with a failing-first test, required checks green. Fixes #2839.

@devswha
devswha merged commit cbcb961 into main Nov 5, 2026
15 of 16 checks passed
@devswha
devswha deleted the fix/reconnect-late-reply branch November 5, 2026 04:00
devswha added a commit that referenced this pull request Nov 5, 2026
…ry runs (needs owner OK) (#2857)

## Summary

GitHub's hosted queue for `ubuntu-24.04` is saturated (about 20
concurrent jobs on this plan) while most of the self-hosted
`self-hosted-ovis` runners sit idle, so jobs that run for seconds wait
minutes: `Detect changes` waited 373 s and 635 s before starting on two
recent PRs, and every other CI job waits on it.

This moves the light Linux jobs to the self-hosted pool for
same-repository runs:

- `ci.yml`: Detect changes, herdr-core live contract, the Integration
and browser summary
- `pr-title.yml`: Pull request title (Node only; the runner image has
Node 22)
- `remote-bundles.yml`: `bundle-windows` (Bun only)
- `pages.yml`: site build and deploy (push-to-main only; they already
accepted `CI_SELF_HOSTED_LABELS`)

Each uses one expression:

```yaml
runs-on: ${{ github.event.pull_request && github.event.pull_request.head.repo.full_name != github.repository && 'ubuntu-24.04' || fromJSON(vars.CI_LIGHT_LABELS || vars.CI_SELF_HOSTED_LABELS || '["self-hosted","self-hosted-ovis"]') }}
```

A fork pull request gets `ubuntu-24.04` before any variable is read (the
runner's job-started hook still refuses fork code as a second guard).
`CI_LIGHT_LABELS` (new, unset) or `CI_SELF_HOSTED_LABELS` set to
`"ubuntu-24.04"` keeps these jobs hosted, e.g. while the PC is offline.

Kept hosted on purpose: the Rust PTY host job and the Rust `bundle`
matrix (no Rust toolchain in the runner image), the `ssh` job (`sudo
apt-get` and Docker need a clean VM), `desktop.yml` builds,
Windows/macOS jobs, and release-only jobs.

`scripts/light-runner-workflow.test.ts` pins the rule: every job a pull
request runs (including reusable workflows it calls) must be
GitHub-hosted, the light expression with its fork guard, ci.yml's routed
Linux jobs (`scripts/ci-runner-route.sh`, already tested), or gated off
pull requests.

`scripts/ci-runner-route.sh` leaves these light jobs out of its busy
count (they hold a runner for seconds), and a push to main or a run from
main takes `CI_MAIN_SELF_HOSTED_LABELS` first, so main's Detect changes
never waits behind pull requests.

## Queue time (job created -> started)

Before (main, 2026-11-05 ~03:20-03:45 UTC, GitHub-hosted):

| PR | Job | Queued |
|---|---|---|
| #2842 | Detect changes | 373 s |
| #2848 | Detect changes | 635 s |
| #2842 | Pull request title | 301 s |
| #2848 | herdr-core live contract | 145 s |

After (this PR's two runs, self-hosted, 04:06 and 04:2x UTC, same
saturated hosted queue: its own Rust and hosted jobs still waited 115
s+):

| Run | Detect changes | Pull request title | herdr-core live contract |
bundle-windows |
|---|---|---|---|---|
| e8ceaa2 | 2 s | 3 s | 8 s | 3 s |
| 29c0a00 | 2 s | 3 s | 6 s | 2 s |

## Validation

- `bun run check fast` (workflow syntax via actionlint, typecheck,
build, unit tests: 11441 pass, 0 fail) at 29c0a00.
- `bun test ./scripts/light-runner-workflow.test.ts`: fails on
origin/main's workflows ("some job uses the light runner expression"),
passes here; removing the fork guard from `pr-title.yml` makes the
pr-title case fail.
- Skipped: `check full`, a real fork PR run.
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.

Chat shows a reply tens of seconds late after the connection is replaced

1 participant