Write2/WriteSecured2 timestamp is interpreted as box-local time: stored source timestamp is shifted by the UTC offset #228
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?
Found while proving #212 on the DEV gateway (wonder-app-vd03), 2026-11-12.
Write2writes the value correctly, but the timestamp lands shifted by the box's UTC offset. On vd03 (US Eastern, UTC-5 in November) the stored source timestamp is 5 hours in the future.Evidence (vd03 gateway
2b13564e, itemMESReceiver_025.MoveInBatchID, Int32, supervisory advise, user id 0)Timestamp, UTC)2026-11-13T01:33:00.000Z2026-11-13T06:33:00.000Z(+5 h)2026-11-12T20:33:50.000Z(meant01:33:50Z)2026-11-13T01:33:50.000Z(the intended instant)Both values were applied (
212212, then212213), with OnWriteCompleteOk/RespondingAutomationObject. A plainWriterestore in the same session got a correct source timestamp (01:33:42.766Z, the current time). So the read path is right, and only the timestamp argument of the timestamped writes is off.Cause
VariantConverter.ConvertToComValueturns the timestamp intovalue.TimestampValue.ToDateTime(), aDateTimeKind.UtcDateTime. The COM marshaler writes its clock fields into theVT_DATEand ignoresKind. MXAccess reads theWrite2time argument as local time and converts it to UTC, which adds the offset. The read direction (ToTimestamp) treats aDATEfrom MXAccess as UTC, and that matches what MXAccess sends. So the two directions disagree.Fix
Convert to local time (
ToDateTime().ToLocalTime()) for the timestamp argument ofWrite2,WriteSecured2,Write2BulkandWriteSecured2Bulk(MxAccessCommandExecutor). Do not change value conversion: whether aTime-typed attribute value write has the same local-time rule is unproven. Add a unit test for the conversion. The opt-in live testWrite2_SupervisoryAdvise_KeepsSentTimestamp(Client.Tests, see #212) then passes on a non-UTC box. On a UTC box the bug cannot be seen at all, which is probably why it was never caught.Impact
No consumer calls
Write2today: ScadaBridge and OtOpcUa have no call site (grep, 2026-11-12). This only changes what MXAccess receives when the timestamp parameter is set. Side effect of the proof run:MESReceiver_025.MoveInBatchIDbriefly carried a06:33:00Zsource timestamp for about 12 s before the restore. If that attribute is historized, the Historian may hold one future-dated point for it.Fixed on main in
9ef6fc84. The deploy note is in76a71bc8. Not deployed. Deployment is tracked in #229 (DEV first, then QA, shipped together with #226).Fix
VariantConverter.ConvertToComTimestamp. It converts atimestamp_valueinstant to wall-clock time in the worker box's zone before the COM call, usingTimeZoneInfo.ConvertTimeFromUtcwithTimeZoneInfo.Localand its DST rules. The zone can be injected through a constructor, used only by tests.MxAccessCommandExecutoruses it for the time argument only, inWrite2,WriteSecured2,Write2BulkandWriteSecured2Bulk. The bulk session methods now take a separateconvertTimestamp.ConvertToComValuestill renders a timestamp value as UTC, because theTime-typed value-write rule is unproven. A time argument of another kind (string or number) passes through unchanged.Timestamp, and clients build it from UTC orDateTimeOffset. This is the only conversion.ToTimestamptreats them as UTC, which is correct: a plainWritereports the current UTC time. The #226 fix (892bdc1a) is the alarm path and is consistent with this. wnwrap DATE+TIME are UTC, so no offset is applied there.VT_DATEcannot tell them apart. This is documented indocs/WorkerConversion.mdandgateway.md. Run the box on UTC if exact timestamps through that hour matter.Tests
VariantConverterTimestampTests. Cases: UTC-5 (the live case 01:33Z → 20:33 local), US-Eastern EDT, both sides of spring-forward and fall-back, the fall-back ambiguity, fixed UTC+05:30 including a year rollover, a UTC box (identity), and a check that the value path stays UTC. All zones are built in code, so results don't depend on the machine.Write2,WriteSecured2and both bulk forms) now inject a fixed UTC-5 zone and assert the −5 h shift.Eastern Standard Time, UTC-5) results:Worker.Testsx86: 783 passed, 0 failed, 12 skipped.Testson the Mac: 1446 passed, 0 failed, 6 skipped.ConvertToComValuefails the 4 executor tests.WorkerLiveMxAccessSmokeTests.GatewaySession_WithLiveWorker_Write2ValueWithTimestampToAdvisedItem. This test now sends a whole-second timestamp 30 s in the past and asserts that the stored timestamp equals it when the completion isOk. It runs an in-process gateway with its own scratch worker, onTestChildObject.TestInt:9ef6fc842026-11-13T01:46:31Z2026-11-13T01:46:31ZOnWriteCompleteOk, value restored)2026-11-13T01:47:32Z2026-11-13T06:47:32ZThe windev
MxAccessGwservice was not touched: worker PIDs 14700 and 22108 were the same before and after, and/health/readyreturned 200. The scratch folder isC:\work\mxgw228.Deploy note (DEV first, then QA; full text in
docs/deploy/2026-11-12-pending-worker-time-fixes-226-228.md)mainSHA at or after9ef6fc84. Build the Worker with-p:Platform=x86and runWorker.Testsx86. Ship #226 in the same deploy.2b13564e; the only other change is #227, additive and opt-in): runUpgrade-MxGatewayService.ps1 -ExpectedSha <sha> -Label issue226-228, then the runbook section 7 checks. Then, from the Mac:LiveGatewayWrite2TestswithMXGATEWAY_LIVE_GATEWAY_ASSERT_WRITE2_TIMESTAMP=1onMESReceiver_025.MoveInBatchID, using a scoped key that is revoked afterwards.KeepsSentTimestampmust pass; it failed on2b13564e(sent 01:36:51Z, stored 06:36:51Z).CVDAisle_1.TableAlarms_008.RuntimeAlertreads2026-07-28T20:02:46.830Z.4f931e4): amainbuild carries the operator-authenticated alarm ack, so the #170 prerequisites must be met first. Deploy rolling, vq03 then vq04, and run the same checks with a QA Z28062 test attribute..bakpair has no store or schema impact.Closing on merge, following the #226 convention. The deploy and its live check are tracked in #229. Reopen this issue if the post-deploy
KeepsSentTimestampcheck fails.