fix(py-isolation-api-server): use public accessors in get_stats#2165
Merged
imran-siddique merged 1 commit intoMay 12, 2026
Conversation
The `/api/v1/stats` endpoint reached into three private attributes: - `hv._sessions.values()` for participant / saga rollups - `len(hv._sessions)` for total session count - `len(hv.vouching._vouches)` for total vouch count Reaching into private state from a different module makes refactoring the internal containers (locking, indexing, storage backend) a breaking API change rather than an internal one. The fields are all underscored on purpose. Adds three public accessors and switches `get_stats` to use them: - `Hypervisor.sessions` — snapshot list of every managed session - `Hypervisor.session_count` — total session count incl. archived - `VouchingEngine.vouch_count` — total sponsorship-record count `Hypervisor.active_sessions` already existed; the new `sessions` / `session_count` accessors give callers the *full* registry (active + archived/terminating), which is what `get_stats` needed. The snapshot form (`list(self._sessions.values())`) lets callers iterate without holding internal references. Behaviour of `get_stats` is unchanged — same fields, same values, same ordering — and the iteration is now done once over `hv.sessions` rather than twice over `hv._sessions.values()`. Three regression tests cover the new accessors: empty-state count, inclusion of terminated sessions, snapshot-semantics. One test covers `VouchingEngine.vouch_count` including released bonds.
🤖 AI Agent: security-scanner — View detailsNo security issues found. |
🤖 AI Agent: test-generator — `agent-governance-python/agent-hypervisor/src/hypervisor/api/server.py`
|
🤖 AI Agent: code-reviewer — View detailsTL;DR: 0 blockers, 0 warnings. No issues found. Clean change. |
🤖 AI Agent: docs-sync-checker — Docs SyncDocs Sync
|
🤖 AI Agent: breaking-change-detector — API CompatibilityAPI Compatibility
|
|
🟡 Contributor Check: MEDIUM
Automated check by AGT Contributor Check. |
PR Review Summary
Verdict: ✅ Ready for human review |
MohammadHaroonAbuomar
pushed a commit
to MohammadHaroonAbuomar/agt-acs
that referenced
this pull request
Jun 1, 2026
…osoft#2165) The `/api/v1/stats` endpoint reached into three private attributes: - `hv._sessions.values()` for participant / saga rollups - `len(hv._sessions)` for total session count - `len(hv.vouching._vouches)` for total vouch count Reaching into private state from a different module makes refactoring the internal containers (locking, indexing, storage backend) a breaking API change rather than an internal one. The fields are all underscored on purpose. Adds three public accessors and switches `get_stats` to use them: - `Hypervisor.sessions` — snapshot list of every managed session - `Hypervisor.session_count` — total session count incl. archived - `VouchingEngine.vouch_count` — total sponsorship-record count `Hypervisor.active_sessions` already existed; the new `sessions` / `session_count` accessors give callers the *full* registry (active + archived/terminating), which is what `get_stats` needed. The snapshot form (`list(self._sessions.values())`) lets callers iterate without holding internal references. Behaviour of `get_stats` is unchanged — same fields, same values, same ordering — and the iteration is now done once over `hv.sessions` rather than twice over `hv._sessions.values()`. Three regression tests cover the new accessors: empty-state count, inclusion of terminated sessions, snapshot-semantics. One test covers `VouchingEngine.vouch_count` including released bonds.
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.
Summary
api/server.py's/api/v1/statshandler reached into three private attributes on the Hypervisor and VouchingEngine:Reaching into another module's underscored containers makes any internal refactor (locking, indexing, storage backend) a breaking API change rather than an internal one. The fields are underscored on purpose.
Change
Adds three public accessors and switches
get_statsto use them:Hypervisor.sessionslist[ManagedSession]of every managed sessionHypervisor.session_countVouchingEngine.vouch_countHypervisor.active_sessionsalready existed but filters via_active_ids, so it isn't equivalent tolen(hv._sessions). The new accessors give the full registry, which is whatget_statsneeded. The snapshot form (list(self._sessions.values())) lets callers iterate without holding internal references.Behaviour of
get_statsis unchanged — same fields, same values, same ordering — and the iteration is now done once overhv.sessionsrather than twice overhv._sessions.values().Tests
test_session_count_emptysession_count == 0,sessions == []test_session_count_includes_terminatedactive_sessions == 1butsession_count == 2test_sessions_returns_snapshot_not_live_viewcreate_sessiondoes not growtest_vouch_count_accessorrelease_bond(records aren't deleted)Full suite: 617 passed, 2 pre-existing failures in
tests/unit/test_ring_improvements.py::TestBreachDetectorconfirmed unrelated to this change (verified by stashing and re-running on upstream/main).Test plan
test_agent_manager.py+test_liability.pytests pass/api/v1/statsresponse shape or valuesHypervisor.sessions/session_count/VouchingEngine.vouch_countavailable to other internal callers that previously reached into_sessions/_vouchesSurfaced during independent audit conducted by @finnoybu (Ken Tannenbaum, AEGIS Initiative); [LOW, Python Isolation].