Scripts: WriteBatchAndWaitAsync handshake fast-paths on the previous run's cached CompleteFlag (MesMoveOut returns stale BatchID/result) #36
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
WriteBatchAndWaitAsync(values, "MoveOutFlag", true, "MoveOutCompleteFlag", true, 25s)can be satisfied instantly by the previous run's cachedTrueon the response attribute. The script resetsMoveOutCompleteFlag = falseimmediately before the call, but that write has not echoed back from the device yet, so the event-driven wait fast-paths on the stale value. The script then readsMoveOutSuccessfulFlag/MoveOutBatchID/MoveOutErrorTextbefore the Galaxy receiver has processed the request, and returns whatever the receiver last reported.Observed on QA (vq03/vq04, build
2b9a7c3c), instance Z28061, CvdReactorMesMoveOut(template script 14) andMesMoveIn(13). The same pattern exists in the baseMESReceiver.MoveIn/MoveOutscripts (15, 16, 25, 26, 37, 38) and inMesSampleData(36).Evidence (all UTC, 2026-09-10)
MoveOutCompleteFlag3c85cc1f-825f-481c-9e15-316eb29ef4c3FalseWasSuccessful:true, BatchID:28944b3dd07f2-8ec6-4987-ab44-c474065263b1WasSuccessful:false, ErrorText:""MoveOutErrorText = "Error updating database : Machine batch not found"at 18:02:31.144,CompleteFlagat 18:02:31.16 — after the script's read6e15783d-1e61-4713-97e0-870013e710c3BatchID:28944(stale)cd5c3bfa-dd10-4e00-9dc9-a1e21c2ddcf6WasSuccessful:false, ErrorText:""SuccessfulFlag = Trueat 18:04:25.154, script read at ~18:04:25.1981db04ad-8c06-4d18-8d20-ccb5597c8279WasSuccessful:true, BatchID:28944, Data: 16 rowsThe Sept 3 MES runs on the same SAPID/container (
FBC47A3A…,F800A775…) returned"Machine batch not found"withBatchID:28944— same signature: the batch id is the receiver's last known value, not confirmation of this request.The fixed
Task.Delay(1000)after the wait masks the race only when the receiver completes inside a second; on QA it completes in roughly 0.4–1.2 s, so the outcome is a coin flip.Interim mitigation applied on QA (config only, not in the repo)
Template scripts 13 and 14 were edited on the QA central (audit entries after
AuditLogEntries383) to add, right afterrx.Attributes["<X>CompleteFlag"] = false;:With that in place the completion wait observed a real edge (see the last row above). Z28061 redeployed as deployment record 110.
Proposed follow-up
WriteBatchAndWaitAsync(andWaitAsyncwhen used as a handshake) an edge-triggered option — e.g.waitForTransition: true/ an explicit "arm after the reset echo" step — so a handshake wait cannot fast-path on the pre-existing cached value. Alternatively makeWriteBatchAndWaitAsyncaccept a reset key/value it writes and waits for before writing the trigger.MESReceiver.MoveIn/MoveOut, CvdReactorMesMoveIn/MesMoveOut/MesSampleData) so the fix is not QA-config-only, and replace the fixedTask.Delay(1000)with a wait on the result attributes where possible.ScopeAccessors/ScriptRuntimeContexttest that writesfalse, leaves the cache attrue(no device echo yet) and asserts the handshake wait does not match until the echo arrives.Related: the same session found the QA site had never received a system-artifact deployment (no
BTDBdefinition on the site), which is why thedbo.MachineCycleread inMesMoveOutfailed silently before today; that was fixed operationally withdeploy artifacts --site-id 2and is not part of this issue.Implementation and remaining deployment gates (2026-10-13)
The runtime reset-echo overload is already implemented on main (
b623fdb0). Fresh rebuilt hermetic HandshakeResetEchoTests verification passed all three cases: legacy cached-true behavior; reset echo before fresh completion; reset timeout. The earlier no-build invocation matched no tests and is not verification evidence.This issue remains open for the database-owned script rollout: deploy the supporting runtime then port/compile the reset-echo calls in QA and production scripts 13, 14, 36 and receiver scripts 15, 16, 25, 26, 37, 38. Deployment register row119 is in docs/plans/2026-09-10-handshake-reset-echo.md. No database script writes or deployments occurred in this run. Historical live OPC UA rig evidence remains historical; these three cases used local fakes.
Runtime fix landed on local main @
31b1b8db(16 commits, NOT pushed yet; QA/prod scripts deliberately untouched).Remaining for this issue: port QA/prod MES scripts 13/14/15/16/25/26/36/37/38 onto the overload and drop the Task.Delay(1000) — deferred-work register row 119 (needs this build on the target central + sites first). Design: docs/plans/2026-09-10-handshake-reset-echo-design.md
Triage 2026-11-09: runtime half verified on origin/main. Reset-aware Attributes.WriteBatchAndWaitAsync overload is
b623fdb0(ancestor of origin/main), withf7504a94(WriteBatchResetAndWait),17d5d3e6(null reset value refused),03c8a01d+3595f00d(HandshakeResetEchoTests),465a9d71(rig live gate), and was deployed to vd03 (fe89363b, 2026-09-28) and QA vq03/vq04 (b3021e7c, 2026-09-28). Remaining per the 2026-10-13 body and the 2026-09-10 comment, and found nowhere in the repo or deployment records: porting database-owned scripts 13, 14, 36 and receiver scripts 15, 16, 25, 26, 37, 38 onto the overload and dropping Task.Delay(1000) (register row 119). Leaving open for that script rollout.Platform fix is already on main (reset-echo WriteBatchAndWaitAsync overload
b623fdb0+ HandshakeResetEchoTests, deployed to vd03/QA). What remains is porting MES scripts 13/14/36 and receiver scripts 15/16/25/26/37/38 onto that overload (register row 119). Those scripts live only in the QA/prod configuration databases — the only checked-in scripts (docker/seed-mes-test-machine.sh, seed-delmia-sim.sh) use static attributes and are unaffected. Needs a wonder-side script update (CLI/UI, not a code change here).Fixed in code on main @
545d3e8b, so a new handshake no longer completes from a stale cached flag, even for the unported database-owned scripts.The six-argument
Attributes.WriteBatchAndWaitAsyncnow detects the run's own reset. If this execution wroteresponseKeythroughSetAttributeto a value other thanresponseValue(rx.Attributes["MoveOutCompleteFlag"] = false;right before the call, the MesMoveOut/MesMoveIn/MESReceiver/MesSampleData shape), it first waits event-driven for that reset to echo, and only then writes batch + trigger.falsewith nothing written and logs a warning.WaitAsyncis deliberately not gated: there the trigger is written before the wait (design §2).Tests (
HandshakeResetEchoTests):LegacyOverload_AfterTheScriptsOwnReset_WaitsForTheEcho_ThenMatchesTheFreshTrueis the QA repro (stale True cached, reset acked, not echoed). Before the fix the batch went out at once and the call returned true.…_NoEcho_ReturnsFalse_AndNeverWritesTheBatch,LegacyOverload_ResetIsConsumedByTheHandshakeThatObservedIt,ResetAwareOverload_ConsumesItsReset_SoALaterLegacyHandshakeIsNotGated. Mutation-proved: with the gate disabled the first two fail; without the reset-aware consume the last one fails.Remaining is operational only: the fix takes effect when a build at or after
545d3e8bis deployed to the sites (QA/prod runb3021e7c). After that, porting scripts 13/14/36 and 15/16/25/26/37/38 to the nine-argument overload is optional. It gives a phase-aware result. Dropping theirTask.Delay(1000)is still a script edit. No wonder-box or DB access was used. Closing as the code defect is fixed. Track the rollout under the normal deploy record.Evidence:
dotnet build ZB.MOM.WW.ScadaBridge.slnx0 warnings / 0 errors; DataConnectionLayer.Tests 483 passed (4 skipped), SiteRuntime.Tests 1016, Transport.Tests 232, Transport.IntegrationTests 151, ScriptAnalysis.Tests 103 — all green. Not deployed anywhere.