agent_trace: Add git vcs metadata to built trace payloads#41
agent_trace: Add git vcs metadata to built trace payloads#41stefanskoricdev wants to merge 2 commits into
Conversation
Extend the Agent Trace model and builder to emit top-level vcs metadata from caller-provided commit metadata, with vcs.type fixed to git and vcs.revision mapped from commit_revision. Update hook wiring, golden fixtures, schema-validation tests, and context docs so the payload contract and optional-schema semantics stay aligned. Co-authored-by: SCE <sce@crocoder.dev>
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (3)
📒 Files selected for processing (9)
📝 WalkthroughWalkthroughAgent traces now capture Git VCS metadata. A new ChangesVCS Metadata Tracking
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cli/src/services/agent_trace.rs`:
- Around line 385-388: The code assigns metadata.commit_revision directly into
AgentTraceVcs.revision which can persist empty/whitespace revision strings; trim
and validate metadata.commit_revision before emitting the trace, and only
populate the revision when non-empty. Update the AgentTraceVcs type to use
Option<String> for revision (if it isn't already) and, in the construction code
that sets vcs: AgentTraceVcs { kind: "git".to_owned(), revision: ... }, do
something like let rev = metadata.commit_revision.trim(); revision: if
rev.is_empty() { None } else { Some(rev.to_owned()) } so the payload omits
invalid revisions. Ensure downstream serialization/consumers still handle the
Option case.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: ff1be2ac-ead3-4a12-a4e0-f67c2b56f758
⛔ Files ignored due to path filters (4)
context/context-map.mdis excluded by!context/**/*.mdcontext/glossary.mdis excluded by!context/**/*.mdcontext/sce/agent-trace-embedded-schema-validation.mdis excluded by!context/**/*.mdcontext/sce/agent-trace-minimal-generator.mdis excluded by!context/**/*.md
📒 Files selected for processing (10)
cli/src/services/agent_trace.rscli/src/services/agent_trace/fixtures/average_age_reconstruction/golden.jsoncli/src/services/agent_trace/fixtures/file_rename_reconstruction/golden.jsoncli/src/services/agent_trace/fixtures/hello_world_reconstruction/golden.jsoncli/src/services/agent_trace/fixtures/mixed_change_reconstruction/golden.jsoncli/src/services/agent_trace/fixtures/poem_edit_reconstruction/golden.jsoncli/src/services/agent_trace/fixtures/poem_write_reconstruction/golden.jsoncli/src/services/agent_trace/fixtures/text_file_lifecycle_reconstruction/golden.jsoncli/src/services/agent_trace/tests.rscli/src/services/hooks/mod.rs
| vcs: AgentTraceVcs { | ||
| kind: "git".to_owned(), | ||
| revision: metadata.commit_revision.to_owned(), | ||
| }, |
There was a problem hiding this comment.
Validate commit revision before emitting trace payload.
Line 387 copies caller-provided revision without validation. An empty/whitespace revision can silently persist unusable VCS metadata.
🛡️ Proposed fix
-use anyhow::{Context, Result};
+use anyhow::{ensure, Context, Result}; pub fn build_agent_trace(
constructed_patch: &ParsedPatch,
post_commit_patch: &ParsedPatch,
metadata: AgentTraceMetadataInput<'_>,
) -> Result<AgentTrace> {
+ ensure!(
+ !metadata.commit_revision.trim().is_empty(),
+ "Invalid commit revision: expected non-empty commit OID."
+ );
let commit_time = parse_commit_timestamp(metadata.commit_timestamp)?;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| vcs: AgentTraceVcs { | |
| kind: "git".to_owned(), | |
| revision: metadata.commit_revision.to_owned(), | |
| }, | |
| use anyhow::{ensure, Context, Result}; | |
| pub fn build_agent_trace( | |
| constructed_patch: &ParsedPatch, | |
| post_commit_patch: &ParsedPatch, | |
| metadata: AgentTraceMetadataInput<'_>, | |
| ) -> Result<AgentTrace> { | |
| ensure!( | |
| !metadata.commit_revision.trim().is_empty(), | |
| "Invalid commit revision: expected non-empty commit OID." | |
| ); | |
| let commit_time = parse_commit_timestamp(metadata.commit_timestamp)?; | |
| // ... rest of function ... | |
| vcs: AgentTraceVcs { | |
| kind: "git".to_owned(), | |
| revision: metadata.commit_revision.to_owned(), | |
| }, |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@cli/src/services/agent_trace.rs` around lines 385 - 388, The code assigns
metadata.commit_revision directly into AgentTraceVcs.revision which can persist
empty/whitespace revision strings; trim and validate metadata.commit_revision
before emitting the trace, and only populate the revision when non-empty. Update
the AgentTraceVcs type to use Option<String> for revision (if it isn't already)
and, in the construction code that sets vcs: AgentTraceVcs { kind:
"git".to_owned(), revision: ... }, do something like let rev =
metadata.commit_revision.trim(); revision: if rev.is_empty() { None } else {
Some(rev.to_owned()) } so the payload omits invalid revisions. Ensure downstream
serialization/consumers still handle the Option case.
Update the Agent Trace runtime default and schema pattern to require three-part numeric semver-style versions. Align golden fixtures and context docs so generated payloads, validation behavior, and documented contracts stay consistent. Co-authored-by: SCE <sce@crocoder.dev>
Summary by CodeRabbit
New Features
Tests