← Back to Pull requests

feat(api): add the steward dataset upload route (P38) #210

Closed
unknown closed this pull request without merging on Nov 14, 2026 04:48 UTC
View on GitHub
unknown unknown commented on Nov 09, 2026 03:05 UTC
Author

What and why

Steward dataset upload: plan item P38 (docs/V1_PLAN.md), the "Upload" step of the dataset lifecycle in docs/PROJECT_SCOPE.md, towards definition-of-done item 1. Until now, research datasets could arrive only through connector syncs. With this change a steward uploads one from the browser, and a granted researcher queries it through the same grant, budget and disclosure gates.

  • Route. PUT /api/v1/datasets/{dataset} stores Parquet that the steward's browser sealed (steward-upload-v1|{tenant}|{dataset}|{object}), together with the snapshot manifest the browser also sealed. They become the dataset's new ADR 0003 snapshot: the object, then a plaintext record, then the manifest as the commit, then pruning of everything the new snapshot does not list. The tenant comes only from the token, and the route needs no query service. The body format and its parser are in platform_connectors::upload.

  • Namespace. Uploaded datasets use slugs with a reserved upload_ prefix, which no connector may use. Grants, listings, requests and SQL work unchanged (FROM upload_cohorts).

  • Record. Every snapshot, including a connector sync's, now writes a plaintext record before its manifest: the envelope suite, plus the declared row cap and schema for an upload. Pruning deletes superseded records.

  • Query. Each object opens under the info binding of its dataset's kind. The record is read before any key is released, and must name a suite this build reads. An upload's Parquet must match its declared schema and row cap, or the query fails with QueryError::DeclarationMismatch (502).

  • Catalog. publish_listing refuses a dataset the steward does not hold, meaning one with no committed snapshot. It returns 404 and emits a research.catalog denial. The "holds" check is one shared function (platform_connectors::snapshot::holds) for P39 to reuse. Since #204 the check is in ResearchService::publish_listing, so ResearchService::new and from_config take the app's vault.

  • Config. DATASET_MAX_MIB defaults to 64 and accepts 1 to 512; a value out of range refuses startup. The default is a placeholder until P34 and P40 measure the browser upload.

  • Fuzzing. A new upload_body target, added to the weekly matrix.

  • ADR 0012 (Accepted) records the decisions: the namespace; the storage layout with its create-only record and commit, with keys/{version}/ reserved for ADR 0004's wrapped data keys; who chooses each id and who seals what; why the declared schema is plaintext; the size limit; and the "holds" rule.
  • Changes to existing behaviour:

  • Connector snapshots now store one more small file, the record.

  • A query whose snapshot has no valid record, or whose manifest lists a missing object, now returns 502. A missing object used to return 404.

  • Publishing a dataset that has no committed snapshot now returns 404.

  • A snapshot version keeps the first record stored for it and can be committed only once, because the record and the manifest are both written create-only. A second commit at the same version gets 409, and so does a write that declares another record for it (another row cap, schema or suite). A retry that declares the same record goes through. Connector syncs use a new version each time, so they are unaffected.
  • For reviewers:

  • ADR number: this is 0012 because main now has 0009 to 0011 and no open branch uses 0012. Renumber it if you reserve numbers differently.

  • Code owners: platform-crypto/src/lib.rs (public check_envelope_frame, plus EnvelopeSuite::id, from_id and min_frame_bytes) and .github/workflows/fuzz.yml.

  • Maintainer's call: the note on the Upload row of docs/PROJECT_SCOPE.md.

  • Overlap with #228: both change snapshot.rs, and #228 also changes the EnvelopeSuite helpers this uses and the simulated TEE script's HPK1 check. Whichever lands second reconciles them.

  • Out of scope:

  • - the dataset listing route (P39);
    - browser sealing and the upload form (P40);
    - deleting a dataset (P42);
    - query resource limits (P52);
    - whether a declaration mismatch costs research budget (P54). Today it does, because the charge comes before decryption.

    How it was tested

    New tests:

  • platform-api/tests/dataset_upload_api.rs (14 tests):

  • - an upload is stored as ciphertext and is queryable;
    - 401 with no token, and with a preauth or refresh token;
    - 422 for malformed bodies: empty, not an upload, truncated, object cut to 20 bytes, unknown suite;
    - 413 for an object over the dataset limit, and for a body over the request limit;
    - 422 for a declared schema unlike the recorded one;
    - 409 for a stale version or a retried body, and 422 for a version an hour ahead of the server clock;
    - 404 outside the upload_ namespace, and 400 for an invalid dataset id;
    - a re-upload replaces the snapshot: one manifest, one record and one object remain, and counts are not doubled;
    - a partial upload is never visible: when the manifest write fails the route returns 503, queries still read the previous snapshot, and the next upload prunes the leftovers;
    - a retry at the same version replaces an attempt that stopped before its manifest if it declares the same record. A body declaring another row cap gets 409 and leaves the stored record. The matching retry commits and prunes both earlier objects, and sending the version again gets 409;
    - 503 with Retry-After when a storage put or list fails;
    - tenant isolation: the same dataset name under two tenants, and a body sealed for one tenant, stored under another, never opens (502);
    - data unlike its declared schema or row cap is refused in the enclave (502);
    - a manifest that lists a missing object fails closed (502).
  • research_api.rs: upload through the route, grant, then the researcher's aggregate query succeeds with the small cohort suppressed.

  • catalog_api.rs: publishing is refused (404) before any upload, for a connector with no data, and for another tenant; it succeeds after an upload.

  • audit_coverage.rs:

  • - upload ok, committed and pruned, including a leftover object at the committed version (uncommitted_objects);
    - upload denials: bad_magic, stale_version, not_upload_dataset;
    - the refused publish;
    - no declared column name in the audit stream;
    - connector commit and prune keep their connector= detail.
  • envelope_vectors.rs: the committed wrong-magic and truncated-frame vectors are refused by the route (422).

  • token_types.rs: the upload route is added to ROUTES.

  • query_api.rs: superseded records are pruned, and a snapshot without its record, or with a record naming a suite this build cannot read, fails closed (502).

  • pipeline_e2e.rs: stored-file counts include the record, and a connector snapshot's record holds only its suite.

  • Unit tests:

  • - platform-core: namespace kinds, version write times, schema validation;
    - platform-crypto: the frame check, including a 20-byte HPK1 prefix, and suite ids;
    - platform-config: DATASET_MAX_MIB bounds;
    - platform-storage: record paths, parsing and refusals;
    - quackxide-engine: declared schema and row-cap mismatches, an error that names no column, and type families;
    - platform-connectors: a table of body-parser refusals, the size-limit boundary, commit order, re-upload, a same-version retry that keeps the failed attempt's record and prunes its object, a version another write committed first (409), a version another write recorded differently (409 before the manifest, its record kept), a stored record that is never replaced, with only an equal one going through (write_record), stale and too-far-ahead versions, schema mismatch, an unreadable record, namespace refusals, record pruning, and property tests.

    scripts/check.sh passes locally, run with the Node version in .nvmrc.

    Not covered:

  • The upload_body fuzz target compiles (CI's fuzz-build check) but was not run locally, because there is no nightly toolchain or cargo-fuzz here. It runs weekly in CI.

  • An upload's prune_failed event is emitted but not asserted in audit_coverage.rs.

  • The 502 for an unreadable record at upload time is tested in platform-connectors (an_unreadable_record_fails_closed), not through the route.

  • The create-only record and manifest writes were not run against a real GCS bucket. They use the same put_if_absent the drive manifests rely on.

  • gitleaks is not installed locally; CI runs it.
  • Checklist

  • scripts/check.sh passes locally

  • Every new refusal has a negative test

  • Every new security decision emits a SECURITY_AUDIT_EVENT covered by audit_coverage.rs

  • Fails closed on missing configuration, key material, or attestation

  • No new cryptographic primitives; suites stay behind their type aliases

  • Synthetic or public data only (docs/DATA_POLICY.md)

  • Docs and CHANGELOG.md updated for user-visible changes

  • Architectural decision recorded in docs/adr/ if one was made
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: abendrothj Review duration: 7303m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #210"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%