Skip to content

Local control-plane stack (DM-08) - #2151

Merged
neuromechanist merged 8 commits into
feature/portable-compute-epicfrom
feature/pc-dm08-local-stack
Nov 13, 2026
Merged

neuromechanist merged 8 commits into
feature/portable-compute-epicfrom
feature/pc-dm08-local-stack

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Card DM-08 of the portable compute plan: the local control-plane stack.
bun backend/scripts/compute-local-stack.ts serve runs NEMAR's real admin, compute, runner and webhook routers on loopback over a persistent SQLite file carrying every migration and a persistent Miniflare R2 behind the S3 stand-in; outputs downloads a job's results through the real links route. It is the test harness made long-running and says "not a deployment" on start.
Binds 127.0.0.1 only and refuses any other host; the S3 stand-in's key and secret are 32 random bytes each, generated on first start into s3.json (never the stand-in's public defaults); every file in the state directory is mode 0600 and every directory 0700 (umask 077 for the process and the Miniflare child, plus a chmod pass); keys are in keys.json and never printed.
Seeds through the real services on first start (and repaired if interrupted): owner, administrator, nemar-pipelines, the default policy as a stored version, grants to the pipelines and people pools. A restart keeps the runner, keys, seeds and R2.
--seed-fixture inserts the pipeline fixture's dataset; --seed-from-catalog <id> reads the public record (User-Agent nemar-local-stack/0), refuses nm000103-nm000107 and the reserved band, copies only the eligibility predicate's inputs plus the version, and prints the field names.
Helper changes (this card owns them): openMigratedDb in d1.ts (records each applied migration, applies a missing one on a later open, never resets, refuses a foreign file); the S3 stand-in takes a port and now listens on 127.0.0.1 only (it listened on every interface before).
Gates run: bun run typecheck and bun run lint clean; bunx biome check on the four touched files clean; bun test backend/test/compute-local-stack.test.ts 18 pass; bun test backend/test/compute-e2e.test.ts 3 pass; compute-results-routes, compute-s3, compute-runner-registry 113 pass. Each guard was proven by a one-line mutation (loopback bind of both servers, host guard, umask, random S3 credentials, migration record, grant idempotency key, cursor follow, path-escape check, runners switch, r2Persist, chmod pass, catalog restart skip).
Run by hand: serve --seed-from-catalog nm000274 on the default ports printed the banner, curl -s http://127.0.0.1:8787/health answered, and the real CLI registered and listed a runner against it.
Deviations: the public API's versions route is authenticated, so the one version row is built from the record's latest_version* fields and zarr_source_commit is kept as the version's commit; a stop by signal exits 0 through process.exit because Miniflare's own signal handler exits 143 synchronously.
Not run, would check: the full bun test (the epic gate) because it takes about 80 minutes.
Card: DM-08.

Review round 1 fixes (head f77181e):
Host guard: both servers answer a fixed 421 {"error":"host_not_allowed"} unless Host is exactly 127.0.0.1:<own port> or localhost:<own port> (case-insensitive); a name, another IP literal, a missing Host and another port are refused on the API (public, admin and runner routes) and on the S3 stand-in (hostGuard option, off by default for the other suites). Host semantics through ssh -R: the Host is the one the client dialed on the remote machine, so the tunnel must use the same port number on both ends (8787 and 8788 as planned); I did not run ssh here, this is by protocol and is DM-15's to confirm.
Tests: the bind address is no longer asserted in-process (the bun test preload makes loopback the default of every Bun.serve, so it proved nothing); the spawned serve case reads the listening address from the operating system, and a missing hostname fails it. The --host refusal case now runs under a kill timer, so a stack that wrongly starts fails in 15 seconds and not after minutes.
Fixture id nm000900 is refused by --seed-from-catalog (documented in the script); no reserved-band id is taken (needs the owner, ADR 0068).
outputs: containment uses realpath on --to and on the deepest existing ancestor of each target plus a relative-path check that never throws (root and ..-prefixed names covered), refuses a symbolic link (also dangling) as the target, and pins every download to the stack's S3 origin (--s3-port, default 8788) with redirects refused.
Stored secrets: usableSecret refuses a short, public-default, constant or repeated value, and an access key equal to its secret, for s3.json, secret and keys.json.
SIGHUP is handled like SIGINT and SIGTERM (servers and database closed in the same tick, then exit 0); a spawned stack stopped by SIGHUP, restarted over the same state, still lists the runner registered before and reuses keys.json.
Gates rerun: bun run typecheck and bun run lint clean; biome check on the four files clean; compute-local-stack.test.ts 27 pass; compute-e2e, compute-results-routes, compute-s3 and compute-runner-registry 116 pass; leak check prints nothing. Each new guard was proven by a one-line mutation. Redundant by design: the public-default check of usableSecret (those values are also shorter than 32), and the synchronous close of the servers in the signal handler (process exit closes the sockets, so it is not externally observable).

@github-actions

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR2151

Version: 0.10.34-PR2151.f77181e
Commit: f77181e


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit f1f5b01 into feature/portable-compute-epic Nov 13, 2026
1 check passed
@neuromechanist
neuromechanist deleted the feature/pc-dm08-local-stack branch November 13, 2026 23:40

This branch was previously deployed

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