fix(rust-sandbox): generate IDs from rand::random, not nanos+ThreadId+FNV#2172
Merged
imran-siddique merged 1 commit intoMay 12, 2026
Conversation
…not nanos+ThreadId+FNV
`generate_id()` in `agent-governance-rust/agentmesh/src/sandbox.rs` derived
its 16-hex-char ID by FNV-1a–mixing `SystemTime::now().as_nanos()` with the
debug-formatted `std::thread::ThreadId`. Two calls landing in the same
nanosecond on the same thread (e.g. tight `create_session()` loops, or
`create_session()` immediately followed by `execute_code()` inside the same
function) would produce identical IDs because both inputs to the mix were
identical and FNV-1a is deterministic.
For an internal namespacing helper, a non-CSPRNG `rand::random::<u64>()`
(OS-seeded thread RNG, used in the same shape elsewhere in this crate —
e.g. `governance_support::violation_id`, `control_support::incident_id`,
`identity_support::credential_id`) is the right primitive: collision
probability over 10k draws is ~2.7e-12 and it doesn't require a clock
read at all.
Replace the FNV body with `format!("{:016x}", rand::random::<u64>())` and
add two regression tests in `sandbox_test.rs`:
- `generate_id_no_collisions_under_burst` — 10 000 sequential calls.
- `generate_id_no_collisions_across_threads` — 8 threads × 2 000 calls.
The existing `generate_id_uniqueness` smoke test still passes.
🤖 AI Agent: test-generator — `agent-governance-rust/agentmesh/src/sandbox.rs`
|
🤖 AI Agent: code-reviewer — View detailsTL;DR: 1 blocker, 0 warnings. The ID generation method may lead to collisions under specific conditions.
Action items: Refactor Warnings: No warnings found. Fine as follow-up PRs. |
🤖 AI Agent: breaking-change-detector — API CompatibilityAPI Compatibility
|
🤖 AI Agent: security-scanner — View detailsNo security issues found. |
🤖 AI Agent: docs-sync-checker — Docs SyncDocs Sync
|
|
🟡 Contributor Check: MEDIUM
Automated check by AGT Contributor Check. |
PR Review Summary
Verdict: ❌ Changes needed |
MohammadHaroonAbuomar
pushed a commit
to MohammadHaroonAbuomar/agt-acs
that referenced
this pull request
Jun 1, 2026
…not nanos+ThreadId+FNV (microsoft#2172) `generate_id()` in `agent-governance-rust/agentmesh/src/sandbox.rs` derived its 16-hex-char ID by FNV-1a–mixing `SystemTime::now().as_nanos()` with the debug-formatted `std::thread::ThreadId`. Two calls landing in the same nanosecond on the same thread (e.g. tight `create_session()` loops, or `create_session()` immediately followed by `execute_code()` inside the same function) would produce identical IDs because both inputs to the mix were identical and FNV-1a is deterministic. For an internal namespacing helper, a non-CSPRNG `rand::random::<u64>()` (OS-seeded thread RNG, used in the same shape elsewhere in this crate — e.g. `governance_support::violation_id`, `control_support::incident_id`, `identity_support::credential_id`) is the right primitive: collision probability over 10k draws is ~2.7e-12 and it doesn't require a clock read at all. Replace the FNV body with `format!("{:016x}", rand::random::<u64>())` and add two regression tests in `sandbox_test.rs`: - `generate_id_no_collisions_under_burst` — 10 000 sequential calls. - `generate_id_no_collisions_across_threads` — 8 threads × 2 000 calls. The existing `generate_id_uniqueness` smoke test still passes.
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
agent-governance-rust/agentmesh/src/sandbox.rs—generate_id()derived its 16-hex-char session/execution ID by FNV-1a–mixingSystemTime::now().as_nanos()with the debug-formattedstd::thread::ThreadId. Two calls landing in the same nanosecond on the same thread (tightcreate_session()loops, orcreate_session()+execute_code()back-to-back in one function) produce identical inputs to a deterministic mix, so they produce identical IDs.Change
format!("{:016x}", rand::random::<u64>())— the same shape already used elsewhere in this crate (governance_support::violation_id,control_support::incident_id,identity_support::credential_id,trust_support::grant_id).randis already a[dependencies]entry; no Cargo.toml change.sandbox_test.rs:generate_id_no_collisions_under_burst— 10 000 sequential calls, all unique.generate_id_no_collisions_across_threads— 8 threads x 2 000 calls, union all unique.Tests
cargo test -p agentmesh --lib sandbox— 14 passed, 0 failed (including the two new tests and the existinggenerate_id_uniquenesssmoke test).Test plan
generate_idwere reverted to the FNV-1a-on-nanos approach (tight loop hits same nanosecond)Surfaced during independent audit conducted by @finnoybu (Ken Tannenbaum, AEGIS Initiative); [LOW, Rust].