refactor(tunnel): PR-1 — remove memory-triggered reconnect, gate legacy diagnostics#1
Open
mrmidi wants to merge 1 commit into
Open
refactor(tunnel): PR-1 — remove memory-triggered reconnect, gate legacy diagnostics#1mrmidi wants to merge 1 commit into
mrmidi wants to merge 1 commit into
Conversation
mrmidi
force-pushed
the
pr-1/measurement-safety
branch
from
July 20, 2026 07:32
476b55e to
4fb85bb
Compare
…nostics PR-1 (Measurement Safety) — stop legacy telemetry from contaminating native memory baselines before PR0/PR1 optimization work. Memory pressure: - Remove triggerMemoryPressureReconnect(): the emergency threshold (42 MiB) no longer destroys the WebSocket bridge and schedules a full reconnect. Recreating TLS, queues and buffers near the memory ceiling increased peak usage and obscured the actual growth source. - evaluateMemoryPressure() is now telemetry-only: both warning and emergency emit a throttled os_log entry. No bridge action, no JSONL event recording, no heartbeat rewrite originates from this method. - Remove memoryEmergencyReconnectInProgress state and all references. Measurement configuration: - Add a real Measurement build configuration (release-based) to project.yml with FPTN_MEASUREMENT_BUILD compilation condition. - recordProviderEvent() uses @autoclosure + #if gate: interpolated message strings are never constructed in Measurement builds. - updateDiagnosticsHeartbeat() returns before constructing the full runtime snapshot (native status query, ISO-8601 dates, string copies) in Measurement builds. - emitTelemetry() samples only Mach memory counters in Measurement builds, skipping the full TunnelRuntimeSnapshot construction. - TunnelLogLevelStore forces .warning in Measurement builds so info/debug messages never reach the formatter or redactor. - RingLogSink.tunnel.write() gated behind #if DEBUG: the 1 MiB ring buffer and 512 KiB file sink are compiled out of Release builds. Release builds do not retain provider text in the application-owned ring or shared log file; sparse messages continue through os_log. - TunnelDiagnosticsStore.providerRecordingEnabled runtime guard remains as defense-in-depth for non-Measurement builds. Thresholds (30/42 MiB) retained as telemetry-only markers. Recalibration deferred until real-device measurements post-PR0. Tests: 22/22 passed. Debug + Measurement configurations build.
mrmidi
force-pushed
the
pr-1/measurement-safety
branch
from
July 20, 2026 07:43
4fb85bb to
1ce6510
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR-1 — Measurement Safety
Purpose: Stop legacy telemetry from contaminating PR0/PR1 native memory measurements.
Changes (5 files)
PacketTunnelProvider.swifttriggerMemoryPressureReconnect().evaluateMemoryPressure()is telemetry-only (throttled os_log, no bridge action).recordProviderEvent()uses@autoclosure+#if FPTN_MEASUREMENT_BUILD— interpolated strings never constructed in Measurement builds.updateDiagnosticsHeartbeat()returns before building the full snapshot.emitTelemetry()samples only Mach memory counters in Measurement builds. RemovedmemoryEmergencyReconnectInProgressand all references.TunnelDiagnosticsStore.swiftproviderRecordingEnabledstatic flag as runtime defense-in-depth.recordProviderEvent()andwriteHeartbeat()no-op when disabled. App-side read path and MetricKit unaffected.TunnelLogger.swiftRingLogSink.tunnel.write()gated behind#if DEBUG.TunnelLogLevelStoreforces.warningin Measurement builds so info/debug never reach formatter/redactor.project.ymlMeasurement: releasebuild configuration withFPTN_MEASUREMENT_BUILDcompilation condition on the tunnel target. Build with-configuration Measurement.FptnVPNTests.swiftmemoryEmergencyIsTelemetryOnlytest: verifies emergency classification at/above threshold, warning just below.Measurement configuration
This is a real, reproducible build configuration — no manual uncommenting required.
What Measurement builds eliminate
recordProviderEventcall site (@autoclosure+#if)TunnelRuntimeSnapshotconstruction on 15s telemetry ticks (memory-only path)#if DEBUGgate).warninglevel)What remains active
os_logwarning/error output (sparse, transient formatting cost only)task_infomemory sampling (2 syscalls per 15s tick)Verification
Part of the memory reduction sequence