feat(cloud-agent): add PostHog tracking for remote session events#1767
Merged
feat(cloud-agent): add PostHog tracking for remote session events#1767
Conversation
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (3 files)
Reviewed by gpt-5.4-20260305 · 1,962,217 tokens |
433f22f to
700e5ef
Compare
jeanduplessis
approved these changes
Mar 31, 2026
Add onResolved callback to CloudAgentSession that fires after transport
resolution, giving the session manager access to the authoritative
ResolvedSession. Use this to track an ActiveSessionType ('cloud-agent'
| 'cli') and emit PostHog analytics events (remote_session_opened,
remote_session_message_sent) for live CLI sessions.
700e5ef to
848b151
Compare
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.
Summary
Adds PostHog analytics tracking for remote (CLI) session interactions. Two new optional callbacks are introduced in the session manager:
onRemoteSessionOpened— fires when a CLI session becomes active and is ready to accept inputonRemoteSessionMessageSent— fires after a message is successfully sent to a CLI sessionThese callbacks are wired in
CloudAgentProviderto captureremote_session_openedandremote_session_message_sentPostHog events, each tagged withfeature: 'remote-session'and thekilo_session_id. A stableuseRefwrapper around the PostHog instance avoids stale-closure issues in the one-time manager initialization block.Verification
pnpm typecheck— passed, no type errorspnpm test— 159 tests passed (session-manager + cloud-agent-next), 0 failuresVisual Changes
N/A
Reviewer Notes
onRemoteSessionOpenedcallback fires insideonFirstActivityinswitchSession, gated by!data.cloudAgentSessionId && session.canSend— this correctly limits it to CLI sessions that are live and interactive.onRemoteSessionMessageSentcallback fires insend()after a successfulcurrentSession.send(...), gated by!fetchedData.cloudAgentSessionIdto scope it to remote sessions only.createSessionManager.