From 396327e4ade554bed2b2b157fbf4818a1d65141a Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Thu, 19 Nov 2026 16:23:37 -0800 Subject: [PATCH 1/2] fix(agents): Claude Code keeps its transcripts on an env clock set ahead of real time The CLI deletes transcripts older than cleanupPeriodDays (default 30) by its own clock. On an env clock months ahead of the files' real times, it deleted the live session's transcript a few seconds into each run, so each resume saw only what the previous run wrote after that. Co-Authored-By: Claude Opus 5.5 --- .../agents/agents/claude-code/claude_bridge.py | 5 ++++- .../agents/claude_code/test_env_clock_image.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/agent_env/agents/agents/claude-code/claude_bridge.py b/src/agent_env/agents/agents/claude-code/claude_bridge.py index 1d030f2da..2b8e15c83 100644 --- a/src/agent_env/agents/agents/claude-code/claude_bridge.py +++ b/src/agent_env/agents/agents/claude-code/claude_bridge.py @@ -55,6 +55,9 @@ def project_dir(workspace: Path) -> Path: ) # What agent-env gives an agent for [model.headers]: a JSON object of header names to values. MODEL_HEADERS_ENV = "LITELLM_EXTRA_HEADERS" +# Settings every CLI run takes. The CLI deletes a transcript older than cleanupPeriodDays by its own clock, and on an env +# clock months ahead of the files' real times the transcript of the conversation it resumes looks that old. +CLI_SETTINGS = {"cleanupPeriodDays": 36500} # The CLI version ClaudeCodeTool names the tools of; a test holds it to the Dockerfile's CLAUDE_CODE_VERSION. @@ -627,7 +630,7 @@ def _command(session_id: str, resume: bool, *, model: str | None, allowed_tools: the CLI's own tools: ``{"disable": "*"}`` offers none, ``{"only": [...]}`` just those, and ``{"disable": [...]}`` the CLI's defaults but those; with any selection, its MCP servers are only ``mcp_servers``.""" cmd = ["claude", "-p", "--output-format", "stream-json", "--verbose", "--dangerously-skip-permissions", - "--setting-sources", "user"] + "--setting-sources", "user", "--settings", json.dumps(CLI_SETTINGS)] cmd += ["--resume", session_id] if resume else ["--session-id", session_id] if model: cmd += ["--model", _with_1m_window(model)] diff --git a/tst/unit/agents/claude_code/test_env_clock_image.py b/tst/unit/agents/claude_code/test_env_clock_image.py index 64de53fe4..67dcc0f22 100644 --- a/tst/unit/agents/claude_code/test_env_clock_image.py +++ b/tst/unit/agents/claude_code/test_env_clock_image.py @@ -1,7 +1,8 @@ """Claude Code's bridge on the env's clock: it hands the shared egress rule (tst/unit/agents/test_agent_egress.py) the model endpoint's URL and every MCP server's, so on an armed clock an env MCP server over TLS goes through the egress -proxy and loopback and plain-HTTP hosts go direct; unarmed, the CLI goes out as before. What every clocked image shares -is checked in tst/unit/agents/test_agent_clock_images.py.""" +proxy and loopback and plain-HTTP hosts go direct; unarmed, the CLI goes out as before. Every run keeps its transcripts, +which the CLI's own cleanup would delete on a clock ahead of the files' real times. What every clocked image shares is +checked in tst/unit/agents/test_agent_clock_images.py.""" from __future__ import annotations @@ -27,6 +28,15 @@ def test_on_an_armed_clock_the_cli_goes_out_through_the_proxy_and_to_loopback_di assert env["NODE_USE_ENV_PROXY"] == "1" +@pytest.mark.parametrize("resume", [False, True]) +def test_every_cli_run_keeps_transcripts_a_clock_years_ahead_would_call_old(resume): + command = claude_bridge._command("sess", resume, model=None, allowed_tools=None, mcp_servers=None, + system_prompt=None, output_format=None, role=None, effort=None, max_turns=None) + + assert command[command.index("--setting-sources") + 1] == "user" + assert json.loads(command[command.index("--settings") + 1])["cleanupPeriodDays"] >= 365 * 100 + + def _spawned_env(monkeypatch, tmp_path, armed: bool) -> dict[str, str]: """The environment _spawn_claude starts the CLI with, for an env MCP server over TLS, one over plain HTTP and the peer-agents one.""" From 6a243e45fb82ff8f8fca39e51ff4c6c813b22f58 Mon Sep 17 00:00:00 2001 From: Edgar Arakelyan Date: Thu, 19 Nov 2026 17:06:21 -0800 Subject: [PATCH 2/2] fix(agents): keep transcripts on any clock date, not just a century ahead The CLI refuses cleanupPeriodDays 0 and --no-session-persistence keeps no transcript, so the retention is every day a JavaScript date can be from 1970: the CLI's cutoff is never after 1970 on any clock. Checked on a clock 1,000 years ahead (36500 days lost the history, this kept it) and on a 1950 clock. Co-Authored-By: Claude Opus 5.5 --- src/agent_env/agents/agents/claude-code/claude_bridge.py | 7 ++++--- tst/unit/agents/claude_code/test_env_clock_image.py | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/agent_env/agents/agents/claude-code/claude_bridge.py b/src/agent_env/agents/agents/claude-code/claude_bridge.py index 2b8e15c83..3bffd332d 100644 --- a/src/agent_env/agents/agents/claude-code/claude_bridge.py +++ b/src/agent_env/agents/agents/claude-code/claude_bridge.py @@ -55,9 +55,10 @@ def project_dir(workspace: Path) -> Path: ) # What agent-env gives an agent for [model.headers]: a JSON object of header names to values. MODEL_HEADERS_ENV = "LITELLM_EXTRA_HEADERS" -# Settings every CLI run takes. The CLI deletes a transcript older than cleanupPeriodDays by its own clock, and on an env -# clock months ahead of the files' real times the transcript of the conversation it resumes looks that old. -CLI_SETTINGS = {"cleanupPeriodDays": 36500} +# Settings every CLI run takes. The CLI deletes files older than cleanupPeriodDays by its own clock, so on an env clock +# ahead of real time it deleted the transcript it resumes. It refuses 0, and --no-session-persistence keeps none, so +# this is every day a JavaScript date can be from 1970: the cutoff is never after 1970, whatever the clock says. +CLI_SETTINGS = {"cleanupPeriodDays": 100_000_000} # The CLI version ClaudeCodeTool names the tools of; a test holds it to the Dockerfile's CLAUDE_CODE_VERSION. diff --git a/tst/unit/agents/claude_code/test_env_clock_image.py b/tst/unit/agents/claude_code/test_env_clock_image.py index 67dcc0f22..a611472d3 100644 --- a/tst/unit/agents/claude_code/test_env_clock_image.py +++ b/tst/unit/agents/claude_code/test_env_clock_image.py @@ -17,6 +17,8 @@ from tst.util.build_context import sent PROXY = "http://127.0.0.1:3128" +# How many days a JavaScript date can be from 1970 either way (ECMAScript's time value range). +JS_DATE_RANGE_DAYS = 100_000_000 ARMED_PAGE = agent_egress.clockpage.encode(2, 1_900_000_000 * 10**9, 10**18, 1.0, 1, 3, 0, 0) @@ -29,12 +31,12 @@ def test_on_an_armed_clock_the_cli_goes_out_through_the_proxy_and_to_loopback_di @pytest.mark.parametrize("resume", [False, True]) -def test_every_cli_run_keeps_transcripts_a_clock_years_ahead_would_call_old(resume): +def test_every_cli_run_keeps_transcripts_whatever_date_the_clock_shows(resume): command = claude_bridge._command("sess", resume, model=None, allowed_tools=None, mcp_servers=None, system_prompt=None, output_format=None, role=None, effort=None, max_turns=None) assert command[command.index("--setting-sources") + 1] == "user" - assert json.loads(command[command.index("--settings") + 1])["cleanupPeriodDays"] >= 365 * 100 + assert json.loads(command[command.index("--settings") + 1])["cleanupPeriodDays"] >= JS_DATE_RANGE_DAYS def _spawned_env(monkeypatch, tmp_path, armed: bool) -> dict[str, str]: