feat(registration): report the agent's commit and source repo at registration - #508
feat(registration): report the agent's commit and source repo at registration#508max-parke-scale wants to merge 1 commit into
Conversation
| repo = normalize_remote(env_vars.AGENT_SOURCE_REPO) | ||
| if repo: | ||
| metadata["source_repo"] = repo |
There was a problem hiding this comment.
Repository Credentials Can Leak
If AGENT_SOURCE_REPO contains a credential in its query string or fragment, such as https://github.com/org/repo?access_token=SECRET, normalize_remote preserves that suffix. The credential is then sent in source_repo and included in the successful-registration log. Strip query strings and fragments before adding the repository to the metadata.
How this was verified: The environment value reaches the registration payload through normalize_remote, whose string processing never removes ? or # suffixes.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agentex/lib/utils/registration.py
Line: 40-42
Comment:
**Repository Credentials Can Leak**
If `AGENT_SOURCE_REPO` contains a credential in its query string or fragment, such as `https://github.com/org/repo?access_token=SECRET`, `normalize_remote` preserves that suffix. The credential is then sent in `source_repo` and included in the successful-registration log. Strip query strings and fragments before adding the repository to the metadata.
**How this was verified:** The environment value reaches the registration payload through `normalize_remote`, whose string processing never removes `?` or `#` suffixes.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Valid. Fixed at the layer that promises it: normalize_remote now drops the query string and fragment before any other processing (ee05394), with a table row for ?access_token=SECRET#frag. Same fix pushed to the Gitea copy of the normalizer in scaleapi/sgp#5720.
🤖 — posted via Claude Code
| commit = (env_vars.AGENT_COMMIT_SHA or "").strip() | ||
| if commit: | ||
| if is_git_object_name(commit): | ||
| metadata["commit_sha"] = commit | ||
| else: | ||
| logger.warning( | ||
| "AGENT_COMMIT_SHA=%r is not a git commit SHA; commit_sha omitted from registration.", | ||
| commit, | ||
| ) | ||
| repo = normalize_remote(env_vars.AGENT_SOURCE_REPO) |
There was a problem hiding this comment.
The new unconditional accesses to AGENT_COMMIT_SHA and AGENT_SOURCE_REPO break the existing register_agent tests. Their environment stub in tests/lib/test_agent_card.py defines neither attribute, so all three tests raise AttributeError before making their mocked HTTP requests. Update the fixture or read these optional fields defensively so the test suite can pass.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agentex/lib/utils/registration.py
Line: 31-40
Comment:
**New Fields Break Test Stubs**
The new unconditional accesses to `AGENT_COMMIT_SHA` and `AGENT_SOURCE_REPO` break the existing `register_agent` tests. Their environment stub in `tests/lib/test_agent_card.py` defines neither attribute, so all three tests raise `AttributeError` before making their mocked HTTP requests. Update the fixture or read these optional fields defensively so the test suite can pass.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Fixed in ee05394 by extending the EnvVars stub in test_agent_card.py with the two new fields. The accesses stay unconditional on purpose: EnvironmentVariables declares both fields, and a defensive getattr would hide a real typo in the model.
🤖 — posted via Claude Code
…stration Registration is the one moment an agent built and deployed outside SGP tells SGP about itself, and until now it reported only the deployment id and the agent card. It now also sends commit_sha (from AGENT_COMMIT_SHA, same git object-name guard as __commit_sha__) and source_repo (from a new AGENT_SOURCE_REPO, normalized to host/path with the build-provenance util). Keys appear only when the value is known; nothing is sent empty. The metadata assembly moves into build_registration_metadata so it can be tested without the HTTP round trip. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
36d770d to
ee05394
Compare
Agent registration now carries
commit_shaandsource_repoinregistration_metadata, alongside the existingdeployment_idand agent card. Registration is the one moment an agent built and deployed outside SGP (CLI Helm deploys, e.g. BP Wells' Azure DevOps → ACR →agentex agents deploy) tells SGP about itself, so it is the consistent place to record what is deployed right now without inventing a build row for a build SGP never performed. Part of AGX1-969.What
commit_sha: fromAGENT_COMMIT_SHA, accepted only when it is a git object name, the same guard__commit_sha__uses (code_revision.is_git_object_name, now public). A non-commit value logs a warning and is omitted, never forwarded.source_repo: from a newAGENT_SOURCE_REPOenv var, normalized tohost/pathwithbuild_provenance.normalize_remote(feat(lib): capture client-attested build provenance #454), sogit@github.com:scaleapi/Demo.gitandhttps://token@github.com/scaleapi/Demoboth record asgithub.com/scaleapi/Demo.build_registration_metadataso it is testable without the HTTP round trip.register_agentbehavior is otherwise unchanged; the backend storesregistration_metadataas-is, so no server change.Relation to #507 and #5553
Independent of #507: registration reports the deployment's declared commit whether or not the agent opted into span stamping. Today nothing sets
AGENT_SOURCE_REPO; the chart follow-up is aglobal.agent.sourceRepovalue rendered into that env var, in the #5553 contract.AGENT_COMMIT_SHAis set by #5553 from a SHA-shaped image tag orglobal.agent.commitSha.Tests
tests/lib/utils/test_registration.py: empty metadata when nothing is known; commit and normalized repo when set; non-commit values (tag, semver, AWS composite, too short, blank) omitted; credential and scheme stripping; deployment id and agent card unchanged.ruffandpyrightclean.🧑💻🤖 — posted via Claude Code
Greptile Summary
Agent registration now reports validated source provenance while preserving existing deployment and agent-card metadata.
AGENT_COMMIT_SHAandAGENT_SOURCE_REPOenvironment configuration.Confidence Score: 5/5
The PR appears safe to merge; both previous findings are fully addressed and no new actionable issues remain.
The repository normalizer now removes query strings and fragments before source metadata is returned, and the existing registration test stub now supplies both newly required environment attributes. The added tests cover these fixes and the principal metadata behaviors.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart LR Env[Environment variables] --> Validate[Validate commit SHA] Env --> Normalize[Normalize source repository] Validate --> Metadata[Registration metadata] Normalize --> Metadata Deployment[Deployment ID] --> Metadata Card[Agent card] --> Metadata Metadata --> Registration[Agent registration request]Reviews (2): Last reviewed commit: "feat(registration): report the agent's c..." | Re-trigger Greptile