Skip to content

Plugin tests inherit host secrets and environment instead of isolating them #3434

Done

Description

@Birfy

The runtime/flybot-workspace-web test suite inherits host state instead of isolating it, so on any machine that has the workspace secrets in place, node --test --test-concurrency=2 test/*.test.js fails tests that have nothing to do with the code under test. Three separate mechanisms are involved.

Reproduction

Working directory runtime/flybot-workspace-web, node v22.23.5:

node --test --test-concurrency=2 test/*.test.js

On a host whose /run/secrets contains flybot-workspace-runtime-key.json (10,873 B, mode 0600), flybot-workspace-seal.key (32 B) and flybot-workspace-model-api.json, and whose shell exports FLYBOT_WORKSPACE_ROUTING_INSTANCE_ID:

run node tests pass fail cancelled exit
as npm test runs it 22.23.5 497 482 11 4 1
FLYBOT_WORKSPACE_RUNTIME_KEY_FILE=/nonexistent/flybot-key.json 22.23.5 497 490 3 4 1
as npm test runs it 24.22.3 497 486 11 0 1
FLYBOT_WORKSPACE_RUNTIME_KEY_FILE=/nonexistent/flybot-key.json 24.22.3 497 494 3 0 1

Recorded on the content of 1a981717f2b708f796b820ec871058ab339b8fa2 (tree b43a727d), rebuilt from a codeload archive. The eleven failing names are identical on both node versions; node 24 differs only in not reporting cancelledByParent. Two independent runs of the isolated case agreed on 3 fail but disagreed on the node 22 cancelled count (4 and 2), so that count is not a fixed value.

Mechanism 1: the runtime key file is the host's, and its instance id does not match

features/agents/index.js:1664 and :1677 load the bootstrap file named by FLYBOT_WORKSPACE_RUNTIME_KEY_FILE (defaulting to /run/secrets/flybot-workspace-runtime-key.json) and compare its instance_id with host.identity.routingInstanceId || host.identity.instanceId. On this host that file belongs to another runtime, so the agents feature fails to load with Personal agent bootstrap target mismatch, and every test that needs the feature fails with it. Pointing the variable at a path that cannot exist removes 8 of the 11 failures.

Mechanism 2: an empty seal key path means "use the host key"

test/model-api.test.js:30 passes env = { FLYBOT_WORKSPACE_SEAL_KEY_FILE: '' } to mean "no operator key", and expects loadSealKey to create the private fallback file. In lib/b4/seal.js:22 and :36 an empty string is falsy, so the loader falls back to DEFAULT_KEY_FILE = /run/secrets/flybot-workspace-seal.key; that file exists here, the host key is returned, the fallback file is never created and the following statSync raises ENOENT. Probe on the same tree: empty string -> fallback not created; /nonexistent/op.key -> fallback created. This one cannot be fixed from outside the test: the empty string is passed by the test itself.

Mechanism 3: the suite builds identity from process.env

index.js:31 calls loadIdentity({ env: process.env, dataDir }), and src/identity.js:13 turns FLYBOT_WORKSPACE_ROUTING_INSTANCE_ID into identity.routingInstanceId, which test/search.test.js:76 and test/meetings.test.js:875 then prefer over the per-volume id. With the host variable set, two different volumes report the same identity: search.test.js:146 fails with expected '294cbd1bc71f44268f01b7790dc06acc' actual '294cbd1bc71f44268f01b7790dc06acc', and meetings.test.js:908 imports a bundle that should be rejected with import target mismatch.

Measured caveat: unsetting the variable does not make these two files green — search.test.js then fails five other cases and meetings.test.js fails a different one. The files are environment-sensitive beyond that single variable, which is why the fix has to pass an explicit env object rather than tune one variable.

Approved change: one injection seam, explicit env, unchanged production default

A tests-only patch cannot clear mechanism 1: features/agents/index.js:1664 and :1677 call loadPersonalAgentBootstrap() with no arguments, and that loader reads process.env and the real secrets path; the host object handed to a feature carries no env. The approved slice is therefore one seam, added as optional parameters only:

  1. index.js:31: loadIdentity({ env: config.env ?? process.env, dataDir }).
  2. index.js:35: pass the same env into loadFeatures.
  3. src/features.js:67 and :85: accept env = process.env in loadFeatures and expose it as host.env (the host stays frozen).
  4. features/agents/index.js:1664 and :1677: loadPersonalAgentBootstrap(host.env).

loadPersonalAgentBootstrap already takes (env = process.env, reader = readFileSync), so it needs no change. No call site in production passes env, so the default keeps today's behaviour.

Test-side, in the same slice:

  1. test/helpers.js (or a per-file helper): build identity and feature hosts from an explicit env object, never from process.env.
  2. test/model-api.test.js: pass a seal key path that cannot exist instead of an empty string.
  3. Runtime-key consumers: pass a temp path for FLYBOT_WORKSPACE_RUNTIME_KEY_FILE in the explicit env object.

Out of scope, and not to be done here: the empty-string fallback in lib/b4/seal.js (deliberate for a real deployment), unsetting variables to make the suite pass, skipping or relaxing any test, and src/host.js (timer.unref() on node 22 is a separate issue).

Acceptance, by class

The suite is not expected to turn fully green in this slice, and the pull request must not claim it does. Acceptance is measured per class, each with the numbers it produced:

class tests accepted when
runtime key cascade 8 green under an explicit env object
seal key fallback 1 (model-api.test.js) green with an explicit non-existent seal key path
identity routing 2 (search.test.js, meetings.test.js) fixed if the seam covers them; if it does not, they stay open and the pull request says so with the measured failure
cancelledByParent on node 22 up to 4 out of scope, separate issue

Not claimed

  • No CI failure is attributed to this: the CI job runs from a clean checkout where none of these files exist, and the runtime-image job pins node-version: '24', so the node 22 cancelledByParent count never reaches CI.
  • Counts are from one 192-core host; the 11-failure cascade depends on /run/secrets being populated, the 3 remaining failures are deterministic there.
  • This issue does not cover the node 22 timer.unref() mechanism; that is a separate issue.

Activity

  1. added
    bug
    agent-ready
    on Nov 28, 2026
  2. Birfy commented on Nov 28, 2026

    @Birfy
    CollaboratorAuthor

    Claimed. Branch will be dev/3434-isolate-plugin-test-host-state, cut from main 1a981717f2b708f796b820ec871058ab339b8fa2.

    Slice boundary: test files under runtime/flybot-workspace-web/test/ plus a helper they share. Production defaults (lib/b4/seal.js fallbacks, the bootstrap key lookup in features/agents/index.js) stay as they are: they are correct for a real deployment, and the defect is that the tests inherit host state instead of constructing their own.

    Acceptance for the slice: with the host secrets present and FLYBOT_WORKSPACE_ROUTING_INSTANCE_ID exported, the full directory run matches the run with those variables pointed elsewhere, and no test reads process.env for identity or seal keys. A patch that simply unsets variables in the runner, or that skips the affected cases, does not meet it.

    First step is a re-measurement on 1a981717 so the numbers in this issue are bound to a current sha; the table above was recorded at c738897c.

    Related #3434

  3. added
    agent-working
    on Nov 28, 2026
  4. Birfy commented on Nov 29, 2026

    @Birfy
    CollaboratorAuthor

    #3435 is merged: main is now e6aeae4e2bae52d13e721506a41e598a222655ea (tree 93a2fb2d). That tree is identical to the tree of the merged head 8f70ad59, so the content that landed is the content that was reviewed and that recorded 18/18 completed + success checks.

    Two notes for the record:

    State set to closed. Related #3435.

  5. removed
    agent-working
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions