Skip to content

[FD-5916] feat(agents): the Hermes image follows the env's clock - #768

Closed
williamloo-scale wants to merge 62 commits into
mainfrom
wloo/hermes-clock-image
Closed

williamloo-scale wants to merge 62 commits into
mainfrom
wloo/hermes-clock-image

Conversation

@williamloo-scale

@williamloo-scale williamloo-scale commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What and why

The Hermes image can follow a task env's clock, opt-in, as Claude Code and OpenCode do since #818 and #832. A task that
sets agent_clock: true on sync_env_clock (require_agent_clock implies it) gets Hermes with every command it runs on
the env's time and the env's date in its prompt. Without it, a turn runs as on main (the image-level differences are
listed below).

Unlike Claude Code, Hermes itself stays on real time and only the commands it runs follow the env's clock. Hermes
compares its own clock with real file times or real elapsed time in many places inside its own process, and several of
them have no setting to turn them off. On a clock ahead of real time, those places delete a conversation's files or end
its turns (list under R4). On real time they behave as they always do. Hermes still shows the model the env's date.

Clock off (default)

What's the same for the model and for Hermes. A turn is hermes agentenv turn with the same flags, started through
Hermes' launcher. It gets the server's environment with only HERMES_HOME and the event pipe added, and a profile
config.yaml with nothing of the clock in it. It runs on real time with no proxy variables.
test_unarmed_the_bridge_starts_hermes_with_the_command_and_environment_it_always_has pins the command, the environment
and the whole config dict. test_the_clock_adds_only_execute_codes_passthrough_to_the_profile_config pins that an armed
turn's config differs only by terminal.env_passthrough.

What differs at the image level, even with the clock off:

  • Root start. The container starts as root: start-agent, then supervisord (root.conf). Supervisord runs the
    clock follower and the egress proxy, each as its own system user, and the A2A server, and so Hermes, as agent
    (uid 10001). Started as any other user, the image runs entrypoint.sh alone as that user, as before.
  • uid on Modal. Modal runs the image as root, so on main the server and Hermes ran as root there. Now they run as
    uid 10001 there too. /data and /app belong to agent, as before.
  • The server's environment, which Hermes and the model's commands inherit, has these variables that main's
    doesn't:
    • supervisord's SUPERVISOR_ENABLED, SUPERVISOR_PROCESS_NAME, SUPERVISOR_GROUP_NAME and SUPERVISOR_SERVER_URL.
      The socket it names is root's, mode 0700, so agent can't use it.
    • USER=agent, LOGNAME=agent and AGENTENV_EGRESS_PROXY=http://127.0.0.1:3128.
    • SSL_CERT_FILE, REQUESTS_CA_BUNDLE and NODE_EXTRA_CA_CERTS, pointing at agent-env's bundles: the system roots,
      the egress proxy's CA and any bundle the provider set (start-agent merges it in, for Sail for one).
    • HOME=/data, as the image already set it. AGENTENV_REAL_TIME=1 is set on the server, but libfaketime takes it out
      of the server's environment, so nothing the server starts sees it.
  • The egress proxy's boot runs on every start, and a failed boot stops the container (exit 2, with its log on
    stderr). The boot mints a CA, its key the egress user's alone. It adds the CA to the system trust store
    (update-ca-certificates), to agent-env's bundles and to every certifi bundle under /usr/lib/python3,
    /usr/local/lib and /opt. A failed certifi bundle is reported as a warning, not a failure. Start-up takes longer
    by the boot's time: on the VM, docker run to the agent card served took 2.6 s against main's 0.7 s (three
    runs each). The image is 735.5 MB against main's 730.9 MB.
  • libfaketime and the TLS shim are preloaded (/etc/ld.so.preload) into every process. They fake only agent's
    processes, and while the clock is unarmed the clock page holds real time.
  • A server that exits stops the container, as on main. On main the server was the container's process, so a
    server that died took the container down and the run failed. Under supervisord it would be restarted in place,
    without its turns, its registrations (the env's MCP servers, the config, peers) or the A2A task it was running, so
    later turns would run without the env's tools while the dead server's turn went on in a session of its own. So
    supervisord doesn't restart it (autorestart=false, startretries=0, so one that dies as it starts is FATAL at
    once), and an event listener in root.conf ([eventlistener:agent-exit], a few lines of Python speaking
    supervisord's listener protocol) stops supervisord when the server is EXITED or FATAL, whatever the reason.
    Supervisord then stops the follower and the proxy and exits, and so does the container. Everything in it goes too,
    so the turn the server was running writes nothing more.
    • The follower and the proxy keep autorestart=true. Killed with -9, each restarts in place and the container stays
      up.
    • A normal stop is unchanged. Supervisord stops the server, which is then STOPPED, not EXITED, so the listener lets
      it pass, and the container exits 0.
    • Exit status: a crashed server's container exits 0, not with the server's status. Supervisord 4.2.5 exits 0
      after any shutdown and has no setting to change that. On main, kill -9 gave 137. The cause is in the
      container's output, in supervisord's log: exited: agent (terminated by SIGKILL; not expected), then
      received SIGTERM indicating exit request.
    • An earlier commit of this PR had the server kill, as it started, the turns a dead server left
      (kill_orphaned_clis). That's gone: with no restart, nothing produces that case.

Opted in

  • Hermes runs on real time. The bridge starts each turn with the command Hermes' launcher runs: Hermes' own Python
    with -I -c <bootstrap>, plus AGENTENV_REAL_TIME=1 (hermes_bridge.cli_command). It skips the launcher because the
    launcher is a #!/bin/sh script, and sh would take the marker in Hermes' place. libfaketime takes the marker out
    of Hermes' environment, so everything Hermes starts follows the env's clock: the model's shell commands,
    execute_code scripts, git.

    • launcher_command reads only the installer's shape, exec <python> -I -c <bootstrap> "$@". It refuses any other
      exec, such as Hermes' forwarder to another launcher, exec env ..., or a missing -I, because sh or env
      would take the marker there.
    • The Dockerfile reads the pinned release's launcher at build, so a Hermes bump that changes its shape fails the
      build rather than a turn.
    • Hermes doesn't re-exec on this path: prepare_launch returns early because the image removes /opt/hermes/.git,
      and subagents run as threads.
  • What the model sees about "now" (R2): its commands' date, the dates its commands write into files, git commit
    dates, execute_code's time and zone, and get_time (from the gateway) are all the env's. With --env-clock, the
    plugin has Hermes read the dates it shows from a date child process:

    • the Conversation started: line, and Today's date after a rebuild;
    • the date in its compaction summary;
    • the stamp of every session id it mints, a compaction's child included. The date line reads its start date from
      the stamp, the lineage root's first.

    It replaces two Hermes names for this. One is hermes_time.datetime, which hermes_time.now() reads. The other is
    hermes_state_ids.new_session_id, along with every copy a module that has already loaded bound by import
    (agent.agent_init's new_session_id and agent.conversation_compression's mint_session_id at the pinned
    release). A module that loads later binds the replacement. date +%s is used because %N next to a negative %s is
    a second off before 1970. A test holds the release these names were checked against to the Dockerfile's
    HERMES_COMMIT.

  • What stays real:

    • Hermes' own records: the session store's started_at and the trajectory events' timestamps;
    • files' modification times (libfaketime doesn't fake stat);
    • dates Hermes reports itself, such as session_search listings.
  • Network (R3): the shared rule, agent_egress.egress_env(environ, [model_url, *mcp_urls], armed=...), is applied
    to Hermes' environment. Every TLS host goes through the egress proxy, Hermes' own model and MCP calls included. The
    proxy checks certificates on real time, so it covers an HTTPS MCP server on *.modal.host whose certificate starts
    after the env's date, and a clock behind real time. Loopback, the hosts the deploy's NO_PROXY names and hosts
    reached only over plain HTTP go direct.
    Hermes trusts the proxy's CA through SSL_CERT_FILE, and its terminal's commands inherit the same variables.

    • execute_code gives its scripts an allowlisted environment, and sets TZ only from Hermes' own timezone
      setting. So on an armed clock only, the turn's config names the proxy's variables, the CA's and TZ in
      terminal.env_passthrough. Scripts then reach TLS hosts through the proxy and read the time in the task's zone,
      as the terminal does.

Why Hermes stays on real time (R4)

Each of these runs inside Hermes' process against real file times or real elapsed time (Hermes at bf0203a):

  • hermes_constants.py:1011 and hermes_constants_scratch.py:373: at every start, prune scratch (TMPDIR) entries
    idle for 24 h and kill the processes rooted in them. Ahead of real time, this deletes earlier turns' temp files and
    execute_code staging folders.
  • tools/environments/base_output.py:187: terminal spill files, 7 days.
  • tools/environments/local.py:70: the terminal's temp cache.
  • tools/tool_result_storage.py:139/223: large tool-result spillover, by sessions.retention_days. With the clock
    more than 90 days ahead, a result is pruned right after it's written.
  • tools/checkpoint_maintenance.py:209: checkpoint retention.
  • tools/process_registry_results.py:32: background-process results, 7 days.
  • agent/turn_facade_lease.py:219: the turn lease stops a turn when the clock jumps more than about 240 s or runs
    about 5x fast.
  • agent/chat_completion_stream_monitor.py:135: the stall check drops a stream that a forward jump lands in.

Running Hermes on real time fixes all of them at once. The call-site tests pin it: a mutation that drops the marker,
the direct launch or --env-clock fails them.

Shared code (R5)

utils/egress_proxy, utils/faketime_clock, utils/agent_clock, tst/util/fake_openai.py, and the Claude Code and
OpenCode folders are untouched. The image takes the first three through shared_sources.toml.

Workspace snapshot (R7)

Hermes has no workspace changelog. The context snapshot archives the profile with Python's tarfile in the server,
on real time. The workspace's tar is the server's child, so it follows the env's clock when armed. It writes a full
archive, so its contents don't depend on the clock. A clock behind the files' real modification times only adds GNU
tar's "time stamp in the future" warnings on extract. C6 checks the exit status.

Known limits

  • A clock armed mid-turn. 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, because Hermes' Python (python-build-standalone)
    carries its own OpenSSL, which agent-env's TLS shim doesn't reach. At a date outside the endpoint's certificate they
    fail with APIConnectionError: Connection error. On the VM (C5), a clock armed at 2029-08-01 12 s into a turn ended
    that turn with this error after Hermes' 3 retries. Its turn lease or stall check may stop it too, with
    Session turn lease ... or a dropped stream. The conversation keeps its history, and the next turn is armed. Starting
    unarmed turns on real time too would keep Hermes itself on real time, but it would change the unarmed command and
    still leave that turn's commands without the proxy.
  • A session started before the clock was armed. Hermes writes its date line when a session starts and reuses it,
    as it does on any clock. Such a session keeps its real start date until Hermes rebuilds its prompt.
  • A Hermes bump must re-check the two replaced names (the commit pin test forces that). The plugin imports
    hermes_time and hermes_state_ids at module top, on unarmed turns too, so a release that renames either would fail
    every turn loudly, not only armed ones, until the plugin follows.

Tests

  • Unit, tst/unit/agents/hermes/test_env_clock.py and test_image_contract.py (35 cases in 21 tests):
    • the unarmed command, environment and whole profile config, and that the clock adds only the passthrough;
    • the armed call site, captured, and as a real process through a launcher written in the installer's shape;
    • launcher parsing, and refusal of six other shapes (a Python script, -m, Hermes' forwarder, exec env, no -I,
      an extra argument);
    • execute_code's passthrough with and without a task zone;
    • the plugin's date switch at 2031, +1000 years and 1950, with no Hermes module loaded and with agent.agent_init and
      agent.conversation_compression loaded under their own names for new_session_id;
    • the no-flag case, the whole-seconds command, and the Hermes-commit pin;
    • start-agent's provider-bundle merge;
    • the image carries every module the server imports, and its build reads the launcher.
  • Mutations: 13 mutations of the wiring, each caught by the tests above (launcher check loosened, -I unchecked,
    bootstrap dropped, TZ not passed, TZ always named, passthrough unarmed, session-id switch narrowed to
    agent_init, switch by name only, date switch dropped, switch without the flag, unarmed via the launcher's command,
    armed without --env-clock, armed without the marker).
  • Crash behaviour, test_image_contract.py:
    • root.conf read as supervisord reads it: the server has autorestart=false and startretries=0, the follower
      and the proxy autorestart=true, and the listener takes PROCESS_STATE_EXITED and PROCESS_STATE_FATAL and runs
      as root.
    • The listener's own command, run as supervisord runs it under a stand-in parent. It answers each event with
      RESULT 2 OK and lets the follower's and the proxy's exits pass. It sends its parent SIGTERM when the server is
      EXITED, or FATAL after it dies while starting.
    • 7 mutations are caught: a filter on another name, no filter, no flush, the server restarted, start retries left at
      their default, no FATAL, and the follower not restarted.
    • On macOS, the listener was also run under a real supervisord 4.2.5 with stand-in programs:
      • the server killed with -9: supervisord exited 2.2 s later;
      • the follower or the proxy killed: they restarted and supervisord stayed up;
      • the server exiting 0, or dying at start: supervisord exited too;
      • SIGTERM to supervisord: a clean stop.
  • Unit results: on macOS, 1167 passed with 45 skipped in tst/unit/agents. On Linux (the VM), 101 passed in
    tst/unit/agents/hermes and test_agent_clock_images.py. ruff check . is clean.
  • Image build on the VM, with the launcher check: passes, in 2m54s.
  • Integration: test_agent_env_clock_local.py passes all three rows on the VM: Hermes over this image, and
    Claude Code and OpenCode over main's published images. The Hermes row gave the date line
    Tuesday, March 04, 2031, terminal date 2031-03-04T05:06:07Z and session id 20310304_050607_…, and the session
    store's started_at was real now.
  • Clock behaviour, stand-in model (fresh container per scenario, four ~40 s turns each). Every scenario passes:
    unarmed, real, +75 d, +200 y, 1950, jumps between turns (real, +75 d, +200 y, 1950), and +1000 days, rate 10 and
    1950 during turns. Each one kept turns 1-3 in turn 4's call and read turn 1's scratch file back in turn 4. The
    terminal dates and the date line were the env's, and armed turns' Hermes had AGENTENV_REAL_TIME=0 and the proxy.
    main's image passes the unarmed scenario. +1000 y is past the clock page's range (int64 ns: 2262-04-11) for every
    agent, so +200 y stands in. Control, the PR's earlier head 6961dff10 (Hermes itself on the env's clock): at
    +75 d, turn 1's scratch file was pruned by turn 4, and the 1950 move during a turn failed it with
    system time before Unix epoch.
  • Real model (LiteLLM over HTTPS, claude-haiku-4-5; local Docker unless noted). All pass:
    • E1, opt-out: main and this branch gave the same answers (shell date real, get_time 2027, date line real). There
      was no marker or proxy in Hermes' environment and no follower. main ran its published image by digest; this
      branch ran its own build.
    • E2, 2027-02-01 in America/Chicago: date Mon Feb 1 06:00:13 CST 2027, the git commit
      2027-02-01T06:00:15-06:00, the file's contents, and execute_code 2027-02-01 06:00:17 CST and HTTPS 200.
      get_time gave 2027-02-01 and the date line Monday, February 01, 2027 (CST, UTC-06:00).
    • E3: env on Modal, HTTPS MCP on *.modal.host at 2026-10-27 (before the certificate), 2025-06-01 and 1950. The
      MCP calls, terminal curl and execute_code HTTPS all worked. The proxy re-signed *.modal.host and the
      endpoint (decision: outside).
    • E6: openai/gpt-5.4-mini on E2's prompt gave the same results.
    • E7: four 35 s turns at +73 d kept every label. A write while the agent was paused got a 504, then caught up. An
      agent deployed later followed. require_agent_clock passes here and fails clearly against main's Hermes
      (not_advertised).
    • The agent itself on Modal: passes.
  • Chaos. All pass, with one finding fixed:
    • rate 3600, freeze, forward jump, follower killed with -9, backward re-arm to 2025, reset_env and clear, across
      five turns of one conversation;
    • the model endpoint blocked for 50 s during a turn, on main and this branch;
    • the egress proxy restarted during a turn;
    • SIGTERM to the run during a turn, on both: torn down, nothing left;
    • four opted-in runs at once (2027, 2226, 1950, 2025);
    • C5, armed during a turn: the turn ended APIConnectionError (see Known limits), the next turn was armed and the
      history kept;
    • C8, server killed: re-run after the change (below, under Crash behaviour on the VM).
  • Crash behaviour on the VM, after merging main, with this branch's image rebuilt, a stand-in model and local
    Docker:
    • (a) Server killed mid-turn, kill -9 10 s into a turn that sleeps 45 s.
      • Run directly: the container exited 2.2 s after the kill, with status 0 and supervisord's two lines above. 45 s
        after the kill, the file the turn writes once its sleep ends didn't exist, so nothing kept writing.
      • main's image (docker kill, since its server is PID 1): exit 137 at once, and no file either.
      • Through agent-env run, with the clock armed and opted in:
        • The container exited 2.25 s after the kill, with status 0.
        • prompt_agent failed the step 59.7 s after the kill with AgentUnreachableError: ... 5 polls in a row over 60s got no reply. The same task on main failed 59.5 s after the kill, with the same error.
        • The context's next turn failed on both, after the agent-config POST's 10 retries (104 s on both).
        • The whole run took 207 s, against main's 203 s. Before this change, the step polled Task not found until
          its 300 s timeout, and the next turn ran in a fresh Hermes session without the env's tools.
    • (b) Normal turns, two in one context through agent-env run, all verifiers passing:
      • clock off: the terminal date was real (2026-11-21);
      • opted in: it was the env's (2027-02-01).
    • (c) Follower and proxy killed with -9:
      • Run directly: both restarted with new pids, the server kept its pid, the container stayed up, and the next turn
        completed.
      • Through agent-env run, between two opted-in turns: both restarted and the container stayed up. A clock advance
        to 2027-02-11, with wait_followers_s, then reached the restarted follower. The next turn's date was
        2027-02-11, and the verifiers passed.
    • (d) Normal stop, docker stop:
      • idle: exit 0 in 1.3-2.3 s (main: 0.4 s);
      • during a turn: exit 0 in 8.0 s (main: 5.5 s). That's uvicorn's 5 s graceful shutdown, then the server kills
        the turn as it stops.
      • In each case supervisord logged stopped: agent, and the listener didn't fire.
  • Not run: E5, the A2A validator; E8, compaction (the session-id switch for conversation_compression is
    unit-tested only); C6, a snapshot round trip. On the env's clock, the workspace tar created at +200 y and extracted
    at 1950 with exit 0 and only time stamp … in the future warnings.
  • Cost: about $1.40 of model spend, all claude-haiku-4-5 but one gpt-5.4-mini turn.

Also in this push: main merged in. #855's usage counting turns off the profile's background review, which the
unarmed config pin now includes.

Claude, working with Edgar, finished this PR: the merge with main, the crash behaviour and its VM re-test.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge, with no new actionable issues found.

Summary

Adds opt-in clock support to Hermes while keeping Hermes itself on real time.

  • Hermes commands follow the task clock when an environment opts in.
  • Hermes images start the agent alongside clock and network helpers.

williamloo-scale documents these accepted limits: arming the clock during a turn can fail that turn, existing sessions retain their original date until a prompt rebuild, and a server crash stops the container with exit status 0.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  S["A2A server: real time"] --> H["Hermes: real time"]
  H --> D["Prompt dates: task clock"]
  H --> C["Commands: task clock"]
  H --> P["TLS proxy: real time"]
  C --> P
  F["Clock follower"] --> C
Loading

Reviews (11) · Last reviewed commit: "fix(agents): a Hermes server that exits ..." · Reviewed by Greptile

williamloo-scale and others added 30 commits November 16, 2026 11:29
…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:
#	src/agent_env/agents/agents/hermes/requirements.txt
# Conflicts:
#	tst/integration/task_step/test_agent_env_clock_local.py
@earakely-scale

Copy link
Copy Markdown
Collaborator

Hi @williamloo-scale, this is Claude, working with Edgar. Please don't merge this yet. It needs main and a small migration first, or it will turn main red.

#818 merged a single egress rule for every clocked agent: src/agent_env/utils/agent_clock/agent_egress.py. With the clock armed, every TLS host goes through the egress proxy, the env's MCP servers included. Only loopback, host.docker.internal, the deploy's NO_PROXY hosts, and hosts reached only over plain HTTP go direct. NO_PROXY matches by host, so a host also reached over HTTPS stays behind the proxy.

tst/unit/agents/test_agent_clock_images.py on main now requires every clocked agent to:

  • take agent_clock = "utils/agent_clock" in its shared_sources.toml;
  • import clock_armed and egress_env from agent_egress, and define none of the rule itself;
  • have its Dockerfile, and install.sh if it has one, copy agent_clock/agent_egress.py and clock/clockpage.py beside the bridge.

This branch still has its own clock_armed / model_direct_hosts / egress_env. main doesn't require branches to be up to date before merging, so this PR's green checks predate #818, and merging it now would fail main's unit tier for this agent. OpenCode hit exactly this. In #818, commit ddb5993 moved it over, and it makes a short template: the bridge's change is the import plus egress_env(environ, [model_url, *mcp_urls], armed=...).

Why it matters beyond the test: on an armed clock, the CLI checks TLS certificates against the virtual date. An env on Modal whose *.modal.host certificate was issued after that date fails if its MCP host goes direct. We reproduced that on main before #818 (CERT_NOT_YET_VALID, no env tools). #818's PR description has the end-to-end results for Claude Code and OpenCode.

Hermes specifically: plain-HTTP MCP hosts go direct, but a host also reached over HTTPS would then bypass the proxy too. The shared rule handles that case.

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.

williamloo-scale and others added 2 commits November 19, 2026 15:06
The bridge imports clock_armed and egress_env from agent_egress, which
the image copies beside it with clockpage, and hands it the model
endpoint's URL and every MCP server's: a host also reached over HTTPS
now stays behind the proxy.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@williamloo-scale

Copy link
Copy Markdown
Contributor Author

Thanks, done. I merged main (v0.9.1595, with #818) and moved this agent onto agent_egress. Its shared_sources.toml takes agent_clock, the image (and install, where it has one) copies agent_egress.py and clockpage.py beside the bridge, and the bridge hands egress_env the model endpoint's URL and every MCP server's, so an HTTPS MCP host stays behind the proxy. The unit tests pass, including test_agent_clock_images.py and test_agent_egress.py. I rebuilt the image and ran the local armed-clock e2e and the A2A validator against a real model through LiteLLM: clock/v1 is supported, synced and follows writes, and both readings (2031-03-03T23:06:07-0600, then a day later) match. (head 11e1ddd)

@earakely-scale

Copy link
Copy Markdown
Collaborator

Claude again, working with Edgar. I checked the update, and the migration onto the shared rule looks right:

  • agent_clock in shared_sources.toml;
  • clock_armed and egress_env imported from agent_egress, with no copies of the rule;
  • the Dockerfile copies agent_egress.py and clockpage.py beside the bridge;
  • the model URL and every MCP server's URL are passed in;
  • CI is green.

Hermes reaches MCP from Python, whose HTTP clients honour the proxy variables, so the shared rule should carry through.

One thing hasn't been done yet: a run with an armed clock against an env on Modal, whose certificate starts after the virtual date. That's the case #818 was about. I'm happy to run it for Hermes before this merges, if you'd like.

williamloo-scale and others added 11 commits November 20, 2026 01:30
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ommands it runs follow it

Hermes compares its own clock with times it didn't make on that clock in many places: its scratch
folder (TMPDIR) is pruned at each start of entries idle for 24 h, and the processes running in
them; terminal spills and large tool results are deleted past 7 days and sessions.retention_days;
checkpoints past their retention; the turn lease stops a turn the clock jumps past or runs fast
through; the stream stall check drops a stream the clock jumps past. On an env clock ahead of real
time these delete a conversation's files or end its turns.

On an armed clock the bridge now starts Hermes as the command its launcher runs, Hermes' own
Python, with AGENTENV_REAL_TIME=1, rather than through the launcher's shell, which would take the
marker. Hermes and everything it does in-process stay on real time; every command it starts (the
model's shell, execute_code scripts, git) follows the env's clock. With --env-clock the plugin has
Hermes read the date it shows the model (hermes_time.now) and the session id's stamp, which the
"Conversation started" line reads, from a `date` it runs. The turn's config names the egress
proxy's and its CA's variables in terminal.env_passthrough, as execute_code hands its scripts only
a fixed few. Unarmed, the command, environment and config are main's.

The Dockerfile reads the pinned release's launcher at build, so a Hermes bump that changes it fails
the build rather than an armed turn; the plugin names the release whose names it replaces, which a
test holds to the Dockerfile's HERMES_COMMIT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and reads its launcher at build

Hermes had no image contract test: every file the Dockerfile copies is in the build context, every
module the A2A server imports (the folder's own and the shared egress rule and clock page format)
is copied into /opt/agent beside it, with the plugin, and the build reads the pinned launcher.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nAI-compatible stand-in

The Hermes row had no turn: Hermes calls chat completions, which the Anthropic stand-in doesn't
serve. Each agent now names the stand-in its CLI speaks. Hermes' turn checks the date line it sends
the model and a terminal `date` are the env's, its session id carries the env's date, and its
session store records a real-time start, so Hermes itself ran on real time.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Hermes README gets a section on the clock: off by default, what opting in changes, why Hermes
stays on real time, the date the model sees and its limits; the image paragraph says it starts as
root under supervisord. The agents README names Hermes among the clocked agents.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s every session id and passes the zone to execute_code

- launcher_command takes only `exec <python> -I -c <bootstrap> "$@"`: Hermes' forwarder to another launcher, or an
  `exec env ...`, would hand the real-time marker to sh or env, Hermes would follow the env's clock again, and the
  build's launcher check would still pass.
- --env-clock replaces every binding of new_session_id a loaded module made by import, not only agent_init's:
  conversation_compression binds it as mint_session_id for a compaction's child session.
- On an armed clock, terminal.env_passthrough names TZ too: execute_code scrubs TZ and sets it only from Hermes' own
  timezone setting, so its scripts saw UTC while the terminal showed the task's zone.
- The README says what a clock armed mid-turn does: that turn's Hermes was started unarmed, through the launcher, so it
  jumps with the clock and its lease or stall check may stop it; the next turn is armed. It also names the variables
  supervisord adds to the server's environment.
- The unarmed test pins the whole profile config, and a test pins that the clock adds only the passthrough. The fake
  launcher is written in the installer's shape.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Supervisord restarts a Hermes A2A server that dies, and the turns it was running, in sessions of their own, went on
after the restart: on the VM a turn kept running its tool, wrote the workspace and the session store, and only then
exited, ~45 s after the new server was up. As it starts, the server now kills each such turn and what it started,
known by the event pipe's variable and a home under the profiles (kill_orphaned_clis). The README also says what a
turn running when the clock is armed meets: its model calls check certificates on the env's clock, since Hermes'
Python carries its own OpenSSL, which the TLS shim doesn't reach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main's Hermes usage counting (#855) turns the profile's background review off, which the unarmed config pin now
names; the README keeps main's usage paragraph with the image's supervisord paragraph.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e the clock

On main the A2A server was the container's process, so a server that died took the container down and the run failed
at once. Under root's supervisord it was restarted in place without its turns, registrations or the A2A task it was
running: the caller polled "Task not found" until its timeout, and the context's next turn started a fresh Hermes
session. Now supervisord doesn't restart the server (autorestart=false, startretries=0), and an event listener in
root.conf stops supervisord when the server is EXITED or FATAL; supervisord then stops the follower and the proxy and
exits, and the container with it. The follower and the proxy still restart in place, and a normal stop exits 0 as
before. supervisord 4.2.5 exits 0 after any shutdown, so a crashed server's container exits 0; supervisord's log line
says why. The startup sweep for turns a dead server left (kill_orphaned_clis) goes with the case it handled.

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

Copy link
Copy Markdown
Collaborator

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

  • Hermes itself now runs on real time on an armed clock, and only the model's commands follow it. Hermes compares its own clock with real times in about nine places, among them its scratch prune, output spill cleanup, turn lease and stream stall detector. Running Hermes on the env's clock broke those once the clock was days ahead, or when it jumped mid-turn.
  • The env's date reaches the model. A small plugin makes Hermes's system prompt show the env's date.

Tested on a dedicated VM, with a stand-in model and real models, side by side with main:

  • clock off matches main;
  • opted in (agent_clock), the model sees the env's time;
  • the fix(claude-code): reach env MCP servers through the egress proxy on an armed clock #818 case: HTTPS MCP on a Modal env armed before its certificate, and with a clock behind real time;
  • four-turn history at +75 days, 1950 and 2262;
  • late agents, the require policy, and the agent on Modal;
  • chaos: clock rate and jumps, re-arm, clear, a killed clock follower, env reset, endpoint outages, cancel mid-turn, a killed server, concurrent runs.

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 main, instead of supervisord restarting the server in place. Edgar decided this after testing showed in-place restarts leave the old CLI writing and the new server without the env's MCP tools. #862 makes the same change for Claude Code and OpenCode.

Merging: the five clock PRs (#765 #768 #769 #770 #771) each add a row to tst/integration/task_step/test_agent_env_clock_local.py, so after the first one lands the others need a main merge that keeps both rows. I can do those merges.

The full details are in the PR description.

Claude, working with Edgar

@earakely-scale

earakely-scale commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Closing this, per Edgar's decision. Claude here, working with Edgar.

Why: Hermes on libfaketime compares its own clock with real file times and timers in about nine places: the scratch prune, output spill cleanup, the turn lease, the stream stall detector, and others. With the clock a day or more ahead, or jumping mid-turn, it deleted its own working files and killed turns. The version on this branch kept Hermes on real time and only put the model's commands on the clock, so advertising clock/v1 would overstate what the agent does.

Edgar's rule: an agent advertises the clock (clock/v1 sync_time) only if the agent itself faithfully follows libfaketime, as Claude Code, OpenCode and Letta Code (#769) do.

What this agent does instead: it stays as it is on main. It runs on real time, and the env's time is available from the gateway's get_time tool, which has been the default for agents since #832.

  • A task with require_agent_clock fails up front for this agent ("can't follow the clock: not advertised").
  • Plain agent_clock skips it.
  • Its image stays identical to main, so none of the clock image's side effects apply: running as non-root on Modal, slower start and teardown, and the egress-proxy boot.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants