Skip to content

fix(clock): computers and clock-following agents declare the times they hold, and the gateway refuses to take the clock outside them - #892

Open
earakely-scale wants to merge 16 commits into
mainfrom
edgararakelyan/fd-6471-clock-past-2262
Open

earakely-scale wants to merge 16 commits into
mainfrom
edgararakelyan/fd-6471-clock-past-2262

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Why

Setting the env clock past 2262-04-11 broke computers, and nothing said why (FD-6471). The clock page, which every computer's follower writes and every faked process reads, holds the universe as a signed 64-bit count of nanoseconds since 1970. That count runs out on 2262-04-11. Arming a later date made the follower crash-loop, and the computer failed with "the clock follower hasn't heard from the gateway yet".

Widening the page isn't enough, because CPython keeps time the same way. Outside 1677-09-21 to 2262-04-11, inside a faked session:

  • time.time() raises OverflowError;
  • import logging fails, so most Python programs don't start;
  • datetime.now() silently sticks at the edge of the range.

The limit belongs to what follows the clock, not to the clock. An MCP-only env's gateway clock is a Python datetime and reaches year 9999 fine. So the envs and agents that can't go further now say so, and the gateway refuses on their behalf.

What

Followers declare the times they hold.

  • A computer's card and a clock-following agent's card declare clock/v1's range: 1677-09-21T00:12:44Z to 2262-04-11T23:47:16Z (agentenv_protocol.computer.clock.RANGE).
  • Core passes each computer's range to its multi env's gateway (CLOCK_FOLLOWER_RANGES, read from the computer's card). An agent brings its own to declare_follower.

The gateway keeps to its followers' ranges (env/gateway/clock.py, clock_followers.py):

  • While the clock has a follower with a range, set_time and advance refuse a time outside it, naming the follower: virtual_time '3026-11-23T12:00:00Z' is outside the times clock follower 'desktop' holds, 1677-09-21T00:12:44Z to 2262-04-11T23:47:16Z.
  • set_time also refuses a time it would run past the end of the range from within a real hour, so a rate of 86400 still arms at today's dates.
  • declare_follower refuses an agent whose range the clock is outside now, or would run past from within a real hour. The refusal carries error code outside_range, and that agent can't follow: it's skipped, or the step fails under require_agent_clock, as for any other reason.
  • A clock that runs to the end of a follower's range anyway stops there, at rate 0. That happens when it's armed in the last hour, or sped up there by set_rate, which refuses nothing, so always_on can always restart a clock it froze.
    • Its reads, state, watch, get_time and delays all stop with it, so the gateway's tools agree with the computer.
    • Retiring the follower leaves the clock where it stands, and a follower declared while it stands is accepted.
    • A set_rate while it stands answers rate 0, until a set_time moves it.
  • A malformed range on a card is dropped with a warning, as if the card declared none.

Nothing changes without a declared range. An MCP-only env, or a computer or agent whose card predates range, gets the clock as on main, up to what a datetime holds.

Smaller change: the protocol client takes a gateway's bare-string error as the message. The advance-to-next-event hook and always_on now say why a clock write failed, rather than "400 error: Bad Request".

agent-env's libfaketime and the page. Three of these were existing bugs, found by the new range gates:

  • Absolute realtime deadlines before 1970 follow the clock. timerfd_settime, timer_settime, FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME and clock_nanosleep(TIMER_ABSTIME) got EINVAL before.
  • Deadlines are exact at either end of the range. ft_ns used to clamp any deadline past ±9e9 s, before 1684-10 or after 2255-03, so a wait there ended at once or never. A deadline and the universe at opposite ends no longer overflow.
  • libfaketime's own spec is written with its sign once before 1970. It was @-631108799.-991862200.
  • A clock that runs into the end of the range stands there in the computer rather than wrapping. Reads, waits and periodic timers stop at it, and session_time() too. The page writer keeps any universe inside the range.

Known limits, unchanged:

  • The egress proxy's CA starts in 1950, so HTTPS through a computer's proxy fails before then (FD-6928).
  • A clock change drops a timerfd's unread expirations (FD-6927).
  • HotSpot returns at once from parkUntil for a negative absolute time.

Tests

  • Unit, gateway:

    • a follower's range refuses times outside it, naming the follower;
    • the end-hour rule for arming;
    • an advance into the last hour, or a rate change, goes through;
    • an agent declared with a range brings it and loses it when retired;
    • a declaration the clock is outside is refused;
    • with no ranged follower, the clock arms in 1600, 3026 and 9999 as before;
    • CLOCK_FOLLOWER_RANGES parsing.
  • Unit, core and protocol:

    • a computer's range read from its card into the compose environment;
    • an agent's range in declare_follower, and its refusal reported as outside_range (only on that error code), or failing the step when required;
    • a malformed card range dropped;
    • both cards declaring range;
    • a clock run into a follower's end standing there at rate 0, and one with no ranged follower running on.
  • Integration:

    • computer_clock_test asserts the desktop's range in the gateway's state, and its refusal of 3026 naming it;
    • gateway_test's clock extension test arms an MCP-only gateway at 3026 and 9999.
  • Clock gates (tst/clock/range_test.py), at 1677-09-22, 1950-01-01 and 2261-08-01, and in the last hour:

    • the waits in C, Python, Java and Node at rates 1, 2 and 60, and frozen;
    • jumps, timerfds, cancellation, stalled-writer and torn reads;
    • Chrome;
    • a clock run past the end;
    • waits at the end;
    • a page before 1970 left running for 29.7 hours;
    • frozen timers that resume;
    • a periodic timer into the end.

    The tier passes 69/69 on x86_64 and arm64.

  • E2E and chaos:

    • Five rounds ran on the libfaketime changes and an earlier, gateway-wide version of the refusal: real Claude Code, OpenCode and Letta on claude-haiku-4-5, the desktop and browser computers, always_on, the hooks and triggers, and 4000 seeded clock operations, A/B against main.
    • The per-follower design ran end to end on dedicated VMs, A/B against main:
      • An MCP-only env at 3026, 9999 and 1600 matches main, including triggers, get_time and main's refusals.
      • A desktop refuses those dates naming itself, and arms at 1950, the last hour and a day per second. The refusals hold through a follower kill, a gateway restart and a reset.
      • Agents follow in range. At 3026 they're skipped as outside_range, or fail the step when required, and they bind or free the clock as they come and go.
    • The follow-up commits were re-verified on the same VMs:
      • Both new integration tests pass.
      • At a desktop's end, the gateway's state (rate 0), get_time and the session's date and python3 all read 2262-04-11T23:47:16Z.
      • A trigger delay straddling the end doesn't fire while the clock stands.
      • Retiring leaves the clock put, and a late follower is accepted.
      • set_time back to 1950 recovers, and triggers resume.
      • An MCP-only gateway still matches main at 3026 and 9999, running past 2262.
      • The agents' skip cases hold, and a real Haiku turn at the end reports 2262-04-11.

Docs

The docs site should cover:

  • clock/v1's range on an env's or agent's card: the times it holds, and the computers' and clock-following agents' 1677-09-21T00:12:44Z to 2262-04-11T23:47:16Z;
  • the gateway refusing a set_time or advance outside a follower's range, naming it;
  • a clock that runs to that end standing there;
  • sync_env_clock's outside_range reason for an agent that can't follow.

Agents get their range on their cards once their images are rebuilt with this release's protocol.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; the previous backward-read issue is fixed, and no new blocking issue was found.

Summary

Followers declare the dates they support, and the gateway keeps clock writes and running time within those dates.

  • Clock-following computers and agents declare their supported times.
  • Computer clock reads and waits stay within the supported time range.
  • Protocol callers see the message from a gateway clock refusal.

Reviews (14) · Last reviewed commit: "fix(clock): each clock operation reads r..." · Reviewed by Greptile

earakely-scale and others added 3 commits November 23, 2026 09:43
The clock page held the universe as one signed 64-bit count of nanoseconds, which runs out on 2262-04-11: a later date
made every follower crash-loop with nothing saying why. The page (version 3) holds whole seconds and nanoseconds in the
same 80 bytes; agent-env's libfaketime keeps universe times as 128-bit nanoseconds in its waits and computes clock reads
with 64-bit operations alone, in one place both share; the egress proxy reads the new page and no longer overflows on a
certificate ending past 2262; a page of another version is replaced at boot and never read. The gateway names
9999-12-31T23:59:59Z, the latest it reaches, in every error about the range. The clock gates run at 1950, across 2262,
in 3026 and in 9999.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… universe clock

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…Python and the clock page hold

CPython keeps time as 64-bit nanoseconds (time.time() raises, datetime.now() sticks at
2262-04-11 outside them), so the gateway refuses a time outside that range, or one it would
run past the end from within a real hour, with a message naming the range. The page, C and Go
go back to main; the pre-1970 deadline fix stays, with libfaketime's spec written with its
sign once before 1970.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale earakely-scale changed the title fix(clock): the env clock follows any date to 9999, past 2262 fix(clock): the env clock refuses times outside 1677–2262 up front, and timers before 1970 follow it Nov 23, 2026
earakely-scale and others added 3 commits November 23, 2026 11:07
… either end of the clock's range

ft_ns clamped any deadline past +-9e9 s (1684..2255) to +-4.6e18 ns, so near either end of the
range an absolute wait ended at once or never; it's now exact and saturates beyond 64 bits.
A deadline and the universe at opposite ends no longer overflow in ft_real_of or the timers, and
the universe at a real time (reads and waits share ft_universe_at) stops at the end of 64 bits
rather than wrapping when a gateway outlives its range.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ery refusal names the range where it's read

The gateway's clock stopped refusing times outside 1677-09-21..2262-04-11, but a clock armed within its last real
hour still ran past the end: the gateway's reads went on toward 9999, a computer's follower then wrote a universe the
page can't hold and crash-looped with the page left mid-write, and the session's clock stopped at the end of 64 bits,
where any deadline computed from now was already reached, so waits in a loop spun.

- The gateway's clock stands at LATEST: its reads, state and watch stop there, and its state says rate 0 there, so
  followers stop with it. It can still be frozen or advanced to the time it shows, and set back.
- A write is refused for passing the end within a real hour only when it brings the end closer: an advance to the time
  the clock shows (as always_on's settle makes) or a rate no faster goes through in the last hour. The check compares
  seconds, so a rate too slow for a microsecond an hour is refused too.
- Every out-of-range spelling names the range: a UTC instant past datetime's ends (0001 at +01:00, 9999 at -01:00) and
  year 0000; a string that isn't RFC3339 at all is refused as one, five digits or not.
- sync_env_clock reports a time or rate the gateway would refuse as a config problem, before anything deploys, naming
  the time as the task wrote it, its zone included; a zoned wall time no date holds names the range too.
- The clock/v1 card states the range.
- The protocol client takes a bare-string error as the message, so a refused clock write read through invoke (the
  hooks, always_on) says why instead of "400 error: Bad Request".
- clockpage.py writes a universe outside the range at its end, so a write never fails halfway.
- agent-env's libfaketime: the universe stops at FT_END, the range's last second, as the gateway's does, and a deadline
  past it is never reached; a page before 1970 runs on exactly however far it runs (128-bit sum); a periodic realtime
  timer armed on a frozen clock gets no kernel interval, where x86_64 got 1 ns from interval / 0; timerfd_gettime
  gives the whole time left to a deadline at the other end of the range.
- get_time drops its zone-overflow error, which a clock inside the range can't reach.

Tests: unit tests for each gateway case, the card, sync_env_clock's config problems, the client's string error and the
page writer's bounds; tst/env's stale 9999 tests moved to the range; clock gates for waits at the end (running into it
and frozen there), a page before 1970 left to run 29.7 h, timers on a frozen clock, and a page written past the end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ond once the clock runs again

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nt names a sync_env_clock step once

set_rate refused any rate faster than the current one, and advance any jump, that would bring the clock to the end of
its range within a real hour. A clock armed an hour or more before the end and frozen, as always_on freezes it between
turns (or a harness that pauses it, or sync_env_clock at rate 0 then set_env_clock_rate), couldn't be started again
there: always_on failed mid-run at a time inside the range, where main completes, and a hook's advance to an event in
that hour failed too. Only set_time, which arms the clock, still refuses that hour; set_rate takes any rate and advance
any time up to the end, and a clock that reaches the end stands there at rate 0, as one that outlives its range does.
A clock armed frozen at the end now answers set_rate as one that ran there does.

sync_env_clock's config problem no longer names its step itself, as the verifiers' don't: lint, which adds the step,
printed "step 'clock': step 'clock': ...".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale marked this pull request as ready for review November 24, 2026 03:11
@earakely-scale
earakely-scale requested a review from a team as a code owner November 24, 2026 03:11
…ck gets there, and session_time stands there too

A clock running into the end stood still for reads but not for a periodic timer the kernel
held, which ticked on until the follower wrote the standing page: libfaketime's helper now
wakes when the clock reaches the end and stops them there, and a timer armed past it gets no
interval. agentenv_protocol's session_time, which stamps an agent's trajectory, stops at the
end as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale and others added 3 commits November 23, 2026 19:36
…program's loop does

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nread expirations

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… it, and the gateway keeps to it

The gateway no longer limits every clock to 1677..2262: an MCP-only env's clock reaches what a
datetime holds, as before. A computer's card and a clock-following agent's declare clock/v1's
range (what 64 bits of nanoseconds since 1970 hold, as their clock page and Python keep time);
core passes a computer's to the gateway (CLOCK_FOLLOWER_RANGES) and an agent brings its own to
declare_follower. While the clock has such a follower, set_time and advance refuse a time outside
its range, naming it, set_time one it would run past the end of from within a real hour, and
declare_follower one the clock is outside now (an agent then can't follow: skipped, or the step
fails under require_agent_clock). A follower that declares none leaves the clock as it was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale earakely-scale changed the title fix(clock): the env clock refuses times outside 1677–2262 up front, and timers before 1970 follow it fix(clock): computers and clock-following agents declare the times they hold, and the gateway refuses to take the clock outside them Nov 24, 2026
@greptile-apps

This comment has been minimized.

earakely-scale and others added 3 commits November 24, 2026 09:39
…ad range never stops the gateway

Fixes from testing the per-follower clock ranges, the design unchanged:

- declare_follower refuses a ranged follower the clock would run past the end of from within a
  real hour, as set_time refuses arming with it, so arming first and declaring the agent after
  no longer gets around the horizon.
- Its range refusals carry error code outside_range, and follow() reports only those as
  outside_range: any other refusal (a name a start follower holds) raises as it does for an agent
  with no range.
- Core parses a computer's or an agent's card range itself; one that doesn't parse is logged and
  left out, as a card that declares none, rather than crash-looping the gateway at boot
  (CLOCK_FOLLOWER_RANGES) or being sent to declare_follower.
- A range that doesn't parse is refused naming "range earliest" or "range latest", not
  virtual_time.
- set_time checks an unknown time zone before overflow again, as main does.
- ExternalChild holds the parsed FollowerRange, so it stays hashable.

set_rate stays unchecked: a horizon check there would refuse always_on starting a clock it froze
near the end again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… there, and sync_env_clock is as on main

While the clock has a follower that holds only a range of times, its reads, state and watch stand
at the end of the narrowest such range, at rate 0, so the gateway's tools and the computer agree
(Greptile). sync_env_clock's up-front check is dropped: it reached steps with no follower range,
which run as on main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e and an MCP-only gateway arming past 2262

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/agent_env/env/gateway/clock.py Resolved
…there, rather than only reading there

Its run up to the end is folded in and its rate set to 0 the first time anything reads or writes it
after, so its delays and marks stop with it (elapsed and at_elapsed agree with the time it shows),
retiring the follower leaves it where it stands rather than jumping it to where it would have run,
and a follower declared while it stands is taken (Greptile, testers).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale

Copy link
Copy Markdown
Collaborator Author

Re the outside-diff P1 Gateway and computer times split (clock.py:309 on 811274d): fixed in eeb111a and 3cc0d61.

While the clock has a follower that holds only a range of times, a clock that runs to the end of that range stops there at rate 0. Its reads, state, watch and get_time stand where the computer's page stands, so the gateway's tools and the computer's programs agree.

Without a ranged follower (an MCP-only gateway, or followers from before range), the clock runs on as on main. e2e on a desktop multi env: /clock/time, /clock/state (rate 0), get_time and the session's date and python3 all read 2262-04-11T23:47:16Z within 0.7 s of a set_rate 86400, and still do after the watch's 25 s hold.

Comment thread src/agent_env/env/gateway/clock.py Resolved
…cross a follower's end never passes it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant