Skip to content

Phase A4: Tapis client and stand-in - #2038

Merged
neuromechanist merged 12 commits into
feature/issue-2005-epic-compute-corefrom
feature/issue-2009-phase4-tapis-client-and-stand-in
Nov 4, 2026
Merged

neuromechanist merged 12 commits into
feature/issue-2005-epic-compute-corefrom
feature/issue-2009-phase4-tapis-client-and-stand-in

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Phase A4 of the compute gateway core (epic #2005, issue #2009, ADR 0118): the Worker can talk to a Tapis tenant, and every part of that conversation is tested against a stand-in before a tenant exists. No tenant, secret or production object was touched, and nothing here has been verified against a real tenant.

What changed

  • backend/src/services/tapis/: config.ts (tapisConfig(env) is { strategy, baseUrl, tenantId, ... } or { unconfigured: true, problems }; TAPIS_BASE(env) is globalThis.NEMAR_TAPIS_API_URL else TAPIS_BASE_URL, which must be https), auth.ts (password grant and service-minted user tokens behind one cache keyed by strategy and username, refresh lead, one shared in-flight mint, a failed mint dropped, compare-and-delete invalidateTapisToken), http.ts (15-second timeout nobody can lengthen, bounded streaming body read, no redirect, no body ever read into an error), errors.ts (TapisError with kind unconfigured | unauthorized | not_found | rejected | unavailable | invalid_response wrapping HttpError, and outcomeUnknown), schemas.ts (zod from the OpenAPI schemas: strict on what NEMAR sends, .passthrough() on responses) and client.ts (submitJob, getJob, getJobHistory, cancelJob, searchJobsByTag, listJobs, subscribeWebhook, listOutputs, downloadOutput, tapisHealth, nemarJobTag).
  • backend/test/helpers/tapis-standin.ts: a real Bun.serve stand-in with in-memory jobs (advance), the documented tag search, subscription capture, fireWebhook (CloudEvents-shaped notification, User-Agent: Tapis/v3), a request log with headers, ALL_JOBS as the documentation defines it (own plus shared, shareJob), a fullRecords mode that ignores select and serves whole records (fullRecordsServed notes a job only when the answer really carries both parameterSet and subscriptions), and the failure modes (forced status per route, hang, non-JSON or wrong-shape or invalid-UTF-8 bodies, chunked and broken streams, expired tokens, every token rejected, down and up). Its header says no response was recorded from a real tenant, and bun backend/test/helpers/tapis-standin.ts starts it by hand.
  • backend/src/services/compute-switches.ts: computeEnabled(env) is exactly production or development and COMPUTE_ENABLED exactly the string "1", read at call time; computePipelinesDispatchEnabled(env) also needs COMPUTE_PIPELINES_DISPATCH_ENABLED as the string "1". Both names, and every Tapis name, are absent from every table of wrangler-sccn.toml and pinned by compute-switches-flag.test.ts; the toml comment block lists the Tapis secret names only.
  • GET /admin/compute/status (admin) and nemar admin compute status [--json]: both switches as the Worker reads them, the strategy, whether each of Tapis, the two R2 bindings, the signing secrets and the ACCESS key is configured, and one fresh token mint and one health call as fixed words. Booleans and words only: no secret, address, tenant name or username.
  • Pins that had to move with it: the admin route inventory (one new route, total 213), the CLI export surface, and the compute-admin contract test's table (the new open response schema is classified there). .context/compute-program/implementation-notes.md has a new section 9.

Round 1 review: what was fixed

  • TapisJob is derived from the schema (TapisJobSchema.omit(...) with z.infer), so job.uuid and job.status are typed; the old Omit of a passthrough type collapsed every field to unknown. A compile-time assertion in schemas.ts (covered by tsc -p backend, unlike the tests) fails the typecheck if it collapses again or if parameterSet or subscriptions becomes a named key.
  • Token stampede: invalidateTapisToken(env, owner, refusedToken) deletes only when the cache still holds the refused token, so callers that hold one stale token share one new mint (8 concurrent calls after expiry add exactly one mint).
  • The "never returns parameterSet or subscriptions" rule is now tested on search and list against a tenant that ignores select and serves whole records, as well as on get and submit.
  • Mint and health answers of the wrong shape (no result, empty token, expires_in 0 or missing or fractional, [], null, {}) are invalid_response, send no empty X-Tapis-Token, cache nothing, and are reported as invalid_response by the status route.
  • The launch specification's other copies: every submit sends parameterSet.archiveFilter: { includeLaunchFiles: false } (field and nesting checked against ReqSubmitJob -> JobParameterSet.archiveFilter -> IncludeExcludeFilter.includeLaunchFiles in the Jobs OpenAPI), the request schema allows exactly that key with that value, and downloadOutput and listOutputs refuse a path whose basename is tapisjob.env or tapisjob.sh in any case. The application definition's archiveIncludeLaunchFiles: false stays as the second layer (nemar-process phase C5).
  • LAUNCH_SPEC_ENV_KEY is LAUNCHER_ENV.SPEC, not a second copy of the word, and the tests assert the contract's word.
  • Under the password strategy submitJob refuses an owner that is not the configured account (kind unconfigured, a fixed sentence that names no one); under the service strategy the owner stays a free parameter.
  • Caps: a download asks for at most 16 MiB (more is a RangeError, not a clamp); maxAttempts that is not a finite number is the default 3 and anything else is kept within 1 and 3 (a NaN used to stop a read from running at all); retryDelayMs is kept within 0 and 5000 ms (not a number: 500).
  • subscribeWebhook refuses http: addresses unless the test-only base URL override is active, because the address carries a token.
  • unavailable and invalid_response of submitJob, cancelJob and subscribeWebhook carry outcomeUnknown and say so in the message (a 2xx answer that fails its schema means the job may exist, so search by tag before any re-submit); the status the answer came with is carried, and a refusal, a failed read or a mint that failed before anything was sent is not marked.
  • Tests added for both switches, with NO change of behaviour: the code was already a strict === "1", and isOne is a refactor that names the rule. The new tests pin that a TOML integer, true, ["1"], new String("1"), { toString }, 1n and " 1" do not turn a switch on, and that String(x) === "1" and x == "1" would.
  • ALL_JOBS in the stand-in is the caller's own jobs plus the jobs shared with the caller, as the documentation says (the stand-in used to return every job in the tenant), and the client's comment says the same; the stand-in's status list is written out from the specification and a test compares it with NEMAR's.
  • Tests for the transport: the 15-second ceiling reaches AbortSignal.timeout whatever a caller asks for, the chunked bound is exact (the bound accepted, one byte over refused), a body that stalls or breaks after the headers is unavailable (and a read tries three times, a submit once), and invalid UTF-8 is invalid_response. The status route's own default timeout is pinned at 8 seconds for the mint and for the health call.

Round 2 review (delta): four low findings, fixed

  • The switches: isOne is a refactor with no change of behaviour (the code was already a strict === "1"); the comment in compute-switches.ts and the round-1 bullet above now say so, and what the round added is the tests.
  • The status carried on an invalid_response is pinned at every site that carries it, each checked by replacing the status with null at that site and running the client file: the mint's non-JSON body (new test, 200), the mint's schema failure (201, asserted in the wrong-shape test), the over-bound body (200, asserted in the chunked test), the job calls' non-JSON body (200, asserted on a read and on a submit), their schema failure, the health call's non-JSON body (200), the health schema failure, and the parse helper's own error. All eight were killed (three of them, and the job-call and health non-JSON sites, survived before this round).
  • invalidateTapisToken with an empty refused token never drops a mint in flight: a direct test holds a mint in flight, passes "", and asserts that a second getTapisToken shares the single mint (two strategies); removing the refused !== "" guard was killed.
  • Stand-in fidelity: fullRecordsServed now notes a job only when the answer really carries both parameterSet and subscriptions (for search and for list, after paging), so a stand-in that honoured select under fullRecords makes the test fail (killed, and the list variant too); the archive-filter comment says the request's filter is merged over the default (assumed, unverified); and the circular test line that read the stand-in's own echo ("Tapis's record says so") is gone, leaving the assertion on the body that was sent.

Who can read a job's parameterSet (the amendment on #2009; all of it unverified against a real tenant)

The launch specification, including job_token, travels in NEMAR_LAUNCH_SPEC, which Tapis keeps in the job record's parameterSet.envVariables. From the Jobs specification and documentation, the roles that can read it are: the job's owner, its creator and a tenant administrator, through GET /v3/jobs/{uuid} and the search with every attribute; a user the job's JOB_HISTORY resource was shared with (the documentation says that grantee can get the job's history, status and "job's detail information", and search the jobs shared with them); a user its JOB_RESUBMIT_REQUEST resource was shared with, through GET /v3/jobs/{uuid}/resubmit_request (the whole submission request); and a user its JOB_OUTPUT resource was shared with, through the launch files tapisjob.env and tapisjob.sh that Tapis archives with the output unless archiveFilter.includeLaunchFiles is false. JobListDTO (the list), the status and the history have no such field. The same record's subscriptions field carries the webhook address, which holds a token. Per the owner's decision there is one NEMAR tenant and NEMAR owns every Tapis job, so no person can read any of this; the client's owner stays a parameter (a NEMAR service identity from configuration), and a test pins that it is never a constant. As defence in depth the client never returns parameterSet or subscriptions from any record, the tag search asks only for named fields, every submit asks Tapis not to archive the launch files, and the client will not read those two files.

Gates

  • bun test on backend/test/tapis-client.test.ts, compute-switches-flag.test.ts, compute-status-route.test.ts, test/admin-compute-status-cli.test.ts, test/compute-admin-contract.unit.test.ts, test/contract-schemas.test.ts, repull-switches-flag.test.ts, compute-buckets-config.test.ts, the admin route inventory, the CLI export surface, test/compute-contract.unit.test.ts and test/admin-compute-cli.test.ts: 803 pass, 0 fail, 12 files at the current head (the client file alone is 168 tests in about 2.7 seconds).
  • bun run typecheck: clean (tsc --noEmit && tsc --noEmit -p backend).
  • bunx biome check on src shared backend/src: only the 5 known errors in untouched zenodo.ts and doi-orcid-discovery.ts; the touched test files have warnings only (any in test bodies, as in the neighbours).

What was mutated, and how

Each mutation is one line (or one expression) of production code changed, the one test file that guards it run, and the file restored; the run was done with the test file as a separate argument from the command.

  • First pass: 44 mutations of the client, auth, transport, errors, schemas and config, 15 of the status service and route, about 10 of the CLI command and response schema, and 8 of the switches and the toml pin. Two survivors (the declared-length bound and the 429 kind) got tests and were killed.
  • Round 1: 56 mutations across schemas.ts, auth.ts, client.ts, http.ts, errors.ts, compute-switches.ts and compute-status.ts, covering items 1 to 5, 7 to 16 and 19 of the review (the TapisJob collapse and a secret field left in the type, both caught by tsc -p backend; unconditional and never-firing invalidation; search, list, get and submit left uncleaned; an empty token returned after a failed mint parse; min(1) dropped from the token and expires_in; the health check dropped, and its status dropped; the archive key not sent, loosened, made optional or open; each launch file left readable, the case fold and the basename logic; the password owner check off or applied to the service strategy; each cap, bound and guard of attempts, delay and download size, at its helper and at each call site; http webhook addresses allowed or https refused; the outcome flag and sentence left out, set on reads, or set on the wrong kinds; the transport ceiling bypassed; the chunked bound at three times and at plus one; the body error catch removed; a lenient UTF-8 decoder; String(x), == and x === 1 in place of the string test; the status route's timeout), plus two of the stand-in (ALL_JOBS back to the whole tenant, a status removed from its list). All were killed. One mutation (the health safeParse) first did not apply because of formatting, was redone and killed; one (the health status carried as null) survived and got an assertion. Replacing the status carried on an invalid_response with null was killed at the schema-failure site and the health-schema site of that round only; round 2 found the others and pinned them (below).
  • Not mutated: the parts of status and the CLI command that round 1 did not touch were covered in the first pass; the retry log lines ([retry] ...) are the Worker's own and fixed-text.
  • One survivor kind is accepted: nothing waits the full 15 seconds. The ceiling is proven by recording what AbortSignal.timeout is asked for (the real one still does the timing), and the retry waits by recording what setTimeout is asked for (cut to 1 ms), so those two tests wrap a platform primitive and do not replace any NEMAR logic.

Unverified (nothing was checked against a real tenant)

  • Which credential strategy the operator grants (the password grant, or a Tokens API service credential), and whether the service credential may mint tokens for the usernames NEMAR names.
  • Whether X-Tapis-Token is how POST /v3/tokens takes the service credential: the issue and the notes say so, while the Tokens API specification does not state it and declares a basic-auth security scheme for that API.
  • listType=ALL_JOBS: the documentation says it lists the caller's own jobs plus the jobs shared with the caller, not every job in the tenant, which contradicts the earlier assumption (and the first stand-in) that it returns every person's jobs. A search by tag before a re-submit is therefore safe only while one identity submits and searches, which the 2026-11-04 owner decision gives; whether a tenant administrator sees more is unknown.
  • The POST search body shape: { "search": ["tags IN ('nemar_job:<id>')"] } is the Jobs documentation's example, and the specification only says object.
  • Whether Tapis takes parameterSet.archiveFilter.includeLaunchFiles from the request, and how it merges with the application definition's setting (the documentation says the includes and excludes arrays are merged and is silent on the flag).
  • The webhook retry policy, source addresses and ordering, and the spelling ttlminutes of the subscription lifetime (both the specification and the documentation use it; the notification service's own field is ttlMinutes).
  • The schedulerOptions spelling for GPUs: { "arg": "--gpus=N" }, as Expanse's user guide writes it, and that a scheduler profile does not hide it.
  • That the partition word is the logical queue's name, and the application's own defaults (a request with no memoryMB takes Tapis's 100 MB default unless the application sets one).
  • Which fields a real tenant returns where the specification and the documentation's examples differ (a job's parameterSet as a string or an object, a history event's eventDetail or jobStatus, a file's url or uri); the client accepts both.
  • How Tapis handles an environment value that is a JSON text (quotes, braces, ; and &): its documentation says such values are double quoted and rejects control characters, and does not say how a quote inside one is escaped. This could break NEMAR_LAUNCH_SPEC on the first real job and is worth a deliberate test on the debug partition.

Deviations from the issue and from the review list

  • DECISION NEEDED (unchanged): the status view reports whether the ACCESS key is configured, and the issue names no Worker secret for it. I used ACCESS_GATEWAY_API_KEY; no secret exists, so renaming is a few lines.
  • Under the service strategy TAPIS_USERNAME is optional and is the NEMAR service identity the status probe mints a token for; without it the token step answers skipped.
  • Every client call takes a context { env, owner, timeoutMs?, retryDelayMs?, maxAttempts?, now? } first, which the issue's signatures leave out; the knobs exist so tests do not wait, and each is now bounded (see above).
  • Reads retry (three attempts); submitJob, cancelJob and subscribeWebhook never retry inside the client. A 401 is refreshed once and retried once for every call, submit included. 403 is unauthorized and not refreshed; other 4xx and a 3xx are rejected, and a redirect is never followed.
  • Additions beyond the issue: the stripping of parameterSet and subscriptions, the named-field search, the archive filter and launch-file refusal, outcomeUnknown, and the status response schema in shared/contract/compute-admin.ts (open, like its neighbours).
  • Round 1 choices that were left to me: the download cap is a refusal (not a clamp) at 16 MiB; a non-finite maxAttempts or retryDelayMs is the default, and a finite one is clamped; the webhook rule reuses the base URL override; the password-owner refusal is kind unconfigured; the transport and status-timeout tests record AbortSignal.timeout and setTimeout instead of waiting 15 or 5 seconds.
  • Commits are grouped by file, not by item: the client test file, the stand-in and the six tapis/ source files each carry several of the review items, so one commit holds the client work, one the switches, one the status route tests and one the notes.
  • .rules/testing.md in this checkout has no "Test cost" section; the whole client file runs in under three seconds.
  • The docs checkout was five commits behind, so I read the design page from origin/main. The issue's "When merged" docs step (design section 12 as "assumed in code", the secret names in the owner actions) is the driver's and is not done here.
  • Not done on purpose, as instructed: a --fail-on-problem flag on nemar admin compute status (it exits 0 by documented design) and a call-level time budget in the client (the ceiling is per request; phase A5's brief says read-through calls pass maxAttempts: 1 and a short timeoutMs).

Not run, would check

  • The full bun test: the owner's rule is that it runs at epic to dev as CI.
  • bun run migrations:d1-check: there is no migration in this phase.
  • The A3 compute suites that need Miniflare beyond the status route (compute-jobs, compute-records, compute-s3): this phase does not touch them, and the status suite starts the same harness.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR2038

Version: 0.10.28-PR2038.5a29e4f
Commit: 5a29e4f


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit c3e815b into feature/issue-2005-epic-compute-core Nov 4, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/issue-2009-phase4-tapis-client-and-stand-in branch November 4, 2026 20:59

This branch was previously deployed

1 inactive deployment
npm — 5a29e4f0 Deployed Nov 4, 2026 by neuromechanist via publish #4167
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