Repository navigation
fix(claude-code): reach env MCP servers through the egress proxy on an armed clock - #818
Conversation
…n armed clock With the env clock armed, the CLI reached every MCP server directly and checked its TLS certificate against the env's date, so an env whose certificate was issued after that date failed to connect and the agent got no env tools. Only loopback hosts (the peer-agents MCP server's among them) stay direct now; every other MCP host goes through the egress proxy, which runs on real time and reaches private addresses. Unarmed behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rvers through the proxy The clock page check and the CLI's proxy variables move from Claude Code's bridge into utils/faketime_clock/agent_egress.py, which reads the page by clockpage's own layout and check. Every clocked agent's bridge imports it; its image copies it and clockpage.py beside the bridge, and install.sh does the same for an installed agent. On an armed clock every TLS host goes through the egress proxy, the env's MCP servers included; only loopback, the deploy's NO_PROXY hosts and the hosts of plain-HTTP URLs (the model endpoint's and every MCP server's) go direct. Unarmed, or without the proxy, nothing changes. A page whose check never matches now reads as unarmed. The AST-copy test becomes a check that every clocked bridge imports the rule, defines none of it, and that its Dockerfile copies the module beside it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s take agent_egress.py moves to utils/agent_clock, which claude-code's shared_sources.toml takes as agent_clock; the Dockerfile and install.sh copy it beside the bridge with clock/'s clockpage.py. The computer bases take utils/faketime_clock and utils/egress_proxy whole, so the rule there would have changed their build contexts, and every edit to it would rebuild them; their folders, READMEs included, are now as on main. A page still mid-write or torn after the retries is taken at its armed flag again, as the bridge's reader did: unarmed, the proxy relays untouched, so it is the safe side. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
For reference only. This doesn't need to block the refactor in progress here. End-to-end check of the original rule from Setup: a clone of an ST task run,
The runner was agent-env 0.9.1584. On 0.9.1571/0.9.1582 the same agent's clock sync fails with HTTP 401 (control token, #808). |
…p-via-proxy Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lso reached over TLS stays proxied OpenCode's image, on the clock since main's #766, takes utils/agent_clock as agent_clock; its Dockerfile and install.sh copy agent_egress.py and clock/'s clockpage.py beside the bridge, which drops its own clock_armed, model_direct_hosts and egress_env and hands the rule the model endpoint's URL and every MCP server's. NO_PROXY matches by host, not scheme, so a host goes direct only when every URL for it is plain HTTP; one also reached over HTTPS stays behind the proxy, which relays plain HTTP too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
andrewpark-scaleai
left a comment
There was a problem hiding this comment.
LGTM. I checked this against my gateway and control token work (#820 to #825) and it doesn't overlap or widen anything. The proxy refuses loopback and link-local, so routing env MCP through it narrows what the agent can reach. The agent could already reach these hosts directly by dropping the proxy variables. The proxy logs only connection metadata, so MCP tokens don't land in its log. The Greptile fix holds. I ran the claude_code, opencode, test_agent_clock_images and test_agent_egress suites at ddb5993 and got 493 passed. The e2e table ran 0c4ec2a, so the Greptile fix and the OpenCode move haven't had an e2e run. The unit tests cover both. Nit: the title says claude-code, but the PR now moves OpenCode onto the shared rule too.
| return {} | ||
| configured = [host.strip() for name in ("NO_PROXY", "no_proxy") for host in (environ.get(name) or "").split(",")] | ||
| parsed = [urlsplit(url) for url in urls] | ||
| tls = {parts.hostname for parts in parsed if parts.scheme != "http"} |
There was a problem hiding this comment.
Non-blocking. Every TLS MCP host now goes through the proxy, and the proxy checks upstreams only against its public roots (PublicRoots in main.go). Before this PR, Claude Code reached a TLS MCP server signed by a private CA directly, and that worked while the date sat inside the cert. Now an armed clock fails that server at any date. OpenCode already worked this way, and the Modal hosts use public certs, so I don't think anything breaks today. A line in the README would save the next person a debug session.
|
🤖 Automated Claude routine — Env Pod PR Context Review. This is a bot, not Edgar Arakelyan; not a human review. Context from the other open PRs rather than from this diff.
All five write only The description anticipates the shape of this ("each one that follows would have brought the exemption back"); what isn't visible from here is that the five are in flight at the same time, so whichever side merges second has to carry the other's change. On the behavioural half the five are not uniform: #768 and #769 already send only plain-HTTP MCP hosts direct, which matches the rule here, while #765's description still states that MCP traffic stays direct either way. Generated by Claude Code |
The bridge imports clock_armed and egress_env from agent_clock's agent_egress, which the image and an install copy beside it with clockpage, and hands it the model endpoint's URL; its own copy of the rule goes. mcp-remote, which codex hands only the trust variables, is still not given the proxy. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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>
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>
The bridge imports clock_armed and egress_env from agent_egress and hands it the model endpoint's URL and every MCP server's, so on an armed clock a host reached over HTTPS stays behind the proxy even when it's also reached over plain HTTP. The image copies agent_egress.py and clockpage.py beside the bridge; an install (install/v1), which unpacks the build context with them in agent_clock/ and clock/, puts those folders on the server's path. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The bridge imports clock_armed and egress_env from agent_clock/agent_egress and hands it the model endpoint's URLs and every MCP server's, so on an armed clock an HTTPS MCP host goes through the egress proxy like the rest. The CLI still gets no HTTP(S)_PROXY (_CLI_PROXY_VARS): it ignores NO_PROXY. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ss proxy on an armed clock Codex hands mcp-remote only the variables its env_vars names, so on an armed clock it went to an HTTPS MCP server directly and checked the server's certificate against the env's date. It now gets the proxy's variables too, and the bridge hands the egress rule every MCP server's URL, so only plain-HTTP ones go direct, as #818 has for Claude Code and OpenCode. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
What and why
With the env clock armed (FD-5916),
_spawn_claudeput every MCP server's host inNO_PROXY. The CLI therefore reached the env's MCP server directly and checked its TLS certificate against the env's date. An env whose certificate was issued after that date failed to connect, and the agent got no env tools.We hit this in an ST task run: virtual time 2026-11-03T09:00 America/New_York, the env's
*.w.modal.hostcertificate valid from 2026-11-18, and the CLI listed the env MCP asfailedwith 0 env tools. Modal reissues these certificates every few months, so any task whose virtual date is a few weeks in the past is exposed.On an armed clock, only loopback hosts now stay direct, the peer-agents MCP server's among them. Every other MCP host goes through the egress proxy, which runs on real time and also reaches private addresses (
AGENTENV_EGRESS_PRIVATE). This removescli_env'sdirect_hostsparameter, which only ever had an effect while the clock was armed. Unarmed behaviour is unchanged. Theegress_envdocstring andagents/README.mdare updated to match.How it was tested
pytest tst/unit/agents/claude_code/ tst/unit/agents/test_agent_clock_images.py: 282 passed, 30 skipped (all of the skips are intest_changelog.py). The new armed-clock test drives the real_spawn_claudewith the subprocess faked: anhttps://…w.modal.hostMCP host is not inNO_PROXY,HTTPS_PROXYis set and loopback stays direct. It fails on the old bridge.ruff checkis clean on the touched files.cli_envin a downstream agent built on the v0.9.1584 image, ran an ST task clone withsync_env_clockand the env's tools. That rerun is in progress and the result will be added here.One rule for every clocked agent (added on top)
The MCP exemption came from the clock's design ("only the env's MCP hosts and a plain-HTTP model endpoint go direct"). It was copied into every clocked agent's bridge: the shared test required an identical copy of
clock_armed,model_direct_hostsandegress_envin each one. Claude Code is the only clocked agent today, but each one that follows would have brought the exemption back. Two commits on top move the rule into one place:src/agent_env/utils/agent_clock/agent_egress.pyholdsEGRESS_PROXY_ENV,clock_armed()andegress_env(environ, urls, armed=...). It reads the clock page throughclockpage's own layout and check, so the format isn't copied either.The rule: on an armed clock with the proxy, only these go direct:
host.docker.internal;NO_PROXYhosts;Every TLS host goes through the proxy, the env's MCP servers included. Unarmed, or without the proxy, nothing changes.
Only agent images take the folder (
shared_sources.toml:agent_clock = "utils/agent_clock"). Changing the rule therefore rebuilds no computer base.source_digestis unchanged on every image undersrc/agent_envexcept claude-code.claude-code: the bridge imports the rule. The Dockerfile and
install.shcopyagent_egress.pyandclockpage.pybeside it;install_agentcopies only the files it lists, soinstall.shneeded them.Tests:
test_agent_clock_images.pynow requires every clocked agent to takeagent_clock, import the rule, and define none of it.test_agent_egress.pycovers the rule and the page reader (torn, short, foreign and missing pages, and a round trip throughclockpage.write).End-to-end and chaos, round 1 (dedicated amd64 VM, 0c4ec2a's code)
Setup:
mailenv on Modal. Its MCP URL ishttps://…w.modal.host/mcp, with certificate*.w.modal.hostvalid from 2026-11-17.search_emails; a check reads the reply.main, Claude Code, armed before the certificatefailed:HTTP Connection failed after 82ms: certificate is not yet valid (code: CERT_NOT_YET_VALID). The Modal host is in the CLI'sNO_PROXYand never reaches the proxy.main, unarmedmode: intercept, decision: outside, verified: truefor the Modal hostmode: splice, decision: inside(passed through)host.docker.internal,172.17.0.1)Also proven:
import claude_bridgeworks asagent.tst/integration/task_step/test_agent_env_clock_local.pypasses.run_bundle_claude_code_install_test.py's two container installs (Debian, Alpine) pass, which coversinstall.sh's two new files.Other agents (armed before the certificate; none follow the clock today, and their images are unchanged): opencode, pi, hermes, pydantic-ai, openhands, letta-code, codex and gemini all pass.
A second TLS stack: gemini built clocked in a throwaway image with the same clock pieces and this rule (not committed).
CERT_NOT_YET_VALID, no env tools.HTTPS_PROXYand ignoresNO_PROXY. Its loopback calls then reach the proxy, which refuses loopback.Chaos:
ECONNREFUSED), the same asmainfor the model endpoint; started again, the next turn passesdeploy_agentSpend: about $1.80 of model spend and $0.54 of Modal.
Found, unrelated to this PR:
_init_service_db_via_exec(env_gateway_provider.py) races the postgres image's temporary start-up server.pg_isreadypasses, thenpsqlfails ("No such file or directory" or "the database system is shutting down") in 5 of about 38 deploys, all on thepostgres:16-alpinefallback.Round 2: after merging
main(ddb5993)maingained fe31f5a, which put OpenCode on the clock with its own copy of the rule. This PR's new shared-rule test caught it in CI. ddb5993 moves OpenCode ontoagent_egressas well.It also fixes Greptile's P1.
NO_PROXYgoes by host, so a host goes direct only when every URL for it is plain HTTP. A host also reached over HTTPS stays behind the proxy.Build contexts: compared with
main, only claude-code's and opencode's change.Re-tested on a second dedicated VM:
test_agent_env_clock_local.pypasses for both.intercept / outsidesplice / insidehost.docker.internal,172.17.0.1)main's OpenCode, Greptile's case: one Modal host reached overhttp://andhttps://status=failed. Shown with OpenCode's own Bun at a date before a certificate: direct givesCERT_NOT_YET_VALID, through the proxy gives HTTP 200.intercept / outsideChaos on clocked OpenCode, run twice:
deploy_agentsleepOne turn after a forward jump failed once: OpenCode dropped the MCP server 126 ms after a completed, intercepted TLS handshake. It didn't reproduce in three tries, the full chaos rerun passed 6/6, and OpenCode gives up on a remote MCP server after one failed request.
Spend, both rounds: about $4.60 of model spend at most, and $0.71 of Modal.
Found again, unrelated to this PR: the service-db start-up race on Modal hit 4 times in about 24 deploys.
🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge.Summary
Claude Code and OpenCode now share the rule for routing requests through the egress proxy when the env clock is armed.
No new actionable issues found. Tests were inspected but not run.
Reviews (7) · Last reviewed commit: "refactor(agents): OpenCode takes the sha..." · Reviewed by Greptile