Skip to content

Derive the Console API's OpenAPI response schemas from the Rust response types #1865

Open

Description

@JacobStephens2

This was generated by AI during triage.

Problem

The Console's OpenAPI description (/api/v1/openapi.json, thirdshift console openapi) describes each 200 response with a schema written by hand in src/console/openapi.rs (about 500 lines of json!). Those schemas are a second copy of the Serialize types the handlers actually return, and nothing checks that the two agree:

  • Some schemas duplicate a real type field by field. For example, the View::Whoami arm restates Whoami in src/console/identity.rs. If a field is added to or renamed in the struct, the published description goes stale silently.
  • Many views fall back to {"type": "object"}, array(record) or {"type": "string"} (Evals, RecordDifficulty, Rechecks, RenameExperiment and others). A client author learns nothing about their shape, which is the reason Spec: the Console API, /api/v1 behind scoped tokens #1753's user story 39 asked for a description at all.
  • openapi_equals_cli_and_describes_operations_without_local_secrets in tests/console/api.rs checks that the description matches the CLI, lists the routes, and has a schema object per operation. It never checks a response against that schema.

#1753 suggested generating the description "for example with utoipa". The implementation kept the route table as the source of operations (ADR 0026) but hand-wrote the response schemas.

Proposal

Derive each API response schema from the Rust type the handler serializes, and test real responses against the published description.

  • Derive a JSON Schema for each /api/v1 response type: schemars::JsonSchema, or utoipa::ToSchema (OpenAPI-native, as Spec: the Console API, /api/v1 behind scoped tokens #1753 suggested). Pick one in the PR and say why. Replace the hand-written per-View schemas in operation() with the derived ones, keeping the route table as the source of paths, scopes and CLI twins.
  • Responses that are genuinely free-form text (help, version, process output) can stay {"type": "string"}.
  • Add a test that validates each API endpoint's actual JSON response (from the existing Console test fixtures) against the schema the description publishes for it, so a type change that isn't reflected fails CI.

Context

The TypeScript prototype (#1839, docs/research/typescript-vs-rust.md, "Console velocity and type sharing") showed one contract shared by CLI, server, browser and tests through Zod. That report noted Rust could get partway there with schemars. This issue takes the server-side part of that. Generating TypeScript declarations (ts-rs) is out of scope: the Console's browser assets are plain JavaScript, so nothing would consume them.

Acceptance

  • No per-View response schema in src/console/openapi.rs restates a struct by hand. Shapes come from derives on the returned types.
  • Views that currently publish {"type": "object"} for a structured response publish the real shape.
  • A test fails when an endpoint's response does not validate against its published schema.
  • thirdshift console openapi and /api/v1/openapi.json stay equal, and secrets stay out of the description.

Activity

  1. added
    enhancement
    needs-triage
    in-progress
    and removed
    needs-triage
    on Nov 9, 2026
  2. JacobStephens2 commented on Nov 11, 2026

    @JacobStephens2
    OwnerAuthor

    This was generated by AI during triage.

    Investigation summary

    Investigated existing issue #1865 against main at dbdd894. The reported duplication and incomplete response descriptions are confirmed. Recommend shaping this as a Spec with Tickets before implementation because it spans 65 published operations across 60 paths, including recursive Command responses, Fleet passthrough and deeply nested Experiment responses.

    Evidence:

    • src/console/openapi.rs:116-284 manually describes each View's success response; Whoami repeats src/console/identity.rs:33. The setting, tree, span and experiment helpers also duplicate response fields.
    • An isolated Console returned address, allowed_emails, fleet, hidden_sections, other_accounts, port and theme from GET /api/v1/look, while its published schema was exactly {"type":"object"}. The handler serializes ConsoleSettings in src/console/look.rs:141; the type lives in src/config/console.rs:136.
    • Several apparently opaque handlers already serialize concrete types upstream: Suite in src/evals/suite.rs:66, Reading in src/evals/experiment/difficulty.rs:14, PendingList in src/evals/experiment/rechecks.rs:29 and View in src/evals/experiment/store.rs:46. Deriving a schema for their intermediate serde_json::Value would leave the problem unresolved.
    • Fleet Document deliberately retains commands as Vec and flattened metadata in src/logs/status/fleet.rs:17; InboxItem is recursive and flattened in src/logs/reading/inbox.rs:128. These need careful schema integration that preserves existing serialized output and extensibility.
    • The issue's cited OpenAPI test does not validate responses. A newer test, experiments::openapi_experiment_format_matches_served_list_and_detail, compares the format constant with a real response, but does not validate the whole response.

    Validation: cargo test --locked --test console openapi -- --nocapture passed both tests. Isolated HTTP and CLI OpenAPI documents were equal. scripts/affected-tests main reported no changed files and no affected tests.

    Implementation constraints: preserve ADR 0026's route-table ownership of operations, scopes and CLI twins; derive serialization-facing shapes, including omitted fields and variants; retain genuine text responses and genuinely dynamic values; keep credentials and local records out of schema generation. Library selection remains delegated to implementation as requested. No current response/schema incompatibility was established; the confirmed problem is incomplete contracts and missing comprehensive validation.

    Questionnaire

    For the Day shift: #1865's incomplete response schemas are confirmed, including a seven-field /api/v1/look response documented only as an object. Completing the acceptance criteria spans 65 operations and response types across several domains.

    1. Approve shaping Derive the Console API's OpenAPI response schemas from the Rust response types #1865 as a Spec with the following five Tickets and dependencies, or identify the scope to change. This resolves whether the full migration should proceed as coordinated work:

    A. Establish derived-schema generation, reference handling and reusable response validation through Whoami end to end. Select schemars or utoipa with a documented rationale; cover identity variants, serialization omissions, CLI/HTTP equality, secret exclusion and rejection of an incompatible response.

    B. Migrate Command and observation responses: status aliases, Fleet, inspection, metrics, spans, logs, Stop and Dismissal. Describe known local structure while preserving deliberate passthrough metadata and recursive output. Add response validation alongside existing fixtures. Blocked by A.

    C. Migrate Eval and Experiment reads and actions using their actual serialized types, including Difficulty, rechecks, pairwise views and nested results. Validate populated and relevant optional/variant responses. Blocked by A.

    D. Migrate remaining operations, including configuration, look/themes, resources, start results/options, process and utility responses, and the OpenAPI document response itself. Preserve genuine text and dynamic values; add fixture validation. Blocked by A.

    E. Complete a coverage inventory checked against every published path/method, close fixture gaps, remove remaining hand-written structured response shapes, and run the required repository checks. Blocked by B, C and D.

    Keep each migration Ticket responsible for its own validation so it is independently reviewable. TypeScript declarations remain out of scope. This questionnaire proposes publication only; no Spec or Tickets were created during investigation.

  3. added
    ready-for-human
    and removed
    in-progress
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementready-for-human

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions