TL;DR: A face terminal at a canteen counter kept changing its own clock, from India time (+05:30) to UTC and back again. While it was on UTC, every scan it stamped looked exactly 5 hours 30 minutes (19,800 seconds) old to the agent that judges scans, so the freshness rule refused them as stale and those people were not served. The terminal was not faulty. On ZKTeco-family push-protocol devices, the server’s reply to the device handshake carries settings the device applies to itself, and ours hard-coded TimeZone=0. The fix sends the site’s real offset (TimeZone=330 for India), takes effect only after the terminal restarts or reconnects, and has a regression test on the handshake reply. If a rejected event’s age equals a timezone offset, look for a timezone bug before anything else.

Key takeaways

  • In a push protocol, the handshake reply is configuration the device applies to itself. Every constant in it is a setting you own, whether you meant to own it or not.
  • An error that sits on a round number of seconds is a clue. 19,800 s is +05:30. 3,600 s is one hour. Ages that match an offset point to a timezone bug, not drift.
  • Device timestamps without a zone are only as correct as the zone you read them in, and the device’s idea of its zone may come from you.
  • A rule that works as designed on bad input still turns people away. The freshness rule was right to refuse those scans. The input was wrong.
  • A handshake setting applies at the next handshake. A fix that ships today reaches each terminal only when it restarts or reconnects.

The symptom: scans refused as stale, all at the same age

The setup is the one in the offline-queue post: biometric terminals push each scan over plain HTTP to a small agent on the site network, and the agent decides whether the scan can be served before forwarding it. One of its rules refuses a scan that is 3 minutes old or more, measured from the moment the agent queued it. That rule exists for one case, a terminal replaying old history after a reconnect, and it had passed its tests.

On site, it started refusing live scans. A person stood at the counter, looked at the camera, and the agent logged the scan as stale. The age it printed was not “200 seconds” or “a few minutes”. It was 19,800 seconds, again and again.

That number looks random until you divide it: 19,800 / 3,600 = 5.5. Five and a half hours is the offset of India Standard Time from UTC. The IANA time zone database lists Asia/Kolkata as +05:30, with no daylight saving, so the offset never moves. A rejection age equal to exactly that offset said what the bug was before I opened any code: something was reading a UTC timestamp as if it were IST.

The other half of the symptom was on the terminal itself. Its on-screen clock was not consistently wrong. It flipped: some of the time it showed local time, some of the time it showed UTC. That made the bug look like flaky hardware, which it was not.

How a server sets a terminal’s clock without meaning to

ZKTeco-family terminals speak the iclock (ADMS) push protocol. The device is always the client. When it connects, it sends a handshake request, and the server answers with a block of Key=Value options. The device reads that block and changes its own behaviour to match. The command-latency post covers one of those options, Delay, which sets how often the device polls. TimeZone is another.

The terminal sets its clock from two things the server hands it on that exchange: the Date header on the HTTP response, which RFC 9110 defines as always being in UTC (written as GMT), and the TimeZone option, which tells the device what offset to add. Send the right offset and the device shows and stamps local time. Send TimeZone=0 and you have just told it to live in UTC.

Ours sent TimeZone=0. It was one line in the shared handshake template, and no test checked it against anything:

// Illustrative. BROKEN.
function handshakeReply(device) {
  return [
    `GET OPTION FROM: ${device.id}`,
    'ATTLOGStamp=None',
    'Delay=10',
    'Realtime=1',
    'TimeZone=0',        // reads like a harmless default; it sets the device clock
  ].join('\n');
}

Here is what one scan went through while the terminal was on UTC:

  person scans at 12:30 IST
        │
        ▼
  terminal clock (told TimeZone=0) says 07:00
  scan record stamped "07:00:00"  ──  local time, no zone attached
        │
        ▼
  agent reads "07:00:00" in the site zone (IST) → 07:00 IST
  agent queued it at 12:30 IST
  age = 12:30 − 07:00 = 5 h 30 min = 19,800 s
        │
        ▼
  stale rule: 19,800 s ≥ 180 s → rejected

  ▼  a scan taken a second ago, refused as five and a half hours old

The attendance record carries a local date and time with no offset. The agent has to supply the zone, and it uses the site’s configured zone, which is correct. The device’s stamp was the wrong one, and the device stamped in UTC because the server had told it to.

The flipping had a simple cause too. Every handshake dragged the terminal to UTC. Something on the device, its own zone setting by the look of it, pulled it back to +05:30 later. The next handshake dragged it to UTC again. A terminal on a flaky network reconnects often, so from the counter it looked like a clock that could not make up its mind.

Why the freshness rule was right to refuse those scans

It is tempting to read this as the stale rule being too strict. It was not. From the agent’s side, a scan stamped five and a half hours before it arrived is exactly what a replay looks like: a terminal resending the morning’s log. Refusing it is the rule’s whole job, and if it had let the scan through, it would let through a real replay the same way.

The rule worked as designed on input that was wrong. That is the worse kind of bug to have in front of people, because nothing in the agent’s code fails. Every log line says the system did the right thing.

The direction of the error matters, and it is worth being precise about. A device clock that is behind by an offset produces scans that look old, and the stale rule catches them. A clock that is ahead by an offset produces scans from the future, and those hit the clock-skew rule (anything more than 5 minutes ahead) instead. Same bug, different rejection reason, depending on which side of UTC you are on. A site west of Greenwich, with this bug, would have seen a wall of clock_skew and no stale at all.

Reading an age as a diagnosis

The single most useful thing from this bug is the habit of looking at the exact age a rejected event reports, not only the reason. A few signatures:

Age the agent reportsMost likely causeWhy
Exactly the site offset, positive (19,800 s for +05:30)Device clock on UTC, stamps read as localA local stamp in UTC is behind local time by the whole offset
Exactly the site offset, negativeDevice clock on local time, stamps read as UTCReversed: the stamp looks ahead by the offset
A whole multiple of 1,800 s or 3,600 s that isn’t the site offsetWrong zone configured somewhere (device, agent or server)Real zones differ by half or whole hours (a few by 45 minutes)
3,600 s, starting on a known dateDST rule mismatch between device and readerOne side moved its clock and the other did not
Varies, grows slowly over daysClock drift, no time syncCrystal error accumulates; it is never a round number
Varies, large, arrives in a burstReplay of stored historyOld records sent after a reconnect, which is what the rule is for

None of this needs new tooling. The agent already printed the age in seconds on every rejection. The number was there from the first refused scan. The whole diagnosis was dividing it by 3,600.

The fix: send the site’s offset, and test the reply

The fix replaces the hard-coded line with the site’s real offset, computed from the same configured zone the agent uses to read stamps. One detail of the option’s format: the value is in hours when the offset is a whole number of hours and in minutes otherwise. So UTC is 0, +04:00 is 4, and India’s +05:30 is 330. I took that convention from our protocol code, not from a published spec, and every site we run is on +05:30. If your devices are in a whole-hour zone, check it on one before you trust it.

// Illustrative. FIXED.
function timeZoneOption(offsetMinutes) {
  // Whole hours as hours, anything else as minutes: 0, 4, 330.
  return offsetMinutes % 60 === 0
    ? String(offsetMinutes / 60)
    : String(offsetMinutes);
}

function handshakeReply(device, site) {
  return [
    `GET OPTION FROM: ${device.id}`,
    'ATTLOGStamp=None',
    'Delay=3',
    'Realtime=1',
    `TimeZone=${timeZoneOption(site.utcOffsetMinutes)}`,
  ].join('\n');
}

The site stores a fixed offset in minutes rather than an IANA name. The agent runs on an embedded Node build without a time zone database, a story told in the Node.js on Android post, and a fixed offset is safe for a zone with no daylight saving.

Then the test that should have existed from the start. It asserts on the bytes of the handshake reply, because that reply is configuration and configuration gets tests:

// Illustrative.
test('handshake sets the terminal clock to the site zone, not UTC', () => {
  const reply = handshakeReply({ id: 'T1' }, { utcOffsetMinutes: 330 });
  assert.match(reply, /^TimeZone=330$/m);
});

test('TimeZone uses hours when whole, minutes otherwise', () => {
  assert.equal(timeZoneOption(0), '0');
  assert.equal(timeZoneOption(240), '4');
  assert.equal(timeZoneOption(330), '330');
});

There is a second option I considered: leave the TimeZone line out entirely, so the terminal keeps whatever zone someone set on its own menu. That is a fair choice when the device belongs to someone else and its setting is already right. It also means the server can never correct a terminal set up wrongly. For terminals we install and configure, I would rather the server state the zone it reads stamps in. Then there is one place where it is decided.

What the handshake sendsWhat happens to the device clockWhat it costs
TimeZone=0 hard-codedDragged to UTC on every handshakeEvery stamp is off by the site offset whenever the device’s own setting loses
A hard-coded local value (330)Correct for one zoneBreaks silently the first time the code runs at a site in a different zone
Derived from the site’s configured zoneMatches the zone the agent reads stamps inOne more config value to get right per site
No TimeZone lineLeft as configured on the deviceCorrect only if someone set it right on the device; the server can’t fix it remotely

What actually broke in production

People at the counter were refused a meal because their scan was judged five and a half hours old. That is the outcome, and the reason this post exists. I do not have a reliable count of how many scans it hit. I didn’t keep one at the time, and I am not going to rebuild a number from memory.

Three things about how it happened are worth more than the count.

The default that wasn’t a default. TimeZone=0 looked like the kind of value you put in a template to be filled in later. It wasn’t filled in later, because nothing read it on our side. On the device side, it was an instruction. I had been treating the handshake reply as protocol plumbing, the thing you get byte-exact so the device keeps talking. It was also the only configuration channel the device has, and I was writing to it without reading what I wrote.

The fix does not apply when it ships. The terminal reads handshake options when it handshakes, which means after it restarts or reconnects. A deployed fix changes nothing until then. That is easy to forget when you are watching logs and waiting for the stale rejections to stop. Restart the terminal as part of the fix, and check its on-screen clock afterwards.

The bug made the hardware look broken. A clock that flips between two times looks like a failing battery or bad firmware, so the device is the obvious suspect. The pattern that cleared the device was the exactness: hardware faults are not accurate to the second, and these errors were always 19,800 seconds.

FAQ

Why does my biometric device show UTC time instead of local time? On push-protocol terminals such as ZKTeco’s iclock/ADMS devices, the server’s reply to the device handshake can include a TimeZone option, and the device applies it to its own clock. If the server sends TimeZone=0, the terminal switches to UTC. Check what your server or cloud service sends in the handshake reply before suspecting the hardware.

Why does a biometric terminal’s clock keep changing by itself? Usually two sources are setting it. The server’s handshake reply sets one zone on every connection, and the device’s own setting or time sync sets another. Each reconnect flips it back. Make the server send the zone you actually want, or stop sending a zone at all, so only one thing decides.

What does an error of exactly 19,800 seconds mean? 19,800 seconds is 5 hours 30 minutes, the offset of India Standard Time from UTC. An age, delay or difference of exactly that size almost always means a UTC timestamp was read as IST, or the reverse. In general, a time error equal to a timezone offset points to a zone mix-up, not clock drift, which is never a round number.

What unit does the ZKTeco TimeZone option use? In the convention our integration follows, the value is in hours when the offset is a whole number of hours and in minutes otherwise: 0 for UTC, 4 for +04:00, 330 for India’s +05:30. That comes from our integration code rather than a published spec, and our sites are all on +05:30, so test a whole-hour zone on your own device before relying on it.

Why didn’t my handshake change apply to the device right away? A push-protocol terminal reads its handshake options only when it handshakes: at boot, or when it reconnects after losing the connection. A server-side fix reaches each terminal at its next handshake. Restart the device after deploying, and confirm its displayed clock is correct.

Should a server send a timezone to a device at all? Send one if you install and own the devices and your server reads their timestamps in a known zone. Then the zone is decided in one place. Leave it out if the devices belong to someone else and are already set correctly, because a wrong value from the server overrides a correct setting on the device.

How do I test device handshake settings? Treat the handshake reply as configuration. Write a test that builds the reply for a known site and asserts the exact option lines in it, such as TimeZone=330 and the poll interval. A hard-coded value that is wrong for your site then fails a test instead of failing at the counter.

What I’d still improve

  • Alerting on the shape of the ages, not just the count. The agent records the age of every rejected scan. A check that flags a terminal whose stale or skewed ages cluster on a multiple of 1,800 seconds would have caught this from the first few scans. I still have not built it.
  • A clock check on every handshake. The handshake is the one moment the agent and the terminal both talk about time. Comparing the device’s reported time with the agent’s at that point would turn a wrong device clock into a warning before it turns into a rejected scan.
  • Before-and-after numbers. I did not record the stale count before and after the fix, so this post can’t show the drop. Next time a handshake option changes, I want the rejection breakdown captured on both sides of the restart.
  • The rest of the handshake template. TimeZone was the one that bit. The other options in that block deserve the same question: what does this tell the device to do, and is that what we want at this site?

The one idea to take away

Every constant you send to a device is a setting you own.

A config file gets reviewed, because everyone knows it changes behaviour. A protocol reply template doesn’t, because it looks like formatting. But when the device on the other end reads that reply and changes itself, the template is a config file that nobody is reviewing. Grep your replies the way you grep your config.


I write about backend reliability, edge devices and data correctness from work on food-tech and healthcare platforms. More on what I build and how I work, on which clock an offline queue should judge events by, and on why commands to a polling terminal are slow. If your server talks to devices, read your handshake reply line by line once.