Repository navigation
Conversation
- Make `transparency: str | None = None` optional in `TraceAGTAdapter` and omit `"transparency"` from the emitted record when `None`, matching `TraceSandboxAdapter`. - Reject empty or non-string non-`None` `transparency` values with `ValueError` in both `TraceAGTAdapter` and `TraceSandboxAdapter`. - Validate `agent_did`, `policy_bundle_bytes`, `audit_entries`, `merkle_chain_tip` (including UTF-8 surrogate rejection), and `call_count` in `AGTSessionResult` and `TraceAGTAdapter`, raising `ValueError`. - Validate `policy_bundle_bytes`, `decisions`, `attestation`, `call_count`, and `software_measurement` digest inputs in `SandboxSessionResult` and `TraceSandboxAdapter`, raising `ValueError`. - Remove the `transparency="https://example.test/unused"` and `record.pop("transparency")` workaround from `docs/tutorials/agt-adapter.md`. Fixes agentrust-io#534 Signed-off-by: Raghuvar Durga <177662415+drk-ram@users.noreply.github.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
imran-siddique
left a comment
There was a problem hiding this comment.
Approving 2bbecec. The three touched test files run 337 of 337 here; full suite 3864 passed, and the only local failures are Windows path cases that fail identically on main. Three mutations, each killed: emitting transparency when it is None, dropping the JCS_SAFE_INTEGER bound on call_count, and accepting non-dict entries in decisions. The tutorial no longer needs the record.pop("transparency") workaround, which was the point of #534.
One cleanup for later: _check_policy_bundle_bytes, _check_call_count and _check_transparency are now identical in agt.py and sandbox.py. A shared adapters module would keep the two from drifting.
| ) | ||
|
|
||
|
|
||
| def _check_call_count(value: object) -> None: |
There was a problem hiding this comment.
Same body as agt.py:73. Not blocking.
What this changes
Closes #534
Contributor: Raghuvar Durga (@drk-ram)
tests/test_public_functions_raise_what_they_document.pydeclares"adapters": ("ValueError", "ValidationError")inDOCUMENTED, but_public_functions()skips classes, leavingTraceAGTAdapter,AGTSessionResult,TraceSandboxAdapter, andSandboxSessionResultunswept. This change fixes four boundary defects across the two reference adapters:transparencyinTraceAGTAdapter:TraceAGTAdapter.__init__now acceptstransparency: str | None = None(matchingTraceSandboxAdapter.__init__), omits"transparency"from the emitted record whenself._transparency is None, and validates that any non-Nonetransparencyin bothTraceAGTAdapterandTraceSandboxAdapteris a non-emptystr. Removes thetransparency="https://example.test/unused"andrecord.pop("transparency")workaround fromdocs/tutorials/agt-adapter.md.AGTSessionResultfield validation: Validatesagent_did(against_SUBJECT_RE),policy_bundle_bytes(isinstance(..., bytes)),audit_entries(listofdictobjects),merkle_chain_tip(non-empty UTF-8strwithout lone surrogates), andcall_count(non-negativeint, notbool, within[0, JCS_SAFE_INTEGER], orNone) both inAGTSessionResult.__post_init__and inTraceAGTAdapter.build_trust_record/ hash helpers, raisingValueError.SandboxSessionResultandTraceSandboxAdapterfield validation: Validatespolicy_bundle_bytes(isinstance(..., bytes)),decisions(listofdictobjects),attestation(SandboxAttestationorNone), andcall_count(non-negativeint, notbool, within[0, JCS_SAFE_INTEGER], orNone) inSandboxSessionResult.__post_init__andTraceSandboxAdapter.build_trust_record/bundle_hash/transcript_hash, and validatesimage_digestandbundle_hashinTraceSandboxAdapter.software_measurement, raisingValueError.Cold-reader review findings and changes made:
SandboxSessionResult.attestationwas not checked inSandboxSessionResult.__post_init__or re-validated inTraceSandboxAdapter.build_trust_record, allowing non-SandboxAttestationobjects to leakAttributeErrorin_runtime()and post-constructionobject.__setattr__(att, "platform", "software-only")mutations to bypassSandboxAttestation.__post_init__. Added_check_attestationto bothSandboxSessionResult.__post_init__andTraceSandboxAdapter.build_trust_record.build_trust_record(session)in both adapters accessed attributes onsessionbefore checkingisinstance(session, ...), raisingAttributeErroronNoneor non-session inputs. Addedisinstancechecks raisingValueErrorat the start ofbuild_trust_recordin both adapters._check_merkle_chain_tipaccepted lone UTF-16 surrogates ("\ud800") atAGTSessionResultconstruction and deferred aUnicodeEncodeErrorto_measurement. Added a UTF-8 encode check in_check_merkle_chain_tip.TraceSandboxAdapter.software_measurement(image_digest, bundle_hash)did not validate its arguments. Added_check_image_digestand_check_bundle_hashchecks insoftware_measurement.TraceAGTAdapter._measurement,SandboxSessionResult.attestation,TraceSandboxAdapter.software_measurement, and in-place / post-construction mutation guards onbuild_trust_record.Type of change
Spec section
Reference library adapters (
src/agentrust_trace/adapters/agt.py,src/agentrust_trace/adapters/sandbox.py) and tutorial (docs/tutorials/agt-adapter.md), aligning withspec/trace-v0.2.mdsection 3.1 (optionaltransparencybelow Level 2,subjectURI pattern,tool_transcript, andpolicy.bundle_hash).Tests for a fix
Added in
tests/test_agt_adapter.pyandtests/test_sandbox_required_string_fields.py:test_transparency_defaults_to_none_and_is_omitted_when_unanchoredtest_transparency_rejects_empty_or_non_stringtest_agent_did_rejects_invalid_or_non_string_valuestest_policy_bundle_bytes_rejects_non_bytestest_audit_entries_rejects_non_list_or_non_dict_itemstest_merkle_chain_tip_rejects_empty_or_non_stringtest_call_count_rejects_invalid_valuestest_build_trust_record_revalidates_session_and_in_place_mutationstest_session_policy_bundle_bytes_refuses_non_bytestest_session_decisions_refuses_non_list_or_non_dict_entriestest_session_call_count_refuses_invalid_valuestest_adapter_transparency_refuses_empty_or_non_stringtest_session_attestation_refuses_non_attestation_valuestest_software_measurement_refuses_invalid_digeststest_sandbox_build_trust_record_revalidates_session_and_in_place_mutationsValidation commands run and results:
python -m pytest tests/test_agt_adapter.py tests/test_sandbox_required_string_fields.py tests/test_sandbox_adapter.py tests/test_docs_quickstart.py tests/test_integer_by_value.py tests/test_public_functions_raise_what_they_document.py -q: passed (607 passed)python tools/review_bar.py --base origin/main --head HEAD: passed (79 fail on behaviour, 0 fail on a missing name or file, 64 pass or skip)python -m ruff check src/agentrust_trace/adapters/agt.py src/agentrust_trace/adapters/sandbox.py tests/test_agt_adapter.py tests/test_sandbox_required_string_fields.py: passed (All checks passed!)python -m mypy src/agentrust_trace/adapters/agt.py src/agentrust_trace/adapters/sandbox.py: passed (Success: no issues found in 2 source files)python tools/check_dashes.py: passed (no dashes outside examples/, spec/trace-v0.1.md)Checklist
git commit -s)CHANGELOG.mdupdated (for any normative change)<!-- CHANGED: #NNN: description -->in spec text