fix: subagent file modifications invisible to checkpoint detection (ENT-297)#323
Open
fix: subagent file modifications invisible to checkpoint detection (ENT-297)#323
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes ENT-297 by ensuring checkpoint detection includes file modifications performed by Claude Code subagents (spawned via the Task tool), so turns aren’t skipped when only subagents write/edit files.
Changes:
- Added
claudecode.ExtractAllModifiedFiles()to aggregate modified files across main + subagent transcripts. - Updated Claude Code stop hook (
commitWithMetadata) and mid-session “new content” detection to include subagent transcripts. - Added unit and integration tests to cover subagent-only modification scenarios.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| cmd/entire/cli/agent/claudecode/transcript.go | Adds ExtractAllModifiedFiles() to collect modified files from main + subagent transcripts. |
| cmd/entire/cli/hooks_claudecode_handlers.go | Stop hook now uses ExtractAllModifiedFiles() for subagent-aware modified-file detection. |
| cmd/entire/cli/strategy/manual_commit_hooks.go | Mid-session commit detection now checks subagent transcripts for Claude Code sessions. |
| cmd/entire/cli/agent/claudecode/transcript_test.go | Adds unit tests for ExtractAllModifiedFiles() (subagent inclusion + dedupe cases). |
| cmd/entire/cli/strategy/mid_turn_commit_test.go | Adds test ensuring subagent-only changes are detected as “new content.” |
| cmd/entire/cli/integration_test/hooks_test.go | Adds integration regression test for stop-hook checkpointing when only subagents modify files. |
| cmd/entire/cli/strategy/registry.go | Updates //nolint:ireturn rationale comment. |
| cmd/entire/cli/strategy/manual_commit.go | Updates //nolint:ireturn rationale comment. |
| cmd/entire/cli/strategy/auto_commit.go | Updates //nolint:ireturn rationale comment. |
This was referenced Feb 13, 2026
2d26295 to
97fb2a9
Compare
…gents This function extracts modified file paths from both the main transcript and any subagent transcripts spawned via the Task tool. It follows the same pattern as CalculateTotalTokenUsage: parse once, extract agent IDs, read subagent transcripts, and merge results with deduplication. This is the foundation for fixing ENT-297 where subagent-only file changes were invisible to checkpointing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 732abe6dd3e4
Replace extractModifiedFiles (main transcript only) with claudecode.ExtractAllModifiedFiles which also parses subagent transcripts. This fixes the core bug where subagent-only file changes produced totalChanges=0, causing checkpoints to be skipped. Falls back to main-transcript-only extraction on error. Also reuses the subagentsDir variable for token usage calculation to avoid redefinition. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 732abe6dd3e4
…difications The PrepareCommitMsg hook's live transcript check only scanned the main transcript via ExtractModifiedFilesFromOffset, missing file changes made by subagents spawned via the Task tool. When the main transcript contained only Task calls (no direct Write/Edit), modifiedFiles was empty and the function returned false -- causing missing checkpoint trailers on commits that included subagent-written files. After the existing main transcript scan, also call claudecode.ExtractAllModifiedFiles which parses both the main and subagent transcripts, picking up Write/Edit tool calls from subagent files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 732abe6dd3e4
…-297) Verify that the Stop hook creates checkpoints when only subagents modify files. The test constructs a main transcript with only a Task tool call and a subagent transcript with Write tool calls, then confirms both auto-commit and manual-commit strategies detect the changes via ExtractAllModifiedFiles. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 732abe6dd3e4
- Add logging.Debug when ExtractAllModifiedFiles errors in sessionHasNewContentFromLiveTranscript (was silently swallowed) - Fix AddTaskToolResult to produce "agentId: <id>" format matching real Claude Code transcripts (was "Task completed by agent <id>") - Use AddTaskToolResult in integration test instead of reaching into TranscriptBuilder internals Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 1facd4391816
Three functions duplicated the same pattern: extract modified files from the main transcript, augment with subagent transcripts, normalize paths. Consolidate into extractModifiedFilesFromLiveTranscript(state, offset) and two thin wrappers (extractFilesFromLiveTranscript for carry-forward, extractNewModifiedFilesFromLiveTranscript for content detection). Also wires subagent file extraction into extractFilesFromLiveTranscript (carry-forward) and sessionHasNewContentInCommittedFiles (PostCommit ACTIVE sessions) which were missing it. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: fc1317d7f797
When condensing a mid-session commit (no shadow branch), FilesTouched was extracted only from the main transcript. Subagent-modified files were missed, causing the condensed checkpoint to have incomplete file lists. Use the shared extractModifiedFilesFromLiveTranscript helper which includes subagent transcripts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: e91ff0dab977
For ACTIVE sessions in PostCommit, always set hasNew=true instead of re-validating via transcript analysis. PrepareCommitMsg already validates the trailer (unconditionally for no-TTY/agent commits, via content detection for TTY/human commits). Transcript-based re-validation is unreliable because subagent transcripts may not be available at PostCommit time (subagent still running). Removes sessionHasNewContentInCommittedFiles which is now unused. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: f20127b19334
017c468 to
cdc5c7e
Compare
Contributor
Author
|
bugbot run |
For Claude Code agents, skip the generic ExtractModifiedFilesFromOffset call and go directly to ExtractAllModifiedFiles, which parses the main transcript and subagent transcripts in one pass. Previously both were called, parsing the main transcript twice. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Entire-Checkpoint: 184069756ffc
Contributor
Author
|
bugbot run |
…gent-only-changes-checkpointing
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.
Summary
Fixes subagent file modifications being invisible to checkpoint detection. When Claude Code delegates work to subagents via the Task tool, file changes made by those subagents were not tracked, causing:
totalChanges=0)Changes
ExtractAllModifiedFiles()— new function that scans both main and subagent transcripts (agent-<id>.jsonl) for Write/Edit/NotebookEdit tool callsExtractAllModifiedFilesso checkpoints aren't skipped when only subagents modify filessessionHasNewContentFromLiveTranscript— augmented with subagent transcript scanning for mid-session commit detectionextractModifiedFilesFromLiveTranscript— consolidates 3 duplicated code blocks (main transcript extraction + subagent augmentation + path normalization)extractSessionDataFromLiveTranscript— uses shared helper so condensed checkpoints include subagent filessessionHasNewContentInCommittedFiles— now unused after the PostCommit simplificationKey insight
At PostCommit time during a mid-subagent commit, subagent transcript data is unavailable: the main transcript has no
tool_resultwithagentId:yet, and subagent files may still be in-flight. Since PrepareCommitMsg already validates the trailer (unconditionally for no-TTY/agent commits, via content detection for TTY/human commits), PostCommit trusts that decision for ACTIVE sessions rather than re-validating.Fixes ENT-297
Test plan
ExtractAllModifiedFiles(4 cases: includes subagent files, deduplicates, no subagents, subagent-only changes)sessionHasNewContentFromLiveTranscriptwith subagent-only modificationsTestHookRunner_SimulateStop_SubagentOnlyChanges(both strategies)mise run fmt && mise run lint && mise run test:ci)🤖 Generated with Claude Code