Skip to content

fix: track agent turns from real user messages#2109

Merged
jschwxrz merged 1 commit into
mainfrom
jona/eng-1111-meaning-of-agent_run_startedagent_run_finished-event
May 19, 2026
Merged

fix: track agent turns from real user messages#2109
jschwxrz merged 1 commit into
mainfrom
jona/eng-1111-meaning-of-agent_run_startedagent_run_finished-event

Conversation

@jschwxrz
Copy link
Copy Markdown
Collaborator

  • capture turns instead of pty spawns and exits

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 19, 2026

Greptile Summary

This PR shifts agent_run_started telemetry from PTY lifecycle events (spawn/exit) in the main process to per-turn user input events in the renderer, improving semantic accuracy of what constitutes an "agent turn."

  • local-conversation.ts and ssh-conversation.ts no longer fire agent_run_started / agent_run_finished on PTY spawn and exit; the corresponding telemetryService import is also removed from both files.
  • conversations-panel.tsx adds a captureTelemetry('agent_run_started', …) call inside onEnterPress, which is now defined for all active conversations (including SSH) rather than only when shouldSetWorkingOnEnter is true; the call is already gated downstream by isRealTaskInput inside use-pty.ts before onEnterPress is invoked.
  • agent_run_finished is removed from TelemetryEventProperties entirely, reflecting the intentional decision not to track PTY exits as a turn-completion signal.

Confidence Score: 5/5

Safe to merge — the change is a straightforward relocation of a telemetry call from PTY lifecycle hooks in the main process to user-turn input callbacks in the renderer, with no impact on conversation functionality.

All four changed files make clean, targeted deletions from the main-process providers and a focused addition in the renderer. The new captureTelemetry call is gated by isRealTaskInput in use-pty.ts before onEnterPress is ever invoked, the extra envelope fields are valid under TelemetryEnvelope, and the widened onEnterPress condition matches the intent of tracking turns rather than sessions. No application logic paths are affected.

No files require special attention.

Important Files Changed

Filename Overview
src/renderer/features/tasks/conversations/conversations-panel.tsx Moves telemetry capture into onEnterPress (now active for all conversations including SSH); logic is correct and already gated by isRealTaskInput in use-pty.ts.
src/main/core/conversations/impl/local-conversation.ts Removes PTY-spawn and PTY-exit telemetry calls; telemetryService import cleanly removed.
src/main/core/conversations/impl/ssh-conversation.ts Same removal as local-conversation.ts; SSH turns are now tracked in the renderer via onEnterPress instead.
src/shared/telemetry.ts Removes agent_run_finished event type; agent_run_started retained with its existing shape (provider only), while project_id/task_id/conversation_id are valid via TelemetryEnvelope at the call site.

Sequence Diagram

sequenceDiagram
    participant User
    participant PtyPane
    participant usePty
    participant ConversationsPanel
    participant TelemetryClient

    Note over usePty,ConversationsPanel: Before (PTY-spawn tracking — removed)
    Note over usePty: LocalConversationProvider spawns PTY<br/>→ telemetryService.capture('agent_run_started')
    Note over usePty: PTY exits<br/>→ telemetryService.capture('agent_run_finished')

    Note over User,TelemetryClient: After (turn tracking — this PR)
    User->>PtyPane: Keystroke + Enter
    PtyPane->>usePty: sendInput(data)
    usePty->>usePty: SubmittedInputBuffer.feed(data)
    usePty->>usePty: isRealTaskInput(message)?
    alt message passes isRealTaskInput
        usePty->>ConversationsPanel: onEnterPress(message)
        ConversationsPanel->>TelemetryClient: "captureTelemetry('agent_run_started', {provider, project_id, ...})"
        opt shouldSetWorkingOnEnter (local only)
            ConversationsPanel->>ConversationsPanel: activeConversation.setWorking()
        end
    else shell command / short input
        usePty-->>usePty: no-op (telemetry not fired)
    end
Loading

Reviews (2): Last reviewed commit: "fix: track agent runs from real user mes..." | Re-trigger Greptile

Comment thread src/renderer/features/tasks/conversations/conversations-panel.tsx
Comment thread src/shared/telemetry.ts
@jschwxrz
Copy link
Copy Markdown
Collaborator Author

@greptileai

@jschwxrz jschwxrz merged commit 9bb6eda into main May 19, 2026
1 check passed
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.

1 participant