feat(BA-5864): Add KernelStatusData Pydantic model for unified status_data envelope#11338
feat(BA-5864): Add KernelStatusData Pydantic model for unified status_data envelope#11338rapsealk wants to merge 2 commits into
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>
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"] | ||
|
|
| class SchedulingPredicateInfo(BaseResponseModel): | ||
| """Single scheduling predicate evaluation result.""" | ||
|
|
||
| name: str = Field(description="Predicate identifier (e.g., 'reserved_time').") | ||
| msg: str | None = Field( | ||
| default=None, | ||
| description="Failure message; null when the predicate passed.", | ||
| ) |
There was a problem hiding this comment.
Why are you using a deprecated feature? Isn't it supposed to pass history information?
|
This PR has had no activity for 14 days and has been marked as stale. It will be closed on 2026-07-02 (in 14 days) if no further activity occurs. Push a commit or leave a comment to keep it open. |
|
This PR has been automatically closed because it had no activity for 14 days after being marked as stale. Feel free to reopen it if you intend to continue the work. |
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