Skip to content

Comments

feat: emit agent usage metrics even when not in a git repo#568

Merged
svarlamov merged 1 commit intomainfrom
devin/1771641578-checkpoint-metrics-without-repo
Feb 21, 2026
Merged

feat: emit agent usage metrics even when not in a git repo#568
svarlamov merged 1 commit intomainfrom
devin/1771641578-checkpoint-metrics-without-repo

Conversation

@svarlamov
Copy link
Member

@svarlamov svarlamov commented Feb 21, 2026

feat: emit agent usage metrics even when not in a git repo

Summary

When git-ai checkpoint <agent> is invoked outside a git repository, the process previously exited early without recording any metrics. This PR ensures the AgentUsage metric event is still emitted at the two no-repo exit paths in handle_checkpoint:

  1. Multi-repo file detection finds no repositories for the edited files
  2. No edited files provided and working directory is not a git repo

A new emit_no_repo_agent_metrics helper in git_ai_handlers.rs builds EventAttributes with the available agent info (tool, model, prompt_id) but without repo-specific fields (repo_url, branch, base_commit_sha), records the AgentUsage event, and triggers a background flush.

should_emit_agent_usage in checkpoint.rs was changed from private to pub(crate) so the rate-limiting logic can be reused.

Review & Testing Checklist for Human

  • Verify spawn_background_flush vs process::exit(0) timing: The metric is written synchronously to the local log file via record(), but spawn_background_flush() is called right before std::process::exit(0). Confirm the background flush either completes or that the local log file will be picked up on the next flush cycle — otherwise the metric may never reach the server.
  • Confirm only AgentUsage is needed (not per-file Checkpoint events): This PR does not emit Checkpoint (event ID 4) events in the no-repo path since per-file line stats can't be computed without a repository. Verify this matches the intended requirement.
  • Nullable attrs on server side: The AgentUsage events emitted here will lack repo_url, branch, and base_commit_sha. Confirm the metrics ingestion server handles these as nullable without errors.
  • Test manually: Run git-ai checkpoint claude --hook-input '<valid_json>' from a non-git directory and verify an AgentUsage event appears in the local observability log.

Notes


Open with Devin

When running AI checkpoint outside a git repository, the AgentUsage
metric event is now emitted before exiting. This ensures client metrics
are still recorded for agent usage tracking regardless of whether the
user is working in a git repo.

Changes:
- Make should_emit_agent_usage pub(crate) in checkpoint.rs
- Add emit_no_repo_agent_metrics helper in git_ai_handlers.rs
- Call it at both no-repo exit paths (no repos from files, no files)

Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@git-ai-cloud-dev
Copy link

No AI authorship found for these commits. Please install git-ai to start tracking AI generated code in your commits.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@svarlamov svarlamov merged commit 9963039 into main Feb 21, 2026
23 checks passed
@svarlamov svarlamov deleted the devin/1771641578-checkpoint-metrics-without-repo branch February 21, 2026 05:05
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.

2 participants