Repository navigation
Phase D2: Compute user API and read commands - #2072
Merged
neuromechanist merged 13 commits intoNov 7, 2026
Merged
neuromechanist merged 13 commits into
neuromechanist merged 13 commits into
Conversation
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR2072Version: 🤖 Updated on each push. |
neuromechanist
merged commit Nov 7, 2026
40050c3
into
feature/issue-2021-epic-compute-users
25 of 27 checks passed
2 tasks
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase D2 of epic #2021 (issue #2023): the
/computeread routes, their credential rule, queue estimates, the wire contract andnemar compute balance|limits|queue|list|status. Base is the epic branchfeature/issue-2021-epic-compute-users, notdev.The router
backend/src/routes/compute.tsbecame the directorybackend/src/routes/compute/(index.tsis the old file,auth.tsthe credential rule,read.tsthe five read routes), so phases D3 and D4 can add their ownregister*file beside them.Routes (for website phases E1 and E2)
All are GETs. Refusals are
{ error: <sentence>, code: <word> }. Times areYYYY-MM-DD HH:MM:SS(UTC), daysYYYY-MM-DD(UTC), money whole milli-SU integers. Every response schema is open and lives inshared/contract/compute-user.ts(also exported fromshared/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 isYYYY-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 } }.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_credential403,insufficient_scope403,invalid_token401,missing_credential401,invalid_range400,invalid_group400,invalid_state400,invalid_limit400,invalid_cursor400,job_not_found404,policy_unavailable503.Credentials and scopes (ADR 0119 amendment)
/compute/me*: a CLI key, the session cookie, or an OIDC access token carryingcompute.read(live account rule, read at every call). A token without the scope is 403insufficient_scopewith the scope in the challenge. A client credentials token is not a person./compute/stats: only a client credentials access token carryingcompute.stats. A CLI key is 403forbidden_credential(answered the same for a valid and an invalid key), a person's token is 403forbidden_credentialbefore its scope is judged, noAuthorizationheader is 401missing_credential.oidc-token-allowlist.test.tslists exactly these five paths;compute-route-inventory.test.tspins each route's guard and the scope of eachoidcBearerinstance.Exposure rules
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.job_not_found, as for cancel and links. A swept (unreserved) job is nobody's to read.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...becauselistComputeJobsis 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.tskeeps this evidence (fails on any scan of the jobs or the ledger).Without 0132:
With 0132 (
compute_jobs_queue_started,compute_jobs_created,compute_ledger_created,compute_jobs_account_created_id, partial onflag_unreserved = 0):Where the phase issue differed from the merged code
name: the specification's name is in the records bucket and the index row has no column for it. It carriesapp_idandapp_version. Adding a column is a later phase's call.limitshasmax_live_jobsinstead ofmax_runningandmax_queued: the owner's policy has one number (maxLiveJobsPerPerson) for jobs created, queued or running together, and the wire does not invent a split.accessgainsrequests_open(false in exact production while the terms are unpublished), becauseterms_publishedalone would hide the request form on staging, where requests are taken.src/lib/api/compute.tsalready had an administrator'slistComputeJobs; the person's functions arelistMyComputeJobsandgetMyComputeJob.active_peopleleaves 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.GET /me/jobs/:idreads back only a live job that has a Tapis job (it never submits acreatedjob, which would read the compute switch from a GET) and is skipped in the read-only maintenance mode, serving the stored record withstale: true.granted_milli,held_milli,charged_milli,available_milli(the administrator's contract names), not the*_milli_sunames the issue wrote; the website phases transcribe the schema./compute/me/usagewith an administrator's correction (no job) returnsnullfor 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.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-30with a laterto), the list's swept-job filter, the statsactive_peopleswept-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 oldcreatedjob), and theforbidden_credentialbranches of the stats guard. Two queue conditions (IS NOT NULLon 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 hasapp_id/app_versionand noname, andmax_live_jobs.Review round 1 fixes
tapis_synced_atis unchanged.compute_jobs_account_created_id.GET /compute/mereads the queue partitions together and reuses an estimate for 30 seconds (per-isolate, per-database, 32 partitions)./statsand 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 reportbecameFinished, that the policy coupling of/meis deliberate, and the wire-name deviation./me, and the maintenance modes through the whole Worker (startOidcHarnessexists); the allowlist regex matchesme/jobs/:idonly. 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 indexcompute_jobs_account_created_id (account_id, created_at, id)was chosen forWHERE account_id = ? AND results_bytes IS NOT NULL. The index is now partial onflag_unreserved = 0, which the list states and the quota sums do not, so it cannot apply to them.compute-read-plans.test.tspins the quota sums (compute_jobs_results) and the live-job count (compute_jobs_live).SEARCH compute_jobs USING INDEX compute_jobs_account_created_id (account_id=?); after:SEARCH compute_jobs USING INDEX compute_jobs_results (account_id=?).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.EXPLAIN QUERY PLAN,sqlite_masteror index lists, and the three root tests that do, were run one at a time and pass;migrations:d1-checkis clean (239 objects, 65 tables).