Skip to content

fix(agent-discovery): save scan risk tags and reconcile statuses - #4324

Open
Anish Mehta (anishmehta24) wants to merge 1 commit into
microsoft:mainfrom
anishmehta24:fix/discovery-cli-persist-state
Open

Anish Mehta (anishmehta24) wants to merge 1 commit into
microsoft:mainfrom
anishmehta24:fix/discovery-cli-persist-state

Conversation

@anishmehta24

Copy link
Copy Markdown

Related Issue

None. Problem & Solution, Impact and Alternatives are filled in below.

Problem & Solution

Problem: AgentInventory only writes to disk inside ingest(), remove() and clear(). The scan command adds the risk_level/risk_score tags after ingest(), and reconcile marks agents REGISTERED or SHADOW in memory only, so neither reaches the stored inventory. scan prints "Inventory saved to ..." but the file has no risk tags, and agent-discovery inventory afterwards shows every agent as unknown.

Solution: add a public AgentInventory.save() and call it at the end of scan and right after reconcile.

Impact on Your Work

After scan and then reconcile --registry-file ... (which printed Registered: 1, Shadow: 2), agent-discovery inventory -o summary still reported all three agents as unknown, so the inventory couldn't be used to track which agents were registered.

Timeline

None

Alternatives Considered

Having Reconciler.reconcile() save the inventory itself. I kept the save in the CLI, which already owns the storage path, so the library classes stay side-effect free.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Maintenance (dependency updates, CI/CD, refactoring)
  • Security fix

Package(s) Affected

Governance & security:

  • agent-discovery

Testing

Unit Testing

test_scan_and_reconcile_save_results in tests/test_cli.py runs scan and then reconcile with CliRunner and reloads the inventory from disk after each step. It fails on main (no risk_level tag, status unknown) and passes with the change. The agent-discovery suite passes (58 tests).

Manual Testing

Ran scan and reconcile from the CLI and checked the stored JSON before and after the change.

Checklist

  • I have linked a related issue above, or completed "Problem & Solution", "Impact on Your Work", and "Alternatives Considered"
  • My code follows the project style guidelines (ruff check)
  • I have added tests that prove my fix/feature works
  • All new and existing tests pass (pytest)
  • I have updated documentation as needed
  • I have signed the Microsoft CLA

Attribution & Prior Art

  • This contribution does not contain code copied or derived from other projects without attribution
  • Any external projects that inspired this design are credited in code comments or documentation
  • If this PR implements functionality similar to an existing open-source project, I have listed it below

Prior art / related projects (if any):

AI Assistance

  • I can explain every meaningful change in this PR: what it does, why, and what tradeoffs were considered
  • I have run tests and verification appropriate for this change
  • No part of this PR was autonomously submitted by an AI agent without my review
  • I have not used AI to generate review comments on others' PRs

If AI tools materially shaped this change, briefly note what was used:
Claude Code helped find the bug and draft the fix and test. I reviewed the change and ran the tests.

IP, Patents, and Licensing

  • This contribution does not implement patent-pending or patent-encumbered techniques
  • This contribution does not require an NDA or licensing agreement to understand or use
  • Any AI tools used have terms compatible with the MIT License

The inventory only wrote to disk inside ingest(), so the risk tags
that scan adds afterwards and the statuses that reconcile sets were
never stored. scan printed "Inventory saved", but a later inventory
command showed every agent as unknown with no risk. Add a public
save() and call it at the end of scan and after reconcile.

Signed-off-by: Anish Mehta <mehtaanish111@gmail.com>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@github-actions github-actions Bot added tests size/S Small PR (< 50 lines) labels Oct 15, 2026
@github-actions

Copy link
Copy Markdown

PR Review Summary

Check Status Details
🔍 Code Review ⚠️ Missing No current-run comment
🛡️ Security Scan ⚠️ Missing No current-run comment
🔄 Breaking Changes ⚠️ Missing No current-run comment
📝 Docs Sync ⚠️ Missing No current-run comment
🧪 Test Coverage ⚠️ Missing No current-run comment

Verdict: ⚠️ AI review incomplete; ready for human review

AI review comments are untrusted advisory output. The summary reports workflow-generated completion status only, not model-authored pass/fail claims.

@github-actions

Copy link
Copy Markdown

🔴 Contributor Check: HIGH

Check Result
Profile HIGH
Credential LOW
Overall HIGH

Automated check by AGT Contributor Check.

@github-actions github-actions Bot added the needs-review:HIGH Contributor reputation check flagged HIGH risk label Oct 15, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-review:HIGH Contributor reputation check flagged HIGH risk size/S Small PR (< 50 lines) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant