feat(BA-5864): Add KernelStatusData Pydantic model for unified status_data envelope#11338
Open
feat(BA-5864): Add KernelStatusData Pydantic model for unified status_data envelope#11338
Conversation
…tus_data envelope Introduce a typed Pydantic envelope for the kernel/session ``status_data`` payload (kernel, session, scheduler, error branches) under ``common/dto/manager/v2/status_data/``. The model tolerantly parses both legacy error shapes — single dict and ``MultiAgentError`` ``collection`` form — into a flat ``errors: list[ErrorDetailInfo]``, which becomes the canonical field going forward. This is purely additive: no producer or consumer is wired to it yet. Producer/consumer migration follows in #11337. Tracks #679 (BA-253). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new typed DTO module for the manager v2 status_data JSON envelope so consumers can rely on a unified schema (especially for error reporting) while still tolerantly parsing legacy error shapes during migration.
Changes:
- Introduce
KernelStatusDataand branch sub-models (kernel,session,scheduler) plus canonicalerrors: list[ErrorDetailInfo]normalization. - Add unit tests covering parsing/normalization behavior, round-trips, and unknown-key tolerance.
- Add a changelog entry documenting the new DTO surface.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ai/backend/common/dto/manager/v2/status_data/types.py | Adds the Pydantic models and legacy-to-canonical error → errors normalization. |
| src/ai/backend/common/dto/manager/v2/status_data/init.py | Exposes the new types from the status_data package. |
| tests/unit/common/dto/manager/v2/status_data/test_types.py | Validates branch parsing and legacy/new error-shape normalization behavior. |
| tests/unit/common/dto/manager/v2/status_data/BUILD | Registers the new unit test target with Pants. |
| tests/unit/common/dto/manager/v2/status_data/init.py | Marks the new test directory as a Python package. |
| changes/11338.feature.md | Documents the feature addition in release notes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def _normalize_legacy_error(cls, data: Any) -> Any: | ||
| if not isinstance(data, dict): | ||
| return data | ||
| if data.get("errors"): |
| } | ||
| data = KernelStatusData.model_validate(mixed) | ||
| assert [e.name for e in data.errors] == ["New"] | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
status_datapayload undercommon/dto/manager/v2/status_data/:KernelStatusBranch,SessionStatusBranch,SchedulerStatusBranch(withSchedulingPredicateInfo),ErrorDetailInfo, and the top-levelKernelStatusDataenvelope.errorshapes (single dict andMultiAgentErrorcollectionform) into a flaterrors: list[ErrorDetailInfo]canonical field.Closes #11336 (BA-5864). Sub-issue of #679 (BA-253).
Why
Today
status_data["error"]is emitted in two incompatible shapes (single dict vs.{name: 'MultiAgentError', collection: [...]}), forcing consumers likeevent_dispatcher/handlers/session.py:232-235to shape-sniff at runtime. This PR establishes the typed envelope; the producer/consumer migration follows in #11337.Test plan
pants fmt --changed-since=HEAD~1pants fix --changed-since=HEAD~1pants lint --changed-since=HEAD~1pants check --changed-since=HEAD~1pants test --changed-since=HEAD~1— 12 cases, including legacy single-error parse,MultiAgentErrorcollection flattening, mixed precedence, full-envelope round-trip, unknown-key tolerance, serialization shape.Follow-up
manager/exceptions.py:convert_to_status_data) and the consumer inevent_dispatcher/handlers/session.pyto emit/read the newerrorslist with backward-compat for the legacyerrorfield.🤖 Generated with Claude Code