Skip to content

[FD-5916] feat(agents): the Letta Code image follows the env's clock - #769

Merged
earakely-scale merged 60 commits into
mainfrom
wloo/letta-code-clock-image
Nov 21, 2026
Merged

earakely-scale merged 60 commits into
mainfrom
wloo/letta-code-clock-image

Conversation

@williamloo-scale

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

Copy link
Copy Markdown
Contributor

What and why

The Letta Code image can now follow a task env's virtual clock, as the Claude Code and OpenCode images do (#726, #818, #831, #832). It follows only when a sync_env_clock step sets agent_clock: true (require_agent_clock implies it). Otherwise the agent runs on real time and reads the env's time from the gateway's get_time tool, exactly as on main.

How it works once a task opts in

Time

  • Letta Code's local backend runs inside each letta process, so the whole CLI follows the clock. That includes the - **Local time**: line of the environment context the CLI gives the model, and every command the model runs (date, the timestamps it writes into files).
  • The A2A server starts with the real-time marker, so the server, its model relay and its records stay on real time. libfaketime takes the marker out of the server's environment, so everything the server starts reads the env's time: every letta command, letta mcp call (started by the CLI for each MCP tool call), the model's commands, and the bridge's own git commit to the memory.
  • The workspace changelog's GNU tar runs on real time (AGENTENV_REAL_TIME=1). Left on the env's clock, it would write a virtual dump time into its .snar, and on a clock ahead of real time the next increments would miss every modified file. The snapshot's plain tars stay on the env's clock; they record only the files' own times.
  • File modification times stay real (libfaketime is built without stat faking).

Network

  • The CLI reaches the model through the bridge's relay on 127.0.0.1 over plain HTTP, directly. The relay, on real time, makes the TLS call to the endpoint.
  • For everything else the bridge passes every MCP server's URL to the shared rule agent_egress.egress_env. On an armed clock, every letta command of a turn gets HTTP(S)_PROXY, ALL_PROXY, NO_PROXY and NODE_USE_ENV_PROXY=1, and so do letta mcp call and the model's commands, which inherit them.
  • Loopback (the relay, the peers MCP server), host.docker.internal, the deploy's NO_PROXY hosts and plain-HTTP-only hosts go direct. Every TLS host goes through the egress proxy.
  • The proxy passes TLS through when the site's certificate is valid at the universe date. Otherwise it re-signs with the image CA, which the CLI trusts through NODE_EXTRA_CA_CERTS. That is the *.modal.host case fix(claude-code): reach env MCP servers through the egress proxy on an armed clock #818 fixed, and it also covers a clock behind real time.

State

  • Nothing on the CLI's headless path ages conversations or tool output by file times. History is read back from messages.jsonl in file order (read in the pinned 0.34.26 bundle).

What changes

  • shared_sources.toml takes utils/faketime_clock, utils/egress_proxy and utils/agent_clock.
  • Dockerfile: the egress and clock build stages, the root setup block, no USER, CMD ["/usr/local/bin/start-agent"]. It copies agent_egress.py and clockpage.py beside the bridge, and install.sh does the same.
  • start-agent and root.conf: root's supervisord runs the follower, the egress proxy (AGENTENV_EGRESS_PRIVATE="allow") and the A2A server, the server as agent with the real-time marker. Started as another user, the image runs entrypoint.sh alone, as before. A provider's CA bundle stays trusted.
  • The A2A server is still the container, as on main: supervisord never restarts it (autorestart=false), and an [eventlistener:agent-exit] in root.conf stops supervisord when the server exits or fails to start (PROCESS_STATE_EXITED / PROCESS_STATE_FATAL for the agent program), so the container ends. The listener is a few lines of inline python3 speaking supervisord's eventlistener protocol, sending SIGTERM to its parent. The follower and the proxy keep their own restart policy (autorestart=true). See "Server exit" below.
  • letta_code_bridge._turn: _context_env(context_id, [every MCP URL], armed=clock_armed()).
  • a2a_server: the changelog's baseline and capture tars run with AGENTENV_REAL_TIME=1.
  • READMEs: Letta Code's says how the image follows the clock and lists the edge cases below; the agents README names Letta Code among the agents on the shared egress rule.
  • Tests:
    • tst/unit/agents/letta_code/test_env_clock.py: the call site; the default-off equality; the changelog's real time; CA bundles.
    • tst/unit/agents/letta_code/test_image_contract.py: every copied file exists; the image and an install carry every module the server imports; an install puts each file under app/ by its own name, where run.sh imports from.
    • tst/unit/agents/letta_code/test_server_exit.py: root.conf parsed as supervisord parses it. The server has autorestart=false and the follower and the proxy autorestart=true. There is one listener, running as root, on exactly EXITED and FATAL. Its inline command is also run against a stand-in supervisord that plays the protocol: it sends SIGTERM for the agent program's EXITED and FATAL and for nothing else (clock, egress), and keeps serving after each.
    • The shared test_agent_clock_images.py covers this image.
    • The local clock e2e (test_agent_env_clock_local.py) has a row for it, with a real CLI turn against a stub OpenAI chat-completions endpoint (tst/util/fake_openai.py). The turn checks that the Local time line and the model's Bash date show the env's date, and that model calls reach the loopback relay with the proxy variables set.

No change to the shared utils/egress_proxy, utils/faketime_clock or utils/agent_clock. requirements.txt is unchanged: main's floor of 0.1.588 already serves sync_time.

With the clock off: same as main, except at the image level

A turn runs exactly main's letta commands, with exactly the environment main's bridge built: no proxy variables, the same flags. test_unarmed_a_turn_runs_mains_commands_with_mains_environment pins this. What still differs, even with the clock off:

  • Start. The container starts as root, and root's supervisord is PID 1. It runs the clock follower (as agentenv-clock, idle until a task opts in), the egress proxy (as agentenv-egress, on 127.0.0.1:3128, unused) and the A2A server (as agent). On local Docker the server was already agent. A docker exec without -u now runs as root, because the image no longer sets USER.

  • Modal. Modal runs the image as root. On main, the A2A server, the CLI and the model's commands ran as root there; now they run as agent, uid 10001. A task whose model needs root (apt-get install, writing outside /app, /data and /tmp) can fail on Modal. A side effect: the CLI's own auto-updater, which starts on every letta run and, as root on main, could replace the pinned CLI with a global npm install, now fails harmlessly.

  • Egress boot. The egress proxy's boot (minting the per-boot image CA) runs on every start, and a failed boot stops the container with exit 2.

  • Server exit. Same as main: when the A2A server exits, for any reason, the container ends and the run fails. Earlier on this branch supervisord restarted a crashed server in place. That left the dead server's CLI running in the workspace, and the new server had lost the env's MCP registrations, the agent-config values, the peers and the running tasks. Later turns then ran silently without the env's tools, and prompt_agent polled "Task not found" until its full timeout. Now root.conf never restarts the server, and the agent-exit listener stops supervisord. Two small differences from main remain:

    • The container's exit status is 0, where main's was the server's own (137 after a kill -9). supervisord 4.2.5 always exits 0 after a shutdown and has no setting to change that.
    • A server that fails to start is retried three times (about 12 s, supervisord's startretries with backoff) before supervisord gives up and the container ends. On main the container ended at once.

    The follower and the proxy still restart in place, and a normal stop of the container (docker stop, a sandbox teardown) stops the server without an exit event and exits cleanly. Claude Code's and OpenCode's clocked images on main still restart a crashed server in place.

  • Environment. The server's environment, which the CLI and the model's commands inherit, gains:

    • AGENTENV_EGRESS_PROXY;
    • NODE_EXTRA_CA_CERTS, SSL_CERT_FILE and REQUESTS_CA_BUNDLE, pointing at agent-env's bundles: the system roots plus the per-boot image CA, plus a provider's own bundle when it sets one;
    • USER and LOGNAME (agent);
    • supervisord's SUPERVISOR_ENABLED, SUPERVISOR_PROCESS_NAME, SUPERVISOR_GROUP_NAME and SUPERVISOR_SERVER_URL.
  • Trust. The per-boot image CA is trusted in the system store and in the certifi bundles.

  • Preload. libfaketime and the TLS shim are preloaded in every process (/etc/ld.so.preload). With an unarmed page, both read real time.

  • Changelog tar. The changelog tar gets AGENTENV_REAL_TIME=1 in its environment. With the clock off this changes nothing.

  • Installs. An install into a task container or onto a VM host (install.sh) also copies agent_egress.py and clockpage.py into app/. It gets no clock, as before.

What still reads the env's clock against other times (in the README)

  • Memory commits. A memory commit, the bridge's or the CLI's, carries the env's date. Before 1970 git stores an overflowed time, and after 2099 a broken time zone; git fsck flags both. commit, ls-tree, show, log and status work. Checked with git 2.52 on macOS, and with Debian's 2.39 in the image at 1950 and 2262: every turn's commit landed, and fsck reports badDateOverflow and badTimezone.
  • Memory listing. The memory tool's folder listing shows the 10 most recently edited entries. Committed ones are dated by their commit (the env's clock) and uncommitted ones by their file times (real), so the clock's offset changes which 10 a larger folder shows.
  • Compaction. A jump back across a compaction makes the CLI's pre-turn compaction check estimate the context's size from its text instead of using the last reported usage.
  • Placeholder date. Messages written on 2026-01-01 UTC, the CLI's placeholder date, get timestamps interpolated from file times when loaded. Content and order don't change.
  • Retry-After. A Retry-After given as a date is read against the env's date. The CLI waits at most 60 s, and LiteLLM and the providers send seconds anyway.
  • File locks. File-lock timeouts and staleness run on the env's clock. A rate above 1 or a jump forward shortens both.
    • A jump back lengthens both. A lock a killed CLI left (the reflection transcript's, say) goes stale only once the env's clock passes the time it was taken plus 90 s. Until then, every turn waits 10 s for it at its end and leaves its messages out of that transcript (Failed to append transcript delta in the context's debug log).
    • A jump back during a wait for a held lock stretches the wait by the jump. A frozen clock stretches it to the turn's timeout.
    • A context's locks are its own.
  • Message ids. On a frozen clock, every assistant message from a provider that gives no response id takes the same time-based id. LiteLLM gives one.

Other limits

  • Arming mid-turn. A turn that is running when the clock is first armed keeps the environment it started with. Its CLI reads the env's time from then on but goes out directly until the turn ends; the next turn goes through the proxy. Every clocked agent behaves this way.
  • Programs that ignore the proxy. A program the model runs that ignores the proxy variables goes direct. If it checks certificates with OpenSSL, the TLS shim checks them on real time. With anything else (Go, rustls, GnuTLS), it checks them against the env's date.
  • Updater and telemetry. On an armed clock, the CLI's auto-update check (registry.npmjs.org) and its telemetry (api.letta.com) go through the proxy. In the VM runs the proxy re-signed them (mode: intercept) and they worked.
  • Compaction evidence. In the image, the stand-in model made the CLI compact once, after turn 2, and the clock then jumped back to 1950. Turns 3 and 4 completed, the last call carried the summary, turn 1's reply and turns 2-4, and messages.jsonl only grew. The pre-turn size estimate after the jump comes from reading the code.
  • Dates past 2262. The shared clock page holds nanoseconds in an int64, so it ends at 2262-04-11. A clock armed later (3026, say) can't be followed. sync_env_clock with agent_clock or require_agent_clock then fails the step with "this agent's clock follower isn't following the gateway: it hasn't heard from the gateway … yet", which doesn't name the date as the cause. This is shared code, the same for every clocked agent.
  • R2 (what the model sees about "now"). All of it is the env's time, except file modification times (ls -l, stat, find -newer) and whatever a live service reports, such as HTTP Date headers. Both stay real.

Testing

Unit (macOS, this head)

  • tst/unit/agents and tst/unit/utils: 1346 passed, 46 skipped (Linux-only). ruff check: clean.
  • Mutation-checked at this head. Each of these mutations breaks at least one test:
    • at the call site: armed=False, armed=True, dropping the MCP URLs, dropping egress_env;
    • in the changelog: dropping the real-time env from either tar;
    • in the image and install: the image not copying agent_egress.py, the install not carrying mcp_tools.ts, and the install putting a file at app/<path> instead of app/<name>. That last mutation passed all 54 other tests, so a test was added for it;
    • in root.conf: the server's autorestart=true, the listener matching another program name, the listener dropping PROCESS_STATE_FATAL, the listener signalling itself instead of supervisord, and a ; in its command, which supervisord would read as the start of a comment.

The pinned CLI (0.34.26), locally, against a stand-in model API, no key

  • Setup. Node's Date was faked through NODE_OPTIONS, a macOS stand-in for libfaketime, so the model's shell showed real time. Each run had four turns of about 40 s in one conversation, through the bridge and through the real A2A server.
  • Clocks. Real, +75 days, +1000 years, 1950, 2026-01-01, and jumps between turns plus 3600x within them.
    • At every clock, the last model call sent every earlier turn's prompt and reply and kept the committed task instructions.
    • The CLI's Local time line showed the set date.
  • Frozen clock (rate 0). At the e2e's 2031-03-04T05:06:07Z, a frozen-clock turn through the bridge against tst/util/fake_openai.py, with the e2e's responder, completed in 3.4 s. It read - **Local time**: Tuesday, March 4, 2031 at 05:06 AM UTC, which the e2e's assertions accept.
  • Proxy. The CLI's MCP client on Node 22.23.1 and 24.22.1 sent an HTTPS MCP host to the proxy as CONNECT …:443 and reached a NO_PROXY plain-HTTP host directly. The image runs Node 22.23.4.
  • git at 1950 and 3026 (git 2.52, a macOS clock interposer): commit, log --format=%ct, status, show and ls-tree work. At 1950, %ct prints the overflowed 18446744073081078017.

Earlier on this branch (at e7bc8c0): an image build, the local armed-clock e2e, and the A2A validator against a real model through LiteLLM. clock/v1 was supported, synced and followed writes.

VM phase (dedicated x86_64 Ubuntu 24.04 VM, branch at 602e31e against main = agentenv-framework 0.9.1609 from PyPI, whose letta-code is the published ghcr.io/scaleapi/agentenv-letta-code@sha256:cce226db…; models through LiteLLM with anthropic/claude-haiku-4-5)

  • Linux unit tests. tst/unit/agents and tst/unit/utils: 1355 passed and 0 skipped. The 46 that skip on macOS ran and passed.

  • Image smoke. The image built from 602e31e in 81 s. test_agent_env_clock_local.py -k letta-code passed (158 s):

    • it synced and followed;
    • date and datetime.now() showed 2031-03-04T05:06:07Z at rate 0;
    • the real CLI turn's Local time line read "Tuesday, March 4, 2031 at 05:06 AM UTC" and its Bash date read 2031-03-04T05:06:07Z;
    • the write waited 0.02 s and answered 504 naming agent-solver while the agent was paused;
    • after teardown, writes stopped waiting (0.01 s).
  • Clock off. Each letta process's /proc/<pid>/environ (sampled during stand-in turns and real turns) has no *_PROXY and no NODE_USE_ENV_PROXY. Against main's it has exactly 10 more variables, the ones listed above (19 → 29). docker run --user 10001 runs uvicorn alone (via entrypoint.sh), with no supervisord and real time. On Modal, with the clock off, the model's id -u printed 0 on main and 10001 here.

  • FD-6434 repro in the image (stand-in model, 4 turns of about 43 s). Real, +75 d, 1950 and 2262 (the clock page's limit; +1000 y can't be set, see "Dates past 2262"), plus jumps (real → +75 d → 1950 → 2262 between turns, and 3600x then a jump back inside each turn), all pass:

    • every turn completed, and the last call carried every earlier turn's prompt and reply;
    • the task instructions stayed in the system prompt (Debian git 2.39 committed at every date);
    • the Local time line and the shell's date read the clock's date;
    • messages.jsonl only grew;
    • no lock, lease or cleanup errors.

    The jumps run with a compaction after turn 2 compacted once and completed turns 3 and 4 (see "Compaction evidence").

  • Real-model end to end (agents on local Docker; mail on local Docker or on Modal):

    • Clock off, A/B against main on the same prompts, unarmed and armed without agent_clock, local and Modal. Both sides showed the same behaviour: real date and Local time, get_time UNAVAILABLE when unarmed and the env's date when armed, MCP direct, no follower config.
    • long-lc-on (+75 d): following; date, Local time and get_time read 2027-02-03; MCP worked; the write while the agent was paused answered 504 naming it; the late agent followed; all 4 turns kept every earlier label (5/5 checks).
    • The armed CLI's environment had HTTP(S)_PROXY, ALL_PROXY, NODE_USE_ENV_PROXY=1 and NO_PROXY=localhost,127.0.0.1,::1,host.docker.internal. The egress logs show no loopback host anywhere: model calls went to the relay directly.
    • fix(claude-code): reach env MCP servers through the egress proxy on an armed clock #818: mail on Modal, armed at 2026-10-27, before the *.w.modal.host certificate's notBefore (Nov 19 2026, ZeroSSL). MCP went through the proxy, re-signed (intercept), and the invoice came back; every date read 2026-10-27.
    • behind-lc-on (2025-06-01, certificate notBefore Nov 20 2026): passed the same way.
    • require_agent_clock, with the agent deployed after or before the clock: passed here. On main it fails clearly: "agent 'default-agent' can't follow the clock of env …: not_advertised".
    • The agent itself on Modal (Modal built the image from the build context), opted in: followed, and both turns read 2027-02-03.
    • The changelog with the clock 75 days ahead: three increments, each with the edited notes/notes.txt (versions 1, 2, 3) (R7).
    • Four concurrent opted-in runs: all passed.

    The Modal service-db start-up race hit 5 times (retried). One main clock-off run on Modal lost all three of its attempts to it; the same case passed in its other Modal pair.

  • Chaos (two runs, both opted in, mail on Modal). In the first run, Modal terminated the env from outside (a shared app) during the 600 s wait below, so its second half was run again.

    • Every one of these turns completed with the clock's date and MCP working: rate 3600 (the agent's clock moved 5 h in 5 s); freeze and a jump forward; kill -9 of the follower (restarted in 3 s, the next write acknowledged); kill -9 of the egress proxy (restarted, MCP fine on the next turn); the model endpoint blocked for 45 s mid-turn (that turn still completed).
    • After the follower and server kills: setting the clock back to 2025-06-01, reset_env (the clock and follower were kept), clear (back to real time) and a backward re-arm at 2026-01-15 without agent_clock (the agent kept following) all showed the right date.
    • No File lock timeout and no Failed to append transcript delta in any container log or session.
    • But killing the server mid-turn, with the server then restarting in place, lost the env's MCP tools and the history for the rest of the run, silently, and the killed turn's prompt_agent polled "Task not found" until its own timeout (600 s by default). The image now ends the container instead; see "Server exit" above and the crash checks below.
  • Server crash, this head (eb890df: main at 64afced merged in; the stand-in model API, the mail env and the agent on local Docker; main = agentenv-framework 0.9.1609's published image). In each run, the A2A server got kill -9 12 s into a turn, while its CLI ran the model's sleep 30. On the branch that was a kill -9 inside the container; on main, where the server is PID 1, it was docker kill -s KILL. Each run had a second turn after the crash.

    branch main
    container gone after the kill 2.1 s, exit 0 0.04 s, exit 137
    killed turn's prompt_agent failed after the kill 60.2 s 58.3 s
    second turn failed loudly (agent-config unreachable, 10 tries in 104 s) the same
    model calls after the kill none none

    Both fail at prompt_agent's own rule ("stopped answering: 5 polls in a row over 60s got no reply"), so the branch now fails as fast as main. Before this change it polled "Task not found" for 600 s. supervisord's log reads exited: agent (terminated by SIGKILL; not expected), then received SIGTERM indicating exit request 1 s later, then each program stopped. The killed turn's CLI and its sleep 30 went with the container: the CLI never made its next model call. The previous phase's attempt to kill main's server by its host pid had been refused, unnoticed, by AppArmor (docker-default doesn't take signals from the SSM agent's snap profile). The main column above is the first real measurement.

  • Turns still work, this head (stand-in model, mail on local Docker; all passed):

    • Clock off: the model's date read real time (2026-11-21).
    • Opted in (agent_clock): the agent's date and the model's date read 2027-02-03.
    • The follower got kill -9, then the egress proxy: each restarted within 4 s with a new pid, while the server kept its pid and uptime and the container stayed running with 0 restarts. Next, an advance with wait_followers_s was acknowledged in 0.02 s, and a turn read the new date, 2027-02-04.
  • Stops and start failures, this head (docker run of the image):

    • An idle docker stop exited 0 in 2.3 s.
    • A docker stop mid-turn exited 0 in 6.5 s: the server waited out its 5 s graceful shutdown and killed the turn's CLI. The listener stayed silent, since each program ended as stopped, not exited.
    • A server that can't start (A2A_PORT=notaport) was retried three times, went FATAL, and the container ended 12.6 s after docker run, exit 0.
    • Started as uid 10001, the image runs uvicorn alone, as before.
  • SIGTERM to agent-env run mid-turn, both sides: the run was recorded cancelled, 2 sandboxes were torn down, and no containers or sandbox folders were left.

  • Image size: 1,369,446,346 B against main's 1,352,085,856 B (+17.4 MB, +1.3%).

Follow-up (separate PR, from main)

Set DISABLE_AUTOUPDATER=1 in the image. Every letta run starts the CLI's auto-update check in the background: it fetches from the npm registry, and when a newer version is out it runs a global npm install. That is main's behaviour with the clock off, so changing it here would break "same as main".

Claude, working with Edgar, finished this PR.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no new actionable issue was established.

Summary

Letta Code can now follow the task environment’s clock after explicit opt-in.

  • Letta Code follows the task environment’s clock when a task opts in.
  • The container ends when its A2A server exits.
  • Workspace changelog snapshots keep using real time.

The earlier unnumbered finding about missing shared clock helpers is fixed: both helpers are declared, copied, and imported.

williamloo-scale documents the accepted Modal user change, container exit status and startup retries, and CLI limits around dates, locks, and memory ordering.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  S[Root supervisord] --> F[Clock follower]
  S --> E[Egress proxy on real time]
  S --> A[A2A server on real time]
  F --> P[Shared clock page]
  A --> C[Letta CLI]
  P --> C
  C --> R[Loopback model relay]
  R --> M[Model endpoint]
  C --> E
  E --> T[HTTPS task tools]
  A --> X[Server exit listener]
  X --> Q[Stop supervisord and container]
Loading

Reviews (12) · Last reviewed commit: "fix(agents): Letta Code's container ends..." · 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/letta-code/requirements.txt
…-image

# 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.

Letta Code specifically: _context_env passes direct for the model relay and the env's MCP servers. An HTTPS MCP host in direct is exactly the case that fails on an armed clock. With the shared rule, pass the URLs and loopback stays direct by itself.

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_clock/agent_egress
and hands it every MCP server's URL, so an HTTPS MCP host goes through the
egress proxy on an armed clock (its certificate is checked on real time);
loopback, the model relay's among it, and plain-HTTP hosts stay direct.
The image and install.sh copy agent_egress.py and clockpage.py beside it.

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 e7bc8c0) Letta's model relay is on loopback, so it stays direct without being passed. The earlier unit (2/2) failure was a cancelled xdist job, not a test.

@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.

Letta Code's MCP client is Node or Bun. It's worth confirming end to end that it honours HTTPS_PROXY and NO_PROXY (gemini-cli, for one, ignores NO_PROXY).

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 Letta Code before this merges, if you'd like.

williamloo-scale and others added 9 commits November 20, 2026 01:30
…-image

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…on real time

The changelog's tar is a child of the A2A server, which runs on real time, but libfaketime takes the
real-time marker out of the server's environment, so tar read the env's clock. Its dump time went into
the snapshot file, and on a clock ahead of real time the next increment missed every file changed after
it, since file times stay real. Both incremental tars now run with AGENTENV_REAL_TIME=1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, its default-off equality and its image contract

- every letta command of a turn carries the egress variables on an armed clock, with the env's
  HTTPS MCP host behind the proxy and loopback and plain-HTTP hosts direct;
- unarmed, a turn runs main's commands with main's environment;
- the changelog's incremental tars run on real time;
- the image and an install carry every module the server imports, the egress rule and the clock
  page's format among them, and the MCP mod the bridge installs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s clock and what still reads it against other times

The image starts as root and runs the server as the agent's user; the whole CLI follows the clock once a
task opts in, its environment context's "Local time" line included, while the server, its model relay and
its records stay on real time; MCP over TLS goes through the egress proxy and the changelog's tar runs on
real time. The edge cases that remain are listed. root.conf and start-agent lose a ticket id.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…'s file names are pinned, and the README names the lock and listing edges

- The local clock e2e gives letta-code a turn against the OpenAI chat-completions stub: the CLI's Local time line and
  the model's Bash date show the env's date, and its model calls reach the loopback relay with the proxy variables set.
- The image contract test runs install.sh's copy loop and checks every file lands in app/ by its own name, where run.sh
  imports from; putting agent_clock/agent_egress.py at app/agent_clock/ passed every other test.
- Letta Code's README: what a jump back or a frozen clock does to file locks (a killed CLI's reflection transcript lock,
  waits for a held lock), the time-based message id on a frozen clock, the memory listing's mixed commit and file times,
  and git log and status among the commands that work at 1950 and 3026.
- The agents README names Letta Code among the agents on the shared egress rule.

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

Under root's supervisord a crashed server was restarted in place: the dead server's CLI went on in the workspace, the
new one had lost the env's MCP servers, config, peers and tasks, so later turns ran silently without the env's tools,
and prompt_agent polled "Task not found" until its timeout. Now root.conf never restarts the server, and an event
listener on its EXITED or FATAL stops supervisord, so the container ends and the run fails as on main. The clock
follower and the egress proxy keep restarting in place; a stop of the container stops the server without an exit event.
supervisord 4.2.5 always exits 0, so the container's status is 0 rather than the server's.

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

  • Letta Code stays on the env's clock, as you had it. I read its headless path at the pinned version, and the stand-in runs confirmed it is safe.
  • The changelog's tar now runs on real time. On the env's clock it missed edits to existing files once the clock was ahead; [FD-6434] fix(agents): the changelog's tar runs on real time in clocked agent images #859 fixes the same for Claude Code and OpenCode.
  • New tests: one at the bridge's call site, and an install contract test.

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

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