Story-993: structured failure envelope
PR #21 ยท pramaan-io/pramaan-agents ยท merged 2026-06-02
How it flows
sequenceDiagram
autonumber
participant runtime as Runtime
participant envelope as Envelope Builder
participant store as Store
runtime->>runtime: run dies (model / tool / validation / resume)
runtime->>envelope: mark failure context
envelope->>envelope: classify kind + build envelope
envelope->>runtime: envelope dict
runtime->>store: fail run (envelope)
store->>store: persist + legacy fields
runtime->>runtime: emit failure event payload
failure_envelope.py ยท +244 โ new methods
| Method | in โ out | what it does |
|---|
mark_failure_context | (error, failure_stage, failure_kind, failed_component) โ BaseException | |
build_failure_envelope | (error, run_id, firm_id, matter_id, failure_stage, failed_component, created_at) โ dict[str, Any] | |
failure_event_payload | (error, envelope) โ dict[str, Any] | |
What changed, file by file
| new method | signature |
|---|
mark_failure_context | (error, failure_stage, failure_kind, failed_component) โ BaseException |
build_failure_envelope | (error, run_id, firm_id, matter_id, failure_stage, failed_component, created_at) โ dict[str, Any] |
failure_event_payload | (error, envelope) โ dict[str, Any] |
_classify_kind | (error, stage) โ str |
_sanitized_summary | (kind, stage) โ str |
_recovery_recommendation | (kind, stage) โ str |
_user_visible_message | (kind, stage) โ str |
_is_retryable | (kind) โ bool |
_retry_after_seconds | (kind) โ int |
_internal_debug_ref | (raw_error_class, raw_message) โ str |
_context_value | (error, name) โ str | None |
_valid_kind | (value) โ str |
_valid_stage | (value) โ str |
_default_component | (stage) โ str |
| new method | signature |
|---|
fail_run | (run_id, error, firm_id, failure_envelope) โ None |
What doesn't happen anymore
- raw trace leaked to user
- retry storm triggered
- legacy fields overwritten
- silent misclassification
- envelope without firm id
user-visible message is sanitized
debug ref stays private
legacy class + message preserved
firm id stamped on every envelope
unknown stage on unclassified error
safe back-off if retry is ambiguous
Files changed (8)