Skip to content

feat(sdk)!: run the Node SDK lifecycle in the shared Rust protocol - #4963

Open
ScriptedAlchemy wants to merge 8 commits into
masterfrom
triage/native-sdk
Open

ScriptedAlchemy wants to merge 8 commits into
masterfrom
triage/native-sdk

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Problem and issue scope

Refs #4226, and the SDK portion of the audit tracker #4230.

The Node SDK duplicated the Rust client's lifecycle and semantic rules. The
original PR also left native release delivery unwired, so publishing its
TypeScript facade would have produced an SDK without installable platform
packages and an offline extension without its required binding.

This PR moves the Node HTTP lifecycle onto the shared Rust protocol and adds
the native release, npm, installer, and updater paths needed to distribute it.
Issue #4226 should remain open until the full production-daemon installed-consumer checks,
supported-platform release builds, and npm package setup are complete. The unrelated work items tracked by #4230 remain independently
scoped.

Resulting behavior

  • The generated TypeScript facade calls a thin napi-rs binding. Rust and Node
    use the same request preparation, envelope/problem admission, SSE framing,
    cursor tracking, reconnect policy, and terminal classification. The duplicate
    TypeScript HTTP/SSE implementation is removed. The daemon retains storage,
    scheduling, authorization, and operation ownership.
  • Network and stream I/O run asynchronously on the binding's runtime.
    AbortSignal interrupts in-flight transport I/O. Explicit iterator return or
    throw interrupts an outstanding next call; a terminal frame closes its
    response before the consumer asks for another event. Disposing a stream does
    not request daemon-operation cancellation. Reads advance on consumer demand.
  • Receipt-only effect/preview outcomes and timed-out non-cancellable
    operations follow the canonical contracts. Rust TypedResponse.result is now
    optional for valid receipt-only outcomes. Typed cancellation evidence is
    decoded through its canonical type.
  • NaN, infinities, fractions, and unsafe integers in numeric transport controls
    are refused before JSON can turn them into absent values. Existing sequence
    number/bigint/decimal-string handling remains supported.
  • Native requests and responses reject integer values outside JavaScript's safe range before they can be rounded. Canonical Rust projections preserve legitimate large f64 metrics; real HTTP tests cover both directions. Receipts, events, problems, and unknown integer fields are also guarded. Decimal-string and bigint resume cursors retain exact u64 query bytes.
  • MCP-backed calls retain their existing adapter and do not load the addon.
  • Offline plugin resolution finds the addon beside the real executable, including a Windows tracedecay.exe selected through PATH; PATHEXT is only applied to an unsuffixed executable name.

Versioned migration

The TypeScript SDK is bumped from 0.15.0 to 0.16.0. The README documents the
removed custom fetch hook, strict framing and response admission, unchanged
public error classes with Rust-origin messages, explicit operation cancellation,
and iterator disposal. Applications need the platform package or an explicit
addon path. The Rust SDK README documents optional typed result payloads.

Native distribution

  • Bazel remains the Rust build authority. Stable releases build and load the
    addon on each target from .github/release-targets.json: macOS arm64, Linux
    x64/glibc, Linux arm64/glibc, and Windows x64.
  • Each target stages one @tracedecay/sdk- npm package. The facade
    build verifies complete platform coverage, package identity/version/platform
    constraints, and exact addon bytes, then links optional dependencies at the
    SDK version before packing the facade.
  • The clean installed-consumer release check uses the exact facade and host
    platform tarballs. Publication receives only digest-verified build artifacts
    and the reviewed npm CLI; it publishes platform packages before the facade
    through the existing protected OIDC environment.
  • Stable and beta native archives include tracedecay_sdk_node.node beside the
    daemon. Packaging verifies the extracted addon bytes and loads the extracted
    binding. SPDX inventory records its checksum and Rust dependency closure
    separately from the CLI. MCPB continues to launch the CLI directly.
  • The shell installer resolves its member contract from the selected release's immutable source, with source-bound attestation verification. Default and explicitly selected historical binary-only releases remain installable; releases declaring the native crate must include the addon.
  • Windows addon action outputs use drive-qualified paths across Bash and PowerShell. The Windows updater probes the installed addon before either publication and gives a typed close-ChatGPT/Node refusal when the DLL is loaded; automatic Windows CI now executes the real Node-held-addon regression. Two final file renames remain individually atomic; a later executable failure is reported as an incomplete installation.
  • The shell installer and native self-updater install both release members for native releases.
    The updater stages both before replacement and checks release identity when
    completing an older executable-only updater's missing addon. Post-update
    ChatGPT integration refresh performs that completion when needed.
  • Immutable releases predating the native SDK skip native jobs before action
    resolution. Release recovery retains the tag's target roster and uses
    compatible current runners.

Measured implementation and distribution cost

Measured against master fc80c47, using tracked
source lines including comments and blanks. Generated contracts, tests, and
unchanged SDK modules are excluded from this runtime comparison.

Handwritten implementation Before Current
TypeScript client, native loader, request controls 1,253 544
Rust client, shared protocol, semantic and request controls 1,938 2,396
Node binding and its build script 0 595
Total for these runtime files 3,191 3,535

The runtime total grows by 344 lines (10.8%) while removing the duplicate
protocol authority. The new native package staging/verification script adds
133 lines separately. These counts do not establish a speed or binary-size
improvement.

Cargo.lock adds 11 external package identities and the local sdk-node crate,
with no removed package identities. The new native build requires a target
addon build and target load check. Distribution changes from one JavaScript
package to a facade plus one selected native platform package per consumer,
with four platform packages published per release. No consumer-side compile
or package install script is introduced. Optimized addon size and cold/warm
build timing are not yet measured in this session.

Verification performed for the follow-up changes

  • TypeScript typecheck passed, including the installed-package test. The normal pinned-pnpm test command also passed all 126 cases; a Vitest include keeps the separate Node packaging tests out of that suite.
  • The actual native addon passed the 126-test TypeScript socket suite; Rust
    SDK unit tests passed all 10 cases. The addon measured 83,831,704 bytes in
    the local k8-fastbuild profile (per-crate opt level 1 with assertions), which
    is not a shipping-size measurement. The final fastbuild native package packed to 19,288,148 bytes; this is not an optimized shipping artifact or a comparable build-time benchmark.
  • Before the numeric follow-up, an empty consumer installed the actual packed Linux x64 addon and 0.16 facade with npm install --offline --ignore-scripts, imported both public entry points, resolved the platform package without an addon override, and completed a real native HTTP request plus typed 401 error mapping. This is an installed-package smoke test; its package loader and native ABI were unchanged by the numeric follow-up, whose runtime is covered by the final native tests. The full production-daemon journey remains separate.
  • Two real-file offline executable-resolution regressions passed, the ChatGPT extension typecheck passed, and regenerated embedded artifacts passed the parity check.
  • The shell installer fixture suite passed, including incomplete archives, failed second staging allocation, destination directories/symlinks, preserved prior bytes, and executable/addon permissions.
  • All 16 publication-boundary policy tests passed.
  • Native package staging/verification passed for the four target records,
    including a 2 MiB addon, byte mismatch, missing package, and empty-addon
    rejection.
  • Deterministic tar.gz/zip archive packaging tests passed.
  • Immutable release recovery tests passed, including historical retired target
    handling and complete native roster planning.
  • SPDX inventory tests passed, including native dependency ownership,
    missing-addon refusal, shared-component deduplication, and addon digest
    verification.
  • Release workflow/action YAML parsed; Bash syntax passed for 46 run blocks.
  • Pinned actionlint 1.7.12 passed all seven affected workflows without
    diagnostics; its downloaded checksum was verified.
  • Targeted blocking Clippy passed for the SDK library, SDK unit-test binary, and native addon after correcting the two hosted lint findings. The Windows Node-holder fixture now uses the production installer path to avoid inheriting read-only build-output attributes.
  • git diff --check passed.

The runtime follow-up adds regressions for receipt-only results, non-cancellable
deadline receipts, malformed cancellation observations, numeric controls,
pending-read iterator disposal, terminal connection cleanup, and the live
typed-terminal fixture. The local native SDK results above cover the changed shared runtime; the Windows resolver follow-up has its own filesystem, typecheck, and embedded-artifact verification.

Final-head integration status

Current head: cfc375d3eb008381cadb8c9554df655b48d41c28.

  • Current hosted CI run 45547003126 is validating this head, including the Windows workspace build and real Node-held-addon regression.
  • The preceding head a66593d passed repository gates, feature gates, dashboard checks, benchmark harness self-tests, blocking Clippy, and all 181 Linux Bazel test targets (31 executed, the others cached). Its Windows build exposed an addon-rule analysis failure: the Rust shared library's default output set contains multiple files on Windows, so a single-input copy could not select the DLL.
  • The corrected generator and generated SDK-node BUILD now select the primary runtime artifact through the Rust crate provider before copying it to the Node addon. Import and debug artifacts remain separate. Local generator policy tests passed, all 62 generated BUILD files passed parity checking, and all 126 native TypeScript cases executed successfully with this rule.
  • The canonical production CLI and native addon both built successfully through Bazel on the preceding head in the local assertion-enabled CI profile; this follow-up changes artifact selection, not Rust runtime source.
  • The full installed-package journey was attempted locally, but the production daemon exited before publishing its authority endpoint or making any SDK calls: UnixListener::bind returned Operation not permitted. An independent probe confirmed that socket(AF_UNIX, SOCK_STREAM) creation itself is denied before binding or accessing a filesystem path, while file locking and loopback TCP succeeded. This workspace cannot run that Unix-socket-dependent journey. This attempt is not a passing installed-consumer result.
  • The ordinary CI Rust SDK integration suite does not include its manually selected ignored production-daemon tests. The Windows loaded-DLL test is wired into hosted CI and is not claimed as locally executed on Linux.

Remaining release prerequisites and limits

  • Configure or seed npm trusted publishing for every new platform package,
    using workflow release.yml and environment npm-tracedecay-sdk as documented
    in docs/RELEASE-AUTOMATION.md. No npm publication was performed in this
    repair session.
  • Complete full production-daemon installed-consumer conformance and target release builds on the final head. The Linux native socket and installed-package smoke tests passed; YAML checks and fixture tarballs do not establish successful native linking on every supported platform. The SDK conformance workflow can be dispatched on this branch; this session could not dispatch it because the connector has no dispatch operation and the available GitHub browser session is signed out.
  • Existing external Homebrew formulas are stale source-build recipes and were
    not changed by this PR. They do not yet deliver the addon. Manager-owned
    incomplete installations receive a precise refusal rather than an
    unmanaged write into the package manager's directory. Direct archives,
    the shell installer, self-updates, and npm distribution are owned here.

Devin Review

ScriptedAlchemy and others added 2 commits November 24, 2026 14:34
Move request preparation, envelope and problem admission, SSE framing,
the delivered cursor, and the reconnect budget into `protocol`, which
performs no I/O. The blocking client now only reads and writes bytes
for it, so an async transport can reuse the same rules (#4226).

Generate `OPERATION_CONTRACTS` from the canonical registry so callers
can resolve an operation's lifecycle contract by identifier.

Fix defects the TypeScript client already guarded against:
- Evidence pages decode through the canonical `PageState`: opaque
  `{kind, cursor}` continuations are admitted, bare strings and
  non-canonical cursors are refused, and `returned` may not exceed
  `total`.
- Problems must be bound to the invoked binding; denials name none.
- Receipts must not end before they start, and cancelled or timed-out
  receipts must carry cancellation evidence.
- Curation receipts must carry a scope whose digest commits to it.
- Operations accept page size and cursor options.
- 401/403 and non-JSON media are refused from the response head,
  before reading a body that would be discarded.

The shared problem-detail fixture is proven against
`ApplicationProblem::from_detail` so other clients can build canonical
problems from it.

Refs #4226

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`@tracedecay/sdk` becomes a generated TypeScript facade over a Node-API
binding (`crates/tracedecay-sdk-node`) of the Rust SDK protocol. Node and
Rust now admit the same envelopes, problems, stream frames, terminal
states and reconnects, and the TypeScript lifecycle runtime (SSE parsing,
envelope and problem validation, cursor and reconnect handling) is
deleted.

Boundary ownership:
- Network waits run on the binding's Tokio runtime; the event loop is
  never blocked.
- An AbortSignal interrupts the in-flight native request and closes its
  connection. It never cancels the daemon operation; `cancelOperation`
  does.
- A stream reads its body only when the iterator asks for an event, so
  a slow consumer applies TCP backpressure. Early return, `close`, or
  abort release the connection.
- Errors cross as one typed payload and map onto the unchanged public
  error classes.
- MCP-backed operations stay on the caller's adapter and never load the
  binding.

Packaging: Bazel builds the addon as a `rust_shared_library` emitted by
the BUILD generator. `scripts/native-packages.mjs` stages napi-rs style
`@tracedecay/sdk-<platform>` packages from `.github/release-targets.json`
and links them as optionalDependencies at release time. Hosts can pass
an explicit `addon` path; the ChatGPT extension loads the binding
shipped beside the daemon binary, because its embedded server is a
single bundled file.

Conformance runs on real loopback sockets: event-loop responsiveness,
abort of in-flight I/O, early-return transport release without
cancellation, backpressure, process exit after settled calls, framing
limits from the shared fixture, cursor resume, and typed refusals.

BREAKING CHANGE: `ClientOptions.fetch` is removed. A Node >= 20 host
needs the platform package for its OS/arch, or an explicit `addon`
path. Error classes are unchanged but messages now come from the Rust
client. Event names outside the canonical set, problem records with
unknown or inconsistent fields, lone-CR line endings, a byte-order mark,
malformed UTF-8, and a body ending inside a frame are protocol failures.
`retry:` fields are ignored. The README documents the migration.

Refs #4226

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ScriptedAlchemy
ScriptedAlchemy enabled auto-merge (squash) November 24, 2026 23:01
devin-ai-integration[bot]

This comment was marked as resolved.

Preserve receipt-only workflow outcomes, reject invalid numeric controls, and
release native stream I/O promptly. Ship and verify native platform packages
and archive members, complete direct-install upgrades, and exercise lifecycle
and installation regressions. Refresh the branch onto current master.
@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: cfc375d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

devin-ai-integration[bot]

This comment was marked as resolved.

Reject unsafe integers across the native JSON boundary without rejecting
canonical floating-point metrics. Verify real native HTTP, SSE and resume
behavior. Install historical releases according to their immutable source
contract, normalize Windows addon paths, and refuse updates while a Node
host holds the binding. Exercise that refusal in Windows CI.

This branch has not been deployed

No deployments
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.

1 participant