Skip to content

agent_trace: Add git vcs metadata to built trace payloads#41

Open
stefanskoricdev wants to merge 2 commits into
mainfrom
feat/add-vcs-to-agent-trace
Open

agent_trace: Add git vcs metadata to built trace payloads#41
stefanskoricdev wants to merge 2 commits into
mainfrom
feat/add-vcs-to-agent-trace

Conversation

@stefanskoricdev
Copy link
Copy Markdown
Contributor

@stefanskoricdev stefanskoricdev commented May 14, 2026

Summary by CodeRabbit

  • New Features

    • Agent traces now include git commit revision information, enabling better tracking of code changes associated with agent activities.
  • Tests

    • Updated test fixtures and validation to support VCS metadata integration with commit revision data.
    • Enhanced schema validation to ensure backward compatibility and proper handling of VCS fields.

Review Change Stack

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>
@stefanskoricdev stefanskoricdev marked this pull request as draft May 14, 2026 16:06
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Warning

Rate limit exceeded

@stefanskoricdev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 38 minutes and 3 seconds before requesting another review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: de54f083-a698-4406-9b37-606d709ba887

📥 Commits

Reviewing files that changed from the base of the PR and between 3bd56db and 1b85f6e.

⛔ Files ignored due to path filters (3)
  • context/glossary.md is excluded by !context/**/*.md
  • context/sce/agent-trace-embedded-schema-validation.md is excluded by !context/**/*.md
  • context/sce/agent-trace-minimal-generator.md is excluded by !context/**/*.md
📒 Files selected for processing (9)
  • cli/src/services/agent_trace.rs
  • cli/src/services/agent_trace/fixtures/average_age_reconstruction/golden.json
  • cli/src/services/agent_trace/fixtures/file_rename_reconstruction/golden.json
  • cli/src/services/agent_trace/fixtures/hello_world_reconstruction/golden.json
  • cli/src/services/agent_trace/fixtures/mixed_change_reconstruction/golden.json
  • cli/src/services/agent_trace/fixtures/poem_edit_reconstruction/golden.json
  • cli/src/services/agent_trace/fixtures/poem_write_reconstruction/golden.json
  • cli/src/services/agent_trace/fixtures/text_file_lifecycle_reconstruction/golden.json
  • config/schema/agent-trace.schema.json
📝 Walkthrough

Walkthrough

Agent traces now capture Git VCS metadata. A new AgentTraceVcs struct holds the repository kind and commit revision, populated from caller-provided commit OIDs in the post-commit hook flow. The trace builder assigns this metadata to the top-level AgentTrace payload, and tests validate the structure with schema compliance checks and fixture snapshots.

Changes

VCS Metadata Tracking

Layer / File(s) Summary
VCS metadata contract and domain structures
cli/src/services/agent_trace.rs
AgentTraceMetadataInput adds commit_revision field; new AgentTraceVcs struct holds kind (serialized as type) and revision; top-level AgentTrace payload includes vcs field.
VCS field population in trace builder
cli/src/services/agent_trace.rs
build_agent_trace constructs and sets the vcs object, hardcoding kind to "git" and assigning revision from metadata input.
Post-commit hook integration
cli/src/services/hooks/mod.rs
Post-commit hook flow threads captured commit_oid into AgentTraceMetadataInput.commit_revision when building the agent trace.
Test validation and fixture updates
cli/src/services/agent_trace/tests.rs, cli/src/services/agent_trace/fixtures/*/golden.json
Test infrastructure now imports json, introduces TEST_COMMIT_REVISION constant, extends helper to assert vcs field matches golden data, and adds schema-validation tests for optional vcs presence and required revision property. All 7 golden fixtures updated with VCS metadata.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • ivke995
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the main change: adding git VCS metadata (with commit revision) to agent trace payloads, which is reflected across the core domain model updates and fixture modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/add-vcs-to-agent-trace

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between b321a3a and 3bd56db.

⛔ Files ignored due to path filters (4)
  • context/context-map.md is excluded by !context/**/*.md
  • context/glossary.md is excluded by !context/**/*.md
  • context/sce/agent-trace-embedded-schema-validation.md is excluded by !context/**/*.md
  • context/sce/agent-trace-minimal-generator.md is excluded by !context/**/*.md
📒 Files selected for processing (10)
  • cli/src/services/agent_trace.rs
  • cli/src/services/agent_trace/fixtures/average_age_reconstruction/golden.json
  • cli/src/services/agent_trace/fixtures/file_rename_reconstruction/golden.json
  • cli/src/services/agent_trace/fixtures/hello_world_reconstruction/golden.json
  • cli/src/services/agent_trace/fixtures/mixed_change_reconstruction/golden.json
  • cli/src/services/agent_trace/fixtures/poem_edit_reconstruction/golden.json
  • cli/src/services/agent_trace/fixtures/poem_write_reconstruction/golden.json
  • cli/src/services/agent_trace/fixtures/text_file_lifecycle_reconstruction/golden.json
  • cli/src/services/agent_trace/tests.rs
  • cli/src/services/hooks/mod.rs

Comment on lines +385 to +388
vcs: AgentTraceVcs {
kind: "git".to_owned(),
revision: metadata.commit_revision.to_owned(),
},
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

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.

Suggested change
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>
@stefanskoricdev stefanskoricdev marked this pull request as ready for review May 14, 2026 16:28
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