feat: scope code-reviewer diff to per-task commit to reduce context window pressure (#67) (#67)#74
Merged
feat: scope code-reviewer diff to per-task commit to reduce context window pressure (#67) (#67)#74
Conversation
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
The code-reviewer agent was previously receiving the full cumulative diff from the base commit to HEAD, meaning by task 13 of a 13-task decomposition the reviewer would see all prior changes. This PR scopes the diff to the current task only by committing code-writer + test-writer output before the review step and using
git diff HEAD~1..HEAD. A 200,000-character truncation guard is also applied to prevent extremely large single-task diffs from overflowing the context window.Closes #67
Changes
src/git/commit.ts: AddedgetTaskDiff()method toCommitManagerthat returnsgit diff HEAD~1..HEAD, with a graceful fallback togit show HEADwhen no parent commit exists (first commit scenario).src/executors/implementation-phase-executor.ts: Added an intermediatewip:commit after code-writer + test-writer complete, then callsgetTaskDiff()(instead ofgetDiff(baseCommit)) to obtain the task-scoped diff. Added atruncateDiff()helper that caps the diff at 200,000 characters and appends a truncation notice when the limit is exceeded.tests/git-commit.test.ts: Added tests forgetTaskDiff()covering the normal case, the first-commit fallback, and empty-diff behavior.tests/implementation-phase-executor.test.ts: Added tests verifying the executor callsgetTaskDiff()(notgetDiff()), commits before the review step with the expectedwip:prefix, and correctly applies truncation logic at and above the 200,000-character threshold.tests/e2e-pipeline.test.tsandtests/issue-orchestrator-zod-retry.test.ts: Updated mocks to exposegetTaskDiffso existing integration tests continue to pass.Implementation Details
The key insight is that at the point the code-reviewer runs, the code-writer and test-writer have already produced their changes but no commit has been made yet for the current task. Using
HEAD~1..HEADwithout an intermediate commit would return the previous task's diff. The fix introduces an intermediatewip:commit before the review, then callsgetTaskDiff()soHEAD~1..HEADcorrectly reflects the current task's changes. The final task commit still occurs at thequeue.completestep as before, so the overall commit structure gains one additional intermediate commit per task per attempt.Testing
CommitManager.getTaskDiff()covering normal, fallback, and empty-diff scenariosimplementation-phase-executor.test.tscovering task diff usage, intermediate commit ordering, truncation at/above/below the 200,000-character limit, and truncation notice contentIntegration Verification
Notes
wip:commit adds one extra commit to the git history per task attempt. If a task is retried, each attempt produces its ownwip:commit. The squash step at the end of the implementation phase will collapse these into the final commit, so the PR diff remains clean.cadre.config.json.Cadre Process Challenges
git diff HEAD~1..HEADwithout noting that the current task's changes are uncommitted at review time required the implementation plan to reason carefully about timing. This took significant space in the task description to work through.e2e-pipeline.test.ts,issue-orchestrator-zod-retry.test.ts) were needed to exposegetTaskDiff— these were not surfaced by the implementation plan and were caught only at test time.HEAD~1..HEADwithout accounting for the uncommitted state of the worktree when the reviewer runs. The implementation-planner had to reason through this and encode the intermediate-commit approach, which added complexity to task-002's description and to the test surface.Closes #67