Skip to content

crates: install per-project worker packages with nix - #244

Merged
moonthebot merged 5 commits into
mainfrom
factory/job-76-pr-5
Nov 23, 2026
Merged

moonthebot merged 5 commits into
mainfrom
factory/job-76-pr-5

Conversation

@moonthebot

@moonthebot moonthebot commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Why

A stdio MCP server such as playwright-mcp needs tools in the worker, for example a browser. The worker image has none, and baking them in would grow it for every project. A project now lists nixpkgs packages on a "Worker packages" card. Its agent and checks runs then execute inside nix shell nixpkgs#<a> nixpkgs#<b> --command ....

The runner wraps the backend command in a bash script. The script takes a package count, then that many package names as argv elements, then the command. A count ends the list, so no package name can collide with a separator. The script builds the packages with nix build --no-link and exits 86 if that fails. It then creates a temporary file, holds it open on a descriptor and deletes it, and exits 86 if any of those steps fails. The command writes a line to that file and runs only if the write succeeds. Cleanup of temporary files by the command cannot erase the signal, and nothing is left on disk. If nix shell ends without that line, the script also exits 86. Otherwise it passes on the command's exit code, and a command that exits 86 itself becomes 1. So 86 always means setup failed, and a checks command that exits 86 is still ChecksFailed. With an empty list the arguments are unchanged. Checks use bash -c instead of bash -lc when packages are present, because the image's /etc/profile resets PATH for a login shell.

The server stores the list in a new project_packages table and reads it on every run. It validates names (at most 128 bytes, at most 32 entries, duplicates collapsed) and answers 400 with the bad entry.

Docs

docs/design.md: a Worker packages row that describes the count and descriptor protocol, the Project registry and Settings layout rows, the Architecture block, and a new "Recipe: playwright-mcp" section.

Verification

  • nix develop -c just lint passed.
  • nix develop -c cargo test -p factory-runner --test github wrapper passed. It executes the generated wrapper under a fake nix for a build failure, a nix shell failure, command exits of 3 and 86, a command that deletes temporary files before exiting 3, a missing temporary directory (the command must not run), and a package named --. It also checks that no marker file is left behind.
  • nix develop -c just test and nix develop -c just e2e (167 tests) passed before the wrapper changes. Those changes touch only the runner wrapper.
  • Not run: a real run on moon with a package list, which needs a deploy.

A project lists nixpkgs packages on a Worker packages card. When the list
is non-empty, every agent and checks run of that project starts its command
inside `nix shell nixpkgs#<a> nixpkgs#<b>`, so a stdio MCP server finds
what it needs on PATH. The scheduler reads the list on every run.

A fixed bash wrapper builds the packages first and exits with code 86 when
that fails. An agent run then fails with a reason that names the worker
packages, and a checks run is a checks error, not a checks failure.

The design doc gains a Worker packages row and the playwright-mcp recipe.
The ast-grep rule no-inline-tests forbids tests under src/, so the
validation tests move to the dashboard tests and post to the card.
The wrapper takes a package count instead of a -- separator, so no package name can collide with the command. The command touches a marker file when it starts. Exit 86 now means the setup failed before the command ran, and a command that exits 86 itself is reported as 1.
A marker file in the temporary directory could be erased by the command's own cleanup, which reported a setup failure. The wrapper now holds a deleted file open on a descriptor, which leaves nothing behind.
A failed mktemp, descriptor setup or unlink let the command run and then reported a setup failure. The wrapper now exits 86 before nix shell, and the inner shell execs the command only after the start signal is written.
@moonthebot
moonthebot merged commit e6bd1ed into main Nov 23, 2026
3 checks passed
@moonthebot
moonthebot deleted the factory/job-76-pr-5 branch November 23, 2026 22:18
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