Repository navigation
Local control-plane stack (DM-08) - #2151
Merged
neuromechanist merged 8 commits intoNov 13, 2026
Merged
Conversation
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR2151Version: 🤖 Updated on each push. |
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.
Card DM-08 of the portable compute plan: the local control-plane stack.
bun backend/scripts/compute-local-stack.ts serveruns 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;outputsdownloads 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 inkeys.jsonand 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 thepipelinesandpeoplepools. A restart keeps the runner, keys, seeds and R2.--seed-fixtureinserts the pipeline fixture's dataset;--seed-from-catalog <id>reads the public record (User-Agentnemar-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):
openMigratedDbind1.ts(records each applied migration, applies a missing one on a later open, never resets, refuses a foreign file); the S3 stand-in takes aportand now listens on 127.0.0.1 only (it listened on every interface before).Gates run:
bun run typecheckandbun run lintclean;bunx biome checkon the four touched files clean;bun test backend/test/compute-local-stack.test.ts18 pass;bun test backend/test/compute-e2e.test.ts3 pass;compute-results-routes,compute-s3,compute-runner-registry113 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 nm000274on the default ports printed the banner,curl -s http://127.0.0.1:8787/healthanswered, 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 andzarr_source_commitis kept as the version's commit; a stop by signal exits 0 throughprocess.exitbecause 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"}unlessHostis exactly127.0.0.1:<own port>orlocalhost:<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 (hostGuardoption, off by default for the other suites). Host semantics throughssh -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 testpreload makes loopback the default of everyBun.serve, so it proved nothing); the spawnedservecase reads the listening address from the operating system, and a missinghostnamefails it. The--hostrefusal 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--toand 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:
usableSecretrefuses a short, public-default, constant or repeated value, and an access key equal to its secret, fors3.json,secretandkeys.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 typecheckandbun run lintclean; biome check on the four files clean;compute-local-stack.test.ts27 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 ofusableSecret(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).