Skip to content

nsolid Phase 1: the agent a Console can rely on - #2

Open
edsadr wants to merge 8 commits into
claude/blissful-wozniak-s0rvb1from
claude/nsolid-p1-1-transport
Open

edsadr wants to merge 8 commits into
claude/blissful-wozniak-s0rvb1from
claude/nsolid-p1-1-transport

Conversation

@edsadr

@edsadr edsadr commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Phase 1 of nsolid-bun, the second PR of the stack:

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

The Console-side Phase 1 work is in the Console repository, in a draft pull request of its own.

Phase 1 items

  • Transport: TLS with a custom CA, client certificates with refresh, keylog
  • Reconnects: N|Solid's backoff, the 20-try auth limit, the Console's retry-after
  • Config: N|Solid's precedence and validation; reconfigure applies the same rules
  • SaaS token parsing and endpoint routing (from Phase 0)
  • Process metrics: rusage, load average, memory, uptime, CPU %
  • JSC heap metrics, mapped to N|Solid's metric names where the meaning matches
  • Metrics exported over OTLP on the gRPC channel every interval, and answered on metrics
  • VM registry: workers registered with thread ids
  • Per-thread metrics for worker threads (heap; loop, GC and HTTP metrics are Phase 2)
  • Exit: ExportExit with code, signal and error, sent before the process exits (aborts and crashes are Phase 2)
  • Package inventory: the node_modules scan, loaded packages, bun's isolated linker
  • Public nsolid module, part 1: start, config, id, info, metrics, packages
  • Branding as nsolid-bun: version key, --version, User-Agent, bun upgrade, crash reports
  • WebKit prebuilt mirror, in use by this repository's CI

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's process.versions statics are byte arrays now, so Bun__nsolidBunVersion is one too; and this branch no longer merges Phase 0's lint fix, it sits on top of it, so the stack is linear.

What does this PR do?

Transport and config (commit 373a254)

  • NSOLID_GRPC_CERTS replaces the default roots with a CA bundle.
  • NSOLID_GRPC_CLIENT_CERT and NSOLID_GRPC_CLIENT_KEY present a client certificate, re-read every NSOLID_GRPC_CLIENT_CERT_REFRESH_INTERVAL seconds, with N|Solid's two warnings.
  • NSOLID_GRPC_KEYLOG writes the TLS secrets to ./nsolid-tls-keylog-<pid>.log.
  • Reconnects follow N|Solid's rules:
    • the delay starts at 500 ms and doubles up to 60 s, with jitter;
    • the 20th UNAUTHENTICATED close stops the agent;
    • the Console's retry-after lengthens a delay.
  • Config follows lib/nsolid.js: precedence, tag limits, value validation, sticky snapshot flags. reconfigure validates new values.
  • Fix: a Command stream that the gateway ended with a status never reconnected.

Metrics, thread registry, exit, packages, the nsolid module (commit b775aa0)

  • Metrics:

    • Every interval, N|Solid's process metrics and each JavaScript thread's heap (heapTotal, heapUsed, externalMem) go out over OTLP's MetricsService/Export. They use N|Solid's names, units, nsolid scope and resource attributes.
    • metrics answers with the last periodic sample, as N|Solid's does.
    • A thread's heap is read on that thread: the main thread and workers register, and the agent posts each a request through ScriptExecutionContext::postTaskTo.
    • The agent's own VM takes a context id outside the sequence that numbers workers, so worker.threadId is the same with the agent as without it.
  • Exit: these are sent as ExportExit:

    • exit codes;
    • uncaught exceptions, with message and stack;
    • SIGINT, SIGTERM and SIGHUP, when nothing else handles them.

    The exiting thread waits 5 s at most. A process with no Console connection exits at once.

  • Packages:

    • N|Solid's genPackageList scan runs on the agent's thread.
    • required means the main thread loaded a module of the package, read from its module registry and require.cache.
    • The isolated linker's node_modules/.bun layout is listed correctly.
  • nsolid module: it is N|Solid's start(), with id, config, info, metrics, packages and the config getters on it.

    • start({ grpc }) or start({ saas }) starts the agent.
    • The agent publishes its configuration, so nsolid.config shows what the Console set.

Branding, WebKit mirror, a scan that doesn't block (commit 30c5190)

  • Version: nsolid-bun has its own, beside Bun's.
    • process.versions.nsolid_bun is 0.1.0.
    • bun --version prints 1.4.6 (nsolid-bun 0.1.0).
    • The User-Agent is Bun/1.4.6 nsolid-bun/0.1.0.
    • The agent's nsolid-version is nsolid-bun-v0.1.0+bun-v1.4.6.
  • bun upgrade: it no longer replaces nsolid-bun with oven-sh's Bun. It points at this repository's releases and exits 1.
  • Crash reports: a crash sends nothing unless BUN_CRASH_REPORT_URL names where to. It prints its trace without a bun.report address and asks for it to be included in a report to NodeSource. With BUN_CRASH_REPORT_URL set, upstream's reporting runs as before.
  • WebKit mirror:
    • --webkit-mirror=<base URL> downloads the WebKit prebuilts from a mirror, still checked against deps/webkit.sha256.
    • nsolid-webkit-mirror.yml (on main) copies the pinned release's Linux tarballs and AoT sources to a prerelease of this repository. It has run, and the repository variable NSOLID_WEBKIT_MIRROR is set, so nsolid-bun.yml builds from github.com/nodesource/ns-bun/releases/download.
  • Package scan: the agent's scan no longer blocks its thread. On a large node_modules it took seconds, during which no command was acknowledged. nsolid.packages() still scans at once, as N|Solid's does.

CI, and two fixes it found (commits 12475bc to c098795)

  • Format, Lint JavaScript (with the built-in modules type check), clippy and mordant pass. The signal handler uses bun_sys for its pipes.
  • The nsolid-bun workflow turns off core dumps in the test step. GitHub's runners hand a crashing process to systemd-coredump, which held the crash test past its timeout.
  • A SIGTERM handled on one of the agent's own threads held the exit for 5 s (the agent's thread) or 6 s (the signal reporter's) and sent no report. The handler now passes such a signal on to the main thread. Blocking the signals on those threads wasn't enough: Bun's event loop waits with every signal unblocked.

Behavior changes from Phase 0:

  • Tags shorter than 2 bytes are dropped.
  • bun --version and the default User-Agent now name nsolid-bun.

Bun's own tests that check those strings, or that expect a bun.report link, will differ. This repository's CI runs only the N|Solid tests.

How did you verify your code works?

  • bun bd test test/js/bun/nsolid/nsolid-agent.test.ts: 27 tests. They cover:

    • transport and config;
    • OTLP metrics with a worker;
    • the metrics and packages commands;
    • exit by code, uncaught exception and SIGTERM, including a SIGTERM sent with tgkill to the agent's thread and to the signal reporter's;
    • the package inventory, including the isolated-linker layout;
    • the nsolid module with and without an agent;
    • start({ grpc });
    • --version, the User-Agent, bun upgrade and the crash message.

    With USE_SYSTEM_BUN=1 they fail. All 27 pass on the debug build; when the whole file runs at once there, a few tests can take longer than the 5 s default (the same tests take about 1 s or less in CI's release build).

  • vm-thread-door inventory updated: the new signal-reporting thread is the second thread spawn in nsolid_agent.rs.

  • Against a local N|Solid Console:

    • TLS with the Console's agent CA, and a client certificate renewed without a restart;
    • an app with a worker reported metrics (heap, CPU %, RSS series), threads 0 and 1, its packages with the right required flags, and its exit with code 3.
  • --webkit-mirror checked by configuring with and without it, and in CI: the build log shows the WebKit tarball fetched from the mirror.

  • CI on 3b3aafd, before the rebase: every check passes, Linux x64 and cargo miri test included.

After the rebase: every check passes at c098795, cargo miri test included.

https://claude.ai/code/session_013nEe5T77UhAYmQxqQRbPpR


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! 😃

@edsadr edsadr changed the title nsolid (P1 layer 1): TLS, client certificates and N|Solid's reconnect and config rules nsolid Phase 1: the agent a Console can rely on Nov 23, 2026
@socket-security

socket-security Bot commented Nov 24, 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.

…ules

The agent now connects and configures itself the way N|Solid's gRPC agent
does, so a deployment's NSOLID_* settings mean the same for Bun processes.

Transport:
- NSOLID_GRPC_CERTS replaces the default roots with a CA bundle; one that
  can't be read leaves the defaults.
- NSOLID_GRPC_CLIENT_CERT and NSOLID_GRPC_CLIENT_KEY present a client
  certificate, read again every NSOLID_GRPC_CLIENT_CERT_REFRESH_INTERVAL
  seconds (60), so a renewed one is used from the next connection on. Both
  of N|Solid's warnings are kept word for word.
- NSOLID_GRPC_KEYLOG writes ./nsolid-tls-keylog-<pid>.log.
- Reconnects back off from 500 ms to 60 s with jitter, and the 20th
  UNAUTHENTICATED close stops the agent with N|Solid's warning. A stream
  that stayed up a minute resets both. The Console's retry-after lengthens
  a delay.
- A Command stream that the gateway ends with a status now counts as
  closed: before, the agent's open half kept it from reconnecting.

Config follows lib/nsolid.js: NSOLID_APPNAME before NSOLID_APP, tags of 2
to 140 bytes and at most 20 (with N|Solid's warnings), validated interval,
trace sample rate and contCpuProfileInterval, the tracing module
blacklist, statsd's localhost shorthand and default bucket, and
redactSnapshots/disableSnapshots that stay on once a source turns them on.
Reconfigure applies updateConfig's validation.

BUN_NSOLID_RETRY_MS_FOR_TESTING fixes the reconnect delay for tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013nEe5T77UhAYmQxqQRbPpR
Metrics. Every `interval` the agent exports N|Solid's process metrics
(rusage counts, memory, load, CPU %, uptimes) and each JavaScript
thread's heap (heapTotal, heapUsed, externalMem) over OTLP's
MetricsService on the gRPC channel, with N|Solid's names, units, scope
and resource. The `metrics` command answers with the last periodic
sample, as N|Solid's does. A thread's figures are read on that thread:
the main thread and each worker register with the agent, which posts
each a request through ScriptExecutionContext::postTaskTo. The agent's
own VM takes a context id outside the sequence that numbers workers, so
worker.threadId is the same with the agent as without it.

Exit. The main thread's exit, uncaught exception (message and stack)
and SIGINT/SIGTERM/SIGHUP when nothing else handles them are sent as
ExportExit; the exiting thread waits for it, 5 seconds at most. A
process that is not connected exits at once.

Packages. The node_modules scan of N|Solid's genPackageList runs on
the agent's thread; a package is `required` once the main thread has
loaded a module of it, read from its module registry and require.cache.
Packages linked by bun install's isolated linker are listed, with their
dependencies found beside them.

The nsolid module is N|Solid's: start(config) (which also starts the
agent for `grpc` or `saas`), id, config, info, metrics, packages and the
config getters. The agent publishes its configuration, so nsolid.config
shows what the Console set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013nEe5T77UhAYmQxqQRbPpR
nsolid-bun has a version of its own, 0.1.0, beside Bun's:
process.versions.nsolid_bun, `bun --version` prints "1.4.6 (nsolid-bun
0.1.0)", the User-Agent is "Bun/1.4.6 nsolid-bun/0.1.0", and the agent
sends nsolid-version "nsolid-bun-v0.1.0+bun-v1.4.6".

`bun upgrade` no longer replaces nsolid-bun with oven-sh's Bun (which
has no N|Solid agent): it points at nsolid-bun's releases and exits 1.

A crash sends no report unless BUN_CRASH_REPORT_URL names where to, and
prints its trace string without the bun.report address, asking for it
to be included in a report to NodeSource.

WebKit: --webkit-mirror=<base URL> downloads the prebuilts from a mirror,
still checked against deps/webkit.sha256. nsolid-webkit-mirror.yml copies
the pinned release (Linux tarballs and the AoT sources) to a release of
this repository; nsolid-bun.yml builds from it once the repository
variable NSOLID_WEBKIT_MIRROR is set.

The agent's package scan now runs without holding up its thread: on a
large node_modules it took seconds, during which no command was
acknowledged. nsolid.packages() still scans at once, as N|Solid's does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013nEe5T77UhAYmQxqQRbPpR
The crash test timed out in CI: the runner pipes a crashing process to
systemd-coredump, which keeps it alive while it reads bun-profile's
memory. The N|Solid test step now writes cores to a plain file and turns
them off, as Bun's own CI machines do (ci-images/spec.ts sets
kernel.core_pattern to a file).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013nEe5T77UhAYmQxqQRbPpR
- Format: rustfmt over the Phase 1 Rust.
- Lint JavaScript: four properties read in an `if` and again in its body
  are read once into a local.
- clippy: the signal module reads and writes its pipes with bun_sys,
  zeroes structs with bun_core::ffi::zeroed and passes raw pointers with
  &raw.
- mordant (unused_pub): `bun --version` and the crash handler keep
  upstream's code below an `if Global::NSOLID_BUN` branch, as
  `bun upgrade` does, so package_json_version_nl and
  bun_analytics::is_enabled stay in use. Behavior is unchanged: a crash
  is reported only to BUN_CRASH_REPORT_URL, which upstream already
  preferred over every other setting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013nEe5T77UhAYmQxqQRbPpR
The handler for SIGINT, SIGTERM and SIGHUP waits for the reporter
thread to send the exit and acknowledge it, and the report runs on the
agent's thread. A signal sent to the process goes to any thread that
does not block it, so it could land on either of them: the handler then
waited on itself, and the process took 5 seconds (the agent's thread)
or 6 (the reporter's) to exit, with no report. It is the likely cause
of a CI test whose cleanup ran past the 5-second test timeout.

Both threads now start with the three signals blocked, as do the
threads the agent's VM starts. The main thread's mask is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013nEe5T77UhAYmQxqQRbPpR
The Lint JavaScript job type-checks src/js after `bun lint`, which
failed first until now. Its types give os.userInfo().username and
fs.promises.readFile(path, "utf8") as string | Buffer; both are strings
here, and are now passed through String().

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

The last commit blocked SIGINT, SIGTERM and SIGHUP on the agent's thread
and its signal reporter. That holds for the reporter, but not for the
agent: Bun's event loop waits in epoll_pwait2 with an empty signal mask,
so the agent's thread takes every signal while it is idle. CI's release
build showed it, and another test then ran past its 5-second timeout.

The handler now checks where it runs instead. On the agent's thread or
the reporter's, the two it waits on, it sends the signal to the main
thread with pthread_kill and returns. No thread's mask changes, so the
threads the agent starts (Bun's pool among them) no longer inherit
blocked signals either.

The tests send SIGTERM to each of the two threads with tgkill: the
process now reports the signal and exits at once; it used to report
nothing and exit after 5 seconds (the agent's thread) or never (the
reporter's, with the signal blocked).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013nEe5T77UhAYmQxqQRbPpR
@edsadr
edsadr force-pushed the claude/nsolid-p1-1-transport branch 2 times, most recently from a80f658 to c098795 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