Skip to content

feat(agents): Codex follows the env's clock, its CLI on real time and the model told the env's date - #926

Merged
earakely-scale merged 8 commits into
mainfrom
edgararakelyan/fd-6995-codex-clock-sync
Nov 26, 2026
Merged

earakely-scale merged 8 commits into
mainfrom
edgararakelyan/fd-6995-codex-clock-sync

Conversation

@earakely-scale

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

Copy link
Copy Markdown
Collaborator

Why

Codex didn't follow a task env's clock. Its card served no clock/v1 sync_time, so sync_env_clock with agent_clock recorded it as not_advertised and moved on. The commands the model ran read real time.

Worse, Codex tells the model the date itself. Every request's <environment_context> carries <current_date>, from the CLI's own clock (local_time_context() in codex-rs core/src/session/turn_context.rs). So a Codex run on a 2031 story told the model it was the machine's date.

The CLI can't simply be put on the clock the way Claude Code is. @openai/codex's Linux builds (x64 and arm64) are static musl binaries, which /etc/ld.so.preload and libfaketime never reach.

What

The image follows the clock like the other clocked agents.

  • It takes the clock follower, agent-env's libfaketime and the egress proxy from utils/faketime_clock and utils/egress_proxy (shared_sources.toml), with start-agent and root.conf as Claude Code's image has them.
  • It starts as root; supervisord runs the A2A server as agent with the real-time marker.
  • Its card advertises clock/v1 sync_time through the protocol's framework, so sync_env_clock with agent_clock (or require_agent_clock) has it follow.

The CLI stays on real time; the commands it runs don't. Codex, a static binary, keeps real time whatever the clock, so its threads, rollouts and resumes are unaffected by a clock set behind them. The commands the model runs (bash, date, python, node) and the MCP clients the CLI starts read the env's time.

Each CLI run calls the endpoint through a model relay of its own (model_relay.py, shared with OpenCode and Letta Code), given to the CLI as a -c override of the provider's base_url. While the clock is armed, the relay's rewrite (codex_date.py) puts the env's date, read from date, into every message of each call:

  • each <environment_context>'s <current_date>, a resumed thread's earlier ones included;
  • the time of the <current_time_reminder> Codex gives a turn at persistent effort.

The relay takes a text as the CLI's only when the whole text is one such fragment between its markers, as Codex writes them, so a task prompt that quotes one is sent as written. A call whose date can't be read, or whose fragment writes a date or time in a form the relay doesn't know, is refused. The turn then fails rather than tell the model the machine's date. Off the clock, calls go through untouched.

MCP through the egress proxy. On an armed clock, the CLI's commands and MCP clients get the egress proxy (agent_egress.egress_env, with the env's MCP URLs). Codex hands a stdio MCP server only the variables its entry names, so mcp-remote's entry now names the proxy variables too. It also gets --enable-proxy, since mcp-remote's bundled HTTP client ignores proxy variables without it; with none set, it connects directly as before.

install/v1 copies the relay and the clock modules beside the bridge. An installed agent has no follower, so it calls through the relay with nothing to rewrite.

The protocol floor moves to 0.1.643 (ModelUsage.of, which the relay uses), and aiohttp joins the requirements.

Not changed

  • File modification times stay real on every agent, Claude Code's included, so ls -l in a solver's sandbox still shows the machine's date.
  • <timezone> stays the container's.
  • For a model in Codex's catalog, such as gpt-6-astra, Codex runs in code mode: the model's tool calls are JavaScript run by exec in codex-code-mode-host, another static binary. The tools it calls follow the clock, but JavaScript's own Date in that code reads real time. This follows from the binary being static; no run here was seen using it, since the trajectory doesn't record the JavaScript.

Tests

Unit:

  • codex_date: the env's date and time in every environment context and reminder, the first and a resumed thread's; before 1970, in 2200, in the CLI's zone; text outside an environment context and tool output left alone; off the clock or with nothing to rewrite, the call goes byte for byte; a non-JSON call, an unknown date or time form, a date that fails, hangs or leaves a child are refused.
  • The bridge: each CLI run's relay, the provider override and the relay closed however the run ends; no relay without an endpoint; the egress variables on an armed clock only, with plain-HTTP MCP hosts direct; mcp-remote handed the proxy variables and --enable-proxy.
  • The image and install contract, now with the shared sources; test_agent_clock_images.py covers Codex like the other clocked agents.

Integration:

  • codex_env_date_test.py runs the CLI package-lock.json pins against a fake Responses endpoint, a new thread and a resumed one, with the clock armed: every <current_date> the CLI sent carries the env's date, and no part of any request carries the machine's. With the rewrite off, the same test fails on 2026-11-25. Bumping the CLI runs it against the new version.
  • test_agent_env_clock_local.py gains Codex: deployed with an env on local Docker, it follows the env's clock until it is torn down, its turn told the env's date and its shell's date the env's. Passes on x86_64 and arm64.

E2E on dedicated VMs, a stand-in model, A/B against main. Each run: the mail env and Codex on local Docker, the clock armed with agent_clock, turns that call the gateway's get_time, the env's search_emails and a shell probe (date, python, node, HTTPS from python and node), a late agent, in-container probes.

  • Dates 1950, 1969 (crossing into 1970 mid-run), a past date, 2031 frozen, 2200, the last hour before 2262, and a day per second. Every call the model got carried the env's date, the shell, python and node read it, and live HTTPS went through the egress proxy (node direct got CERT_HAS_EXPIRED/CERT_NOT_YET_VALID, as expected). The machine's date appeared only in tool output, from file times.
  • Chaos:
    • jumps both ways between turns, a rate change, clear (real dates again) and a re-arm without agent_clock;
    • a jump mid-turn: the next call carried the new date;
    • the clock armed mid-turn: calls from then on carried the env's date;
    • the follower and the egress proxy killed;
    • date removed: the turn failed naming why, and the next turn, with date back, passed;
    • 500, 429 and 503 from the endpoint: Codex retried through the relay;
    • two Codex agents with concurrent turns;
    • the agent paused during a write that waits for followers: 504 naming it, then caught up;
    • the solver torn down and a new one deployed;
    • require_agent_clock;
    • a prompt that quotes an environment context and a malformed reminder: sent as written, not refused, while Codex's own context carried the env's date;
    • persistent effort: each time reminder carried the env's time.
  • No clock at all: identical to main.
  • Main: not_advertised, and every call told the model the machine's date; require_agent_clock failed the run.

install/v1: Codex installed into a Debian task container and onto the sandbox's host answered through its relay on real time (Alpine is refused for glibc, as before).

Real models, A/B against main:

  • Local Docker, gpt-6-luna and gpt-6.2-astra, at 1950, a past date, 2031 and 2200, and across a jump between turns. A recorder between the agent and LiteLLM logged every call: each carried the env's date and none the machine's. Asked to quote its context date, get_time, an invoice from the env's mail, and date, python and node, the model answered with the env's date for every one.
  • Modal, the env and Codex both on Modal, at 1950 and 2031 with both models: the same answers, the env's MCP reached over HTTPS through the egress proxy at dates where its certificate isn't valid.
  • Main: the model answered CONTEXT_DATE: 2026-11-25 while get_time said 2031-03-04.
  • At persistent effort, Codex sends reasoning.effort: "disabled", which gpt-6.2-astra answers with a 500 on main and on this branch alike. The reminders those calls carried had the env's time, as a stand-in run at that effort shows end to end.
  • Model spend about $0.05.

On the prod hub, real Cooperation Bench tasks, A/B against today's codex-cli (v37): this branch's image registered as a test agent, two tasks run once on each image the benchmark's way (gpt-6-astra at xhigh, sandboxes closed at the end).

  • The image built on Modal from its build context and deployed; its solver synced in both tasks (synced: true), where v37 was not_advertised.

  • All four runs completed with no failed step and no permission error; neither solver ran a shell command (the tasks give it MCP tools only).

  • Scores: on kl01 both images scored 1.0 (Codex's earlier runs: 4 of 5). On kl12, over three batches:

    • v37 scored 1.0 in 4 of 4 (Codex's two earlier kl12 runs also 1.0);
    • this image scored 1.0 in 5 of 7. Its two misses scored 0.77 the same way: the agent ended its turn with "I'm waiting for …" at about 09:12 story time, before a scheduled 9:16 update the rubric wants read;
    • a control, this image with the date rewrite off (the model told the real date, everything else the same), scored 1.0 in 3 of 3.

    The latest three runs of this image all passed, no agent wrote about the date in any run, and two misses in fourteen runs split this way happen by chance about one time in four. So there's no measured effect of the story date on this task.

Test upkeep: the start-agent CA-bundle test, which Codex's, OpenCode's and Letta Code's suites each had a copy of, is one parametrized test in test_agent_clock_images.py; the stand-in date the Codex and OpenCode date tests share is tst/util/fake_date.py; and test_agent_env_clock_local.py reads the Codex and OpenCode versions its --version check expects from each agent's package.json.

Timing tests: the hung-date test (Codex's and OpenCode's) and Codex's hung catalog read gave a stand-in 1 s to start its child, which xdist load sometimes exceeds (OpenCode's failed 6 of 8 runs under 12 workers). They now give it 3 s, and 8 of 8 runs passed.

🤖 Generated with Claude Code

Confidence Score: 5/5 · The PR appears safe to merge with the documented mid-turn proxy limitation accepted.RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge with the documented mid-turn proxy limitation accepted.

Summary

Codex gains the shared clock follower and egress proxy. Each CLI run uses a model relay to replace Codex’s date and time with the environment’s while the clock is armed.

  • Codex tells the model the task environment’s date and time.
  • Codex commands and MCP clients follow the task environment’s clock.
  • Shared clock tests reuse one date helper and allow more startup time.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Clock[Environment clock] --> Follower[Clock follower]
  Follower --> Commands[Commands and MCP clients]
  CLI[Codex CLI on real time] --> Relay[Per-run model relay]
  Follower --> Date[Environment date]
  Date --> Relay
  Relay --> Endpoint[Model endpoint]
Loading

Reviews (9) · Last reviewed commit: "docs(agents): a clocked agent's proxy se..." · Reviewed by Greptile

earakely-scale and others added 2 commits November 25, 2026 10:38
… the model told the env's date

The Codex image takes the clock follower, libfaketime and the egress proxy, so its card serves clock/v1 sync_time and
sync_env_clock's agent_clock has it follow. The Codex CLI is a static binary that no preloaded library reaches, so it
stays on real time while the commands it runs read the env's time; each CLI run calls the endpoint through a model
relay of its own, which puts the env's date in the environment context and time reminder the CLI writes, and refuses
a call it can't date. mcp-remote gets the egress proxy on an armed clock.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale marked this pull request as ready for review November 25, 2026 19:09
@earakely-scale
earakely-scale requested a review from a team as a code owner November 25, 2026 19:09
earakely-scale and others added 2 commits November 25, 2026 11:28
…the CLI writes, and two timing tests get room

A task prompt that quotes an environment context or a time reminder is now sent as written, not rewritten or refused:
the relay takes a text as the CLI's only when it is one fragment between its markers. The two tests that gave a stand-in
1 s to start a child under xdist load (Codex's and OpenCode's hung date, Codex's hung catalog read) now give it 3 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… tests, and the clock e2e reads pinned CLI versions

The start-agent CA-bundle test, copied into Codex's, OpenCode's and Letta Code's suites, is one parametrized test in
test_agent_clock_images.py. The stand-in date the Codex and OpenCode date tests share is tst/util/fake_date.py. The
agent clock e2e reads the Codex and OpenCode versions its --version checks from each agent's package.json, so a CLI bump
doesn't leave them stale.

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

Copy link
Copy Markdown
Collaborator Author

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

Context from another open PR: #924 (Codex/Gemini atif/1) starts from the same base (7eefbc8) and rewrites the same Codex agent. A trial merge of the two heads (c68add6 + 1230fbf) conflicts in 6 files: codex/Dockerfile, codex/codex_bridge.py, codex/install.sh, and tst/unit/agents/codex/{agent.py,test_image_contract.py,test_message_contract.py}. Whichever PR merges second will have to resolve these. Two places where the fix needs more than picking a side:

  • run_codex signature. This PR adds mcp_urls to run_codex (codex/codex_bridge.py:970) and passes it down to the per-attempt call (:1013). a2a_server.py:753 passes mcp_urls= in, and that file auto-merges. feat(agents): Codex and Gemini serve atif/1, from the CLI's rollout and its session transcript #924 turns run_codex into a wrapper (codex_bridge.py:1194) that forwards a fixed set of kwargs through functools.partial(_run_codex_attempts, ...) (:1212-1215) and moves the old body into _run_codex_attempts (:1234). In the conflict, mcp_urls ends up on _run_codex_attempts. So it has to be added in three places: the wrapper's signature, that partial, and _run_codex_attempts. If it is left out of the partial, nothing fails: the URLs are just never handed to cli_env(..., urls=mcp_urls) (:830 here).
  • Dockerfile COPY line. Each PR adds a different module to the same line: codex_date.py here (Dockerfile:38, imported at codex_bridge.py:27) and codex_atif.py in feat(agents): Codex and Gemini serve atif/1, from the CLI's rollout and its session transcript #924 (Dockerfile:24, imported at a2a_server.py:68). The resolved line needs both.

Just a merge-order heads-up. Neither PR is wrong on its own.


Generated by Claude Code

earakely-scale and others added 3 commits November 25, 2026 15:46
…n static host, whose Date reads real time

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ent too, which merged from main

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale merged commit 366c19d into main Nov 26, 2026
35 checks passed
@earakely-scale
earakely-scale deleted the edgararakelyan/fd-6995-codex-clock-sync branch November 26, 2026 04:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant