Skip to content

How can clock changes affect my application's task deadlines and leases?

Use a monotonic clock for in-process elapsed durations and a consistent server-side clock for durable scheduling and lease comparisons. Wall-clock adjustments can distort timeout calculations. Do not let a browser's clock determine whether an AISwapLab job failed or whether another worker owns local work.

OPERATE AN API INTEGRATIONAISwapLab team · Editorial methodPublished 2 min read
Open API documentationExplore 67 Image SkillsPrivate keys · Explicit credit approval
Article workflow: Separate time representations; Centralize coordination comparisons; Inject clock movement.
Workflow diagram: Separate time representations → Centralize coordination comparisons → Inject clock movement. Read the article for evidence and limits.

Time has several meanings

A displayed timestamp, a retry eligibility time and a measured duration serve different purposes. A laptop clock can jump, and worker clocks can disagree. Mixing those values can make leases expire early or leave overdue work apparently scheduled far in the future.

What to do next

  1. 01

    Separate time representations

    Store absolute instants for durable records and use a monotonic duration source for local performance measurement. Label client-displayed elapsed time as presentation rather than using it to authorize task transitions.

  2. 02

    Centralize coordination comparisons

    Where possible, claim and expire leases using the database's time within the same conditional operation. Avoid comparing a timestamp produced by worker A with a separately drifting local clock on worker B.

  3. 03

    Inject clock movement

    Test a forward and backward wall-clock adjustment in your application environment. Verify elapsed measurement remains meaningful, due work eventually progresses and no remote outcome is inferred solely from clock movement.

A concrete example

Illustrative example: the browser clock moves backward ten minutes while a job runs. The UI's local duration logic does not become negative, and the backend's scheduling decision remains based on its durable coordination clock.

Before you call it ready

  • Browser time cannot expire server leases.
  • Duration and timestamp fields are distinct.
  • Clock movement has a controlled test.

When to stop or choose another method

Stop using unsynchronized client wall clocks to decide ownership, terminal job status or whether a new paid action is safe.

Sources

One task. A recoverable workflow.

Check the contract, approve the quote and retain the job.

Open API documentation