Repository navigation
fix(chat): show a reply at once after a silent reconnect - #2848
Conversation
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.
|
Warning Review limit reachedYou'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. View limit details
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. |
Deploying ovis with
|
| Latest commit: |
ad0cbbc
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://dc9145eb.ovis.pages.dev |
| Branch Preview URL: | https://fix-reconnect-late-reply.ovis.pages.dev |
…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.
|
Review notes for this PR.
Validation for the head after the fix (1731371, then a merge of origin/main touching only |
|
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. |
…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.
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-changedpush 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:
omo tasks, health and machine checks. Each went out on a connection that never answers again.
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.
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 (thesilent-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 requestsopen 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 abortstill 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 flightinstead of queueing behind it.
ChatViewtreats a read given up this way as no failure (no errorflash, 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):
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 anda caller's own abort behave as before.
src/lib/ws.test.ts: a connection dropped for an unanswered probe gives up the reads in flightwhen 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 reconnectand reads again at once.
Each failed before the change (missing export / no abort /
restart is not a function).Validation
bun run check fastat 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.touch the relay transport's requests.
Fixes #2839.