Skip to content

feat(BA-5864): Add KernelStatusData Pydantic model for unified status_data envelope#11338

Open
rapsealk wants to merge 2 commits intomainfrom
feat/kernel-status-data-model
Open

feat(BA-5864): Add KernelStatusData Pydantic model for unified status_data envelope#11338
rapsealk wants to merge 2 commits intomainfrom
feat/kernel-status-data-model

Conversation

@rapsealk
Copy link
Copy Markdown
Member

@rapsealk rapsealk commented Apr 27, 2026

Summary

  • Introduce typed Pydantic models for the kernel/session status_data payload under common/dto/manager/v2/status_data/: KernelStatusBranch, SessionStatusBranch, SchedulerStatusBranch (with SchedulingPredicateInfo), ErrorDetailInfo, and the top-level KernelStatusData envelope.
  • Tolerantly parse both legacy error shapes (single dict and MultiAgentError collection form) into a flat errors: list[ErrorDetailInfo] canonical field.
  • Pure addition — no producer or consumer is wired to the model yet.

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 like event_dispatcher/handlers/session.py:232-235 to shape-sniff at runtime. This PR establishes the typed envelope; the producer/consumer migration follows in #11337.

Test plan

  • pants fmt --changed-since=HEAD~1
  • pants fix --changed-since=HEAD~1
  • pants lint --changed-since=HEAD~1
  • pants check --changed-since=HEAD~1
  • pants test --changed-since=HEAD~1 — 12 cases, including legacy single-error parse, MultiAgentError collection flattening, mixed precedence, full-envelope round-trip, unknown-key tolerance, serialization shape.

Follow-up

🤖 Generated with Claude Code

…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>
@rapsealk rapsealk added this to the 26.5 milestone Apr 27, 2026
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions github-actions Bot added size:L 100~500 LoC comp:common Related to Common component labels Apr 27, 2026
@rapsealk rapsealk changed the title feat(common.dto): add KernelStatusData Pydantic model for unified status_data envelope feat(BA-5864): Add KernelStatusData Pydantic model for unified status_data envelope Apr 27, 2026
@rapsealk rapsealk marked this pull request as ready for review April 27, 2026 06:16
Copilot AI review requested due to automatic review settings April 27, 2026 06:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 KernelStatusData and branch sub-models (kernel, session, scheduler) plus canonical errors: 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 errorerrors 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"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:common Related to Common component size:L 100~500 LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Define KernelStatusData Pydantic model in common/dto/manager/v2/

2 participants