Skip to content

refactor: offload Exact builds through the iOS plugin interface - #6650

Merged
janicduplessis merged 5 commits into
mainfrom
refactor/6649-exact-offload-interface
Nov 28, 2026
Merged

janicduplessis merged 5 commits into
mainfrom
refactor/6649-exact-offload-interface

Conversation

@janicduplessis

@janicduplessis janicduplessis commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #6649

Slice S3 of the plan in the design comment on #6599.

Description

After #6648 the local iOS path of the built-in Exact integration ran through the internal plugin interface, but its remote-build path still named Exact in the wire protocol and the generic host: typed exact fields in build.offer, build.start and BuildTarget, the job host calling exactPinsParam, exactOffloadParam and exactToolProblems directly, and the worker's selected.id !== 'exact' check with its Exact-only sequence.

This changes no behaviour and loads no plugin. A worker still builds only the built-in Exact module, which the job looks up by id.

Two parts of the issue are not done here, on purpose, because each needs a decision the issue did not make. They are listed first under "Deviations".

Solution

What moved where

  • packages/core/protocol.ts and the JSON Schema in packages/server/src/protocol.ts: BuildExactPins and the exact fields become BuildPluginPins and one plugin field. The offer carries { id, version, pins }, the offer result plugin: { missing }, the start { id, version, pins, payload, checkout: { name, sibling } }. For Exact, pins is the old pin object unchanged, payload is { env }, checkout.name is the old name and checkout.sibling the old link.
  • BuildTarget (engine/toolchain.ts) carries plugin?: BuildPluginPins instead of exact?: ExactPins.
  • New integrations/plugin-offload.ts: the host's own validation of the checkout name and sibling path (today's APP_NAME and LINK rules), and the readers of the offer's and the start's plugin field, which look the plugin up by id and call its validators.
  • New integrations/ios-plugins.ts: the built-in iOS plugin list (Exact only) and iosPlugin(id). The Exact source and its offload member moved here from exact-ios.ts, which keeps only the project and doctor bindings.
  • integrations/plugin-ios.ts: IosPluginSource gains version and the offload member; the adapter builds the target and the request generically and validates the checkout layout on the client before an offer.
  • job/offload/host.ts: the offer and the start read plugin through plugin-offload.ts; the fingerprint-replay skip keys on plugin.
  • job/offload/worker.ts: compileExact becomes compilePlugin, selected by the id the job names. Codes, the simulator label and the progress line are built from the id and name: exact-tools, exact-simulator, exact-build-failed, stim-exact-, Exact Debug, and exact_build through the shared runPluginIosBuild.
  • integrations/exact-offload.ts: exactOffloadParam split into the pins validator it already called and exactPayloadParam; the worker's app.json check (exactProjectProblem) and environment filter (exactBuildEnv) moved here unchanged.

The interface as it ended up

export interface IosPluginCheckout {
  name: string;
  sibling: string | null;
}

export interface IosPluginOffload<
  Pins extends Record<string, unknown> = Record<string, unknown>,
  Payload extends Record<string, unknown> = Record<string, unknown>,
> {
  plan(
    root: string,
    env: NodeJS.ProcessEnv,
  ): { pins: Pins; payload: Payload; checkout: IosPluginCheckout } | { unsupported: string };
  pins(value: unknown): Pins | null;
  payload(value: unknown): Payload | null;
  malformed: { offer: string; start: string };
  tools(pins: Pins, env: NodeJS.ProcessEnv): Array<{ reason: string; commands: string[] }>;
  source(pins: Pins): { dir: string; commit: string };
  project(root: string, payload: Payload): { code: string; message: string } | null;
  env(input: {
    root: string;
    payload: Payload;
    env: NodeJS.ProcessEnv;
    source: string;
    sibling: string | null;
  }): NodeJS.ProcessEnv;
}

export interface IosPluginSource {
  id: string;
  name: string;
  version: string;
  ios: IosPlugin;
  offload: IosPluginOffload;
}

Deviations from the design comment

  1. No PluginHost, and the tool checks stay synchronous on the host side. The design gives the module one host object (exec plus an abort signal) for the tool checks. The Exact module is lint-restricted to Node built-ins, so a module-side check needs that host passed in. exact-offload.test.ts calls exactToolProblems(pins, env), exactLocalToolProblems(app, env) and exactCheckoutDir(pins, home) with no host, and the plan is read synchronously: ProjectDoctor.offloadTargets returns null synchronously for an app that cannot offload, which commands/doctor.ts turns into check: null, and a test asserts that null. Moving these behind an async exec therefore needs one of: a host argument added to those test calls; host-side wrappers that only tests use, which knip --production and CLAUDE.md reject; or a test helper that binds a host. Each edits tests beyond an import or an await, so this PR leaves Exact's plan, tools and checkout lookup in exact-offload.ts, synchronous, wired into the generic offload member by ios-plugins.ts, and adds no host object (a host with no caller would be a member Exact does not use). The doctor's exact-tools findings stay where refactor: serve Exact iOS through an internal plugin interface #6648 left them.
  2. The client's problem code and texts stay Exact-specific. OffloadProblem.code is part of the published stim API (packages/stim-cli/api.api.txt, through BuildMachineReport.problems in stim doctor --json). Replacing 'exact' with a generic code changes that line, which plugin-api-report.mjs rejects without a STIM_API_VERSION bump and a release note. So offerProblems, problemCode, the doctor's title and fix, and the exact-tools remedy in commands/ios/artifact.ts are unchanged apart from reading target.plugin and offer.plugin.
  3. Two validators instead of one check(pins, payload). The offer validates pins alone and the start validates pins and payload; the existing validators were already split that way.
  4. Three members the design does not list: malformed, project and env. The offer and start refusals ("An Exact offer needs the exact2 commit and the Bun and Rust versions.", "An Exact build needs an iOS request with its app name, pins and settings.") cannot be built from the id and name, and the host also needs them for its own checks (native present, platform not iOS, bad checkout). project holds the app.json and declared-settings refusals, which run before the tool check; env holds the environment filter. The design put the filter inside build; keeping it a separate member leaves the local build untouched.
  5. source returns the commit too. Sibling placement checks the placed checkout out at the pinned commit, and only the plugin knows which pin that is.
  6. version is the Stim version for the built-in. The wire carries it and the job host requires a string, but nothing compares it in this slice, so it cannot refuse a build.

Compatibility of the renamed wire field

The client and the job that reads build.offer and build.start are always the same Stim build:

  • The client asks the worker's stimd to start a job from its own build id: ownBuild() and BuildConnection.startJob in packages/stim-cli/src/offload/client.ts (lines 464 and 645).
  • stimd runs only an installed tree whose manifest names exactly that build (entry(), packages/server/src/offload-jobs.ts:290-300). It fetches the npm release or takes the client's packed build only under server.acceptClientBuilds, and checks the installed build id (:377). When it cannot, job.start answers job-refused or job-needs-package (:228-252), and the client gets no job and sends no offer.
  • The job answers build.offer and build.start itself (packages/stim-cli/src/job/offload/serve.ts:67,72) and passes the job to its worker child, a process of the same build (packages/stim-cli/src/job/main.ts:26), over stdin.

Components that see these frames but may be another version:

Component Reads exact today With plugin
The worker's stimd, any version that runs jobs No. It writes each client message to the job's stdin and each job frame to the socket without parsing (offload-jobs.ts:146,405), as LLP 0009 "Run the client build" freezes. Passes it through.
Older stim-server without job support Never sees the offer: job.start fails first, and the peer check refuses it. Same.
The JSON Schema Not validated at runtime; tsdown.config.ts:62 only writes dist/protocol.schema.json, and the schema is read by tests. Same.
Stim Desktop and the phone app Neither builds nor reads build connection frames. Unaffected.
The mobile protocol schema test Builds a full BuildStartParams. Updated to plugin.
Recorded fixtures (apps/mobile/mock-server/fixtures, test JSON) None carries the field; exact.json is a status payload. Unaffected.
A build area that outlives the job The worker's on-disk layout: checkout/.../up/<name>, .stim-exact2-, stim.exact2-source, stim-exact- simulators. Kept byte-identical, so a later job of another build reads it the same way.

STIM_BUILD_COMPAT stays 6. LLP 0009 "Artifact compatibility" asks for a bump when a machine with the same value but the other version of a listed file would build a different artifact or read a build or artifact message differently. Exact artifacts are never retained or reused, nothing else a worker builds changed, and the renamed field is read only by the job of the same build that sent it. scripts/build-compat.json records the new digest.

New refusal texts, unreachable for Exact

  • The job host: build.offer names no plugin this Stim builds. and build.start names no plugin this Stim builds. for an unknown id or a plugin that is not an object.
  • The worker: This Stim builds no <id> plugin. (unsupported-provider), after the job host has already checked the id.
  • The client: <name> asks for a checkout layout a build machine does not place, when a plan returns a checkout the host rules reject; Exact's plan already applies the same rules and returns its own reasons.

For later slices

  • An async PluginHost and the tool checks moved into the module (deviation 1), with the test edits it needs.
  • A generic problem code with a STIM_API_VERSION bump (deviation 2).
  • Loading a module from a plugin directory, resolving the worker's plugins setting, comparing version, and the JOB_SIMULATOR pattern.

Moved unchanged, and still odd

  • Sibling placement in the worker keeps its Exact text and on-disk names: "the app names exact2 at ...", "... is not an exact2 checkout this machine made", the .stim-exact2- staging prefix and the stim.exact2-source git config key. Changing the names would orphan a worker's existing checkouts.
  • The probe simulator's progress text still says "for the native-module roster".
  • reservedAreaEntry and EXACT2_MAKING stay in exact-offload.ts, which the worker imports.

Test plan

Checks, each with its exit code: pnpm run format:check 0, pnpm run lint 0, pnpm run typecheck 0, pnpm run build 0, pnpm run knip 0, node scripts/build-compat.mjs 0 (after --update), node scripts/plugin-api-report.mjs 0.

Tests:

  • exact-ios.test.ts, exact-offload.test.ts, project-registry.test.ts, project-contracts.test.ts, build-headroom.test.ts, ios-command.test.ts, mobile-protocol.test.ts, receive-protocol.test.ts, guide-budget.test.ts, offload-engine-admission.test.ts: 826 passed.
  • pnpm run test:integration on offload, exact-offload-worker, offload-job, server-builds, build-toolchain, protocol-2-cli, offload-worker-entry and offload-connection: 188 passed. The first two also passed on main before the change (53). Pull request CI does not run these two. The worker test runs the real generic sequence with real git: checkout naming, sibling placement and its containment refusals, the environment filter and the build.
  • The Exact files again with EXACT2=/nonexistent CARGO_TARGET_DIR=/nonexistent: 37 and 8 passed.
  • pnpm test --changed origin/main, run on the commit before offload-engine-admission.test.ts was updated: 8468 passed. That file passes on the head (5 of 5). One status.integration.test.ts case, "status prints the end command for a stimd that did not answer...", failed under load in that run; it passes when run alone and touches no offload code.

Test edits, each one naming the renamed field:

  • exact-ios.test.ts: the fake machine answers plugin: instead of exact: in its offer.
  • offload.integration.test.ts: the target, offers and start use plugin in place of exact; the expected reasons are unchanged.
  • exact-offload-worker.integration.test.ts: the job builder writes plugin from the same plan; assertions unchanged.
  • exact-offload.test.ts: the doctor test reads target.plugin?.pins. The malformed-request test goes through pluginStartParam with the same valid, older-client and eight malformed requests, now in the plugin shape; a malformed request returns the refusal text instead of null.
  • mobile-protocol.test.ts: the full BuildStartParams carries plugin.
  • offload-engine-admission.test.ts: the admitted Exact start sends plugin in place of exact.

Added: the round-trip test named above (changing the plan mapping's payload shape fails it), and one assertion in the malformed-request test: a start naming a plugin id this Stim does not build is refused. Making iosPlugin accept any id fails it, and replacing the host's checkout-name or sibling rule with /./ fails the rows for a hostile checkout name and sibling path.

Before and after, on a real Exact app, with a scratch Stim home:

Capture main This branch
stim ios --plan --json exit 0 identical stdout, stderr, exit
stim ios --plan --json --remote-build local exit 0 identical
stim ios --plan --json --remote-build <machine> exit 1, not listed in remote.machines identical
stim doctor --json exit 0 identical after removing timings
stim ios --json --remote-build local not run exit 0, built here, installed, launched: true

In this copy the offload plan is unsupported (the app copy and its exact2 checkout share no top directory), so these captures exercise the plan, placement and doctor paths around the offload member, not the target or request mapping. The new test a build machine reads the Exact build request the client plans as the client sent it covers that mapping: the plan the client builds goes through the job host's reader unchanged.

Real remote builds, from one scratch Stim home approved for builds on a second Mac acting as build machine, first with the merge base (e0e746f) and then with this branch (c09fafb), on the same copy of a real Exact app. The build machine's stimd is the stable 2.0.0 release, so the renamed field passes through an older stimd. Each client pushed its own Stim build into its jobs: the machine's engine store gained both build ids.

Run with --remote-build <machine> Merge base This branch
stim ios --json (Debug) exit 0, built on the machine, installed here, launched: true same; the compile is incremental because the merge base had built this checkout there
stim ios --configuration Release --json exit 1: the job reaches Exact's build on the machine, which fails for this app (production updater requires deploy.signing.keys) identical
stim ios --json with modules declared exit 1: the machine boots the stim-exact-<job> simulator, then Exact rejects the module name identical
stim doctor, exact2 commit absent on the machine names the missing commit and the install commands identical
stim ios --json, exact2 commit absent on the machine exit 1, STIM_OFFLOAD_REFUSED with the same commands, no job started identical
stim ios --plan --json in each state exit 0 identical

After removing timestamps, ids, ports and paths, what still differs follows from the order of the runs: a cold compile and a created simulator on the first build, an incremental compile on the second, and a stim status --json right after the second, short build that printed the snapshot its stimd took at boot (ageMs 22522), because the home already listed that directory from the earlier status calls; the status code is not in this diff. Not covered: a Release build or a build with native modules that succeeds on the machine (both fail inside Exact with the merge base too, for reasons in the app), and a cold Debug build with this branch.

Replace the typed exact fields of build.offer, build.start and BuildTarget with
one generic plugin field: id, version and pins, plus payload and checkout in
the start. The job host validates the checkout name and sibling path itself
and looks the plugin up by id; the worker runs one sequence driven by the
plugin the job names. Exact keeps every message, code, label and log event.
The renamed field is read only by the job of the same Stim build that sent it,
and Exact builds are never retained, so no compatibility bump.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: cli packages/stim-cli, including its README and guide area: core packages/core area: server packages/server ci-full run the macOS, Windows, Desktop and license jobs on this pull request review: ai-approved A fresh AI review found nothing left to fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Offload Exact builds through the internal plugin interface, with a generic plugin wire field

1 participant