Skip to content

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

Closed
williamloo-scale wants to merge 65 commits into
mainfrom
wloo/codex-clock-image
Closed

williamloo-scale wants to merge 65 commits into
mainfrom
wloo/codex-clock-image

Conversation

@williamloo-scale

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

Copy link
Copy Markdown
Contributor

What and why

The Codex image can follow a task env's clock when the task opts in with sync_env_clock's agent_clock (or
require_agent_clock). Claude Code has had the same opt-in since #832. Without it, Codex runs on real time as before.

Codex can't follow the clock the way Claude Code does. On Linux the Codex CLI is a static musl binary, and so are
codex-code-mode-host and bwrap, so the preloaded libfaketime never reaches them. So this PR leaves the CLI, and the
state it keeps, on real time: rollouts, state.db, thread ids and its own certificate checks. Only the model's commands
follow the clock, and the model is told the env's date.

How it works

The image is the same kind as Claude Code's and OpenCode's:

  • shared_sources.toml takes utils/faketime_clock, utils/egress_proxy and utils/agent_clock from agent-env's
    one copy of each.
  • start-agent and root.conf run root's supervisord. The clock follower and the egress proxy each run as their own
    user, on real time. The A2A server runs as agent with the real-time marker, which libfaketime takes out of its
    environment, so what it starts is faked.
  • libfaketime and its TLS shim are preloaded for the agent user alone.
  • start-agent merges a provider's CA bundle (Sail's, say) into agent-env's trust files and into the proxy's roots.
  • The server's exit ends the container, as on main, where the server was the container's only process. root.conf
    never starts it again (autorestart=false, startretries=0). An agent-exit event listener, a few lines of Python
    inline in root.conf that speak supervisord's eventlistener protocol, hears PROCESS_STATE_EXITED and
    PROCESS_STATE_FATAL. When the process is agent, it sends its parent, supervisord, a SIGTERM. supervisord then
    stops the follower and the proxy and exits, and the container with it. The follower and the proxy keep restarting
    in place. A server started again would have lost the task's MCP servers, config, peers and running tasks, and the
    dead server's CLI would have gone on in the workspace beside it.

A CLI run applies the clock only when clock_followed() holds: the clock page is armed (the shared clock_armed(),
read once per CLI run) and the server has AGENTENV_EGRESS_PROXY in its environment. Only root.conf sets that
variable, and root.conf starts the server as the user libfaketime fakes. An agent installed with install/v1 runs as
root, and libfaketime doesn't fake root's commands. So such an agent never applies the clock, even inside a computer
whose clock page is armed. Without this check it would tell the model that the real date was the task's.

On such a run, each codex exec also gets:

  • Each MCP server's mcp-remote, started by Node itself on real time. These overrides change how the server starts:

    • -c mcp_servers.<name>.command="<node>";
    • -c mcp_servers.<name>.args=["<.../mcp-remote/dist/proxy.js>", <config.toml's args>];
    • -c mcp_servers.<name>.env.AGENTENV_REAL_TIME="1".

    mcp-remote compares its clock with server times and real file times: cookie Expires, lease ages, a stale-file
    sweep by mtime, OAuth token expiry. On real time it also checks certificates against the real date, so it reaches
    the servers directly. That includes an HTTPS server on Modal whose certificate starts after the virtual date, and a
    clock behind real time (proven in the image by E3 below). The marker has to reach Node itself. mcp-remote's bin is
    dist/proxy.js, which starts with #!/usr/bin/env node. Started that way, the first process is env, which is
    dynamically linked. libfaketime keeps env on real time, takes the marker out of its environment, and env then
    execs Node without it. config.toml still names mcp-remote, so an unarmed run starts it as before.

  • The egress proxy for the model's commands. -c shell_environment_policy.set.<VAR>=... sets the proxy variables
    from the shared egress_env. The model's commands check certificates against the env's date, so they go out through
    the proxy. The exceptions are loopback, NO_PROXY's hosts, and the model endpoint's and MCP servers' hosts when
    they are served over plain HTTP only.

  • The env's date before the prompt, as an <environment_clock> note: "Today is 2027-02-03 (Wednesday) in
    America/Chicago on this task's clock…". The date is what date prints when the real-time server starts it.

The CLI's own environment has no proxy variables. It checks the model endpoint's certificate on real time and reaches
the endpoint directly.

What the model sees on an armed clock

  • The env's time: date, Python, Node and everything else it runs (bash, git, rg on arm64, the bundled zsh);
    what its commands write into files; the gateway's get_time; and the note at the top of every turn. File mtimes
    stay real, because stat isn't faked.

  • The host's real time:

    • current_date in Codex's own <environment_context>, which the CLI renders. Codex has no setting for it.
      include_environment_context = false would also drop cwd, shell and permissions. developer_instructions sit in
      a thread's first context only, so they can't follow a clock that moves between turns. clock_source = "external"
      fails codex exec at session start.
    • for the GPT-5.6 and GPT-6 catalog models, which run code mode: Date in the JavaScript the model runs in Codex's
      V8 host (codex-code-mode-host, static);
    • for GPT-6 models: the clock tool.

    The note tells the model all of this and says to go by the env's clock. Whether models follow it is what E1 and E2
    below measure.

Clock off

With no agent_clock, the bridge builds the same command, CLI environment and prompt as on main, and a unit test
pins this. config.toml is unchanged. What still differs at the image level:

  • Who runs it. The container starts as root, and supervisord starts the A2A server as agent (uid 10001). On local
    Docker the old image already ran as agent. Providers that ignore USER and ran the old image as root (Modal) now
    run the server, the CLI and the model's commands as uid 10001. Those commands can't apt-get install or write
    root-owned paths, including files a root step stages into /app. /app itself and /home/agent/.codex are
    agent's.
  • The server's environment, which the CLI and the model's commands inherit:
    • supervisord adds SUPERVISOR_ENABLED, SUPERVISOR_PROCESS_NAME, SUPERVISOR_GROUP_NAME and
      SUPERVISOR_SERVER_URL. The URL names root's socket, which is mode 0700, so agent can't use it.
    • root.conf sets HOME=/home/agent, USER=agent and LOGNAME=agent.
    • AGENTENV_EGRESS_PROXY is set. It isn't a proxy variable, so nothing reads it on an unarmed run.
    • SSL_CERT_FILE, REQUESTS_CA_BUNDLE and NODE_EXTRA_CA_CERTS point at agent-env's bundles: the system roots,
      the image's CA and any provider bundle.
  • The boot. The egress proxy's boot runs on every start. It mints the image's CA and adds it to the system store,
    agent-env's trust files and every certifi bundle; the CA key is readable by the egress user alone. If the boot
    fails, the container stops (start-agent exits 2).
  • The server's exit. It ends the container, as on main, 2 to 3 s later: supervisord stops the follower and the
    proxy first. The exit status is 0. supervisord 4.2.5 exits 0 after a signalled shutdown and has no setting to change
    that. main's container exited with the server's status, 137 when it was killed. Nothing in agent-env reads an agent
    container's exit status.
  • Processes. The clock follower and the egress proxy run beside the server.
  • The preload. libfaketime and the TLS shim are loaded into every dynamically linked process. Only agent's
    processes are faked, and on an unarmed page they read real time.
  • Started as another user, the image runs entrypoint.sh alone, as before.
  • install/v1 copies two more files into an install: agent_egress.py and clockpage.py.

Limits

  • R2 is met with a note, not by the CLI. See the list above. On armed turns the note is part of the user message,
    so trajectories and judges see it.
  • The armed state is read when each CLI run starts. A turn that started unarmed keeps mcp-remote faked, with no
    proxy and no note, until the next turn. Claude Code and OpenCode have the same edge.
  • Some of what the CLI starts follows the clock. The CLI's npm launcher (codex.js, #!/usr/bin/env node) is
    dynamically linked. So are the programs the CLI starts itself: rg on arm64 (static on x86_64), the bundled zsh,
    git, bash. The launcher only starts the binary and passes on its arguments, environment and signals. 0.162.1
    still has a [ghost_snapshot] config and skips "legacy" ghost_snapshot rollout lines. Whether codex exec still
    makes ghost commits, and whether anything prunes them on the env's clock, is checked in the VM run (git compares
    real object mtimes with a virtual now). On the VM, with git installed by hand at 2262 and 1950, 0.162.1's
    codex exec wrote no ghost_snapshot items into its rollouts (4 turns each); the image has no git.
  • The mcp-remote start is resolved from PATH on each armed run: node, and the file mcp-remote resolves to.
    In the image these are /usr/local/bin/node and /opt/agent/node_modules/mcp-remote/dist/proxy.js.
  • MCP headers on the command line. On armed runs each server's arguments, including its --header values, are on
    the codex command line. Any process can read that with ps, including the model's commands. The same values are
    already in mcp-remote's own command line and in config.toml, which agent can read, on main too.
  • Clocks before 1970. The proxy's leaves for model commands start at the CA's 1950 start plus an inset, as the
    shared proxy has them. A virtual date on 1950-01-01 itself could still fall before a leaf starts; the tests use
    1950-06-15.
  • Claude Code's and OpenCode's images on main still start a crashed server again in place. This PR changes
    Codex's alone.
  • A clock cleared mid-conversation. After clear, a turn has no note (the page is unarmed), so the model sees
    the real date in date and <environment_context>, but earlier turns' notes, still in the thread, gave it the
    virtual date. On the VM a model then answered date with the real date and "today" with the last note's date.
  • <timezone> in <environment_context> reads the image's /etc/localtime (Etc/UTC), while its
    current_date follows TZ: on an armed turn in America/Chicago the CLI said current_date 2026-11-20 and
    timezone Etc/UTC at 00:05 UTC on 2026-11-21.
  • Dates past 2262-04-11 can't be armed: the shared clock page holds nanoseconds in an int64 (clockpage.py set
    for +1000 years fails with struct.error), for every clocked image.
  • R7. Codex has no workspace changelog. Its snapshot archive is built by Python's tarfile in the real-time
    server, so header times are real.

Changes

  • codex_bridge.py: clock_followed() (the armed check), clock_overrides, and clock_note, applied in
    _run_codex_once on such a run. run_codex takes the task's MCP registrations (name to URL and headers).
  • codex_config.py: server_args, mcp-remote's arguments, which config.toml's entry and the armed overrides share.
  • a2a_server.py passes the task's MCP registrations.
  • Image files: Dockerfile, root.conf (with the agent-exit listener), start-agent and
    shared_sources.toml. install.sh carries agent_egress.py and clockpage.py. Codex's README describes the
    clock and the server's exit.
  • No shared code changes (git diff origin/main -- src/agent_env/utils src/agent_env/computers packages src/agent_env/agents/agents/{claude-code,opencode} is empty). An earlier revision of this PR floored the shared
    proxy's leaves at 1970, because rustls refuses earlier certificates. That was needed only while the real-time CLI
    went through the proxy. The CLI now goes direct, so the change is reverted.

Tests

  • tst/unit/agents/codex/test_env_clock.py:

    • the proxy rule for the model's commands;
    • each MCP server on an armed run, with node and mcp-remote laid out on PATH as in the image (a link through
      npm's .bin to a #!/usr/bin/env node script). The command the CLI is given must not be a #! script. Its
      arguments must be mcp-remote's script followed by config.toml's arguments, and its environment must hold the
      marker.
    • unarmed, no overrides;
    • an armed page without the image's egress proxy, which leaves the run as on main;
    • the CLI spawn armed: the overrides, the CLI's unchanged environment, and the note from a faked date;
    • the CLI spawn unarmed, equal to main's;
    • a turn through the A2A server with MCP servers registered, headers included;
    • the provider CA merge.

    Each of these mutations fails a test: starting mcp-remote by name again, dropping the command override, dropping the
    script from the arguments, dropping the marker, dropping either half of the armed check, dropping the note, and the
    server passing URLs without headers.

  • tst/unit/agents/codex/test_server_exit.py reads root.conf as supervisord reads it. It checks that the server is
    never started again, that the follower and the proxy restart, and that the listener hears EXITED and FATAL and
    runs as root. It also runs the listener exactly as root.conf writes it, under a stand-in supervisord that speaks
    its protocol. The listener must signal its parent on the server's exit and on its failed start, and not on the
    follower's, the proxy's or its own. Each of 5 mutations fails a test: the filter inverted, the wrong program name,
    FATAL dropped, autorestart turned back on, and signalling itself instead of its parent.

  • tst/unit/agents/test_agent_clock_images.py covers codex: shared pieces, users, preload, the shared egress rule.

  • tst/util/fake_responses.py is a fake Responses API. The local agent clock e2e now runs a real Codex turn. It
    checks that the note and a shell date show the virtual date and that <current_date> doesn't. It also checks, in
    the image, that the env MCP server's mcp-remote Node process has AGENTENV_REAL_TIME=0 in its environment block:
    libfaketime rewrites the marker to that value in a process that received it, so this shows Node itself got the
    marker.

Testing

  • Unit: the codex, agents, a2a_agent, utils and shipped-bundle tests pass, and ruff is clean. After the merge with
    main at 0.9.1611: all of tst/unit/agents passes (1146 passed).

  • Against the real Codex 0.162.1 CLI (darwin-arm64 build) through the bridge, with a stand-in Responses API, before
    the change to how mcp-remote starts:

    • armed, the model's command saw the proxy variables and the CLI's environment had none;
    • the note reached the model;
    • unarmed, nothing was added;
    • a resumed turn kept its history.

    macOS has no libfaketime, so this run says nothing about how mcp-remote runs.

  • On an x86_64 VM (Ubuntu 24.04, Docker), the image built from this branch, models through LiteLLM:

    • unit tests on Linux (the codex, clocked-image and egress tests, and all of tst/unit/agents, 1151 passed, no
      skips) and the local e2e (test_agent_env_clock_local.py -k codex): note and date on 2031-03-04,
      <current_date> the host's, mcp-remote on real time: [True, True] (the env's server and the agent's own
      peer_agents server), the advance waited for, 504 naming the agent while paused, teardown drops the follower.
    • the FD-6434 repro with a stand-in model: 4 turns of about 36 s each at real, now, +75 days, 2262-01-01 and
      1950-06-15, then with a 30-day jump, a clear and re-arm, a jump back to 1950 during a turn and rate 60x: every
      turn completed, the last request held every earlier turn, each note gave the date date showed, Node, Python and
      curl reached https://example.com at every date (200), no lock, lease or cleanup error. +1000 years can't be
      armed (see Limits).
    • git under the clock: no ghost_snapshot items at 2262 or 1950.
    • clock off, main (0.9.1609 from PyPI, its published image) and this branch on the same prompts: the same
      answers (real date, the env's MCP tool, get_time absent with no clock and the env's time with an unopted env
      clock, both turns remembered), no note, no overrides, no proxy variables in the CLI's environment.
    • opted in at 2027-02-01 (gpt-5.4-mini): BELIEVED, date, Python, notes.txt and get_time on 2027-02-01, the
      note on every turn, <current_date> the host's, ECHO=ping, curl and Node 200 through the proxy; main's image
      with require_agent_clock fails at deploy_agent: "agent 'solver' can't follow the clock of env ...:
      not_advertised".
    • the env on Modal, its MCP at *.w.modal.host with a certificate starting 2026-11-18 to 2026-11-20: armed
      at 2026-10-27, 2025-06-01 and 1950-06-15, ECHO=ping on each; each mcp-remote ran as
      /usr/local/bin/node /opt/agent/node_modules/mcp-remote/dist/proxy.js with the marker in its environment block
      and no proxy variables.
    • 4 turns at +75 days kept every word; an agent deployed after them followed the clock (both followers in the
      gateway's state).
    • the agent on Modal too (prod's path), armed at 2027-02-01: as local.
    • code mode (gpt-6-astra): the clock tool and JavaScript's Date said 2026-11-21 (real), the model believed
      and answered 2027-02-01, as the note says.
    • chaos: rate 3600 (date; sleep 10; date 10 h apart) then frozen (equal); a 30-day advance, a re-arm back to
      2026-12-01 and a clear between turns (each turn's date right, every word kept); reset_env (the clock and the
      MCP tool survive); the follower killed -9 mid-turn (restarted, the next advance acknowledged in 0.02 s); the
      model endpoint blocked 45 s mid-turn (the turn completed; same on main with the clock off); 4 concurrent
      opted-in runs (all passed); the run SIGTERMed mid-turn (cancelled in 7 s, nothing left); the A2A server killed -9
      mid-turn, then restarted in place (its CLI went on writing for 20 s; the step waited out its 300 s timeout on
      Task not found, and the next turn ran on the restarted server). That is why the server's exit now ends the
      container (below).
    • no Modal sandbox, container, network or iptables rule left.
    • spend: about $1.2 of models (estimated from token counts).
    • not run: the A2A validator and the install/v1 smoke.
  • On the same VM, after the server's exit was made to end the container (merged with main at 0.9.1611). These runs
    used a stand-in Responses API and local Docker, because the VM no longer holds a model key:

    • unit tests on Linux (codex, clocked images and egress: 321 passed). The local e2e (-k codex) passed: the
      note and date on 2031-03-04, mcp-remote on real time: [True, True], and teardown terminated the sandbox with no
      failure.
    • the A2A server killed -9 10 s into a turn. The container stopped 3.4 s after the kill with the clock on, and
      2.4 s after with it off. It exited with status 0, and the image's supervisord log shows exited: agent (terminated by SIGKILL), received SIGTERM, then the proxy, the follower and the listener stopped. The model's beat loop
      wrote 2 or 3 more lines before the container stopped and none after. prompt_agent failed the step 59.8 s after the
      kill, both times, with AgentUnreachableError ("5 polls in a row over 60s got no reply"). For comparison, main's
      image (0.9.1609 from PyPI), killed the same way on the same VM, failed it after 60.0 s with the same error. The
      60 s is prompt_agent's own unreachable rule, so it isn't something the image can shorten.
    • clock off, and opted in with agent_clock at 2027-02-01: two turns each passed, with date on the real date
      and on 2027-02-01.
    • the clock follower, then the egress proxy, killed -9 mid-turn: each restarted within a second, the container
      stayed up, and both turns passed on 2027-02-01.
    • docker stop after a turn took 3.3 s and exited 0. supervisord stopped the server (STOPPED, not EXITED, so
      the listener stays out of it), then the proxy, the follower and the listener.

Claude, working with Edgar, finished this PR: the clock design, the VM runs, and the change that has the server's exit
end the container.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new actionable issue was found.

Summary

Adds opt-in clock support to the Codex image while keeping the CLI and MCP connections on real time.

  • Codex model commands can follow an opted-in task clock.
  • A Codex server exit now shuts down its supervised container.

The earlier findings are addressed: provider certificates are merged before startup, the shared certificate-window change is absent, and the bridge reuses the shared clock helpers.

williamloo-scale explicitly documents the change to running as agent on Modal and the container’s zero exit status after shutdown as accepted limits. No new actionable issue was found. This review inspected code; it did not run tests.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Start["start-agent"] --> Supervisor["Root supervisord"]
  Supervisor --> Follower["Clock follower"]
  Supervisor --> Proxy["Egress proxy"]
  Supervisor --> Server["A2A server: real time"]
  Server --> CLI["Codex CLI: real time"]
  CLI --> MCP["Node / mcp-remote: real time"]
  CLI --> Commands["Model commands: task clock"]
  Commands --> Proxy
  Server --> Note["Task date added to armed prompts"]
  ServerExit["Server exits or fails to start"] --> Listener["agent-exit"]
  Listener --> Shutdown["Supervisord stops the container"]
Loading

Reviews (15) · Last reviewed commit: "fix(codex): the A2A server's exit ends t..." · 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>
@earakely-scale

Copy link
Copy Markdown
Collaborator

🤖 Automated Claude routine — Env Pod PR Context Review. This is a bot, not Edgar Arakelyan; not a human review.

Context from a sibling PR rather than from this diff.

#818 (open, ready) moves the clock-egress rule out of the per-agent bridges into one src/agent_env/utils/agent_clock/agent_egress.py, taken through a new agent_clock = "utils/agent_clock" key in shared_sources.toml (it adds that key to claude-code and opencode), and adds two checks to tst/unit/agents/test_agent_clock_images.py:

  • test_the_egress_rule_is_taken_from_the_one_copy_only_agent_images_take asserts taken["agent_clock"] == "utils/agent_clock" and that the agent folder holds no copy of it;
  • the _clock_helpers check is replaced by one requiring the bridge to take clock_armed / egress_env from that shared module and define none of them itself.

CLOCKED is derived from any agents/*/shared_sources.toml carrying a clock key, so codex enrols automatically here: the new src/agent_env/agents/agents/codex/shared_sources.toml sets clock and egress but no agent_clock, and codex_bridge.py defines clock_armed, model_direct_hosts and egress_env along with its own copy of the clock-page struct, magic, version and check salt. Both of #818's checks fail for codex if it lands first. The same holds for #768, #769, #770 and #771, so the five are worth sequencing against #818 rather than each resolving it separately.

One behavioural note on the same seam: #818 was opened for an env whose *.w.modal.host certificate was issued after the task's virtual date, where the CLI listed the env MCP as failed with 0 env tools. This PR's description keeps MCP traffic direct either way; #768 and #769 instead send only plain-HTTP MCP hosts direct, which is the rule #818 settles on.


Generated by Claude Code

# 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.

Codex specifically: only the model endpoint goes direct here, so MCP is already proxied. This one is just the migration.

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 3 commits November 19, 2026 15:06
The bridge imports clock_armed and egress_env from agent_clock's
agent_egress, which the image and an install copy beside it with
clockpage, and hands it the model endpoint's URL; its own copy of the
rule goes. mcp-remote, which codex hands only the trust variables, is
still not given the proxy.

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

Codex hands mcp-remote only the variables its env_vars names, so on an
armed clock it went to an HTTPS MCP server directly and checked the
server's certificate against the env's date. It now gets the proxy's
variables too, and the bridge hands the egress rule every MCP server's
URL, so only plain-HTTP ones go direct, as #818 has for Claude Code and
OpenCode.

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

Copy link
Copy Markdown
Contributor Author

Thanks, done, with one correction: codex's MCP wasn't already proxied. Codex hands a stdio server only what env_vars names, and that was the trust variables, so on an armed clock mcp-remote went direct to an HTTPS MCP host and checked its certificate against the env's date. 764a13c adds the proxy's variables to env_vars and passes every MCP server's URL to egress_env, so only plain-HTTP servers go direct. d864a99 is the agent_egress migration, and 96ad61c fixes the proxy for rustls: leaves started in 1950, and webpki refuses any certificate dated before 1970, so codex rejected every leaf (bad certificate). Leaves now start at the Unix epoch; the CA keeps its window. Rebuilt image: the local armed-clock e2e and the A2A validator against a real model pass, and clock/v1 is supported, synced and follows writes, with both readings matching.

@greptileai review

@earakely-scale

Copy link
Copy Markdown
Collaborator

Claude again, working with Edgar. Thanks for the update. The migration onto agent_egress looks right:

  • shared_sources.toml, the import and no copies of the rule;
  • the Dockerfile, and install.sh's AGENT_FILES;
  • egress_env given the model URL and the MCP URLs.

I agree with Greptile's open P1 on utils/egress_proxy/leaves.go, and there's a second effect.

  1. Every image's proxy changes, not just Codex's. Moving the leaf's notBefore from 1950 to 1970 changes the proxy in every image. A computer or Claude Code or OpenCode agent on a clock before 1970 would get a certificate that isn't valid yet for live HTTPS sites.
  2. It rebuilds every computer. ubuntu-24.04 and ubuntu-24.04-browser take utils/egress_proxy as egress/ in their build contexts. Any change in that folder changes their src- tags, so every composed computer recomposes after the next release. fix(claude-code): reach env MCP servers through the egress proxy on an armed clock #818 kept its new module out of those folders for exactly this reason.

It would help to say in the PR why Codex needs 1970. My guess is that its TLS stack rejects a notBefore before the Unix epoch.

Two codex-scoped options:

  • Keep 1950 by default and let an image opt into a later floor, the way it opts into private addresses with AGENTENV_EGRESS_PRIVATE. That still edits the Go code once, so the bases rebuild once, but nobody else's behaviour changes.
  • Mint each leaf's window around the universe's date instead of a fixed start. That works for any client at any date.

I can run the armed-clock check against a Modal env for Codex once this settles, if that helps.

williamloo-scale and others added 11 commits November 20, 2026 01:30
The shared proxy's leaves had been floored at the Unix epoch because rustls refuses an earlier certificate, but only
the Codex CLI checks with rustls, and it now runs on real time and reaches the model endpoint directly. The floor
broke HTTPS for every computer and agent following a clock before 1970, and rebuilt both computer bases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…low the clock and its proxy

The Codex CLI is a static musl binary, so the preloaded libfaketime never reaches it: it, its state and its own
certificate checks run on real time, and it reaches the model endpoint directly. On an armed clock each CLI run now:

- keeps proxy variables out of the CLI's own environment and gives them to the model's commands alone, through
  `-c shell_environment_policy.set.*`, built from the shared `egress_env`;
- starts each MCP server's mcp-remote with AGENTENV_REAL_TIME=1 (`-c mcp_servers.<name>.env.*`), so its certificate
  checks, cookie and token expiry and leases stay on real time and it reaches the servers directly; config.toml's
  entries go back to main's;
- puts the env's date and zone before the prompt, as `date` shows it, since Codex renders the host's real date into
  its <environment_context>, and says that a clock tool and Date in code mode's JavaScript read real time too.

Unarmed, a run's command, environment and prompt are main's, which a test pins. Tests at the spawn and through the
A2A server fail when the wiring is removed. The image's comments say what follows the clock and lose a ticket id.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a fake Responses API

The codex row now runs one turn of the real CLI in the image: the date line the agent puts before the prompt and a
shell `date` the model runs show the env's time, and the CLI's own <environment_context> date is the host's.
tst/util/fake_responses.py answers the CLI with the shell tool its request offers, then quotes the output.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the image's server applies the clock

The real-time marker given to an MCP server's environment never reached mcp-remote: its bin is a
`#!/usr/bin/env node` script, so env, the first program libfaketime loads into, stayed on real time and
took the marker out of what it handed Node, which then checked certificates and compared expiries on the
env's clock. On an armed run each server is now started as Node with mcp-remote's script and
config.toml's arguments (`codex_config.server_args`), the marker in its environment. Unarmed runs and
config.toml are unchanged.

The clock applies only where root.conf starts the server, as the user libfaketime fakes, with the egress
proxy in its environment (`clock_followed`): an install/v1 agent runs as root, whose commands stay on real
time, so a computer's armed page no longer gets its real date labelled as the task's.

The local agent clock e2e checks in the image that the env MCP server's Node process got the marker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e, the peer agents' server's too

The CLI is given two MCP servers on Linux, the env's and the agent's own peer_agents
server, so a turn starts two mcp-remote processes; the e2e expected one and failed on
the VM with both marked.

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

In the image supervisord restarts a crashed A2A server in place, and the CLIs it was
running, each leading a session of its own, outlived it: on the VM a server killed -9
mid-turn left its CLI running for another 20 s, writing to the workspace and its
thread's rollout beside the restarted server. The server now kills every codex exec
of its user that leads its own session, process group and all, as it starts; only
where root.conf starts it (AGENTENV_EGRESS_PROXY), since elsewhere a crash ends the
agent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On main the server was the container's only process, so its death ended the container and the run failed within
prompt_agent's unreachable window. Under root's supervisord a crashed server was started again in place: the dead
server's CLI went on writing in its own session, the new server had lost the task's MCP servers, config, peers and
running tasks, and prompt_agent polled "Task not found" until its timeout. root.conf now never starts the server
again (autorestart=false, startretries=0) and an agent-exit event listener has supervisord shut down when the server
exits or can't start; the clock follower and the egress proxy keep restarting in place. supervisord 4.2.5 exits 0
after a signalled shutdown, so the container's exit status is 0.

The startup sweep of the CLIs a crashed server left running is gone with the case it handled.

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

  • The CLI stays on real time. The Codex CLI is a static binary, so libfaketime never reached it anyway.
  • Shared proxy untouched. I reverted the change to utils/egress_proxy (the 1970 leaf floor), so no other image is rebuilt.
  • Proxy variables go only to the model's commands. Each MCP server's mcp-remote is started by node directly, on real time (its launcher was losing the marker).
  • The env's date reaches the model. On armed turns, the prompt starts with a short note giving the env's date. Codex's own <current_date> stays real, and the description says so.

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: Codex can't follow libfaketime faithfully. Every Linux build OpenAI publishes is a static musl binary (0.162.1 ships only *-unknown-linux-musl), and libfaketime loads through the dynamic loader, which a static binary never uses. The version on this branch kept the CLI on real time and only put the model's commands on the clock, so advertising clock/v1 would overstate what the agent does. Codex's own <current_date> still shows the real date.

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