Deserialize unknown ActivityState variants leniently #110

Closed
opened 2026-08-24 19:32:19 +01:00 by naps62-yolo · 0 comments
Collaborator

docs/SIDEBAR.md states that a client receiving an ActivityState variant it does not know must render it as Idle rather than fail, and that Rust clients deserialize activity leniently. Nothing implements that half. ActivityState is a plain #[derive(Deserialize)] enum, so an unknown variant fails deserialization of the whole Session — an older TUI or CLI talking to a newer daemon drops every session in the snapshot, not just the unknown field.

Every other forward-compatibility hazard in this struct is already handled with #[serde(default)]; this one is not, and #105 is about to add a path that sets activity states from outside the daemon's own inference.

Make an unknown ActivityState deserialize to the neutral default instead of erroring, without silently swallowing a genuinely malformed payload elsewhere in Session. Cover it with a test that feeds a future variant name and asserts the session still parses.

The TypeScript mirror needs the same treatment: web/src/types.ts types activity as a union, so an unknown string is a type lie at runtime — the renderer must fall back to the neutral style rather than produce an uncoloured or undefined dot.

`docs/SIDEBAR.md` states that a client receiving an `ActivityState` variant it does not know must render it as `Idle` rather than fail, and that Rust clients deserialize activity leniently. Nothing implements that half. `ActivityState` is a plain `#[derive(Deserialize)]` enum, so an unknown variant fails deserialization of the whole `Session` — an older TUI or CLI talking to a newer daemon drops every session in the snapshot, not just the unknown field. Every other forward-compatibility hazard in this struct is already handled with `#[serde(default)]`; this one is not, and #105 is about to add a path that sets activity states from outside the daemon's own inference. Make an unknown `ActivityState` deserialize to the neutral default instead of erroring, without silently swallowing a genuinely malformed payload elsewhere in `Session`. Cover it with a test that feeds a future variant name and asserts the session still parses. The TypeScript mirror needs the same treatment: `web/src/types.ts` types `activity` as a union, so an unknown string is a type lie at runtime — the renderer must fall back to the neutral style rather than produce an uncoloured or undefined dot.
naps62-yolo added this to the Sidebar cards milestone 2026-08-24 19:32:19 +01:00
naps62-yolo added the area/protocoltype/fixdifficulty/easy labels 2026-08-24 19:32:19 +01:00
This repo is archived. You cannot comment on issues.
1 Participants
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: naps62/maestro#110