Skip to content

Recover one-way-stale remote daemon connections - #2359

Merged
ymichael merged 1 commit into
mainfrom
bb/fix-worktree-model-picker-loading-thr_67snhz37mn
Aug 24, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/fix-worktree-model-picker-loading-thr_67snhz37mn

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

What was wrong

A remote host could lose only the server-to-daemon direction of its Connect-relayed WebSocket after sleep or a network transition while daemon-to-server heartbeats still arrived. The server therefore kept the host registered and sent host RPCs into a stale return path. Provider discovery amplified one unreachable host into two 30-second waves because four installed-only probes ran with concurrency three and each received a fresh command timeout. See #2358.

What changed

  • The server now acknowledges every daemon heartbeat, and the daemon tracks the last acknowledgement as end-to-end proof that it can still receive server messages.
  • If acknowledgements stop for longer than the session lease timeout, the daemon reconnects. A likely system-suspension timer gap resets the acknowledgement grace window so waking a laptop does not cause an immediate false reconnect.
  • Installed-only provider health probes now share one provider-listing deadline, preventing queued probes from starting another full timeout wave.
  • The server-to-daemon WebSocket contract now includes heartbeat-ack, and HOST_DAEMON_PROTOCOL_VERSION is bumped from 164 to 165 so enrolled hosts update atomically with the wire change.

How you verified

Added regression coverage that fails without the change:

  • contract parsing and strictness for heartbeat-ack
  • server heartbeat acknowledgement emission
  • daemon reconnect after acknowledgements stop, plus sleep/wake grace
  • one shared timeout across four installed-only provider probes

Commands run after rebasing onto current main:

pnpm exec turbo run test --filter=@bb/host-daemon-contract --force -- test/contract.test.ts
pnpm exec turbo run test --filter=@bb/host-daemon --force -- src/server-connection.test.ts
pnpm exec turbo run test --filter=@bb/server --force -- test/internal/internal-environment-change.test.ts test/system/execution-options.test.ts
pnpm exec turbo run typecheck --filter=@bb/host-daemon-contract --filter=@bb/host-daemon --filter=@bb/server

All 94 focused tests passed, and all three affected packages typechecked.

Fixes #2358

AGENT GENERATED

@ymichael
ymichael merged commit 5eb19fa into main Aug 24, 2026
15 checks passed
@ymichael
ymichael deleted the bb/fix-worktree-model-picker-loading-thr_67snhz37mn branch August 24, 2026 22:57
ymichael added a commit that referenced this pull request Aug 25, 2026
## What was wrong

Heartbeat acknowledgement expiry was coupled to the older 60-second
system-suspension log heuristic. With the landed 5-second heartbeat and
30-second acknowledgement lease, a heartbeat callback delayed for
roughly 31–64 seconds saw the acknowledgement as expired before the
delay qualified for suspension grace, so waking a healthy host forced an
unnecessary `heartbeat-ack-timeout` reconnect. This is a follow-up to
[PR #2359](#2359).

## What changed

- Grant one fresh acknowledgement lease whenever the heartbeat timer gap
itself exceeds the lease, independently of how the gap is classified for
logging.
- Keep the existing sub-minute heartbeat-delay warning and 60-second
likely-suspension info classification unchanged.
- Add regression coverage proving a 35-second gap does not reconnect
immediately and that a genuinely dead return path still reconnects after
the fresh lease expires.

There are no wire-contract changes, so `HOST_DAEMON_PROTOCOL_VERSION`
remains unchanged.

## How you verified

The new regression failed before the production change with an immediate
`(1013, "heartbeat-ack-timeout")` reconnect and passed afterward.

```sh
pnpm exec turbo run test --filter=@bb/host-daemon --force --concurrency=1 -- src/server-connection.test.ts
pnpm exec turbo run typecheck --filter=@bb/host-daemon --force --concurrency=1
pnpm exec turbo run test --filter=@bb/host-daemon --force --concurrency=1
pnpm exec turbo run build --filter=@bb/host-daemon --force --concurrency=1
pnpm exec oxfmt apps/host-daemon/src/server-connection.ts apps/host-daemon/src/server-connection.test.ts --check
```

- Focused current-`main` result: 13 tests passed; 7/7 Turbo tasks
successful.
- Host-daemon typecheck: 4/4 Turbo tasks successful.
- Full host-daemon suite: 45 files and 555 tests passed; 7/7 Turbo tasks
successful.
- Host-daemon build: 5/5 Turbo tasks successful.

Follow-up to #2358 and #2359.

> AGENT GENERATED
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.

Remote host can remain connected with a one-way-stale daemon WebSocket

1 participant