Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions amplifier_module_loop_live/failures.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def turn_failure(error, stage="manager_turn"):
safe_codes = {"native_input_oversized", "native_checkpoint_invalid", "native_no_reduction",
"native_measurement_unavailable", "native_compaction_failed",
"disabled", "request_context_unavailable", "invalid_native_contract",
"authoritative_measurement_unavailable"}
"authoritative_measurement_unavailable", "summary_output_limit", "summary_empty",
"previous_failure", "summary_failed", "native_failed"}
count_failure = count_diagnostic(error)
if count_failure is not None:
category, stage = 'context_measurement', 'context_preparation'
Expand Down Expand Up @@ -89,7 +90,7 @@ def turn_failure(error, stage="manager_turn"):
# Class names from arbitrary third-party exceptions are not trusted text.
kind = next((cls.__name__ for cls in type(error).__mro__
if cls.__module__ in {"builtins", "amplifier_core.llm_errors"}), "Exception")
return {**({"error_code": code} if code in safe_codes else {}),
return {**({"error_code": code} if isinstance(code, str) and code in safe_codes else {}),
**({'count_failure': count_failure} if count_failure is not None else {}),
"error_type": "CompactionError" if compaction else kind, "error_category": category, "error_stage": stage,
"error_message": message, "effects": "not_rolled_back", "replayed": False,
Expand Down
5 changes: 3 additions & 2 deletions tests/test_failures.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ async def test_local_failure_keeps_cause_and_identity_without_provider_error_or_
loop._execute_guarded_goal.assert_awaited_once()


@pytest.mark.parametrize('code', ['native_input_oversized', 'private payload'])
@pytest.mark.parametrize('code', ['native_input_oversized', 'summary_output_limit', 'summary_empty',
'previous_failure', 'summary_failed', 'native_failed', 'private payload', {'secret': 'value'}])
def test_compaction_failure_preserves_bounded_code_without_optional_dependency(code):
error_class = type('CompactionError', (RuntimeError,), {
'__module__': 'amplifier_module_context_managed.errors'})
Expand All @@ -69,7 +70,7 @@ def test_compaction_failure_preserves_bounded_code_without_optional_dependency(c
assert failure['error_category'] == 'context_compaction'
assert failure['error_stage'] == 'context_preparation'
assert failure['error_type'] == 'CompactionError'
assert failure.get('error_code') == ('native_input_oversized' if code != 'private payload' else None)
assert failure.get('error_code') == (code if isinstance(code, str) and code != 'private payload' else None)
assert 'secret' not in json.dumps(failure)
assert 'private payload' not in json.dumps(failure)
assert failure['retryable'] is False
Expand Down
Loading