feat: emit agent usage metrics even when not in a git repo#568
Merged
feat: emit agent usage metrics even when not in a git repo#568
Conversation
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>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
No AI authorship found for these commits. Please install git-ai to start tracking AI generated code in your commits. |
|
|
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.
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 theAgentUsagemetric event is still emitted at the two no-repo exit paths inhandle_checkpoint:A new
emit_no_repo_agent_metricshelper ingit_ai_handlers.rsbuildsEventAttributeswith the available agent info (tool, model, prompt_id) but without repo-specific fields (repo_url, branch, base_commit_sha), records theAgentUsageevent, and triggers a background flush.should_emit_agent_usageincheckpoint.rswas changed from private topub(crate)so the rate-limiting logic can be reused.Review & Testing Checklist for Human
spawn_background_flushvsprocess::exit(0)timing: The metric is written synchronously to the local log file viarecord(), butspawn_background_flush()is called right beforestd::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.AgentUsageis needed (not per-fileCheckpointevents): This PR does not emitCheckpoint(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.AgentUsageevents emitted here will lackrepo_url,branch, andbase_commit_sha. Confirm the metrics ingestion server handles these as nullable without errors.git-ai checkpoint claude --hook-input '<valid_json>'from a non-git directory and verify anAgentUsageevent appears in the local observability log.Notes