Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
ae1d4be
feat(agents): agents follow the env's clock the way computers do (FD-…
williamloo-scale Nov 16, 2026
eea933c
refactor(agents): leave the Claude Code image to its own PR; agents s…
williamloo-scale Nov 17, 2026
608a93d
Merge origin/main
williamloo-scale Nov 17, 2026
182cef0
feat(agents): the Claude Code image follows the env's clock (FD-5916)
williamloo-scale Nov 17, 2026
bce00d4
fix(agents): agent clock review: new config's status, one clock per a…
williamloo-scale Nov 17, 2026
84381b8
fix(agents): keep each agent's clock record on a key of its own; a re…
williamloo-scale Nov 17, 2026
56dac45
fix(agents): agent clock keys can't collide; one clock env per agent;…
williamloo-scale Nov 17, 2026
c726743
chore: drop test run output committed by mistake
williamloo-scale Nov 17, 2026
5e8c756
Merge #714
williamloo-scale Nov 17, 2026
3b6f499
test(agents): the Claude Code image follows the env's clock end to en…
williamloo-scale Nov 17, 2026
cecc686
fix(agents): a failed agent sync retires its follower; the task's zon…
williamloo-scale Nov 17, 2026
afe55b4
Merge origin/main
williamloo-scale Nov 17, 2026
d523a6e
Merge #714
williamloo-scale Nov 17, 2026
ac0a39e
fix(agents): libfaketime's init can't deadlock the CLI; the CLI goes …
williamloo-scale Nov 17, 2026
c8ed6e1
fix(agents): a later clock sync leaves agents teardown_sandboxes took…
williamloo-scale Nov 17, 2026
b5d3b4b
fix(ci): the agent clock e2e skips as a declared capability gap; the …
williamloo-scale Nov 17, 2026
25af21a
chore: drop test-run output committed again, and ignore where the pro…
williamloo-scale Nov 17, 2026
7216c7c
fix(agents): route the CLI through egress by the clock page's armed f…
williamloo-scale Nov 17, 2026
fc3134b
Merge #714
williamloo-scale Nov 17, 2026
f8bd9ff
feat(a2a-agent): validate clock/v1 by the time the agent's own comman…
earakely-scale Nov 17, 2026
f9af1b6
refactor(a2a-agent): name the clock validation's timeouts and error l…
williamloo-scale Nov 17, 2026
43fdb97
fix(gateway): get_time says the machine's clock may not be synchroniz…
earakely-scale Nov 18, 2026
8bf8e4c
refactor(a2a-agent): move agent_clock to a2a_agent/clock.py, beside t…
earakely-scale Nov 18, 2026
810f42e
Merge #714
williamloo-scale Nov 18, 2026
686fdf1
test(agents): the agent clock e2e imports FOLLOWING_KEY from a2a_agen…
williamloo-scale Nov 18, 2026
9d7d6c0
Merge origin/main (#714 merged)
williamloo-scale Nov 18, 2026
1ff90bd
fix(agents): the Claude Code image installs protocol 0.1.575, the fir…
earakely-scale Nov 18, 2026
ca97b37
fix(computers): the clock follower follows a changed config while its…
earakely-scale Nov 18, 2026
0875e06
fix(agents): an armed clock keeps the agent's own NO_PROXY hosts dire…
williamloo-scale Nov 18, 2026
bb4f07f
test(agents): the agent clock checks run over every clocked agent ima…
williamloo-scale Nov 18, 2026
e64e871
feat(agents): the Gemini image follows the env's clock (FD-5916)
williamloo-scale Nov 18, 2026
a3f9e34
Merge main into #726: the clock and egress proxy now live in utils (#…
earakely-scale Nov 18, 2026
3c60fda
refactor(agents): the Claude Code image takes the clock and egress pr…
earakely-scale Nov 18, 2026
c43b294
Merge #726: the clock and egress proxy come from utils
williamloo-scale Nov 18, 2026
150c563
test(agents): Claude Code's contract test takes the folders shared_so…
williamloo-scale Nov 18, 2026
5bfe6dc
refactor(agents): the image takes the clock and egress proxy from uti…
williamloo-scale Nov 18, 2026
0a9d2be
Merge #726
williamloo-scale Nov 18, 2026
c65c5e6
test(agents): the contract test takes the folders shared_sources.toml…
williamloo-scale Nov 18, 2026
aed27ee
fix(agents): a private HTTPS model endpoint is reached directly on an…
williamloo-scale Nov 18, 2026
642c612
fix(agents): a private HTTPS model endpoint is reached directly on an…
williamloo-scale Nov 18, 2026
6f09361
Merge #726
williamloo-scale Nov 18, 2026
987da31
test(agents): the clock test's HTTPS model hosts resolve publicly wit…
williamloo-scale Nov 18, 2026
a6f3720
fix(agents): the model host's lookup is bounded and kept, so a slow r…
williamloo-scale Nov 18, 2026
62be360
fix(agents): the model host's lookup is bounded and kept, as #726's is
williamloo-scale Nov 18, 2026
5a6a42a
Merge #726
williamloo-scale Nov 18, 2026
ac0ea75
Merge main (#726 merged)
williamloo-scale Nov 18, 2026
1ab2e3f
refactor(agents): follow the merged Claude Code image (#726): the pro…
williamloo-scale Nov 18, 2026
11eb021
fix(agents): keep a provider's CA bundle trusted, and send HTTPS MCP …
williamloo-scale Nov 18, 2026
fdefbf3
Merge main: the control token (#780, #784)
williamloo-scale Nov 19, 2026
6bc6be3
Merge remote-tracking branch 'origin/main' into wloo/gemini-clock-image
williamloo-scale Nov 19, 2026
8fbb207
Merge remote-tracking branch 'origin/main' into wloo/gemini-clock-image
williamloo-scale Nov 19, 2026
4b6538a
refactor(gemini): take the shared egress rule (#818)
williamloo-scale Nov 19, 2026
0462f5a
Merge remote-tracking branch 'origin/main' into wloo/gemini-clock-image
williamloo-scale Nov 20, 2026
90f7a88
Merge remote-tracking branch 'origin/main' into wloo/gemini-clock-image
earakely-scale Nov 20, 2026
198d3e9
fix(agents): Gemini's changelog captures and tars on real time on an …
earakely-scale Nov 20, 2026
56fd5c1
feat(agents): Gemini's CLI stays on real time on an armed env clock, …
earakely-scale Nov 20, 2026
c00faa4
docs(agents): how Gemini's image follows the env's clock
earakely-scale Nov 20, 2026
db7a2da
test(agents): the Gemini clock row runs a real turn against a stand-i…
earakely-scale Nov 20, 2026
3ad0860
docs(agents): Gemini's root.conf and start-agent say its CLI stays on…
earakely-scale Nov 20, 2026
b25a95f
Merge remote-tracking branch 'origin/main' into wloo/gemini-clock-image
earakely-scale Nov 20, 2026
ca60022
fix(agents): Gemini's CLI takes the armed path only in its image, and…
earakely-scale Nov 20, 2026
d43bf72
Merge remote-tracking branch 'origin/main' into wloo/gemini-clock-image
earakely-scale Nov 21, 2026
7d3e0d8
fix(agents): Gemini's container exits when its A2A server does, as on…
earakely-scale Nov 21, 2026
ebbcd96
fix(agents): only the Gemini CLI's own context gets the env's date
earakely-scale Nov 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/agent_env/agents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ The A2A server starts with the real-time marker, so it and its records stay on r
- **One rule for every clocked agent.** That rule is `agent_egress.py` in `utils/agent_clock`, which only agent images
take (`agent_clock = "utils/agent_clock"` in `shared_sources.toml`), so changing it rebuilds no computer base. The
bridge imports it, and the image and `install.sh` copy it beside the bridge with the clock's `clockpage.py`, whose
layout and check it reads the page by, so every agent put on the clock, OpenCode's too, goes out the same way.
layout and check it reads the page by, so every agent put on the clock, OpenCode's and Gemini's too, goes out the
same way. Gemini's image follows the clock in its own way: its CLI stays on real time, and only the commands the
model runs follow the clock and go out by that rule, as its folder's `README.md` says.

Started as a user other than root, the image runs the A2A server alone, on real time, as before.

Expand Down Expand Up @@ -94,8 +96,9 @@ by its id, `@local/agentenv-framework/agents/gemini`. It calls the `[model]` end
`<base>/gemini`, which a LiteLLM gateway serves, through a proxy in the agent that adds the run's attribution; a model
named with a provider prefix, such as `vertex_ai/...`, goes to `<base>/v1/chat/completions` instead. It takes its
model from the prompt, so its smoke task needs `[model] default` (or the `agent` role) set. It declares `install/v1`
too, into a container or onto a `vm` sandbox's Linux host, with glibc. Its folder's `README.md` covers the extensions
it implements.
too, into a container or onto a `vm` sandbox's Linux host, with glibc. Its image can follow a task env's clock, as
Claude Code's does, once a `sync_env_clock` sets `agent_clock`. Its folder's `README.md` covers the extensions it
implements and how it follows the clock.

`agents/opencode/` runs the [OpenCode](https://github.com/anomalyco/opencode) CLI behind the protocol's A2A agent
framework: each turn is one `opencode run --format json` run, resumed in the context's OpenCode session, the task env's
Expand Down
48 changes: 43 additions & 5 deletions src/agent_env/agents/agents/gemini/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# The env's clock: the egress proxy, one static Go binary, and agent-env's libfaketime and its TLS shim, taken from
# agent-env's sources as clock/ and egress/ (shared_sources.toml) and built for this image's libc (Debian bookworm) in
# stages of their own, so no toolchain is left in the image.
FROM public.ecr.aws/docker/library/golang:1.26.11-bookworm@sha256:dc40a13b61304647ed7e5d581d246b86413dfc29d63c6d018310feb93cd98fc0 AS egress
COPY egress/ /egress/
RUN cd /egress && go vet ./... && go test -count=1 ./... \
&& CGO_ENABLED=0 GOFLAGS=-mod=readonly go build -trimpath -ldflags=-s -o /out/egress .

FROM public.ecr.aws/docker/library/python:3.11-slim@sha256:c20888b6acdd1e63e1c433a185bf3ad162c0288fe484616ce062e0d28add2900 AS clock
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential patch curl ca-certificates
COPY clock/ /clock/
RUN sh /clock/build.sh /out

FROM public.ecr.aws/docker/library/python:3.11-slim@sha256:c20888b6acdd1e63e1c433a185bf3ad162c0288fe484616ce062e0d28add2900
# Node for the Gemini CLI, checked against its published checksum; install.sh brings the same.
ARG NODE_VERSION=22.23.3
Expand All @@ -21,13 +35,37 @@ COPY requirements.txt model-requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt -r model-requirements.txt
# install.sh and run.sh are install/v1's: in the image, so they stay in its build context.
COPY a2a_server.py gemini_bridge.py gemini_changelog.py gemini_config.py gemini_kit.py entrypoint.sh install.sh run.sh ./
# The CLI's cwd and file-tool boundary, /workspace, and its state, fixed so neither follows the uid: Modal runs the
# image as root. /app is kept, empty and writable, for tasks that name it.
# Every clocked agent's egress rule, which the bridge imports, and the clock page's format it reads (shared_sources.toml).
COPY agent_clock/agent_egress.py clock/clockpage.py ./
# The CLI's cwd and file-tool boundary, /workspace, and its state, fixed so neither follows the uid. /app is kept,
# empty and writable, for tasks that name it.
RUN useradd --create-home --uid 10001 agent && mkdir -p /workspace/inputs /app /home/agent/.gemini \
&& chown agent:agent /workspace /workspace/inputs /app /home/agent/.gemini && chmod 0755 entrypoint.sh
# The env's clock: the follower and the egress proxy, each as its own user, under root's supervisord (root.conf), and
# agent-env's libfaketime and its TLS shim preloaded into every process, faking only the agent's (clock.conf). The
# follower's config is the agent's user's to write (agentenv_protocol.a2a_agent.clock) and the follower's to read.
RUN pip install --no-cache-dir supervisor==4.2.5 \
&& useradd --system --no-create-home --home-dir /nonexistent --shell /usr/sbin/nologin agentenv-clock \
&& useradd --system --no-create-home --home-dir /nonexistent --shell /usr/sbin/nologin agentenv-egress \
&& mkdir -p /usr/local/lib/agentenv-clock /usr/local/lib/agentenv-egress /etc/agentenv \
&& install -d -o agent -g agentenv-clock -m 2750 /etc/agentenv/clock \
&& touch /etc/agentenv/ca.pem \
&& cp /etc/ssl/certs/ca-certificates.crt /etc/agentenv/ca-bundle.pem \
&& cp /etc/ssl/certs/ca-certificates.crt /usr/local/lib/agentenv-egress/roots.pem
COPY --from=clock /out/libfaketimeMT.so.1 /out/libtls_realtime.so /usr/local/lib/agentenv-clock/
COPY --from=egress /out/egress /usr/local/lib/agentenv-egress/egress
COPY clock/clockpage.py clock/clock-follower /usr/local/lib/agentenv-clock/
COPY clock/clock.conf /etc/agentenv/clock.conf
COPY root.conf /etc/agentenv/root.conf
COPY start-agent /usr/local/bin/start-agent
RUN sed -i -e "s/^AGENTENV_SESSION_UID=.*/AGENTENV_SESSION_UID=$(id -u agent)/" \
-e "s/^AGENTENV_CLOCK_PAGE_UID=.*/AGENTENV_CLOCK_PAGE_UID=$(id -u agentenv-clock)/" /etc/agentenv/clock.conf \
&& chmod 0755 /usr/local/lib/agentenv-clock/clock-follower /usr/local/bin/start-agent \
&& printf '%s\n' /usr/local/lib/agentenv-clock/libfaketimeMT.so.1 /usr/local/lib/agentenv-clock/libtls_realtime.so \
> /etc/ld.so.preload
ENV A2A_PORT=8000 PYTHONPATH=/opt/agent GEMINI_CLI_HOME=/home/agent GEMINI_CWD=/workspace
USER agent
WORKDIR /workspace
EXPOSE 8000
# CMD rather than ENTRYPOINT: Modal passes a sandbox's env to the image's CMD only.
CMD ["/opt/agent/entrypoint.sh"]
# Starts as root, which start-agent needs for the clock; the A2A server and the CLI run as the agent's user. CMD rather
# than ENTRYPOINT: Modal passes a sandbox's env to the image's CMD only.
CMD ["/usr/local/bin/start-agent"]
40 changes: 38 additions & 2 deletions src/agent_env/agents/agents/gemini/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,43 @@ CLI by its last segment, and the proxy translates its generate calls to `/v1/cha
| `attribution-probe/v1` | the `project_id` and `task_id` the proxy last sent |
| `install/v1` | `install.sh`, into a task container (as root, the CLI working in `/workspace`) or onto a `vm` sandbox's Linux host: Node and uv checked against their checksums, the CLI from `package-lock.json` and the agent's requirements in a Python of its own, which the target's own Node and Python are never replaced by; the model's commands get the agent's where the target has none. Node's builds need glibc |
| `triggers/v1` | SDK default |
| `clock/v1` | the framework's `sync_time`, in the image, which runs the clock follower |

The image is `python:3.11-slim` with Node, the CLI, the agent and the Python packages `model-requirements.txt` pins for
the model's scripts, running as the `agent` user; the CLI's state is in
`/home/agent/.gemini` (`GEMINI_CLI_HOME`) whatever the uid.
the model's scripts. It starts as root, whose supervisord (`start-agent`, `root.conf`) runs the clock follower and the
egress proxy, each as its own user, and the A2A server as the `agent` user, on real time; the CLI's state is in
`/home/agent/.gemini` (`GEMINI_CLI_HOME`) whatever the uid. When the A2A server exits, supervisord stops and the
container exits with it, as when the server was the container's process, so a run fails at once rather than going on
with a new server that has none of its registrations; the follower and the proxy restart in place. Started as another
user, it runs the A2A server alone.

## The env's clock

The image can follow a task env's clock as Claude Code's does, with agent-env's libfaketime preloaded for the `agent`
user and the computer base's follower and egress proxy (`src/agent_env/agents/README.md`), and only once a
`sync_env_clock` sets `agent_clock`. Unarmed, the CLI runs exactly as it did before it could: the same environment, and
started as `gemini`. So does an install's (`install/v1`), which has no egress proxy of the image's: its clock page, a
computer's say, follows a clock the agent never opted in to. On an armed clock the CLI itself stays on real time, and
only the commands the model runs follow the clock:

- **The CLI, on real time.** Each turn starts the CLI's script with node itself, with agent-env's real-time marker and
`GEMINI_CLI_NO_RELAUNCH`, so neither `gemini`'s `#!/usr/bin/env node` line nor the CLI's relaunch of itself hands node
an environment the marker is gone from. It judges its `projects.json` lock stale, its sessions, tool outputs and logs
old and its credentials expired by real file and server times, which would be wrong on the env's clock, and it checks
certificates against real time, so it reaches its model relay and the env's MCP servers directly, an HTTPS server on
Modal included, whatever the clock shows. It keeps Node's default heap, which its relaunch would have raised to half
the host's memory.
- **The model's commands, on the env's clock.** Every bash the CLI starts, each command the model runs and each hook,
first reads a file beside the run's settings (`BASH_ENV`) that exports the egress proxy by the rule every clocked
agent shares (`agent_egress.egress_env`): every TLS host through the proxy but loopback, `host.docker.internal`, the
deploy's `NO_PROXY` hosts and hosts reached over plain HTTP alone. The CLI itself is handed no proxy, since it would
send every request through one, `NO_PROXY` or not, its loopback relay included.
- **The env's date.** The CLI words its "Today's date is" line from its own clock, so the model relay names the env's
date there instead, read as the turn starts from `date`, which follows the clock as the model's commands do. A CLI
that calls no relay, with no `LITELLM_BASE_URL` or with a `GOOGLE_GEMINI_BASE_URL` of its own, shows the real date
there. The commands' `date` and the gateway's `get_time` show the env's time.
- **The changelog, on real time.** The capture hook and its `tar` run with the marker: the hook checks its grant's
expiry, and tar the times its incremental snapshot compares, against real time, as both are.

A clock armed while a turn runs reaches that turn's CLI, which was started to follow it, without the proxy; the next
turn starts as above.
28 changes: 19 additions & 9 deletions src/agent_env/agents/agents/gemini/a2a_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@
chats_dir_for_cwd,
cli_env,
cli_model,
cli_on_real_time,
detect_format,
env_today,
find_session_file,
gemini_request_to_openai,
get_last_attribution_snapshot,
Expand All @@ -82,6 +84,7 @@
run_gemini,
transcript_session_id,
wants_sse,
with_date,
)
from gemini_changelog import (
HOOK_TIMEOUT_S,
Expand Down Expand Up @@ -197,11 +200,13 @@ class GeminiConfig(AgentConfig):

@dataclass(frozen=True)
class _Route:
"""What the proxy forwards one run's model calls with."""
"""What the proxy forwards one run's model calls with: on an armed clock, ``today``, the env's date as the run
started, which the CLI's date line names in place of its own, on real time."""

model: str | None
project_id: str | None
task_id: str | None
today: str | None = None


# install.sh, from the build context install_agent unpacks, brings Node, the Gemini CLI and a Python of the agent's
Expand Down Expand Up @@ -362,16 +367,16 @@ def _answer(uploaded: Uploaded) -> dict[str, Any]:


async def _vertex_openai_bridge(
rest: str, request: Request, base: str, route_model: str, project_id: str | None, task_id: str | None,
rest: str, request: Request, body: bytes, base: str, route_model: str, project_id: str | None,
task_id: str | None,
) -> Response:
"""Translate the CLI's native-Gemini generate call into an OpenAI
"""Translate the CLI's native-Gemini generate call, ``body``, into an OpenAI
/v1/chat/completions call whose `model` is the provider-prefixed route
string (e.g. vertex_ai/global/gemini-3.1-pro-preview) — the only endpoint
that reaches Vertex — then translate the response back to a single native
Gemini GenerateContentResponse (SSE-framed when the CLI asked for
streamGenerateContent). Attribution headers are injected identically to the
passthrough path so cost tagging is preserved."""
body = await request.body()
try:
greq = json.loads(body) if body else {}
except json.JSONDecodeError:
Expand Down Expand Up @@ -544,9 +549,10 @@ async def run(self, request: TaskRequest[GeminiConfig]) -> TaskResult:
async with self._context_locks_guard:
self._active_contexts.add(context_id)
token = uuid.uuid4().hex
self._routes[token] = _Route(cfg.model, cfg.project_id, cfg.task_id)
own = self.session_ref_for_context(context_id)
try:
armed = cli_on_real_time(os.environ)
self._routes[token] = _Route(cfg.model, cfg.project_id, cfg.task_id, env_today() if armed else None)
with run_settings(request.mcp_servers, cfg.role, cfg.system_prompt) as settings:
base_url = None
if os.environ.get("LITELLM_BASE_URL"):
Expand All @@ -566,7 +572,10 @@ async def run(self, request: TaskRequest[GeminiConfig]) -> TaskResult:
attachment_paths=attachment_paths or None,
timeout_s=cfg.timeout_seconds,
event_callback=lambda event: self._on_event(event, request),
env=cli_env(os.environ, system_settings=settings, base_url=base_url),
env=cli_env(
os.environ, system_settings=settings, base_url=base_url, clock_armed=armed,
mcp_urls=[str(info.get("url") or "") for info in (request.mcp_servers or {}).values()],
),
cwd=GEMINI_CWD,
other_sessions=lambda: {*self.bound_session_refs(), *self._claimed_sessions} - {own},
)
Expand Down Expand Up @@ -751,7 +760,8 @@ async def load_snapshot(self, request: ObjectSnapshotLoadRequest) -> ObjectSnaps
return ObjectSnapshotLoadResponse(context_id=new_context_id)

async def litellm_gemini_proxy(self, request: Request) -> Response:
"""Forward one run's model call to LiteLLM with that run's attribution headers."""
"""Forward one run's model call to LiteLLM with that run's attribution headers, its date line naming the env's
date when the run started on an armed clock."""
route = self._routes.get(request.path_params["token"])
if route is None:
raise HTTPException(status_code=404, detail="no running turn has this proxy route")
Expand All @@ -764,13 +774,13 @@ async def litellm_gemini_proxy(self, request: Request) -> Response:
# OpenAI-compat endpoint instead. Everything else (countTokens, the native
# AI-Studio models) keeps the verbatim passthrough below.
route_model = (route.model or "").strip()
body = with_date(await request.body(), route.today)
if needs_openai_route(route_model) and is_generate_path(rest):
return await _vertex_openai_bridge(rest, request, base, route_model, route.project_id, route.task_id)
return await _vertex_openai_bridge(rest, request, body, base, route_model, route.project_id, route.task_id)
fwd_headers = _upstream_headers(
{k: v for k, v in request.headers.items() if k.lower() not in _PROXY_DROP_REQ_HEADERS},
route.project_id, route.task_id,
)
body = await request.body()
try:
async with httpx.AsyncClient(timeout=_DEFAULT_TIMEOUT_S) as client:
upstream = await client.request(
Expand Down
Loading
Loading