Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 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
f228c9e
feat(agents): the Codex 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
dd8de29
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
cc3ff73
refactor(agents): the image takes the clock and egress proxy from uti…
williamloo-scale Nov 18, 2026
655614e
Merge #726
williamloo-scale Nov 18, 2026
84ca228
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
2cea6f9
fix(agents): a private HTTPS model endpoint is reached directly on an…
williamloo-scale Nov 18, 2026
1837705
Merge #726
williamloo-scale Nov 18, 2026
b605046
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
b47867b
fix(agents): the model host's lookup is bounded and kept, as #726's is
williamloo-scale Nov 18, 2026
9eff419
Merge #726
williamloo-scale Nov 18, 2026
ff48a8f
Merge main (#726 merged)
williamloo-scale Nov 18, 2026
155ef84
refactor(agents): follow the merged Claude Code image (#726): the pro…
williamloo-scale Nov 18, 2026
ef0d8de
fix(agents): keep a provider's CA bundle trusted, and send HTTPS MCP …
williamloo-scale Nov 18, 2026
716f5fc
Merge main: the control token (#780, #784)
williamloo-scale Nov 19, 2026
96ad61c
fix(egress): leaves start at the Unix epoch, which rustls accepts
williamloo-scale Nov 19, 2026
158f548
Merge remote-tracking branch 'origin/main' into wloo/codex-clock-image
williamloo-scale Nov 19, 2026
0a90ec9
Merge remote-tracking branch 'origin/main' into wloo/codex-clock-image
williamloo-scale Nov 19, 2026
d864a99
refactor(codex): take the shared egress rule (#818)
williamloo-scale Nov 19, 2026
764a13c
fix(codex): mcp-remote reaches the env's MCP servers through the egre…
williamloo-scale Nov 19, 2026
94b7ddd
Merge remote-tracking branch 'origin/main' into wloo/codex-clock-image
williamloo-scale Nov 20, 2026
e2fa4b7
Merge remote-tracking branch 'origin/main' into wloo/codex-clock-image
earakely-scale Nov 20, 2026
79bc6cb
revert(egress): leaves start in 1950 again, as the shared proxy had them
earakely-scale Nov 20, 2026
4677d85
fix(codex): the CLI stays on real time; only the model's commands fol…
earakely-scale Nov 20, 2026
2bb858f
test(codex): the local agent clock e2e runs a real Codex turn against…
earakely-scale Nov 20, 2026
ee083b0
Merge remote-tracking branch 'origin/main' into wloo/codex-clock-image
earakely-scale Nov 20, 2026
a689200
fix(codex): mcp-remote starts by Node itself on an armed clock; only …
earakely-scale Nov 20, 2026
4f0f0b9
test(codex): the local clock e2e expects every mcp-remote on real tim…
earakely-scale Nov 21, 2026
2ef1f9f
fix(codex): a restarted server kills the CLIs the crashed one left ru…
earakely-scale Nov 21, 2026
4bd82a8
Merge remote-tracking branch 'origin/main' into wloo/codex-clock-image
earakely-scale Nov 21, 2026
e07b556
fix(codex): the A2A server's exit ends the image's container, as on main
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
47 changes: 43 additions & 4 deletions src/agent_env/agents/agents/codex/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 Codex CLI's launcher and mcp-remote, checked against its published checksum; install.sh brings the same.
ARG NODE_VERSION=22.23.3
Expand All @@ -22,12 +36,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 codex_bridge.py codex_config.py codex_kit.py entrypoint.sh install.sh run.sh ./
# The CLI's cwd, /app, and its state, fixed so neither follows the uid: Modal runs the image as root.
# 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, /app, and its state, fixed so neither follows the uid.
RUN useradd --create-home --uid 10001 agent && mkdir -p /app /home/agent/.codex \
&& chown agent:agent /app /home/agent/.codex && 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 dynamically linked process, faking only the agent's
# (clock.conf): the model's commands, not the Codex CLI, a static binary. 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 CODEX_HOME=/home/agent/.codex
USER agent
WORKDIR /app
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"]
27 changes: 25 additions & 2 deletions src/agent_env/agents/agents/codex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,31 @@ Codex reads its settings from `$CODEX_HOME/config.toml`, which the agent writes:
| `triggers/v1` | SDK default |

The image is `python:3.11-slim` with Node, the CLIs, the agent and the Python packages `model-requirements.txt` pins for
the model's scripts, running as the `agent` user; Codex's state is in
`/home/agent/.codex` whatever the uid.
the model's scripts. It starts as root, runs the env clock's follower and egress proxy under supervisord (`start-agent`,
`root.conf`) and the A2A server as the `agent` user; started as another user, it runs the server alone. Either way the
server's exit ends the container: supervisord never starts it again, and its `agent-exit` listener shuts supervisord
down, while the follower and the proxy restart in place. Codex's state is in `/home/agent/.codex` whatever the uid.

A task's `sync_env_clock` with `agent_clock` has the agent follow the env's clock (`clock/v1` `sync_time`). agent-env's
libfaketime, preloaded for the `agent` user, then gives the model's commands the env's time. The Codex CLI is a static
binary the library doesn't reach, so the CLI and what it keeps (rollouts, `state.db`, thread ids) stay on real time,
and it checks the model endpoint's certificate on real time and reaches it directly. On an armed clock each CLI run
also gets:

- each MCP server's `mcp-remote` started by Node itself (`-c mcp_servers.<name>.command` and `.args`) with
`AGENTENV_REAL_TIME=1` in its environment, so it stays on real time: the expiry of its cookies and tokens and the age
of its leases are server times or real file times. Its `#!/usr/bin/env node` would start `env` first, which takes the
marker out of what it hands Node. On real time it checks certificates against the real date, so it reaches the
servers directly.
- `-c shell_environment_policy.set.<name>=...` with the egress proxy's variables (`agent_egress.egress_env`), so the
model's commands, which check certificates on the env's date, go out through the proxy, all but loopback, the hosts
`NO_PROXY` names and the model endpoint's and MCP servers' hosts served over plain HTTP alone.
- the env's date and zone before the prompt (`<environment_clock>`), as `date` shows it: Codex puts the host's real
date in its `<environment_context>`, and the note says so, and that a clock tool and `Date` in JavaScript the model
runs in code mode read real time too.

Unarmed, a CLI run is as before. So is one of an agent installed with `install/v1`, which runs as root, whose
commands libfaketime doesn't fake, whatever the clock of a computer it's installed in.

A `deploy_agent` `builtin_tools` selection turns the CLI's own tools off with `-c` overrides on the task's CLI alone;
config.toml stays as it is. `{"disable": "*"}` turns off every setting below, `{"only": [...]}` every one but those whose
Expand Down
1 change: 1 addition & 0 deletions src/agent_env/agents/agents/codex/a2a_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ def _record_event(event: dict) -> None:
task_id=cfg.task_id,
event_callback=_record_event,
max_turns=cfg.max_turns,
mcp_servers=request.mcp_servers,
config_overrides=[*codex_config.role_overrides(request.mcp_servers, cfg.role),
*codex_config.builtin_tools_overrides(cfg.builtin_tools),
*catalog],
Expand Down
57 changes: 55 additions & 2 deletions src/agent_env/agents/agents/codex/codex_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import logging
import os
import re
import shutil
import signal
import threading
import time
Expand All @@ -21,11 +22,15 @@
from dataclasses import dataclass, field
from datetime import datetime, timezone
from pathlib import Path
from typing import Any

from codex_config import MODEL_HEADERS_ENV, model_headers
from agent_egress import EGRESS_PROXY_ENV, clock_armed, egress_env
from codex_config import MODEL_HEADERS_ENV, model_headers, server_args

logger = logging.getLogger(__name__)
WORKSPACE_DIR = os.environ.get("CODEX_WORKSPACE_DIR", "/app")
# The one switch agent-env's libfaketime takes from a program's environment: that program stays on real time.
REAL_TIME_ENV = "AGENTENV_REAL_TIME"

# `todo_list` is excluded: it's a plan update, not a tool invocation.
_TOOL_ITEM_TYPES = {"command_execution", "mcp_tool_call", "file_change", "web_search"}
Expand Down Expand Up @@ -113,6 +118,48 @@ def cli_env(environ: Mapping[str, str], *, project_id: str | None = None,
return env


def clock_followed() -> bool:
"""Whether the model's commands follow an armed clock: only where the image's root.conf starts this server, as the
user agent-env's libfaketime fakes, with the egress proxy in its environment. An agent installed with install/v1
runs as root, whose commands stay on real time beside a computer's armed clock."""
return bool(os.environ.get(EGRESS_PROXY_ENV)) and clock_armed()


def _real_time_mcp_remote(name: str, info: Mapping[str, Any]) -> list[str]:
"""One MCP server's mcp-remote started by Node itself with the real-time marker: its `#!/usr/bin/env node` would
start env first, which libfaketime loads into, keeps on real time and takes the marker out of what it hands Node."""
node, script = shutil.which("node"), os.path.realpath(shutil.which("mcp-remote"))
return [f"mcp_servers.{name}.command={json.dumps(node)}",
f"mcp_servers.{name}.args={json.dumps([script, *server_args(info['url'], info.get('headers'))])}",
f'mcp_servers.{name}.env.{REAL_TIME_ENV}="1"']


def clock_overrides(environ: Mapping[str, str], mcp_servers: Mapping[str, Mapping[str, Any]], *,
armed: bool) -> list[str]:
"""The `-c` overrides an armed clock adds to a CLI run. The CLI, a static binary libfaketime can't reach, and
mcp-remote, whose cookie and token expiry and leases are server or real file times, stay on real time and go out
directly; the model's commands follow the env's clock, so they get the egress proxy (``egress_env``)."""
if not armed:
return []
urls = [environ.get("LITELLM_BASE_URL", ""), *(info["url"] for info in mcp_servers.values())]
return [*(override for name, info in mcp_servers.items() for override in _real_time_mcp_remote(name, info)),
*(f"shell_environment_policy.set.{name}={json.dumps(value)}"
for name, value in egress_env(environ, urls, armed=True).items())]


async def clock_note() -> str:
"""The env's date, put before a turn's prompt on an armed clock: the CLI renders the host's real date into its own
context, so the model is told the date `date` shows, which, run by this real-time server, follows the env's
clock."""
proc = await asyncio.create_subprocess_exec("date", "+%Y-%m-%d (%A)", stdout=asyncio.subprocess.PIPE)
shown, _ = await proc.communicate()
zone = os.environ.get("TZ") or "UTC"
return (f"<environment_clock>\nToday is {shown.decode().strip()} in {zone} on this task's clock, which `date` and "
"every command you run read. What the Codex CLI itself reports of the time, such as the current_date in "
"<environment_context>, a clock tool or Date in JavaScript you run in code mode, is the host's real time; "
"go by this task's clock.\n</environment_clock>\n\n")


@dataclass
class CodexResult:
response: str
Expand Down Expand Up @@ -780,7 +827,11 @@ async def _run_codex_once(
config_overrides: Sequence[str] = (),
max_turns: int | None = None,
prior_tool_calls: int = 0,
mcp_servers: Mapping[str, Mapping[str, Any]] | None = None,
) -> CodexResult:
armed = clock_followed()
if armed:
prompt = await clock_note() + prompt
# JSON Schema: codex's `--output-schema` flag takes a FILE PATH (unlike
# claude-code's inline-JSON `--json-schema`). Write the inner schema to a
# per-invocation temp file. Canonical agent-env envelope is
Expand Down Expand Up @@ -819,7 +870,7 @@ async def _run_codex_once(
]
if schema_file is not None:
cmd += ["--output-schema", str(schema_file)]
for override in config_overrides:
for override in [*config_overrides, *clock_overrides(os.environ, mcp_servers or {}, armed=armed)]:
cmd += ["-c", override]

inactivity_s = inactivity_timeout_s(effort)
Expand Down Expand Up @@ -961,6 +1012,7 @@ async def run_codex(
event_callback: Callable[[dict], None] | None = None,
config_overrides: Sequence[str] = (),
max_turns: int | None = None,
mcp_servers: Mapping[str, Mapping[str, Any]] | None = None,
) -> CodexResult:
"""Run one logical turn with bounded transient recovery.

Expand Down Expand Up @@ -1002,6 +1054,7 @@ async def run_codex(
event_callback=event_callback,
config_overrides=config_overrides,
max_turns=max_turns,
mcp_servers=mcp_servers,
prior_tool_calls=tool_call_count,
)
failure = _resumable_api_failure(result)
Expand Down
15 changes: 10 additions & 5 deletions src/agent_env/agents/agents/codex/codex_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,12 @@ def _server_entry(url: str, headers: dict[str, str] | None = None) -> dict[str,
concurrent turns of different roles share it.
"""
registered = ""
args: list[str] = [url, "--allow-http"]
for k, v in (headers or {}).items():
if k.lower() == ROLE_HEADER.lower():
registered = v
else:
args += ["--header", f"{k}: {v}"]
args += ["--header", f"{ROLE_HEADER}: ${{{_ROLE_VARIABLE}}}"]
return {
"command": "mcp-remote",
"args": args,
"args": server_args(url, headers),
"env": {_ROLE_VARIABLE: registered},
"env_vars": list(_TRUST_ENV),
"startup_timeout_sec": 60,
Expand All @@ -278,6 +274,15 @@ def _server_entry(url: str, headers: dict[str, str] | None = None) -> dict[str,
}


def server_args(url: str, headers: Mapping[str, str] | None = None) -> list[str]:
"""mcp-remote's arguments for one server, as its config table gives them."""
args = [url, "--allow-http"]
for k, v in (headers or {}).items():
if k.lower() != ROLE_HEADER.lower():
args += ["--header", f"{k}: {v}"]
return [*args, "--header", f"{ROLE_HEADER}: ${{{_ROLE_VARIABLE}}}"]


async def write_mcp_servers(servers: Mapping[str, Mapping[str, Any]]) -> None:
"""Write every registered MCP server's entry, before each turn."""
async with _write_lock:
Expand Down
4 changes: 2 additions & 2 deletions src/agent_env/agents/agents/codex/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ START_TIMEOUT_S=120
STOP_TIMEOUT_S=10
dockerfile_arg() { sed -n "s/^ARG $1=//p" "$here/Dockerfile"; }
NODE_VERSION=$(dockerfile_arg NODE_VERSION)
AGENT_FILES="a2a_server.py codex_bridge.py codex_config.py codex_kit.py requirements.txt run.sh"
AGENT_FILES="a2a_server.py codex_bridge.py codex_config.py codex_kit.py requirements.txt run.sh agent_clock/agent_egress.py clock/clockpage.py"

# put SRC DEST replaces DEST by a rename, so a binary an earlier install's agent still runs can be replaced; put_dir SRC
# DEST copies a folder to DEST, which isn't there.
Expand Down Expand Up @@ -144,7 +144,7 @@ put "$stage/agent.env" "$root/agent.env"
put "$here/package.json" "$root/npm/package.json"
put "$here/package-lock.json" "$root/npm/package-lock.json"
for file in $AGENT_FILES; do
put "$here/$file" "$root/app/$file"
put "$here/$file" "$root/app/${file##*/}"
done
on "chmod 0600 $r/agent.env && chmod 0755 $r/bin/uv $r/bin/codex $r/bin/mcp-remote $r/app/run.sh"

Expand Down
79 changes: 79 additions & 0 deletions src/agent_env/agents/agents/codex/root.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
; Root's supervisord (start-agent): the clock follower and the egress proxy, each as its own user, on real time, and
; the A2A server as the agent's user. The server starts with the real-time marker, which agent-env's libfaketime takes
; out of its environment, so the server's own records keep real timestamps and the model's commands, which it starts
; through the CLI, read the env's time; the Codex CLI itself is a static binary the library doesn't reach, so it stays
; on real time. Its socket and logs are root's alone, so the agent's user can neither stop nor restart any of them. The
; follower follows nothing until the server writes its config, which sync_env_clock has it do, then picks it up within
; a quarter second.
[supervisord]
nodaemon=true
user=root
logfile=/var/log/agentenv-root/supervisord.log
pidfile=/run/agentenv-root/supervisord.pid
childlogdir=/var/log/agentenv-root

[unix_http_server]
file=/run/agentenv-root/supervisor.sock
chmod=0700

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///run/agentenv-root/supervisor.sock

[program:clock]
command=/usr/local/bin/python3 -I /usr/local/lib/agentenv-clock/clock-follower
user=agentenv-clock
directory=/
priority=3
autorestart=true
startsecs=1
startretries=1000
redirect_stderr=true
stdout_logfile=/var/log/agentenv-root/clock.log
environment=HOME="/nonexistent",USER="agentenv-clock",LOGNAME="agentenv-clock"

[program:egress]
command=/usr/local/lib/agentenv-egress/egress serve
user=agentenv-egress
directory=/
priority=3
autorestart=true
startsecs=1
startretries=1000
redirect_stderr=true
stdout_logfile=/var/log/agentenv-root/egress.log
environment=HOME="/nonexistent",USER="agentenv-egress",LOGNAME="agentenv-egress",AGENTENV_EGRESS_PRIVATE="allow"

; uvicorn itself, not entrypoint.sh: the marker holds for the process it's given to alone, and a shell that execs
; uvicorn would hand uvicorn an environment without it. It is never started again (agent-exit below).
[program:agent]
command=/usr/local/bin/python3 -m uvicorn a2a_server:app --host 0.0.0.0 --port %(ENV_A2A_PORT)s --timeout-graceful-shutdown 5
user=agent
directory=/app
priority=10
autorestart=false
startretries=0
stopasgroup=true
killasgroup=true
stopwaitsecs=30
redirect_stderr=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
environment=HOME="/home/agent",USER="agent",LOGNAME="agent",AGENTENV_REAL_TIME="1",AGENTENV_EGRESS_PROXY="http://127.0.0.1:3128",NODE_EXTRA_CA_CERTS="/etc/agentenv/ca.pem",SSL_CERT_FILE="/etc/agentenv/ca-bundle.pem",REQUESTS_CA_BUNDLE="/etc/agentenv/ca-bundle.pem"
Comment thread
williamloo-scale marked this conversation as resolved.
Resolved

; The A2A server's exit, for any reason, ends the container, as it did when the server was the image's only process: a
; server started again would have lost the task's MCP servers, peers and running tasks, and the CLIs the dead one
; started would go on in the workspace beside it. This listener has root's supervisord, its parent, shut down when the
; server exits or can't start; the follower and the proxy restart in place.
[eventlistener:agent-exit]
command=/usr/local/bin/python3 -I -c "import os, signal, sys
fields = lambda line: dict(field.split(b':', 1) for field in line.split())
stdin, stdout = sys.stdin.buffer, sys.stdout.buffer
while True: stdout.write(b'READY\n'); stdout.flush(); header = fields(stdin.readline()); event = fields(stdin.read(int(header[b'len']))); event[b'processname'] == b'agent' and os.kill(os.getppid(), signal.SIGTERM); stdout.write(b'RESULT 2\nOK'); stdout.flush()"
events=PROCESS_STATE_EXITED,PROCESS_STATE_FATAL
directory=/
autorestart=true
stdout_logfile=NONE
stderr_logfile=/var/log/agentenv-root/agent-exit.log
5 changes: 5 additions & 0 deletions src/agent_env/agents/agents/codex/shared_sources.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# What this image's build context takes from agent-env's own sources, at the name its Dockerfile copies it from: one
# copy of each, shared with the other images that take it (utils/docker/context.py). Paths are under src/agent_env.
clock = "utils/faketime_clock"
egress = "utils/egress_proxy"
agent_clock = "utils/agent_clock"
Loading
Loading