Skip to content

[FD-5916] feat(agents): the pi image follows the env's clock - #771

Closed
williamloo-scale wants to merge 63 commits into
mainfrom
wloo/pi-clock-image
Closed

williamloo-scale wants to merge 63 commits into
mainfrom
wloo/pi-clock-image

Conversation

@williamloo-scale

@williamloo-scale williamloo-scale commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What and why

The pi image can follow a task env's clock, as the Claude Code and OpenCode images can (#726, #766, #818, #832). It
follows #832's contract: it's opt-in. The agent follows only when sync_env_clock sets agent_clock: true
(require_agent_clock implies it). Otherwise pi and everything it runs keep real time.

pi follows differently from Claude Code: pi itself stays on real time, and only the commands it runs for the model
follow the clock.
pi can't safely follow the clock itself:

  • Before 1970, its compaction throws. It calls uuidv7() on Date.now(), and uuidv7 refuses a negative time. Every
    auto-compaction and every overflow recovery takes that path, so the conversation overflows for good (FD-6434).
    pi 1.5.2 and 1.6.0 have the same code, so upgrading doesn't help.
  • Its file locks (proper-lockfile) compare its clock with the locks' modification times, which stay real.

pi 1.1.0 shows the model no date of its own (upstream dropped the date from its prompt), so keeping pi on real time
hides nothing from the model.

How it works

  • Image. The clock library, the egress proxy and the shared egress rule come from utils/faketime_clock,
    utils/egress_proxy and utils/agent_clock through shared_sources.toml. The container starts as root:
    start-agent makes the clock page and the proxy's CA, then root's supervisord (root.conf) runs:

    • the follower and the egress proxy, each as its own user, on real time;
    • the A2A server as agent, with the real-time marker AGENTENV_REAL_TIME=1.
    • a listener that stops supervisord, and with it the container, once the server exits (see When the server
      exits
      ).

    libfaketime and the TLS shim are preloaded into every process and fake only agent's.

  • pi on real time. Wherever the image runs the clock (the server's environment names AGENTENV_EGRESS_PROXY), the
    bridge starts pi with the marker (cli_env), armed or not, as a clock may arm mid-turn. libfaketime keeps pi on real
    time and takes the marker out of environ, so every bash -c pi starts reads the env's time. libfaketime rewrites
    the marker string in place, so pi's /proc/<pid>/environ shows AGENTENV_REAL_TIME=0; what pi starts has no marker
    at all.

  • node /opt/pi/bin/pi. The bridge starts node itself (PI_COMMAND), with the same program and arguments the
    script's #!/usr/bin/env node gives node. Run through the shebang, env would be the process that gets the marker:
    it would scrub it and start node faked.

  • Egress. On an armed clock, pi and its commands go out by the shared rule (agent_egress.egress_env): every TLS
    host goes through the egress proxy, except:

    • loopback (the peers MCP server);
    • host.docker.internal;
    • the hosts NO_PROXY names;
    • hosts reached by plain HTTP alone.

    pi honours HTTP_PROXY, HTTPS_PROXY and NO_PROXY itself (undici's EnvHttpProxyAgent), for its model and MCP
    calls alike. On real time, pi doesn't need the proxy. But its commands inherit its environment, so it carries the
    proxy variables and goes through the proxy too. Where the proxy re-signs a certificate, pi trusts the image's CA
    through NODE_EXTRA_CA_CERTS. Node programs the model runs honour the variables through NODE_USE_ENV_PROXY, which
    Node honours from 22.21, so Node goes to 22.23.3.

  • install/v1. The build context it unpacks keeps the shared modules in their folders, and install.sh copies them
    beside the bridge, as the image's build does. An installed agent doesn't follow the clock: the target runs neither
    the follower nor libfaketime, and the bridge then adds neither the marker nor proxy variables.

  • No change to shared code. utils/faketime_clock, utils/egress_proxy, utils/agent_clock and the protocol
    package are taken as they are. The diff touches pi's folder, the agents README and tests.

What the model sees, opted in

The env's time:

  • date, datetime.now(), and the timestamps its programs write into files;
  • get_time, in the env's time and zone.

pi adds no date or time line to the prompt, and its own file tools (read, ls, find, grep) print no dates.

What isn't the env's time:

  • Times the kernel reports: files' modification times (libfaketime is built without faking stat or utime, so
    ls -l shows real times), ps start times and /proc/uptime.
  • pi's own records: session and trajectory timestamps, and its timings, are real time. They aren't sent to the
    model. The model would see them only by reading ~/.pi-a2a/sessions itself.
  • Live sites' own answers, such as an HTTP Date header, are real time, as for every clocked agent.

Clock off: what is the same and what differs

For the model and the harness:

  • pi gets the same flags.
  • The bridge adds only the marker to the server's environment. pi never sees it as =1, and the commands never see it.
  • No proxy variables are set, and everything runs on real time. A unit test pins this.

pi's and the commands' environment still differs from main's, because the image changed the server's environment (see
Environment below).

At the image level, these differ from main even with the clock off:

  • Startup: the container starts as root (CMD start-agent, no USER) under root's supervisord, which runs the
    follower (agentenv-clock), the egress proxy (agentenv-egress) and the server as agent. Started as another user,
    the image runs the server alone, as before.
  • User and home on Modal: main's image ran as root on Modal, since Modal doesn't apply the image's USER (checked
    on the VM: main's pi ran as uid 0 with HOME=/root, this image's as agent). There, pi and the model's commands now run as agent, with HOME=/home/agent, so pi's
    state moves out of root's home, and commands that need root, such as apt-get, now fail. agent is uid 1001: pi's
    Dockerfile picks no uid and the base's ubuntu user holds 1000. Unlike the other clocked images, which pin 10001,
    this is unchanged from main. On local Docker and other providers that apply USER, main already ran pi as agent.
  • Egress boot: it runs on every start. It mints the image's CA and trusts it in the system store, agent-env's
    trust files and every certifi bundle. A provider's own CA bundle (Sail's, say) is merged into agent-env's bundles and
    the proxy's roots. A failed boot stops the container (exit 2).
  • Exit status when the server exits: as on main, the container exits when the A2A server does, whatever the
    reason, so the run fails fast (see When the server exits below). What differs is the status: the container exits
    0, where main's exited with the server's own (137 when killed). supervisord 4.2.5 exits 0 after every shutdown, and
    it has no setting to change that.
  • Preload: libfaketime and the TLS shim are preloaded into every process. With the clock unarmed, they read real
    time.
  • Environment: the server's environment, and so pi's and every command's, gains (a unit test pins root.conf's set):
    • USER=agent and LOGNAME=agent (root.conf);
    • supervisord's SUPERVISOR_ENABLED=1, SUPERVISOR_SERVER_URL (root's 0700 socket, which agent can't use),
      SUPERVISOR_PROCESS_NAME=agent and SUPERVISOR_GROUP_NAME=agent;
    • NODE_EXTRA_CA_CERTS, SSL_CERT_FILE and REQUESTS_CA_BUNDLE, pointing at agent-env's bundles. On local
      Docker, main's container already had these three, with the same values, from the local provider; on Modal, main's
      had none;
    • AGENTENV_EGRESS_PROXY.
  • Python: the agent's venv, whose python3 is first on the commands' PATH, also has supervisor 4.2.5 and
    setuptools<81.
  • Logs: the server's stderr is merged into its stdout, which goes to the container's stdout. supervisord prints its
    own log there too, so docker logs shows a server's exit and the shutdown that follows. That log, and the clock and
    proxy logs, are also in /var/log/agentenv-root, which only root can read.
  • Node: 22.19.0 becomes 22.23.3, checked against nodejs.org's sha256, in the image and in install/v1.
  • pi command: pi is started as node /opt/pi/bin/pi rather than through its shebang.

When the server exits

On main, the A2A server was the container's process, so when it died the container exited and the run failed fast.
Here, root's supervisord is the container's process. If it restarted the server in place, the restarted server would
have lost what it holds in memory: the env's MCP servers, its config, its peers and the turns it's running. Later turns
would then run without the env's tools, and prompt_agent would poll Task not found until its timeout. Also, the pi
that was mid-turn would keep running and writing, because the bridge starts it in a session of its own.

So supervisord brings the whole container down with the server, and does it alone (root.conf):

  • The server is never restarted, not even when it fails to start: autorestart=false and startretries=0 on
    [program:agent].
  • A small event listener, [eventlistener:agent-exit], runs as root. It is an inline Python loop that speaks
    supervisord's READY/RESULT protocol. It hears PROCESS_STATE_EXITED and PROCESS_STATE_FATAL, and when the
    process is agent, it sends SIGTERM to its parent, supervisord. supervisord then stops the follower and the proxy,
    and exits.
  • The follower and the egress proxy keep their own restarts. When one of them exits, the listener does nothing.
  • A normal stop is unchanged. supervisord stops the server itself, which supervisord reports as STOPPED and not as
    EXITED, so the listener stays quiet.
  • No orphaned pi: when the container exits, every process in it ends with it, including a pi that was mid-turn.

Claude Code's and OpenCode's images, already on main, still restart their server in place. They need the same change.
This PR leaves shared and other agents' files alone.

Question for reviewers: should a failed egress boot stop an agent whose clock is off? All three clocked images do
today. I recommend failing fast for now: a half-done boot can leave the trust files that the server's CA variables
point at inconsistent, which breaks TLS even with the clock off. If we want resilience when the clock is off, we should
change all three images together in a follow-up: a failed boot would run the server without the clock, and
sync_time would report why.

History and working state (FD-6434)

Audit of pi 1.1.0, against FD-6434 and the #831 class:

Place What breaks on pi's own clock Fix
compaction / overflow recovery (uuidv7()) throws before 1970; the conversation overflows pi on real time
proper-lockfile (settings, auth, trust) compares Date.now() with lock mtimes; a jump forward marks a held lock compromised pi on real time
session discovery by mtime not on our path: --session-id finds the session by its header's id none needed
cache warmer, remote catalog, createSessionId benign or unreachable (PI_OFFLINE=1, --session-id always passed) none needed
changelog capture none: the server, on real time, compares each file's mtime, size and mode with the previous scan, and writes each increment's tar itself with Python's tarfile (no tar process) none needed

Known edges

  • Arming mid-turn: if a clock arms during a turn, pi stays on real time, but commands started after arming lack
    the proxy variables until the next turn. The other clocked agents behave the same way.
  • NO_PROXY matches by host: a host reached over both plain HTTP and TLS stays behind the proxy, as the shared
    rule does for every clocked agent.
  • A model endpoint outage on an armed clock: pi's model calls go through the egress proxy, which remembers an
    upstream address it found unreachable for a minute (ProbeFailedTTL) and refuses new connections to it meanwhile,
    without dialing. On the VM, with the endpoint blocked for 40 s mid-turn, pi's retries (2, 4 and 8 s) ran out on both
    sides. On this branch, pi's next turn, sent 15 s after the endpoint came back, failed too. Main's pi, going direct,
    recovered at once. main's Claude Code image's proxy does the same, and Claude Code's longer retries ride it out. The
    fix belongs in the shared proxy, outside this PR.
  • Clock range: the clock page holds the env's time as signed int64 nanoseconds, so no clock can be set after
    2262-04-11. Set later, the follower crash-loops (struct.error) and sync_env_clock reports that the agent can't
    follow. Every clocked image shares this (main's Claude Code image does the same). pi follows at 2262-01-01.

Review findings addressed

  • Call site: pi_agent.py's cli_env(...) call is tested through the A2A route with the fake CLI, which records
    the agent-env, pi and proxy variables. Mutation-checked: each of these fails tests:
    • **os.environ instead of cli_env;
    • armed=False;
    • dropping the marker;
    • always adding the marker.
  • FD-6434: fixed by running pi on real time. A newer pi (1.5.2, 1.6.0) doesn't fix it, and refusing pre-1970
    clocks would have failed the 1950 case instead of surviving it.
  • README:
    • the build instruction works (build_image, or a2a-agent put);
    • install/v1 is described as unpacking the build context;
    • the clock, the opt-in and how pi follows are documented, in pi's README and in the agents README;
    • both READMEs say pi starts as node /opt/pi/bin/pi.
  • Integration test: pi's row now checks, with no model, that a program started as the bridge starts pi (node,
    with the marker) prints real time, while the date it runs prints the env's time and its process.env has no
    marker. The module docstring no longer says every CLI follows the clock.
  • Nits:
    • the unused PYTHONPATH constant is gone;
    • the keyword is now armed;
    • install.sh checks Node's checksum;
    • ticket ids are dropped from root.conf and start-agent;
    • start.sh no longer exports a PYTHONPATH that reached the model's commands in installed agents.

Testing

Unit tests (run on macOS; the skipped tests are other agents' Linux-only tests; on the Linux VM, tst/unit/agents,
the shipped-bundle and docker-context checks: 1395 passed, none skipped):

  • tst/unit/agents/pi, test_agent_clock_images.py, test_agent_egress.py: 125 passed.
  • tst/unit/agents, the shipped-bundle, release-pin, infra-image, runtime-dependency and docker-context checks: 1446
    passed, 46 skipped.
  • New in tst/unit/agents/pi:
    • test_root_conf.py pins the crash behaviour: the server is never restarted (autorestart=false,
      startretries=0), while the follower and the proxy are. A single root listener hears EXITED and FATAL. The test
      also runs the listener's own code against a stand-in supervisord, which shows that it stops its parent on the
      server's exit or failure to start, and on nothing else. Mutation-checked: the test fails if the listener matches
      another program, signals itself, or answers FAIL, or if startretries is raised;
    • test_image_contract.py checks that the image and an install carry every module the server imports, and that
      Node is pinned by checksum;
    • test_env_clock.py covers the call site, clock-off parity, and the variables root.conf gives the server. That
      last one fails when a variable is added or dropped.
  • ruff check: clean.

Local checks against pi 1.1.0 with a stand-in OpenAI endpoint (no key):

  • no request carries a date, except in tool output;
  • pi honours the proxy variables and NO_PROXY for model and MCP calls;
  • the compaction repro passes on real time and fails with pi's clock at 1950;
  • node /opt/pi/bin/pi runs pi as the shebang does.

On a VM (Ubuntu 24.04, Docker, local sandboxes unless noted; real model anthropic/claude-haiku-4-5; A/B against
main 0.9.1609 from PyPI, whose pi is ghcr.io/scaleapi/agentenv-pi@sha256:b5af60d8…; this branch's image built from
its context, sources sha256:4e422beb…):

Case Result
Local clock e2e (test_agent_env_clock_local.py -k pi) Passed. node, started as the bridge starts pi, prints real time, the date it runs prints the env's, and the marker is scrubbed from its process.env
Clock off, no sync and a sync without agent_clock, A/B Same on both sides: real shell date, CONTEXT_DATE: NOT_GIVEN, MCP works, get_time unavailable unarmed and the env's when armed, no proxy variables, uid 1001. The model's commands see only AGENTENV_EGRESS_PROXY, USER, LOGNAME and the four SUPERVISOR_* added
Opted in at 2027-02-01 Shell, Python, file contents and get_time show 2027-02-01. ls shows the real mtime, and pi's session header is real. pi's /proc/<pid>/environ shows AGENTENV_REAL_TIME=0 and the proxy variables, and its commands have no marker. The model endpoint goes through the proxy. Main's pi, opted in, stays on real time
What pi sends the model (stand-in, every clocked FD-6434 run) No date in the system prompt or user turns. The only date is the env's, in tool output and in what quotes it
#818: env on Modal, HTTPS MCP on *.w.modal.host (cert from 2026-11-18/20), armed at 2026-10-27, at 2025-06-01 and at 2262-01-01 Passed at each: the MCP works (the proxy re-signs), and the model's curl and node fetch of example.com get 200
4 turns at +75 d, with a frozen container's advance between turns 2 and 3, a late agent and require_agent_clock Every turn kept every earlier label, and the late agent follows. With main's pi, require_agent_clock fails the step clearly (can't follow ... not_advertised)
The agent itself on Modal, env on Modal Passed: the env's date, MCP and get_time, as agent (uid 1001, HOME=/home/agent). Main's pi there runs as root (uid 0, HOME=/root)
FD-6434: 4 turns of ~40 s against a stand-in model (no key), this image vs the control (pi on the clock, fffdf44) This image passed at real, +75 d, 2262-01-01 and 1950, and at +75 d and 1950 with an advance between turns 2 and 3 and rate 10 during turn 3; its session header is real. The control passed except at 1950, with and without the jump: Auto-compaction failed: UUIDv7 timestamp must be ..., then turn 4 is refused as over the window. +1000 y can't be set (see Clock range)
Chaos Passed: rate 3600 then freeze, a forward jump, kill -9 of the follower, a backward re-arm, reset_env, clear (each turn's shell date was the clock's then; main's pi kept real time through all of it); an advance, freeze and thaw during a sleep 30 (the second date shows the jump, history kept); SIGTERM to the run mid-turn on both sides (cancelled, everything torn down); 4 opted-in runs at once with two contexts each on one agent. Endpoint blocked for 40 s mid-turn: see Known edges. Server killed mid-turn: see the next table
Workspace changelog at +75 d Each change, including a same-size rewrite with a virtual mtime, is in the next increment; an unchanged call's has no files. Same on main
Spend $1.35 by the ledger, plus about $0.10 not recorded (two cancelled turns and one Claude Code run), of $8

On the VM, after the crash-behaviour change (this branch merged with main at 64afced. The image was built from
its context and run on local Docker, against a stand-in OpenAI endpoint with no key, so this round cost nothing):

Case Result
A2A server kill -9 mid-turn, 12 s into a sleep 40 tool call, twice. ps just before the kill shows pi and its bash -c ... sleep 40 The container stopped 2.2 s and 3.2 s after the kill, with status 0. supervisord logged exited: agent (terminated by SIGKILL), and then, one second later, received SIGTERM. prompt_agent reported AgentUnreachableError 60.1 s after the kill, both times. Main took about 58 s: the time is prompt_agent's own policy (5 polls in a row over 60 s). Nothing ran on after the kill: no request reached the model, and no pi was left anywhere. The next turn failed at agent-config, as on main. Before this change, the killed turn ran to its 600 s timeout.
A turn with the clock off Passed: the real date.
A turn opted in at 2027-02-01, then the follower kill -9'd, an advance to 2027-02-11, and another turn Passed: 2027-02-01. The follower restarted and the container stayed up. The advance was followed, and the next turn showed 2027-02-11.
The image alone (docker run, no agent-env) kill -9 of the server: the container exited 2.1 s later, with status 0. kill -9 of the follower, then of the egress proxy: each restarted, and the container stayed up. docker stop: 1.2 s, status 0; the server shut down on SIGTERM and supervisord logged it as stopped. A server that can't start (its script renamed): FATAL at once, no restart, and the container exited, with status 0.

Claude, working with Edgar, finished this PR.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new actionable issues were found.

Summary

The pi image can now follow the env’s clock when opted in. Pi stays on real time; commands it starts follow the env’s time.

  • Pi’s commands can follow an opted-in environment clock while pi stays on real time.
  • The pi container stops when its A2A server exits or cannot start.
  • Pi installs use verified Node 22.23.3 and copy the bridge’s shared modules.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Start["start-agent as root"] --> Setup["Create clock page and prepare trust"]
  Setup --> Supervisor["supervisord"]
  Supervisor --> Follower["Clock follower on real time"]
  Supervisor --> Proxy["Egress proxy on real time"]
  Supervisor --> Server["A2A server on real time"]
  Server --> Pi["Node runs pi with real-time marker"]
  Pi --> Commands["Commands follow the armed clock"]
  Server --> Exit["Server exits or fails to start"]
  Exit --> Listener["Listener stops supervisord"]
  Listener --> Stop["Container stops"]
Loading

Reviews (12) · Last reviewed commit: "fix(agents): the pi container exits when..." · Reviewed by Greptile

williamloo-scale and others added 30 commits November 16, 2026 11:29
…5916)

Prototype of the Agents on the Env Clock design, to size the change. The gateway takes followers declared after it
starts; every AgentEnvAgent in an image that runs the clock follower serves clock/v1 sync_time; sync_env_clock and
deploy_agent declare each agent as a follower and hand it its config; the Claude Code image runs the computer base's
follower, egress proxy and libfaketime, copied in until FD-5700; get_time no longer calls the machine's clock unsynced.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…kip unless require_agent_clock

The image's changes move to wloo/claude-code-clock-image, along with the computer base's egress options only it uses:
on CI the image's Claude Code timed out reaching the test's model endpoint. What stays serves sync_time for an agent
whose image runs the follower and is otherwise inert. An agent that can't follow is now skipped even when
tolerate_missing_sync_time is false, which stays about the env's servers; require_agent_clock fails the step instead.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The image half of the agent clock: the computer base's clock follower and egress proxy, copied in until FD-5700,
libfaketime preloaded for the agent's user, root's supervisord starting them and the A2A server, and the CLI sent
through the proxy. Needs #714 and an agentenv-protocol release with CLOCK_V1.

Not ready: on CI this image's CLI timed out reaching the integration tests' model endpoint, likely the proxy refusing
a private address; it should go through the proxy only once the clock is armed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…gent, retire on teardown

- An agent's sync_time takes only a status of the config it just wrote (its URL and name, written after it), so what
  the follower showed of an earlier gateway or token never passes for success.
- An agent follows one env's clock; another env's is skipped as follows_another_env, as its one follower can't watch
  two gateways. deploy_agent's late follows are recorded with the sync's, so both see it.
- teardown_sandboxes retires a torn-down agent's follower (DELETE /clock/followers, retire_follower), so later writes
  don't wait for it or answer 504 naming it. A declaration no longer replaces a follower the gateway started with.
- Logs say an outcome's synced, reason and follower, never the agent's answer; the timeouts, token size and error
  length are named constants.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…tirement wakes waiting writes

- Which env an agent follows moves from clock_configurations' items to metadata.agent_clock_following, one key per
  agent, so late deploy_agent steps that save at once never overwrite each other's record and teardown still finds it.
- Retiring a follower notifies writes waiting for it, and a watch by a follower retired meanwhile acknowledges nothing.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… retire however its sandbox goes

- Agent names are percent-encoded into their metadata keys, so team.solver and team_solver never share a record.
- An agent follows the clock of the first env it's registered with, fixed by the agent alone, so two steps arming two
  of its envs at once never both take its one follower.
- teardown_sandboxes retires the follower of every agent whose sandbox it takes down, by agent, sandbox or env name.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…d on local Docker (FD-5916)

Deploys the image with an env, runs sync_env_clock with require_agent_clock, and checks that the agent's user reads
the env's time (date and datetime.now()) while the real-time marker opts out; that a write waiting for followers waits
for the agent, answering 504 naming it while its container is paused; and that after teardown_sandboxes writes no
longer wait for it. Skipped unless AGENTENV_E2E_CLAUDE_CODE_IMAGE names an image built from this branch.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…e survives a server restart; get_time keeps its sentence

- follow retires the follower it declared when the agent's sync_time fails, by an HTTP error or a transport one, so the
  gateway isn't left waiting on every later write for a follower that never watches.
- sync_time saves the task's zone in the follower's config, and the A2A server takes it back when it starts, so a
  server supervisord restarts mid-run keeps the zone as the follower keeps the clock.
- get_time's description keeps "the clock on the machine you are running on is not synchronized": most agents
  won't follow the clock for a while yet.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…through the proxy only on an armed clock

- The agent's libfaketime takes Edgar's init guard: a clock call made while ftpl_really_init runs on that thread, as
  the CLI's allocator makes one when dlsym allocates, reads the kernel's clock instead of waiting on pthread_once, which
  deadlocked: claude --version never returned. The computer base's patch doesn't take it yet; the agent's copy is the
  base's, then the guard, which the drift test checks.
- The CLI goes out through the egress proxy only while the follower follows an armed clock (clock_armed), and reaches a
  plain-HTTP model endpoint directly then: unarmed, it goes out as before, so a private endpoint keeps working.
- egress/ is the base's again after main moved it.
- The e2e test checks claude --version under the preload, and one turn of the real CLI against a stub Messages
  endpoint: its "Today's date is" line and a Bash date are the env's.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… down alone

Their records stay in deployed_agents after teardown, and calling their gone servers failed the step.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…browser base's egress copy takes boot.go

- test_agent_env_clock_local skips as agentenv-capability-missing: agent_clock_image, which the slow integration job
  allows, as no CI job builds agent images.
- ubuntu-24.04-browser's egress/ is ubuntu-24.04's again, with this PR's AGENTENV_SESSION_USER and AGENTENV_EGRESS_NSS.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…tocol's tests write it

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…lag, not the follower's status

The page is what libfaketime reads, and it keeps the last armed clock while the follower reconnects to a restarted
gateway or restarts itself, when its status says connected false or armed false. A CLI started then reads the env's
time, so it must go through the proxy. Unit tests pin both windows.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ds show

An agent whose card serves clock/v1 sync_time is now checked end to end after the validation DAG: the validation
env's clock is armed frozen in America/Chicago with require_agent_clock, the agent runs `date` through its harness
and must show that instant and zone, a write that waits for followers must be acknowledged, and `date` must show the
time it moved to. A synced follower alone doesn't pass: an image whose preload is missing, or whose harness can't run
under it, follows and still fails. An agent whose card serves no sync_time is skipped. The result is recorded under
validated_a2a_extensions[urn:agentenv:clock/v1] and verifications["a2a_clock"].

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

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ed with the env

An agent in an image that follows the env's clock reads the env's time, so "is not synchronized, so do not use it"
is false for it. "May not be" holds for every agent, following or not, and get_time answers what a following
agent's clock already shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he other agent extension clients

It drives an agent's clock/v1 sync_time and the gateway's follower declarations for the steps that call it
(sync_env_clock, deploy_agent, teardown_sandboxes), as object_transfer does for snapshot transfers; it defines no step.
The name mirrors agentenv_protocol.a2a_agent.clock, the agent's side of the same extension. The persisted
metadata key agent_clock_following is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t.clock, where #714 moved it

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…st with an agent's clock/v1 sync_time

0.1.575 is the release that carries #714 (agentenv_protocol.a2a_agent.clock): before it, the image's protocol serves
no clock/v1, so the agent advertises none and sync_env_clock skips it as not_advertised. The image is built again only
when this folder changes, so the floor is what makes it take the release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… gateway refuses at once

A watch that fails fast (connection refused) answers before the follower's quarter-second poll sees a changed config,
and the retry backoff ends early on that change, so the follower kept retrying the old URL in a tight loop and never
followed the new one: an agent re-synced to another gateway after its first one went away stayed on the old clock,
burning a core, and every write that waited for it answered 504. It now checks the config after each failed watch.
The base's, the browser base's and the Claude Code image's copies stay identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ct; name the egress probe's error limit

- egress_env merges the hosts NO_PROXY and no_proxy already name with the direct ones, so a private registry the agent
  was deployed to reach directly isn't sent to the proxy, which refuses it, once the clock is armed.
- egress/upstream.go names its 200-character problem limit (problemChars), in the computer bases' copies too, which
  stay byte for byte the same.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ge, not Claude Code's alone

- tst/unit/agents/test_agent_clock_images.py: every agent folder with clock/ copies the base's clock pieces with the
  init guard, runs the follower, the proxy and the server as their users, preloads libfaketime for the agent's user,
  starts as another user as before, and decides the CLI's proxy with the same clock_armed and egress_env as Claude Code.
- The local e2e runs over each image AGENTENV_E2E_AGENT_IMAGES names (claude-code=<tag>,...), with a CLI turn for an
  agent whose CLI the stub endpoint speaks to.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
# Conflicts:
#	src/agent_env/agents/agents/pi/requirements.txt
# Conflicts:
#	tst/integration/task_step/test_agent_env_clock_local.py
@earakely-scale

Copy link
Copy Markdown
Collaborator

Hi @williamloo-scale, this is Claude, working with Edgar. Please don't merge this yet. It needs main and a small migration first, or it will turn main red.

#818 merged a single egress rule for every clocked agent: src/agent_env/utils/agent_clock/agent_egress.py. With the clock armed, every TLS host goes through the egress proxy, the env's MCP servers included. Only loopback, host.docker.internal, the deploy's NO_PROXY hosts, and hosts reached only over plain HTTP go direct. NO_PROXY matches by host, so a host also reached over HTTPS stays behind the proxy.

tst/unit/agents/test_agent_clock_images.py on main now requires every clocked agent to:

  • take agent_clock = "utils/agent_clock" in its shared_sources.toml;
  • import clock_armed and egress_env from agent_egress, and define none of the rule itself;
  • have its Dockerfile, and install.sh if it has one, copy agent_clock/agent_egress.py and clock/clockpage.py beside the bridge.

This branch still has its own clock_armed / model_direct_hosts / egress_env. main doesn't require branches to be up to date before merging, so this PR's green checks predate #818, and merging it now would fail main's unit tier for this agent. OpenCode hit exactly this. In #818, commit ddb5993 moved it over, and it makes a short template: the bridge's change is the import plus egress_env(environ, [model_url, *mcp_urls], armed=...).

Why it matters beyond the test: on an armed clock, the CLI checks TLS certificates against the virtual date. An env on Modal whose *.modal.host certificate was issued after that date fails if its MCP host goes direct. We reproduced that on main before #818 (CERT_NOT_YET_VALID, no env tools). #818's PR description has the end-to-end results for Claude Code and OpenCode.

pi specifically: plain-HTTP MCP hosts go direct, but a host also reached over HTTPS would then bypass the proxy too. The shared rule handles that case.

If it helps, I can push the merge and migration commits to this branch and run the same armed-clock end-to-end check against a Modal env. Just say so here or on Slack.

williamloo-scale and others added 2 commits November 19, 2026 15:06
The bridge imports clock_armed and egress_env from agent_egress and hands
it the model endpoint's URL and every MCP server's, so on an armed clock a
host reached over HTTPS stays behind the proxy even when it's also reached
over plain HTTP. The image copies agent_egress.py and clockpage.py beside
the bridge; an install (install/v1), which unpacks the build context with
them in agent_clock/ and clock/, puts those folders on the server's path.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@williamloo-scale

Copy link
Copy Markdown
Contributor Author

Thanks, done. I merged main (v0.9.1595, with #818) and moved this agent onto agent_egress. Its shared_sources.toml takes agent_clock, the image (and install, where it has one) copies agent_egress.py and clockpage.py beside the bridge, and the bridge hands egress_env the model endpoint's URL and every MCP server's, so an HTTPS MCP host stays behind the proxy. The unit tests pass, including test_agent_clock_images.py and test_agent_egress.py. I rebuilt the image and ran the local armed-clock e2e and the A2A validator against a real model through LiteLLM: clock/v1 is supported, synced and follows writes, and both readings (2031-03-03T23:06:07-0600, then a day later) match. (head a4e9b4b) pi's install unpacks the whole build context instead of copying files, so start.sh puts agent_clock/ and clock/ on PYTHONPATH; a test imports both from the unpacked context.

@earakely-scale

Copy link
Copy Markdown
Collaborator

Claude again, working with Edgar. I checked the update, and the migration onto the shared rule looks right:

  • agent_clock in shared_sources.toml;
  • clock_armed and egress_env imported from agent_egress, with no copies of the rule;
  • the Dockerfile copies agent_egress.py and clockpage.py beside the bridge;
  • the model URL and every MCP server's URL are passed in;
  • CI is green.

start.sh putting agent_clock/ and clock/ on PYTHONPATH covers the install/v1 path. pi's MCP client is Node, so it's worth confirming end to end that it honours HTTPS_PROXY and NO_PROXY.

One thing hasn't been done yet: a run with an armed clock against an env on Modal, whose certificate starts after the virtual date. That's the case #818 was about. I'm happy to run it for pi before this merges, if you'd like.

williamloo-scale and others added 11 commits November 20, 2026 01:30
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the env's clock

pi compares its own clock with times it didn't make on the env's: before 1970 its compaction
throws (it makes a UUIDv7 from Date.now(), which refuses a negative time, and every compaction
and overflow recovery takes one), and its proper-lockfile locks compare its clock with their
modification times. pi 1.1.0 shows the model no date of its own, so the bridge starts it with
the real-time marker wherever the image runs the clock; libfaketime takes the marker out of pi's
environment, so the model's commands still read the env's time. On an armed clock pi and its
commands go out by the shared egress rule as before.

The call site is now under test: a run through the agent's A2A route records how pi was started,
armed and not, in a clocked image and as an installed agent; with the clock off its flags and
environment are the server's plus the run's own variables and the marker. cli_env's keyword is
armed, so it no longer shadows clock_armed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…m, and the image carries what the server imports

install.sh, which the image and install/v1 both run, pins Node's archive by nodejs.org's sha256
for each architecture. A contract test checks every file the Dockerfile copies is in the build
context, every module the server imports, its own and the shared ones, is copied beside it and
importable from an unpacked install, and install.sh installs the pi version the bridge names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…w pi follows the clock

A plain docker build of the folder lacks what shared_sources.toml takes, so the README builds it
with build_image, and install/v1 unpacks the build context rather than copying the folder. A new
section covers the opt-in clock: the commands follow it, pi stays on real time and why, what the
model sees of the date, the egress rule, and why the changelog needs no change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…arker reaches pi

pi's bin is a #!/usr/bin/env node script. Run as it is, env is the process started with the
marker: libfaketime keeps env on real time, takes the marker out of its environment, and env
starts node, and with it pi, on the env's clock. The bridge now runs node /opt/pi/bin/pi, the
same program with the same arguments the shebang gives it, where install.sh installs it for the
image and install/v1 alike.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e, not on a PYTHONPATH

start.sh exported PYTHONPATH for the folders the build context keeps the egress rule and the
clock page's format in, and the server passes its environment to pi, so every command the model
ran in an installed agent saw it, which main's didn't. install.sh copies the two modules beside
the bridge when it runs from an unpacked build context, as the image's build does, and start.sh is
main's again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…arts it, stays on real time while its commands follow

- The integration test's pi row starts node with the real-time marker, as the bridge starts pi, and checks that node
  prints real time, that the date it runs prints the env's time, and that its process.env has no marker. The module
  docstring no longer says every agent's CLI follows the clock.
- A unit test pins the variables root.conf gives the server, which reach pi and the model's commands with the clock
  off too.
- Both READMEs say pi starts as `node /opt/pi/bin/pi`. The agents README says pi's image can follow the clock with pi
  itself on real time. pi's README says its /proc environ shows the marker rewritten in place as =0, and that the
  changelog writes its tar in the real-time server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Root's supervisord restarted a crashed server in place. The restarted server had lost what the run gave it (the env's
MCP servers, its config, its peers, its running turns), the pi that was mid-turn ran on in a session of its own, and
prompt_agent polled "Task not found" until its timeout. root.conf no longer restarts the server (autorestart=false,
startretries=0), and an event listener stops supervisord once the server has exited or failed to start, so the
container exits and the run fails as fast as on main. The follower and the egress proxy keep their restarts, and a
normal stop is unchanged. supervisord exits 0 after any shutdown, so the container's status is 0, not the server's.

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

Copy link
Copy Markdown
Collaborator

Hi @williamloo-scale, Claude here, working with Edgar. I finished this PR on your branch. Edgar asked me to bring all five clock PRs to the same bar as Claude Code's (#818, #831, #832).

What changed

  • pi now runs on real time on an armed clock, and only the model's commands follow it. On the env's clock, a universe before 1970 broke pi's compaction for good: uuidv7 throws.
  • The bridge starts node directly, so the real-time marker isn't lost to env.
  • New tests: a call-site test and the README fix.

Tested on a dedicated VM, with a stand-in model and real models, side by side with main:

  • clock off matches main;
  • opted in (agent_clock), the model sees the env's time;
  • the fix(claude-code): reach env MCP servers through the egress proxy on an armed clock #818 case: HTTPS MCP on a Modal env armed before its certificate, and with a clock behind real time;
  • four-turn history at +75 days, 1950 and 2262;
  • late agents, the require policy, and the agent on Modal;
  • chaos: clock rate and jumps, re-arm, clear, a killed clock follower, env reset, endpoint outages, cancel mid-turn, a killed server, concurrent runs.

Greptile is 5/5 on the head and CI is green.

Also new here: if the A2A server dies, the container now exits, as on main, instead of supervisord restarting the server in place. Edgar decided this after testing showed in-place restarts leave the old CLI writing and the new server without the env's MCP tools. #862 makes the same change for Claude Code and OpenCode.

Merging: the five clock PRs (#765 #768 #769 #770 #771) each add a row to tst/integration/task_step/test_agent_env_clock_local.py, so after the first one lands the others need a main merge that keeps both rows. I can do those merges.

The full details are in the PR description.

Claude, working with Edgar

@earakely-scale

earakely-scale commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Closing this, per Edgar's decision. Claude here, working with Edgar.

Why: on libfaketime, a universe before 1970 breaks pi's compaction for good, because uuidv7() throws when the clock is before 1970. The version on this branch kept pi on real time and only put the model's commands on the clock, so advertising clock/v1 would overstate what the agent does.

Edgar's rule: an agent advertises the clock (clock/v1 sync_time) only if the agent itself faithfully follows libfaketime, as Claude Code, OpenCode and Letta Code (#769) do.

What this agent does instead: it stays as it is on main. It runs on real time, and the env's time is available from the gateway's get_time tool, which has been the default for agents since #832.

  • A task with require_agent_clock fails up front for this agent ("can't follow the clock: not advertised").
  • Plain agent_clock skips it.
  • Its image stays identical to main, so none of the clock image's side effects apply: running as non-root on Modal, slower start and teardown, and the egress-proxy boot.

What's kept: the branch stays for reference. The investigation is in this PR's description and comments, and in Linear FD-6434.

Thanks for all the work on this, William. It's what showed where libfaketime does and doesn't hold up.

Claude, working with Edgar

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.

2 participants