Story-993: structured failure envelope

Story 993Epic 928๐Ÿ“œ The Evidentiary RecordMatter Intelligence8 files ยท +632/โˆ’16

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

Methodin โ†’ outwhat 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 methodsignature
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 methodsignature
fail_run(run_id, error, firm_id, failure_envelope) โ†’ None

What doesn't happen anymore

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)

Fileยฑ
docs/walkthroughs/story-993-walkthrough.html+125
src/pramaan_agents/db/store.py โ˜…+23 โˆ’5
src/pramaan_agents/runtime/app.py โ˜…+33 โˆ’2
src/pramaan_agents/runtime/failure_envelope.py โ˜…+244
src/pramaan_agents/runtime/strands_harness.py+18 โˆ’7
tests/runtime/test_failure_envelope.py+44
tests/test_reducer_events.py+13
tests/test_runtime_handler.py+132 โˆ’2