Skip to content

Map task run failure into the run-result envelope error field - #491

Merged
chubes4 merged 3 commits into
Automattic:mainfrom
lezama:fix/task-run-envelope-error-mapping
Aug 26, 2026
Merged

Map task run failure into the run-result envelope error field#491
chubes4 merged 3 commits into
Automattic:mainfrom
lezama:fix/task-run-envelope-error-mapping

Conversation

@lezama

@lezama lezama commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Task run results use the canonical run-result envelope, but failed task runs stored their failure details under diagnostics while the converter always emitted an empty error. This left task failures inconsistent with the runtime and workflow envelope producers.

Fix

  • Map failed task diagnostics into the canonical envelope error field.
  • Map error_code and error_message to error.code and error.message, preserving the raw diagnostics under error.data.diagnostics.
  • Use deterministic agents_task_run_failed / The task run failed. fallbacks when diagnostics are missing.
  • Keep successful and other non-failed runs' error empty.
  • Populate cancellation state for cancelling/cancelled runs without claiming updated_at is the cancellation request time; no persisted request timestamp currently exists.
  • Remove the dead task evidence_refs read, which had no normalized source.
  • Leave the raw task result contract unchanged; the mapping applies only when converting to the canonical envelope.

Testing

  • php tests/run-result-envelope-smoke.php - 36 assertions passed.
  • php tests/task-execution-smoke.php - 59 assertions passed; raw task behavior unchanged.
  • composer test - passed.
  • composer phpstan - no errors.
  • git diff --check - clean.

lezama and others added 3 commits August 6, 2026 17:37
The task converter was the only run-result envelope producer whose `error`
and `cancellation` fields were permanently empty. `to_run_result_envelope()`
read `$normalized['error']`, `$normalized['cancellation']`, and
`$normalized['evidence_refs']`, but `normalize_run()` whitelists keys and never
emits any of those three — so they always fell through to empty defaults. A
`STATUS_FAILED` task run stores its failure under `diagnostics` (see
`agents_run_task`), which was never mapped to `envelope.error`, so failed task
runs carried no error at all.

Make the contract honest, mirroring the Runtime/Workflow producers that carry
their own error map:

- Map a failed run's `diagnostics` (error_code/error_message + raw diagnostics)
  into the canonical `envelope.error`, guaranteeing failed runs always carry a
  non-empty error.
- Populate `cancellation` from the run status for cancelling/cancelled runs.
- Drop the dead `evidence_refs` read (normalize_run has no such source).
- Keep successful runs with empty error and empty cancellation.

Adds smoke coverage asserting a failed run produces a non-empty error carrying
the diagnostics, a cancelled run populates cancellation, and a successful run
stays empty.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@chubes4
chubes4 marked this pull request as ready for review August 26, 2026 21:51
@chubes4
chubes4 merged commit d269bc5 into Automattic:main Aug 26, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants