Skip to content

Commit 1c91088

Browse files
authored
docs: add scoped PTP timing and failure-handling contract (#19)
* docs: add scoped timing and failure-handling contract * ci: add NuGet audit fallback when dependency graph unavailable * ci: make NuGet audit fallback parse vulnerability warnings * ci: support Windows-targeted projects in NuGet audit fallback * ci: keep NuGet audit fallback SDK-8 compatible
1 parent 560043e commit 1c91088

2 files changed

Lines changed: 129 additions & 1 deletion

File tree

‎.github/workflows/dependency-review.yml‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,47 @@ jobs:
1717
- name: Checkout
1818
uses: actions/checkout@v7
1919

20-
- name: Dependency Review
20+
# Preferred gate: evaluates dependency changes against GitHub's dependency graph.
21+
# Some repositories can have the graph unavailable/disabled. Treat that as a
22+
# capability failure, not as permission to skip dependency security validation.
23+
- name: GitHub dependency review
24+
id: github_dependency_review
25+
continue-on-error: true
2126
uses: actions/dependency-review-action@v4
2227
with:
2328
config-file: .github/dependency-review-config.yml
29+
30+
- name: Setup .NET fallback
31+
if: steps.github_dependency_review.outcome == 'failure'
32+
uses: actions/setup-dotnet@v6
33+
with:
34+
dotnet-version: '8.0.x'
35+
36+
- name: NuGet vulnerability audit fallback
37+
if: steps.github_dependency_review.outcome == 'failure'
38+
shell: bash
39+
run: |
40+
set -euo pipefail
41+
echo "GitHub dependency review is unavailable or failed; enforcing NuGet audit fallback."
42+
43+
audit_log="$RUNNER_TEMP/nuget-audit.log"
44+
set +e
45+
dotnet restore ./PtpLabClock.sln \
46+
-p:EnableWindowsTargeting=true \
47+
-p:NuGetAudit=true \
48+
-p:NuGetAuditMode=all 2>&1 | tee "$audit_log"
49+
restore_exit=${PIPESTATUS[0]}
50+
set -e
51+
52+
if [[ "$restore_exit" -ne 0 ]]; then
53+
echo "NuGet restore/audit failed with exit code $restore_exit." >&2
54+
exit "$restore_exit"
55+
fi
56+
57+
if grep -Eq 'warning NU190[1-4]:' "$audit_log"; then
58+
echo "NuGet audit found a package vulnerability (NU1901-NU1904)." >&2
59+
grep -E 'warning NU190[1-4]:' "$audit_log" >&2 || true
60+
exit 1
61+
fi
62+
63+
echo "NuGet audit completed without NU1901-NU1904 vulnerability warnings."

‎src/AGENTS.md‎

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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

Comments
 (0)