lablup / lablup/backend.ai

Normalize status_data.error to list[ErrorDetail]

Open
#11,337 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
670
Forks
183
Avg merge
15h 13m
Merged PRs (30d)
368

Description

Sub-issue of #679.

## Goal

Eliminate the dual-shape `status_data.error` payload (single dict vs. `{collection: [...]`} for `MultiAgentError`) by always emitting a flat `errors: list[ErrorDetail]`.

## Background

Currently `src/ai/backend/manager/exceptions.py:101-143` (`convert_to_status_data`) produces one of two incompatible shapes depending on whether the cause is a `MultiAgentError`. Consumers must shape-sniff at runtime — see `src/ai/backend/manager/event_dispatcher/handlers/session.py:232-235`:

```python
if status_data["error"]["name"] == "MultiAgentError":
errors = status_data["error"]["collection"]
else:
errors = [status_data["error"]]
```

## Scope

**Backward-compatible rollout** (so backend.ai-webui can migrate independently):

1. Modify `convert_to_status_data` to return both:
- The legacy `error: ErrorDetail` field (unchanged, for backward compat)
- A new `errors: list[ErrorDetail]` field (always flat — single errors are a 1-element list, `MultiAgentError` is the flattened collection)
1. Update the manager-internal consumer at `event_dispatcher/handlers/session.py:232-235` to read `errors` first, fall back to shape-sniffing only if missing.
1. Add deprecation note for the legacy `error` field; plan removal in a later release after backend.ai-webui migrates.

## Non-goals

- DB row migration of historical `status_data` entries (separate sub-issue, see #679 Step 4).
- Exposing the typed schema in v2 DTOs (separate sub-issue, see #679 Step 6).
- backend.ai-webui changes (separate sub-issue, see #679 Step 7).

## Acceptance criteria

- [ ] `convert_to_status_data` always emits `errors: list[ErrorDetail]` in addition to legacy `error`.
- [ ] `event_dispatcher/handlers/session.py` consumes `errors` first.
- [ ] Tests cover: single error → 1-element list; `MultiAgentError` → flattened list; debug mode preserves traceback / agent_id per entry.
- [ ] Pants quality gates pass.
- [ ] PR description flags follow-up work for webui coordination.

JIRA Issue: BA-5865

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.