Skip to content

Phase D2: Compute user API and read commands - #2072

Merged
neuromechanist merged 13 commits into
feature/issue-2021-epic-compute-usersfrom
feature/issue-2023-compute-user-api
Nov 7, 2026
Merged

neuromechanist merged 13 commits into
feature/issue-2021-epic-compute-usersfrom
feature/issue-2023-compute-user-api

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Phase D2 of epic #2021 (issue #2023): the /compute read routes, their credential rule, queue estimates, the wire contract and nemar compute balance|limits|queue|list|status. Base is the epic branch feature/issue-2021-epic-compute-users, not dev.

The router backend/src/routes/compute.ts became the directory backend/src/routes/compute/ (index.ts is the old file, auth.ts the credential rule, read.ts the five read routes), so phases D3 and D4 can add their own register* file beside them.

Routes (for website phases E1 and E2)

All are GETs. Refusals are { error: <sentence>, code: <word> }. Times are YYYY-MM-DD HH:MM:SS (UTC), days YYYY-MM-DD (UTC), money whole milli-SU integers. Every response schema is open and lives in shared/contract/compute-user.ts (also exported from shared/contract/index.ts).

  • GET /compute/me (ComputeMeResponseSchema): access { state, requested_at, granted_at, terms_version, current_terms_version, terms_published, requests_open? }, pools { cpu, gpu } each { granted_milli, held_milli, charged_milli, available_milli }, frozen, limits { partitions[{ name, pool, max_nodes, max_cores_per_node, max_gpus_per_node, max_minutes }], max_live_jobs, results_days }, queue[{ partition, median_seconds, p90_seconds, count, window_days }]. Answers in every access state.
  • GET /compute/me/usage?from=&to=&group= (ComputeUsageResponseSchema): { from, to, group[], rows[{ day?, app?, partition?, source?, charged_milli, jobs }] }.
  • GET /compute/me/jobs?state=&limit=&after= (ComputeUserJobsResponseSchema): { jobs[], next_after }; the cursor is YYYY-MM-DDTHH:MM:SS|<job id>.
  • GET /compute/me/jobs/:id (ComputeUserJobResponseSchema): { job, stale? }.
  • GET /compute/stats?from=&to= (ComputeStatsResponseSchema): { from, to, by_day_partition_source[{ day, partition, source, charged_milli, jobs }], active_people, jobs_by_outcome { finished, failed, cancelled } }.
  • Job view (ComputeUserJobSchema): id, kind, source, state, app_id, app_version, partition, pool, resources { nodes, cores_per_node, memory_mb, gpus, minutes }, created_at, started_at, ended_at, charged_milli, failure_code, cancel_requested.

Error codes (COMPUTE_USER_ERROR_STATUS): forbidden_credential 403, insufficient_scope 403, invalid_token 401, missing_credential 401, invalid_range 400, invalid_group 400, invalid_state 400, invalid_limit 400, invalid_cursor 400, job_not_found 404, policy_unavailable 503.

Credentials and scopes (ADR 0119 amendment)

  • /compute/me*: a CLI key, the session cookie, or an OIDC access token carrying compute.read (live account rule, read at every call). A token without the scope is 403 insufficient_scope with the scope in the challenge. A client credentials token is not a person.
  • /compute/stats: only a client credentials access token carrying compute.stats. A CLI key is 403 forbidden_credential (answered the same for a valid and an invalid key), a person's token is 403 forbidden_credential before its scope is judged, no Authorization header is 401 missing_credential.
  • Every other route still refuses an OIDC token. oidc-token-allowlist.test.ts lists exactly these five paths; compute-route-inventory.test.ts pins each route's guard and the scope of each oidcBearer instance.

Exposure rules

  • A person's job view is built from a narrow column list: no flag, no platform_failure, no failure detail, no cancel reason, no Slurm or Tapis id, no pseudonym, no hold figure, no client, no purpose, no identity. A test pins the exact key list and walks the wire.
  • Another person's job id, an absent id and a malformed id are one 404 job_not_found, as for cancel and links. A swept (unreserved) job is nobody's to read.
  • The stats body has no account, subject, name, email, pseudonym, Tapis owner or client (a test walks keys and values).
  • No route reads the compute switch; the reads work with compute off.

CLI

nemar compute balance|limits|queue|list [--state] [--limit] [--all]|status <job>, each with --json (the Worker's answer only) and an "Exit codes:" block; SU with three decimals from integers. API client: getComputeMe, getComputeUsage, listMyComputeJobs, getMyComputeJob (named ...My... because listComputeJobs is already the administrator's).

Migration 0132 and EXPLAIN QUERY PLAN

A migration was needed for four statements; a person's own usage and job read were already covered. backend/test/compute-read-plans.test.ts keeps this evidence (fails on any scan of the jobs or the ledger).

Without 0132:

queue estimate      SCAN compute_jobs
partner usage       SCAN e USING INDEX compute_ledger_job
active people       SEARCH compute_jobs USING INDEX compute_jobs_account_created (account_id>?)   (every job)
jobs by outcome     SCAN compute_jobs

With 0132 (compute_jobs_queue_started, compute_jobs_created, compute_ledger_created, compute_jobs_account_created_id, partial on flag_unreserved = 0):

queue estimate      SEARCH compute_jobs USING INDEX compute_jobs_queue_started (partition=? AND started_at>?)
person usage        SEARCH e USING INDEX compute_ledger_pool (pool_id=?)
partner usage       SEARCH e USING INDEX compute_ledger_created (created_at>? AND created_at<?)
person jobs         SEARCH compute_jobs USING INDEX compute_jobs_account_created_id (account_id=? AND created_at<?)   (no sort; with only Epic A's index, ordering by (created_at, id) plans USE TEMP B-TREE FOR LAST TERM OF ORDER BY)
one job             SEARCH compute_jobs USING INDEX sqlite_autoindex_compute_jobs_1 (id=?)
active people       SEARCH compute_jobs USING INDEX compute_jobs_created (created_at>? AND created_at<?)
jobs by outcome     SEARCH compute_jobs USING INDEX compute_jobs_created (created_at>? AND created_at<?)

Where the phase issue differed from the merged code

  • The job view has no name: the specification's name is in the records bucket and the index row has no column for it. It carries app_id and app_version. Adding a column is a later phase's call.
  • limits has max_live_jobs instead of max_running and max_queued: the owner's policy has one number (maxLiveJobsPerPerson) for jobs created, queued or running together, and the wire does not invent a split.
  • access gains requests_open (false in exact production while the terms are unpublished), because terms_published alone would hide the request form on staging, where requests are taken.
  • The issue's migration number 0126 is 0132 (owner decision of 2026-11-06).
  • src/lib/api/compute.ts already had an administrator's listComputeJobs; the person's functions are listMyComputeJobs and getMyComputeJob.
  • active_people leaves out NEMAR's pipelines account and swept jobs (the issue said "distinct accounts with a job in the window"); a pipeline is a service account, not a person.
  • The refresh on GET /me/jobs/:id reads back only a live job that has a Tapis job (it never submits a created job, which would read the compute switch from a GET) and is skipped in the read-only maintenance mode, serving the stored record with stale: true.
  • Audience is not checked on the OIDC routes (ADR 0119 amendment, item 4).
  • Pool figures keep the wire names granted_milli, held_milli, charged_milli, available_milli (the administrator's contract names), not the *_milli_su names the issue wrote; the website phases transcribe the schema.
  • /compute/me/usage with an administrator's correction (no job) returns null for app, partition and source on that row so every grouping sums to the same total.

Gates

  • bun run lint, bun run typecheck (CLI and backend), bun run migrations:d1-check: clean on the final head.
  • Backend, one file at a time: compute-read-me 19, compute-read-usage 15, compute-read-jobs 12, compute-read-credentials 26, compute-read-refresh 8, compute-read-plans 12, compute-queue-estimates 15, compute-route-inventory 8, oidc-token-allowlist 6, all pass.
  • Root: compute-read-cli 21, compute-user-contract.unit 20, api-export-surface.unit 14, help-tiers.unit 12, compute-access-cli 27, contract-schemas 63, compute-admin-contract.unit 37, compute-responses-contract.unit 6, all pass.
  • Neighbours run and green: compute-source-scan, compute-switches-flag, compute-end-callers, compute-access-source-scan, oidc-bearer, compute-person-responses, compute-job-callbacks, compute-results-routes, compute-full-path, compute-lifecycle-money, and the other scan, inventory and callers suites.
  • Not run: the full suite (the epic gate), test/account-copy-parity.test.ts (known red until website#494). No mirrored account-copy key was added; the CLI uses existing keys.

Mutation results

Each guard was mutated one line at a time and the named suite run. A first run left survivors in these places and the tests were strengthened until they were killed: the ordering of the queue sample (a 15 percent tail now decides it), the calendar-day roll-over (2026-02-30 with a later to), the list's swept-job filter, the stats active_people swept-job filter (a swept job on an account with no other job), the zero-initialised outcomes (an empty window), the stale-refresh terminal and no-Tapis-job guards (a terminal job owed a copy; an old created job), and the forbidden_credential branches of the stats guard. Two queue conditions (IS NOT NULL on the two stamps) were redundant with the comparisons and the partial index, so they were removed. The scope check mutations (oidcBearer([]) on either guard) are killed by the credential matrix.

Not verified

No response of a real Tapis tenant was available; the refresh is tested against the existing stand-in. The design page admin/design/compute-gateway (section 6, usage figures) is in the gated docs repository and was not edited; it should say the person's job has app_id/app_version and no name, and max_live_jobs.

Review round 1 fixes

  • The live job refresh is attempted at most once a minute per job whether it worked or not (best-effort per-isolate map of attempt times, 1,000 jobs, oldest forgotten first) and parallel reads share one attempt; tapis_synced_at is unchanged.
  • The list cursor carries the job id instead of the row number; migration 0132 (edited in place) adds compute_jobs_account_created_id.
  • GET /compute/me reads the queue partitions together and reuses an estimate for 30 seconds (per-isolate, per-database, 32 partitions).
  • ADR 0118 now says: no minimum cell on /stats and why, the three bases of the stats figures (also in the schema comment), that a refresh from a GET can cancel, settle and copy records and cannot report becameFinished, that the policy coupling of /me is deliberate, and the wire-name deviation.
  • Tests added for a revoked grant, a disabled client on /me, and the maintenance modes through the whole Worker (startOidcHarness exists); the allowlist regex matches me/jobs/:id only. The CLI no longer tells a suspended, revoked, denied or requested person that an admin can lift a freeze; no new account-copy key.

CI fix: the list index stole Epic A's quota-sum plan

compute-lifecycle-migration.test.ts ("the partial index answers the two quota sums") failed because the plain index compute_jobs_account_created_id (account_id, created_at, id) was chosen for WHERE account_id = ? AND results_bytes IS NOT NULL. The index is now partial on flag_unreserved = 0, which the list states and the quota sums do not, so it cannot apply to them. compute-read-plans.test.ts pins the quota sums (compute_jobs_results) and the live-job count (compute_jobs_live).

  • Quota sum, before the fix: SEARCH compute_jobs USING INDEX compute_jobs_account_created_id (account_id=?); after: SEARCH compute_jobs USING INDEX compute_jobs_results (account_id=?).
  • Job list, after: SEARCH compute_jobs USING INDEX compute_jobs_account_created_id (account_id=?) and (account_id=? AND created_at<?) with a state filter and cursor; no sort.
  • Every backend test that reads EXPLAIN QUERY PLAN, sqlite_master or index lists, and the three root tests that do, were run one at a time and pass; migrations:d1-check is clean (239 objects, 65 tables).

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR2072

Version: 0.10.28-PR2072.3931d89
Commit: 3931d89


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit 40050c3 into feature/issue-2021-epic-compute-users Nov 7, 2026
25 of 27 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-2023-compute-user-api branch November 7, 2026 07:57

This branch was previously deployed

1 inactive deployment
npm — 3931d898 Deployed Nov 7, 2026 by neuromechanist via publish #4308
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.

1 participant