Repository navigation
Attribute files a late-joined session wrote before its first turn start - #3245
peyton-alt wants to merge 1 commit into
Conversation
A session already running elsewhere can write untracked files into a repo during a turn before Entire sees its first TurnStart there. The pre-prompt baseline recorded those files as pre-existing, so turn end never reported them and files_touched and the checkpoint omitted them. When no session state exists for the session and its transcript records an earlier answered turn, drop untracked files modified since that turn started from the baseline. Agents opt in through the new PreviousTurnStartReader capability (Claude Code: last answered user prompt; Codex: last answered task_started). Any failure keeps today's baseline. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XJeHKew3A4AUgjs8Habf7z
There was a problem hiding this comment.
🟡 Changes recommended
Turn-boundary detection mishandles sidechain replies and image-only prompts, producing incorrect baseline anchors that can miss copied files or attribute unrelated files.
2 open issues
What changed in this PR
This PR adjusts Entire’s file attribution for sessions that join a repository after working elsewhere, addressing a case that becomes more common with global enable.
Changes:
- Adds an optional previous-turn reader for Claude Code and Codex.
- Excludes recently modified untracked files from the first-turn baseline when prior answered-turn history exists, preserving existing behavior on errors.
- Adds unit and integration coverage for late joins and new-session baseline preservation.
| File | Description |
|---|---|
cmd/entire/cli/state.go |
Applies late-join trimming during baseline capture. |
cmd/entire/cli/late_join_baseline.go |
Detects late joins and filters files by modification time. |
cmd/entire/cli/late_join_baseline_test.go |
Tests filtering and baseline-preservation conditions. |
cmd/entire/cli/integration_test/shell_capture_test.go |
Tests late-copy attribution and new-session behavior. |
cmd/entire/cli/agent/codex/transcript.go |
Extracts a shared task_started event constant. |
cmd/entire/cli/agent/codex/previous_turn.go |
Reads the latest answered Codex turn’s start time. |
cmd/entire/cli/agent/codex/previous_turn_test.go |
Tests Codex turn selection. |
cmd/entire/cli/agent/claudecode/previous_turn.go |
Reads the latest answered Claude prompt’s timestamp. |
cmd/entire/cli/agent/claudecode/previous_turn_test.go |
Tests Claude turn selection and error handling. |
cmd/entire/cli/agent/capabilities.go |
Adds the optional capability accessor. |
cmd/entire/cli/agent/agent.go |
Defines the previous-turn reader interface. |
Review effort: Balanced
| var header struct { | ||
| Type string `json:"type"` | ||
| Timestamp string `json:"timestamp"` | ||
| } | ||
| if json.Unmarshal(bytes.TrimSpace(raw), &header) != nil { | ||
| continue | ||
| } | ||
| if header.Type == transcriptlib.TypeAssistant && pending != "" { | ||
| answered, pending = pending, "" |
| if _, ok := userPrompt(raw); ok { | ||
| pending = header.Timestamp | ||
| } |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 328ec12. Configure here.
| } | ||
| kept = append(kept, f) | ||
| } | ||
| return kept, stats, dropped |
There was a problem hiding this comment.
Late-join trim ignores change time
Medium Severity
dropFilesSince decides whether a late-joined untracked file is this session's work using only ModTime. UntrackedFileStat already records ChangeTime because agents often bring files in with timestamps preserved (mv across a sibling directory, cp -p/cp -a, rsync -a). Those files still look older than the previous turn start, stay in the baseline, and turn end omits them from files_touched and the checkpoint — the gap this change is meant to close.
Reviewed by Cursor Bugbot for commit 328ec12. Configure here.



Problem
An agent session that is already running can write a new file into a repo before that repo sees its first turn start for the session. For example, the agent shell-copies
client.jsin from another folder. When the turn then starts, Entire recordsclient.jsas already untracked, so turn end treats it as pre-existing. The file is missing fromfiles_touchedand from the checkpoint.This is more common under global enable (#2030), where one session moves between repos, but it happens on main as well.
Fix
At turn start, Entire now asks whether this session is joining the repo late. That is the case when:
If so, untracked files modified at or after that earlier turn's start are not treated as pre-existing, so turn end reports them as new. Everything else keeps today's behaviour.
PreviousTurnStartReader, implemented for Claude Code (user prompts) and Codex (task_startedevents). Other agents are unchanged.Not affected
Tests
client.jsis now infiles_touched. The other two event orders are unchanged.🤖 Generated with Claude Code
https://claude.ai/code/session_01XJeHKew3A4AUgjs8Habf7z
Note
Medium Risk
Turn-start baseline logic changes file attribution for sessions with prior transcript history; behavior is gated and fails open, but incorrect timestamps could misclassify files.
Overview
Fixes late-joined sessions missing files they created (e.g. shell copies) in
files_touchedbecause those untracked files were captured as pre-existing at the repo's firstUserPromptSubmit.At turn start, when the repo has no session state but the transcript already has an earlier answered turn,
CapturePrePromptStatenow callstrimLateJoinBaseline: untracked files whose mod time is at or after that turn's start are dropped from the baseline so turn-end treats them as new.Adds optional agent capability
PreviousTurnStartReader(withAsPreviousTurnStartReader) and implements it for Claude Code (answered user prompts) and Codex (task_started+ assistant). Failures keep the full baseline unchanged.Includes unit tests for trimming and per-agent readers, plus integration tests for late-join shell copy vs. brand-new sessions.
Reviewed by Cursor Bugbot for commit 328ec12. Configure here.