Skip to content

feat(api): typed response structs, batch 1 — jobs/tasks (#1191) - #1190

Merged
athvin merged 5 commits into
mainfrom
issue/864-typed-responses
Nov 24, 2026
Merged

athvin merged 5 commits into
mainfrom
issue/864-typed-responses

Conversation

@athvin

@athvin athvin commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Closes #1191

Part of #864 (batch 1 of 10: jobs/tasks).

🚧 Claimed by an agent session — 2026-11-23T23:47:09Z, session Claude Code:d1e3b2dc-3174-4091-9c30-c08fc4820306 on Mac.
The claim is this open draft PR: closing it releases the ticket.

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

Why

Proof

Risk & rollback

Post-merge ledger

Closed by: agent · session Claude Code:d1e3b2dc-3174-4091-9c30-c08fc4820306 on Mac · 2026-11-24T00:30:06Z

Specific to this change

Context — plan, discoveries, measurements, files

Plan

Batch 1 of #864 (jobs/tasks). Today a typed Json(LocalStruct {…}) classifies to the same keys-only envelope as json!, so converting handlers alone would add no schema. This batch builds the mechanism first, then converts.

  • er-api-spec: resolve each success Json(…) to a component when its type is registered. The forms are Json(Registered { … }), Json(XWire::from(…)) → X, and Json::<Vec<XWire>>(…) → array of X. A handler mixing typed and untyped success responses fails generation. classify_envelope treats the wire spellings as Bare, so envelopes.json does not change.
  • openapi.rs: emit $ref (or anyOf of refs) for typed responses and register the new response structs in ApiDoc.
  • Handlers: get_job, create_job, cancel_job → JobWire; list_jobs → JobList { jobs }; jobs_global → Vec<JobWire>; list_job_tasks → TaskList { tasks }; resume_job → ResumeAccepted; clear_job_task → ClearAccepted.
  • Proof: a serialization-equivalence test per converted shape (the old json! bytes equal the typed bytes); envelopes.json byte-identical; regenerated openapi.json, openapi.public.json and schema.d.ts; make check and make check-e2e.

Discoveries

The ticket's counts still hold on b809525f: 149 Json(json! sites and 27 Query<HashMap in er-server/src. Job and JobWire have identical fields in the same order (the job entity has no internal columns), so JobWire::from(&job) serializes to the same bytes as json!(job). #864 closes only after all ten batches, so it was split into sub-issues #1191–#1200 and each batch PR closes one.

Byte identity does not hold for record bodies, and cannot. The workspace's serde_json has no preserve_order, so every json! object, json!(job) included, emitted its keys sorted. A struct serializes in declaration order. So the converted Job and TaskInstance bodies carry every value unchanged, but their keys now arrive in the entity's declaration order. JSON object order carries no meaning and every consumer parses these bodies. Verification is therefore value equality per shape (response_shape_tests), plus byte equality for ResumeAccepted and ClearAccepted, whose fields are declared in sorted order.

JobList::from(iter) is not a form either reader resolves (the derivation saw it as untyped, and the ledger would have read scalar), so list_jobs builds JobList { jobs } as a literal.

Measurements

  • make check: exit 0, 1,138 tests passed, 0 failed.
  • ER_TEST_PG_DSN=… cargo test -p er-server --test main: 142 passed, 0 failed, 2 ignored (real Postgres, every job/task endpoint test included).
  • response_envelopes passes, so envelopes.json is byte-identical. Mutation: disabling the wire_value rule fails it (GET /v1/jobs [jobs_global]: no Json(...) … found).
  • Operations with a typed success schema: 0 → 8 of 119 (all eight jobs/tasks operations).
  • pg_task_instances pinned the task list's bytes; it now pins the parsed value, for the key-order reason above. That is the only test changed.

Files

@athvin athvin changed the title feat(api): typed response structs, batch 1 — jobs/tasks (#864) feat(api): typed response structs, batch 1 — jobs/tasks (#1191) Nov 23, 2026
bmoore813 and others added 4 commits November 23, 2026 16:00
A success Json(...) naming a registered type now becomes a component
reference in the generated document. Json(Name { .. }), Json(NameWire::from(..))
and Json::<Vec<NameWire>>(..) are supported; a handler mixing typed and untyped
success bodies fails generation. Response envelopes that are not entities
register on a separate ResponseDoc, so the entity-registration guards keep
their meaning.

Batch 1 of #864 converts get/create/cancel_job and jobs_global to JobWire,
list_jobs to JobList, list_job_tasks to TaskList, and resume_job and
clear_job_task to ResumeAccepted and ClearAccepted. envelopes.json is
unchanged. serde_json has no preserve_order, so a json! object sorted its keys:
the converted Job bodies keep every value but now emit keys in declaration
order. response_shape_tests pins value equality for each shape, and byte
equality where the fields were already sorted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The typed TaskList (#864) emits each row's keys in declaration order, where the
json! it replaced sorted them. The test's purpose is to pin every field and
value with token_hash removed, which the parsed value does without depending
on key order.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

The marketing preview was removed because this PR is closed or merged.

This branch was previously deployed

1 inactive deployment
marketing-preview — 90b879f0 Deployed Nov 24, 2026 by athvin via remove closed PR previews #22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#864 batch 1: typed responses for jobs/tasks

2 participants