# serialization Output serialization, codecs. Generated by `make records` from the decisions whose `topic` (or `also`) is this one; edit the decisions, not this page. ## Current ### Pydantic - **Pydantic JSON Schema describes model types** (D59): Pydantic model descriptors store JSON Schema: serialization schemas for outputs, with every field always written required (not one excluded by a condition or a TypedDict's optional key), validation schemas for parameters. Python compares these with model, dataclass and plain types; Rust stores them. Compatibility requires proof that every output value is accepted; uncomparable constructs require identical schemas, references are followed, and errors name the field and constraints. - **Pydantic dates interoperate with schedr date types** (D60): Pydantic date/datetime/duration text and schedr’s corresponding tagged types fit each other both ways; the runner converts through Pydantic’s parsing and JSON validation. Plain strings do not fit date types without the appropriate schema format. A model’s naive datetime stays naive when read, but schedr refuses it when subsequently storing it as its own datetime, advising `AwareDatetime` or an explicit zone. - **Read Pydantic models back using JSON validation** (D111): The runner validates stored model data with model_validate_json. Schedr tags in the data are first written in Pydantic's JSON representation. ### Stored values - **Schedr refuses to store naive datetimes** (D63): A naive datetime passed on from a Pydantic model is refused when schedr stores it. The error suggests `AwareDatetime` or adding a time zone. - **Escape user dictionaries shaped like serialization tags** (D104): A user dict whose sole key is a serialization tag is stored inside a $dict escape. Output paths and literal dictionaries containing references pass through the escape. - **Stored numbers round-trip exactly within the 64-bit integer range** (D105): Floats round-trip to the same bits; integers outside -2**63 through 2**64 - 1 fail where written. The integer limit also applies to Literal integers and timedelta microseconds. - **Reject NUL in stored output strings and dictionary keys** (D106): The runner fails an attempt when an output string or dictionary key contains NUL. The error identifies the value at encoding time. - **Replace NUL in command output text with U+FFFD** (D110): The agent replaces NUL in ProcessResult stdout and stderr with U+FFFD. The log file keeps the original bytes. - **Build structures containing references as the parameter's type** (D112): Structured arguments containing references are built recursively as the parameter’s type. A union uses the first fitting member of the same shape; when only one member has that shape, its literals are checked at parse time. Missing or refused fields fail the attempt with input_mismatch. ### From other topics - Oversized task results fail before they are sent (D61, `protocol`; built M4.1e) - The master sends each mapped instance its elements (D76, `python-api`; built M4.3b) - Mapped outputs are stored per instance (D77, `outcomes`; built M4.3b) - Mapped product arguments vary in written order (D79, `python-api`; built M4.3b) - Replace NUL in database JSON strings and keys (D114, `state`; built M4.3e) - Durations may be given in weeks (D139, `task-context`; built M4.5a) - A whole number with a fraction fits an integer parameter (D140, `task-context`; built M4.5a) - The master checks duration formats as ISO 8601 (D141, `task-context`; built M4.5a) - Secret values are masked in outputs before storage (D167, `secrets`; built M4.6b) - Handles are masked before the journal and master (D222, `cleanup`; built M4.8a) ## Replaced None. ## Where in code - `crates/schedr-agent/src/agent.rs` (D167) - `crates/schedr-agent/src/agent.rs::fit_result` (D61) - `crates/schedr-agent/src/handles.rs::add` (D222) - `crates/schedr-agent/src/mask.rs::MaskSet` (D167) - `crates/schedr-agent/src/mask.rs::mask_json` (D167) - `crates/schedr-agent/src/output.rs::text` (D110) - `crates/schedr-db/src/attempts.rs` (D77) - `crates/schedr-db/src/query.rs::without_nul` (D114) - `crates/schedr-master/src/mapping.rs::Sources` (D77) - `crates/schedr-master/src/mapping.rs::coordinates` (D79) - `crates/schedr-master/src/mapping.rs::into_inputs` (D76) - `crates/schedr-master/src/params.rs` (D139) - `crates/schedr-master/src/params.rs::is_duration` (D141) - `crates/schedr-master/src/validate.rs::output_problems` (D61) - `crates/schedr-model/src/params.rs::duration_micros` (D139) - `crates/schedr-model/src/params.rs::whole` (D140) - `crates/schedr-model/src/task.rs` (D79) - `crates/schedr-model/src/types.rs` (D59) - `python/schedr/_model/tasks.py::ExpandProduct` (D79) - `python/schedr/_model/types.py` (D59) - `python/schedr/_serialization/codec.py::INTEGERS` (D105) - `python/schedr/_serialization/codec.py::_decode_time` (D60) - `python/schedr/_serialization/codec.py::_encode_time` (D63) - `python/schedr/_serialization/codec.py::_escape_tags` (D104) - `python/schedr/_serialization/codec.py::_text` (D106) - `python/schedr/_serialization/compatibility.py::assignment_problem` (D59) - `python/schedr/_serialization/models.py::parse_date` (D60) - `python/schedr/_serialization/models.py::validate` (D111) - `python/schedr/_serialization/schemas.py` (D60) - `python/schedr/_serialization/schemas.py::from_desc` (D59) - `python/schedr/runner/task.py` (D76) - `python/schedr/runner/task.py::build` (D112) ## Open None. Details and edge cases, with the reasons; read them before changing this: - archive/PROJECT.md: Output serialization