Skip to content

Phase D1: Compute access request and approval - #2071

Merged
neuromechanist merged 14 commits into
feature/issue-2021-epic-compute-usersfrom
feature/issue-2022-compute-access
Nov 7, 2026
Merged

neuromechanist merged 14 commits into
feature/issue-2021-epic-compute-usersfrom
feature/issue-2022-compute-access

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Phase D1 of Epic D (#2021), closes #2022. A verified person with a proven ORCID iD can ask for compute access once, an administrator can grant, deny, suspend or revoke it from the CLI, a grant opens the owner's default allocation, and every path that ends the person's compute standing freezes their pools and live jobs through Epic A's release statements. Compute access is its own grant: nothing here reads or writes service_access.

What changed

  • Migration 0131_compute_access.sql (the issue said 0125; the owner moved it to 0131, and 0125 to 0129 stay unused): users.compute_access (none, requested, active, suspended, denied, revoked) plus requested, notified and granted stamps, the granter, the purpose (20 to 1000 characters), the terms version and time, and a partial index on open requests. Existing rows read none. The ADR 0118 addendum says 0131.
  • shared/compute-access-state.ts (states, edges, canTransition, canUseCompute), shared/contract/compute-terms.ts (COMPUTE_TERMS_VERSION = "2026-11-draft", COMPUTE_TERMS_PUBLISHED = false), shared/contract/compute-access.ts (request body, error codes, responses).
  • POST /users/me/compute-access/request: 409 already_active and access_closed (also for suspended), the already-requested short circuit that re-mails while compute_access_notified_at is NULL, then purpose, terms version, inbox, ORCID proof (an oauth_identities row, not the orcid_verified flag; service and test kinds exempt), profile gaps; a conditional UPDATE ... WHERE compute_access = 'none' decides who mails. In the exact production environment it is 503 terms_unpublished while the terms are unpublished.
  • Admin: GET /admin/compute/access and POST /admin/compute/access/{grant|deny|suspend|revoke}/:username and /by-id/:id. Each decision is one batch (flip with from-states, audit only if the flip landed, the rest guarded on the state the flip leaves). A grant writes Epic A's GRANT_INSERT_SQL per pool word from the policy's defaultGrantMilli under the key compute_access_grant:<id>:<pool> (a re-grant adds nothing; a zero default grants nothing and says policy_default_zero) and unfreezes the pools. Suspend and revoke run endComputeStatements: computeReleaseStatements plus oidcEndStatements(..., "compute_suspended", { scopePrefix: "compute." }), no network call in the batch.
  • finalizeRevocation sets every compute state but none to revoked (a none account stays none: nothing was asked, nothing to close); the tombstone mask sets revoked and erases compute_purpose; the test-account sweep takes only accounts at none. Role demotion and key revocation still end none of it.
  • Gap matrix: GapBlock gains compute_access, GapField gains affiliation (blocks only compute_access), profileGapFields(account, block?) filters by block, checkUploadAccessRequest passes upload_access so its missing list is unchanged. affiliation reaches profileGapsForRow from every SELECT (/users/me, /auth/me via publicUser, the web session, code verify, the profile PATCH echo).
  • compute_access, compute_access_requested_at and compute_access_granted_at on /users/me and /auth/me, optional and never defaulted; the notified stamp is on no wire.
  • Mail: compute_requests category (default on) in EmailPreferences, the parse, the PUT schema and nemar admin email-preferences; sendComputeAccessRequestEmail (links to <APP_BASE_URL>/admin/compute) and sendComputeAccessDecisionEmail.
  • CLI: nemar compute request-access and nemar admin compute access list|grant|deny|suspend|revoke (all take --json), nemar auth profile set-affiliation, requestComputeAccess in src/lib/api/compute.ts, src/lib/api/compute-access-admin.ts, both pinned in test/api-export-surface.unit.test.ts.
  • Docs: ADR 0118 amendment (items 1 to 10), ADR 0119 rule 12 table row and caller list, the docblock caller lists (COMPUTE_END_CALLERS now three, OIDC_END_CALLERS now seven), implementation-notes.md section 3.

Decisions and departures from the issue text

  • The compute switch is read nowhere in this phase (compute-source-scan.test.ts still pins its one reader, and compute-access-source-scan.test.ts pins that none of these files reads it). Request, grant, deny, suspend and revoke are bookkeeping and work with compute off, tested with the switch unset, 0 and 1.
  • The release statements and the OIDC statements are called by endComputeStatements in services/compute-access.ts, not inline in the routes, so the caller lists name one function. Both lists and their docblock counts are updated and the scans pass.
  • Freeze cause (A8 amendment item 3 left it to this phase): derived from the access state. A pool is unfrozen only by a grant, and a grant is refused (409 account_not_in_good_standing, enforced in the flip's WHERE as well) unless the account is not deleted and is verified or approved.
  • backend/test/helpers/compute-app.ts already existed from Epic A (it mounts the real adminRoutes, which now carries the new routes); it now also mounts the real userRoutes. src/lib/api/compute.ts also existed (Epic A's admin client), so requestComputeAccess is added there.
  • nemar auth profile set-affiliation is not in the issue. The new affiliation gap would otherwise name a command that does not exist (the ADR 0040 failure), and PATCH /auth/profile already takes the field.
  • The new gap is raised on /users/me and /auth/me for every account without an affiliation. One existing test fixture that expected an empty gap list (cli-self-service-routes.test.ts) now seeds an affiliation. No website test was read as objecting; the escalation trigger did not fire.
  • The admin list is ordered by account id with an id cursor (next_after), not by request time.
  • suspended answers a new request with the code access_closed and its own words (compute_access.suspended.body, "paused"), not the denied/revoked wording.
  • The decision mail does not carry the administrator's reason (it is on the audit row only).
  • The user-search column classification (USER_COLUMN_ROLES) classifies the state and terms version as flag (returned, not searched), the dates as text, the granter as ref and the purpose as omit; the admin user detail contract carries the state, dates, granter and terms version.

For website#494 (phase E1) to transcribe

Copy keys added to shared/contract/account-copy.ts (27 non-cli. keys are mirrored, plus one cli. key the website ignores):

compute_access.section.title, compute_access.section.lede, compute_access.state.none, .requested, .active, .suspended, .denied, .revoked, compute_access.request.cta, compute_access.request.form_body, compute_access.request.purpose_label, compute_access.request.purpose_hint (written-out bounds 20-1000, pinned to COMPUTE_PURPOSE_*_CHARS by account-copy-parity.test.ts), compute_access.request.terms_label, compute_access.requested.title, .requested.lede, .requested.lede_dated, .requested.body, compute_access.granted.body, compute_access.closed.body, compute_access.suspended.body, compute_access.terms_unpublished.body, compute_access.docs_link, gap.blocks.compute_access, gap.blocks.noun.compute_access, gap.field.affiliation.label, gap.field.affiliation.set_on.web, gap.field.affiliation.set_on.cli; CLI-only: cli.compute_access.cta.

Gap matrix changes in shared/contract/profile-gaps.ts: new block compute_access (after upload_access, before publication); email_verified blocks ["verified","upload_access","compute_access"]; given_name and family_name ["upload_access","compute_access","publication"]; city and country ["upload_access","compute_access"]; new field affiliation (after country, before why) with blocks ["compute_access"], label "Affiliation", web "Settings", CLI nemar auth profile set-affiliation, missing when blank; computeProfileGaps(account, block?) and profileGapFields(account, block?) filter by block; the wire blocks carry compute_access. test/profile-gaps-matrix.test.ts is extended (512 combinations, the block filter, the compute list). Wire: userSchema and webUserSchema gain optional compute_access, compute_access_requested_at, compute_access_granted_at. The admin page the request mail links to is /admin/compute and the person's /compute.

test/account-copy-parity.test.ts compares against the website checkout; those keys are absent there until #494 lands, so that test fails where a website checkout is present (it skips otherwise). On the sibling staging checkout here it already fails before this change for 26 oidc.* keys and 3 upload_access.* bodies, so the 27 keys of this phase add to a drift that exists.

Tests

Targeted only, run from this worktree on the final head; the full suite is the epic gate and was not run (not run, would check: full bun test because it is the epic -> dev gate).

  • bun run lint, bun run typecheck (both tsc passes) and bun run migrations:d1-check (128 migrations through real D1, catalog matches bun:sqlite): clean.
  • Root: bun test test/<file>: profile-gaps-matrix 52, admin-route-inventory.unit 6 (256 admin handlers, was 247), api-export-surface.unit 14, help-tiers.unit 12, compute-access-cli 26, compute-access-state.unit 9, email-preferences 19, identifier-sweep-cli 3, contract-schemas 63, auth-gaps-cli 30; account-copy-parity 8 pass and 2 fail (the website drift above).
  • Backend, one file at a time from backend/: compute-access-migration 13 (bun:sqlite and Miniflare D1), compute-access-request-route 33, compute-access-decision-routes 53, compute-access-cascade 16, compute-access-oidc 5, compute-access-source-scan 10, upload-access-request-route 30, profile-gaps-route 26, auth-me-payload-route 12, cli-self-service-routes 39, admin-user-search-route 66, compute-end-callers 15, oidc-cascade-callers 24, compute-release-cascade 20, admin-credential-cascade 13, test-account-sweep 72, test-account-sweep-d1 3, admin-revoke-route 10, compute-source-scan 4, mail-admin-routes 70, migrations 22, oidc-cascade-filters 17, oidc-cascade-d1 11, oidc-cascade-nonmembership 6, compute-pool-routes 39, compute-status-route 24, compute-policy-routes 21, compute-jobs-admin-routes 7. All pass.

Mutations

Each applied to the production line, the named test file run, then restored (git status clean); a mutation that survived was fixed (two did, and the race tests in compute-access-decision-routes.test.ts were added).

  • Migration (compute-access-migration.test.ts): widen the state CHECK with 'granted' 2 fail; purpose minimum 19 1; drop the terms-version GLOB 1; drop the partial index WHERE 1.
  • State machine (compute-access-state.unit.test.ts): active -> requested 2; revoked -> requested 3; canUseCompute accepts suspended 1.
  • Gaps: drop the block filter (matrix) 3; drop compute_access from city's blocks 7; affiliation never missing 4; drop the block argument in checkUploadAccessRequest 23 (upload-access-request-route.test.ts); drop affiliation from the /users/me SELECT 13 and null it in the web session SELECT 12 (profile-gaps-route.test.ts); change the purpose hint bounds in the copy 1 more fail (parity).
  • Request route: swap the ORCID and profile checks 1; read orcid_verified instead of the identity row 3; drop compute_access = 'none' from the request UPDATE 1 (the concurrent test); COMPUTE_TERMS_PUBLISHED = true 1; count the purpose in UTF-16 units 1; drop the notified stamp 3.
  • Decision routes: make the default grant key unique per call 2; drop the standing term from the grant UPDATE 1; let none reach active 1; drop the unfreeze 4; drop the state guard from the release and OIDC statements 1 (and 1 in compute-access-oidc.test.ts); drop the audit statement 4.
  • Cascades (compute-access-cascade.test.ts): omit endComputeStatements from the route 4; omit the compute flip from finalizeRevocation 5; always revoked there 1; omit the compute columns from the tombstone mask 2; omit the release statements from tombstoneUserCascade 1. Sweep predicate dropped: 1 (test-account-sweep.test.ts). OIDC: omit oidcEndStatements 4; use the whole-account ending instead of the compute. filter 3.
  • CLI (compute-access-cli.test.ts): drop the compute block override from the gap rendering 2; drop the client's compute arm of prefersMessage 2; stdout noise under --json 1 (request) and 4 (admin). Other: drop compute_access from publicUser 3 (auth-me-payload-route.test.ts); compute_requests === true in the parse 9 (email-preferences.test.ts); drop the route registration 2 (inventory); put service_access into the request route or computeEnabled into a decision 1 each (compute-access-source-scan.test.ts).

Not done

Review round (Sonnet review of this PR)

  • Stale state: every flip now binds the state the administrator read in addition to the allowed list, so the loser of a race answers 409 stale_state (tests: revoke racing grant on a suspended account in both orders, grant after deny, suspend racing revoke). The observed-state term is redundant for deny and suspend (their allowed list is one state), so only grant and revoke have a killable mutation.
  • The request route has cookieOriginGuard (after the router's authMiddleware, before the body is read): a cookie with a foreign, null or missing Origin is 403 origin_not_allowed, a NEMAR Origin works, a bearer key is unaffected.
  • A purpose with a control character other than newline and tab (NUL above all) is 400 purpose_required; the migration test records that length() stops at a NUL on bun:sqlite and Miniflare D1.
  • Self-grant: an admin granting their own account is 409 self_decision (new word in the admin codes and status table; also enforced in the flip), an owner may; deny, suspend and revoke of oneself stay allowed.
  • nemar auth profile lists Affiliation and Compute access under "Where to change each"; nemar auth signup, signup and register take --affiliation, offered (a flag, or a terminal prompt that Enter skips) and never required, so a non-interactive signup is not failed by a gap that stops compute access only.
  • ADR 0118 amendment items 11 to 16 record the bound state, the self-grant rule, the Origin guard and control characters, the suspended wording, the D3 obligation (canUseCompute as well as pool.frozen, also posted on Phase D3: User job submission and nemar compute submit #2024), the tombstone-versus-revocation difference, purpose retention, the at-most-one-duplicate admin mail, and, as an open product question, that unlinkOrcid does not end compute standing.
  • The granted body mentions nemar compute before D3 exists: accepted within this epic.
  • American spelling in the prose I added; the em-dashes in the reflowed profile-gaps comment removed. The @example.org fixture addresses come from Epic A's shared helper, not from files this PR added, so they were left.

@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@PR2071

Version: 0.10.28-PR2071.6ea969f
Commit: 6ea969f


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit 3a86990 into feature/issue-2021-epic-compute-users Nov 7, 2026
29 of 31 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-2022-compute-access branch November 7, 2026 06:37

This branch was previously deployed

1 inactive deployment
npm — 6ea969f4 Deployed Nov 7, 2026 by neuromechanist via publish #4304
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