Repository navigation
[FD-6434] fix(agents): the changelog's tar runs on real time in clocked agent images - #859
Merged
Merged
Conversation
…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>
…changelog-real-time
…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>
11 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
FD-6434. snapshot/v1's changelog loses data when a run puts the agent on the env's clock (
sync_env_clockwithagent_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 timeit 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:
/usr/local,/etcand the home folder, 278 MB per tool call, and the CLI waits on each hook.expires_atagainst its own clock. Once the clock ispast 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
a2a_server.py): both incremental tars,_baseline_changelogand_capture_changelog, start withAGENTENV_REAL_TIME=1in their environment.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 runson real time. Its grant-expiry check and its uploads are then correct.
Why it's built this way:
its children are faked again. That's why the server and the hook each hand it to tar, rather than rely on inheritance.
envrather than an assignment prefix, which works only through a shell.envworks with orwithout one. This isn't the
#!/usr/bin/env Xtrap: thereenvitself starts with the marker and loses it before itexecs X. Here
envstarts without it and sets it for the interpreter it execs.envin place, andenvexecs Python in place, so the hook keeps the PID the CLI spawned.The CLI's SIGTERM on a hook timeout still reaches Python.
apply-changelog) stay on the env's clock, since neither compares times against the clock. Ata clock behind real time GNU tar warns "time stamp … in the future" per member and exits 0.
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 andget_timekeep the env'stime. 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.confnames it, and the server's/proc/<pid>/environshows it. No shared code changes(
utils/egress_proxy,utils/faketime_clockandutils/agent_clockare untouched).Testing
Unit.
tst/util/recording_tar.py: a stand-intar, put first onPATH. It records each run's arguments and whether the runstarted with the marker.
test_the_changelogs_tar_runs_on_real_time(Claude Code and OpenCode): enable, then capture, with the marker absentfrom 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, asthe CLI does, and directly, as a shell-less CLI would. A
sitecustomizeprobe records the environment the hookstarted in. Dropping the launch fails both cases. Going back to a bare assignment prefix fails the no-shell case.
tst/unit/agents/claude_code,opencodeandtest_agent_clock_images.pypass on the Mac withGNU 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
mailand the agents ran onlocal, unless noted. "Stand-in" runs use a scripted model on the Docker bridge, 4turns, each editing
/app/existing.txtand writing a newturn-n.date. "Real" runs use claude-haiku-4-5, each turnappending a label to
/app/notes.md. Each run ends with a rewind: a second agent restored from the first one'schangelog.
/appempty, conversation gone (real model: "this is the first turn")SHELL_DATEandGET_TIMEread 2027-02-04turn-1.datein 3 increments; run 3:10existing.txt/notes.mdstale (turn 1 only)/appcompletesettings.jsonholds/usr/bin/env AGENTENV_REAL_TIME=1 /usr/local/bin/python3 /tmp/claude-code-changelog-8000/capture.py. A privileged/procwatcher saw the CLI run it undersh -c. The hook'sPython and every tar carry
AGENTENV_REAL_TIME=0(started with the marker, which libfaketime then cleared). On mainneither carries it. A probe from a faked shell: the
envlaunch reads real time, plain Python reads the env's time.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.
supervisorctl restart agent, +75 d). Claude Code keeps capturing (3increments; main: 0). OpenCode stops capturing after the restart on both sides (see Limits).
expiry is judged on real time. On main both fail at once.
*.modal.hostwith a certificate that starts after the virtual date, ClaudeCode at 1950, real model.
search_emailsworks through the egress proxy (CONNECT intercepted). 12 increments hold bothturns' edits, and the rewound agent recalls both labels.
rewound agent (also on Modal) recalls both labels.
Model spend: $1.43 (claude-haiku-4-5), plus about $0.15 of Modal.
Limits
so the follower crash-loops past 2262 and
sync_env_clockfails (FD-6471). 2200 stood in as the far-future case. Thetar repro above covers +1000 y directly.
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.
date and
get_timefollow the jump. Same on main (FD-6474).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.service-db start-up race on all 3 attempts. Claude Code's Modal runs passed.
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.
settings.jsoncaptured by an image without this change, applied ontoan 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


Confidence 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.
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 timeReviews (1) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile