Repository navigation
Recover a wedged gRPC channel in place instead of hanging until app restart (#1672) - #1880
Conversation
…estart (#1672) The desktop app rides every service client and long-lived stream on a single shared h2 channel. A stream churn during a heavy sync can wedge that connection: reads/writes and streams hang forever (the lazy channel has no client-side timeout) even though the daemon socket stays healthy — a freshly-dialed client answers fine. The socket-based daemon-status check therefore keeps reporting "healthy", onDaemonReconnect never fires, and the journal stays stuck on "Loading…"; only a full app restart (fresh channel) recovered it. Recover in place, the way a restart would, across every surface on the channel: - GrpcClient::reconnect() rebuilds the lazy channel and every service client from scratch, preserving the active-database routing AND this window's client_id (echo suppression is scoped by it), and bumps db_generation so the node-event watcher re-opens its WatchNodes stream on the fresh channel. - probe_and_recover_channel runs one lightweight RPC bounded by a short timeout: any completion (incl NotFound) proves the channel is live; a timeout means it is wedged, so it calls reconnect() and re-probes. - The daemon-status steady-state poll calls the probe after a healthy status and, when the channel had to be rebuilt, re-fires the reconnect listeners so panes re-fetch — applyStatus won't, since the daemon never left "healthy". - The ai-chat token stream now selects on db_generation (biased), mirroring the watcher, so a rebuild drops its wedged stream and it re-subscribes on the fresh channel instead of hanging forever. - ProClient::rebind() points the cached Pro cloud-sync client at the rebuilt channel, so unary cloud-sync calls stop riding the dead connection. The Pro live-status WatchSyncStatus forwarding task still needs coordinated respawn on recovery — tracked in #1879. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
APPROVE (self-review, author=reviewer per merge policy). Adversarial review of the first cut CONFIRMED the core mechanics — lock discipline (no lock held across the probe/reconnect awaits), watcher re-subscription on the new channel (swap_channel installs new clients before bumping
Remaining coordinated piece (Pro live-status |
Summary
Recovers a wedged gRPC channel in place instead of hanging until the user restarts the app — the mechanism behind the reopened #1672 (Daily Journal stuck on "Loading…" forever).
The desktop app rides every service client and the
WatchNodesstream on a single shared h2 channel. A stream churn during heavy sync can wedge that connection: reads/writes and the stream hang indefinitely (the lazy channel has no client-side timeout) even though the daemon socket stays healthy — a freshly-dialed client answers fine. So the socket-basedcheck_daemon_statuskeeps reportinghealthy,onDaemonReconnectnever fires, and panes stay stuck. Only a full app restart (fresh channel) recovered it.What changed
Recover every surface on the shared channel, the way a restart would:
GrpcClient::reconnect()+swap_channel()(services/grpc_client.rs) — rebuild the lazy channel and every service client from scratch, preserving the active-database routing and this window'sclient_id(echo suppression is scoped by it — a fresh id would make our own writes re-appear as remote changes), then bumpdb_generationso the node-event watcher re-opens itsWatchNodesstream on the fresh channel.probe_and_recover_channelcommand (commands/nodes.rs) — one lightweightget_nodebounded by a 5 s timeout: any completion (incl.NotFound) proves the channel is live →false; a timeout means it is wedged →reconnect()+ re-probe →trueonly if the rebuilt channel answers.daemon-status.ts) — after ahealthystatus, probe the real channel; if it had to be rebuilt, re-fire the reconnect listeners so panes re-fetch (applyStatuswon't — the daemon never lefthealthy).commands/local_agent.rs) — nowselect!s ondb_generation(biased), mirroring the node watcher, so a rebuild drops its wedged stream and it re-subscribes on the fresh channel instead of hanging forever.ProClient::rebind()(services/pro_client.rs, called from the probe) — points the cached Pro cloud-sync client at the rebuilt channel so unary cloud-sync calls stop riding the dead connection.Adversarial review
An adversarial review of the first cut confirmed the core mechanics (lock discipline, watcher re-subscription,
client_idpreservation) and caught that the Pro cloud-sync and ai-chat surfaces were left on the dead channel — addressed above. The Pro live-statusWatchSyncStatusstream still needs coordinated respawn-on-recovery (task interruption +STREAM_SPAWNEDreset + frontendonDaemonReconnectre-subscribe); tracked as a focused follow-up in #1879.Testing
bun run testdaemon-status suite: 17/17, including a new test that drives the steady-state poll into a wedged channel and asserts it rebuilds + re-firesonDaemonReconnect.test:all(frontend + skill + Rust) +cargo build --bin nodespaced+test:e2e(headless daemon round-trip) +cargo test -p nodespace-app(Tauri-seam, ADR-048).cargo build -p nodespace-appclean; the token-stream and Pro-rebind additions follow the node watcher's provendb_generationinterruption pattern.NotFoundimmediately → no-op).Closes #1672.
Co-Authored-By: Claude Opus 4.8 [email protected]