Skip to content

feat(api): /api/v1 projects, states, labels and work items with the oracle gate on those operations #58

Closed

Description

@aRustyDev

Context

No wire-compatible route exists. thrust_api::router() (crates/thrust-api/src/lib.rs:269-293) puts only the slice's non-Plane routes under /api/v1 (:278-291), and #47 moves them out. Requests authenticate with Authorization: Bearer through the SessionStore (:82-99), not with X-Api-Key. Errors use a Thrust shape, {"error":{"code","message"}} (:47-49), and every authentication failure is a 401 (:54). The schema has projects (id, workspace_id, name) and a work_items table with no state, priority, labels, assignees, parent or dates (crates/thrust-adapters-postgres/migrations/0001_init.sql:4-8,26-41), and no states or labels table. Spike 0008 (bead plane-b6a) built the v1 oracle as the schema, an exception register and a golden corpus (research/0005; ADR-0122 round 26). The oracle exists only on a local, unpushed branch of the Plane fork, feat/plane-b6a-upstream-sync-oracle (research/0005:4-5; Q-0122.4, QUESTIONS.md:293), and it has only ever run against Plane.

Problem

  • M1 includes /api/v1 for projects, states, labels and work items, with the oracle gate on those operations (review §3, FR-01). ADR-0031 keeps v1 wire-compatible and confirms it with the oracle (lines 23, 39). ADR-0032 requires a CI breaking-change diff of the code-first schema (line 41). That diff is not done yet because it "needs the Rust v1 slice" (line 70).
  • In the pinned schema (oracle/schema/openapi.v1.json, 130 operations), these resources are the tags Projects (8), States (5), Labels (5) and Work Items (14): 32 operations, including both the issues/ and work-items/ families, search and lookup by identifier. The fuzzer skips seven of them (the six DELETEs and archive, under SX-001 and SX-002, oracle/exceptions.yaml:25-44). The corpus covers six of those seven; it has no exchange for DELETE .../issues/{pk}/.
  • The gate cannot be pointed at a partial implementation as it stands. run_conformance.py runs the whole schema (:56-80), a register entry that matches nothing fails as stale, and the vacuity floors are sized for the full surface (:205-212; exceptions.yaml:22-23: 100 operations tested, 40 with a 2xx). Only seven of the 12 entries touch the 32 operations (EX-001 to EX-004, EX-006, EX-007, EX-011), so the other five would go stale. Staleness is also counted per entry, so reproducing a quirk on one of an entry's operations hides its absence on the others.
  • The owner chose to reproduce these quirks (ADR-0031 lines 64-74; ADR-0033 lines 79, 83). Only a missing key gets 401; an invalid, expired or inactive key gets 403 {"detail":"Given API token is not valid"} (Plane apps/api/plane/api/middleware/api_authentication.py:32-38). Error bodies come in two shapes. State create returns 200. A per_page of 0 or −1, and some work-item create payloads, give 500 (EX-001, EX-002). ADR-0052 still says "revoke key → 401" (line 53).
  • Every in-scope corpus exchange that passes authentication and permissions carries x-ratelimit-remaining and x-ratelimit-reset; the 401 and 403 answers carry neither (oracle/NORMALISATION.md:23; Plane apps/api/plane/api/rate_limit.py:47-48, default 60/minute at settings/common.py:154). The port can report remaining (crates/thrust-ports/src/lib.rs:208-211). The Workers Rate Limiting binding (ADR-0033, round-29 note) reports only whether a request is allowed.

Proposal

  • Routes: serve the 32 operations under /api/v1/workspaces/{slug}/ as a thin surface over thrust-core use-cases (ADR-0031 line 60). The project and work-item use-cases are shared with feat(compat): the 48-route minimum slice with the auth-client JSON change #44; the state and label use-cases are new. Each one runs on a &Scope from authorize (feat(core): make Scope the argument of every repository and Tx method #35), with the workspace resolved from {slug} through membership (feat(core): user-only Principal, database-authoritative sessions, delete KvSessionStore #36).
  • Schema and types: add workspaces (with slug), workspace_members, api_tokens, states and labels, plus the work-item columns and join tables the v1 serializers return. Plane-shaped DTOs, the pagination envelope and error bodies stay out of thrust-contracts (the rule from chore(contracts): keep compat DTOs out of thrust-contracts; add the check-deps.sh rule #52). A reproduced 500 goes through plane_500() from chore(api): one plane_500() helper for reproduced 500s; compat parity scoped to the acceptance list #51, or is a handled 500 with the pinned body, never a panic (ADR-0031 line 74).
  • Auth: look up X-Api-Key by its SHA-256 hash (ADR-0052 K1; spike(auth): the two-day Rust auth slice (argon2id, sessions, CSRF, API keys, one OIDC login) #38 tries this shape). Return 401 for a missing key, and 403 with Plane's body for an invalid, expired or inactive one. Rate-limit per key; a 429 carries {"error_code":5900,"error_message":"RATE_LIMIT_EXCEEDED"} and Retry-After. Send X-RateLimit-Remaining and X-RateLimit-Reset on every response that passes authentication and permissions. On Cloudflare the binding does not report these values, so they are derived; if the countdown cannot match Plane's, record a deviation.
  • Harness home: vendor oracle/ from the fork branch into tools/oracle-v1/ with a SOURCE file that names the commit, or push the branch instead (the owner decides, Q-0122.4). Either way, add the harness to the ADR-0006 tooling register; the uv rule applies.
  • Scoped gate: run_conformance.py --scope m1 passes Schemathesis --include-tag for the four tags (the script already passes --exclude-method and --exclude-path-regex, :77,79). It restricts the register to the in-scope operations, counts staleness per (entry, operation), and uses floors measured on Plane for this scope.
  • Seed and corpus:
    • A fixture loaded through /internal/seed (crates/thrust-api/src/lib.rs:150-156) reproduces the uuid5 ids, names and seven tokens of oracle/scripts/seed.py, so seed-manifest.json applies unchanged. Before every gate and control run, a reset script loads the fixture again.
    • record_corpus.py --only (:427) records against Thrust, and the result is compared exchange by exchange with the committed corpus for the in-scope operations. Add the missing DELETE .../issues/{pk}/ exchange to the corpus, recorded on Plane first.
    • scripts/oracle-v1.sh <target> runs the gate and the corpus comparison, and is one of the planned cells of gate.
  • Schema diff: generate the 32 operations with utoipa, then run oasdiff breaking against the pinned schema restricted to those operations. The EX-006 nullables are recorded exceptions. Never pass --open.

Acceptance criteria

  • scripts/oracle-v1.sh native-pg and scripts/oracle-v1.sh worker-cf end in VERDICT: PASS with unaccepted=0, stale=0 (per entry and operation) and the scoped floors met. The same scoped run against Plane passes too.
  • Control: with run_controls.py --upstream <thrust>, the gate fails C1, C2 and C3 (each breaks one field of GET .../states/, run_controls.py:33-44) on that operation, and passes C0. The corpus comparison catches C4 (a dropped id, which the schema cannot see). The results are committed.
  • After normalisation, the corpus comparison shows no difference for the in-scope exchanges in projects, states, labels, work_items, pagination and errors. A run that compares zero exchanges fails. Control: making state create return 201 makes it fail.
  • Contract tests pass on all four targets: no key gives 401; a bogus, expired or inactive key gives 403 with Plane's body; a create by a guest gives 403.
  • oasdiff reports no breaking change for the 32 operations, and the generated schema is committed.
  • The four list endpoints stay within the round-trip budget from chore(worker): set placement.region = aws:us-east-1; add the 5-round-trip budget counter to the contract suite #39.

References

  • Review: .agents/plans/contrail/reviews/2026-10-19-fable-architecture-review.md (FR-01; §3 M1 row; FR-06)
  • ADR-0031 (lines 23, 39, 60, 64-74), ADR-0032 (lines 29, 41, 70), ADR-0122 (lines 44, 77-79, 86, 90), ADR-0033 (lines 31, 79, 83; round-29 note), ADR-0052 (line 53), ADR-0006 (register), ADR-0034 (round-29 note)
  • research/0005-oracle-harness.md (lines 4-5, 49-55, 64-72, 88-89); spikes/0008-v1-oracle-harness.md; FEATURES §A5 (FEATURES.md:88-91), F-X06 (:135); Q-0122, Q-0122.4, Q-0120.3, Q-0033.2; DEVIATIONS C-2 (DEVIATIONS.md:32), D-002, D-007, D-013
  • crates/thrust-api/src/lib.rs:47-49,54,82-99,150-156,269-293; crates/thrust-ports/src/lib.rs:208-211; crates/thrust-adapters-postgres/migrations/0001_init.sql:4-8,26-41
  • Plane fork branch feat/plane-b6a-upstream-sync-oracle (72b2e01497): oracle/exceptions.yaml:12-23,25-44,45-89; oracle/harness/run_conformance.py:56-80,205-212; oracle/harness/run_controls.py:33-44; oracle/harness/record_corpus.py:427; oracle/NORMALISATION.md:23; oracle/scripts/seed.py; oracle/corpus/seed-manifest.json
  • Plane oracle (oracle/v1-pin-20261018): apps/api/plane/api/middleware/api_authentication.py:32-38; apps/api/plane/api/rate_limit.py:12-48; apps/api/plane/settings/common.py:154

Blocked by: #35, #36, #47

Finding: FR-01

Activity

  1. added this to the M1 Walking skeleton milestone on Oct 20, 2026
  2. added
    area:app
    review:fable-2026-10-19
    on Oct 20, 2026
  3. aRustyDev commented on Oct 23, 2026

    @aRustyDev
    OwnerAuthor

    From the work on #47 (PR #75), which moves the slice's routes out of /api/v1 to /api/_slice: this issue is where the cleanup lands, so it belongs in #58's scope.

    When #58 serves /api/v1/workspaces/{slug}/... and the _slice routes are replaced:

    • delete the /api/_slice routes and SLICE_PREFIX (crates/thrust-api/src/lib.rs), and move the contract suite (wi_path, project_path, the matrix and the model) onto the new routes;
    • retire or rewrite the_slice_routes_are_gone_from_the_reserved_v1_prefix (crates/thrust-contract-tests/tests/contract.rs) in the same PR. It asserts that each slice route is a routing 404 through /api/v1, which stops being true once /api/v1 is live.

    #47's last bullet named #44 as the replacement. #44 supplies the compat routes under /api/ and /auth/, not the /api/v1 work-item routes, so the bullet has been corrected there.

    Also: PLAN.md now lists #35, #36 and #47 as #58's blockers, matching the issue body.

  4. aRustyDev commented on Oct 24, 2026

    @aRustyDev
    OwnerAuthor

    From spike 0002 (#37, PR #77): the slice's list route is unpaged, and that, not the database engine, decides whether the list target holds. Both engines pass the 300 ms list p95 on a realistic list and fail it on an unpaged one:

    List Postgres through Hyperdrive (worker-pg) SQLite in one Durable Object (worker-do)
    a 1,000-item project in a database of about 130k items, p95 at c=1 / c=8 161 / 220 ms 77 / 216 ms
    an unpaged 10,000-item project (about 5 MB), p95 at c=1 / c=8 642 / 1,231 ms 350 / 1,687 ms

    (Numbers are in research/0011-database-engine-cells.md once PR #77 merges, with their conditions: one client in Virginia, n=200 per cell.)

    The owner decided on 2026-10-24 to read the spike's list criterion on the realistic, paged list, so it passes. That makes paging a requirement of this issue's list routes rather than a property of the slice's. When #58 builds the /api/v1 list routes:

    • they page, in Plane's wire shape (the oracle gate will check that shape), instead of returning every row;
    • the 300 ms list p95 at 100k items is measured on a paged list, through the contract suite's bench, and a project the size of the 10,000-item case is part of that measurement;
    • the slice's unpaged GET .../work-items is deleted with the other _slice routes, as the earlier comment on this issue says.
  5. 51 remaining items

  6. aRustyDev commented on Nov 16, 2026

    @aRustyDev
    OwnerAuthor

    Closing on the owner's word. The six acceptance criteria are built, and the evidence for each is on docs/src/testing/status.md (G-24 the round-trip budget, G-25 the oracle gate, the corpus comparison and the schema diff, G-26 the move of the contract suite off the slice):

    Not part of the criteria, and not done here:

    • The slice's /api/_slice routes that have no Plane-shaped counterpart (sign-out-all, session, api-keys, the two activity feeds, attachments) and SLICE_PREFIX stay, as decided on 2026-11-11, until the counterparts exist (feat(compat): the M2 daily-use screens (acceptance list) with every other route stubbed and recorded #46).
    • ?expand=assignees sends two statements per distinct assignee: perf(api-v1): ?expand=assignees sends two statements per distinct assignee #123.
    • Four deviations are proposed in .agents/plans/contrail/DEVIATIONS.md and not yet confirmed (a form or multipart body is a 415: D-031 (5), D-032 (6), D-033 (11); D-030 (5) is the confirmed one for projects), and two register entries (SD-002, SD-003) rest on the pin's source and not on a recorded exchange. They are being decided.
    • The request bodies are described by hand-written types, so on the request side the diff compares the pin with a hand copy of it until each parser returns a typed struct. That is a separate series.
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

    area:appprio:p0review:fable-2026-10-19

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions