Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 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
82d8d17
feat(agents): the Hermes 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
7b67569
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
03df445
refactor(agents): the image takes the clock and egress proxy from uti…
williamloo-scale Nov 18, 2026
40da072
Merge #726
williamloo-scale Nov 18, 2026
aed27ee
fix(agents): a private HTTPS model endpoint is reached directly on an…
williamloo-scale Nov 18, 2026
b7d1860
fix(agents): a private HTTPS model endpoint is reached directly on an…
williamloo-scale Nov 18, 2026
b9a7753
Merge #726
williamloo-scale Nov 18, 2026
e55c83e
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
5248f79
fix(agents): the model host's lookup is bounded and kept, as #726's is
williamloo-scale Nov 18, 2026
934dff4
Merge #726
williamloo-scale Nov 18, 2026
46809d1
Merge main (#726 merged)
williamloo-scale Nov 18, 2026
63e2342
refactor(agents): follow the merged Claude Code image (#726): the pro…
williamloo-scale Nov 18, 2026
b2dc558
fix(agents): keep a provider's CA bundle trusted, and send HTTPS MCP …
williamloo-scale Nov 18, 2026
53d1a13
Merge main: the control token (#780, #784)
williamloo-scale Nov 19, 2026
a85fd68
Merge remote-tracking branch 'origin/main' into wloo/hermes-clock-image
williamloo-scale Nov 19, 2026
a969ace
Merge remote-tracking branch 'origin/main' into wloo/hermes-clock-image
williamloo-scale Nov 19, 2026
11e1ddd
refactor(hermes): take the shared egress rule (#818)
williamloo-scale Nov 19, 2026
6961dff
Merge remote-tracking branch 'origin/main' into wloo/hermes-clock-image
williamloo-scale Nov 20, 2026
e8ef230
Merge remote-tracking branch 'origin/main' into wloo/hermes-clock-image
earakely-scale Nov 20, 2026
6090877
fix(agents): Hermes keeps real time on an armed env clock while the c…
earakely-scale Nov 20, 2026
5b27d11
test(agents): Hermes' image carries every module its server imports, …
earakely-scale Nov 20, 2026
7640b76
test(agents): the agent clock e2e runs one Hermes turn against an Ope…
earakely-scale Nov 20, 2026
08a71c7
docs(agents): Hermes on the env's clock
earakely-scale Nov 20, 2026
df4af27
Merge remote-tracking branch 'origin/main' into wloo/hermes-clock-image
earakely-scale Nov 20, 2026
612facd
fix(agents): Hermes' clock reads only its installer's launcher, stamp…
earakely-scale Nov 20, 2026
6754355
fix(agents): a restarted Hermes server kills the turns the dead one left
earakely-scale Nov 21, 2026
b3241e2
Merge remote-tracking branch 'origin/main' into wloo/hermes-clock-image
earakely-scale Nov 21, 2026
6a9a760
fix(agents): a Hermes server that exits stops its container, as befor…
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
6 changes: 5 additions & 1 deletion src/agent_env/agents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ 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 Hermes' too, goes out the same
way.
- **Hermes' harness stays on real time.** In the Hermes image, Hermes itself keeps real time while the commands it runs
follow the env's clock, and it shows the model the env's date: its own records, leases and cleanups are set against
real file times and elapsed time. `agents/hermes/README.md` says how.

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

Expand Down
50 changes: 45 additions & 5 deletions src/agent_env/agents/agents/hermes/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
# Hermes Agent at a pinned release, installed by its own installer, which the image checks against its checksum. The
# installer brings Hermes' runtime (its Python, Node and ripgrep among them) under its home, /data/.hermes; git and xz
Expand All @@ -23,12 +37,38 @@ WORKDIR /opt/agent
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY a2a_server.py hermes_bridge.py hermes_kit.py entrypoint.sh ./
# 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 ./
COPY agentenv_plugin ./agentenv_plugin
RUN chmod 0755 entrypoint.sh
# Each context's Hermes profile is under /data/.hermes, Hermes' home, whatever the uid: Modal runs the image as root.
# A turn on an armed clock runs the command Hermes' launcher runs, without its shell (hermes_bridge.cli_command): the
# build fails, rather than such a turn, when the pinned release's launcher isn't one the bridge reads.
RUN chmod 0755 entrypoint.sh && python3 -c 'import hermes_bridge; hermes_bridge.launcher_command()'
# 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
# Each context's Hermes profile is under /data/.hermes, Hermes' home, whatever the uid.
ENV A2A_PORT=8000 PYTHONPATH=/opt/agent HOME=/data HERMES_ROOT=/data/.hermes
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"]
49 changes: 46 additions & 3 deletions src/agent_env/agents/agents/hermes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,49 @@ A turn's usage counts every model call the turn made: its main calls and its aux
compression), as Hermes' usage file reports them, and a `delegate_task` child's, from their `post_api_request` events,
which the file leaves out. A turn killed before it wrote the file keeps the calls its events counted, marked as a lower
bound. Hermes' estimated cost is kept only where it priced the calls. The profile turns Hermes' background review off:
its fork outlives the turn's process, which kills it before it reports what the proxy billed. The image is `python:3.11-slim` with Hermes, `pdftoppm` and the agent, running
as the `agent` user. Hermes' runtime (its own Python, Node and ripgrep) and the profiles are under `/data/.hermes`,
whatever the uid. It has no `install/v1`.
its fork outlives the turn's process, which kills it before it reports what the proxy billed. The image is
`python:3.11-slim` with Hermes, `pdftoppm` and the agent. It starts as root, which runs the env clock's follower and
egress proxy under supervisord (`start-agent`, `root.conf`), and the A2A server and Hermes run as the `agent` user, on
Modal too; started as another user, it runs the A2A server alone as that user. A server that exits, for any reason,
stops supervisord and the container with it, as when the server was the container's process, so the run fails at
once; the follower and the proxy restart in place. Hermes' runtime (its own Python, Node and ripgrep) and the profiles
are under `/data/.hermes`, whatever the uid. It has no `install/v1`.

## The env's clock

The image follows a task env's clock as the agents README describes (`../../README.md`), with one difference: Hermes
itself stays on real time and the commands it runs follow the env's clock.

- **Off by default.** Without `agent_clock` on `sync_env_clock`, a turn runs as it would without the clock:
`hermes agentenv turn` with the same flags, the server's environment and a profile config with nothing of the
clock's, on real time, with no proxy variables. The server's environment is supervisord's, which adds its
`SUPERVISOR_*` variables, `USER`, `LOGNAME` and `AGENTENV_EGRESS_PROXY`, and points TLS trust at agent-env's bundles
(`root.conf`).
- **Opted in.** While the agent follows an armed clock, the bridge starts each turn with the command Hermes' launcher
runs, Hermes' own Python, rather than the launcher, a shell script, so the real-time marker reaches Hermes and not the
shell, and passes `--env-clock` (`hermes_bridge.cli_command`). Every command Hermes starts, the model's `date`,
shell and `execute_code` scripts among them, reads the env's time, and goes out through the egress proxy with Hermes,
as the shared rule (`agent_egress.egress_env`) has it for the model endpoint and every MCP server. `execute_code`
hands its scripts only a few variables of its own choosing, so the turn's config names the proxy's, its CA's and the
task's zone (`TZ`) for it (`terminal.env_passthrough`).
- **Why Hermes stays on real time.** Hermes compares its clock with times it didn't make on that clock in many places:
its scratch folder (`TMPDIR`), pruned at each start of entries idle for 24 hours and the processes running in them;
its spill files and large tool results, deleted past 7 days and `sessions.retention_days`; its checkpoints, past
their retention; the turn's lease, which stops the turn when the clock jumps past the lease's deadline or runs a few
times fast; and the stream stall check, which drops a model stream the clock jumps past. Each runs in Hermes' own
process against real file times or real elapsed time, so on real time a conversation keeps its history and files at
any date, jump or rate the env's clock takes.
- **The date the model sees.** With `--env-clock`, the plugin has Hermes read the date it shows the model, its
`Conversation started` line (and `Today's date` after a rebuild) and the date its compaction summary carries, from a
`date` it runs, which follows the env's clock; the session ids it mints, a compaction's new one included, whose stamp
gives the start date, are stamped from it too. Hermes writes that line when a session starts and keeps it, as it does
on any clock, so a session started before the clock was armed keeps the real date it started on until Hermes rebuilds
its prompt. Other times Hermes reports itself, such as the dates `session_search` lists, are real, as files'
modification times are.
- **A clock armed mid-turn.** The command and environment are chosen as a turn starts. A turn already running when the
clock is armed was started as an unarmed turn is, through the launcher with no marker, so its Hermes follows the
env's clock from then on, without the proxy. Its own model and MCP calls then check certificates on the env's
clock: Hermes' Python carries its own OpenSSL, which agent-env's TLS shim doesn't reach, so at a date outside the
endpoint's certificate they fail (`APIConnectionError: Connection error.`), and its turn lease or stall check may
stop it too (`Session turn lease ...`). The turn ends with that error, the conversation keeps its history, and the
next turn is armed.
47 changes: 47 additions & 0 deletions src/agent_env/agents/agents/hermes/agentenv_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@
gateway: so the turn ends with this process, and a timeout or cancel that kills it stops the turn. Hermes' plugin
hooks write the turn's events, each as one JSON line, to the pipe AGENTENV_EVENTS_FD names, as they happen; the bridge
reads them as the turn's trajectory. Each event is a hook's name as ``type`` and the hook's fields the bridge keeps.

On an armed env clock the bridge runs this process on real time and passes ``--env-clock``: everything the process
starts follows the env's clock, and the dates Hermes shows the model are read from one of those (``_EnvDatetime``).
"""

from __future__ import annotations

import json
import os
import subprocess
import sys
import threading
import time
import types
from datetime import datetime

import hermes_state_ids
import hermes_time

_EVENTS_FD = "AGENTENV_EVENTS_FD"
_write_lock = threading.Lock()
# The Hermes release whose names --env-clock replaces (hermes_time.datetime, hermes_state_ids.new_session_id and the
# copies its modules bind by import); a test holds it to the Dockerfile's HERMES_COMMIT, so a bump checks them again.
ENV_CLOCK_HERMES_COMMIT = "bf0203a794a07aac3ff764972ab9087baa4e4f4e"
# The env's time, in whole seconds since the epoch, as a command the model runs reads it.
ENV_TIME_COMMAND = ("date", "+%s")

# Each hook this plugin records, and the fields of its payload an event keeps.
_HOOKS = {
Expand All @@ -32,6 +47,34 @@
}


class _EnvDatetime(datetime):
"""``datetime`` whose ``now`` is the env's time, read from a command this process starts: this process stays on
real time, and what it starts follows the env's clock."""

@classmethod
def now(cls, tz=None) -> datetime:
seconds = int(subprocess.run(ENV_TIME_COMMAND, capture_output=True, text=True, check=True).stdout)
return datetime.fromtimestamp(seconds, tz)


def _show_the_envs_date() -> None:
"""Hermes' dates on the env's clock: the date it shows (``hermes_time.now``) and the session ids it mints, whose
stamp its start date is read from: ``new_session_id`` and every copy a loaded module bound by import, as
``agent.agent_init`` and ``agent.conversation_compression`` (a compaction's new session) do. A module loaded later
binds the replacement, and none is imported here, so Hermes loads its modules in its own order."""
hermes_time.datetime = _EnvDatetime
minted = hermes_state_ids.new_session_id

def new_session_id(now: datetime | None = None, **kwargs) -> str:
return minted(_EnvDatetime.now(), **kwargs)

for module in list(sys.modules.values()):
if isinstance(module, types.ModuleType):
for name, value in list(vars(module).items()):
if value is minted:
setattr(module, name, new_session_id)


def _write(event: dict) -> None:
descriptor = os.environ.get(_EVENTS_FD)
if not descriptor:
Expand All @@ -58,12 +101,16 @@ def _setup(parser) -> None:
turn.add_argument("--resume", help="The session the turn continues")
turn.add_argument("--reasoning", help="The reasoning effort")
turn.add_argument("--usage-file", help="Where to write the turn's usage report")
turn.add_argument("--env-clock", action="store_true",
help="This process is on real time while the env's clock is armed: show the model the env's date")


def _handle(args) -> None:
# The one-shot runner: the turn in this process, then Hermes' own cleanup and a hard exit.
from hermes_cli.main import _run_and_exit_oneshot

if args.env_clock:
_show_the_envs_date()
with open(args.prompt_file, encoding="utf-8") as prompt:
message = prompt.read()
_run_and_exit_oneshot(message, model=args.model, provider=args.provider, resume=args.resume,
Expand Down
Loading
Loading