Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/core/src/core/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,25 @@ describe('Logger', () => {
);
});

it.each([
['null', null],
['number', 123],
])(
'should return an empty history if history is %s instead of an array (#29194)',
async (_label: string, badHistory: unknown) => {
const taggedFilePath = path.join(
TEST_GEMINI_DIR,
'checkpoint-wrong-shape.json',
);
await fs.writeFile(
taggedFilePath,
JSON.stringify({ history: badHistory }),
);
const loadedCheckpoint = await logger.loadCheckpoint('wrong-shape');
expect(loadedCheckpoint).toEqual({ history: [] });
},
);

it('should return an empty history if logger is not initialized', async () => {
const uninitializedLogger = new Logger(
testSessionId,
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/core/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,13 @@ export class Logger {
parsedContent !== null &&
'history' in parsedContent
) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return parsedContent as Checkpoint;
const history: unknown = parsedContent.history;
// A valid-JSON file with a non-array history (crash mid-save, full
// disk, hand edit) must degrade like any other corrupt file (#29194).
if (Array.isArray(history)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return parsedContent as Checkpoint;
}
}

debugLogger.warn(
Expand Down