chore(cloud-agent): track stream disconnects and report agent-server crashes#2461
Merged
Conversation
…crashes Make two previously-invisible cloud-run failures observable, without changing any UX. - Desktop client: emit a "Cloud stream disconnected" PostHog event whenever a cloud-run watcher gives up (failWatcher). Carries the error title and the three reconnect-budget counts, so an idle Envoy cut can be told apart from a real outage, and the event can be joined to run outcomes to see whether the underlying run survived. - Agent server: install uncaughtException / unhandledRejection handlers that mark the run failed (reportFatalError) before exiting. A hard crash was silent — the run stayed non-terminal and the desktop showed only a generic disconnect until the multi-hour inactivity timeout.
Contributor
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
packages/agent/src/server/bin.ts:193-201
**Crash handler can hang indefinitely before exiting**
`reportFatalError` makes two unbounded network calls (`updateTaskRun` and `eventStreamSender.stop()`). If the PostHog API is slow or unreachable at crash time (e.g., network partition during a container restart), neither call has a timeout, so `process.exit(1)` in the `finally` block would never be reached. This leaves the container alive and blocking pod shutdown. Consider wrapping the body in a `Promise.race` with a short deadline (e.g., 5 s) so the process always exits promptly after a fatal error.
Reviews (1): Last reviewed commit: "chore(cloud-agent): track stream disconn..." | Re-trigger Greptile |
reportFatalError makes two unbounded network calls; if the API is slow or unreachable at crash time, process.exit in the handler's finally would never run and the container would block pod shutdown. Race it against a 5s deadline so the process always exits promptly after a fatal error.
Contributor
|
Reviews (2): Last reviewed commit: "chore(cloud-agent): bound fatal-error re..." | Re-trigger Greptile |
joshsny
approved these changes
Jun 2, 2026
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.
Problem
We had instances of cloud-run failure invisible from the desktop app and from analytics:
Changes