tmux: keep the fresh-context intent until a turn completes (#352) - #948
Open
ziomik wants to merge 1 commit into
Open
tmux: keep the fresh-context intent until a turn completes (#352)#948ziomik wants to merge 1 commit into
ziomik wants to merge 1 commit into
Conversation
context_restart launched fresh, but if the fresh REPL wedged before completing its first turn the inflight watchdog force_restarted it at 600s — past the 180s respawn grace — and the relaunch resolved --continue, which resumes the newest transcript on disk: the very one the restart was meant to leave behind. The window was never cleared. Two halves, each insufficient alone: 1. Sticky fresh intent: armed on a force-fresh launch, disarmed only by a correlated post-fresh turn completion. Without it the intent is burned by the first force_restart. 2. Explicit --resume <path> instead of --continue when the session has a bound transcript; if that transcript does not exist on disk (the fresh REPL never wrote one) launch fresh rather than resume another conversation. No recorded bind keeps legacy --continue.
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.
The bug
context_restartlaunches a fresh REPL, but the fresh-context intent is spent on that single launch. If the fresh REPL wedges before completing its first turn, the inflight watchdog force-restarts it at 600s — well past the 180sFRESH_CONTEXT_RESPAWN_GRACE_SECwindow — and the relaunch resolves--continue, which resumes the newest transcript on disk: the pre-restart one. The context window is never actually cleared, so the agent restarts into the same full window and the loop repeats every ~10 minutes.Observed on
engineer(daemon journald,tmux[engineer]):The decisive detail: the fresh transcript (
5543e594.jsonl) never exists on disk. The fresh REPL never completes a turn, so Claude Code never writes the file — which is also why the watchdog sees "transcript quiet" and force-restarts in the first place. So resuming by path alone would not have been enough either: it would point at a file that isn't there.The fix
Two halves, each insufficient alone.
1. The fresh intent is sticky. Armed on a force-fresh launch (same place the respawn grace is armed), disarmed only by a correlated post-fresh turn completion — the one event that proves the fresh REPL is alive and owns a real transcript. Until then every relaunch, force_restart included, builds
mode=fresh. Without this, half 2 is still defeated: the intent is burned by the first force_restart.2. No blind
--continue.--continuemeans "newest transcript in this project dir", a guess that goes wrong exactly when it matters. When the session has a bound transcript path (SessionStart hook or discovery), resume it explicitly with--resume <path>. When that bound transcript does not exist on disk, launch fresh rather than resume somebody else's conversation. When no bind was ever recorded (e.g. first launch after a daemon restart), the legacy--continuebehavior is unchanged.claude_cmd_builtnow also logsfresh_intent_pendingandresume_path.Tests
New
TestStickyFreshContextIntent— written first, and the three behavioral ones failed with exactly the production symptom ('--continue' in ['claude', '--continue', ...]) before the fix:--continueGreen: 589 passed / 1 skipped across
test_tmux_session,test_tmux_transcript,test_tmux_context_autorestart,test_tmux_context_realtime,test_codex_tmux_session,test_codex_tmux_transcript,test_tmux_container_isolation; plus 82 passed acrosstest_daemonandtest_agent_status.ruff checkclean.Not in this PR
Raising the watchdog quiet tolerance (600s → ~900s) for
wake_reason=context_restartwas discussed as a follow-up. Deliberately left out: it changes watchdog timing, and this PR is meant to be reviewable on the launch-mode logic alone.Deploy note
This touches the session-manager force_restart path. Timing of the production rollout to be agreed before shipping.
🤖 Opened by Engineer