|
| 1 | +# Source Addendum — PTP Timing, Result Handling, and Diagnostics |
| 2 | + |
| 3 | +The repository root `AGENTS.md` remains authoritative. This scoped addendum applies to `src/**` and strengthens deterministic failure handling and performance rules for protocol, transport, monitor, health, reporting, console, and WPF source code. |
| 4 | + |
| 5 | +## Root-cause workflow |
| 6 | + |
| 7 | +For non-trivial defects use: |
| 8 | + |
| 9 | +REPRODUCE -> TRACE MESSAGE/STATE OWNERSHIP -> ROOT CAUSE -> SMALLEST COHERENT FIX -> REGRESSION TEST -> TIMING/FAILURE CHECK -> BUILD. |
| 10 | + |
| 11 | +If three consecutive patches in the same subsystem still treat symptoms, stop before patch four and re-audit the architecture/state flow. Do not solve packet/state races with arbitrary sleeps, retries, duplicate state, or UI-side correction. |
| 12 | + |
| 13 | +## Exception-free timing-sensitive paths |
| 14 | + |
| 15 | +Expected or recoverable conditions must not use exceptions as routine control flow in: |
| 16 | +- packet serialization/parsing; |
| 17 | +- raw RX/TX loops; |
| 18 | +- Pdelay pairing/response logic; |
| 19 | +- passive monitor processing; |
| 20 | +- sequence/interval/health evaluation; |
| 21 | +- scheduler/timer callbacks; |
| 22 | +- other high-frequency timing paths. |
| 23 | + |
| 24 | +Prefer `TryXxx`, compact typed Result/status records, enums with output values, or nullable values only when failure detail is unnecessary. |
| 25 | + |
| 26 | +Normal conditions such as malformed frame, unsupported message type, sequence discontinuity, missing Follow_Up, timeout, unavailable raw transport, unsuitable adapter, bounded queue saturation, or incomplete peer state must produce explicit status/evidence rather than repeated exception unwinding. |
| 27 | + |
| 28 | +Exceptions from Npcap, OS/network APIs, filesystem/config/reporting, WPF, or third-party infrastructure may still occur. Catch them at meaningful boundaries and convert them into structured application status/diagnostics. Never let infrastructure exceptions unwind through deterministic packet-processing callbacks. |
| 29 | + |
| 30 | +## Defensive packet handling |
| 31 | + |
| 32 | +Treat all captured bytes and configuration fields as untrusted until validated. Before indexing or converting validate: |
| 33 | +- Ethernet/PTP minimum length; |
| 34 | +- EtherType/VLAN layout; |
| 35 | +- messageLength against available bytes; |
| 36 | +- message type/version/domain/flags; |
| 37 | +- timestamp and correction-field bounds; |
| 38 | +- sequence and identity field lengths; |
| 39 | +- integer/range conversions. |
| 40 | + |
| 41 | +Malformed traffic must not terminate monitor or simulator operation. Preserve raw evidence when decoding is uncertain. |
| 42 | + |
| 43 | +## Bounded asynchronous diagnostics |
| 44 | + |
| 45 | +High-rate protocol/timing paths must not perform expensive logging, file writes, report generation, JSON serialization, stack-trace formatting, or synchronous WPF notifications. |
| 46 | + |
| 47 | +Emit only compact structured events/counters such as error code, subsystem, sequence/domain/message type, timestamp/counter, and small numeric context. Transport must be bounded and non-blocking for high-rate producers. |
| 48 | + |
| 49 | +Repeated failures must be aggregated/deduplicated/rate-limited. Queue saturation must use an explicit drop/coalesce policy and retain counters. Diagnostics are observational; their failure must not stall RX/TX, Pdelay response, scheduler operation, passive monitoring, or Demo Mode. |
| 50 | + |
| 51 | +Human-readable messages/report evidence are formatted on a lower-rate/background consumer. |
| 52 | + |
| 53 | +## Timing truth and claims |
| 54 | + |
| 55 | +Software arrival timestamps are evidence about the capture path, not certified PTP accuracy. Do not convert average callback timing into an accuracy claim. |
| 56 | + |
| 57 | +Keep protocol timestamps, software arrival time, scheduler time, and UI presentation time semantically distinct. Any future hardware timestamping must be represented as a separate capability with explicit provenance. |
| 58 | + |
| 59 | +Measure worst-case/sustained behavior where timing-sensitive code changes, not only average latency. |
| 60 | + |
| 61 | +## State ownership |
| 62 | + |
| 63 | +Core owns engine/session/monitor state. Protocol owns wire semantics. Transport owns adapter/raw I/O. Reporting consumes snapshots/evidence and must not become runtime state authority. WPF presents state and issues commands; it must not repair protocol state independently. |
| 64 | + |
| 65 | +Candidate configuration/session state should be validated before activation. Failed reconfiguration must retain last-known-good state where safe or transition to an explicit stopped/faulted state; never leave a half-applied profile. |
| 66 | + |
| 67 | +## Backpressure and UI handoff |
| 68 | + |
| 69 | +Do not render one UI update per received/transmitted packet. Batch/coalesce high-frequency counters and health/status snapshots. Event evidence requiring retention must have an explicit bound/export policy rather than unbounded in-memory growth. |
| 70 | + |
| 71 | +The WPF thread must not perform blocking capture I/O, packet parsing, report generation, PCAP processing, or large serialization. |
| 72 | + |
| 73 | +## Performance/resource evidence |
| 74 | + |
| 75 | +For relevant changes measure: |
| 76 | +- packet/message throughput; |
| 77 | +- scheduler jitter/deadline misses; |
| 78 | +- Pdelay response latency distribution; |
| 79 | +- queue depth/drop/coalesce counters; |
| 80 | +- steady-state allocation rate; |
| 81 | +- CPU and memory growth; |
| 82 | +- UI update latency under sustained monitor load. |
| 83 | + |
| 84 | +Do not add workers, queues, caches, or pools without a demonstrated need and explicit lifecycle owner. |
| 85 | + |
| 86 | +## Definition of done |
| 87 | + |
| 88 | +Protocol/timing changes require deterministic byte-level regression coverage where practical, malformed/failure-path testing, successful repository build/test gates, and PCAP/Wireshark-verifiable evidence when wire behavior changes. Performance-sensitive changes require measured evidence before claiming improvement. |
0 commit comments