Skip to content

Move Node telemetry consent to mxc_ffi - #1251

Merged
Branden Bonaby (bbonaby) merged 11 commits into
mainfrom
user/bbonaby/node-native-telemetry
Sep 24, 2026
Merged

Branden Bonaby (bbonaby) merged 11 commits into
mainfrom
user/bbonaby/node-native-telemetry

Conversation

@bbonaby

@bbonaby Branden Bonaby (bbonaby) commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

📖 Description

Goal

Replace the Node SDK's telemetry executor protocol with direct, in-process
mxc_ffi calls while preserving the existing public consent API, asynchronous
presenter behavior, fail-closed policy handling, and typed native errors.

The implementation:

  • queries telemetry consent through
    mxc_telemetry_get_consent_status
  • withdraws consent through mxc_telemetry_withdraw_consent
  • requests consent through mxc_telemetry_request_consent
  • uses asynchronous native calls directly for query and withdrawal
  • uses a dedicated worker only for consent requests because the native
    presenter callback is synchronous while the JavaScript presenter may be
    asynchronous
  • returns presenter decisions through SharedArrayBuffer and
    Atomics.wait/Atomics.notify
  • bounds native progress with a deadline that pauses while the JavaScript
    presenter is deciding
  • unreferences and terminates timed-out workers so blocked native calls do not
    keep Node alive
  • preserves MxcError details, including the native FFI status
  • keeps telemetry consent Windows-only and fail-closed
  • removes the Node telemetry dependency on executor processes
flowchart LR
    A[Node telemetry API] --> B{Operation}

    B -->|query| C[Async native binding]
    B -->|withdraw| C
    C --> D[mxc_ffi telemetry APIs]

    B -->|request consent| E[Telemetry request worker]
    E --> F[mxc_telemetry_request_consent]
    F -->|synchronous prompt callback| E
    E -->|present message| G[Main-thread JS presenter]
    G -->|decision| H[SharedArrayBuffer + Atomics]
    H --> E
    E --> F

    D --> I[Native consent and policy implementation]
    F --> I
Loading

The native layer remains authoritative for consent persistence, administrative
policy, prompt content, and consent transitions. The Node SDK owns JavaScript
presentation, public result parsing, cancellation, and worker lifecycle.

Current limitations

  • Telemetry consent remains Windows-only.
  • Native diagnostics are written to process stderr on error paths; they are not
    routed through an SDK-owned console.warn channel.
  • A worker blocked inside synchronous native code may not stop immediately
    when termination is requested. The worker is unreferenced on timeout so it
    cannot keep the Node process alive.
  • Unsupported platforms fail closed and do not invoke the native telemetry
    APIs.

🔗 References

🔍 Validation

  • Node production and unit-test TypeScript builds passed.
  • Focused telemetry binding, worker, timeout, status-mapping, and public API
    tests passed.
  • Full Node unit suite passed: 475 passed, 20 skipped, 0 failed.
  • Two adversarial review-and-fix passes completed.
  • git diff --check passed.
  • Integration type-checking was not completed in the detached worktree because
    its @microsoft/mxc-sdk package alias was unresolved; the resulting errors
    were not specific to the telemetry change.

✅ Checklist

📋 Issue Type

  • Bug fix
  • Feature
  • Task

GitHub Actions runs the PR validation build automatically. The ADO pipeline
(MXC-PR-Build) is the Azure version of the PR pipeline, kept in parity with
the GitHub Actions build; it runs on merge to main, and Microsoft reviewers
with write access can trigger it on a PR with /azp run. See
docs/pull-requests.md.

If the dependency-feed-check check fails on a new dependency, the crate must
be added to the feed before the PR can pass. See
docs/pull-requests.md
for the steps.

Microsoft Reviewers: Open in CodeFlow

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bbe1ffbf-7cf8-48a0-8e3b-956f1d634e6c
Identify the synchronous host-service boundary at the file introduction.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bbe1ffbf-7cf8-48a0-8e3b-956f1d634e6c
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bbe1ffbf-7cf8-48a0-8e3b-956f1d634e6c
Explain the thread split and keep native symbol names out of user-facing failures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bbe1ffbf-7cf8-48a0-8e3b-956f1d634e6c
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bbe1ffbf-7cf8-48a0-8e3b-956f1d634e6c
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bbe1ffbf-7cf8-48a0-8e3b-956f1d634e6c
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bbe1ffbf-7cf8-48a0-8e3b-956f1d634e6c
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bbe1ffbf-7cf8-48a0-8e3b-956f1d634e6c
Restore a presenter-aware native request deadline, terminate stalled workers, cover worker failure paths, and correct native diagnostic documentation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bbe1ffbf-7cf8-48a0-8e3b-956f1d634e6c
Fail closed before committing expired presenter decisions, abandon timed-out native workers without holding process exit, preserve typed withdrawal failures, and align telemetry documentation and tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bbe1ffbf-7cf8-48a0-8e3b-956f1d634e6c
Copilot AI balanced review requested due to automatic review settings September 23, 2026 21:42
@bbonaby
Branden Bonaby (bbonaby) requested a review from a team as a code owner September 23, 2026 21:42
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Worker timeout races and the non-Windows locale behavior regression must be resolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Moves Node telemetry consent from executor processes to direct mxc_ffi bindings while preserving asynchronous presentation and typed errors.

Changes:

  • Adds native telemetry bindings and worker-based consent presentation.
  • Updates error mapping, tests, documentation, and test configuration.
  • Removes obsolete executor-protocol coverage.
File Description
sdk/​node/​tests/​unit/​telemetry.test.ts Updates public telemetry tests.
sdk/​node/​tests/​unit/​telemetry-request-worker.test.ts Tests worker lifecycle and timeouts.
sdk/​node/​tests/​unit/​default-consent-protocol-runner.test.ts Removes obsolete protocol tests.
sdk/​node/​tests/​unit/​binding-run.test.ts Extends native status mapping coverage.
sdk/​node/​src/​telemetry.ts Uses direct native telemetry operations.
sdk/​node/​src/​bindings/​telemetry.ts Defines telemetry FFI bindings.
sdk/​node/​src/​bindings/​telemetry-request-worker.ts Coordinates presenters, deadlines, and worker lifecycle.
sdk/​node/​src/​bindings/​telemetry-request-worker-entry.ts Executes blocking native consent requests.
sdk/​node/​src/​bindings/​native-error.ts Maps telemetry FFI statuses.
sdk/​node/​README.md Documents updated telemetry behavior.
sdk/​node/​package.json Registers the worker test suite.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread sdk/node/src/telemetry.ts Outdated
100: 'malformed_request',
101: 'malformed_request',
102: 'backend_error',
103: 'backend_error',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curiuos

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Return notApplicable before locale validation on unsupported platforms and update the telemetry parity checker for Node's removal of private executor-protocol results.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bbe1ffbf-7cf8-48a0-8e3b-956f1d634e6c

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The worker can invoke the presenter after the request has already timed out.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@bbonaby
Branden Bonaby (bbonaby) merged commit 5dec176 into main Sep 24, 2026
31 checks passed
@bbonaby
Branden Bonaby (bbonaby) deleted the user/bbonaby/node-native-telemetry branch September 24, 2026 00:25
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.

3 participants