Skip to content

Conversation

@oai-coding-agent
Copy link
Contributor

@oai-coding-agent oai-coding-agent bot commented Aug 12, 2025

Summary

  • Added session telemetry that generates a UUIDv4 per launch, records start/end timestamps and duration, and persists events for basic usage analytics.

Implementation Details

  • Introduced oai_coding_agent/telemetry/session.py:
    • SessionTracker manages a single launch lifecycle.
    • Generates a UUIDv4 session_id at start and writes a session_start JSONL record.
    • Persists a stable anonymized user_id (random UUID written once to XDG data dir user.json) to associate relaunches to the same user without PII.
    • On shutdown, writes a session_end record with ended_at and duration_ms. Also registers an atexit hook for extra safety.
    • Events are stored as JSON Lines at: XDG_DATA_HOME/oai_coding_agent/sessions.jsonl.
  • CLI integration (cli.py):
    • Starts a session after RuntimeConfig is created, passing repository path, model, mode, repo and branch metadata when available.
    • Ensures the session is ended in a finally block after the console run (normal exit or KeyboardInterrupt), so end records are captured during tests and real runs.
  • Event shape (one JSON object per line):
    • { event: "session_start", session_id, user_id, started_at, pid, version, python, repo_path?, model?, mode?, github_repo?, branch_name? }
    • { event: "session_end", session_id, user_id, ended_at, duration_ms, exit_reason? }

Assumptions Made

  • Local JSONL persistence satisfies "persist to local file or telemetry backend"; a future backend can consume/ship these events.
  • A random UUID stored once locally is sufficient as an anonymized user identifier to associate relaunches to the same user.
  • Session tracking is scoped to agent launches (default/headless modes), not auxiliary subcommands (e.g., github login/logout).

Testing

  • Added tests/telemetry/test_session.py:
    • Verifies SessionTracker writes start and end events with matching session_id and non-negative duration.
    • Verifies anonymized user_id is stable across tracker instances (simulated relaunch).
    • Verifies CLI run produces start and end events in sessions.jsonl.
  • Ran project checks:
    • uv run ruff check && uv run ruff format
    • uv run mypy . (Success: no issues)
    • uv run pytest (156 passed, 1 skipped locally)

Considerations

  • Chose append-only JSONL to be resilient (no in-place file updates) and easy to ingest in log pipelines. A single-file JSON map was considered but is less robust to concurrency/failures.
  • The tracker currently uses atexit for best-effort end recording; the CLI also explicitly ends the session to ensure completeness.

closes #158

- Add tests verifying session_start and session_end records and persistent user_id across launches
- Provide explicit return types in test factories for mypy compliance
- Adjust session.start_session to support multiple CLI invocations in a single process
- Start session after RuntimeConfig creation with runtime context metadata
- Ensure session end is recorded on normal exit and interrupts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement session ID tracking for Coding Agent launches

2 participants