fix(bindings): sanitize non-JSON-native types at emit() FFI boundary - #76
Conversation
All four unguarded json.dumps() call sites at the Python/Rust FFI boundary now pass default=str so Decimal, datetime, and any other non-JSON-native type becomes its str() representation instead of raising TypeError and crashing the caller. Sites fixed: - helpers.rs: new json_dumps_safe() DRY helper used at all Rust sites - hooks.rs: emit(), set_default_fields(), emit_and_collect() - bridges.rs: PyHookHandlerBridge::handle() result-serialization path - loader_grpc.py: GrpcToolBridge._serialize_input() Incidental fix: provider-anthropic cost_usd crash (PR #52) is resolved automatically. str(Decimal("1.23")) == "1.23", identical to the existing @field_serializer output on the Pydantic model path. Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
d988a22 to
8d714fa
Compare
- pyproject.toml: 1.5.1 → 1.5.2 - crates/amplifier-core/Cargo.toml: 1.5.1 → 1.5.2 - bindings/python/Cargo.toml: 1.5.1 → 1.5.2 - python/amplifier_core/__init__.py: 1.5.1 → 1.5.2 - scripts/bump_version.py: regex fix to handle __version__ (trailing __) - Cargo.lock: updated Verified: E2E smoke test PASSED — manylinux wheel built, pristine-import OK, Docker container test passed. Generated with Amplifier Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
Fix rustfmt CI check failure by applying standard formatting to: - json_dumps_safe function signature in helpers.rs - test binding in tests/mod.rs Generated with Amplifier Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
…ructural guard test - Apply json_dumps_safe() to all remaining unguarded json.dumps() calls: * session.rs: session config serialization * coordinator/mod.rs: coordinator config serialization * wasm.rs: tool input, provider request/response, hook data, context message, set_messages, approval request (7 sites) - Add no_raw_json_dumps_outside_helpers structural test that scans .rs files and fails if raw json.dumps() calls appear outside the safe helper, preventing future regressions - Remove private repo reference from test docstring Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
f482316 to
75fccb7
Compare
DTU Validation — Pre-fix provider-anthropic + fixed amplifier-coreTo validate that the
The provider at that commit passes ResultsWhy the cost stamp is the proofThe Also confirmed
|
Summary
emit()and related registry methods when sent as event payloadsjson_dumps_safe()DRY helper inhelpers.rsthat threadsdefault=strthrough the FFI boundary — all non-JSON types now serialize via theirstr()representationprovider-anthropiccost_usd Decimal serialization issue (related to feat: add --local-source to E2E smoke test + fix input_schema test #52 fix)Sites Fixed
bindings/python/src/helpers.rs— new DRY helperbindings/python/src/hooks.rs—emit(),set_default_fields(),emit_and_collect()bindings/python/src/bridges.rs—PyHookHandlerBridge::handle()result pathpython/amplifier_core/loader_grpc.py—GrpcToolBridge._serialize_input()Test Coverage
bindings/python/tests/test_emit_json_sanitize.pybindings/python/tests/test_loader_grpc.pyDesign doc: docs/plans/2026-05-08-emit-json-sanitize-design.md
Generated with Amplifier