Skip to content

P0 SMV: atomic 8-channel firmware scenario commit with token/hash ACK and verified START - #251

Open
masarray wants to merge 6 commits into
fix/studio-sv-stop-cancel-pending-start-20261019from
feature/smv-scenario-atomic-commit-contract-20261019
Open

masarray wants to merge 6 commits into
fix/studio-sv-stop-cancel-pending-start-20261019from
feature/smv-scenario-atomic-commit-contract-20261019

Conversation

@masarray

Copy link
Copy Markdown
Owner

P0-A: deterministic 4I+4V firmware-applied transaction (stacked on #250)

Target: Change the existing GUI → serial worker → ESP32-P4 live signal bank control path from queued FIFO only to staged, validated, firmware-committed, verified readback before START. PTP ISR, MAC timestamp gate and SV payload serialization are untouched.

Root cause at #247

DeviceController::sendCommandBatch() reports asynchronous Qt invocation admission, not firmware ACK. Each FREQ/SET/ENABLE/SHAPE command immediately published to the live signal bank; a missing/rejected SET could result in partially configured publisher output. A subsequent bare START could reuse obsolete state.

Changes

  • Reuse canonical SvLiveSignalState and SvLiveSignalBank. New fixed-capacity, control-task-only SvLiveScenarioTransaction stages one frequency, 8 value/phase/quality, 8 enable flags and one current CT shape; all required before one atomic bank.publish. Same versioned little-endian FNV-1a semantic fingerprint computed on host and device. No separate realtime SSOT.
  • Firmware capability SCENARIO-TX-V1, SCENARIO BEGIN/COMMIT/SHOW/START/ABORT, token/hash/applied generation ACKs; reject incomplete/invalid/mismatched bank, stale generation, malformed SET, and START with stale/no commit. Pending untrusted SETs cannot leak into the published bank.
  • Studio serializes the current 4I+4V GUI snapshot with the existing unit-quantization/SET encoder (no independent conversion), supplies hash and new token, waits for exact COMMIT then READBACK matching token/hash/generation, finally sends SCENARIO START, waits for same verified ACK. Stage deadlines are bounded, STOP cancels pending START via P0 Studio: cancel queued SV START with bounded priority STOP and block bare START #250 reserved safety slot.
  • Firmware identity contract includes SCENARIO-TX-V1; older compatible devices without the feature require an explicit operator-approved update before new START; no automatic flashing.
  • Portable negative tests in tests/test_live_signal.cpp, deterministic Qt token/reject/boot scope tests and updated operator workspace assertions.

Explicit current evidence limits

A software CI PASS is not evidence of hardware STOP, 4I+4V on-wire RMS/phases or PTP SOURCE AUTO <=10s. Hardware acceptance requires exact-firmware IDENTIFY, full serial transaction log (token + generation + hash), subsequent readback, independently decoded PCAP under isolated lab SOURCE with 4000fps continuity, and measured CPU/stack/ISR metrics. Prior historical captures belong to different runs and cannot validate this build.

Invariants / caution

No changes to smpSynch, SOURCE class/traceability, 4000fps ISR, MAC descriptor gating, 1 ASDU, APPID/VID/stream ID or waveform engine. Fixed one scenario staging object, bounded existing serial queue/STOP. STOP is never claimed complete from queue acceptance. This PR is not production-ready until exact-head CI and physical acceptance. No merge to main. Rollback to #250/eb7448b2 or known good bench build as appropriate.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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-19T05:07:57.588612Z a3a6e63 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: a3a6e6371f

ℹ️ 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".

Comment on lines +405 to +407
if (has_extra_token(&save) || g_running.load(std::memory_order_acquire) ||
!g_scenario.begin(token, g_signal_bank)) {
ESP_LOGE(kTag, "SCENARIO transaction=%lu rejected BEGIN", static_cast<unsigned long>(token));

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 Expire staging when the control session disappears

After SCENARIO BEGIN succeeds, the firmware keeps g_scenario active indefinitely unless it later receives COMMIT, ABORT, or STOP. If Studio disconnects or crashes during the batch, reconnect identifies successfully but the automatic PROFILE SHOW/profile-sync commands are rejected by live_control.cpp while staging is active, so Studio cannot become start-ready and therefore cannot issue a new BEGIN to recover. Bind the transaction to a bounded deadline/session and invalidate it when that ownership is lost.

AGENTS.md reference: AGENTS.md:L158-L166

Useful? React with 👍 / 👎.

Comment on lines +777 to +779
bool DeviceController::stop() {
resetScenarioStart();
return sendCommand(QStringLiteral("STOP"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Purge queued scenario commands when stopping

If Stop or failScenarioStart() runs while the initial exclusive BEGIN/SET/ENABLE/COMMIT batch is still being written, this priority STOP does not cancel the remaining batch: DeviceIoWorker::queuePrioritySvStop() removes only START commands and preserves the queued staging commands. They consequently execute after STOP; if STOP invalidated an already-written BEGIN, the remaining SETs are treated as ordinary live edits and mutate the bank non-atomically despite the cancellation. Drop the whole pending scenario transaction before enqueueing the safety STOP.

AGENTS.md reference: AGENTS.md:L160-L163

Useful? React with 👍 / 👎.

Comment on lines +367 to +370
if (scenarioStartStage_ != ScenarioStartStage::idle) {
failScenarioStart(QStringLiteral("SCENARIO serial queue rejected: ") + message);
return;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Attribute queue rejection to the rejected command

While a scenario is pending, this treats every commandRejected signal as failure of that scenario, even when the rejected command is unrelated. For example, PtpExpertPanel.qml requests a refresh every second while PTP is running; if that request lands while the exclusive scenario batch is queued, the worker rejects the PTP command and this handler aborts the otherwise valid SV start and sends STOP. Include the rejected command/transaction in the signal or suppress unrelated requests without corrupting the scenario state.

AGENTS.md reference: AGENTS.md:L86-L86

Useful? React with 👍 / 👎.

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