Skip to content

Runner registry, credentials, switch and revocation cascade (DM-05) - #2149

Merged
neuromechanist merged 9 commits into
feature/portable-compute-epicfrom
feature/pc-dm05-runner-registry
Nov 13, 2026
Merged

neuromechanist merged 9 commits into
feature/portable-compute-epicfrom
feature/pc-dm05-runner-registry

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Card DM-05 of the portable compute plan: runner registry, credentials, the dark switch and the revocation cascade.
An owner registers, lists and revokes a runner from the CLI; a registration secret (nmr_) buys a 15-minute access token (nmra_) and nothing else; both prefixes are refused by every other path before any lookup; revoking a runner, or ending its registering owner, ends its tokens and its work in one batch.
Migration 0140 adds compute_runners, compute_runner_tokens and twelve compute_jobs columns (executor, accounting, claim and lease, runner usage), with the partial index of waiting runner jobs; no foreign key, no admitted_at.
computeRunnersEnabled needs compute on and COMPUTE_RUNNERS_ENABLED exactly "1"; it is absent from wrangler-sccn.toml and pinned by the flag test, and named in AGENTS.md.
Routes: POST /compute/runners/token and GET /compute/runners/me (runnerAccess), and the owner's POST|GET /admin/compute/runners and POST /admin/compute/runners/:id/revoke; refusals use the protocol's words.
authMiddleware (through resolveBearerUser) and resolveApiKeyUser answer 401 runner_credential_not_accepted for either prefix; the principal RPC refuses them as an invalid credential.
Cascade statements that runnerRevokeStatements(runnerId, reason) and runnerEndStatements(userId, reason) add, in this order, each ending in a WHERE clause with plain placeholders: (1) DELETE the runner's access tokens, (2) UPDATE its unstarted claimed created jobs to clear runner, claim and lease, (3) UPDATE its started or past-created live jobs to unreported with the lease cleared, keeping runner_id, (4) UPDATE the registration to revoked with a reason, last.
Callers of runnerEndStatements: three (finalizeRevocation, tombstoneUserCascade, the role demotion handler), listed in RUNNER_END_CALLERS and held by a source-scan test that reuses the compute scan; before this PR there were none. The compute set stays at two callers and the OpenID Connect set at six, both unchanged. A key revocation and a sign-out are deliberately not callers; the emailed key regeneration is a named exception.
CLI: nemar admin compute runners register|list|revoke; the secret is printed once with a mode-0600 warning, help has an Exit codes block.
Gates run: bun run typecheck and bun run lint pass; bunx biome check on every touched TypeScript file passes; bun run migrations:d1-check passes (128 migrations on real D1, catalog matches bun:sqlite); the eight Acceptance test files pass (171 tests).
Also run and passing: the credential and compute cascade suites (admin-credential-cascade, admin-revoke-route, mail-ticket-cascades, private-site-cascade, test-account-sweep, compute-end-callers, compute-release-cascade, oidc-cascade and its callers and D1 variants, optional-auth-api-key, the two compute migration suites, contract and state suites, private-site RPC).
Each new test was proven by mutating the line it guards (about 75 mutations, listed in the card report); two guards are redundant by design (a revoked secret is refused by the lookup and again by the token INSERT), so only both mutated together are caught.
Not run, would check: the full bun test (the epic gate) because it takes about 80 minutes.
Deviations: the listing and revoke answers have no shape in the runner contract, so open schemas are declared in src/lib/api/compute-runners.ts; two registry-only words (runner_not_found, runner_name_taken) are declared in the admin route file; compute-end-scan.ts takes a target so one scan holds both statement sets.
Card: DM-05.

Review round 1 fixes (head 640540a):
A registration is now written FROM users of an approved, undeleted owner (0 changes is owner_only, and no audit row), and the secret lookup, the token INSERT and resolveRunnerAccess all join users for the same standing; route-level tests cover a late registration after each of the three callers, and a pre-guard row is shown dead.
A claimed job with a cancel recorded is no longer released: it goes to unreported keeping runner_id and runner_claimed_at, lease cleared. For DM-07: after a revoke an unreported job keeps runner_id and runner_claimed_at with a NULL lease_expires_at, so the sweep keys on state unreported plus the runner's revoked flag, never lease expiry.
Deviation recorded: a claimed queued (slurm, no started_at) job goes to unreported too, because releasing it would need the forbidden backward edge queued -> created.
The compute.runner.registered audit row records key_id; the docblock and .rules/revocation.md carry the stolen-key incident step (list runners after revoking a leaked owner key, revoke any you do not recognize). ADR 0121's key-revocation exception is unchanged.
Migration 0140 also adds CHECK (executor = 'tapis' OR source = 'pipeline') (carried on the added column, no rebuild; real D1 accepts it) and the compute_jobs_runner index on runner_id (EXPLAIN QUERY PLAN pinned for all four job statements).
The demotion failure comment and warning now name runner registrations; the exchange is in the strict IP rate bucket (rateLimit.ts AUTH_PATHS, a minimal edit outside the card's file list); RunnerPrincipal and RunnerRow use the shared unions.
New tests: a route-table-wide refusal test (both prefixes against every route, compared with an unknown key), resolvePrincipal with tokens holding the hash, direct service tests (exchange on a revoked id, owner standing at each use), and the bucket pin.
Not done on purpose: release does not clear webhook_nonce (nothing in this card mints one at claim; patch note for DM-06 and DM-07: clear it on release and mint a fresh one at claim so a released claim's job token dies). A concurrent double revoke can write two compute.runner.revoked audit rows; cosmetic, left.

Review round 2 fixes (head 6fd59ad):
finalizeRevocation now writes the revoked status (and the service-access stamps) as the LAST statement of the same atomic batch as the cascade, instead of a separate statement after it; a late registration is either before the batch (ended by it) or after it (refused by the standing guard), so a re-approval brings nothing back, and the retry property of the batch is unchanged. The other two callers have no such gap: tombstoneUserCascade is one guarded batch whose first statement sets deleted_at, and the role demotion writes the role before its batch, so a registration after the role write is already refused.
Test: for each of the three callers the real route runs over a database that injects registerRunner right after the first batch commits, then re-approves the owner; the registration must be refused and nothing resolves. Reverting the status write to a separate statement after the batch fails only the finalizeRevocation case, as expected.
The resolvePrincipal test comment no longer claims to guard the behaviour-neutral case; the migration EXPLAIN pin is now USING INDEX compute_jobs_runner\b; a lowercase bearer scheme is refused by authentication (resolveBearerUser is case-sensitive), so keyIdOf cannot see one, and a test pins that.
Known and left: if the demotion's credential batch fails, the runners are not ended, but the owner no longer stands (role written first), so the join refuses them until a re-promotion; the failure is logged with the manual step, as for tokens.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR2149

Version: 0.10.34-PR2149.6fd59ad
Commit: 6fd59ad


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit bc0ba1c into feature/portable-compute-epic Nov 13, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/pc-dm05-runner-registry branch November 13, 2026 21:42

This branch was previously deployed

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