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