Skip to content

feat: PR3 — native binary diagnostics core (C ABI + C++23)#7

Open
mrmidi wants to merge 1 commit into
pr2/provider-integrationfrom
pr3/binary-diagnostics
Open

feat: PR3 — native binary diagnostics core (C ABI + C++23)#7
mrmidi wants to merge 1 commit into
pr2/provider-integrationfrom
pr3/binary-diagnostics

Conversation

@mrmidi

@mrmidi mrmidi commented Jul 21, 2026

Copy link
Copy Markdown
Owner

PR3 — Native Binary Diagnostics Core

Base: pr2/provider-integration · Head: 76ac6e4 · 17 files, +1739/-98

C++ core (TunnelDiagnosticsCore static library)

  • C++23, no exceptions, no RTTI, C-compatible ABI (void* handles)
  • RAII: PosixFile, FlightRecorder, LifecycleStore
  • Explicit little-endian byte serialization + CRC32 (no struct dumps)
  • 72-byte flight events, 120-record ring (8,704 bytes fixed)
  • Double-buffered lifecycle snapshot (2 × 512 bytes)
  • Thread-safe recorder (internal mutex), reopen recovery from max sequence

Provider integration — complete

  • All 38+ call sites use explicit flightEvent: codes (mandatory parameter, no fallback mapping)
  • recordProviderEventflightRecorder.record() (numeric, @autoclosure message never evaluated)
  • updateDiagnosticsHeartbeatwriteLifecycleSnapshot() (binary snapshot, no JSON)
  • Zero JSONL writes, zero TunnelDiagnosticsStore calls from the provider
  • diagnosticsLock protects latestEventSequence and physicalFootprintPeakBytes
  • wsClient and lastNativeStatus copied under stateLock, status queried outside lock
  • LocalStopInitiator.binaryCode (1/2/3) and TunnelRuntimeState.binaryCode (0-6) — no hashValue
  • All snapshot fields populated: tunnelStartedMachTime, lifecycleState, providerStopReason, footprintPeak, activeBridges, activeReadLoops, latestEventSequence, packetReadPending flag, lastNativeStatus fallback, Mach memory fallback

What was removed

  • JSONL event writes from provider
  • JSON heartbeat writes from provider
  • flightEventCode(for:) category mapping (explicit codes are the contract)
  • updateDiagnosticsHeartbeat(snapshot:lastEvent:) overload (no double currentSnapshot())
  • #if FPTN_MEASUREMENT_BUILD gates on diagnostics (no JSONL to gate)

Kept (app-side, unrelated)

  • MetricKit records
  • Crash signal installer (best-effort)
  • App-side JSON readers (for old files on disk during transition)

Verification

  • C++ core: builds for iOS (arm64)
  • Xcode Debug build: succeeded
  • Tests: 27/27 passed
  • Mandatory flightEvent:: compiler enforces — no call site can regress to unmapped events

Remaining (follow-up PRs)

  • App-side decoder (TunnelDiagnosticsDecoder)
  • VPNService fallback → binary snapshot
  • LogsViewModel export → binary decoder
  • Remove obsolete JSON provider readers/models

Stack

PR-1  → master                    #1
PR0   → pr-1/measurement-safety   #2
PR1A  → pr0/native-build          #3
PR1B  → pr1a/native-baseline      #4
PR1C  → pr1b/queue-bounds         #5
PR2   → pr1c/teardown-ownership   #6
PR3   → pr2/provider-integration  #7  ← this PR
PR3A  → pr3                       next: Instruments signposts

@mrmidi
mrmidi force-pushed the pr3/binary-diagnostics branch 5 times, most recently from 6191d73 to f478402 Compare July 21, 2026 12:10
TunnelDiagnosticsCore static library:
- C++23 implementation with RAII (PosixFile, FlightRecorder, LifecycleStore)
- C-compatible public ABI (void* opaque handles, extern "C")
- Explicit little-endian byte serialization (no struct dumps)
- CRC32 checksums on all records and snapshots
- 72-byte flight events, 120-record ring (8,704 bytes fixed)
- Double-buffered lifecycle snapshot (2 × 512 bytes)
- Thread-safe recorder (internal mutex)
- Reopen recovery: scans existing records, resumes from max sequence
- No exceptions, no RTTI, no heap allocation on record path

Swift wrappers:
- TunnelFlightRecorder: RAII over C handle, allocation-free record()
- TunnelLifecycleSnapshotStore: RAII over C handle
- ProviderProcessIdentity: process-lifetime token + mach timestamp
- TunnelFlightEventCode: 24 numeric event codes

Build integration:
- DiagnosticsCoreBase XcodeGen template (library.static)
- Platform targets: iOS, macOS, tvOS
- Bridging headers include FptnTunnelDiagnostics.h
- HEADER_SEARCH_PATHS for app + tunnel targets

Provider integration (initial):
- Flight recorder + snapshot store initialized in startTunnel
- process_started + start_tunnel events recorded with fsync
- Per-tunnel session token generated

Remaining: full call-site migration, app-side decoder,
fallback migration, legacy JSON gate — follow-up commits.

Tests: 27/27 passed. Debug build succeeded.
@mrmidi
mrmidi force-pushed the pr3/binary-diagnostics branch from f478402 to 76ac6e4 Compare July 21, 2026 14:52
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