Skip to content

nsolid: Phase 0, an N|Solid agent that the Console can see and drive - #1

Open
edsadr wants to merge 3 commits into
mainfrom
claude/blissful-wozniak-s0rvb1
Open

edsadr wants to merge 3 commits into
mainfrom
claude/blissful-wozniak-s0rvb1

Conversation

@edsadr

@edsadr edsadr commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Phase 0 of nsolid-bun, the base of a stack of PRs, each targeting the one below it:

  1. This PR, Phase 0 (base: main)
  2. nsolid Phase 1: the agent a Console can rely on #2 Phase 1 (base: this PR's branch)
  3. nsolid Phase 2: profiles, redacted snapshots, blocked loops, loop and GC metrics #4 Phase 2 (base: the Phase 1 branch)
  4. nsolid Phase 3: traces, logs, source code, continuous profiles, HTTP/DNS and handle metrics #5 Phase 3 (base: the Phase 2 branch)

Rebased on 2026-12-04 onto main at 6cab274, which brings in oven-sh/bun at 39b4945. The commit SHAs in this description are the rebased ones. What the rebase changed here: upstream removed VM::hold_api_lock (oven-sh#49650), so the agent thread takes its VM's API lock with get_api_lock() and never releases it, as upstream's worker threads do.

What does this PR do?

Phase 0 of nsolid-bun, NodeSource's build of Bun with an N|Solid agent.

When NSOLID_GRPC or NSOLID_SAAS is set, the main thread starts one hidden thread, NSolidAgent, with a VM of its own, as the inspector does for its Debugger thread. That VM runs internal/nsolid/agent, which talks to the N|Solid Console over gRPC (grpcagent.NSolidService):

  • Connection. The Command stream over node:http2 with the nsolid-agent-id, nsolid-version and, for SaaS, nsolid-saas metadata. SaaS tokens are routed the way N|Solid's parse_saas_token routes them. TLS by default; plaintext only with NSOLID_GRPC_INSECURE, and for a SaaS token only in testing mode. Reconnects back off from 1 s to 30 s with jitter.
  • Commands. Every CommandRequest is acknowledged at once with an empty CommandResponse, then answered on the RPC the Console expects: info (no versions.node or v8, so the Console doesn't treat the process as Node.js), startup_times (main module start, agent thread start and agent ready, in nanoseconds since the process started), reconfigure (every key, eBPF profiling unsupported). Everything else gets N|Solid's 404 "Resource not available" right away.
  • Configuration. Read the way N|Solid reads it: NSOLID_* variables, then the "nsolid" key of the app's package.json, then defaults.
  • Protocol. The protos are vendored in packages/nsolid-protocol (N|Solid's, with the Console's later additions, OTel's metrics, common and resource protos, and protobuf's Struct). generate.ts writes the schema tables in src/js/internal/nsolid/messages.ts; protobuf.ts encodes and decodes against them. No new dependency.
  • Public module. bun:nsolid, with require("nsolid") as an alias, as in N|Solid for Node.js. It exposes id, the process's agent id. It is not added to node:module's builtinModules, so Node compatibility counts are unchanged. Types in packages/bun-types/nsolid.d.ts.
  • CI. .github/workflows/nsolid-bun.yml builds Linux x64 release, runs the N|Solid tests against it and uploads the binary. scripts/nsolid/install-llvm.ts installs the LLVM that Bun's CI images pin, with sha256 checks, for machines that can't use apt.llvm.org.

Changes to existing upstream files are kept to hooks:

  • src/jsc/VirtualMachine.rs: two calls next to ensure_debugger.
  • src/jsc/lib.rs: the module.
  • src/bun_core/env_var.rs: NSOLID_GRPC and NSOLID_SAAS.
  • src/resolve_builtins/HardcodedModule.rs: bun:nsolid and the nsolid alias.
  • The AOT model's declaration of the module's host function.
  • src/js/private.d.ts.
  • packages/bun-types/index.d.ts.
  • scripts/build/unified.ts: NSolidAgent.cpp compiles on its own, so it moves no other file between bundles.
  • The thread-crossing lint's inventory: the agent thread holds no state of another VM.

How did you verify your code works?

  • Tests. test/js/bun/nsolid/nsolid-agent.test.ts has 6 tests. They pass with bun bd test and with the release build, and all fail with stock Bun.

    • The command tests use a real gRPC server (@grpc/grpc-js) built from the vendored protos.
    • The other tests cover the metadata, acknowledgements split across frames, SaaS routing, not keeping the process alive, and the module.
  • Codec. Cross-checked against protobufjs. OTel exponential histograms encode byte for byte the same. Also checked: 64-bit values above 2^53, negative integers, packed fields, Struct, and frames split across chunks.

  • Lints. The source lints, builtins-manifest and the bun-types tests pass. Some only pass when they can find WebKit's aot sources, as in CI.

  • End to end. Against a locally run N|Solid Console, the release binary was listed with its app name, version, tags, entry script and startup times, and its configuration converged. Through the Console's CLI, info and startup_times completed, while profile, snapshot, heap_sampling, packages and metrics returned 404 in about 2 s. A SaaS token connects. On SIGTERM the process exits and shows as disconnected; the exit event comes in Phase 1.

  • Cost (release build, medians):

    Without agent With agent
    Startup 4.1 ms 4.6 ms
    Memory, idle Bun.serve 48 MB 70 MB
    Idle CPU 0.1% of a core 0.27% of a core
    Hello-world throughput no measurable difference
  • CI. The workflow's first run passed: https://github.com/nodesource/ns-bun/actions/runs/45256133468

After the rebase: every check passes at 91d408a.


Generated by Claude Code

@ns-control-tower

Copy link
Copy Markdown

ns-control-tower

Note

Reviewing the latest changes on this PR — this may take a few minutes.
This comment will be updated in place with the findings; no other top-level comments will be posted.

@autofix-troubleshooter

Copy link
Copy Markdown

Hi! I'm the autofix logoautofix.ci troubleshooter bot.

It looks like you correctly set up a CI job that uses the autofix.ci GitHub Action, but the autofix.ci GitHub App has not been installed for this repository. This means that autofix.ci unfortunately does not have the permissions to fix this pull request. If you are the repository owner, please install the app and then restart the CI workflow! 😃

@socket-security

socket-security Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Dependency limit exceeded — report not shown.

This pull request scan exceeded the 10,000-dependency limit applied to this scan, so the results are incomplete and may be inaccurate. To avoid reporting false positives, Socket has not posted a report.

Upgrade your plan to raise the dependency limit and get complete reports, or view the partial scan in the dashboard.

Socket is always free for open source. If this is a public open source project under an OSI-approved license, contact us to request a free Business plan upgrade.

…d stream

When NSOLID_GRPC or NSOLID_SAAS is set, the main thread starts one hidden
thread, NSolidAgent, with a VirtualMachine of its own (modelled on the
inspector's Debugger thread). It runs internal/nsolid/agent, which:

- resolves the endpoint: NSOLID_GRPC (a bare port means localhost), or a
  SaaS token parsed the way N|Solid's parse_saas_token does (production,
  staging, and testing tokens that name their own endpoint);
- opens the grpcagent.NSolidService/Command stream over node:http2 with the
  nsolid-agent-id, nsolid-version and, for SaaS, nsolid-saas metadata;
- answers every CommandRequest with an empty CommandResponse, which the
  Console uses to tell a live agent from a dead one;
- reconnects with jittered exponential backoff (1 s to 30 s).

TLS is the default; plaintext needs NSOLID_GRPC_INSECURE, and a SaaS token
only allows it in testing mode. The agent id is 40 random hex digits, one
per process, kept in Rust so the public nsolid module can read the same id.

The thread is never joined and does not keep the process alive. Workers
never start one. Without the environment variables nothing changes.

NSolidAgent.cpp compiles outside the unified bundles so that it moves no
other file into another bundle.

Decoding commands, the public nsolid module and everything the Console asks
for after the handshake come next.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013nEe5T77UhAYmQxqQRbPpR
… build

The agent now speaks the protocol, not just the handshake:

- A protobuf codec for the agent. The protos are vendored in
  packages/nsolid-protocol (N|Solid's, with the Console's later additions,
  plus OTel's metrics, common and resource protos and protobuf's Struct);
  generate.ts turns them into the schema tables in
  src/js/internal/nsolid/messages.ts, and src/js/internal/nsolid/protobuf.ts
  encodes and decodes against them. Checked against protobufjs.
- Commands are decoded and answered on the RPC the Console expects: info
  (app, version, tags, host, entry script, versions without node or v8),
  startup_times (process start, main module start, agent thread start, agent
  ready, in nanoseconds since the process started), and reconfigure (the
  merged configuration, every key, eBPF profiling unsupported). Everything
  else gets N|Solid's 404 "Resource not available" at once.
- Configuration is read as N|Solid reads it: NSOLID_* variables, then the
  "nsolid" key of the app's package.json, then defaults.
- `require("nsolid")` is an alias of the new `bun:nsolid` module; `id` is the
  process's agent id, the one the agent reports. The id now lives in C++.
- The main thread hands the agent its entry point; the agent VM has none.

A Bun process running this build shows up in a local N|Solid Console with
its app name, version, tags and startup times, and its configuration
converges; a profile request is answered "not available" instead of
timing out.

.github/workflows/nsolid-bun.yml builds Linux x64 release, runs the N|Solid
tests against it and uploads the binary. scripts/nsolid/install-llvm.ts
installs the LLVM that Bun's CI images pin, from LLVM's release, for
machines that can't use apt.llvm.org.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013nEe5T77UhAYmQxqQRbPpR
bun lint's no-duplicate-conditional-property-access flagged four
properties read in an `if` and again in its body; each is now read once
into a local. bun fmt orders generate.ts's imports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013nEe5T77UhAYmQxqQRbPpR
@edsadr
edsadr force-pushed the claude/blissful-wozniak-s0rvb1 branch 2 times, most recently from dad3681 to 91d408a Compare December 4, 2026 15:09
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.

4 participants