-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix: Allow reading large Claude session files by disabling size limit #3166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,50 @@ describe('ClaudeCodeSessionService', () => { | |
| service = instaService.createInstance(ClaudeCodeSessionService); | ||
| }); | ||
|
|
||
| it('handles large session files (>5MB) correctly', async () => { | ||
| // Create a large session file by repeating a valid message entry | ||
| const fileName = 'large-session.jsonl'; | ||
| const timestamp = new Date().toISOString(); | ||
|
|
||
| // Create a base message entry | ||
| const baseMessage = JSON.stringify({ | ||
| parentUuid: null, | ||
| sessionId: 'large-session', | ||
| type: 'user', | ||
| message: { role: 'user', content: 'x'.repeat(1000) }, // 1KB per message | ||
| uuid: 'uuid-1', | ||
| timestamp | ||
| }); | ||
|
|
||
| // Repeat the message 6000 times to create ~6MB file | ||
| const lines: string[] = []; | ||
| for (let i = 0; i < 6000; i++) { | ||
| const message = JSON.parse(baseMessage); | ||
| message.uuid = `uuid-${i}`; | ||
| if (i > 0) { | ||
| message.parentUuid = `uuid-${i - 1}`; | ||
| } | ||
| lines.push(JSON.stringify(message)); | ||
| } | ||
|
|
||
| const largeFileContents = lines.join('\n'); | ||
| const fileSizeInMB = Math.round(largeFileContents.length / (1024 * 1024)); | ||
|
|
||
| // Verify the file is actually large enough (>5MB) | ||
| expect(fileSizeInMB).toBeGreaterThan(5); | ||
|
|
||
| mockFs.mockDirectory(dirUri, [[fileName, FileType.File]]); | ||
| mockFs.mockFile(URI.joinPath(dirUri, fileName), largeFileContents, 1000); | ||
|
|
||
| // Should not throw an error for large files | ||
| const sessions = await service.getAllSessions(CancellationToken.None); | ||
|
|
||
|
Comment on lines
+91
to
+96
|
||
| expect(sessions).toHaveLength(1); | ||
| expect(sessions[0].id).toBe('large-session'); | ||
| // Verify we loaded all messages | ||
| expect(sessions[0].messages).toHaveLength(6000); | ||
| }); | ||
|
|
||
| it('loads 2 sessions from 3 real fixture files', async () => { | ||
| // Setup mock with all 3 real fixture files | ||
| const fileName1 = '553dd2b5-8a53-4fbf-9db2-240632522fe5.jsonl'; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,7 +52,7 @@ export class MockFileSystemService implements IFileSystemService { | |
| return this.mockDirs.get(uriString) || []; | ||
| } | ||
|
|
||
| async readFile(uri: URI): Promise<Uint8Array> { | ||
| async readFile(uri: URI, disableLimit?: boolean): Promise<Uint8Array> { | ||
|
||
| const uriString = uri.toString(); | ||
| if (this.mockErrors.has(uriString)) { | ||
| throw this.mockErrors.get(uriString); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing
disableLimit=trueremoves the 5MB safeguard for these session files. Since this code auto-loads all*.jsonlsessions, a very large/corrupted file could now cause high memory usage or extension host instability. Consider adding a separate (higher) hard cap for session files (and/or a streaming reader) so “large but reasonable” files work while still protecting against extreme sizes.