Skip to content

fix(p0): gate PTP SOURCE on real Ethernet link, preserve INVALID_STATE and fail clearly in Studio - #271

Open
masarray wants to merge 15 commits into
fix/p0-sv-lease-stop-provenance-20261021from
fix/p0-ptp-ethernet-link-preflight-20261021
Open

masarray wants to merge 15 commits into
fix/p0-sv-lease-stop-provenance-20261021from
fix/p0-ptp-ethernet-link-preflight-20261021

Conversation

@masarray

Copy link
Copy Markdown
Owner

Physical bench PTP SOURCE START failure — proven on #270 build

Operator flashed matching Studio+board 7f30f99a1fe43228 and attached native Copy diagnostics and GUI screenshots. PTP CONFIG accepted, but ESP32-P4 logged:

PTP general TX failed: ESP_ERR_INVALID_STATE
PTP hardware-timestamp TX failed: ESP_ERR_INVALID_STATE
PTP source readiness timeout: no verified Announce/Sync/Follow_Up TX
PTP start rejected: source_reason=SOURCE_TX_EVIDENCE_TIMEOUT

Actual PTP Announce/Sync/Follow_Up counts each 0. Role=SOURCE, STOPPED, no SV. This is a real board MAC/PHY TX readiness failure, not a cosmetic QML toggle. Whether cable/PHY link was physically DOWN or the EMAC failed despite LINK_UP is not proven by this log; the old firmware did not persist actual ETH driver+PHY state in PTP SHOW.

Fixes

  • ethernet_port.c: register independent per-driver ESP-IDF ETH_EVENT observer before esp_eth_start, distinguish STARTED/STOPPED driver and real CONNECTED/DISCONNECTED PHY. PTP START now waits at most 2.5s for both real proofs before enabling EMAC PTP mode. Fail with ETHERNET_LINK_DOWN, ETHERNET_DRIVER_NOT_STARTED, or ETHERNET_DRIVER_UNAVAILABLE, not noisy misleading TX attempts. Any Ethernet unplug/replug is reflected by event state; no guessed readiness from USB identity or selected PTP profile.
  • Always report PTP ETH driver=... link=... tx_ready=... start_reason=... in board PTP SHOW and on SOURCE START rejection.
  • ptp_lab_task.cpp: classify ESP_ERR_INVALID_STATE from BOTH general and hardware-timestamp TX as ETHERNET_TX_INVALID_STATE; preserve it through timeout rather than overwriting with SOURCE_TX_EVIDENCE_TIMEOUT. Actual transmitted Announce+Sync/FollowUp evidence remains the only successful SOURCE proof. Give up to 3.5s (was 1.6s) for established-link verified 1s-cadence TX, within Studio's 10s START_ACK deadline.
  • Studio: explicit PHY LINK DOWN/cable/switch operator message; driver not started is a separate fault; MAC TX INVALID_STATE with physical link UP is separately actionable. Firmware preflight rejection occurs before runtime ownership and MUST NOT send a redundant STOP; a TX failure from launched runtime still requires STOP ACK verification. No QML auto-start, false LOCK, or auto-release.
  • Native deterministic negative harness covers all above; structural regression guards ETH event observer, real link gating and explicit MAC fault classification.

Review/acceptance

New native Qt, embedded ESP32-P4, SOURCE/RECEIVER, C++ and Windows installer CI at exact HEAD required; do not merge main or release. Physical acceptance only after ESP32-P4 with real Ethernet cable on live switch emits consecutive Announce, Sync and HW FollowUp through PCAP and Studio, survives PTP STOP/START cycles and SV injection without device STOP, plus 1h endurance. If link remains physically DOWN, PTP must continue to refuse START and clearly identify that wiring issue (never fake RUNNING).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T03:28:07.646190Z d314217 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d31421710a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

and "kTxReady" in eth_port
and "ETHERNET_LINK_DOWN" in eth_port
and "ETHERNET_DRIVER_NOT_STARTED" in eth_port
and "ar_esp32p4_ptp_print_link_status()" in eth_port

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Fix the impossible link-status source check

Whenever check_operator_workspace.py runs, this predicate is false: the newly added function is declared in ethernet_port.c as ar_esp32p4_ptp_print_link_status(void), while the exact ar_esp32p4_ptp_print_link_status() text occurs only in live_control.cpp. Consequently, the workspace contract test now fails unconditionally before validating the rest of the change; check the C declaration spelling or inspect the call-site file instead.

AGENTS.md reference: AGENTS.md:L230-L234

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

2026-10-21 final #271 artifact handoff: physical LINK + EMAC SOURCE START gate

Exact unmerged HEAD e44cf25099841e22268e394209767742b9499179. Physical PTP SOURCE START was rejected on previous build 7f30f99a1fe43228 with both PTP general and hardware-timestamp TX returning ESP_ERR_INVALID_STATE, and 0 Announce/Sync/Follow_Up. The old snapshot could not prove whether the PHY link was connected, or whether the EMAC/driver was INVALID_STATE despite the link.

Implemented on top of #270: ETH_EVENT START+CONNECTED gate before EMAC PTP enable; bounded 2500ms preflight; typed ETHERNET_LINK_DOWN / ETHERNET_DRIVER_NOT_STARTED / ETHERNET_TX_INVALID_STATE; correctly classified GUI fail-closed transitions (no gratuitous rollback for preflight rejection, stop ACK proof for launched runtime); preserves actual SOURCE three-frame TX evidence; 3.5s bounded SOURCE startup at 1s cadence; board-reported driver/PHY link in PTP ETH status line and Advanced → Time Sync UI/Copy Diagnostics; positive/negative Qt regressions. No invented LOCK, auto START, main merge or release.

Exact SHA CI: 8/8 workflow SUCCESS (Product Naming, Embedded Profile, ESP32-P4 SMV Injector, PTP SOURCE/RECEIVER, Qt Studio native session harness and QML, Windows Lifecycle, C++ CI Linux+MSVC, Native Preview with matched firmware and clean install/upgrade/uninstall/NSIS migration).

Windows matched installer is the setup.exe within GitHub Actions artifact https://github.com/masarray/arstack61850/actions/runs/39538730514/artifacts/12319535776 . EXE ARStack-Studio-Preview-win-x64-setup.exe is 31,039,739 bytes, SHA256 328f0cb281f01daad5e66baa978349b3ab591b7f34c8927c67af02917c5cd751, independently checked against SHA256SUMS.txt in the artifact. Build ID e44cf25099841e22. Prefer supplying EXE without ZIP to operator.

Hardware still NOT ACCEPTED. Operator: install and flash matching firmware via Studio, connect ESP32-P4 physical Ethernet port to active switch, verify Advanced → Time Sync Driver STARTED · PHY UP, start SOURCE and capture actual consecutive Announce/Sync/Follow_Up, assert no false RUNNING/LOCK if link DOWN; if PHY UP yet TX INVALID_STATE, report PTP ETH and exact PTP last error for further MAC recovery investigation. Validate PTP+SV, START/STOP and 1h steady endurance. Keep PR open/unmerged.

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