…g one (bug-076)
At a station, 73 STATION STOP presses ran as 73 concurrent StopAsync calls on the carriage. Each wrote its own
[Stop, CommandSeq]; the PLC acknowledges only the sequence it last saw, so 72 callers failed NotAcknowledged
while the axis stopped.
- A pending Stop is one shared task: the first caller writes the edge at once, later callers join it and get its
result (success or failure); a Stop after it finished is a new Stop. It runs to its end regardless of one
caller's cancellation.
- While a Stop is pending no other command word is written: a new verb is refused (G2, Busy), a command already
past its guards waits (a pre-empted verb ends with OperationCanceledException), the disconnect's Enable 0 goes
after the Stop.
- A command pre-empted at its ack deadline no longer clears its edge with CancellationToken.None after the Stop
(that stale CommandSeq made the PLC drop the Stop's ack).
- protocol.md § Command semantics: "One command in flight".
Tests: StopStormTests (8): 6 red on master (73 Stop writes, 72 of 73 callers NotAcknowledged), 8 green here.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Defect (bug-076, MAJOR)
At Pamet, 73 STATION STOP presses in 1.5 s ran as 73 concurrent
StopAsynccalls on the carriage.AxisEngine.SendCommandAsynctakes the nextCommandSequnder_sync, writes[Command, CommandSeq]and waits up to 500 ms forCommandAck == seq. Nothing serialized two callers. Each later write replaced the earlierCommandSeq, and the PLC acknowledges only the sequence it last saw. Every earlier caller therefore failed withNotAcknowledged: Stop not accepted. CommandSeq 232 written, CommandAck 302 read, although the axis stopped. Each failing Stop then cleared its edge with its own older sequence. The PLC accepted that older sequence as a new command word, so the ack went backwards (CommandSeq 237 written, CommandAck 235 read).Fix (
AxisEngineonly, plus one protocol paragraph)_stop, guarded by the existing_sync). The firstStopAsyncwrites the Stop edge at once. Callers that arrive while it is pending join it, write nothing and get its result. AStopAsyncafter it finished starts a new Stop. The Stop runs to its end underCancellationToken.None; one caller's cancellation ends only that caller's wait.Busy: … refused: a Stop is in progress, nothing written)._runningis read under the same lock that publishes the Stop, so a verb is either cancelled by the Stop or refused by G2.SendCommandAsync. The check sits under the lock that takes the sequence. A verb the Stop pre-empted ends there withOperationCanceledException, as it does today. The disconnect'sEnable 0goes after the Stop.ClearEdgeAsyncnow uses the command's own token, which the Stop cancels, instead ofCancellationToken.None. TheNotAcknowledgedbranch throws the cancellation instead of reporting the Stop's ack as its own.docs/protocol.mdI added a paragraph, One command in flight, under § Command semantics. Decision: this belongs in the protocol, not only in the driver. It changes what the PLC sees on the wire: a command the Stop pre-empts no longer gets its edge cleared, which the Acknowledge bullet promises today, and a second Stop is never written while one is pending. The repo rule says the protocol file is the contract.
protocol.pdfis not regenerated in this PR.Red → green (
StopStormTests,FakePlcChannel+DriverRig.BehaveLikePlc, which acks the lastCommandSeqit saw, like the real PLC)Stop not accepted. CommandSeq 2 written, CommandAck 1 readMaster: 6 failed, 2 passed. Branch: 8 passed. Whole
ModelingEvolution.GenericAxis.Tests: 220 passed (212 existing + 8 new).ModelingEvolution.GenericAxis.Plugin.Tests: 69 passed.TestApp.Testswas not run locally; that is CI's job.Mutation check, one change per mutant,
StopStormTestsre-run each time:SendCommandAsync→ 1 redThrowIfCancellationRequestedin the NotAck branch → 1 redNone→ 1 redNonewhileThrowIfCancellationRequestedis kept → survives. The only window is between that check and the gate acquire, and the synchronous fake has no such window. I kept it as defence in depth.Stop vs. a motion command whose handshake is waiting for its ack: what master does
Verified by the tests above on master.
StopAsynccancels the running verb, the ack wait ends at once withOperationCanceledException, nothing is written for it, and the Stop is written immediately.NotAcknowledgedbranch, clears the edge withCancellationToken.None. That writes[Enable, olderSeq]after the Stop; the PLC accepts it as a new command word and the Stop failsNotAcknowledged.NotAcknowledgedfollows.Safety (owner's order: a STOP never gets slower or weaker)
StopAsyncreturns. It goes on the Stop lane and never waits for a motion ack, with no debounce and no delay. The test asserts the write before any tick and before any fake time passes. Only one thing changed: the Stop is no longer aborted by a caller's cancellation token, which makes it stronger, not weaker.NotAcknowledged)._stopis cleared before the result is published (test).PriorityGatefinishes before the Stop's frame, because the gate serializes and the Stop enqueues after the cancel. Its queued frame is dropped; the gate never grants a cancelled waiter (PriorityGate.Waiter.WaitAsync/TakeNext).Deferred until observed (not built: no source)
Enable 0(DisableForDetachAsync, tokenNone) could take its sequence just before a Stop starts and still sit queued on the Move lane. The Stop lane would then overtake it, andEnable 0would land after the Stop with the older sequence. That frame is not motion: it drops the drive. Reaching it needs a station STOP inside the few milliseconds of a disconnect'sEnable 0. Not observed, not reproduced.ReattachAsync(the PLC dropped the lease) writes the attach edge clear outsideSendCommandAsync, and could overwrite a pending Stop's word. Not observed.StationHaltcoalescing, the "may still be moving" verdict, the Handset sending 54 presses) belongs to the separate rw2 PR.Release path into rw2 (not done here; no tag, no publish)
v0.2.1. The latest tag isv0.2.0= 2d2da1d, this branch's base.git tag v0.2.1 <merge sha> && git push origin v0.2.1..github/workflows/publish-nuget.ymlthen:ModelingEvolution.GenericAxis0.2.1 andModelingEvolution.GenericAxis.Plugin0.2.1;GenericAxis.Plugin-0.2.1.zip(layoutplugins/ModelingEvolution.GenericAxis.Plugin/0.2.1/) to the GitHub release;git grep GenericAxison rw2origin/masterfinds only a comment inMotionRoster.cs.Pluginsconfiguration section (PluginEntry[]).PluginServicewrites it on install/update (POST /api/plugins/update), stages the closure intoplugins/<id>/<version>/, and reports restart-required.PluginLoaderloads that folder at the next start.🤖 Generated with Claude Code