Skip to content

[Linux][Onboard] the API port allocated for one sandbox is written into process.env and silently becomes the pinned port for the next create in the same process #13628

Closed as not planned

Description

@Leryl

Investigation Summary

  • reserveCreateSandboxHermesApiPort() ends with env[HERMES_API_PORT_ENV] = String(effectivePort), and env defaults to process.env.
  • In allocation, an environment value outranks the sandbox's own durable hermesApiPort; with allowRegisteredOverride (the rebuild/recreate path) the override is silent.
  • Reproduced against the shipped v0.0.135 build with a stubbed registry — no sandbox involved (see Reproduction Steps). A second run on Ubuntu 24.04 gives the same output, so the defect is host-agnostic.
  • Hit during upgrade-sandboxes --auto: the second sandbox pinned the first sandbox's port, the collision check ran after the destroy, and the sandbox was lost (see [Ubuntu 26.04][Sandbox] retained-recovery record cannot be cleared by any supported command; destroy and onboard refuse each other #12290 for the resulting state).
  • Unknown: whether the write-back is load-bearing. withHermesApiPortReservationScope is already exported, so a scoped write may be the intended design.

Description

nemohermes update reconciles sandboxes sequentially in one process. Each create asks for an API port.
The allocator records its choice in process.env. The next create in the same batch therefore starts
from hasRequestedPort = true, so it pins the previous sandbox's port instead of the port registered for
its own name, and then fails.

Expected: a create resolves the port from the sandbox it is creating — its registered hermesApiPort, or
a fresh allocation — never from state that a sibling create left in process.env. A port conflict must be
detected before the source sandbox is destroyed.

Actual, observed during upgrade-sandboxes --auto:

  Sandbox recreate error: Cannot allocate Hermes API port 8643: it is registered to 'agent-b'.
  Recreate failed after sandbox was destroyed.

Here 8643 was agent-b's registered port, and the destroyed sandbox's own registered port was 8642.

Reproduction Steps

No sandbox, gateway mutation, or network access is required. The node -e snippet runs against the
shipped build at ~/.nemoclaw/source (v0.0.135), so it also gives maintainers an executable spec.

Reproduced on Fedora Server 44 and on Ubuntu 24.04 in a KVM VM, both at v0.0.135:

cd ~/.nemoclaw/source && node -e '
const p = require("./dist/lib/onboard/hermes-api-port.js");
const getSandbox = () => ({ name: "agent-a", hermesApiPort: 8642 });

// 1) clean environment: the registered port wins, as designed
console.log(p.resolveOnboardHermesApiPort("agent-a", { env: {}, getSandbox }));            // 8642

// 2) environment left behind by a previous create in the same process
try {
  console.log(p.resolveOnboardHermesApiPort("agent-a",
    { env: { NEMOCLAW_HERMES_API_PORT: "8643" }, getSandbox }));
} catch (e) { console.log("THREW:", e.message.split("\n")[0]); }

// 3) same call as the rebuild/recreate path makes it (allowRegisteredOverride)
console.log(p.resolveOnboardHermesApiPort("agent-a",
  { env: { NEMOCLAW_HERMES_API_PORT: "8643" }, getSandbox, allowRegisteredOverride: true }));'

Output on both hosts:

8642
THREW: NEMOCLAW_HERMES_API_PORT=8643 conflicts with sandbox "agent-a", which serves its
       OpenAI-compatible API on port 8642. Rerun onboarding with --recreate-sandbox to apply a different port.
8643        <-- the sibling's port silently wins, then "it is registered to 'agent-b'"

The write-back itself is observable without a stubbed conflict. One call to
resolveOnboardHermesApiPort("agent-a", { getSandbox }) sets process.env.NEMOCLAW_HERMES_API_PORT
to 8642. A following resolveOnboardHermesApiPort("agent-b", { getSandbox, allowRegisteredOverride: true })
then returns 8642, although agent-b's registered port is 8643.

End-to-end reproduction: register two Hermes sandboxes on one host (API ports 8642/8643), then run
nemohermes update or nemohermes upgrade-sandboxes --auto so both are reconciled in one process.

Environment

Primary (Fedora Server 44):

- Host OS: Fedora Linux 44 (Server), SELinux Enforcing, kernel 7.2.10-200.fc44.x86_64
- Hardware: x86_64 workstation, 20 vCPU / 31.1 GiB RAM, RTX 4090 (sandbox GPU passthrough
  disabled, NEMOCLAW_SANDBOX_GPU=0; inference is a host-side llama.cpp container)
- Node.js: v24.18.0 (host), 24.18.1 in the sandbox image
- Docker: Docker Engine 29.8.2 (build 2.fc44)
- NemoClaw: nemohermes v0.0.135 (Hermes variant), OpenShell 0.0.116, Hermes agent pin 0.21.3
- Topology: two Hermes sandboxes on one host, gateway `nemoclaw` at 127.0.0.1:8080, all
  dashboard/API listeners loopback-only, each sandbox behind its own Cloudflare Access app

Confirmation run (Ubuntu, KVM VM):

- Host OS: Ubuntu 24.04.5 LTS, kernel 6.8.0-147-generic, KVM guest
- Node.js: v24.18.0
- Docker: Docker Engine 29.9.2
- NemoClaw: nemohermes v0.0.135 (Hermes variant), OpenShell 0.0.116, install ref v0.0.135

Debug Output

dbg-leryl-03-scrubbed.tar.gz

Logs

Relevant source (v0.0.135):


src/lib/onboard/hermes-api-port.ts
  239:  const hasRequestedPort = Boolean(env[HERMES_API_PORT_ENV]?.trim());
  242:  const pinnedPort = hasRequestedPort || registered ? resolveOnboardHermesApiPort(...) : null;
  281:        `Cannot allocate Hermes API port ${String(pinnedPort)}: it is registered to '${registeredOwner}'.`
  305:        env[HERMES_API_PORT_ENV] = String(effectivePort);     // env defaults to process.env

Checklist

  • I confirmed this bug is reproducible
  • I searched existing issues and this is not a duplicate

Activity

  1. added theissue type on Oct 22, 2026
  2. added
    needs: triage
    on Oct 22, 2026
  3. self-assigned this
    on Oct 22, 2026
  4. changed the title [-]# [Linux][Onboard] the API port allocated for one sandbox is written into `process.env` and silently becomes the pinned port for the next create in the same process[/-] [+][Linux][Onboard] the API port allocated for one sandbox is written into `process.env` and silently becomes the pinned port for the next create in the same process[/+] on Oct 22, 2026
  5. added a commit that references this issue on Oct 22, 2026
    e5ab1d2
  6. added
    area: networking
    area: onboarding
    integration: hermes
    and removed
    needs: triage
    on Oct 22, 2026
  7. rsliter commented on Oct 27, 2026

    @rsliter
    Collaborator

    PR #13629 review disposition for Advisor run 40429567695: the P1 claim that two sibling rebuilds can overlap while publishing NEMOCLAW_HERMES_API_PORT is false for the production rebuild entry point. rebuildSandbox enters withPortableOnboardRetirementBoundary before the per-sandbox lock and holds it through rebuildSandboxUnlocked and environment restoration. That boundary uses the same-home host fence. The fence queues same-home operations and retains a process-bound lock until the awaited operation completes. Tests cover async serialization and cross-process exclusion. No new lock or test is needed for this claim.

    This disposition does not complete #13628: pre-destroy sibling-port conflict detection remains for separate work, so the issue stays open.

  8. rsliter commented on Oct 27, 2026

    @rsliter
    Collaborator

    Follow-up boundary after reviewing PR #13629: cross-home delegated rebuilds currently omit a caller-supplied NEMOCLAW_HERMES_API_PORT. rebuildSandbox delegates before entering its scoped environment block, and the owning-registry worker's REBUILD_ENV_NAMES allowlist does not forward that key. The allowlist is unchanged by PR #13629. This is distinct from the reported same-process, selected-gateway upgrade-sandboxes --auto port leak fixed by that PR. A future fix should decide whether explicit port overrides are supported across registry roots, then validate forwarding or intentional refusal at the worker boundary. The original pre-destroy sibling-port conflict criterion also remains open.

  9. wscurran commented on Nov 18, 2026

    @wscurran
    Contributor

    Hi @Leryl, thanks for reporting the rebuild port-conflict and override behavior. We’re planning an updated architecture for NemoClaw and won’t be prioritizing this follow-up in the current implementation. Closing as not planned.

    If this is still an issue that needs prioritization in our v1 release, please re-open and tag @wscurran.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: networkingarea: onboardingintegration: hermes

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions