Add JSON-representable kernel payload types and event conversion errors
- Dominant language
- Python
- Stars
- 670
- Forks
- 183
- Avg merge
- 15h 13m
- Merged PRs (30d)
- 368
Description
### Goal
Land the type and error definitions the event JSON cutover (BA-7315) needs, on their own. Nothing changes on the wire here, so this can merge and be reviewed without the cutover attached to it.
### Work
- Add ai.backend.common.data.kernel.types with KernelCreationInfo and its parts (ServicePortData, AttachedDeviceData, DeviceCapacityData, MountData, KernelResourceSpecData), every field JSON-representable and typed by what it holds rather than by str/Any.
- Give KernelResourceSpecData a to_resource_slot() that sums the per-device allocations, leaving a slot with no allocation out rather than recording it as zero.
- Add KernelResourceSpec.to_data() on the agent as the single conversion into that form, and drop to_json_serializable_dict() / to_json(), whose only caller is a log line. The removed pair also mis-rendered slots: the loop replaced the whole dict with a string instead of setting one key.
- Add EventPayloadEncodingError / EventPayloadDecodingError and raise them from AbstractEvent.to_message() / from_message(), so a caller sees one event-layer error instead of a Pydantic one. An event deriving BackendAISchema maps ValidationError to a BackendAIError of its own, so both forms have to be funnelled in.
- Add ErrorDomain.EVENT for those error codes.
### Done when
- The new types round-trip through JSON with no loss, including an unbounded (Infinity) allocation amount.
- to_message() / from_message() raise the event-layer errors, and no existing behaviour changes.
JIRA Issue: BA-7353
Contributor guide
Research direction
Start with ai.backend.common.data.kernel.types and the agent's KernelResourceSpec conversion entry point, then inspect AbstractEvent.to_message()/from_message(), BackendAISchema handling, and ErrorDomain. Verify that the new data types round-trip through JSON, preserve unbounded allocations, and that both event conversion paths expose the new event-layer errors without changing existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100