🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix: avoid whole-file Codex diffs for missing snapshots (#17241)
Arvin Xu88c4eaf88ae6
diff --git a/packages/heterogeneous-agents/src/spawn/codexFileChangeTracker.test.ts b/packages/heterogeneous-agents/src/spawn/codexFileChangeTracker.test.tsindex 079e35b6783..f77de124d49 100644--- a/packages/heterogeneous-agents/src/spawn/codexFileChangeTracker.test.ts+++ b/packages/heterogeneous-agents/src/spawn/codexFileChangeTracker.test.ts@@ -114,6 +114,45 @@ describe('CodexFileChangeTracker', () => {expect(enriched.item.changes?.[0]).not.toHaveProperty('diffText');});+ it('does not synthesize a whole-file diff when an update snapshot says the file is missing', async () => {+ const dir = await mkdtemp(path.join(tmpdir(), 'codex-file-change-tracker-'));+ tempDirs.push(dir);++ const updatePath = path.join(dir, 'large-existing.md');+ const tracker = new CodexFileChangeTracker();++ await tracker.track({+ item: {+ changes: [{ kind: 'update', path: updatePath }],+ id: 'item_missing_file_snapshot',+ type: 'file_change',+ },+ type: 'item.started',+ });++ const originalContent = Array.from({ length: 1200 }, (_, index) => `line ${index + 1}`).join(+ '\n',+ );+ await writeFile(updatePath, `${originalContent}\nnew 1\nnew 2\nnew 3\nnew 4\nnew 5\n`, 'utf8');++ const enriched = await tracker.track({+ item: {+ changes: [{ kind: 'update', linesAdded: 5, linesDeleted: 0, path: updatePath }],+ id: 'item_missing_file_snapshot',+ type: 'file_change',+ },+ type: 'item.completed',+ });++ expect(enriched.item).toMatchObject({+ changes: [{ kind: 'update', linesAdded: 5, linesDeleted: 0, path: updatePath }],+ linesAdded: 5,+ linesDeleted: 0,+ });+ expect(enriched.item).not.toHaveProperty('diffText');+ expect(enriched.item.changes?.[0]).not.toHaveProperty('diffText');+ });+it('treats rename changes as metadata-only and keeps line stats at zero', async () => {const dir = await mkdtemp(path.join(tmpdir(), 'codex-file-change-tracker-'));tempDirs.push(dir);diff --git a/packages/heterogeneous-agents/src/spawn/codexFileChangeTracker.ts b/packages/heterogeneous-agents/src/spawn/codexFileChangeTracker.tsindex 5265308c668..d70cbb10eb7 100644--- a/packages/heterogeneous-agents/src/spawn/codexFileChangeTracker.ts+++ b/packages/heterogeneous-agents/src/spawn/codexFileChangeTracker.ts@@ -149,16 +149,16 @@ const computeFileChangeDiff = async (return buildFileChangeDiff(filePath, previousContent, '');}- if (!snapshot) {+ // An update diff is only trustworthy when the pre-change file was read successfully.+ // Treating a missing or unreadable snapshot as empty content turns a small edit into a+ // synthetic whole-file addition (for example, +5 lines can be reported as +1205).+ if (!snapshot?.exists || snapshot.content === undefined) {return {linesAdded: change.linesAdded ?? 0,linesDeleted: change.linesDeleted ?? 0,};}- if (!snapshot?.exists && !current.exists) return { linesAdded: 0, linesDeleted: 0 };-- if (snapshot?.exists && snapshot.content === undefined) return { linesAdded: 0, linesDeleted: 0 };if (current.exists && current.content === undefined) return { linesAdded: 0, linesDeleted: 0 };return buildFileChangeDiff(filePath, previousContent, nextContent);