Repository navigation
[FD-5916] feat(agents): the Gemini CLI image follows the env's clock - #770
williamloo-scale wants to merge 64 commits into
Conversation
…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: # tst/integration/task_step/test_agent_env_clock_local.py
|
Hi @williamloo-scale, this is Claude, working with Edgar. Please don't merge this yet. It needs #818 merged a single egress rule for every clocked agent:
This branch still has its own Why it matters beyond the test: on an armed clock, the CLI checks TLS certificates against the virtual date. An env on Modal whose Gemini specifically: gemini-cli builds its proxy agent from 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. |
# Conflicts: # src/agent_env/agents/agents/gemini/a2a_server.py
The bridge imports clock_armed and egress_env from agent_clock/agent_egress and hands it the model endpoint's URLs and every MCP server's, so on an armed clock an HTTPS MCP host goes through the egress proxy like the rest. The CLI still gets no HTTP(S)_PROXY (_CLI_PROXY_VARS): it ignores NO_PROXY. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Thanks, done. I merged |
|
Claude again, working with Edgar. Thanks for the update. The migration onto There's one behavioural gap left, and it's the one #818 fixed for Claude Code. What happens:
Evidence: in #818's testing we built a clocked gemini image (throwaway, not committed). With MCP direct, it failed with Two ways to close it:
I can push either one and run the armed-clock check against a Modal env, if you'd like. |
…env clock The capture hook is a child of the CLI, so on an armed env clock it read the env's time: ahead of real time, its grant looked expired and every upload was refused before it was sent, and tar recorded the env's time as its incremental baseline, missing writes made after it. The hook now starts with the real-time marker, and the baseline and capture tar runs get it too, since the marker reaches no child of the process started with it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and only the model's commands follow it On an armed clock the CLI judged its projects.json lock stale by real file times against the env's clock, so two of its own lockers raced and a turn exited with ECOMPROMISED once the clock was more than 10 s ahead; its session retention, tool-output and log cleanups would delete files the same way, and with no proxy of its own (it ignores NO_PROXY, so it can't take one) it checked its MCP servers' certificates against the env's date. Now a turn on an armed clock starts the CLI on real time: its script run by node with the real-time marker, since `gemini`'s env shebang would consume the marker, and GEMINI_CLI_NO_RELAUNCH, since its relaunched child would inherit none. Its locks, cleanups and TLS checks compare real times with real times, and it reaches its loopback relay and MCP servers directly. The commands the model runs follow the clock and get the shared egress rule from a file every bash the CLI starts reads first (BASH_ENV). The model relay names the env's date, read at the turn's start from a child that follows the clock, in the CLI's "Today's date is" line. Unarmed, the CLI's environment and command are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n Gemini endpoint The local agent-clock e2e ran no turn for Gemini. It now serves a fake Gemini API (LiteLLM's /gemini passthrough, tst/util/fake_gemini.py) behind the agent's model relay and runs one turn on the armed, frozen clock: the CLI's date line names the env's date, a `date` the model runs shows the env's time with the egress proxy's variables and no marker, and node runs the CLI's script itself. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… real time Also drops a ticket id from their comments, and tightens the cli_env docstring. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… reads no stdin - The armed path is taken only where the image runs its own egress proxy and its page is armed (gemini_bridge.cli_on_real_time). An install's page, a computer's say, follows a clock the agent never opted in to, and its `gemini` is install.sh's shell launcher, which node failed to parse on every turn there. node is now also handed the CLI's script only when `gemini` resolves to a .js. - The CLI's stdin is /dev/null. It inherited the server's, which under supervisord is a pipe that never closes, so the CLI waited 500 ms for piped input on every start; under Docker before supervisord it was /dev/null. - A unit test pins the CLI's version to the 0.38.2 whose date-line wording the relay matches, since no CI job builds the image, and another pins root.conf's server command to entrypoint.sh's arguments and the image's working directory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… main Under root's supervisord the A2A server was restarted in place after a crash: the dead server's CLI kept running in its own session, and the new server had none of the run's registrations (the env's MCP servers, config, peers, running tasks), so later turns ran without env tools and prompt_agent polled "Task not found" until its timeout. On main the server was the container's process, so the container exited and the run failed at once. root.conf now never starts the server again (autorestart=false, startretries=0), and an event listener on PROCESS_STATE_EXITED and PROCESS_STATE_FATAL stops supervisord when the program is the server, so the container exits. The clock follower and the egress proxy keep restarting in place, and a normal stop is unchanged. supervisord exits 0 however it's stopped, so the container's exit status is 0; its log names the server's exit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On an armed turn the relay rewrote every "Today's date is ... (formatted according to the user's locale)." in a model call's body, so the same sentence in a prompt, a tool's result or a pasted CLI transcript reached the model with the env's date. It now rewrites only the date line of the call's first content, and only when that content is the CLI's environment context. The CLI puts that context first in its chat's history (getInitialChatHistory), and the SDK writes contents before the rest of the body. A side call that starts without it, such as loop detection's, goes as sent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
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 gemini CLI now runs on real time on an armed clock, and only the model's commands follow it. That fixes three things:
The env's date still reaches the model: the relay rewrites the CLI's "Today's date" line to the env's date. Tested on a dedicated VM, with a stand-in model and real models, side by side with
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 Merging: the five clock PRs (#765 #768 #769 #770 #771) each add a row to The full details are in the PR description. Claude, working with Edgar |
|
Closing this, per Edgar's decision. Claude here, working with Edgar. Why: on libfaketime, gemini-cli broke in four ways:
The version on this branch kept the CLI on real time and only put the model's commands on the clock, so advertising Edgar's rule: an agent advertises the clock ( What this agent does instead: it stays as it is on
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 |
What and why
The Gemini CLI image can follow a task env's clock, like Claude Code's (#726, #818, #831, #832). It is off unless a
sync_env_clocksetsagent_clock(require_agent_clockimplies it).Claude, working with Edgar, finished this PR on William's branch: the review fixes below, the crash behaviour in
"Clock off", and the VM runs in "Testing".
Opted in, Gemini works differently from Claude Code: the CLI itself stays on real time, and only the commands the model
runs follow the clock. gemini-cli 0.38.2 can't follow the clock safely, for three reasons:
~/.gemini/projects.json.lockstale by comparing the lock's file time, whichis the kernel's and real, with its own clock (proper-lockfile, 10 s). With the clock more than 10 s ahead, two of its
own lockers race, and the turn exits 1 with
Lock is already released/ ECOMPROMISED.tool-output (30 d) and log (7 d) cleanups delete their files the same way.
NO_PROXY, its loopbackmodel relay included. So a faked CLI goes direct and checks the env's MCP certificates against the virtual date.
That is fix(claude-code): reach env MCP servers through the egress proxy on an armed clock #818's bug: an HTTPS MCP server on Modal whose certificate starts after the virtual date gives no env tools.
How it follows the clock, opted in
The armed path is taken only in the image, once its clock page is armed. The image's root.conf hands the A2A server
the egress proxy (
AGENTENV_EGRESS_PROXY), and onlysync_env_clock'sagent_clockarms the image's page. An install(
install/v1) has no such proxy, and its page, a computer's say, follows a clock the agent never opted in to, so itsturns run as on
main(gemini_bridge.cli_on_real_time).node /opt/agent/node_modules/@google/gemini-cli/bundle/gemini.js,with agent-env's real-time marker (
AGENTENV_REAL_TIME=1) andGEMINI_CLI_NO_RELAUNCH=true.geministarts with#!/usr/bin/env node, andenv, started with the marker,would stay on real time itself and start node without it. The relaunch is off because the CLI's relaunched child
would inherit no marker.
reaches its relay and the env's MCP servers directly, at any virtual date, ahead of real time or behind it.
by
BASH_ENV. That file exports the egress proxy by the shared rule (agent_egress.egress_env, given the modelendpoint and every MCP server's URL): every TLS host through the proxy but loopback,
host.docker.internal, thedeploy's
NO_PROXYhosts and hosts reached over plain HTTP alone.relay rewrites that line to the env's date in every model call that carries the CLI's context, the chat-completions
bridge's included. The CLI always sends that context as a call's first content. The same sentence in a prompt, a
tool's result or a pasted transcript reaches the model as written. The relay reads the date at the turn's start from
date, a child of the server, which follows the clock as the model's commands do. Thecommands'
dateand the gateway'sget_timeshow the env's time.every upload once the clock was past it.
tar --listed-incrementalruns (the baseline and each capture) also get the marker. On the env's clock aheadof real time, tar recorded that clock's time as its baseline and missed files modified after it.
What the model can still see of real time, opted in
ls -l,statand the like show the kernel's times, which are real, for every file, as for everyclocked agent: agent-env's libfaketime is built without stat faking.
LITELLM_BASE_URL, or aGOOGLE_GEMINI_BASE_URLof its own) shows the real date in that line.
per start, so at a fast clock rate it can lag the shell's
dateuntil the next turn.Clock off
The bridge gives the CLI the environment it gave it on
main, with no marker, proxy variables,BASH_ENVor relaunchswitch, and the CLI starts as
gemini, through its shebang, which relaunches itself as onmain. The relay rewrites nodate line. A unit test pins this. One bridge change applies with the clock off too: the CLI's stdin is
/dev/null. Under Dockerthat is what
main's CLI inherited from the server. Under supervisord the server's own stdin is a pipe that nevercloses, and the CLI would wait 500 ms for piped input on every start.
What differs at the image level, clock or not:
USERline. It starts as root, andstart-agentmakes the clock page and boots theegress proxy, then
execs root's supervisord (root.conf) as PID 1. That runs the clock follower and the egressproxy, each as its own user (
agentenv-clock,agentenv-egress), and the A2A server asagent. Adocker execwithout
-u, or anything else that runs commands as the image's user, now runs as root, notagent.agent, uid 10001. The model can no longer write outside/workspace,/app,/tmpand its home, or installsystem packages, as it could as root.
agent-env's bundles and every certifi bundle in the image, its key the egress user's alone. A failed boot stops the
container with exit 2 before the server starts. With the clock off, nothing goes through the proxy unless a process
is handed proxy variables.
start-agentappends a bundle thatSSL_CERT_FILE,REQUESTS_CA_BUNDLE,NODE_EXTRA_CA_CERTSorCURL_CA_BUNDLEnames (Sail's, for one) to agent-env's bundles and the proxy's roots, onceeach, since root.conf points the server's trust variables at agent-env's bundles instead.
/etc/ld.so.preloadloads agent-env's libfaketime and its TLS shim into every process. They fakeonly the agent's user's processes, and with the clock off those read an unarmed page, so every clock read is real,
and the shim checks certificates against that real time.
USER=agent,LOGNAME=agent, supervisord'sSUPERVISOR_ENABLED,SUPERVISOR_PROCESS_NAME,SUPERVISOR_GROUP_NAMEandSUPERVISOR_SERVER_URL(its socket is root's alone),AGENTENV_EGRESS_PROXY=http://127.0.0.1:3128, and the CAvariables
NODE_EXTRA_CA_CERTS=/etc/agentenv/ca.pem,SSL_CERT_FILEandREQUESTS_CA_BUNDLE=/etc/agentenv/ca-bundle.pem.HOMEis/home/agent, as before. The server starts withAGENTENV_REAL_TIME=1, which libfaketime takes out of its environment before Python reads it.main, where theserver was the container's process. root.conf never starts the server again (
autorestart=false, andstartretries=0, so a server that exits as it starts is FATAL at once), and an event listener (agent-exit, a fewlines of Python inline in root.conf) stops supervisord on the server's
PROCESS_STATE_EXITEDorPROCESS_STATE_FATAL.supervisord then stops the follower and the proxy and exits. A server started again in place would have had none of
the run's registrations (the env's MCP servers, configuration, peers, running tasks): the turn running at the crash
polled "Task not found" until its timeout, and later turns ran without the env's tools. Measured on the VM, the
container stops about 2 s after the server dies, and prompt_agent fails about 60 s after, as on
main.exits. SIGTERM goes to the server's process group, SIGKILL after 30 s; the server's own graceful shutdown (5 s,
which ends running turns' CLIs) is unchanged, and root.conf's command is pinned to
entrypoint.sh's.main's was the server's own (137 for the kill on the VM):supervisord 4.2.5 exits 0 however it's stopped. Its log line before it stops, in the container's output, says what
happened:
exited: agent (terminated by SIGKILL; not expected).AGENTENV_REAL_TIME=1 <python> <capture.py>, and thetar --listed-incrementalruns get the marker, clock or not. With the clock off those processes are on real timeanyway, so only the command the CLI's settings show changes. The prefix relies on the CLI starting hooks through
bash, as 0.38.2 does.
supervisor4.2.5 in the image's Python, which the model's scripts share; the two systemusers; the clock library, the TLS shim, the follower and the egress proxy's binary;
/etc/agentenv. The build has twomore stages (the proxy's Go build and tests, and libfaketime's C build), and the image's build context takes
utils/faketime_clock,utils/egress_proxyandutils/agent_clock, so a change to any of them rebuilds it.agent_egress.pyandclockpage.pybeside the bridge, and never takes the armed path.Started as another user, the image runs the A2A server alone, as before, with no supervisord, follower or proxy. The
preload still loads, and reads no page there, so time is real.
Review findings and fixes
test_env_clock.pyreal-time, node-direct and call-site testssessionRetention(30 d) deletes the resumed session; tool-output and log cleanupsGEMINI_CLI_NO_RELAUNCH=truegeminishebang'senvconsumes the markercli_programstarts node on the scripttest_a_cli_on_real_time_is_started_as_its_script_run_by_node…BASH_ENVtest_on_an_armed_clock_the_models_commands_go_out_by_the_shared_egress_rule, the call-site testtest_the_changelogs_capture_runs_on_real_time…test_the_changelogs_tar_runs_on_real_time…test_litellm_proxy.pydate tests,test_the_envs_date_is_worded…geminiis install.sh's shell launcher. Under an armed page, a computer's say, the turn took the armed path, and node failed on the launcher (SyntaxError) every turncli_on_real_time); node is handed the CLI's script only whengeminiresolves to a.jsinstalled-under-an-armed-pagecase,test_an_installs_gemini_which_node_cant_run_is_started_as_it_is(install.sh's own launcher text)/dev/nulltest_the_cli_reads_no_input_from_the_servers_stdintest_the_cli_is_the_version_whose_date_line_the_relay_names_the_envs_date_incount=1, bytes otherwise as sent)test_only_the_clis_own_context_names_the_envs_date_and_the_same_words_elsewhere_stayentrypoint.sh's (graceful shutdown, working directory)test_root_conf_starts_the_server_as_entrypoint_sh_doesmain(autorestart=false,startretries=0, theagent-exitlistener)test_server_exit.py: root.conf read as supervisord reads it, and the listener run as supervisord runs it, fed the follower's, the proxy's and the server's eventsEach fix is mutation-checked: 30 mutations of the wiring, each killed by the tests meant to kill it.
Changes
gemini_bridge.py:cli_on_real_timedecides a turn's path: the image's egress proxy, and an armed page.cli_envadds the marker, the relaunch switch and the commands'BASH_ENVfile on that path, and is otherwiseunchanged.
cli_programstarts node directly for a real-time CLI whosegeminiis the CLI's script.run_geminigives the CLI/dev/nullas stdin.env_today/with_dateput the env's date in the date line of the CLI's context, the call's first content.a2a_server.py: each turn's route carries the env's date, which the relay (passthrough and chat-completions bridge)writes in.
gemini_config.py: the commands' file goes with the run's settings.gemini_changelog.py: the capture hook and its tar run on real time.utils/faketime_clockandutils/egress_proxy, plusagent_clock(
shared_sources.toml).start-agent,root.conf, andinstall.sh/ Dockerfile copyingagent_egress.pyandclockpage.pybeside thebridge.
root.conf: the server isn't restarted, and theagent-exitlistener stops the container when it exits.tst/unit/agents/gemini/test_env_clock.py, the date tests intest_litellm_proxy.py, the root.conf pin intest_image_contract.py, andtest_server_exit.py.tst/util/fake_gemini.py, a stand-in for LiteLLM's /gemini passthrough. With it, the local agent-clock e2e'sGemini row runs a real turn on the armed clock: date line, the shell's date, proxy, and node started directly.
agents/README.md.No shared code changed:
utils/egress_proxy,utils/faketime_clockandutils/agent_clockare untouched, so no otherimage is rebuilt.
Testing
Unit tests: 1409 passed for
tst/unit/agents,tst/unit/task_step/agent_clock_test.py,tst/unit/utilsand theshipped bundles, on the head merged with
main. The 46 skips need Linux, GNU tar or a filesystem other than APFS,which CI has; on the VM (Ubuntu 24.04) the earlier head ran the same set with no skips (1417 passed), and this head
ran
tst/unit/agents/geminiand the clocked-image tests with none (218 passed).ruffis clean.Mutation check: 30 of 30 mutations killed, each by the test meant to kill it: the 19 of the clock work, on macOS
and on Linux; 8 of root.conf's crash wiring (the listener's program filter, its kill, its events, its priority, a
;that supervisord's parser would take for a comment, the server'sautorestartandstartretries); and 3 of thedate line's scope (no
count=1, no check of the first content, any first text taken for the context).The date line's scope, on the last head: the Gemini and agent unit tests passed on macOS (1178). In 0.38.2's
bundle, every call that carries the CLI's context sends it first: the chat (
getInitialChatHistory), compression,and both router classifiers, which send a history slice and then the request. The SDK writes
contentsbeforesystemInstruction. Loop detection sends<original_user_request>first, but only after 30 turns, when its 20-itemslice no longer reaches the context.
supervisord 4.2.5 itself, with root.conf's listener, on macOS: the clock program killed comes back and supervisord
stays; the server killed, or failing as it starts (FATAL), stops supervisord within 2 s; a normal stop exits 0.
Real CLI (0.38.2) against a stand-in Gemini API, through this branch's A2A server with an armed clock page, on the
head before the last review round (it changed the path's gate, the launcher check and stdin, not the armed path):
node …/bundle/gemini.js.Real CLI, unarmed: the CLI relaunched as on
main, with no proxy variables and the real date.On a VM (
i-099c903a905ef84c1, Ubuntu 24.04, headca6002219), A/B againstmainas published (PyPI0.9.1609, its Gemini image
ghcr.io/scaleapi/agentenv-gemini@sha256:1f73da02…, whose bridge and server match thewheel's sources). The model was
gemini-2.5-flash; envs ran on local Docker, and on Modal where the row says so.marker=[]and the proxy, undernode …/bundle/gemini.js. +1000 y can't be armed: see Limitstest_agent_env_clock_local.py), with Claude Code's and OpenCode'sTuesday, March 4, 2031g-noclock,g-off,g-off-modal-agent(clock off: none, armed withoutagent_clock; agent local and on Modal)main's CLI command and environment; real date everywhere--max-old-space-size), stdin/dev/null, no proxy variables, marker orBASH_ENV, real shell date and date line,get_timeonly when armed, no egress rows, no follower; the environment adds what "Clock off" listsg-on,g-late-on,g-require,g-require-late,g-on-modal-agent(2027-02-01)get_timeat the env's date; commands through the proxy; the CLI directnode …/bundle/gemini.jswithAGENTENV_REAL_TIME=0(scrubbed),GEMINI_CLI_NO_RELAUNCHandBASH_ENV, no proxy variables; the egress log holds only the command's curl. On Modal: dumb-init, start-agent, supervisord, the server as uid 10001require_agent_clockfails the step:can't follow the clock … not_advertisedg-before-cert-on(2026-10-27; the env's*.w.modal.hostcertificate starts 2026-11-19) andg-behind-on(2025-06-01), env on Modalget_time, shell date and date line at the clockg-long-p75d,-p200y,-y1950p75d: history kept, real datesg-changelog-onat +75 dworkspace/notes.txt, tar times real, no upload failureg-two-agents-on(Claude Code first, Gemini late)reset_env,clearclearreturns tomain's path with history intactclear, the real date line and shell dateagent-env runmid-turnmain's path:gemini, no markerOn the VM again, head
7d3e0d857(the crash change, merged withmain), local Docker, the image rebuilt, astand-in Gemini API on the Docker bridge, since the VM holds no model key now.
mainis its published image as above.x-kill: the server killed-9while the turn's command runs (it writes a line, sleeps 40 s, writes another; opted in)exited: agent (terminated by SIGKILL; not expected); prompt_agent failed 58.7 s after the kill,AgentUnreachableError: … stopped answering: 5 polls in a row over 60s; the file kept only its first line, and nosleep 40was left on the host 50 s laterx-off: a turn with the clock offSaturday, November 21, 2026(real)x-on: a turn opted in at 2027-02-04Thursday, February 4, 2027x-follower: the follower and the proxy killed-9on an armed clock, then a turnTuesday, March 4, 2031,node …/bundle/gemini.js, teardown terminated 1, failed 0docker run):docker stop -t 30-9; sent SIGTERM alone; failing to start (A2A_PORT=99999, FATAL)docker run) after, exit 0 each-9, then 5 more killsLimits
rest of the turn, without the proxy. The next turn starts as above.
host's memory (
autoConfigureMemory, on by default). A headless turn doesn't approach Node's default.pins the CLI's version, so a bump has to recheck the wording; only an image run sees the bundle itself.
env_todaywords the date as Node does under the image'sLANG=C.UTF-8(en-US). Under anotherLANGthe CLI's own wording would differ and the line would be replaced in English.BASH_ENVreaches bash alone. A child the CLI starts without bash (a stdio MCP server, thebrowser agent) would follow the clock without the proxy; none is configured today.
BASH_ENVin their environment.(
GEMINI_CLI_NO_RELAUNCH=trueis there onmaintoo: the CLI's relaunch sets it for its child.)2262-04-11. At +1000 years the follower exits on
struct.errorand restarts in a loop, andsync_env_clockreportsonly that the follower "hasn't heard from the gateway". This is the shared clock code, the same for every clocked
image and computer; +200 years works.
tar -x,-t) still runs on the env's clock: only the--listed-incrementalruns moved.Extracted files keep their archived times; with the clock behind, tar may warn of a time stamp in the future.
AGENTENV_EGRESS_PROXY(thebrowser computer base's image does) and whose page is armed takes the armed path: its commands get that proxy, and
the relay names the date
dategives the server. Its CLI starts through install.sh's launcher, which node can't run,so it runs on real time only if its user isn't the one the target fakes.
🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no new actionable issue remains.Summary
Gemini’s image can follow the env’s clock while keeping the CLI itself on real time.
Both earlier, unnumbered findings are addressed: the image includes the shared clock helpers, and date replacement is limited to the CLI’s opening context. No new actionable issues were found.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Turn starts] --> B{Image clock armed?} B -->|No| C[Start Gemini as before] B -->|Yes| D[Start Node directly on real time] D --> E[CLI reaches model relay and MCP directly] D --> F[Model-run bash commands follow env clock] F --> G[Shared egress proxy rule] E --> H[Relay replaces CLI context date]Reviews (13) · Last reviewed commit: "fix(agents): only the Gemini CLI's own c..." · Reviewed by Greptile