Skip to content

fix(agents): Claude Code keeps its transcripts on an env clock set ahead of real time - #831

Merged
earakely-scale merged 2 commits into
mainfrom
edgararakelyan/fd-6368-hb5118-the-claude-code-agent-loses
Nov 20, 2026
Merged

earakely-scale merged 2 commits into
mainfrom
edgararakelyan/fd-6368-hb5118-the-claude-code-agent-loses

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

What and why

On an env clock set ahead of real time, agent-env's Claude Code agent forgets the conversation between turns.

The CLI has a retention cleanup that deletes transcripts older than cleanupPeriodDays (default 30). It judges age by
each file's modification time against its own clock. Since #726 the CLI runs on the env's clock, while file times
stay real. So with a universe date more than 30 days after the real date, every transcript looks old, including the
live session's.

The cleanup runs a few seconds after each CLI run starts. By then the run has already loaded its history, but it
deletes the transcript and writes the rest of the turn to a fresh file. The next --resume therefore sees only what
the previous run wrote after the deletion.

In the laptop task (psi-benchmark-tasks #19), where the clock is frozen 74 days ahead:

  • The user sim saw only her own previous answer at every read.
  • The assistant started many wakes at about a fresh session's size. It quoted the Windows 11 Pro requirement in one
    wake, then ordered a Windows 11 Home laptop two wakes later.

Now every CLI run takes --settings '{"cleanupPeriodDays": 100000000}', which works alongside --setting-sources user.

Why that value, and not turning the cleanup off:

  • The CLI has no off switch for it. It refuses cleanupPeriodDays: 0, and --no-session-persistence keeps no
    transcript at all, so --resume would have nothing.
  • 100,000,000 days is the whole range a JavaScript date covers on either side of 1970. The cleanup's cutoff is the
    CLI's clock minus that, so it's never after 1970 whatever date the clock shows.
  • Where the cutoff would fall outside that range, as on a clock before 1970, it isn't a valid date, and every sweep
    then skips (if(cutoff===null)return).

What changes

  • claude_bridge.py:
    • CLI_SETTINGS holds {"cleanupPeriodDays": 100_000_000}.
    • _command passes it as --settings on every run, new or resumed.
  • test_env_clock_image.py: a test that every run carries the setting, at least JS_DATE_RANGE_DAYS.

How it was found and checked

  • The real failure: a run of the laptop task on 0.9.1585, with both agents' transcripts copied out of their
    containers every 15 s. Each transcript lost every record five times, e.g. 11.8 MB down to 238 KB. Every loss came
    2–36 s after a CLI run started.
  • A key-free repro: the pinned CLI (2.1.322), a stand-in Messages API that logs what each call sent, and
    libfaketime. Four turns of about 40 s each:
Clock cleanupPeriodDays What turn 4 sent the model
real default turns 1–4
frozen at 2027-02-01 default turn 4 only
frozen at 2027-02-01 36500, by --settings turns 1–4
frozen at 3027-02-01 36500, by --settings turn 4 only
frozen at 3027-02-01 100000000, by --settings turns 1–4
frozen at 1950-02-01 100000000, by --settings turns 1–4
  • Turns that end within a couple of seconds never trigger the cleanup, so short tests pass either way.
  • Unit tests: tst/unit/agents/claude_code passes, except two tests that fail on macOS on main as well
    (test_card_contract install, test_claude_bridge_cancel in-its-group). CI runs them on Linux.

End to end

I ran the laptop task twice more on a test host: agent-env 0.9.1585 with only this change applied, and the same
frozen 2027 clock as the failing runs. Each run built the Claude Code image from the patched sources; the built image's
claude_bridge.py has CLI_SETTINGS. Both conversations were copied out of their containers every 15 s.

  • Run 1: the change with 36500 days.
  • Run 2: the change as merged, 100,000,000 days.
Before (0.9.1585) Run 1 Run 2
Assistant's transcript wiped 5 times (e.g. 11.8 MB → 238 KB) 41 copies, 444 KB → 40.6 MB, no record lost 22 copies, 560 KB → 17.3 MB, no record lost
User sim's transcript wiped at each read 11 copies, 38 KB → 0.2 MB, no record lost 7 copies, 37 KB → 0.1 MB, no record lost
Assistant's wakes many start near a fresh session's 47.6k tokens each of 7 starts where the previous one ended each of 5 starts where the previous one ended
User sim's prompt over her reads flat, 5.3k–8.0k 5.5k → 7.5k → 8.7k → 10.4k → 12.0k → 13.6k 5.3k → 6.8k → 8.3k → 9.9k

One wake per run still gets smaller inside the wake: Claude Code compacted its context (at 170,844 and 158,940
tokens), as it does at any date. The next wake then starts where that one ended. Both runs completed and were scored
normally. They cost $3.44 and $2.26.

Not in this PR

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge.

Summary

Claude Code now receives a transcript retention period of 100,000,000 days on every run, protecting conversation history when the environment clock is far ahead of real time.

  • Claude Code keeps session history when its environment clock runs ahead.

No new actionable issues found.

Reviews (5) · Last reviewed commit: "fix(agents): keep transcripts on any clo..." · Reviewed by Greptile

…ead 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 <noreply@anthropic.com>
…head

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 <noreply@anthropic.com>
@earakely-scale
earakely-scale merged commit 2881d48 into main Nov 20, 2026
39 checks passed
@earakely-scale
earakely-scale deleted the edgararakelyan/fd-6368-hb5118-the-claude-code-agent-loses branch November 20, 2026 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant