Repository navigation
Mark silent hosts offline without cancelling their work - #4271
Merged
Merged
Conversation
ymichael
marked this pull request as draft
September 24, 2026 20:40
ymichael
marked this pull request as ready for review
September 25, 2026 03:11
ymichael
force-pushed
the
bb/close-silent-daemon-sockets
branch
3 times, most recently
from
September 25, 2026 18:32
0c68caf to
8413eaf
Compare
ymichael
force-pushed
the
bb/close-silent-daemon-sockets
branch
from
September 26, 2026 03:56
8413eaf to
437b766
Compare
A host whose machine slept with its daemon socket half-open stayed "connected" indefinitely: liveness came only from the hub's socket registration, so the server kept routing commands to it and each one waited out the 30s command timeout. The server now counts consecutive heartbeat-interval checks with no daemon message per connection and, after a lease's worth, sends the existing session-close "expired", closes the socket, and runs the normal socket-loss side effects with close reason "expired". Counting missed checks rather than comparing wall-clock times keeps the server's own sleep from expiring every host at once. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…work With silent daemons now closed after the lease timeout, every sleeping laptop took the disconnect path, whose timers cancelled pending questions and settled background tasks after 5s and interrupted running turns and workspace setup after 30s, while the machine's work was merely suspended. A disconnect now only marks the host offline. The one remaining timer tells clients when the thread moves from host-reconnecting to waiting-for-host. The reconnect settles the work as it already did: the same daemon instance reconciles its reported threads and a restarted one interrupts everything. Imported server-move sessions still settle their hosts' work at boot. Answering an interaction while its host is offline now fails with host_unavailable and leaves it pending, instead of marking it resolving and losing the answer. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Host status mirrored whether a daemon socket was registered, so every brief tunnel drop showed the host as disconnected and put "<host> disconnected. Waiting for reconnection..." on its running threads, even when the daemon was back two seconds later. With the previous commit a drop no longer costs any work, so there is nothing to warn about. A socket that closes on its own now leaves the host shown connected and its threads active for HOST_OFFLINE_DISPLAY_DELAY_MS (10s). After that, clients get host-disconnected and host-reconnecting, then waiting-for-host once the reconnect grace ends, as before. A session the server ends itself (a silent daemon, a removed host) is shown offline immediately. Commands still fail at once with host_unavailable while no socket is registered. The display reads the host's most recently closed session instead of its latest session, so a daemon that has opened its new session but not yet registered its socket no longer flashes waiting-for-host. Machine provider responses now use the same host mapping as every other host response. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The previous commit hid a dropped connection for 10s, then showed "<host> disconnected. Waiting for reconnection..." until the 30s reconnect grace ended, while a silent daemon was shown offline after its 30s lease. Two windows for one question made the display hard to predict. There is now one rule: a host is shown offline once the server has gone HOST_RECONNECT_GRACE_MS (30s) without contact. A connection that closes on its own leaves the host connected and its threads active for the whole grace, then clients get host-disconnected and waiting-for-host. A session the server ends itself has already been silent for a lease, so it is shown offline immediately. The server no longer produces the host-reconnecting display status. The recovery integration tests wait up to 60s for a crashed host to show offline. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Since the previous commit hides a dropped connection for the whole reconnect grace, the server never reports host-reconnecting, and the "<host> disconnected. Waiting for reconnection..." banner, its spinner label and its follow-up placeholders were unreachable. Remove the value from ThreadRuntimeDisplayStatus, along with the hostReconnectGraceExpiresAt field no client read, and every branch that handled them in the app, client-core and the thread-list plugin. The host connection notice only ever shows "<host> disconnected" now, so it loses its tone. The web UI is always served by the server it talks to, the mobile app does not read display statuses, and realtime status snapshots that fail validation are dropped, so no deployed client breaks. The PluginSidebarThread.runtimeStatus doc no longer lists the value; plugin SDK 0.5.27. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Every reconnect, however short, killed a remote host's terminals: the disconnect cleared their owning session, and the new socket's open marked them exited and sent terminal.close. The daemon keeps its terminals and their scrollback across a dropped connection, so only a restarted daemon has actually lost them. A running terminal now keeps its owning daemon session when it disconnects. When a socket opens, disconnected terminals owned by the same daemon instance are moved onto the new session and marked running; the rest expire as before. A terminal that was still starting keeps the old behaviour, since its open was already rejected. Browsers stay attached through the drop but miss the output produced during it. The server records how far it has forwarded each terminal's output, asks the daemon to replay from there after reattaching, and holds live output until that replay arrives, so browsers see one continuous stream instead of a gap that resets the terminal. The daemon now buffers terminal.exited across a disconnect like other recoverable messages, so a terminal that ends during a drop is reported once the socket reopens rather than being reattached as running. The server relies on that delivery, so HOST_DAEMON_PROTOCOL_VERSION goes to 219. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Server-to-daemon calls failed the moment no daemon socket was registered, so a 1-3s tunnel drop failed every call made during it, and a stop the server re-sent while reconciling a reconnect was lost: the session open runs before the new socket registers, so the command found no socket. Before sending, every online host RPC (callHostOnlineRpc, the ForWork and retryable variants, and plugin host calls through them) now waits up to HOST_DAEMON_RECONNECT_WAIT_MS (5s) for the host's daemon when a reconnect is plausibly under way: the host is active and its newest session is either open but not yet on a socket (within its lease) or was closed by its socket dropping within the reconnect grace. Waiting before the first send is safe for every command because nothing has reached the daemon. Calls still fail fast for hosts that are not coming back soon: a session the server expired for silence, one closed long ago, or a machine that is suspended or being removed. A request whose socket drops after it was sent is still retried only for the idempotent retryable commands. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Stopping a thread whose host was offline left it `stopping` until the daemon returned, and forever if it never did, while the CLI reported it stopped. With no timed cap on lost hosts, stop has to be the way to end that work. A stop the host cannot receive (host_unavailable) now settles the thread on the server the way an unknown environment already did: the active turn is marked interrupted, pending interactions and background tasks are settled, and the thread goes idle. When the same daemon instance later reconnects still running that thread, the server no longer revives it. A thread whose latest run marker is a manual-stop interruption, with no turn started since, is sent the stop instead. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The daemon's reconnect ladder (1s base, x2 growth, 30s cap) tried at roughly 1, 3, 7, 15, 31 and 61s after a drop. Tunnel outages on this instance cluster at 20-27s, so the retry after one of them landed at ~31s: just past the 30s window in which the server still shows the host connected and host calls wait for it, so every such blip surfaced as the host going offline. A 10s cap makes the ladder ~1, 3, 7, 15, 25, 35s, so a daemon back within that window reconnects inside it. The daemon's heartbeat already reconnects after 30s without acknowledgements; this only shortens the wait between attempts. No wire change. Taken from the Modal mid-turn disconnect investigation (thr_dpm2srz4rk); its grace-period change is superseded by this PR's reconnect-decides rule. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Since a disconnect no longer interrupts running threads, a thread whose host drops now shows "<host> disconnected" and keeps running. The server pushed that status change when the host dropped, but nothing when its daemon reconnected, so an open thread page kept the red notice and the "Host disconnected" composer placeholder until it was reloaded, even though the thread was running normally again. When a daemon socket opens, the server now publishes the host's thread runtime status the same way it does on disconnect. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A browser that opened a terminal while its host was disconnected, or re-attached right after a server restart before the daemon re-registered, got "Terminal session is not running" or "Host is not connected" and was dropped as a client. When the daemon came back a moment later and the terminal was reattached, that browser was no longer subscribed, so it showed a dead terminal until the page was reloaded. Such a browser now stays registered: it gets an attached message at the position it asked for, sees the terminal as disconnected, and receives the reattach and the replay of missed output like a browser that was already attached when the connection dropped. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A browser that typed or resized a disconnected terminal got terminal_not_running, and the app treats that code as the terminal having ended, so it stopped reconnecting its socket for good. Disconnected terminals now come back when their daemon reconnects, so input and resize for one are dropped quietly instead; terminals that are starting or exited still get the error. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The terminal panel treated a disconnected terminal as dead. It hid its tab unless it was the one on screen, force-closed every other disconnected terminal whenever the panel was open, and offered a "Start new terminal" replacement that closed it first. That predates terminals surviving a reconnect: now a disconnected terminal is reattached when the same daemon comes back, and the server already expires the ones a restarted daemon lost. So loading a thread page during an outage, or any second terminal tab during a brief drop, closed live terminals and left their processes orphaned on the host. A disconnected terminal is now shown like a running one: its tab stays, its view shows "Terminal disconnected" and resumes on reattach, and nothing closes it except the user. This removes the retained-terminal tracking, the disconnected and clean auto-close effects, and the replacement flow, which only served dead terminals. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…n online A host is shown connected for 30s after its socket closes, and the send path read that displayed status to decide whether to queue a message on a host-offline wait. A follow-up sent during that window skipped the queue, tried to dispatch, and returned "Host is not connected" to the sender, so the message was lost unless they sent it again; a queued message whose drain failed in that window spent a retry instead of waiting for the host. Both decisions now use whether a daemon socket is registered, so a message sent during a drop queues and goes out as soon as the daemon reconnects. The host's displayed status is unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Host status told every consumer a host was connected for 30s after its daemon socket dropped. That was meant for display, but the same field drives decisions on the server, in the CLI, in plugins and in the app, so code acting on it treated a dropped host as reachable: sends skipped the offline queue, and "has it reconnected?" checks in `bb machine reconnect` and the app's reconnect dialog passed before the daemon was back. Host status is again the live daemon connection, as on main. The only thing that waits out a brief drop is a running thread's "<host> disconnected" notice, which keeps its own server-side reconnect grace. Closing a session no longer stamps lastSeenAt, so "last seen" is the daemon's last message rather than the moment the server noticed. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
When a daemon reconnected, the server interrupted every active thread the
daemon no longer reported as running ("Thread interrupted because the
connection to the host was lost"). A turn that finished during the outage
was in that set: its final events were still queued on the daemon, which
only delivers them once the new session is open. They arrived a moment
later, the thread was already in error, the turn's success was rejected and
the agent's final reply never showed.
The daemon now reports, when it opens a session, which threads it still
holds undelivered events for. The server leaves those threads running, and
the held events that follow settle the turn the normal way.
Wire change: session open gains undeliveredEventThreadIds (defaults to
none). The protocol version is already 220 on this branch.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
With "Enter steers the active thread" on (the default), Enter sends the draft as a steer, and the composer disabled that path unless the thread was active, provisioning or starting. Once a host had been gone for 30s and its thread showed waiting-for-host, the send button went grey and Cmd+Enter did nothing, so nothing could be typed ahead. A draft can now be sent while the thread waits for its host. The server already queues a steer for a host whose daemon is not connected and steers it in on reconnect. Sending an already-queued message immediately stays disabled while the host is away. The placeholder said only "Host disconnected", which read as a dead end; it now says "Queue a message for when the host reconnects". With the stale status after reconnect fixed earlier on this branch, this fixes #4353. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ymichael
force-pushed
the
bb/close-silent-daemon-sockets
branch
from
September 26, 2026 04:37
7ff9af5 to
ccfcecd
Compare
This was referenced Sep 28, 2026
ymichael
added a commit
that referenced
this pull request
Sep 28, 2026
…4456) ## Human comments ## What was wrong Answering an approval, plan review or question while the thread's host is offline fails with `host_unavailable`, and the card shows "Failed to submit response. Host is offline." That message is the React Query mutation's last error (`useResolveThreadPendingInteraction`), which only changes on the next submit. So after the host reconnected, the card kept saying the host was offline even though the interaction could be answered again. Since #4271 an interaction survives a host outage instead of being cancelled, so this stale message is now the normal path after answering during a drop. ## What changed - `apps/app/src/hooks/mutations/thread-interaction-mutations.ts`: `useResolveThreadPendingInteraction(threadId)` looks up the thread's host (thread → environment → host list, all cached queries the thread view already uses) and hides a host-offline error once that host shows connected. Any other error, or a new attempt that fails, is shown as before. - `apps/app/src/lib/lifecycle-errors.ts`: `isHostDisconnectedError` recognises the `host_unavailable` / `disconnected` API error. - Callers pass their `threadId`: the approval and plan-review card (`ThreadPendingInteractionBanner.tsx`) and the question form (`UserQuestionInteractionContent.tsx`), which all use this one hook. No wire, CLI or server change. ## How you verified - New `thread-interaction-mutations.test.tsx`: an answer fails with the host-offline error while the thread's host is disconnected; once the host list shows it connected the error is gone. It fails without the change (`expected HttpError: HTTP 502: Host is not connected … to be null`). - `pnpm exec turbo run typecheck lint test --filter=...[origin/main]`. - Same scripted flow on `main` (`1efad32226`): after reconnecting, the card still said "Host is offline." until the next click. - Live on `pnpm start:worktree` at this head, with a real Codex approval on a disposable second host reached through a TCP proxy: "Allow once" while the host was offline showed the error; 5s after reconnecting the error was gone and the button still there; "Allow once" again ran the command and the agent replied `approved-done`. Plan reviews and questions share the code path and the unit test, but were not driven live. > AGENT GENERATED Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
gpambrozio
added a commit
to gpambrozio/bb-menubar
that referenced
this pull request
Nov 13, 2026
…an offline machine (#4) * fix(pairing): point machine codes at Settings → Mobile bb 0.45 (get-bb/bb#4513) removed the `mobileApp` experiment and moved "Add mobile device" from Settings → Remote access to Settings → Mobile. The pairing window and the README still told the user to run `bb settings experiment mobileApp true`, which bb 0.49 rejects with "Unknown experiment 'mobileApp'". Keep the plain `bb connect machine-code` and amend the remote design's quoted copy to match. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(core): re-pin to bb 0.49.0 and mark threads waiting on an offline machine Since bb 0.45 (get-bb/bb#4271) a thread whose machine goes offline keeps `status: "active"` until it reconnects, and bb reports `runtime.displayStatus: "waiting-for-host"` for it. bb Icon read only `status`, so a turn on a sleeping laptop spun the Working glyph all night while bb itself showed nothing running. - Decode `runtime.displayStatus` leniently: absent or unknown changes nothing. - Such a thread stays in Working (it resumes when the machine is back), and its row says `machine offline`. - It no longer draws the Working glyph by itself. Following bb 0.49.0's `RUNNING_RUNTIME_STATUSES`, `waiting-for-host` is not running, while background activity still is. Working draws the glyph only while one of its threads, past the cap included, runs now. - Drop `activity.activeGoalCount`, which bb 0.49 removed (get-bb/bb#6613). - Bring the thread page and the one thread-carrying /ws frame to 0.49.0's shape, checked against this Mac's bb 0.49.0 with GET requests only. - Move the "pinned to bb 0.44.0" citations to 0.49.0 where 0.49.0 was checked, and amend the design spec's bucket rule 4, icon rule, and menu rows. Co-Authored-By: Claude Opus 5.5 <[email protected]> * chore(release): 0.2.0 Bump the version (package.json feeds the bundle's CFBundleShortVersionString and CFBundleVersion), date the changelog entry, and point the README's download and AGENTS.md's release note at v0.2.0. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: marvin-ambrozio <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
Since #421 the server takes a host's liveness from whether the hub has a daemon socket registered. Nothing acted on a connection that stayed open while the daemon went silent. When a laptop host slept, its socket could stay half-open, so the server kept reporting the host
connectedand kept sending it work, and each command waited out the full 30scommand_timeout. On 2026-09-23 M5 (host_stzudmkj6u) went to sleep at 20:10:44 (pmset -g log). Its sessionhses_e4xcqe579wstayedactivewith a lease that expired at 20:11:14,bb host liststill showed itconnected, 12m agoat 20:22, and thread provisioning on it failed withTimed out waiting for command result.Simply closing silent sockets would have exposed a second problem. Every disconnect ran timers that settled the lost host's work: after 5s they cancelled pending approvals/questions and marked background tasks finished, and after 30s they interrupted running turns and workspace setup. A sleeping laptop's work is only suspended, so every lid-close would have errored its turns and permanently thrown away its open questions.
What changed
1. Silent daemons are closed (
ws/hub.ts,ws/daemon-protocol.ts,start-server.ts). Every incoming daemon frame marks the connection as heard from. A check runs once per heartbeat interval (5s) and closes a connection afterLEASE_TIMEOUT_MS / HEARTBEAT_INTERVAL_MS= 6 quiet checks in a row, which is 30–35s after the daemon's last message. It sends the existingsession-closeexpired(daemons already reconnect on it), closes the socket, and records close reasonexpired. It counts missed checks rather than comparing wall-clock times, so the server's own sleep counts as at most one quiet check, which avoids #421's problem where every host was dropped at once after the server woke.2. A disconnect no longer settles work; the reconnect does (
internal/session-owner-side-effects.ts). On any disconnect (socket close or lease expiry) the host goes offline and nothing is cancelled or interrupted on a timer; the 5s and 30s disconnect timers are removed. The reconnect decides what happens to the work, as it already did:reconcileDaemonReportedThreadscarries on with the threads the daemon still reports, and interrupts those it doesn't (host-connection-lost).handleHostSessionOpenedinterrupts turns, pending interactions, background tasks and workspace setup, unchanged.The imported sessions of an experimental server move still settle their hosts' work at boot, as before (
settleLostHostWork).2b. Display: only the thread notice waits, no
host-reconnecting(949d7760b0,5e3b305bff,1b97f8224e,8632254074). A host'sstatuseverywhere (API, CLI, SDK, machine labels, pickers, thread info panel) is its real connection. The one thing that waits out a brief drop is a running thread's " disconnected" notice (waiting-for-host), shown only once a socket has been closed forHOST_RECONNECT_GRACE_MS(30s); a session the server ended itself (silent daemon, removed host) shows it immediately.closeSessionno longer stampslastSeenAt, so "last seen" is the last time the daemon was actually heard from. The unreachablehost-reconnectingdisplay status and thehostReconnectGraceExpiresAtfield are removed from the domain, SDK, client-core, app and thread-list plugin (plugin SDK version bumped).3. Answering a question whose host is offline fails up front (
services/interactions/pending-interactions.ts). Before, the answer marked the interactionresolvingand was sent once; that send failed and the answer was never re-sent, so the agent stayed blocked. Now the request fails with502 host_unavailable("Host is not connected") and the question stayspending, so it can be answered once the host is back.4. Remote terminals survive a same-instance reconnect (
683d232a2a). A running terminal keeps its owning daemon session when the socket drops. When a socket opens, disconnected terminals owned by the same daemon instance move onto the new session and go back torunning; a restarted daemon's terminals, and terminals that were still starting, expire as before. The server records how far it has forwarded each terminal's output, asks the daemon to replay from there after reattaching, and holds live output until the replay arrives, so browsers see one continuous stream. The daemon now buffersterminal.exitedacross a disconnect so an exit during the drop is still reported. Wire change:HOST_DAEMON_PROTOCOL_VERSION219 → 220.5. Host calls wait briefly for a reconnecting daemon (
b2b97cdbce,services/hosts/online-rpc.ts). Before sending, every online host RPC (including plugin host calls) waits up to 5s for the host's daemon when a reconnect is plausibly under way: the host isactiveand its newest session is either open but not yet on a socket (within its lease) or was closed by its socket dropping within the reconnect grace. Nothing has reached the daemon before the wait, so it is safe for every command. Silent-expired, long-gone, suspended or removing hosts still fail fast. Requests whose socket drops after sending are still retried only for idempotent commands. This also fixes the stop the server re-sends during/internal/session/open, which used to run before the new socket registered.6. Stop settles immediately when the host is offline (
8467cb0bd3,threads/thread-lifecycle.ts). A stop the host can't receive (host_unavailable) now settles the thread on the server the wayunknown_environmentalready did: the active turn is interrupted, pending interactions and background tasks are settled, and the thread goes idle. If the same daemon later reconnects still running that thread, the server sends it the stop instead of reviving it; that applies to a thread whose latest run marker is a manual-stop interruption with no turn started since (listThreadIdsStoppedSinceLastTurnStart).7. Daemon reconnect backoff capped at 10s (
d8c367fd25,apps/host-daemon/src/server-connection-support.ts). The ladder was ~1, 3, 7, 15, 31, 61s, so after a tunnel outage of 20–27s (where outages on this instance cluster) the next attempt landed just past the 30s reconnect grace, so running threads showed " disconnected" and host calls stopped waiting for it. With a 10s cap it is ~1, 3, 7, 15, 25, 35s. Taken from the Modal mid-turn disconnect investigation; that investigation's 90s interruption grace is superseded by item 2. No test: it is a single constant whose target (the server's 30s window) the daemon cannot import.8. Bugs found by end-to-end QA against a
pnpm start:worktreeserver (a disposable daemon reached through a TCP proxy that can drop or black-hole its connection):0685d228d5: an open thread page kept the " disconnected" notice after the host came back, until reload. The server now publishes the host's thread status when a daemon socket opens, not only when it closes.14df3f2653: a browser that attached a terminal while its host was reconnecting (after a server restart, or opening the page during an outage) was dropped as a client and showed a dead terminal. It now stays registered and gets the reattach and the replay of missed output.4bd5fafb86: typing in or resizing a disconnected terminal returnedterminal_not_running, which the app treats as the terminal ending, so it stopped reconnecting. Those inputs are now dropped quietly while the host is away.eb01a96829(app): the terminal panel force-closed disconnected terminals that weren't on screen, hid their tabs, and offered a "Start new terminal" replacement that closed them first. Loading a page during an outage, or any second terminal tab during a brief drop, killed live terminals and orphaned their processes on the host. Disconnected terminals are now shown and kept until their host returns; the retained-terminal tracking, auto-close effects and replacement flow are removed.5deced4c62: earlier on this branch a host was reported connected for 30s after its socket closed, and the send path read that status to decide whether to queue onhost-offline. A follow-up sent during that window returnedHTTP 502: Host is not connectedinstead of queueing (reproduced live 8s into a drop). Sends and queued-message drain failures now decide by whether a daemon socket is registered, so a message sent during a drop queues and goes out on reconnect.8632254074: the same mistake applied anywhere that readhost.statusto decide what to do, e.g. the CLI's and app's reconnect checks, which believed a dropped host was still connected for 30s. The server now reports the real connection everywhere; only the thread notice waits (item 2b).9. A turn that finishes while its host is away completes normally (
376defc50f). When a daemon reconnected, the server interrupted every active thread it no longer reported as running. A turn that finished during the outage was in that set: its final events were still queued on the daemon, which only delivers them once the new session is open, so they arrived after the thread had been set toerror("Thread interrupted because the connection to the host was lost"); the turn's success was rejected and the agent's final reply was lost. Session open now carriesundeliveredEventThreadIds, the threads the daemon still holds events for; the server leaves those running and the held events settle the turn as usual. Wire change (same unreleased 220 bump as item 4).10. The composer can send while its thread waits for the host (
ccfcecdff6, client-core). With "Enter steers the active thread" on (the default), Enter sends the draft as a steer, and the composer only allowed that foractive/provisioning/starting. Once a host had been gone for 30s and the thread showedwaiting-for-host, the send button went grey and Cmd+Enter did nothing. A draft can now be sent then; the server queues it (delivery: queued, item 8) and steers it in on reconnect. Sending an already-queued message immediately stays disabled while the host is away. The placeholder, which only said "Host disconnected", now says "Queue a message for when the host reconnects".Items 1–3, 5–8 and 10 change no wire contract; items 4 and 9 share the protocol bump.
Reviewer attention
active/ " disconnected" until someone stops them; there is deliberately no timed cap. Stop now settles them immediately (item 6), and removing the machine settles everything on it.How you verified
Tests (each new or changed test fails with its fix removed):
test/hosts/daemon-liveness.test.ts(new): a silent daemon is still connected at 30s and closed at 35s (session-closeexpired, close1000 expired, sessionclosed/expired, a later realonCloseis a no-op); a daemon sending one message every 25s stays connected.test/public/public-thread-interactions.test.ts: a pending approval survives a 10-minute disconnect; answering while offline returns 502host_unavailableand leaves itpending; answering after reconnect givesresolving.test/internal/session-owner-runtime-status.test.ts: a closed socket stays hidden until the reconnect grace ends, then clients getwaiting-for-hostwhile the thread staysactive; a daemon that reconnects within the grace never shows a disconnect.test/internal/background-task-reconciliation.test.ts,test/threads/thread-provisioning-recovery.test.ts: background tasks, running turns and workspace setup are untouched after a 10-minute disconnect. The existing tests for same-instance vs restarted-instance reconnect still pass.test/services/threads/thread-runtime-display.test.ts: an active thread staysactivewhile its host's closed socket is within the grace or its reconnecting daemon hasn't registered yet; a server-expired (silent) session showswaiting-for-hostat once.test/public/public-terminals.test.ts: a same-instance reconnect reattaches the terminal, sends noterminal.close, asks for a replay from the forwarded position and holds live output until it arrives (browser sees 0,1,2,3,4); a restarted instance still expires terminals.apps/host-daemon/src/server-connection.test.ts: aterminal.exitedsent while disconnected is delivered after reconnect.test/internal/background-task-reconciliation.test.ts: a same-instance reconnect that reports a thread inundeliveredEventThreadIdsleaves itactive, and the helditem/completed+turn/completedthen settle itidle(fails without item 9:error).event-sink.test.ts: held events report their threads until delivered.test/hosts/online-rpc.test.ts: an RPC waits for a daemon reconnecting after its socket dropped; a silent-expired host fails without waiting.test/internal/background-task-reconciliation.test.ts: a stop while offline settles the thread idle with the turn interrupted, and a same-instance reconnect sends the daemonthread.stopinstead of reviving; a thread that started a new turn after its last stop is still revived.origin/mainf3b2460b81. Latest full run on this headccfcecdff6(turbo typecheck lint test --filter=...[origin/main]): typecheck and lint clean; tests all pass (@bb/server3281,@bb/app5120,@bb/host-daemon734,@bb/db583,@bb/client-core281, integration 79) except load flakes that pass when their file is run alone (install-machine-script"restarts its own running daemon…",plugin-native-server-loading×2, host-daemonworkspace-path-list"does not overflow the call stack…",CommandPalette"opens only the selected result in a split…", agent-runtimeruntime.acp-topology).Live QA (scenarios run on
8632254074before the last rebase; the held-events row re-run on376defc50f): an isolatedpnpm start:worktreeinstance (its own data dir), plus a disposable second daemon (host_vmi9qdpe65) that reaches the server through a TCP proxy, so its connection can be dropped (proxy down) or left open but silent (SIGSTOP). The base column comes from the earlier runs on4277998ed7.connectedindefinitely; commands hang ~62sHost is not connected; Online again right after resumedonedelivery: queued, goes out on reconnect and gets its reply; the turn finishesstopping; agent keeps running after reconnectidleimmediately; on reconnect the daemon stops the turn (sleepprocess gone) and the thread stays stoppedpending; answering offline → 502 and stillpending; answering after reconnect → resolved, the command ranerrorand lost the final reply; with item 9 (376defc50f):idleright after reconnect with the reply "done" shown, no rejected eventsFixes #4364: its interruption (
system/thread/interrupted reason=host-daemon-restarted cause=host-connection-lostafter a heartbeat-ack drop) is main's 30s disconnect timer, removed by item 2; a turn that ends during such a drop is covered by item 9. Why that host's heartbeat acknowledgements stopped is not addressed here.Fixes #4353, both of its defects: the composer disabled while the host is away (item 10;
host-reconnectingis also gone, item 2b), and the status that stayed stale after a reconnect (0685d228d5, item 8). Verified live: 36s into an outage the send button was enabled ("Steer current run (Enter), ⌘ Enter to queue"), Enter queued the draft ("Waiting for Manual machine qdpe65 to be ready"), and after reconnect it was steered in and answered.Supersedes #3613, which clears the connection error after a turn completes during a disconnect. Here the error is never raised: the timer is gone (item 2) and the reconnect waits for the daemon's held events (item 9).
Related: #421, #2358 (the opposite direction: daemon heartbeating while server-to-daemon commands failed, fixed with a daemon-side watchdog).