Skip to content

[FD-6434] fix(agents): the changelog's tar runs on real time in clocked agent images - #859

Merged
earakely-scale merged 6 commits into
mainfrom
edgararakelyan/agent-changelog-real-time
Nov 21, 2026
Merged

earakely-scale merged 6 commits into
mainfrom
edgararakelyan/agent-changelog-real-time

Conversation

@earakely-scale

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

Copy link
Copy Markdown
Collaborator

Why

FD-6434. snapshot/v1's changelog loses data when a run puts the agent on the env's clock (sync_env_clock with
agent_clock: true). It affects Claude Code and OpenCode, the two clocked agent images with a changelog.

The changelog stores the agent's writable layer as GNU incremental tars (tar --listed-incremental). tar keeps the time
it starts at as the next increment's baseline. The next increment then takes only the files whose mtime or ctime is at or
after that baseline. The images don't fake stat, so mtimes are real.

The A2A server starts with AGENTENV_REAL_TIME=1, but libfaketime takes the marker out of the server's own environment,
so everything the server starts follows the env's clock. That includes every changelog tar, and Claude Code's post-tool
capture hook (a child of the CLI) and the tar it starts. Measured on the VM with GNU tar 1.35 under libfaketime:

baseline written by tar on edited file new file untouched file
real time (this PR) captured captured not captured
clock +75 d / +1000 y missing captured not captured
clock at 1950 captured captured captured
  • Clock ahead: each increment leaves out edits to files that already existed. A rewound agent gets stale files.
  • Clock behind: each increment carries every file under the roots. For Claude Code that is all of /usr/local,
    /etc and the home folder, 278 MB per tool call, and the CLI waits on each hook.
  • Claude Code, clock ahead: the hook checks the upload grant's expires_at against its own clock. Once the clock is
    past the grant's real expiry, every upload fails with "The object-transfer grant has expired." The run stores nothing,
    and a rewound agent has neither its files nor its conversation.

What changes

  • OpenCode (a2a_server.py): both incremental tars, _baseline_changelog and _capture_changelog, start with
    AGENTENV_REAL_TIME=1 in their environment.
  • Claude Code (tar_changelog.py): the baseline tar (Changelog._reset) and the hook's tar start with the marker.
    The hook command the CLI runs is now /usr/bin/env AGENTENV_REAL_TIME=1 <python> <capture.py>, so the hook itself runs
    on real time. Its grant-expiry check and its uploads are then correct.

Why it's built this way:

  • The marker holds only for the process that starts with it. libfaketime takes it out of that process's environment, so
    its children are faked again. That's why the server and the hook each hand it to tar, rather than rely on inheritance.
  • The hook goes through env rather than an assignment prefix, which works only through a shell. env works with or
    without one. This isn't the #!/usr/bin/env X trap: there env itself starts with the marker and loses it before it
    execs X. Here env starts without it and sets it for the interpreter it execs.
  • sh, bash, dash and zsh exec env in place, and env execs Python in place, so the hook keeps the PID the CLI spawned.
    The CLI's SIGTERM on a hook timeout still reaches Python.
  • Extraction and listing (apply-changelog) stay on the env's clock, since neither compares times against the clock. At
    a clock behind real time GNU tar warns "time stamp … in the future" per member and exits 0.
  • OpenCode's snapshot tars (opencode export/import, the workspace archive) aren't incremental, so they're unchanged.

What the model sees doesn't change. Its shell's date, the CLI's "Today's date is …" line and get_time keep the env's
time. The hook exits 0 whatever happens and its stderr never reaches the model. With the clock off, the clock page holds
real time, so tar and the hook behave as on main. The only container-visible difference is the hook command in
~/.claude/settings.json, which now names the marker. That was already discoverable: the image's
/etc/agentenv/root.conf names it, and the server's /proc/<pid>/environ shows it. No shared code changes
(utils/egress_proxy, utils/faketime_clock and utils/agent_clock are untouched).

Testing

Unit.

  • tst/util/recording_tar.py: a stand-in tar, put first on PATH. It records each run's arguments and whether the run
    started with the marker.
  • test_the_changelogs_tar_runs_on_real_time (Claude Code and OpenCode): enable, then capture, with the marker absent
    from the test's environment, as libfaketime leaves it. Each incremental tar must start with the marker. Removing
    env= at any one of the four call sites fails it (mutation-checked, one site at a time).
  • test_the_hook_starts_on_real_time_with_or_without_a_shell: runs the installed hook command through /bin/sh -c, as
    the CLI does, and directly, as a shell-less CLI would. A sitecustomize probe records the environment the hook
    started in. Dropping the launch fails both cases. Going back to a bare assignment prefix fails the no-shell case.
  • After merging main: tst/unit/agents/claude_code, opencode and test_agent_clock_images.py pass on the Mac with
    GNU tar first on PATH (480 passed; the 9 skips are Linux-only). Before the merge, on Ubuntu 24.04 with GNU tar 1.35,
    477 passed with none skipped, and the new tests run over main's two agent files failed exactly the 4 new tests.
    ruff check . passes.

VM e2e and chaos on a dedicated admin VM. Branch 4e5238c (this PR before merging main) was A/B'd against main. The
env was mail and the agents ran on local, unless noted. "Stand-in" runs use a scripted model on the Docker bridge, 4
turns, each editing /app/existing.txt and writing a new turn-n.date. "Real" runs use claude-haiku-4-5, each turn
appending a label to /app/notes.md. Each run ends with a rewind: a second agent restored from the first one's
changelog.

case main this PR
Claude Code, clock armed at real time 3 increments same 3 increments, same files
Claude Code, +75 d (stand-in and real) 0 increments, every upload "grant has expired"; rewound /app empty, conversation gone (real model: "this is the first turn") 3 / 15 increments with every edit; rewound agent recalls all labels; SHELL_DATE and GET_TIME read 2027-02-04
Claude Code, 2200 0 increments (grant expired) 3 delta increments, rewound complete
Claude Code, 1950 increments 2 and 3 are 277.8 MB each (+10,768 files); turn-1.date in 3 increments; run 3:10 152/197/198 kB, no repeats, rewound complete; run 1:20
OpenCode, clock armed at real time 3 increments same
OpenCode, +75 d (stand-in and real) increments 2 and 3 miss the edit; rewound existing.txt / notes.md stale (turn 1 only) every increment has its turn's edit; rewound /app complete
OpenCode, 2200 increments 2 and 3 miss the edit all edits
OpenCode, 1950 (turns written from the host, see Limits) every increment carries the whole workspace 3 delta increments, no repeats
Clock off, both agents Claude Code 152.1/196.8/198.2 kB Claude Code 152.3/196.9/198.3 kB, same files; OpenCode identical
  • Hook in the real image: settings.json holds /usr/bin/env AGENTENV_REAL_TIME=1 /usr/local/bin/python3 /tmp/claude-code-changelog-8000/capture.py. A privileged /proc watcher saw the CLI run it under sh -c. The hook's
    Python and every tar carry AGENTENV_REAL_TIME=0 (started with the marker, which libfaketime then cleared). On main
    neither carries it. A probe from a faked shell: the env launch reads real time, plain Python reads the env's time.
  • C1, jumps between turns (+75 d, advance to 2200, set 1950, clear). Claude Code: 4 increments, each with exactly
    its turn's edit; the rewound agent sees all 5 labels. Main loses positions 0 and 1 (grant expired), then stores
    277.8 MB at position 3 after the 1950 baseline. OpenCode: deltas with no repeats here; main repeats files.
  • C2, changes during a turn (rate 3600×, freeze, set 1950). Claude Code: 3 increments, all edits, rewound complete.
  • C6, server restarted between turns (supervisorctl restart agent, +75 d). Claude Code keeps capturing (3
    increments; main: 0). OpenCode stops capturing after the restart on both sides (see Limits).
  • C8, grant TTL 150 s at +75 d. Position 0 uploads. Position 1 fails "grant has expired" after a real 150 s, so
    expiry is judged on real time. On main both fail at once.
  • TLS: env on Modal, its HTTPS MCP on *.modal.host with a certificate that starts after the virtual date, Claude
    Code at 1950, real model. search_emails works through the egress proxy (CONNECT intercepted). 12 increments hold both
    turns' edits, and the rewound agent recalls both labels.
  • Prod path: agent and env both on Modal, Claude Code, +75 d, real model. 12 increments reached the store, and the
    rewound agent (also on Modal) recalls both labels.

Model spend: $1.43 (claude-haiku-4-5), plus about $0.15 of Modal.

Limits

  • +1000 y can't be reached by any clocked agent, on main or here. The clock page packs time as 64-bit nanoseconds,
    so the follower crash-loops past 2262 and sync_env_clock fails (FD-6471). 2200 stood in as the far-future case. The
    tar repro above covers +1000 y directly.
  • OpenCode at 1950 fails every turn with "Session not found", and after a backward jump its new message sorts before
    the earlier ones. Same on main (FD-6473). The 1950 OpenCode row writes each turn's files from the host as the agent
    user, so the capture still has something to take.
  • Claude Code's "Today's date is …" line stays at the session's first date after a jump between turns. The shell
    date and get_time follow the jump. Same on main (FD-6474).
  • A server restart mid-run loses the conversation for both agents, on main and with the clock off too. OpenCode's
    changelog also stops capturing after a restart, since its config lives in memory. Whether a crashed server should
    restart in place or end the container is handled in a separate PR; this one doesn't touch root.conf.
  • OpenCode with the env on Modal at a clock behind real time wasn't run: the env deploy hit the known Modal
    service-db start-up race on all 3 attempts. Claude Code's Modal runs passed.
  • gemini and letta-code start the same incremental tars. Neither image is clocked on main. Their clock PRs ([FD-5916] feat(agents): the Gemini CLI image follows the env's clock #770
    gemini, [FD-5916] feat(agents): the Letta Code image follows the env's clock #769 letta-code) need the same tar change, and gemini also needs the hook change, since its hook checks the
    grant's expiry by its own clock. Whichever merges after this one should carry it.
  • Restoring settings from an older image: a settings.json captured by an image without this change, applied onto
    an agent that already enabled its changelog on the same port, keeps its old hook, which runs on the env's clock.
    Applies go onto a fresh agent of the same image, so no caller does this, and it isn't guarded.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

The PR makes both agents’ incremental changelog tars use real time. Claude Code’s capture hook also uses real time so upload grants expire correctly.

  • Claude Code changelogs capture file changes and check grant expiry on real time.
  • OpenCode changelogs compare turn changes against real file times.

Diagram

sequenceDiagram
    participant Server as Agent server
    participant CLI as Claude Code CLI
    participant Hook as Capture hook
    participant Tar as Incremental tar
    Server->>Tar: Baseline with real-time marker
    CLI->>Hook: env sets real-time marker
    Note over Hook: Marker is removed after startup
    Hook->>Tar: Set real-time marker again
    Hook->>Hook: Check grant and upload on real time
Loading

Reviews (1) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

earakely-scale and others added 6 commits November 20, 2026 14:14
…time

GNU tar's --listed-incremental keeps the time tar starts at as the next
capture's baseline and archives only the files whose (real) mtime or ctime is
at or after it. The A2A server runs with AGENTENV_REAL_TIME=1, but libfaketime
takes the marker out of the server's own environment, so the tar it starts,
and the tar Claude Code's post-tool hook starts, ran on the env's clock: with
the clock ahead, every capture after the baseline left edits to existing files
out; behind it, every capture carried every file under the roots. Each
incremental tar now starts with the marker in its environment: Claude Code's
baseline (server) and capture (hook), OpenCode's baseline and capture
(server).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The post-tool hook is a child of the CLI, which follows the env's clock, and it
uploads each increment through a namespace grant whose expiry the protocol's
uploader checks against the process's own clock. On an env clock past the
grant's expiry (any clock days ahead of real time) the hook refused every
upload as grant_expired, so a run captured nothing. The hook's command now
starts with AGENTENV_REAL_TIME=1, which the shell the CLI runs it through hands
the hook; its tar is given the marker again, as libfaketime takes it out of
the hook's own environment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…is process's, as OpenCode's does

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

The hook command was `AGENTENV_REAL_TIME=1 <python> <capture.py>`, which only works because the CLI runs a hook's
command through a shell. A CLI that started hooks without one would fail to start every hook, which it treats as
non-blocking, and the changelog would capture nothing without a word. `/usr/bin/env AGENTENV_REAL_TIME=1 <python>
<capture.py>` works either way: env, started without the marker, sets it for the interpreter it execs. Every shell
checked (sh, bash, dash, zsh) still execs it in place, so the CLI's SIGTERM on a hook's timeout still reaches Python.

The hook test now runs the command through a shell and without one. Going back to the bare assignment fails the
no-shell case, and dropping the launch fails both.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale requested a review from a team as a code owner November 21, 2026 03:37
@earakely-scale
earakely-scale merged commit 4cc84e6 into main Nov 21, 2026
35 checks passed
@earakely-scale
earakely-scale deleted the edgararakelyan/agent-changelog-real-time branch November 21, 2026 06:14
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.

1 participant