Skip to content

telemetry: implement deferred crash/cancellation/state-aware lifecycle instrumentation#624

Open
RamonArjona4 wants to merge 1 commit into
mainfrom
user/ramonarjona4/telemetry-deferred
Open

telemetry: implement deferred crash/cancellation/state-aware lifecycle instrumentation#624
RamonArjona4 wants to merge 1 commit into
mainfrom
user/ramonarjona4/telemetry-deferred

Conversation

@RamonArjona4

@RamonArjona4 RamonArjona4 commented Jul 8, 2026

Copy link
Copy Markdown
Member

📖 Description

Follow-up work implementing the telemetry issues deferred from the original
TraceLogging ETW PR (#493). Extends the experimental telemetry surface with
crash/panic, cancellation, and state-aware lifecycle instrumentation, and
tightens the non-zero-exit diagnostic contract, all behind the existing
--experimental + experimental.telemetry.enabled gate.

The change keeps the established PII invariant: free-form error text is never
emitted — only a bounded FailureReason/error_type enum and numeric exit
codes. On non-Windows platforms all telemetry functions compile as no-ops.

Includes review-driven hardening from adversarial + security + Copilot-style
reviews: the two telemetry-config parser paths were unified on the typed
experimental.telemetry field, a global-free crash-emit test seam was
extracted (making panic/cancellation mapping testable across any
backend/phase), and the state-aware parser now rejects a malformed
(non-object) experimental block consistently with the one-shot path.

Limitation (documented in docs/telemetry/telemetry.md): on backends that
recover panics via catch_unwind (the LXC runner), the panic hook records the
101 sentinel and claims the exactly-once terminal-emit slot, so the recovered
completion event is suppressed. There, mxc.exit_code = 101 is a
"panic occurred" marker rather than the observed process exit code.

🔗 References

Resolves #561
Resolves #562
Resolves #563
Resolves #564
Resolves #565

Related (deferred follow-up, not resolved here):

🔍 Validation

Automated (from src/, toolchain 1.93):

  • cargo fmt --all -- --check — clean
  • cargo clippy --workspace --all-targets -- -D warnings — no warnings
  • cargo test --workspace — all pass (adds panic/cancellation/state-aware
    telemetry unit tests, pure crash/state-aware event-planner tests, and
    state-aware parser tests including malformed/non-object experimental
    rejection)

CI gates run locally (all green):

  • check-version-sync, check-schema-versions, check-rust-toolchain-sync
  • check-schema-codegen + check-sdk-types-codegen (no wire-model drift)
  • validate-configs (173 configs validated against the dev schema)

Reviews: 7-axis adversarial review (findings fixed), security review (clean),
and an emulated GitHub Copilot PR review (three findings fixed).

✅ Checklist

  • Signed the Contributor License Agreement
  • Linked to an issue
  • Updated documentation (if applicable)
  • Updated Copilot instructions (if build, architecture, or conventions changed) — n/a, no build/architecture/convention changes
  • If this PR changes Cargo.lock, the dependency-feed-check check passes — n/a, Cargo.lock is unchanged

📋 Issue Type

  • Bug fix
  • Feature
  • Task
Microsoft Reviewers: Open in CodeFlow

Copilot AI review requested due to automatic review settings July 8, 2026 19:50

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.

Pull request overview

Implements the remaining deferred experimental telemetry work across executors and the state-aware lifecycle, adding crash/panic and cancellation instrumentation while tightening the “non-zero exit must surface a diagnostic” contract.

Changes:

  • Add lock-free “provider active” tracking and a new mxc.phase field to telemetry events.
  • Add a shared crash/cancellation planning + exactly-once terminal emission guard, plus state-aware lifecycle telemetry emission with per-phase attribution.
  • Factor and reuse emit_backend_error_envelope so all executors print a machine-readable diagnostic on infrastructure failures before exiting non-zero; update docs accordingly.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/mxc_telemetry/src/lib.rs Adds lock-free is_active() and threads phase through ETW event emission.
src/core/wxc/src/main.rs Initializes/attributes telemetry on the state-aware path, installs panic hook, emits cancellation telemetry from console handler, and uses shared backend-error envelope emission.
src/core/wxc_common/src/telemetry/mod.rs Adds panic/cancellation/state-aware telemetry plumbing, context attribution, and exactly-once terminal emission guard.
src/core/wxc_common/src/telemetry/events.rs Extends event model with phase and updates error logging signature accordingly.
src/core/wxc_common/src/script_runner.rs Introduces reusable emit_backend_error_envelope helper and basic unit coverage.
src/core/wxc_common/src/config_parser.rs Rejects malformed non-object experimental in state-aware parsing; populates typed experimental.telemetry from raw state-aware block.
src/core/mxc_darwin/src/main.rs Wires telemetry init/emit + panic hook and backend-error envelope emission for parity (no-op telemetry on macOS).
src/core/lxc/src/main.rs Wires panic hook and backend-error envelope emission for parity.
docs/telemetry/telemetry.md Documents state-aware phase telemetry plus crash/cancellation behavior and limitations.
docs/schema.md Reconciles supported-version table with canonical schema version bounds.

…e instrumentation

Follow-up implementing the telemetry issues deferred from the original
TraceLogging ETW PR (#493): crash/panic telemetry via a global panic hook
(#561), state-aware lifecycle instrumentation with an `mxc.phase` field
(#562), cancellation telemetry from the console control handler (#563),
non-zero-exit diagnostic parity across the executors (#564), and
reconciliation of the `docs/schema.md` supported-version table (#565).

All behind the existing `--experimental` + `experimental.telemetry.enabled`
gate. The PII invariant is preserved: free-form error text is never emitted
(bounded `FailureReason`/`error_type` and numeric exit codes only), and on
non-Windows platforms all telemetry functions compile as no-ops.

Also unifies the state-aware telemetry config on the typed
`experimental.telemetry` field, extracts a global-free crash-emit test seam
(making panic/cancellation mapping testable across any backend/phase), and
rejects a malformed (non-object) `experimental` block consistently with the
one-shot path.

Resolves #561
Resolves #562
Resolves #563
Resolves #564
Resolves #565

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@RamonArjona4 RamonArjona4 force-pushed the user/ramonarjona4/telemetry-deferred branch from 67b22aa to c6a773a Compare July 8, 2026 20:29
@RamonArjona4 RamonArjona4 marked this pull request as ready for review July 8, 2026 22:28
@RamonArjona4 RamonArjona4 requested a review from a team as a code owner July 8, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants